From 2e203023b972ab95d86b7d043dc4a6dc4bc4f330 Mon Sep 17 00:00:00 2001 From: Ankit Ahuja Date: Wed, 8 Jun 2011 23:11:50 +0530 Subject: [PATCH] Ran closure linter on almost the entire source --- stylebot/js/apply-css.js | 14 +- stylebot/js/bookmark.js | 10 +- stylebot/js/chrome.js | 46 +++--- stylebot/js/contextmenu.js | 18 +-- stylebot/js/init.js | 10 +- stylebot/js/installation.js | 82 ++++++---- stylebot/js/libs/colorpicker.js | 219 +++++++++++++------------- stylebot/js/libs/css-utils.js | 2 +- stylebot/js/libs/keycombo.js | 32 ++-- stylebot/js/libs/modalbox.js | 38 ++--- stylebot/js/libs/selectionBox.js | 106 ++++++------- stylebot/js/libs/selectorGenerator.js | 34 ++-- stylebot/js/libs/utils.js | 68 ++++---- stylebot/js/options.js | 22 +-- stylebot/js/page.js | 36 ++--- stylebot/js/style.js | 72 ++++----- stylebot/js/stylebot.js | 16 +- stylebot/js/userstyles-org.js | 42 ++--- stylebot/js/widget.js | 168 ++++++++++---------- 19 files changed, 523 insertions(+), 512 deletions(-) diff --git a/stylebot/js/apply-css.js b/stylebot/js/apply-css.js index 8fe8c851..82a043d4 100644 --- a/stylebot/js/apply-css.js +++ b/stylebot/js/apply-css.js @@ -9,24 +9,24 @@ var stylebotTempRules; var stylebotGlobalRules; // send request to background.html to get stylebot global rules -chrome.extension.sendRequest({ name: "getGlobalRules" }, function(response) { +chrome.extension.sendRequest({ name: 'getGlobalRules' }, function(response) { if (response) { stylebotGlobalRules = response; var css = CSSUtils.crunchCSS(response, true); - if (css != "") + if (css != '') { - CSSUtils.injectCSS(css, "stylebot-global-css"); + CSSUtils.injectCSS(css, 'stylebot-global-css'); } } }); // send request to background.html to get stylebot rules for page -chrome.extension.sendRequest({ name: "getRulesForPage", url: window.location.href }, function(response) { +chrome.extension.sendRequest({ name: 'getRulesForPage', url: window.location.href }, function(response) { stylebotTempUrl = response.url; stylebotTempRules = response.rules; var css = CSSUtils.crunchCSS(response.rules, true); - if (css != "") + if (css != '') { - CSSUtils.injectCSS(css, "stylebot-css"); + CSSUtils.injectCSS(css, 'stylebot-css'); } -}); \ No newline at end of file +}); diff --git a/stylebot/js/bookmark.js b/stylebot/js/bookmark.js index 6ed2663f..b8a778be 100644 --- a/stylebot/js/bookmark.js +++ b/stylebot/js/bookmark.js @@ -11,10 +11,10 @@ function createBookmark(name, url, parentId, callback) { parentId: id, title: name }; - + if (url) properties.url = url; - + chrome.bookmarks.create(properties, callback); } @@ -34,9 +34,9 @@ function loadBookmark(id, title, callback) { chrome.bookmarks.get(id, callback); return; } - + if (title) { - chrome.bookmarks.search("stylebot", function(bookmarks) { + chrome.bookmarks.search('stylebot', function(bookmarks) { callback(bookmarks); }); } @@ -58,4 +58,4 @@ function getRootBookmark(callback) { chrome.bookmarks.getTree(function(bookmarks) { callback(bookmarks[0].children[1]); }); -} \ No newline at end of file +} diff --git a/stylebot/js/chrome.js b/stylebot/js/chrome.js index e0ee1e02..385b700e 100644 --- a/stylebot/js/chrome.js +++ b/stylebot/js/chrome.js @@ -7,75 +7,75 @@ stylebot.chrome = { setIcon: function(value) { if (value) - chrome.extension.sendRequest({ name: "enablePageAction" }, function(){}); + chrome.extension.sendRequest({ name: 'enablePageAction' }, function() {}); else - chrome.extension.sendRequest({ name: "disablePageAction" }, function(){}); + chrome.extension.sendRequest({ name: 'disablePageAction' }, function() {}); }, // send request to background.html to copy text copyToClipboard: function(text) { - chrome.extension.sendRequest({ name: "copyToClipboard", text: text }, function(){}); + chrome.extension.sendRequest({ name: 'copyToClipboard', text: text }, function() {}); }, // save all rules for a page save: function(url, rules, data) { - chrome.extension.sendRequest({ name: "save", rules: rules, url: url , data: data }, function(){}); + chrome.extension.sendRequest({ name: 'save', rules: rules, url: url, data: data }, function() {}); }, doesStyleExist: function(url, callback) { - chrome.extension.sendRequest({ name: "doesStyleExist", url:url }, callback); + chrome.extension.sendRequest({ name: 'doesStyleExist', url: url }, callback); }, install: function(url, rules, id) { - chrome.extension.sendRequest({ name: "install", rules: rules, url: url, id: id }, function(){}); + chrome.extension.sendRequest({ name: 'install', rules: rules, url: url, id: id }, function() {}); }, // transfer all rules for src url to dest url transfer: function(src, dest) { - chrome.extension.sendRequest({name: "transfer", source: src, destination: dest }, function(){}); + chrome.extension.sendRequest({name: 'transfer', source: src, destination: dest }, function() {}); }, // send request to fetch options from datastore fetchOptions: function() { - chrome.extension.sendRequest({ name: "fetchOptions" }, function(response) { + chrome.extension.sendRequest({ name: 'fetchOptions' }, function(response) { initialize(response); }); }, saveAccordionState: function(enabledAccordions) { - chrome.extension.sendRequest({ name: "saveAccordionState", enabledAccordions: enabledAccordions }, function(){}); + chrome.extension.sendRequest({ name: 'saveAccordionState', enabledAccordions: enabledAccordions }, function() {}); }, savePreference: function(name, value) { - chrome.extension.sendRequest({ name: "savePreference", preference: { name: name, value: value } }, function(){}); + chrome.extension.sendRequest({ name: 'savePreference', preference: { name: name, value: value } }, function() {}); }, getPreference: function(name, callback) { - chrome.extension.sendRequest({ name: "getPreference", preferenceName: name }, function(response) { + chrome.extension.sendRequest({ name: 'getPreference', preferenceName: name }, function(response) { callback(response.value); }); }, pushStyles: function() { - chrome.extension.sendRequest({ name: "pushStyles" }, function(){}); + chrome.extension.sendRequest({ name: 'pushStyles' }, function() {}); }, openOptionsPage: function() { - window.open(chrome.extension.getURL("options.html")); + window.open(chrome.extension.getURL('options.html')); } -} +}; // Listen to requests from background.html chrome.extension.onRequest.addListener( function(request, sender, sendResponse) { - if (request.name === "status") { + if (request.name === 'status') { if (window != window.top) return; sendResponse({ status: stylebot.status }); } - else if (request.name === "toggle") + else if (request.name === 'toggle') { if (window != window.top) return; @@ -84,31 +84,31 @@ chrome.extension.onRequest.addListener( sendResponse({ status: stylebot.status }); } - else if (request.name === "setOptions") + else if (request.name === 'setOptions') { stylebot.setOptions(request.options); sendResponse({}); } - else if (request.name === "openWidget") + else if (request.name === 'openWidget') { stylebot.contextmenu.openWidget(); sendResponse({}); } - else if (request.name === "searchSocial") { + else if (request.name === 'searchSocial') { if (!window.top) return; stylebot.contextmenu.searchSocial(); } - else if (request.name === "shareStyleOnSocial") { + else if (request.name === 'shareStyleOnSocial') { if (!window.top) return; stylebot.contextmenu.shareStyleOnSocial(); } - else if (request.name === "toggleStyle") { + else if (request.name === 'toggleStyle') { if (!window.top) return; stylebot.style.toggle(); @@ -116,10 +116,10 @@ chrome.extension.onRequest.addListener( sendResponse({ status: stylebot.style.status }); } - else if (request.name === "styleStatus") { + else if (request.name === 'styleStatus') { if (!window.top) return; sendResponse({ status: stylebot.style.status }); } } -); \ No newline at end of file +); diff --git a/stylebot/js/contextmenu.js b/stylebot/js/contextmenu.js index 8094d62a..060ac97a 100644 --- a/stylebot/js/contextmenu.js +++ b/stylebot/js/contextmenu.js @@ -4,17 +4,17 @@ stylebot.contextmenu = { cache: { el: null }, - + initialize: function() { this.attachListeners(); }, - + attachListeners: function() { $(document.body).bind('contextmenu', function(e) { stylebot.contextmenu.cache.el = e.target; }); }, - + openWidget: function() { if (stylebot.contextmenu.cache.el && stylebot.contextmenu.cache.el.nodeType == 1) { @@ -24,15 +24,15 @@ stylebot.contextmenu = { }, searchSocial: function() { - window.open("http://stylebot.me/search?q=" + document.domain); + window.open('http://stylebot.me/search?q=' + document.domain); }, - + shareStyleOnSocial: function() { // check if the current page has any styles if (stylebot.style.rules) { - + var css = CSSUtils.crunchFormattedCSS(stylebot.style.rules, false); - var url = "http://stylebot.me/post"; + var url = 'http://stylebot.me/post'; // create a form and submit data var temp_form = $('
', { @@ -40,7 +40,7 @@ stylebot.contextmenu = { 'action': url, 'target': '_self' }); - + // site $('', { type: 'hidden', @@ -62,4 +62,4 @@ stylebot.contextmenu = { temp_form.remove(); } } -} \ No newline at end of file +}; diff --git a/stylebot/js/init.js b/stylebot/js/init.js index b1a158b1..6d75e52e 100644 --- a/stylebot/js/init.js +++ b/stylebot/js/init.js @@ -32,12 +32,12 @@ function attachListeners() { } } // Handle Esc key to escape editing mode - else if ( e.keyCode == 27 && stylebot.shouldClose(e.target) ) + else if (e.keyCode == 27 && stylebot.shouldClose(e.target)) { e.target.blur(); stylebot.close(); } - + return true; }, true); } @@ -45,11 +45,11 @@ function attachListeners() { function isInputField(el) { var tagName = el.tagName.toLowerCase(); var inputTypes = ['input', 'textarea', 'div', 'object']; - + if ($.inArray(tagName, inputTypes) != -1 || - el.id === "stylebot" + el.id === 'stylebot' ) return true; else return false; -} \ No newline at end of file +} diff --git a/stylebot/js/installation.js b/stylebot/js/installation.js index b480e5e3..8af3c7ae 100644 --- a/stylebot/js/installation.js +++ b/stylebot/js/installation.js @@ -1,7 +1,7 @@ $(document).ready(function(e) { // let social know stylebot is installed sendAvailabilityMessage(); - + // communication channel between stylebot social and the extension var $install_divs = $('.stylebot_install_div'); @@ -9,15 +9,15 @@ $(document).ready(function(e) { // Bind listener for install event $install_divs.bind('stylebotInstallEvent', function(e) { - console.log("Stylebot: Install event received. Installing style..."); - + console.log('Stylebot: Install event received. Installing style...'); + var $post = $(e.target).closest('.post'); var url = $.trim($post.find('.post_site').text()); // first, let's check if a style already exists for the url stylebot.chrome.doesStyleExist(url, function(response) { - + // if yes, warn the user if (response) { console.log("Style for '" + url + "' already exists."); @@ -26,21 +26,21 @@ $(document).ready(function(e) { customEvent.initEvent('stylebotStyleExistsEvent', true, true); e.target.dispatchEvent(customEvent); } - + // else save the style else saveStyleFromSocial(e); }); }); - - + + // Bind listener for overwrite installation (without checking if style already exists) - + $install_divs.bind('stylebotOverwriteEvent', function(e) { - console.log("Stylebot: Overwrite event received. Installing style..."); - + console.log('Stylebot: Overwrite event received. Installing style...'); + var $post = $(e.target).closest('.post'); - + saveStyleFromSocial(e); }); } @@ -51,7 +51,7 @@ $(document).ready(function(e) { function sendAvailabilityMessage() { // get the first communication DIV in DOM var install_div = $('.stylebot_install_div').get(0); - + // dispatch the message if (install_div) { var customEvent = document.createEvent('Event'); @@ -75,54 +75,66 @@ function saveStyleFromSocial(installationEvent) { // var timestamp = $post.attr('data-timestamp'); // // var id = $post.attr('id').substring(4); - + // @new stuff var channel = installationEvent.target; var $channel = $(channel); var data = $channel.data(); - + var parser = new CSSParser(); - + try { var sheet = parser.parse($channel.text(), false, true); var rules = CSSUtils.getRulesFromParserObject(sheet); // add the meta header - var header = "\ + var header = '\ /**\n\ - Title : " + data.title + "\n"; - + Title : +' + + data.title + '\n'; + if (data.description) { - header += "\ - Description : " + data.description + "\n"; + header += '\ + Description : +' + + data.description + '\n'; } - - header += "\ - URL : http://stylebot.me/styles/" + data.id + "\n\ - Author : " + data.author + "\n\ - Author URL : " + "http://stylebot.me/users/" + data.author + "\n\ -**/\n"; - + + header += '\ + URL : http://stylebot.me/styles/ +' + + data.id + '\n\ + Author : +' + + data.author + '\n\ + Author URL : +' + + 'http://stylebot.me/users/' + data.author + '\n\ +**/\n +' +; + var rulesWithMeta = { 'comment-#0' : { comment: header } }; - + for (selector in rules) rulesWithMeta[selector] = rules[selector]; - - stylebot.chrome.save(data.url, rulesWithMeta, { id: data.id, timestamp: data.timestamp }) + + stylebot.chrome.save(data.url, rulesWithMeta, { id: data.id, timestamp: data.timestamp }); stylebot.chrome.pushStyles(); - + // send back success message var customEvent = document.createEvent('Event'); customEvent.initEvent('stylebotInstallationSuccessfulEvent', true, true); channel.dispatchEvent(customEvent); } - - catch(e) { - console.log("Error parsing css: " + e); + + catch (e) { + console.log('Error parsing css: ' + e); // send back error message var customEvent = document.createEvent('Event'); customEvent.initEvent('stylebotInstallationErrorEvent', true, true); channel.dispatchEvent(customEvent); } -} \ No newline at end of file +} diff --git a/stylebot/js/libs/colorpicker.js b/stylebot/js/libs/colorpicker.js index fd97de4a..add81523 100644 --- a/stylebot/js/libs/colorpicker.js +++ b/stylebot/js/libs/colorpicker.js @@ -5,11 +5,10 @@ * * Dual licensed under the MIT and GPL licenses */ - -(function ($) { - var ColorPicker = function () { - var - ids = {}, + +(function($) { + var ColorPicker = function() { + var ids = {}, inAction, charMin = 65, visible, @@ -21,39 +20,39 @@ \ \ ', - + defaults = { eventName: 'click', - onShow: function () {}, - onBeforeShow: function(){}, - onHide: function () {}, - onChange: function () {}, - onSubmit: function () {}, + onShow: function() {}, + onBeforeShow: function() {}, + onHide: function() {}, + onChange: function() {}, + onSubmit: function() {}, appendToElement: document.body, color: 'ff0000', flat: false }, - - setSelector = function (hsb, cal) { + + setSelector = function(hsb, cal) { $(cal).data('colorpicker').selector.css('backgroundColor', '#' + HSBToHex({h: hsb.h, s: 100, b: 100})); $(cal).data('colorpicker').selectorIndic.css({ - left: parseInt(150 * hsb.s/100, 10), - top: parseInt(150 * (100-hsb.b)/100, 10) + left: parseInt(150 * hsb.s / 100, 10), + top: parseInt(150 * (100 - hsb.b) / 100, 10) }); }, - - setHue = function (hsb, cal) { - $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h/360, 10)); + + setHue = function(hsb, cal) { + $(cal).data('colorpicker').hue.css('top', parseInt(150 - 150 * hsb.h / 360, 10)); }, - - update = function (cal) { + + update = function(cal) { var col = cal.data('colorpicker').color; setSelector(col, cal.get(0)); setHue(col, cal.get(0)); cal.data('colorpicker').onChange.apply(cal, [col, HSBToHex(col), HSBToRGB(col)]); }, - - downHue = function (ev) { + + downHue = function(ev) { var current = { cal: $(this).parent(), y: $(this).offset().top @@ -62,23 +61,23 @@ $(document).bind('mousedown', current, moveHue); $(document).bind('mousemove', current, moveHue); }, - - moveHue = function (ev) { + + moveHue = function(ev) { var cal = ev.data.cal; - var hsb_h = parseInt(360*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.y))))/150, 10); + var hsb_h = parseInt(360 * (150 - Math.max(0, Math.min(150, (ev.pageY - ev.data.y)))) / 150, 10); cal.data('colorpicker').color.h = hsb_h; update(cal); return false; }, - - upHue = function (ev) { + + upHue = function(ev) { $(document).unbind('mouseup', upHue); $(document).unbind('mousedown', moveHue); $(document).unbind('mousemove', moveHue); return false; }, - - downSelector = function (ev) { + + downSelector = function(ev) { var current = { cal: $(this).parent(), pos: $(this).offset() @@ -87,11 +86,11 @@ $(document).bind('mousedown', current, moveSelector); $(document).bind('mousemove', current, moveSelector); }, - - moveSelector = function (ev) { + + moveSelector = function(ev) { var cal = ev.data.cal; - var hsb_s = parseInt(100*(Math.max(0,Math.min(150,(ev.pageX - ev.data.pos.left))))/150, 10); - var hsb_b = parseInt(100*(150 - Math.max(0,Math.min(150,(ev.pageY - ev.data.pos.top))))/150, 10); + var hsb_s = parseInt(100 * (Math.max(0, Math.min(150, (ev.pageX - ev.data.pos.left)))) / 150, 10); + var hsb_b = parseInt(100 * (150 - Math.max(0, Math.min(150, (ev.pageY - ev.data.pos.top)))) / 150, 10); hsb_h = cal.data('colorpicker').color.h; cal.data('colorpicker').color = fixHSB({ h: hsb_h, @@ -101,27 +100,27 @@ update(cal); return false; }, - - upSelector = function (ev) { + + upSelector = function(ev) { $(document).unbind('mouseup', upSelector); $(document).unbind('mousedown', moveSelector); $(document).unbind('mousemove', moveSelector); return false; }, - + toggle = function(ev) { var cal = $('#' + $(this).data('colorpickerId')); - if( cal.css('display') == "none" ) + if (cal.css('display') == 'none') { - show.apply( this ); + show.apply(this); } else { cal.hide(); } }, - - show = function (ev) { + + show = function(ev) { var cal = $('#' + $(this).data('colorpickerId')); cal.data('colorpicker').onBeforeShow.apply(this, [cal.get(0)]); var pos = $(this).offset(); @@ -141,23 +140,23 @@ $(document).bind('mousedown keyup', {cal: cal, el: this}, hide); return false; }, - - hide = function (ev) { + + hide = function(ev) { if (ev.type == 'keyup' && ev.keyCode != 27) return true; - + if (ev.type == 'mousedown' && (isChildOf(ev.data.cal.get(0), ev.target, ev.data.cal.get(0)) || isChildOf(ev.data.el, ev.target, ev.data.el))) { return true; } - + if (ev.data.cal.data('colorpicker').onHide.apply(this, [ev.data.cal.get(0)]) != false) { ev.data.cal.hide(); } - + $(document).unbind('mousedown keyup', hide); }, - + isChildOf = function(parentEl, el, container) { if (parentEl == el) { return true; @@ -165,49 +164,49 @@ if (parentEl.contains) { return parentEl.contains(el); } - if ( parentEl.compareDocumentPosition ) { + if (parentEl.compareDocumentPosition) { return !!(parentEl.compareDocumentPosition(el) & 16); } var prEl = el.parentNode; - while(prEl && prEl != container) { + while (prEl && prEl != container) { if (prEl == parentEl) return true; prEl = prEl.parentNode; } return false; }, - - getViewport = function () { + + getViewport = function() { var m = document.compatMode == 'CSS1Compat'; return { - l : window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft), - t : window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop), - w : $(window).width() || (m ? document.documentElement.clientWidth : document.body.clientWidth), - h : window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight) + l: window.pageXOffset || (m ? document.documentElement.scrollLeft : document.body.scrollLeft), + t: window.pageYOffset || (m ? document.documentElement.scrollTop : document.body.scrollTop), + w: $(window).width() || (m ? document.documentElement.clientWidth : document.body.clientWidth), + h: window.innerHeight || (m ? document.documentElement.clientHeight : document.body.clientHeight) }; }, - - fixHSB = function (hsb) { + + fixHSB = function(hsb) { return { h: Math.min(360, Math.max(0, hsb.h)), s: Math.min(100, Math.max(0, hsb.s)), b: Math.min(100, Math.max(0, hsb.b)) }; }, - - fixRGB = function (rgb) { + + fixRGB = function(rgb) { return { r: Math.min(255, Math.max(0, rgb.r)), g: Math.min(255, Math.max(0, rgb.g)), b: Math.min(255, Math.max(0, rgb.b)) }; }, - - fixHex = function (hex) { + + fixHex = function(hex) { var len = 6 - hex.length; if (len > 0) { var o = []; - for (var i=0; i -1) ? hex.substring(1) : hex), 16); return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)}; }, - - HexToHSB = function (hex) { + + HexToHSB = function(hex) { return RGBToHSB(HexToRGB(hex)); }, - - RGBToHSB = function (rgb) { + + RGBToHSB = function(rgb) { var hsb = { h: 0, s: 0, @@ -236,7 +235,7 @@ var delta = max - min; hsb.b = max; if (max != 0) { - + } hsb.s = max != 0 ? 255 * delta / max : 0; if (hsb.s != 0) { @@ -254,54 +253,54 @@ if (hsb.h < 0) { hsb.h += 360; } - hsb.s *= 100/255; - hsb.b *= 100/255; + hsb.s *= 100 / 255; + hsb.b *= 100 / 255; return hsb; }, - - HSBToRGB = function (hsb) { + + HSBToRGB = function(hsb) { var rgb = {}; var h = Math.round(hsb.h); - var s = Math.round(hsb.s*255/100); - var v = Math.round(hsb.b*255/100); - if(s == 0) { + var s = Math.round(hsb.s * 255 / 100); + var v = Math.round(hsb.b * 255 / 100); + if (s == 0) { rgb.r = rgb.g = rgb.b = v; } else { var t1 = v; - var t2 = (255-s)*v/255; - var t3 = (t1-t2)*(h%60)/60; - if(h==360) h = 0; - if(h<60) {rgb.r=t1; rgb.b=t2; rgb.g=t2+t3} - else if(h<120) {rgb.g=t1; rgb.b=t2; rgb.r=t1-t3} - else if(h<180) {rgb.g=t1; rgb.r=t2; rgb.b=t2+t3} - else if(h<240) {rgb.b=t1; rgb.r=t2; rgb.g=t1-t3} - else if(h<300) {rgb.b=t1; rgb.g=t2; rgb.r=t2+t3} - else if(h<360) {rgb.r=t1; rgb.g=t2; rgb.b=t1-t3} - else {rgb.r=0; rgb.g=0; rgb.b=0} + var t2 = (255 - s) * v / 255; + var t3 = (t1 - t2) * (h % 60) / 60; + if (h == 360) h = 0; + if (h < 60) {rgb.r = t1; rgb.b = t2; rgb.g = t2 + t3} + else if (h < 120) {rgb.g = t1; rgb.b = t2; rgb.r = t1 - t3} + else if (h < 180) {rgb.g = t1; rgb.r = t2; rgb.b = t2 + t3} + else if (h < 240) {rgb.b = t1; rgb.r = t2; rgb.g = t1 - t3} + else if (h < 300) {rgb.b = t1; rgb.g = t2; rgb.r = t2 + t3} + else if (h < 360) {rgb.r = t1; rgb.g = t2; rgb.b = t1 - t3} + else {rgb.r = 0; rgb.g = 0; rgb.b = 0} } - return {r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b)}; + return {r: Math.round(rgb.r), g: Math.round(rgb.g), b: Math.round(rgb.b)}; }, - - RGBToHex = function (rgb) { + + RGBToHex = function(rgb) { var hex = [ rgb.r.toString(16), rgb.g.toString(16), rgb.b.toString(16) ]; - $.each(hex, function (nr, val) { + $.each(hex, function(nr, val) { if (val.length == 1) { hex[nr] = '0' + val; } }); return hex.join(''); }, - - HSBToHex = function (hsb) { + + HSBToHex = function(hsb) { return RGBToHex(HSBToRGB(hsb)); }; return { - init: function (opt) { - opt = $.extend({}, defaults, opt||{}); + init: function(opt) { + opt = $.extend({}, defaults, opt || {}); if (typeof opt.color == 'string') { opt.color = HexToHSB(opt.color); } else if (opt.color.r != undefined && opt.color.g != undefined && opt.color.b != undefined) { @@ -311,7 +310,7 @@ } else { return this; } - return this.each(function () { + return this.each(function() { if (!$(this).data('colorpickerId')) { var options = $.extend({}, opt); var id = 'colorpicker_' + parseInt(Math.random() * 1000); @@ -341,31 +340,31 @@ } }); }, - + togglePicker: function() { - this.each( function() { - if( $(this).data('colorpickerId') ) { - toggle.apply( this ); + this.each(function() { + if ($(this).data('colorpickerId')) { + toggle.apply(this); } - }) + }); }, - + showPicker: function() { - return this.each( function () { - if ( $(this).data('colorpickerId') ) { - show.apply( this ); + return this.each(function() { + if ($(this).data('colorpickerId')) { + show.apply(this); } }); }, - + hidePicker: function() { - return this.each( function () { - if ( $(this).data('colorpickerId') ) { + return this.each(function() { + if ($(this).data('colorpickerId')) { $('#' + $(this).data('colorpickerId')).hide(); } }); }, - + setColor: function(col) { if (typeof col == 'string') { col = HexToHSB(col); @@ -376,7 +375,7 @@ } else { return this; } - return this.each(function(){ + return this.each(function() { if ($(this).data('colorpickerId')) { var cal = $('#' + $(this).data('colorpickerId')); cal.data('colorpicker').color = col; @@ -387,7 +386,7 @@ } }; }(); - + $.fn.extend({ ColorPicker: ColorPicker.init, ColorPickerHide: ColorPicker.hidePicker, @@ -395,4 +394,4 @@ ColorPickerToggle: ColorPicker.togglePicker, ColorPickerSetColor: ColorPicker.setColor }); -})(jQuery) \ No newline at end of file +})(jQuery); diff --git a/stylebot/js/libs/css-utils.js b/stylebot/js/libs/css-utils.js index e4af42d8..e74a65d5 100644 --- a/stylebot/js/libs/css-utils.js +++ b/stylebot/js/libs/css-utils.js @@ -224,7 +224,7 @@ cssFormatter.prototype = { } return css; }, - + // @public formatProperties: function(properties, shouldIndent) { var css = ''; diff --git a/stylebot/js/libs/keycombo.js b/stylebot/js/libs/keycombo.js index ce3daf36..00345731 100644 --- a/stylebot/js/libs/keycombo.js +++ b/stylebot/js/libs/keycombo.js @@ -7,13 +7,13 @@ **/ var KeyCombo = { - + // el: the textfield in which key is pressed // codeEl: Hidden textfield which will store the keydown code init: function(el, codeEl) { el.value = KeyCombo.mapKeyDownCode(codeEl.value); el.addEventListener( - "keydown", + 'keydown', function(e) { KeyCombo.lastValue = el.value; if (e.keyCode == 8) @@ -21,14 +21,14 @@ var KeyCombo = { if (KeyCombo.filterKeyCode(e.keyCode)) { codeEl.value = e.keyCode; - el.value = ""; + el.value = ''; } if (e.keyCode == 27) el.blur(); }, false); }, - + filterKeyCode: function(code) { // filter tab/shift/enter/esc/arrow keys if (code == 27 || code == 16 || code == 37 || code == 38 || code == 39 || code == 40 || code == 13 || code == 9) @@ -38,7 +38,7 @@ var KeyCombo = { return false; return true; }, - + mapKeyDownCode: function(code) { code = Math.floor(code); if ((code >= 65 && code <= 90) || (code >= 48 && code <= 57)) @@ -47,18 +47,18 @@ var KeyCombo = { } switch (code) { - case 186: return ";"; - case 187: return "="; - case 188: return ","; - case 189: return "-"; - case 190: return "."; - case 191: return "/"; - case 192: return "`"; - case 219: return "["; - case 220: return "\\"; - case 221: return "]"; + case 186: return ';'; + case 187: return '='; + case 188: return ','; + case 189: return '-'; + case 190: return '.'; + case 191: return '/'; + case 192: return '`'; + case 219: return '['; + case 220: return '\\'; + case 221: return ']'; case 222: return "'"; } return String.fromCharCode(code).toLowerCase(); } -} \ No newline at end of file +}; diff --git a/stylebot/js/libs/modalbox.js b/stylebot/js/libs/modalbox.js index c959b515..895f8dc6 100644 --- a/stylebot/js/libs/modalbox.js +++ b/stylebot/js/libs/modalbox.js @@ -14,7 +14,7 @@ var ModalBox = function(html, options) { } this.box = $('
', { - id:'stylebot-modal' + id: 'stylebot-modal' }) .append(html); @@ -28,10 +28,10 @@ var ModalBox = function(html, options) { } this.box.css({ - height: this.options.height + "!important", - width: this.options.width + " !important", - top: this.options.top + " !important", - left: this.options.left + " !important" + height: this.options.height + '!important', + width: this.options.width + ' !important', + top: this.options.top + ' !important', + left: this.options.left + ' !important' }); }; @@ -44,13 +44,13 @@ ModalBox.prototype.reset = function(options) { this.box .css({ - height: this.options.height + "!important", - width: this.options.width + " !important", - top: this.options.top + " !important", - left: this.options.left + " !important" + height: this.options.height + '!important', + width: this.options.width + ' !important', + top: this.options.top + ' !important', + left: this.options.left + ' !important' }); } -} +}; ModalBox.prototype.options = { bgOpacity: 0.7, @@ -65,7 +65,7 @@ ModalBox.prototype.options = { onClose: function() {}, onOpen: function() {}, parent: null -} +}; ModalBox.prototype.darkenBg = function(callback) { @@ -85,7 +85,7 @@ ModalBox.prototype.darkenBg = function(callback) { .appendTo(document.body) .fadeIn(this.options.bgFadeSpeed); -} +}; ModalBox.prototype.show = function(content, options) { this.box.fadeIn(this.options.fadeSpeed); @@ -93,7 +93,7 @@ ModalBox.prototype.show = function(content, options) { this.options.onOpen(); var closeBox = function(e) { - if (e.type == "keyup" && + if (e.type == 'keyup' && (e.keyCode != 27 || !e.data.modal.options.closeOnEsc) ) return true; @@ -101,11 +101,11 @@ ModalBox.prototype.show = function(content, options) { var id = e.target.id; var parent = $(e.target).closest('#stylebot-modal'); - if ((e.type == "mousedown" && - id != "stylebot-modal" && + if ((e.type == 'mousedown' && + id != 'stylebot-modal' && parent.length == 0 && - e.data.modal.options.closeOnBgClick ) || - e.type == "keyup" + e.data.modal.options.closeOnBgClick) || + e.type == 'keyup' ) { e.preventDefault(); @@ -117,11 +117,11 @@ ModalBox.prototype.show = function(content, options) { } $(document).bind('keyup mousedown', {modal: this}, closeBox); -} +}; ModalBox.prototype.hide = function() { this.box.fadeOut(this.options.fadeSpeed); if (this.background) this.background.fadeOut(this.options.bgFadeSpeed).remove(); this.options.onClose(); -} \ No newline at end of file +}; diff --git a/stylebot/js/libs/selectionBox.js b/stylebot/js/libs/selectionBox.js index 4bd90e1d..560b014a 100644 --- a/stylebot/js/libs/selectionBox.js +++ b/stylebot/js/libs/selectionBox.js @@ -16,46 +16,46 @@ TODO: Canvas? var SelectionBox = function(edgeSize, className) { this.edgeSize = edgeSize; this.className = className; - + this.edges = {}; this.edges.top = this.createEdge(); this.edges.right = this.createEdge(); this.edges.bottom = this.createEdge(); this.edges.left = this.createEdge(); - + for (var edge in this.edges) - this.edges[edge].appendTo($("#stylebot-container").get(0)); -} + this.edges[edge].appendTo($('#stylebot-container').get(0)); +}; SelectionBox.prototype.createEdge = function() { return $('
', { class: this.className }); -} +}; SelectionBox.prototype.moveEdge = function(edge, t, l) { - this.edges[edge].css('top', t + "px"); - this.edges[edge].css('left', l + "px"); -} + this.edges[edge].css('top', t + 'px'); + this.edges[edge].css('left', l + 'px'); +}; SelectionBox.prototype.resizeEdge = function(edge, h, w) { this.edges[edge].height(h); this.edges[edge].width(w); -} +}; SelectionBox.prototype.hide = function() { for (var edge in this.edges) this.edges[edge].width(0).height(0); -} +}; // Modified version of drawOutline() from Firebug Lite SelectionBox.prototype.highlight = function(el) { - if (!el){ + if (!el) { this.hide(); return; } if (el.nodeType != 1) el = el.parentNode; - + var scrollbarSize = 17; var windowSize = this.getWindowSize(); var scrollSize = this.getWindowScrollSize(); @@ -66,62 +66,62 @@ SelectionBox.prototype.highlight = function(el) { var left = box.left; var height = box.height; var width = box.width; - + var freeHorizontalSpace = scrollPosition.left + windowSize.width - left - width - (scrollSize.height > windowSize.height ? // is *vertical* scrollbar visible scrollbarSize : 0); - + var freeVerticalSpace = scrollPosition.top + windowSize.height - top - height - (scrollSize.width > windowSize.width ? // is *horizontal* scrollbar visible scrollbarSize : 0); - + var numVerticalBorders = freeVerticalSpace > 0 ? 2 : 1; - + // top edge - this.moveEdge("top", top - this.edgeSize, left); - this.resizeEdge("top", this.edgeSize, width); - + this.moveEdge('top', top - this.edgeSize, left); + this.resizeEdge('top', this.edgeSize, width); + // left edge - this.moveEdge("left", top - this.edgeSize, left - this.edgeSize); - this.resizeEdge("left", height + numVerticalBorders * this.edgeSize, this.edgeSize); - + this.moveEdge('left', top - this.edgeSize, left - this.edgeSize); + this.resizeEdge('left', height + numVerticalBorders * this.edgeSize, this.edgeSize); + // bottom edge if (freeVerticalSpace > 0) { - this.moveEdge("bottom", top + height, left); - this.resizeEdge("bottom", this.edgeSize, width); + this.moveEdge('bottom', top + height, left); + this.resizeEdge('bottom', this.edgeSize, width); } else { - this.moveEdge("bottom", -2 * this.edgeSize, -2 * this.edgeSize); - this.resizeEdge("bottom", this.edgeSize, this.edgeSize); + this.moveEdge('bottom', -2 * this.edgeSize, -2 * this.edgeSize); + this.resizeEdge('bottom', this.edgeSize, this.edgeSize); } // right edge if (freeHorizontalSpace > 0) { - this.moveEdge("right", top - this.edgeSize, left + width); - this.resizeEdge("right", height + numVerticalBorders * this.edgeSize, (freeHorizontalSpace < this.edgeSize ? freeHorizontalSpace : this.edgeSize)); + this.moveEdge('right', top - this.edgeSize, left + width); + this.resizeEdge('right', height + numVerticalBorders * this.edgeSize, (freeHorizontalSpace < this.edgeSize ? freeHorizontalSpace : this.edgeSize)); } else { - this.moveEdge("right", -2 * this.edgeSize, -2 * this.edgeSize); - this.resizeEdge("right", this.edgeSize, this.edgeSize); + this.moveEdge('right', -2 * this.edgeSize, -2 * this.edgeSize); + this.resizeEdge('right', this.edgeSize, this.edgeSize); } -} +}; SelectionBox.prototype.destroy = function() { for (var edge in this.edges) this.edges[edge].remove(); -} +}; // Unmodified methods from Firebug Lite SelectionBox.prototype.getElementBox = function(el) { var result = {}; - + if (el.getBoundingClientRect) { var rect = el.getBoundingClientRect(); - + var scroll = this.getWindowScrollPosition(); - + result.top = Math.round(rect.top + scroll.top); result.left = Math.round(rect.left + scroll.left); result.height = Math.round(rect.bottom - rect.top); @@ -130,20 +130,20 @@ SelectionBox.prototype.getElementBox = function(el) else { var position = this.getElementPosition(el); - + result.top = position.top; result.left = position.left; result.height = el.offsetHeight; result.width = el.offsetWidth; } - + return result; -} +}; SelectionBox.prototype.getElementPosition = function(el) { - var left = 0 + var left = 0; var top = 0; - + do { left += el.offsetLeft; @@ -151,13 +151,13 @@ SelectionBox.prototype.getElementPosition = function(el) { } while (el = el.offsetParent); - return {left:left, top:top}; -} + return {left: left, top: top}; +}; SelectionBox.prototype.getWindowSize = function() { var width = 0, height = 0, el; - - if (typeof window.innerWidth == "number") + + if (typeof window.innerWidth == 'number') { width = window.innerWidth; height = window.innerHeight; @@ -172,9 +172,9 @@ SelectionBox.prototype.getWindowSize = function() { width = el.clientWidth; height = el.clientHeight; } - + return {width: width, height: height}; -} +}; SelectionBox.prototype.getWindowScrollSize = function() { var width = 0, height = 0, el; @@ -186,7 +186,7 @@ SelectionBox.prototype.getWindowScrollSize = function() { width = el.scrollWidth; height = el.scrollHeight; } - + // then we need to check if document.body has a bigger scroll size value // because sometimes depending on the browser and the page, the document.body // scroll size returns a smaller (and wrong) measure @@ -196,14 +196,14 @@ SelectionBox.prototype.getWindowScrollSize = function() { width = el.scrollWidth; height = el.scrollHeight; } - + return {width: width, height: height}; -} +}; SelectionBox.prototype.getWindowScrollPosition = function() { var top = 0, left = 0, el; - - if (typeof window.pageYOffset == "number") + + if (typeof window.pageYOffset == 'number') { top = window.pageYOffset; left = window.pageXOffset; @@ -218,6 +218,6 @@ SelectionBox.prototype.getWindowScrollPosition = function() { top = el.scrollTop; left = el.scrollLeft; } - + return {top: top, left: left}; -} \ No newline at end of file +}; diff --git a/stylebot/js/libs/selectorGenerator.js b/stylebot/js/libs/selectorGenerator.js index ca451c59..01eb6085 100644 --- a/stylebot/js/libs/selectorGenerator.js +++ b/stylebot/js/libs/selectorGenerator.js @@ -5,7 +5,7 @@ * Dual licensed under GPL and MIT licenses. **/ -var SelectorGenerator = { +var SelectorGenerator = { generate: function(el, granularityLevel) { if (!el) @@ -25,21 +25,21 @@ var SelectorGenerator = { // inspect an element and return a CSS selector for it. this is the default mode inspect: function(el, level) { - var elClass = el.attr("class"); + var elClass = el.attr('class'); if (elClass != undefined) { elClass = $.trim(elClass.replace('stylebot-selected', '')); if (elClass.length != 0) { - var classes = elClass.split(" "); + var classes = elClass.split(' '); var len = classes.length; var selector = el.prop('tagName'); - selector = selector ? selector.toLowerCase() : ""; + selector = selector ? selector.toLowerCase() : ''; for (var i = 0; i < len; i++) - selector += "." + classes[i]; + selector += '.' + classes[i]; return selector; } @@ -48,16 +48,16 @@ var SelectorGenerator = { var elId = el.attr('id'); if (elId != undefined) { - return "#" + elId; + return '#' + elId; } var elTag = el.prop('tagName'); - elTag = elTag ? elTag.toLowerCase() : ""; + elTag = elTag ? elTag.toLowerCase() : ''; // don't go beyond 2 levels up // if (level < 2) - return this.inspect(el.parent(), level + 1) + " " + elTag; + return this.inspect(el.parent(), level + 1) + ' ' + elTag; else return elTag; }, @@ -66,29 +66,29 @@ var SelectorGenerator = { var elId = el.attr('id'); if (elId != undefined) - return "#" + elId; + return '#' + elId; - var elClass = el.attr("class"); + var elClass = el.attr('class'); if (elClass != undefined) { elClass = $.trim(elClass.replace('stylebot-selected', '')); } else { - elClass = ""; + elClass = ''; } var elTag = el.prop('tagName'); - elTag = elTag ? elTag.toLowerCase : ""; + elTag = elTag ? elTag.toLowerCase : ''; var selector; if (level < 1) { - selector = this.inspectHigh(el.parent(), level + 1) + " " + elTag; + selector = this.inspectHigh(el.parent(), level + 1) + ' ' + elTag; if (elClass.length != 0) { - selector += "." + elClass; + selector += '.' + elClass; } } @@ -97,7 +97,7 @@ var SelectorGenerator = { selector = elTag; if (elClass.length != 0) { - selector += "." + elClass; + selector += '.' + elClass; } } @@ -106,6 +106,6 @@ var SelectorGenerator = { inspectLow: function(el) { var elTag = el.prop('tagName'); - return elTag ? elTag.toLowerCase() : ""; + return elTag ? elTag.toLowerCase() : ''; } -}; \ No newline at end of file +}; diff --git a/stylebot/js/libs/utils.js b/stylebot/js/libs/utils.js index 01c03ce1..30cceb71 100644 --- a/stylebot/js/libs/utils.js +++ b/stylebot/js/libs/utils.js @@ -39,9 +39,9 @@ var Utils = { 'top': 38, 'right': 39, 'bottom': 40, - 'arrowkeys':[ 37, 38, 39, 40 ], - } - for (var i = 0; i < len; i++){ + 'arrowkeys': [37, 38, 39, 40] + }; + for (var i = 0; i < len; i++) { var code = keyCodes[keys[i]]; if (code.length > 1) // it is an array { @@ -64,9 +64,9 @@ var Utils = { /** * Make text editable in place. Replaces text with textarea for editing. * Requires Utils.editElement and Utils.endEditing - * @param {Element} el Element which contains the text - * @param {Function} callback Function to be called when user finishes editing - * @param {Object} options Options for edit in place field + * @param {Element} el Element which contains the text. + * @param {Function} callback Function to be called when user finishes editing. + * @param {Object} options Options for edit in place field. * @return {true} */ makeEditable: function($el, callback, options) { @@ -86,10 +86,10 @@ var Utils = { Utils.editElement($el, options); var onClose = function(e) { - if (e.type === "keydown" && e.keyCode != 13 && e.keyCode != 27) + if (e.type === 'keydown' && e.keyCode != 13 && e.keyCode != 27) return true; - if (e.type === "mousedown" && e.target.className === editFieldClass) + if (e.type === 'mousedown' && e.target.className === editFieldClass) return true; e.preventDefault(); @@ -98,8 +98,8 @@ var Utils = { e.data.callback($el.text()); - $(document).unbind("mousedown", onClose); - $(document).unbind("keydown", onClose); + $(document).unbind('mousedown', onClose); + $(document).unbind('keydown', onClose); } $(document).bind('keydown mousedown', { callback: callback }, onClose); @@ -111,9 +111,9 @@ var Utils = { editElement: function($el, someOptions) { // default options var options = { - editFieldClass : 'editing-field', - selectText : true, - fixedWidth : false + editFieldClass: 'editing-field', + selectText: true, + fixedWidth: false }; if (someOptions) { @@ -150,8 +150,8 @@ var Utils = { html: value }) .css({ - 'line-height' : lineHeight, - 'word-wrap' : 'break-word' + 'line-height' : lineHeight, + 'word-wrap' : 'break-word' }) .width(elWidth); @@ -168,12 +168,12 @@ var Utils = { .width(elWidth) .height(height) .css({ - 'font-family' : fontFamily, - 'font-size' : fontSize, - 'font-weight' : fontWeight, - 'line-height' : lineHeight, - 'overflow-y' : 'hidden', - 'resize' : 'none' + 'font-family' : fontFamily, + 'font-size' : fontSize, + 'font-weight' : fontWeight, + 'line-height' : lineHeight, + 'overflow-y' : 'hidden', + 'resize' : 'none' }); if (options.selectText) { @@ -195,7 +195,7 @@ var Utils = { // var len = value.length; - if (value[len - 1] === "\n") + if (value[len - 1] === '\n') len = len - 1; if (options && options.selectText) @@ -223,7 +223,7 @@ var Utils = { }, selectText: function(el, start, end) { - if (!el || !el.value || el.value === "") + if (!el || !el.value || el.value === '') return false; var len = el.value.length; if (end > len) end = len; @@ -232,7 +232,7 @@ var Utils = { }, selectAllText: function(el) { - if (!el || !el.value || el.value === "") + if (!el || !el.value || el.value === '') return false; var len = el.value.length; el.setSelectionRange(0, len); @@ -240,20 +240,20 @@ var Utils = { }, moveCursorToEnd: function(el) { - if (!el || !el.value || el.value === "") + if (!el || !el.value || el.value === '') return false; var len = el.value.length; el.setSelectionRange(len, len); - if (el.localName == "textarea") { + if (el.localName == 'textarea') { el.scrollTop = el.scrollHeight; } }, HTMLDecode: function(text) { - if (text && typeof(text) != "undefined") + if (text && typeof(text) != 'undefined') { // replace < with < and > with > - return text.replace("<", "<").replace(">", ">"); + return text.replace('<', '<').replace('>', '>'); } }, @@ -263,12 +263,12 @@ var Utils = { for (i in obj) { - if (obj[i] && typeof obj[i] == "object") + if (obj[i] && typeof obj[i] == 'object') { newObj[i] = this.cloneObject(obj[i]); } else - newObj[i] = obj[i] + newObj[i] = obj[i]; } return newObj; @@ -303,13 +303,13 @@ var Utils = { update the editor's width only, and only if it's necessary */ editor.getSession().on('change', function() { - setTimeout( function() { + setTimeout(function() { if (editor.renderer.scrollBar.getWidth() != editor.previousScrollbarWidth) { editor.previousScrollbarWidth = editor.renderer.scrollBar.getWidth(); if (editor.previousScrollbarWidth == scrollbarWidth) { - editor.renderer.scroller.style.width = Math.max(0, editor.renderer.scroller.clientWidth - scrollbarWidth) + "px"; + editor.renderer.scroller.style.width = Math.max(0, editor.renderer.scroller.clientWidth - scrollbarWidth) + 'px'; } else { - editor.renderer.scroller.style.width = Math.max(0, editor.renderer.scroller.clientWidth + scrollbarWidth) + "px"; + editor.renderer.scroller.style.width = Math.max(0, editor.renderer.scroller.clientWidth + scrollbarWidth) + 'px'; } if (editor.renderer.session.getUseWrapMode()) { var availableWidth = editor.renderer.scroller.clientWidth - editor.renderer.$padding * 2; @@ -324,4 +324,4 @@ var Utils = { return editor; } } -} \ No newline at end of file +}; diff --git a/stylebot/js/options.js b/stylebot/js/options.js index ba2dea62..dda34b69 100644 --- a/stylebot/js/options.js +++ b/stylebot/js/options.js @@ -323,7 +323,7 @@ function editGlobalStylesheet(e) { var css = rules ? CSSUtils.crunchFormattedCSS(rules, false) : ''; - var headerHTML = "Edit the Global Stylesheet:"; + var headerHTML = 'Edit the Global Stylesheet:'; var footerHTML = " \ "; @@ -417,7 +417,7 @@ function editStyle(e) { var rules = bg_window.cache.styles.getRules(url); var css = CSSUtils.crunchFormattedCSS(rules, false); - var headerHTML = "Edit the CSS for " + url + ":"; + var headerHTML = 'Edit the CSS for ' + url + ':'; var footerHTML = " \ "; @@ -440,7 +440,7 @@ function addStyle() { setTimeout(function() { cache.modal.box.find('input').focus(); - }, 40) + }, 40); } function enableAllStyles() { @@ -520,7 +520,7 @@ function onAdd() { } else if (url === '*') { - displayErrorMessage('* is used for the global stylesheet. Please enter another URL.') + displayErrorMessage('* is used for the global stylesheet. Please enter another URL.'); return false; } @@ -602,8 +602,8 @@ function displayBackupErrorMessage(msg) { if ($error.length === 0) { $error = $('
', { - id : 'backupError', - class : 'error' + id: 'backupError', + class: 'error' }); cache.backupModal.box.append($error); @@ -618,8 +618,8 @@ function displayErrorMessage(msg) { if ($error.length === 0) { $error = $('
', { - id : 'parserError', - class : 'error' + id: 'parserError', + class: 'error' }); cache.modal.box.append($error); @@ -674,7 +674,7 @@ function export() { else json = ''; - var headerHTML = "Copy and paste the following into a text file: "; + var headerHTML = 'Copy and paste the following into a text file: '; var footerHTML = ""; @@ -690,7 +690,7 @@ function copyToClipboard(text) { // Displays the modal popup for importing styles from JSON string function import() { - var headerHTML = "Paste previously exported styles:
Note: Existing styles for similar URLs will be overwritten." + var headerHTML = "Paste previously exported styles:
Note: Existing styles for similar URLs will be overwritten."; var footerHTML = " \ "; @@ -918,4 +918,4 @@ function resizeEditor(bottomSpace) { .width(modalWidth - 2 + 'px'); cache.modal.editor.resize(); -} \ No newline at end of file +} diff --git a/stylebot/js/page.js b/stylebot/js/page.js index f545cbf5..38ef36c5 100644 --- a/stylebot/js/page.js +++ b/stylebot/js/page.js @@ -97,7 +97,7 @@ table {\n\ \
"; - this.modal = new ModalBox(html, options, function(){}); + this.modal = new ModalBox(html, options, function() {}); this.initializeEditor(); @@ -106,9 +106,9 @@ table {\n\ var $livePreviewCheckbox = $(buttons.get(0)); $livePreviewCheckbox.click(this.toggleLivePreview) - .tipsy({delayIn: 100, gravity:'sw'}); + .tipsy({delayIn: 100, gravity: 'sw'}); - stylebot.chrome.getPreference("stylebot_page_live_preview", function(livePreview) { + stylebot.chrome.getPreference('stylebot_page_live_preview', function(livePreview) { if (livePreview) { $livePreviewCheckbox.prop('checked', true); } @@ -117,7 +117,7 @@ table {\n\ }); $(buttons.get(1)).click(this.copyToClipboard) - .tipsy({delayIn: 100, gravity:'sw'}); + .tipsy({delayIn: 100, gravity: 'sw'}); $(buttons.get(2)).click(this.save); $(buttons.get(3)).click(this.cancel); @@ -132,12 +132,12 @@ table {\n\ var editor = self.cache.editor; var session = editor.getSession(); - var cssMode = require("ace/mode/css").Mode; + var cssMode = require('ace/mode/css').Mode; session.setMode(new cssMode()); session.setUseWrapMode(true); session.on('change', self.contentChanged); - editor.setTheme("ace/theme/dawn"); + editor.setTheme('ace/theme/dawn'); editor.renderer.setShowGutter(false); setTimeout(function() { @@ -153,12 +153,12 @@ table {\n\ closeOnEsc: false, closeOnBgClick: false, bgFadeSpeed: 0, - width: $("#stylebot").width() - self.RIGHT_PADDING + "px", + width: $('#stylebot').width() - self.RIGHT_PADDING + 'px', top: '0%', left: '0', - height: $("#stylebot").height() + "px", + height: $('#stylebot').height() + 'px', bgOpacity: 0, - parent: $("#stylebot"), + parent: $('#stylebot'), onOpen: function() { stylebot.page.resize(); @@ -193,10 +193,10 @@ table {\n\ else { self.modal.reset({ - width: $("#stylebot").width() - self.RIGHT_PADDING + "px", + width: $('#stylebot').width() - self.RIGHT_PADDING + 'px', top: '0%', left: '0', - height: $("#stylebot").height() + "px" + height: $('#stylebot').height() + 'px' }); } @@ -232,13 +232,13 @@ table {\n\ stylebot.page.contentChanged(); } - stylebot.chrome.savePreference("stylebot_page_live_preview", true); + stylebot.chrome.savePreference('stylebot_page_live_preview', true); }, contentChanged: function() { var self = stylebot.page; - if (!self.cache.livePreview){ + if (!self.cache.livePreview) { return; } @@ -301,10 +301,10 @@ table {\n\ var self = stylebot.page; self.modal.reset({ - width: $("#stylebot").width() - self.RIGHT_PADDING + "px", + width: $('#stylebot').width() - self.RIGHT_PADDING + 'px', top: '0%', left: '0', - height: $("#stylebot").height() + "px" + height: $('#stylebot').height() + 'px' }); self.resize(); @@ -314,7 +314,7 @@ table {\n\ if (!this.cache.marker) { var Range = require('ace/range').Range; var range = new Range(error.currentLine - 1, 0, error.currentLine, 0); - this.cache.marker = this.cache.editor.getSession().addMarker(range, "stylebot_warning", "line"); + this.cache.marker = this.cache.editor.getSession().addMarker(range, 'stylebot_warning', 'line'); } if (setCursor) { @@ -331,7 +331,7 @@ table {\n\ }, resize: function() { - $("#stylebot-page-editor").css('height', $("#stylebot").height() - this.BOTTOM_EDITOR_PADDING + "px"); + $('#stylebot-page-editor').css('height', $('#stylebot').height() - this.BOTTOM_EDITOR_PADDING + 'px'); this.cache.editor.resize(); } -} \ No newline at end of file +}; diff --git a/stylebot/js/style.js b/stylebot/js/style.js index ba87667a..059b064b 100644 --- a/stylebot/js/style.js +++ b/stylebot/js/style.js @@ -15,7 +15,7 @@ stylebot.style = { } */ rules: {}, - + global: {}, timer: null, @@ -45,7 +45,7 @@ stylebot.style = { } // if domain is empty, return url - else if (!this.cache.url || this.cache.url == "") { + else if (!this.cache.url || this.cache.url == '') { this.cache.url = location.href; } @@ -54,7 +54,7 @@ stylebot.style = { this.rules = stylebotTempRules; delete stylebotTempRules; } - + if (stylebotGlobalRules) { this.global = stylebotGlobalRules; @@ -68,10 +68,10 @@ stylebot.style = { { this.cache.selector = selector; try { - this.cache.elements = $(selector + ":not(#stylebot, #stylebot *)"); + this.cache.elements = $(selector + ':not(#stylebot, #stylebot *)'); } - catch(e) { + catch (e) { this.cache.elements = null; } } @@ -80,13 +80,13 @@ stylebot.style = { // applies property-value pair to currently selected elements as inline css, updates cache and saves the rule // called by basic mode apply: function(property, value) { - if (!this.cache.selector || this.cache.selector == "") + if (!this.cache.selector || this.cache.selector == '') return true; this.savePropertyToCache(this.cache.selector, property, value); this.save(); setTimeout(function() { if (stylebot.style.cache.elements && stylebot.style.cache.elements.length != 0) { - stylebot.style.updateInlineCSS(stylebot.style.cache.elements, stylebot.style.getInlineCSS( stylebot.style.cache.selector)); + stylebot.style.updateInlineCSS(stylebot.style.cache.elements, stylebot.style.getInlineCSS(stylebot.style.cache.selector)); } // if no elements, update the stylesheet else { @@ -160,10 +160,10 @@ stylebot.style = { applyPageCSS: function(css, save) { if (save === undefined) save = true; - + var parsedRules = {}; - - if (css != "") + + if (css != '') { if (!this.parser) this.parser = new CSSParser(); @@ -173,23 +173,23 @@ stylebot.style = { parsedRules = CSSUtils.getRulesFromParserObject(sheet); } - catch(e) { + catch (e) { // } } - + if (parsedRules['error']) { return parsedRules['error']; } - + this.clearInlineCSS(this.cache.elements); this.updateStyleElement(parsedRules); - + if (save) { this.rules = parsedRules; this.save(); } - + return true; }, @@ -201,12 +201,12 @@ stylebot.style = { // empty rule for selector delete this.rules[selector]; - if (css != "") { + if (css != '') { if (!this.parser) this.parser = new CSSParser(); - var sheet = this.parser.parse(selector + "{" + css + "}", false, true); + var sheet = this.parser.parse(selector + '{' + css + '}', false, true); var generatedRule = CSSUtils.getRuleFromParserObject(sheet); // save rule to cache @@ -264,16 +264,16 @@ stylebot.style = { if (rule != undefined) { - var css = ""; + var css = ''; for (var property in rule) { - if(property.indexOf("comment") != -1) continue; + if (property.indexOf('comment') != -1) continue; css += CSSUtils.crunchCSSForDeclaration(property, rule[property], true); } return css; } - return ""; + return ''; }, // apply inline CSS to element(s) @@ -285,10 +285,10 @@ stylebot.style = { var $this = $(this); var existingCSS = $this.attr('style'); - existingCSS = existingCSS ? $.trim(existingCSS) : ""; + existingCSS = existingCSS ? $.trim(existingCSS) : ''; - var existingCustomCSS = $this.data("stylebotCSS"); - existingCustomCSS = existingCustomCSS ? $.trim(existingCustomCSS) : ""; + var existingCustomCSS = $this.data('stylebotCSS'); + existingCustomCSS = existingCustomCSS ? $.trim(existingCustomCSS) : ''; var newCSS; @@ -298,8 +298,8 @@ stylebot.style = { // if there is any existing inline CSS, append stylebot CSS to it if (existingCSS != undefined) { - if (existingCSS.length != 0 && existingCSS[existingCSS.length - 1] != ";") - newCSS = existingCSS + ";" + newCustomCSS; + if (existingCSS.length != 0 && existingCSS[existingCSS.length - 1] != ';') + newCSS = existingCSS + ';' + newCustomCSS; else newCSS = existingCSS + newCustomCSS; } @@ -318,7 +318,7 @@ stylebot.style = { $this.attr('style', newCSS); // update stylebot css data associated with element - $this.data("stylebotCSS", newCustomCSS); + $this.data('stylebotCSS', newCustomCSS); }); // update selection box @@ -336,7 +336,7 @@ stylebot.style = { var $this = $(this); var existingCSS = $this.attr('style'); - var existingCustomCSS = $this.data("stylebotCSS"); + var existingCustomCSS = $this.data('stylebotCSS'); if (existingCustomCSS != undefined && existingCSS != undefined) { @@ -344,7 +344,7 @@ stylebot.style = { $this.attr('style', newCSS); // clear stylebot css data associated with element - $this.data("stylebotCSS", null); + $this.data('stylebotCSS', null); } }); }, @@ -377,15 +377,15 @@ stylebot.style = { // updateStyleElement: function(rules) { if (!this.cache.styleEl) - this.cache.styleEl = $("#stylebot-css"); + this.cache.styleEl = $('#stylebot-css'); if (this.cache.styleEl.length != 0) { this.cache.styleEl.html(CSSUtils.crunchCSS(rules, true)); } else { - CSSUtils.injectCSS(CSSUtils.crunchCSS( rules, true ), "stylebot-css"); - this.cache.styleEl = $("#stylebot-css"); + CSSUtils.injectCSS(CSSUtils.crunchCSS(rules, true), 'stylebot-css'); + this.cache.styleEl = $('#stylebot-css'); } }, @@ -499,17 +499,17 @@ stylebot.style = { disable: function() { this.status = false; - $("#stylebot-css").html(''); - $("#stylebot-global-css").html(''); + $('#stylebot-css').html(''); + $('#stylebot-global-css').html(''); }, enable: function() { if (this.status) return; this.status = true; - $("#stylebot-css").html(CSSUtils.crunchCSS(this.rules, true)); + $('#stylebot-css').html(CSSUtils.crunchCSS(this.rules, true)); if (this.global) - $("#stylebot-global-css").html(CSSUtils.crunchCSS(this.global, true)); + $('#stylebot-global-css').html(CSSUtils.crunchCSS(this.global, true)); }, toggle: function() { @@ -523,4 +523,4 @@ stylebot.style = { else this.enable(); } -} \ No newline at end of file +}; diff --git a/stylebot/js/stylebot.js b/stylebot/js/stylebot.js index 711530dd..4bb684fa 100644 --- a/stylebot/js/stylebot.js +++ b/stylebot/js/stylebot.js @@ -109,7 +109,7 @@ var stylebot = { stylebot.highlight(el); } - catch(e) { + catch (e) { stylebot.selectedElement = null; } } @@ -158,7 +158,7 @@ var stylebot = { }, createSelectionBox: function() { - stylebot.selectionBox = new SelectionBox(2, "stylebot-selection"); + stylebot.selectionBox = new SelectionBox(2, 'stylebot-selection'); }, destroySelectionBox: function() { @@ -189,7 +189,7 @@ var stylebot = { onMouseMove: function(e) { // for dropdown - if (e.target.className == "stylebot-dropdown-li") { + if (e.target.className == 'stylebot-dropdown-li') { var $el = $(e.target.innerText).get(0); if ($el != stylebot.hoveredElement) { stylebot.highlight($el); @@ -200,7 +200,7 @@ var stylebot = { if (!stylebot.shouldSelect(e.target)) return true; - if(stylebot.belongsToStylebot(e.target)) { + if (stylebot.belongsToStylebot(e.target)) { stylebot.unhighlight(); return true; } @@ -234,7 +234,7 @@ var stylebot = { var $el = $(el); var parent = $el.closest('#stylebot, .stylebot_colorpicker, #stylebot-modal'); var id = $el.attr('id'); - if (parent.length != 0 || (id && id.indexOf("stylebot") != -1)) + if (parent.length != 0 || (id && id.indexOf('stylebot') != -1)) return true; return false; }, @@ -244,7 +244,7 @@ var stylebot = { stylebot.widget.basic.isColorPickerVisible || stylebot.isKeyboardHelpVisible || stylebot.page.isVisible || - $("#stylebot-dropdown").length != 0 || + $('#stylebot-dropdown').length != 0 || el.tagName === 'SELECT') { return false; @@ -253,7 +253,7 @@ var stylebot = { }, shouldSelect: function(el) { - if (el.className === "stylebot-selection" + if (el.className === 'stylebot-selection' || stylebot.widget.isBeingDragged || stylebot.page.isVisible || stylebot.isKeyboardHelpVisible @@ -264,4 +264,4 @@ var stylebot = { } return true; } -} \ No newline at end of file +}; diff --git a/stylebot/js/userstyles-org.js b/stylebot/js/userstyles-org.js index 6968e937..c8944658 100644 --- a/stylebot/js/userstyles-org.js +++ b/stylebot/js/userstyles-org.js @@ -5,24 +5,24 @@ window.addEventListener('load', function() { function addInstallLink() { // link var a = document.createElement('a'); - a.innerHTML = "Click to add to Stylebot"; - a.className = "stylebot-link"; - a.href = "#"; - a.style.color = "#fbfbfb"; - a.style.fontSize = "18px"; - a.style.display = "block"; - a.style.marginTop = "20px"; + a.innerHTML = 'Click to add to Stylebot'; + a.className = 'stylebot-link'; + a.href = '#'; + a.style.color = '#fbfbfb'; + a.style.fontSize = '18px'; + a.style.display = 'block'; + a.style.marginTop = '20px'; a.addEventListener('click', install, false); - + // description var desc = document.createElement('div'); - desc.style.color = "#eee"; - desc.style.fontSize = "12px"; - desc.style.fontStyle = "italic"; + desc.style.color = '#eee'; + desc.style.fontSize = '12px'; + desc.style.fontStyle = 'italic'; desc.innerHTML = "( very experimental! if it doesn't work, you may need to copy code manually )"; - - document.getElementById("install").appendChild(a); - document.getElementById("install").appendChild(desc); + + document.getElementById('install').appendChild(a); + document.getElementById('install').appendChild(desc); } function install() { @@ -30,8 +30,8 @@ function install() { if (confirm("Add '" + name + "' to Stylebot ? \n\nIt will replace any existing stylebot CSS for the affected URLs.")) { var xhr = new XMLHttpRequest(); - var url = document.querySelector("link[rel='stylish-code-chrome']").getAttribute("href"); - xhr.open("GET", url, true); + var url = document.querySelector("link[rel='stylish-code-chrome']").getAttribute('href'); + xhr.open('GET', url, true); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { save(xhr.responseText); @@ -44,7 +44,7 @@ function install() { function save(response) { // console.log(response); var json = JSON.parse(response); - + var saveCodeBlock = function(block) { var rules = CSSUtils.parseCSS(block.code); var len = block.domains.length; @@ -55,14 +55,14 @@ function save(response) { locations = block.urls; } for (var i = 0; i < len; i++) { - chrome.extension.sendRequest({name: "save", url: locations[i], rules: rules}, function(response){ + chrome.extension.sendRequest({name: 'save', url: locations[i], rules: rules}, function(response) { }); } } - + if (json.code) saveCodeBlock(json); - + else { var len = json.sections.length; for (var i = 0; i < len; i++) { @@ -72,4 +72,4 @@ function save(response) { } } } -} \ No newline at end of file +} diff --git a/stylebot/js/widget.js b/stylebot/js/widget.js index e563c5a5..76faf160 100644 --- a/stylebot/js/widget.js +++ b/stylebot/js/widget.js @@ -38,7 +38,7 @@ stylebot.widget = { id: 'stylebot-select-icon' }) - .tipsy({delayIn: 1500, gravity:'nw'}) + .tipsy({delayIn: 1500, gravity: 'nw'}) .click(function(e) { stylebot.toggleSelection(); @@ -50,13 +50,13 @@ stylebot.widget = { html: 'custom styles', title: 'Click to edit the CSS selector' }) - .tipsy({ delayIn: 500, gravity:'n' }); + .tipsy({ delayIn: 500, gravity: 'n' }); // Selector dropdown self.dropDown = $('
', { id: 'stylebot-dropdown-button', class: 'stylebot-header-button', - title: "View previously edited CSS selectors" + title: 'View previously edited CSS selectors' }) .tipsy({ delayIn: 1500, gravity: 'ne' }) .mouseup(self.showSelectorDropdown); @@ -73,7 +73,7 @@ stylebot.widget = { class: 'stylebot-editable-text', title: 'Click to edit the URL for the style' }) - .tipsy({delayIn: 1500, gravity:'n', html: true}); + .tipsy({delayIn: 1500, gravity: 'n', html: true}); var urlContainer = $('
', { id: 'stylebot-header-url' @@ -132,9 +132,9 @@ stylebot.widget = { var arrowButton = $('
', { id: 'stylebot-arrow-button', class: 'stylebot-arrow-left stylebot-header-button', - title: "Move stylebot to the left" + title: 'Move stylebot to the left' }) - .data('position', "Right") + .data('position', 'Right') .tipsy({ delayIn: 1500, gravity: 'ne' }) .appendTo(self.cache.box) .mouseup(self.togglePosition); @@ -170,7 +170,7 @@ stylebot.widget = { }); // Basic and Advanced mode buttons - WidgetUI.createOption(WidgetUI.createButtonSet(['Basic', 'Advanced'], "stylebot-mode", 0, self.toggleMode)) + WidgetUI.createOption(WidgetUI.createButtonSet(['Basic', 'Advanced'], 'stylebot-mode', 0, self.toggleMode)) .appendTo(optionsContainer); var btContainer = $('
', { @@ -178,31 +178,31 @@ stylebot.widget = { }); // Edit CSS button - WidgetUI.createButton("Edit CSS") + WidgetUI.createButton('Edit CSS') .attr('title', 'Edit entire page\'s CSS') - .tipsy({ delayIn: 800, gravity:'sw', html: true }) + .tipsy({ delayIn: 800, gravity: 'sw', html: true }) .appendTo(btContainer) .click(self.editCSS); // Undo button - self.cache.undoBt = WidgetUI.createButton("Undo") - .attr('title', "Undo your last action") + self.cache.undoBt = WidgetUI.createButton('Undo') + .attr('title', 'Undo your last action') .prop('disabled', true) - .tipsy({ delayIn: 800, gravity:'s', html: true }) + .tipsy({ delayIn: 800, gravity: 's', html: true }) .appendTo(btContainer) .click(function(e) { stylebot.style.undo(); }); // Reset button - WidgetUI.createButton("Reset") - .attr('title', "Reset custom CSS for the selected elements") - .tipsy({ delayIn: 800, gravity:'s', html: true }) + WidgetUI.createButton('Reset') + .attr('title', 'Reset custom CSS for the selected elements') + .tipsy({ delayIn: 800, gravity: 's', html: true }) .appendTo(btContainer) .click(self.resetCSS); // Reset Page button - WidgetUI.createButton("Reset Page") - .attr('title', "Reset custom CSS for the entire page") - .tipsy({ delayIn: 500, gravity:'se', html: true }) + WidgetUI.createButton('Reset Page') + .attr('title', 'Reset custom CSS for the entire page') + .tipsy({ delayIn: 500, gravity: 'se', html: true }) .appendTo(btContainer) .click(self.resetAllCSS); @@ -216,7 +216,7 @@ stylebot.widget = { self.basic.initAccordions(); // By default, place the widget on the right of the screen - self.setPosition("Right"); + self.setPosition('Right'); }, // Attach listeners for TAB keypresses and window resize @@ -224,7 +224,7 @@ stylebot.widget = { var lastBt = $('#stylebot-main-buttons').find('button').last(); // Shift + TAB on first accordion sets focus to last button - $(this.basic.cache.accordionHeaders[0] ).bind('keydown', {lastBt: lastBt}, function(e) { + $(this.basic.cache.accordionHeaders[0]).bind('keydown', {lastBt: lastBt}, function(e) { if (e.keyCode == 9 && e.shiftKey) { e.stopImmediatePropagation(); @@ -258,7 +258,7 @@ stylebot.widget = { stylebot.widget.setPosition(stylebot.options.position); stylebot.widget.updateHeight(); - if(stylebot.selectionBox) + if (stylebot.selectionBox) stylebot.selectionBox.highlight(stylebot.selectedElement); }, @@ -284,8 +284,8 @@ stylebot.widget = { this.setMode(); this.cache.box.show(); - if (stylebot.options.mode === "Edit CSS") { - stylebot.options.mode = "Basic"; + if (stylebot.options.mode === 'Edit CSS') { + stylebot.options.mode = 'Basic'; this.editCSS(); } }, @@ -305,7 +305,7 @@ stylebot.widget = { // Disable UI of widget disable: function() { - this.setSelector("Select an element"); + this.setSelector('Select an element'); this.basic.disable(); this.advanced.disable(); }, @@ -313,9 +313,9 @@ stylebot.widget = { // Update widget position setPosition: function(where) { var left; - if (where === "Left") + if (where === 'Left') left = 0; - else if (where === "Right") + else if (where === 'Right') left = $(window).width() - this.defaults.width - 2; // some padding this.cache.box.css('left', left); @@ -337,7 +337,7 @@ stylebot.widget = { var newHeight = window.innerHeight - (optionsHeight + headerHeight); - if (stylebot.options.mode === "Advanced") + if (stylebot.options.mode === 'Advanced') self.advanced.resize(newHeight); else self.basic.resize(newHeight); @@ -349,7 +349,7 @@ stylebot.widget = { ui.deselectButton($('.stylebot-mode')); - if (stylebot.options.mode === "Advanced") + if (stylebot.options.mode === 'Advanced') { ui.selectButton($('.stylebot-mode:contains(Advanced)')); stylebot.widget.basic.hide(); @@ -370,7 +370,7 @@ stylebot.widget = { // Reset the UI of the widget reset: function() { - if (stylebot.options.mode === "Advanced") + if (stylebot.options.mode === 'Advanced') stylebot.widget.advanced.reset(); else stylebot.widget.basic.reset(); @@ -397,7 +397,7 @@ stylebot.widget = { // @param Event e The event object for when the left/right arrow button is clicked // togglePosition: function(e) { - var $el = $("#stylebot-arrow-button"); + var $el = $('#stylebot-arrow-button'); var pos; if (e) @@ -405,21 +405,21 @@ stylebot.widget = { else pos = stylebot.options.position; - if (pos === "Left") + if (pos === 'Left') { - pos = "Right"; + pos = 'Right'; - $el.removeClass("stylebot-arrow-right") - .addClass("stylebot-arrow-left") - .attr('title', "Move stylebot to the left"); + $el.removeClass('stylebot-arrow-right') + .addClass('stylebot-arrow-left') + .attr('title', 'Move stylebot to the left'); } else { - pos = "Left"; + pos = 'Left'; - $el.removeClass("stylebot-arrow-left") - .addClass("stylebot-arrow-right") - .attr('title', "Move stylebot to the right"); + $el.removeClass('stylebot-arrow-left') + .addClass('stylebot-arrow-right') + .attr('title', 'Move stylebot to the right'); } $el.data('position', pos); @@ -433,10 +433,10 @@ stylebot.widget = { if (e) stylebot.options.mode = $(e.target).html(); - else if (stylebot.options.mode === "Advanced") - stylebot.options.mode = "Basic"; + else if (stylebot.options.mode === 'Advanced') + stylebot.options.mode = 'Basic'; else - stylebot.options.mode = "Advanced"; + stylebot.options.mode = 'Advanced'; stylebot.widget.updateHeight(); stylebot.widget.setMode(); @@ -444,32 +444,32 @@ stylebot.widget = { // Initialize and toggle the visibility of the selectors dropdown showSelectorDropdown: function() { - var dropdown = $("#stylebot-dropdown"); + var dropdown = $('#stylebot-dropdown'); if (dropdown.length != 0) { dropdown.remove(); return true; } var parent = stylebot.widget.cache.headerSelector.parent(); - var parentHeight = parent.height() + 10 + var parentHeight = parent.height() + 10; var height = $(window).height() - 50 - parentHeight; - dropdown = $("
", { - id: "stylebot-dropdown" + dropdown = $('
', { + id: 'stylebot-dropdown' }) .css({ top: parentHeight, 'max-height': height - }) + }); var onClickElsewhere = function(e) { var $target = $(e.target); - var id = "stylebot-dropdown"; - if ((e.target.id.indexOf(id) === -1 && $target.parent().attr('id') != id && e.type === "mousedown") + var id = 'stylebot-dropdown'; + if ((e.target.id.indexOf(id) === -1 && $target.parent().attr('id') != id && e.type === 'mousedown') || e.keyCode == 27) { - $("#stylebot-dropdown").remove(); + $('#stylebot-dropdown').remove(); stylebot.unhighlight(); stylebot.select(null, stylebot.style.cache.selector); $(document).unbind('mousedown keydown', onClickElsewhere); @@ -480,12 +480,12 @@ stylebot.widget = { var any = false; for (var selector in stylebot.style.rules) { - if(stylebot.style.rules[selector]["comment"]) continue; - if(stylebot.style.rules[selector]["__isAnimation"]) continue; + if (stylebot.style.rules[selector]['comment']) continue; + if (stylebot.style.rules[selector]['__isAnimation']) continue; any = true; - var li = $("
  • ", { + var li = $('
  • ', { class: 'stylebot-dropdown-li', tabIndex: 0, html: selector @@ -512,13 +512,13 @@ stylebot.widget = { stylebot.widget.updateHeight(); stylebot.select(null, Utils.HTMLDecode(value)); $(document).unbind('mousedown keydown', onClickElsewhere); - $("#stylebot-dropdown").remove(); + $('#stylebot-dropdown').remove(); }) .appendTo(dropdown); } if (!any) - $("
  • ", { html: "No CSS selectors edited" } ).appendTo(dropdown); + $('
  • ', { html: 'No CSS selectors edited' }).appendTo(dropdown); dropdown.appendTo(parent); $(document).bind('mousedown keydown', onClickElsewhere); @@ -526,34 +526,34 @@ stylebot.widget = { // Select the next selector in the selectors dropdown list. Called when down arrow key is pressed selectNextDropdownOption: function() { - var $li = $(".stylebot-dropdown-li"); + var $li = $('.stylebot-dropdown-li'); if ($li.length === 0) return; - var $current = $(".stylebot-dropdown-li-selected"); + var $current = $('.stylebot-dropdown-li-selected'); if ($current.length === 0) { - $li = $( $li.get(0) ); - stylebot.highlight( $( $li.text() ).get(0) ); - $li.addClass("stylebot-dropdown-li-selected").focus(); + $li = $($li.get(0)); + stylebot.highlight($($li.text()).get(0)); + $li.addClass('stylebot-dropdown-li-selected').focus(); return; } else { - $current = $( $current.get(0) ); - $current.removeClass("stylebot-dropdown-li-selected"); - var $next = $( $current.next().get(0) ); + $current = $($current.get(0)); + $current.removeClass('stylebot-dropdown-li-selected'); + var $next = $($current.next().get(0)); if ($next.length != 0) { - stylebot.highlight( $( $next.text() ).get(0) ); - $next.addClass("stylebot-dropdown-li-selected").focus(); + stylebot.highlight($($next.text()).get(0)); + $next.addClass('stylebot-dropdown-li-selected').focus(); } else { - $li = $( $li.get(0) ); - stylebot.highlight( $( $li.text() ).get(0) ); - $li.addClass("stylebot-dropdown-li-selected").focus(); + $li = $($li.get(0)); + stylebot.highlight($($li.text()).get(0)); + $li.addClass('stylebot-dropdown-li-selected').focus(); } return; } @@ -561,35 +561,35 @@ stylebot.widget = { // Select the previous selector in the selectors dropdown list. Called when up arrow key is pressed selectPreviousDropdownOption: function() { - var $li = $(".stylebot-dropdown-li"); + var $li = $('.stylebot-dropdown-li'); if ($li.length === 0) return; - var $current = $(".stylebot-dropdown-li-selected"); + var $current = $('.stylebot-dropdown-li-selected'); if ($current.length === 0) { - $li = $( $li[ $li.length - 1 ] ); - stylebot.highlight( $( $li.text() ).get(0) ); - $li.addClass("stylebot-dropdown-li-selected").focus(); + $li = $($li[$li.length - 1]); + stylebot.highlight($($li.text()).get(0)); + $li.addClass('stylebot-dropdown-li-selected').focus(); return; } else { - $current = $( $current.get(0) ); - $current.removeClass("stylebot-dropdown-li-selected"); - var $prev = $( $current.prev().get(0) ); + $current = $($current.get(0)); + $current.removeClass('stylebot-dropdown-li-selected'); + var $prev = $($current.prev().get(0)); if ($prev.length != 0) { - stylebot.highlight( $( $prev.text() ).get(0) ); - $prev.addClass("stylebot-dropdown-li-selected").focus(); + stylebot.highlight($($prev.text()).get(0)); + $prev.addClass('stylebot-dropdown-li-selected').focus(); } else { - $li = $( $li[ $li.length - 1 ] ); - stylebot.highlight( $( $li.text() ).get(0) ); - $li.addClass("stylebot-dropdown-li-selected").focus(); + $li = $($li[$li.length - 1]); + stylebot.highlight($($li.text()).get(0)); + $li.addClass('stylebot-dropdown-li-selected').focus(); } return; @@ -608,8 +608,8 @@ stylebot.widget = { setSelector: function(value) { this.cache.headerSelector.html(value); - if (value === "Select an element") - value = "Click to edit the CSS Selector" + if (value === 'Select an element') + value = 'Click to edit the CSS Selector'; this.cache.headerSelector.attr('title', value); } -} +};