source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/applications/admin/static/codemirror/addon/hint/css-hint.js

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 1.9 KB
Line 
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: http://codemirror.net/LICENSE
3
4(function(mod) {
5  if (typeof exports == "object" && typeof module == "object") // CommonJS
6    mod(require("../../lib/codemirror"), require("../../mode/css/css"));
7  else if (typeof define == "function" && define.amd) // AMD
8    define(["../../lib/codemirror", "../../mode/css/css"], mod);
9  else // Plain browser env
10    mod(CodeMirror);
11})(function(CodeMirror) {
12  "use strict";
13
14  var pseudoClasses = {link: 1, visited: 1, active: 1, hover: 1, focus: 1,
15                       "first-letter": 1, "first-line": 1, "first-child": 1,
16                       before: 1, after: 1, lang: 1};
17
18  CodeMirror.registerHelper("hint", "css", function(cm) {
19    var cur = cm.getCursor(), token = cm.getTokenAt(cur);
20    var inner = CodeMirror.innerMode(cm.getMode(), token.state);
21    if (inner.mode.name != "css") return;
22
23    var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
24    if (/[^\w$_-]/.test(word)) {
25      word = ""; start = end = cur.ch;
26    }
27
28    var spec = CodeMirror.resolveMode("text/css");
29
30    var result = [];
31    function add(keywords) {
32      for (var name in keywords)
33        if (!word || name.lastIndexOf(word, 0) == 0)
34          result.push(name);
35    }
36
37    var st = inner.state.state;
38    if (st == "pseudo" || token.type == "variable-3") {
39      add(pseudoClasses);
40    } else if (st == "block" || st == "maybeprop") {
41      add(spec.propertyKeywords);
42    } else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
43      add(spec.valueKeywords);
44      add(spec.colorKeywords);
45    } else if (st == "media" || st == "media_parens") {
46      add(spec.mediaTypes);
47      add(spec.mediaFeatures);
48    }
49
50    if (result.length) return {
51      list: result,
52      from: CodeMirror.Pos(cur.line, start),
53      to: CodeMirror.Pos(cur.line, end)
54    };
55  });
56});
Note: See TracBrowser for help on using the repository browser.