Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

binds to resize event

  • Loading branch information...
commit fa0f03dee387ebcf7f5116e32bc0e8639c389aa1 1 parent 79e30c6
@indyarmy authored
Showing with 32 additions and 50 deletions.
  1. +22 −47 jquery.cssMinMax.js
  2. +2 −2 jquery.cssMinMax.min.js
  3. +8 −1 readme.markdown
View
69 jquery.cssMinMax.js
@@ -1,5 +1,5 @@
/******************************************
- * jQuery.cssMinMax v0.1 indyarmy.com
+ * jQuery.cssMinMax v0.2 indyarmy.com
*
* A CSS3 min() and max() polyfill plugin for jQuery.
*
@@ -15,57 +15,31 @@
;( function( $ ) {
"use strict";
- var pluginName = "cssMinMax", // Mainly for temporary DOM elements
- sheetText = []; // all stylesheets as a single string
+ var pluginName = "cssMinMax"; // Mainly for temporary DOM elements
$.fn.cssMinMax = function( option, settings ) {
- var data, i, c;
- if ( typeof option === "object" ) {
- settings = option;
- } else if ( typeof option === "string" ) {
- data = this.data( "_" + pluginName );
- if ( data ) {
- if ( $.fn.cssMinMax.defaultSettings[ option ] !== undefined ) {
- if ( settings !== undefined ) {
- data.settings[ option ] = settings;
- return true;
- } else {
- return data.settings[ option ];
- }
- } else {
- return false;
- }
- } else {
- return false;
- }
- }
-
- settings = $.extend( true, {}, $.fn.cssMinMax.defaultSettings, settings || {} );
-
- for ( i = 0, c = document.styleSheets.length; i < c; i++ ) {
- // Combine all stylesheets into a single text string
- sheetText.push( document.styleSheets[i].ownerNode.textContent );
- }
- sheetText = sheetText.join( "\n" );
+ var sheetText = [],
+ i, c;
return this.each( function() {
- var $elem = $( this ),
- $settings = jQuery.extend( true, {}, settings ),
- cssMinMax = new CssMinMax( $settings );
-
- cssMinMax.generate();
+ if ( !$( document ).data( "_" + pluginName ) ) {
+ for ( i = 0, c = document.styleSheets.length; i < c; i++ ) {
+ // Combine all stylesheets into a single text string
+ sheetText.push( document.styleSheets[i].ownerNode.textContent );
+ }
+ sheetText = sheetText.join( "\n" );
+ $( document ).data( "_" + pluginName, {
+ sheetText : sheetText,
+ cssMinMax: new CssMinMax( sheetText )
+ });
+ }
- $elem.data("_" + pluginName, cssMinMax);
+ $( document ).data( "_" + pluginName ).cssMinMax.generate();
+ $( window ).bind("resize." + pluginName, $( document ).data( "_" + pluginName ).cssMinMax.generate );
} );
};
- $.fn.cssMinMax.defaultSettings = {
- position : "mouse",
- color : "black"
- };
-
- function CssMinMax( settings ) {
- this.cssMinMax = null;
- this.settings = settings;
+ function CssMinMax( sheetText ) {
+ this.sheetText = sheetText;
return this;
}
@@ -74,7 +48,7 @@
if ( typeof new CSSParser() === "object" ) {
var $this = this,
parser = new CSSParser(),
- sheet = parser.parse( sheetText, false, false ),
+ sheet = parser.parse( $( document ).data( "_" + pluginName ).sheetText, false, false ),
i, c, j, d, k, e, splitRule, element, calc, type, rule, numbers, metric, finalSize;
sheet.resolveVariables("screen");
for ( i = 0, c = sheet.cssRules.length; i < c; i++ ) {
@@ -97,7 +71,7 @@
if ( splitRule[ 0 ].indexOf( "width" ) !== -1 ) {
metric = "width";
}
- numbers[ k ] = this.getSize( numbers[ k ], numbers[ k ].substr( -2 ), element, metric );
+ numbers[ k ] = $( document ).data( "_" + pluginName ).cssMinMax.getSize( numbers[ k ], numbers[ k ].substr( -2 ), element, metric );
}
}
finalSize = parseFloat( eval( "Math." + type + "(" + numbers.join( "," ) + ")" ) );
@@ -105,6 +79,7 @@
}
}
}
+ parser = null;
return $this;
} else {
jQuery.error( "The JSCSSP library must be loaded before the " + pluginName + " plugin will work" );
View
4 jquery.cssMinMax.min.js
2 additions, 2 deletions not shown
View
9 readme.markdown
@@ -1,4 +1,4 @@
-# cssMinMax - jQuery Plugin
+# cssMinMax v0.2 - jQuery Plugin
The cssMinMax polyfill plugin lets you use the new CSS3 min() and max() function in your stylesheets.
@@ -23,3 +23,10 @@ cssMinMax is very much alpha-quality right now. It has been tested in Firefox 11
## Extra Thanks
Thanks to http://www.websanova.com/tutorials/jquery/jquery-plugin-development-boilerplate for providing a great boilerplate I could use for my second jQuery plugin
+
+## Changelog
+
+### v0.2
+
+* removed unnecessary settings and options code from boilerplate
+* binds to window resize event
Please sign in to comment.
Something went wrong with that request. Please try again.