anyword-hint.js
10 years ago
anyword-hint.min.js
9 years ago
css-hint.js
11 years ago
css-hint.min.js
9 years ago
html-hint.js
11 years ago
html-hint.min.js
9 years ago
javascript-hint.js
11 years ago
javascript-hint.min.js
9 years ago
show-hint.css
11 years ago
show-hint.js
10 years ago
show-hint.min.js
9 years ago
sql-hint.js
10 years ago
sql-hint.min.js
9 years ago
xml-hint.js
11 years ago
xml-hint.min.js
10 years ago
css-hint.js
61 lines
| 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 | if (token.type == "keyword" && "!important".indexOf(token.string) == 0) |
| 24 | return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start), |
| 25 | to: CodeMirror.Pos(cur.line, token.end)}; |
| 26 | |
| 27 | var start = token.start, end = cur.ch, word = token.string.slice(0, end - start); |
| 28 | if (/[^\w$_-]/.test(word)) { |
| 29 | word = ""; start = end = cur.ch; |
| 30 | } |
| 31 | |
| 32 | var spec = CodeMirror.resolveMode("text/css"); |
| 33 | |
| 34 | var result = []; |
| 35 | function add(keywords) { |
| 36 | for (var name in keywords) |
| 37 | if (!word || name.lastIndexOf(word, 0) == 0) |
| 38 | result.push(name); |
| 39 | } |
| 40 | |
| 41 | var st = inner.state.state; |
| 42 | if (st == "pseudo" || token.type == "variable-3") { |
| 43 | add(pseudoClasses); |
| 44 | } else if (st == "block" || st == "maybeprop") { |
| 45 | add(spec.propertyKeywords); |
| 46 | } else if (st == "prop" || st == "parens" || st == "at" || st == "params") { |
| 47 | add(spec.valueKeywords); |
| 48 | add(spec.colorKeywords); |
| 49 | } else if (st == "media" || st == "media_parens") { |
| 50 | add(spec.mediaTypes); |
| 51 | add(spec.mediaFeatures); |
| 52 | } |
| 53 | |
| 54 | if (result.length) return { |
| 55 | list: result, |
| 56 | from: CodeMirror.Pos(cur.line, start), |
| 57 | to: CodeMirror.Pos(cur.line, end) |
| 58 | }; |
| 59 | }); |
| 60 | }); |
| 61 |