diff --git a/README.markdown b/README.markdown index 785e771..0d6770e 100644 --- a/README.markdown +++ b/README.markdown @@ -1,6 +1,9 @@ # jQuery outside events # [http://benalman.com/projects/jquery-outside-events-plugin/](http://benalman.com/projects/jquery-outside-events-plugin/) +Version: 1.2, Last updated: 3/31/2016, By: TomerSH17 +Remove jQuery array and use pure JS array in order to avoid the memory leak that exists in "not" method when the jQuery array is used + Version: 1.1, Last updated: 3/16/2010 With jQuery outside events you can bind to an event that will be triggered only when a specific "originating" event occurs *outside* the element in question. For example, you can click outside, double-click outside, mouse-over outside, focus outside (and over ten more default "outside" events). Also, if an outside event hasn't been provided by default, you can easily define your own. @@ -41,6 +44,7 @@ Internet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1. ## Release History ## +1.2 - (3/31/2016) Remove jQuery array and use pure JS array in order to avoid the memory leak that exists in "not" method when the jQuery array is used. 1.1 - (3/16/2010) Made "clickoutside" plugin more general, resulting in a whole new plugin with more than a dozen default "outside" events and a method that can be used to add new ones. 1.0 - (2/27/2010) Initial release diff --git a/jquery.ba-outside-events.js b/jquery.ba-outside-events.js index 62e83e4..4e9786d 100644 --- a/jquery.ba-outside-events.js +++ b/jquery.ba-outside-events.js @@ -1,6 +1,6 @@ /*! - * jQuery outside events - v1.1 - 3/16/2010 - * http://benalman.com/projects/jquery-outside-events-plugin/ + * jQuery outside events - v1.2 - 3/31/2016 + * https://github.com/TomerSH17/jquery-outside-events * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. @@ -9,6 +9,7 @@ // Script: jQuery outside events // +// *Version: 1.2, Last updated: 3/31/2016, By: TomerSH17* // *Version: 1.1, Last updated: 3/16/2010* // // Project Home - http://benalman.com/projects/jquery-outside-events-plugin/ @@ -44,6 +45,7 @@ // // About: Release History // +// 1.2 - Use "elems" variable as pure JS array and not jQuery array to avoid memory leak when invoking the "not" method on it // 1.1 - (3/16/2010) Made "clickoutside" plugin more general, resulting in a // whole new plugin with more than a dozen default "outside" events and // a method that can be used to add new ones. @@ -122,7 +124,7 @@ // A jQuery object containing all elements to which the "outside" event is // bound. - var elems = $(), + var elems = new Array(), // The "originating" event, namespaced for easy unbinding. event_namespaced = event_name + '.' + outside_event_name + '-special-event'; @@ -165,12 +167,12 @@ // Add this element to the list of elements to which this "outside" // event is bound. - elems = elems.add( this ); + elems.push( this ); // If this is the first element getting the event bound, bind a handler // to document to catch all corresponding "originating" events. if ( elems.length === 1 ) { - $(doc).bind( event_namespaced, handle_event ); + $(doc).on( event_namespaced, handle_event ); } }, @@ -180,12 +182,15 @@ // Remove this element from the list of elements to which this // "outside" event is bound. - elems = elems.not( this ); + var elemIndex = $.inArray(this, elems); + if ( elemIndex !== -1 ) { + elems.splice( elemIndex, 1 ); + } // If this is the last element removed, remove the "originating" event // handler on document that powers this "outside" event. if ( elems.length === 0 ) { - $(doc).unbind( event_namespaced ); + $(doc).off( event_namespaced ); } },