diff options
Diffstat (limited to 'src/js/fiveui/js')
-rw-r--r-- | src/js/fiveui/js/ffcheck.js | 3 | ||||
-rw-r--r-- | src/js/fiveui/js/state.js | 61 | ||||
-rw-r--r-- | src/js/fiveui/js/utils.js | 20 |
3 files changed, 57 insertions, 27 deletions
diff --git a/src/js/fiveui/js/ffcheck.js b/src/js/fiveui/js/ffcheck.js deleted file mode 100644 index 2157ed0..0000000 --- a/src/js/fiveui/js/ffcheck.js +++ /dev/null @@ -1,3 +0,0 @@ -if (! /Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { - window.onload=fiveui.chrome.options.init; -} diff --git a/src/js/fiveui/js/state.js b/src/js/fiveui/js/state.js index b3487c5..903f047 100644 --- a/src/js/fiveui/js/state.js +++ b/src/js/fiveui/js/state.js @@ -41,19 +41,28 @@ fiveui.WinState = function(x, y, width, height, closed) { /** * @constructor - * @param {string} name The name of the rule that this problem represents. - * @param {string} descr Short description of the problem. - * @param {string} url The url that the problem occurred at. - * @param {number} severity The severity of the problem + * @param {string} cfg The config object for the problem. See + * fiveui.Problem.sanitize */ -fiveui.Problem = function(name, descr, url, severity, hash, xpath, msg) { - this.name = name || ''; - this.descr = descr || ''; - this.url = url || ''; - this.severity = severity || 0; - this.hash = hash; - this.xpath = xpath; - this.msg = msg; +fiveui.Problem = function(cfg) { + _.defaults(this, fiveui.Problem.sanitize(cfg)); +}; + +fiveui.Problem.sanitize = function(obj) { + + var defs = { + name: '', // the name of the rule that this problem came from + descr: '', // short description of the problem + url: '', // url that the problem came from + severity: 0, // severity of the problem + phash: null, // hash for the combination of problem and element in context + hash: null, // hash for the element in context + xpath: '', // path of the element in the document + msg: '', // problem message + }; + + return _.defaults(_.pick(obj, _.keys(defs)), defs); + }; /** @@ -61,7 +70,7 @@ fiveui.Problem = function(name, descr, url, severity, hash, xpath, msg) { * @return {!fiveui.Problem} The problem that the object represents. */ fiveui.Problem.fromJSON = function(obj) { - return new fiveui.Problem(obj.name, obj.descr, obj.url, obj.severity, obj.hash, obj.xpath, obj.msg); + return new fiveui.Problem(obj); }; /** @@ -73,26 +82,32 @@ fiveui.Problem.fromJSON = function(obj) { * the corresponding tab. */ fiveui.TabState = function(tabId, winState, uiPort) { - this.tabId = tabId; - this.winState = winState; - this.uiPort = uiPort; + this.tabId = tabId; + this.winState = winState; + this.uiPort = uiPort; this.computePorts = []; - this.problems = []; + this.problems = []; this.seenProblems = new Set(); - this.stats = {}; + this.stats = {}; }; _.extend(fiveui.TabState.prototype, { + /** + * Returns true when the combination of element and problem has been seen + * before, to avoid repeats. + * + * NOTE: we use phash here, as it allows multiple distinct problems to target + * the same element. + */ addProblem: function(prob) { - if(!this.seenProblems.contains(prob.hash)) { + if(this.seenProblems.contains(prob.phash)) { + return false; + } else { this.problems.push(prob); - this.seenProblems.add(prob.hash); + this.seenProblems.add(prob.phash); return true; } - else { - return false; - } }, addStats: function (stats) { diff --git a/src/js/fiveui/js/utils.js b/src/js/fiveui/js/utils.js index 204d961..9f4d2c6 100644 --- a/src/js/fiveui/js/utils.js +++ b/src/js/fiveui/js/utils.js @@ -98,6 +98,8 @@ var removeComments = function(data) { var state = 0; var toEOL = 1; var toEOC = 2; + var inQUOTE = 3; + var inDQUOTE = 4; var sanitized = ''; var len = data.length; @@ -120,8 +122,24 @@ var removeComments = function(data) { } break; + case inQUOTE: + if(data[e] == '\'') { + state = 0; + } + break; + + case inDQUOTE: + if(data[e] == '"') { + state = 0; + } + break; + default: - if(data[e] == '/') { + if(data[e] == '\'') { + state = inQUOTE; + } else if(data[e] == '"') { + state = inDQUOTE; + } else if(data[e] == '/') { if(data[e+1] == '/') { sanitized = sanitized + data.substring(s,e); state = toEOL; |