lib/javascripts/wbench.js in wbench-0.3.2 vs lib/javascripts/wbench.js in wbench-0.3.3
- old
+ new
@@ -1,67 +1,120 @@
-window.resourceURLs = function() {
- urls = backgroundURLs().concat(imageURLs(), scriptURLs(), linkURLs(), currentURL());
+window.WBench = {
+ resourceURLs: function() {
+ urls = this.backgroundURLs().concat(this.imageURLs(), this.scriptURLs(), this.linkURLs(), [this.currentURL()]);
- return jQuery.map(urls, function(url) {
- if (url.match(/^\/\//)) {
- return 'http:' + url;
+ return this.stringify(this.parseURLs(urls));
+ },
+
+ /*
+ * Originally from: http://blogs.sitepointstatic.com/examples/tech/json-serialization/json-serialization.js
+ * Modified slightly by Mario Visic
+ */
+ stringify: function (obj) {
+ var t = typeof (obj);
+ if (t != "object" || obj === null) {
+ /* simple data type */
+ if (t == "string") obj = '"'+obj+'"';
+ return String(obj);
}
- else if (url.match(/^https?/)) {
- return url;
- }
else {
- return window.location.origin + '/' + url;
+ /* recurse array or object */
+ var n, v, json = [], arr = (obj && obj.constructor == Array);
+
+ for (n in obj) {
+ v = obj[n]; t = typeof(v);
+
+ if (t == "string") v = '"'+v+'"';
+ else if (t == "object" && v !== null) v = JSON.stringify(v);
+
+ json.push((arr ? "" : '"' + n + '":') + String(v));
+ }
+
+ return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
}
- });
-}
+ },
-window.backgroundURLs = function() {
- backgroundURLs = new Array();
+ parseURLs: function(urls) {
+ return(urls.map(function(url) {
+ if (url.match(/^\/\//)) {
+ return 'http:' + url;
+ }
+ else if (url.match(/^https?/)) {
+ return url;
+ }
+ else {
+ return window.location.origin + '/' + url;
+ }
+ }));
+ },
- jQuery('*').each(function() {
- if (jQuery(this).css('background').match('url')) {
- backgroundURLs.push(jQuery(this).css('background').match(/url\((.*?)\)/)[1]);
+ backgroundURLs: function() {
+ backgroundURLs = [];
+
+ elements = document.getElementsByTagName('*');
+ length = elements.length;
+
+ for (var i = 0; i < length; i++) {
+ background = window.getComputedStyle(elements[i])['background'];
+
+ if(background.match('url')) {
+ backgroundURLs.push(background.match(/url\((.*?)\)/)[1]);
+ }
}
- });
- return backgroundURLs;
-}
+ return backgroundURLs;
+ },
-window.imageURLs = function() {
- imageURLs = new Array();
+ imageURLs: function() {
+ imageURLs = [];
- jQuery('img').each(function() {
- if (jQuery(this).attr('src')) {
- imageURLs.push(jQuery(this).attr('src'));
+ images = document.getElementsByTagName('img');
+ length = images.length;
+
+ for (var i = 0; i < length; i++) {
+ src = images[i]['src'];
+
+ if (src) {
+ imageURLs.push(src);
+ }
}
- });
+ return imageURLs;
+ },
- return imageURLs;
-}
+ scriptURLs: function() {
+ scriptURLs = [];
-window.scriptURLs = function() {
- scriptURLs = new Array();
+ scripts = document.getElementsByTagName('script');
+ length = scripts.length;
- jQuery('script').each(function() {
- if (jQuery(this).attr('src')) {
- scriptURLs.push(jQuery(this).attr('src'));
+ for (var i = 0; i < length; i++) {
+ src = scripts[i]['src'];
+
+ if (src) {
+ scriptURLs.push(src);
+ }
}
- });
- return scriptURLs;
-}
+ return scriptURLs;
+ },
-window.linkURLs = function() {
- linkURLs = new Array();
+ linkURLs: function() {
+ linkURLs = [];
- jQuery('link').each(function() {
- if (jQuery(this).attr('href')) {
- linkURLs.push(jQuery(this).attr('href'));
+ links = document.getElementsByTagName('link');
+ length = links.length;
+
+ for (var i = 0; i < length; i++) {
+ href = links[i]['href'];
+
+ if (href) {
+ linkURLs.push(src);
+ }
}
- });
- return linkURLs;
-}
+ return linkURLs;
+ },
-window.currentURL = function() {
- return [window.location.href];
+ currentURL: function() {
+ return window.location.href;
+ }
}