aboutsummaryrefslogtreecommitdiff
path: root/src/js
diff options
context:
space:
mode:
authorGravatar Rogan Creswick <creswick@gmail.com>2013-06-14 16:24:52 -0700
committerGravatar Rogan Creswick <creswick@gmail.com>2013-06-14 16:24:52 -0700
commit2c3b25addc2bc8b1cb91eb6e708119ea47379e68 (patch)
treec689287dab1afec4d352e36413b3c032557d59fa /src/js
parentf8c37c2ca06b3185ce988b6fd3552f0ea2ea27fa (diff)
added upgoerfive rule
Diffstat (limited to 'src/js')
-rw-r--r--src/js/fiveui/injected/compute.js24
-rw-r--r--src/js/fiveui/js/background.js30
-rw-r--r--src/js/fiveui/js/rules.js25
3 files changed, 56 insertions, 23 deletions
diff --git a/src/js/fiveui/injected/compute.js b/src/js/fiveui/injected/compute.js
index 67f2d56..a796558 100644
--- a/src/js/fiveui/injected/compute.js
+++ b/src/js/fiveui/injected/compute.js
@@ -35,6 +35,11 @@
core.port = obtainComputePort();
/**
+ * Whether rules are being currently executed.
+ */
+ core.rulesRunning = false;
+
+ /**
* Whether or not rules are fired when a dom change is detected.
*/
core.maskRules = false;
@@ -123,7 +128,7 @@
return "";
}
- return nodeParents(node) + node.id + node.tagName;
+ return nodeParents(node) + node.id + node.tagName + core.getElementXPath(node);
};
var str = prob.name + prob.descr + prob.url + prob.severity
@@ -231,6 +236,7 @@
}
};
+ core.rulesRunning = true;
for(var i=0; i<rs.length; ++i) {
theRule = rs[i];
@@ -245,6 +251,7 @@
stats.numRules += 1;
}
}
+ core.rulesRunning = false;
date = new Date();
stats.end = date.getTime();
@@ -271,7 +278,7 @@
};
var handleDOMEvent = function(e){
- if ( !uicAttrEvent(e.target) && !underFiveUI(e.target) ) {
+ if (!core.rulesRunning && !uicAttrEvent(e.target) && !underFiveUI(e.target) ) {
core.scheduleRules();
}
};
@@ -298,9 +305,20 @@
};
var registerBackendListeners = function(port) {
- var assembleRules = function(ruleStrList) {
+ var assembleRules = function(ruleDescr) {
var ruleList = [];
+ _.each(ruleDescr.dependencies,
+ function(dep){
+ try {
+ eval(dep.content);
+ } catch (x) {
+ console.error('Could not evaluate rule dependency: ' + dep.url);
+ console.error(x);
+ }
+ });
+
+ var ruleStrList = ruleDescr.rules;
for(var i=0; i<ruleStrList.length; ++i) {
var moduleStr =
[ '(function(){'
diff --git a/src/js/fiveui/js/background.js b/src/js/fiveui/js/background.js
index 3d2a2f1..c52aca8 100644
--- a/src/js/fiveui/js/background.js
+++ b/src/js/fiveui/js/background.js
@@ -117,7 +117,7 @@ fiveui.Background.prototype.connect = function(tabId, port, url, isUiPort) {
if (ruleSet == null) {
console.err('could not find url pattern for tab.url, but one was strongly expected');
} else {
- port.emit('SetRules', ruleSet.rules);
+ port.emit('SetRules', _.pick(ruleSet, ["dependencies", "rules"]));
}
}
};
@@ -138,26 +138,18 @@ fiveui.Background.prototype.pageLoad = function(tabId, url, data) {
this.updateWidget(tabState);
- var dependencies = [];
+ var computeScripts =
+ [ this.dataLoader('underscore.js')
+ , this.dataLoader('jquery/jquery-1.8.3.js')
+ , this.dataLoader('md5.js')
+ , this.dataLoader('injected/prelude.js')
+ , this.dataLoader('injected/jquery-plugins.js')
+ , this.dataLoader('injected/compute.js')
+ ];
- if (ruleSet && ruleSet.dependencies ) {
- dependencies = ruleSet.dependencies;
- }
-
- var computeScripts = _.flatten(
- [ [ this.dataLoader('underscore.js')
- , this.dataLoader('jquery/jquery-1.8.3.js')
- , this.dataLoader('md5.js')
- , this.dataLoader('injected/prelude.js')
- , this.dataLoader('injected/jquery-plugins.js')
- ]
- , dependencies
- , [ this.dataLoader('injected/compute.js')
- ]
- ]);
this.loadScripts(tabId, computeScripts, true, data);
- var uiScripts = _.flatten(
+ var uiScripts =
[ this.dataLoader('underscore.js')
, this.dataLoader('jquery/bundled.css')
, this.dataLoader('jquery/jquery-1.8.3.js')
@@ -166,7 +158,7 @@ fiveui.Background.prototype.pageLoad = function(tabId, url, data) {
, this.dataLoader('injected/prelude.js')
, this.dataLoader('injected/ui.js')
, this.dataLoader('injected/jquery-plugins.js')
- ]);
+ ];
this.loadScripts(tabId, uiScripts, false, data);
}
};
diff --git a/src/js/fiveui/js/rules.js b/src/js/fiveui/js/rules.js
index 7e55b4f..8f40c7d 100644
--- a/src/js/fiveui/js/rules.js
+++ b/src/js/fiveui/js/rules.js
@@ -80,6 +80,26 @@ fiveui.RuleSet.load = function(manifest_url, options) {
if(match) {
var base_url = manifest_url.substring(0,match.index);
+ var loadDependencies = function(manifest, dependencies, rules) {
+ if (_.isEmpty(dependencies)) {
+ loadRules(manifest, rules);
+ } else {
+ // XXX there's likely problems here, how should we make sure that the
+ // url is what we expect?
+ var dep_file = dependencies.pop();
+ var dep_url = base_url + '/' + dep_file;
+
+ fiveui.ajax.get(dep_url, {
+ success: function(text) {
+ manifest.dependencies.push({'url': dep_url, 'content': text});
+ loadDependencies(manifest, dependencies, rules);
+ },
+
+ error: options.error
+ });
+ }
+ };
+
// iterate over rules, retrieving the
var loadRules = function(manifest, rules) {
@@ -127,6 +147,9 @@ fiveui.RuleSet.load = function(manifest_url, options) {
// manifest.
manifest.patterns = [];
+ var dependencies = manifest.dependencies;
+ manifest.dependencies = [];
+
// remove the rules, as they'll be added back once processed.
var rules = manifest.rules;
manifest.rules = [];
@@ -134,7 +157,7 @@ fiveui.RuleSet.load = function(manifest_url, options) {
// overwrite any source present with the one given by the user.
manifest.source = manifest_url;
- loadRules(manifest, rules);
+ loadDependencies(manifest, dependencies, rules);
},
error: function() {