diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..310a24c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.project + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a717efe --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014444 Benjamin Leffler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index 8a833dc..022d414 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# jQuery.SwapStyle +# [jQuery.SwapStyle](http://btleffler.github.com/jQuery-SwapStyle/) Simple jQuery plugin that swaps out stylesheets. @@ -14,13 +14,40 @@ Simple jQuery plugin that swaps out stylesheets. * jQuery (obviously) * Two or more stylesheets that you would like to swap out - + ## Usage Using the plugin is very simple. - $.swapstyle( urlOfOriginal, urlOfReplacment ); +```js +$.swapstyle( urlOfOriginal, urlOfReplacment ); +``` + A simple example would be: - $.swapstyle( "styles/one.css", "styles/two.css" ); \ No newline at end of file +```js +$.swapstyle( "styles/one.css", "styles/two.css" ); +``` + + +# LICENSE - MIT +Copyright (c) 2014 Benjamin Leffler + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/jquery.swapstyle.js b/jquery.swapstyle.js index bf964d7..7ecd8c9 100644 --- a/jquery.swapstyle.js +++ b/jquery.swapstyle.js @@ -1,40 +1,38 @@ /** * jQuery.SwapStyle: Swap Stylesheets * Author: Benjamin Leffler - * Date: 09/14/11 + * Date: 03/17/14 */ -( function ( $ ) { +(function ($) { "use strict"; - $.swapstyle = function ( original, replacement ) { - var s, // Sheet index - r, // Rule index - thisSheet, // Cache each sheet as we loop through - thisNode, // Node for link tags - href, // Cache the href - cssRules, // So we can have where the browser keeps import rules - rule; // Cache the rule + $.swapstyle = function (original, replacement) { + var s, // Sheet index + r, // Rule index + thisSheet, // Cache each sheet as we loop through + thisNode, // Node for link tags + href, // Cache the href + cssRules, // So we can have where the browser keeps import rules + rule; // Cache the rule // Loop through all the stylesheets - for ( s = 0; s < document.styleSheets.length; s++ ) { + for (s = 0; s < document.styleSheets.length; s++) { // The current stylesheet - thisSheet = document.styleSheets[ s ]; + thisSheet = document.styleSheets[s]; // If the href property isn't null, we should check the rule. - if ( thisSheet.href !== null && - typeof thisSheet.href !== "undefined" ) { - if ( thisSheet.href.indexOf( original ) !== -1 ) { + if (thisSheet.href !== null && typeof thisSheet.href !== "undefined") { + if (thisSheet.href.indexOf(original) !== -1) { // Modify the link in question thisNode = thisSheet.ownerNode; if (thisSheet.owningElement) { - //IE - thisNode = thisSheet.owningElement; + thisNode = thisSheet.owningElement; //IE } - href = thisNode.href; - thisNode.href = href.replace( original, replacement ); + href = thisNode.href; + thisNode.href = href.replace(original, replacement); // We've already replaced the stylesheet, so we // shouldn't haveto check any of it's rules. @@ -45,48 +43,39 @@ // Figure out where the browser keeps it's css rules cssRules = thisSheet.cssRules; - // IE if (thisSheet.imports) { - cssRules = thisSheet.imports; + cssRules = thisSheet.imports; // IE } // Go through the stylesheet's rules if there are any - if ( cssRules !== null ) { - for ( r = 0; r < cssRules.length; r++ ) { + if (cssRules !== null) { + for (r = 0; r < cssRules.length; r++) { // The current rule - rule = cssRules[ r ]; + rule = cssRules[r]; /* * If the rule has an href, it's an @import! We * should check the href. I tried using 'instanceof,' * but Opera had no idea how to handle that * - if ( rule instanceof CSSImportRule && - rule.href.indexOf(original) != -1 ) { */ + if (rule instanceof CSSImportRule && rule.href.indexOf(original) != -1) { */ - if ( rule.href !== null && - typeof rule.href !== "undefined" ) { - if ( rule.href.indexOf( original ) !== -1 ) { + if (rule.href !== null && typeof rule.href !== "undefined") { + if (rule.href.indexOf(original) !== -1) { // Insert the new rule at the end - if ( thisSheet.insertRule ) { - thisSheet.insertRule( - "@import url(" + replacement + ");", - cssRules.length - ); + if (thisSheet.insertRule) { + thisSheet.insertRule("@import url(" + replacement + ");", cssRules.length); } else { // IE - thisSheet.addImport( - replacement, - cssRules.length - ); + thisSheet.addImport(replacement, cssRules.length); } // Delete the old one to get rid of clutter - if ( thisSheet.deleteRule ) { - thisSheet.deleteRule( r ); + if (thisSheet.deleteRule) { + thisSheet.deleteRule(r); } else { // IE - thisSheet.removeImport( r ); + thisSheet.removeImport(r); } } // IF: rule.href.indexOf( original ) !== -1 } // IF: rule.href !== null && typeof rule.href !== "undefined" @@ -94,4 +83,4 @@ } // IF: typeof cssRules !== "undefined" } // FOR: s = 0; s < document.styleSheets.length; s++ }; -} )( jQuery ); +})(jQuery); diff --git a/jquery.swapstyle.min.js b/jquery.swapstyle.min.js index 539e129..9a3d80f 100644 --- a/jquery.swapstyle.min.js +++ b/jquery.swapstyle.min.js @@ -1,6 +1,7 @@ /** * jQuery.SwapStyle: Swap Stylesheets * Author: Benjamin Leffler - * Date: 09/14/11 + * Date: 03/17/14 */ -(function(a){"use strict";a.swapstyle=function(a,b){var c,d,e,f,g,h,i;for(c=0;c=1.6x <3" + }, + "description": "Simple way to swap out CSS stylesheets using jQuery and the javascript CSS api.", + "keywords": [ + "CSS", + "stylesheet", + "swap", + "theme", + "style" + ], + "homepage": "http://btleffler.github.io/jQuery-SwapStyle/", + "docs": "https://github.com/btleffler/jQuery-SwapStyle/blob/master/README.md", + "demo": "http://btleffler.github.io/jQuery-SwapStyle/", + "bugs": "https://github.com/btleffler/jQuery-SwapStyle/issues" +}