| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- /* ***** BEGIN LICENSE BLOCK *****
- * Distributed under the BSD license:
- *
- * Copyright (c) 2010, Ajax.org B.V.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of Ajax.org B.V. nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * ***** END LICENSE BLOCK ***** */
- define(function(require, exports, module) {
- "use strict";
- var TokenIterator = require("../token_iterator").TokenIterator;
- var commonAttributes = [
- "accesskey",
- "class",
- "contenteditable",
- "contextmenu",
- "dir",
- "draggable",
- "dropzone",
- "hidden",
- "id",
- "inert",
- "itemid",
- "itemprop",
- "itemref",
- "itemscope",
- "itemtype",
- "lang",
- "spellcheck",
- "style",
- "tabindex",
- "title",
- "translate"
- ];
- var eventAttributes = [
- "onabort",
- "onblur",
- "oncancel",
- "oncanplay",
- "oncanplaythrough",
- "onchange",
- "onclick",
- "onclose",
- "oncontextmenu",
- "oncuechange",
- "ondblclick",
- "ondrag",
- "ondragend",
- "ondragenter",
- "ondragleave",
- "ondragover",
- "ondragstart",
- "ondrop",
- "ondurationchange",
- "onemptied",
- "onended",
- "onerror",
- "onfocus",
- "oninput",
- "oninvalid",
- "onkeydown",
- "onkeypress",
- "onkeyup",
- "onload",
- "onloadeddata",
- "onloadedmetadata",
- "onloadstart",
- "onmousedown",
- "onmousemove",
- "onmouseout",
- "onmouseover",
- "onmouseup",
- "onmousewheel",
- "onpause",
- "onplay",
- "onplaying",
- "onprogress",
- "onratechange",
- "onreset",
- "onscroll",
- "onseeked",
- "onseeking",
- "onselect",
- "onshow",
- "onstalled",
- "onsubmit",
- "onsuspend",
- "ontimeupdate",
- "onvolumechange",
- "onwaiting"
- ];
- var globalAttributes = commonAttributes.concat(eventAttributes);
- var attributeMap = {
- "html": ["manifest"],
- "head": [],
- "title": [],
- "base": ["href", "target"],
- "link": ["href", "hreflang", "rel", "media", "type", "sizes"],
- "meta": ["http-equiv", "name", "content", "charset"],
- "style": ["type", "media", "scoped"],
- "script": ["charset", "type", "src", "defer", "async"],
- "noscript": ["href"],
- "body": ["onafterprint", "onbeforeprint", "onbeforeunload", "onhashchange", "onmessage", "onoffline", "onpopstate", "onredo", "onresize", "onstorage", "onundo", "onunload"],
- "section": [],
- "nav": [],
- "article": ["pubdate"],
- "aside": [],
- "h1": [],
- "h2": [],
- "h3": [],
- "h4": [],
- "h5": [],
- "h6": [],
- "header": [],
- "footer": [],
- "address": [],
- "main": [],
- "p": [],
- "hr": [],
- "pre": [],
- "blockquote": ["cite"],
- "ol": ["start", "reversed"],
- "ul": [],
- "li": ["value"],
- "dl": [],
- "dt": [],
- "dd": [],
- "figure": [],
- "figcaption": [],
- "div": [],
- "a": ["href", "target", "ping", "rel", "media", "hreflang", "type"],
- "em": [],
- "strong": [],
- "small": [],
- "s": [],
- "cite": [],
- "q": ["cite"],
- "dfn": [],
- "abbr": [],
- "data": [],
- "time": ["datetime"],
- "code": [],
- "var": [],
- "samp": [],
- "kbd": [],
- "sub": [],
- "sup": [],
- "i": [],
- "b": [],
- "u": [],
- "mark": [],
- "ruby": [],
- "rt": [],
- "rp": [],
- "bdi": [],
- "bdo": [],
- "span": [],
- "br": [],
- "wbr": [],
- "ins": ["cite", "datetime"],
- "del": ["cite", "datetime"],
- "img": ["alt", "src", "height", "width", "usemap", "ismap"],
- "iframe": ["name", "src", "height", "width", "sandbox", "seamless"],
- "embed": ["src", "height", "width", "type"],
- "object": ["param", "data", "type", "height" , "width", "usemap", "name", "form", "classid"],
- "param": ["name", "value"],
- "video": ["src", "autobuffer", "autoplay", "loop", "controls", "width", "height", "poster"],
- "audio": ["src", "autobuffer", "autoplay", "loop", "controls"],
- "source": ["src", "type", "media"],
- "track": ["kind", "src", "srclang", "label", "default"],
- "canvas": ["width", "height"],
- "map": ["name"],
- "area": ["shape", "coords", "href", "hreflang", "alt", "target", "media", "rel", "ping", "type"],
- "svg": [],
- "math": [],
- "table": ["summary"],
- "caption": [],
- "colgroup": ["span"],
- "col": ["span"],
- "tbody": [],
- "thead": [],
- "tfoot": [],
- "tr": [],
- "td": ["headers", "rowspan", "colspan"],
- "th": ["headers", "rowspan", "colspan", "scope"],
- "form": ["accept-charset", "action", "autocomplete", "enctype", "method", "name", "novalidate", "target"],
- "fieldset": ["disabled", "form", "name"],
- "legend": [],
- "label": ["form", "for"],
- "input": ["type", "accept", "alt", "autocomplete", "checked", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "height", "list", "max", "maxlength", "min", "multiple", "pattern", "placeholder", "readonly", "required", "size", "src", "step", "width", "files", "value"],
- "button": ["autofocus", "disabled", "form", "formaction", "formenctype", "formmethod", "formnovalidate", "formtarget", "name", "value", "type"],
- "select": ["autofocus", "disabled", "form", "multiple", "name", "size"],
- "datalist": [],
- "optgroup": ["disabled", "label"],
- "option": ["disabled", "selected", "label", "value"],
- "textarea": ["autofocus", "disabled", "form", "maxlength", "name", "placeholder", "readonly", "required", "rows", "cols", "wrap"],
- "keygen": ["autofocus", "challenge", "disabled", "form", "keytype", "name"],
- "output": ["for", "form", "name"],
- "progress": ["value", "max"],
- "meter": ["value", "min", "max", "low", "high", "optimum"],
- "details": ["open"],
- "summary": [],
- "command": ["type", "label", "icon", "disabled", "checked", "radiogroup", "command"],
- "menu": ["type", "label"],
- "dialog": ["open"]
- };
- var elements = Object.keys(attributeMap);
- function is(token, type) {
- return token.type.lastIndexOf(type + ".xml") > -1;
- }
- function findTagName(session, pos) {
- var iterator = new TokenIterator(session, pos.row, pos.column);
- var token = iterator.getCurrentToken();
- while (token && !is(token, "tag-name")){
- token = iterator.stepBackward();
- }
- if (token)
- return token.value;
- }
- var HtmlCompletions = function() {
- };
- (function() {
- this.getCompletions = function(state, session, pos, prefix) {
- var token = session.getTokenAt(pos.row, pos.column);
- if (!token)
- return [];
- // tag name
- if (is(token, "tag-name") || is(token, "tag-open") || is(token, "end-tag-open"))
- return this.getTagCompletions(state, session, pos, prefix);
- // tag attribute
- if (is(token, "tag-whitespace") || is(token, "attribute-name"))
- return this.getAttributeCompetions(state, session, pos, prefix);
- return [];
- };
- this.getTagCompletions = function(state, session, pos, prefix) {
- return elements.map(function(element){
- return {
- value: element,
- meta: "tag",
- score: Number.MAX_VALUE
- };
- });
- };
- this.getAttributeCompetions = function(state, session, pos, prefix) {
- var tagName = findTagName(session, pos);
- if (!tagName)
- return [];
- var attributes = globalAttributes;
- if (tagName in attributeMap) {
- attributes = attributes.concat(attributeMap[tagName]);
- }
- return attributes.map(function(attribute){
- return {
- caption: attribute,
- snippet: attribute + '="$0"',
- meta: "attribute",
- score: Number.MAX_VALUE
- };
- });
- };
- }).call(HtmlCompletions.prototype);
- exports.HtmlCompletions = HtmlCompletions;
- });
|