Skip to content

Commit

Permalink
Create a new attribute code hints JSON file.
Browse files Browse the repository at this point in the history
Read global attributes from the new JSON file and combine with other tag-specific attributes before filtering with user input.
Replace Array.prototype forEach with $.map as suggested by Ty.
  • Loading branch information
RaymondLim committed Jul 26, 2012
1 parent 0d70a7c commit 82a462f
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 10 deletions.
130 changes: 130 additions & 0 deletions src/extensions/default/HTMLCodeHints/HtmlAttributes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"accesskey": { "attriboption": [], "global": "true" },
"class": { "attriboption": [], "global": "true" },
"contenteditable": { "attriboption": [], "global": "true", "attribtype": "boolean" },
"contextmenu": { "attriboption": [], "global": "true" },
"dir": { "attriboption": ["ltr", "rtl"], "global": "true"},
"draggable": { "attriboption": ["auto", "false", "true"], "global": "true" },
"dropzone": { "attriboption": ["copy", "move", "link"], "global": "true" },
"hidden": { "attriboption": ["hidden"], "global": "true" },
"id": { "attriboption": [], "global": "true" },
"lang": { "attriboption": [], "global": "true" },
"role": { "attriboption": [], "global": "true" },
"spellcheck": { "attriboption": [], "global": "true", "attribtype": "boolean" },
"style": { "attriboption": [], "global": "true" },
"tabindex": { "attriboption": [], "global": "true" },
"title": { "attriboption": [], "global": "true" },

"accept": { "attriboption": [] },
"accept-charset": { "attriboption": [] },
"action": { "attriboption": [] },
"align": { "attriboption": [] },
"alt": { "attriboption": [] },
"archive": { "attriboption": [] },
"async": { "attriboption": [] },
"autocomplete": { "attriboption": [] },
"autofocus": { "attriboption": [] },
"autoplay": { "attriboption": [] },
"behavior": { "attriboption": [] },
"bgcolor": { "attriboption": [] },
"border": { "attriboption": [] },
"challenge": { "attriboption": [] },
"char": { "attriboption": [] },
"charoff": { "attriboption": [] },
"charset": { "attriboption": [] },
"checked": { "attriboption": [] },
"cite": { "attriboption": [] },
"codebase": { "attriboption": [] },
"codetype": { "attriboption": [] },
"cols": { "attriboption": [] },
"colspan": { "attriboption": [] },
"content": { "attriboption": [] },
"controls": { "attriboption": [] },
"coords": { "attriboption": [] },
"data": { "attriboption": [] },
"datetime": { "attriboption": [] },
"declare": { "attriboption": [] },
"default": { "attriboption": [] },
"defer": { "attriboption": [] },
"direction": { "attriboption": [] },
"dirname": { "attriboption": [] },
"disabled": { "attriboption": [] },
"enctype": { "attriboption": [] },
"for": { "attriboption": [] },
"form": { "attriboption": [] },
"formaction": { "attriboption": [] },
"formenctype": { "attriboption": [] },
"formmethod": { "attriboption": [] },
"formnovalidate": { "attriboption": [] },
"formtarget": { "attriboption": [] },
"headers": { "attriboption": [] },
"height": { "attriboption": [] },
"high": { "attriboption": [] },
"href": { "attriboption": [] },
"hreflang": { "attriboption": [] },
"hspace": { "attriboption": [] },
"http-equiv": { "attriboption": [] },
"icon": { "attriboption": [] },
"ismap": { "attriboption": [] },
"keytype": { "attriboption": [] },
"kind": { "attriboption": [] },
"label": { "attriboption": [] },
"list": { "attriboption": [] },
"longdesc": { "attriboption": [] },
"loop": { "attriboption": [] },
"low": { "attriboption": [] },
"manifest": { "attriboption": [] },
"max": { "attriboption": [] },
"maxlength": { "attriboption": [] },
"media": { "attriboption": [] },
"mediagroup": { "attriboption": [] },
"method": { "attriboption": [] },
"min": { "attriboption": [] },
"multiple": { "attriboption": [] },
"muted": { "attriboption": [] },
"name": { "attriboption": [] },
"nohref": { "attriboption": [] },
"novalidate": { "attriboption": [] },
"open": { "attriboption": [] },
"optimum": { "attriboption": [] },
"pattern": { "attriboption": [] },
"placeholder": { "attriboption": [] },
"poster": { "attriboption": [] },
"preload": { "attriboption": [] },
"profile": { "attriboption": [] },
"pubdate": { "attriboption": [] },
"radiogroup": { "attriboption": [] },
"rel": { "attriboption": [] },
"readonly": { "attriboption": [] },
"required": { "attriboption": [] },
"reversed": { "attriboption": [] },
"rev": { "attriboption": [] },
"rows": { "attriboption": [] },
"rowspan": { "attriboption": [] },
"sandbox": { "attriboption": [] },
"seamless": { "attriboption": [] },
"scope": { "attriboption": [] },
"scoped": { "attriboption": [], "attribtype": "boolean" },
"scrollamount": { "attriboption": [] },
"scrolldelay": { "attriboption": [] },
"shape": { "attriboption": [] },
"size": { "attriboption": [] },
"sizes": { "attriboption": [] },
"span": { "attriboption": [] },
"src": { "attriboption": [] },
"srcdoc": { "attriboption": [] },
"srclang": { "attriboption": [] },
"standby": { "attriboption": [] },
"start": { "attriboption": [] },
"step": { "attriboption": [] },
"target": { "attriboption": [] },
"truespeed": { "attriboption": [] },
"type": { "attriboption": [] },
"usemap": { "attriboption": [] },
"value": { "attriboption": [] },
"vspace": { "attriboption": [] },
"width": { "attriboption": [] },
"wrap": { "attriboption": [] },
"xml:lang": { "attriboption": [] },
"xmlns": { "attriboption": [] }
}
34 changes: 24 additions & 10 deletions src/extensions/default/HTMLCodeHints/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define(function (require, exports, module) {
// Load dependent modules
var HTMLUtils = brackets.getModule("language/HTMLUtils"),
HTMLTags = require("text!HtmlTags.json"),
//HTMLAttributes = require("text!HtmlAttributes.json"),
HTMLAttributes = require("text!HtmlAttributes.json"),
CodeHintManager = brackets.getModule("editor/CodeHintManager");


Expand Down Expand Up @@ -126,11 +126,25 @@ define(function (require, exports, module) {
* @constructor
*/
function AttrHints () {
// TODO Raymond
this.tags = JSON.parse(HTMLTags);
// this.attributes = JSON.parse(HTMLAttributes);
this.globalAttributes = this.readAttrHints(HTMLAttributes);
}

/**
* @private
* Parse the code hints from JSON data and extract all hints from property names.
* @param {string} a JSON string that has the code hints data
* @return {!Array.<string>} An array of code hints read from the JSON data source.
*/
AttrHints.prototype.readAttrHints = function(jsonStr) {
var hintObj = JSON.parse(jsonStr);
return $.map(hintObj, function (value, key) {
if (value.global === "true") {
return key;
}
});
};

AttrHints.prototype.handleSelect = function (completion, editor) {
var start = {line: -1, ch: -1},
end = {line: -1, ch: -1},
Expand Down Expand Up @@ -185,15 +199,15 @@ define(function (require, exports, module) {
attrName = queryObj.attrName;

if (this.tags && this.tags[tagName]) {
var unfiltered = this.tags[tagName].attributes;
var unfiltered = this.tags[tagName].attributes,
unfiltered2 = unfiltered.concat(this.globalAttributes);

if (unfiltered.length) {
unfiltered.forEach(function (item) {
if (item.indexOf(attrName) !== 0) {
return false;
if (unfiltered2.length) {
result = $.map(unfiltered2, function (item) {
if (item.indexOf(attrName) === 0) {
return item;
}
result.push(item);
});
}).sort();
}
}
}
Expand Down

0 comments on commit 82a462f

Please sign in to comment.