Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1.2 #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

V1.2 #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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

Expand Down
19 changes: 12 additions & 7 deletions jquery.ba-outside-events.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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 );
}
},

Expand All @@ -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 );
}
},

Expand Down