Permalink
Browse files

Fixed a minor bug that was causing the event to trigger immediately a…

…fter bind in some circumstances. Also changed $.fn.data to $.data to improve performance.
  • Loading branch information...
1 parent 11d39cd commit 21ae0ec06d751a408165a1714963173c2db6adfa @cowboy committed Mar 14, 2010
View
@@ -1,7 +1,7 @@
# jQuery resize event #
[http://benalman.com/projects/jquery-resize-plugin/](http://benalman.com/projects/jquery-resize-plugin/)
-Version: 1.0, Last updated: 2/10/2010
+Version: 1.1, Last updated: 3/14/2010
With jQuery resize event, you can bind resize event handlers to elements other than window, for super-awesome-resizing-greatness!
@@ -26,7 +26,7 @@ tested with, what browsers it has been tested in, and where the unit tests
reside (so you can test it yourself).
### jQuery Versions ###
-1.3.2, 1.4.1, 1.4.2pre
+1.3.2, 1.4.1, 1.4.2
### Browsers Tested ###
Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
@@ -37,6 +37,7 @@ Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
## Release History ##
+1.1 - (3/14/2010) Fixed a minor bug that was causing the event to trigger immediately after bind in some circumstances. Also changed $.fn.data to $.data to improve performance.
1.0 - (2/10/2010) Initial release
@@ -11,15 +11,15 @@
-<div id=Content><div class="CFile"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="jQuery_resize_event"></a>jQuery resize event</h1><div class=CBody><p><b>Version: 1.0, Last updated: 2/10/2010</b></p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>Project Home</td><td class=CDLDescription><a href="http://benalman.com/projects/jquery-resize-plugin/" class=LURL target=_top>http://benalman.com<wbr>/projects<wbr>/jquery-resize-plugin<wbr>/</a></td></tr><tr><td class=CDLEntry>GitHub</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/" class=LURL target=_top>http://github.com/cowboy/jquery-resize/</a></td></tr><tr><td class=CDLEntry>Source</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/raw/master/jquery.ba-resize.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-resize<wbr>/raw<wbr>/master<wbr>/jquery.ba-resize.js</a></td></tr><tr><td class=CDLEntry>(Minified)</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/raw/master/jquery.ba-resize.min.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-resize<wbr>/raw<wbr>/master<wbr>/jquery.ba-resize.min.js</a> (1.0kb)</td></tr></table><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#jQuery_resize_event" >jQuery resize event</a></td><td class=SDescription><b>Version: 1.0, Last updated: 2/10/2010</b></td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#License" >License</a></td><td class=SDescription>Copyright &copy; 2010 &ldquo;Cowboy&rdquo; Ben Alman, Dual licensed under the MIT and GPL licenses. </td></tr><tr class="SGeneric"><td class=SEntry><a href="#Examples" >Examples</a></td><td class=SDescription>This working example, complete with fully commented code, illustrates a few ways in which this plugin can be used.</td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#Support_and_Testing" >Support and Testing</a></td><td class=SDescription>Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).</td></tr><tr class="SGeneric"><td class=SEntry><a href="#Release_History" >Release History</a></td><td class=SDescription></td></tr><tr class="SGroup"><td class=SEntry><a href="#Properties" >Properties</a></td><td class=SDescription></td></tr><tr class="SProperty SIndent1 SMarked"><td class=SEntry><a href="#jQuery.resize.delay" >jQuery.<wbr>resize.<wbr>delay</a></td><td class=SDescription>The numeric interval (in milliseconds) at which the resize event polling loop executes. </td></tr><tr class="SProperty SIndent1"><td class=SEntry><a href="#jQuery.resize.throttleWindow" >jQuery.<wbr>resize.<wbr>throttleWindow</a></td><td class=SDescription>Throttle the native window object resize event to fire no more than once every <a href="#jQuery.resize.delay" class=LProperty id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">jQuery.resize.delay</a> milliseconds. </td></tr><tr class="SGroup"><td class=SEntry><a href="#Events" >Events</a></td><td class=SDescription></td></tr><tr class="SEvent SIndent1 SMarked"><td class=SEntry><a href="#resize_event" >resize event</a></td><td class=SDescription>Fired when an element&rsquo;s width or height changes. </td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>
+<div id=Content><div class="CFile"><div class=CTopic id=MainTopic><h1 class=CTitle><a name="jQuery_resize_event"></a>jQuery resize event</h1><div class=CBody><p><b>Version: 1.1, Last updated: 3/14/2010</b></p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>Project Home</td><td class=CDLDescription><a href="http://benalman.com/projects/jquery-resize-plugin/" class=LURL target=_top>http://benalman.com<wbr>/projects<wbr>/jquery-resize-plugin<wbr>/</a></td></tr><tr><td class=CDLEntry>GitHub</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/" class=LURL target=_top>http://github.com/cowboy/jquery-resize/</a></td></tr><tr><td class=CDLEntry>Source</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/raw/master/jquery.ba-resize.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-resize<wbr>/raw<wbr>/master<wbr>/jquery.ba-resize.js</a></td></tr><tr><td class=CDLEntry>(Minified)</td><td class=CDLDescription><a href="http://github.com/cowboy/jquery-resize/raw/master/jquery.ba-resize.min.js" class=LURL target=_top>http://github.com<wbr>/cowboy<wbr>/jquery-resize<wbr>/raw<wbr>/master<wbr>/jquery.ba-resize.min.js</a> (1.0kb)</td></tr></table><!--START_ND_SUMMARY--><div class=Summary><div class=STitle>Summary</div><div class=SBorder><table border=0 cellspacing=0 cellpadding=0 class=STable><tr class="SMain"><td class=SEntry><a href="#jQuery_resize_event" >jQuery resize event</a></td><td class=SDescription><b>Version: 1.1, Last updated: 3/14/2010</b></td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#License" >License</a></td><td class=SDescription>Copyright &copy; 2010 &ldquo;Cowboy&rdquo; Ben Alman, Dual licensed under the MIT and GPL licenses. </td></tr><tr class="SGeneric"><td class=SEntry><a href="#Examples" >Examples</a></td><td class=SDescription>This working example, complete with fully commented code, illustrates a few ways in which this plugin can be used.</td></tr><tr class="SGeneric SMarked"><td class=SEntry><a href="#Support_and_Testing" >Support and Testing</a></td><td class=SDescription>Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).</td></tr><tr class="SGeneric"><td class=SEntry><a href="#Release_History" >Release History</a></td><td class=SDescription></td></tr><tr class="SGroup"><td class=SEntry><a href="#Properties" >Properties</a></td><td class=SDescription></td></tr><tr class="SProperty SIndent1 SMarked"><td class=SEntry><a href="#jQuery.resize.delay" >jQuery.<wbr>resize.<wbr>delay</a></td><td class=SDescription>The numeric interval (in milliseconds) at which the resize event polling loop executes. </td></tr><tr class="SProperty SIndent1"><td class=SEntry><a href="#jQuery.resize.throttleWindow" >jQuery.<wbr>resize.<wbr>throttleWindow</a></td><td class=SDescription>Throttle the native window object resize event to fire no more than once every <a href="#jQuery.resize.delay" class=LProperty id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')">jQuery.resize.delay</a> milliseconds. </td></tr><tr class="SGroup"><td class=SEntry><a href="#Events" >Events</a></td><td class=SDescription></td></tr><tr class="SEvent SIndent1 SMarked"><td class=SEntry><a href="#resize_event" >resize event</a></td><td class=SDescription>Fired when an element&rsquo;s width or height changes. </td></tr></table></div></div><!--END_ND_SUMMARY--></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="License"></a>License</h3><div class=CBody><p>Copyright &copy; 2010 &ldquo;Cowboy&rdquo; Ben Alman, Dual licensed under the MIT and GPL licenses.&nbsp; <a href="http://benalman.com/about/license/" class=LURL target=_top>http://benalman.com/about/license/</a></p></div></div></div>
<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Examples"></a>Examples</h3><div class=CBody><p>This working example, complete with fully commented code, illustrates a few ways in which this plugin can be used.</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>resize event</td><td class=CDLDescription><a href="http://benalman.com/code/projects/jquery-resize/examples/resize/" class=LURL target=_top>http://benalman.com<wbr>/code<wbr>/projects<wbr>/jquery-resize<wbr>/examples<wbr>/resize<wbr>/</a></td></tr></table></div></div></div>
-<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Support_and_Testing"></a>Support and Testing</h3><div class=CBody><p>Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>jQuery Versions</td><td class=CDLDescription>1.3.2, 1.4.1, 1.4.2pre</td></tr><tr><td class=CDLEntry>Browsers Tested</td><td class=CDLDescription>Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.</td></tr><tr><td class=CDLEntry>Unit Tests</td><td class=CDLDescription><a href="http://benalman.com/code/projects/jquery-resize/unit/" class=LURL target=_top>http://benalman.com<wbr>/code<wbr>/projects<wbr>/jquery-resize<wbr>/unit<wbr>/</a></td></tr></table></div></div></div>
+<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Support_and_Testing"></a>Support and Testing</h3><div class=CBody><p>Information about what version or versions of jQuery this plugin has been tested with, what browsers it has been tested in, and where the unit tests reside (so you can test it yourself).</p><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>jQuery Versions</td><td class=CDLDescription>1.3.2, 1.4.1, 1.4.2</td></tr><tr><td class=CDLEntry>Browsers Tested</td><td class=CDLDescription>Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.</td></tr><tr><td class=CDLEntry>Unit Tests</td><td class=CDLDescription><a href="http://benalman.com/code/projects/jquery-resize/unit/" class=LURL target=_top>http://benalman.com<wbr>/code<wbr>/projects<wbr>/jquery-resize<wbr>/unit<wbr>/</a></td></tr></table></div></div></div>
-<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Release_History"></a>Release History</h3><div class=CBody><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>1.0</td><td class=CDLDescription>(2/10/2010) Initial release</td></tr></table></div></div></div>
+<div class="CGeneric"><div class=CTopic><h3 class=CTitle><a name="Release_History"></a>Release History</h3><div class=CBody><table border=0 cellspacing=0 cellpadding=0 class=CDescriptionList><tr><td class=CDLEntry>1.1</td><td class=CDLDescription>(3/14/2010) Fixed a minor bug that was causing the event to trigger immediately after bind in some circumstances.&nbsp; Also changed $.fn.data to $.data to improve performance.</td></tr><tr><td class=CDLEntry>1.0</td><td class=CDLDescription>(2/10/2010) Initial release</td></tr></table></div></div></div>
<div class="CGroup"><div class=CTopic><h3 class=CTitle><a name="Properties"></a>Properties</h3></div></div>
View
@@ -13,7 +13,7 @@
<div id=Index><div class=IPageTitle>File Index</div><div class=INavigationBar>$#! &middot; 0-9 &middot; A &middot; B &middot; C &middot; D &middot; E &middot; F &middot; G &middot; H &middot; I &middot; <a href="#J">J</a> &middot; K &middot; L &middot; M &middot; N &middot; O &middot; P &middot; Q &middot; R &middot; S &middot; T &middot; U &middot; V &middot; W &middot; X &middot; Y &middot; Z</div><table border=0 cellspacing=0 cellpadding=0><tr><td class=IHeading id=IFirstHeading><a name="J"></a>J</td><td></td></tr><tr><td class=ISymbolPrefix id=IOnlySymbolPrefix>&nbsp;</td><td class=IEntry><a href="../files/jquery-ba-resize-js.html#jQuery_resize_event" id=link1 onMouseOver="ShowTip(event, 'tt1', 'link1')" onMouseOut="HideTip('tt1')" class=ISymbol>jQuery resize event</a></td></tr></table>
<!--START_ND_TOOLTIPS-->
-<div class=CToolTip id="tt1"><div class=CFile><b>Version: 1.0, Last updated: 2/10/2010</b></div></div><!--END_ND_TOOLTIPS-->
+<div class=CToolTip id="tt1"><div class=CFile><b>Version: 1.1, Last updated: 3/14/2010</b></div></div><!--END_ND_TOOLTIPS-->
</div><!--Index-->
View
@@ -21,7 +21,7 @@
<!--START_ND_TOOLTIPS-->
-<div class=CToolTip id="tt3"><div class=CFile><b>Version: 1.0, Last updated: 2/10/2010</b></div></div><!--END_ND_TOOLTIPS-->
+<div class=CToolTip id="tt3"><div class=CFile><b>Version: 1.1, Last updated: 3/14/2010</b></div></div><!--END_ND_TOOLTIPS-->
<!--START_ND_TOOLTIPS-->
Binary file not shown.
View
@@ -1,4 +1,4 @@
1.4
JavaScript
-/srv/projects/jquery-resize/jquery.ba-resize.min.js 1265891740 0 /srv/projects/jquery-resize/jquery.ba-resize.min.js
-/srv/projects/jquery-resize/jquery.ba-resize.js 1265891732 1 jQuery resize event
+/srv/projects/jquery-resize/jquery.ba-resize.min.js 1268597721 0 /srv/projects/jquery-resize/jquery.ba-resize.min.js
+/srv/projects/jquery-resize/jquery.ba-resize.js 1268597210 1 jQuery resize event
View
Binary file not shown.
View
@@ -12,8 +12,7 @@
$shell['h3'] = ob_get_contents();
ob_end_clean();
-//$shell['jquery'] = 'jquery-1.4.2pre.js';
-$shell['jquery'] = 'jquery-1.4.1.js';
+$shell['jquery'] = 'jquery-1.4.2.js';
//$shell['jquery'] = 'jquery-1.3.2.js';
$shell['shBrush'] = array( 'JScript' );
View
@@ -1,5 +1,5 @@
/*!
- * jQuery resize event - v1.0 - 2/10/2010
+ * jQuery resize event - v1.1 - 3/14/2010
* http://benalman.com/projects/jquery-resize-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
@@ -9,7 +9,7 @@
// Script: jQuery resize event
//
-// *Version: 1.0, Last updated: 2/10/2010*
+// *Version: 1.1, Last updated: 3/14/2010*
//
// Project Home - http://benalman.com/projects/jquery-resize-plugin/
// GitHub - http://github.com/cowboy/jquery-resize/
@@ -35,12 +35,15 @@
// tested with, what browsers it has been tested in, and where the unit tests
// reside (so you can test it yourself).
//
-// jQuery Versions - 1.3.2, 1.4.1, 1.4.2pre
+// jQuery Versions - 1.3.2, 1.4.1, 1.4.2
// Browsers Tested - Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.
// Unit Tests - http://benalman.com/code/projects/jquery-resize/unit/
//
// About: Release History
//
+// 1.1 - (3/14/2010) Fixed a minor bug that was causing the event to trigger
+// immediately after bind in some circumstances. Also changed $.fn.data
+// to $.data to improve performance.
// 1.0 - (2/10/2010) Initial release
(function($,window,undefined){
@@ -139,7 +142,7 @@
elems = elems.add( elem );
// Initialize data store on the element.
- elem.data( str_data, { width: elem.width(), height: elem.height() } );
+ $.data( this, str_data, { w: elem.width(), h: elem.height() } );
// If this is the first element added, start the polling loop.
if ( elems.length === 1 ) {
@@ -187,7 +190,7 @@
function new_handler( e, w, h ) {
var elem = $(this),
- data = elem.data( str_data );
+ data = $.data( this, str_data );
// If called from the polling loop, w and h will be passed in as
// arguments. If called manually, via .trigger( 'resize' ) or .resize(),
@@ -213,26 +216,31 @@
};
- // Start the polling loop.
function loopy() {
- // Iterate over all elements to which the 'resize' event is bound.
- elems.each(function(){
- var elem = $(this),
- width = elem.width(),
- height = elem.height(),
- data = elem.data( str_data );
-
- // If element size has changed since the last time, update the element
- // data store and trigger the 'resize' event.
- if ( width !== data.w || height !== data.h ) {
- elem.trigger( str_resize, [ data.w = width, data.h = height ] );
- }
+ // Start the polling loop, asynchronously.
+ timeout_id = window[ str_setTimeout ](function(){
+
+ // Iterate over all elements to which the 'resize' event is bound.
+ elems.each(function(){
+ var elem = $(this),
+ width = elem.width(),
+ height = elem.height(),
+ data = $.data( this, str_data );
+
+ // If element size has changed since the last time, update the element
+ // data store and trigger the 'resize' event.
+ if ( width !== data.w || height !== data.h ) {
+ elem.trigger( str_resize, [ data.w = width, data.h = height ] );
+ }
+
+ });
+
+ // Loop.
+ loopy();
- });
+ }, jq_resize[ str_delay ] );
- // Loop.
- timeout_id = window[ str_setTimeout ]( loopy, jq_resize[ str_delay ] );
};
})(jQuery,this);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 21ae0ec

Please sign in to comment.