Permalink
Browse files

Code cleanup

  • Loading branch information...
1 parent 3cda90c commit 6b46d47be1c2aa35720a2b1eed4058fc660dc80c @premasagar committed Aug 27, 2012
Showing with 7 additions and 47 deletions.
  1. +5 −6 demo/index.html
  2. +2 −41 important.js
View
@@ -1,16 +1,16 @@
<!DOCTYPE html>
-<html lang=en>
+<html lang="en">
<head>
- <meta charset=utf-8 />
+ <meta charset="utf-8">
<title>!importantjs</title>
<!-- <script src="../../mishmash/console/console.js"></script> -->
<!-- <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js></script> -->
- <script src="jquery.js"</script>
+ <script src="jquery.js"></script>
<script src="../important.js"></script>
<!-- document-level !important rules for #elem -->
-<style id=style-elem>
+<style id="style-elem">
#elem {
background-color: darkblue !important;
color: yellow !important;
@@ -492,8 +492,7 @@
elem: elem,
styleElem: styleElem,
computed: window.getComputedStyle(elem, null),
- report: report,
- _: (console && console.log) ? console.log : function(){}
+ report: report
}
);
}(jQuery));
View
@@ -1,5 +1,3 @@
-'use strict';
-
/*!
* !important
* github.com/premasagar/important/
@@ -29,6 +27,7 @@
*/
(function($){
+ 'use strict';
// create CSS text from property & value, optionally inserting it into the supplied CSS rule
// e.g. declaration('width', '50%', 'margin:2em; width:auto;');
@@ -184,7 +183,6 @@
// Override the native jQuery methods with new methods
$.extend($.fn, controller);
-
// jQuery.important
$.important = $.extend(
function(){
@@ -250,54 +248,17 @@
// style elements
if (nodeName === 'style'){
makeImportant = (method !== false);
-
- /*
- // APPROACH 1: Change innerHTML
- // results in incomplete rendering of changes when there are many rules - seen in FF 3.6.3
- elem.html(
- toImportant(elem.html(), makeImportant)
- );
- */
-
- /*
- // APPROACH 2: replace with new node
- // This works, but means that references to the original style element will be broken. This may not be problematic in most cases.
- newStyleInsert = elem.next();
- if (!newStyleInsert.length){
- newStyleInsert = elem.parent();
- newStyleInsertVerb = 'appendTo';
- }
- else {
- newStyleInsertVerb = 'insertAfter';
- }
- elem.remove();
- elem = $(
- '<style id="css-third-party">' +
- $.important(elem.html(), makeImportant) +
- '</style>'
- )[newStyleInsertVerb](newStyleInsert);
- */
-
- // APPROACH 3: CSS DOM
+
elem.html(
toImportant(elem.html(), makeImportant)
);
var stylesheet = elem.attr('sheet');
- _('stylesheet', stylesheet);
if (stylesheet && stylesheet.cssRules){
- _('cssRules', stylesheet.cssRules);
$.each(stylesheet.cssRules, function(i, rule){
- _('rule', rule, rule.cssText);
- _($.important(rule.style.cssText, makeImportant));
if (rule.type === CSSRule.STYLE_RULE){
rule.style.cssText = $.important(rule.style.cssText, makeImportant);
}
- /*
- if (rule.cssText){
- rule.cssText = $.important(rule.cssText, makeImportant);
- }
- */
});
}
}

0 comments on commit 6b46d47

Please sign in to comment.