-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ability to trigger custom events in response to DOM insertions.
Functionality, documentation, and showcasing example added.
- Loading branch information
John Lianoglou
committed
Oct 5, 2014
1 parent
eba1807
commit 1863216
Showing
3 changed files
with
60 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,11 @@ | |
* Tim Ambler <[email protected]> | ||
*/ | ||
(function(root, factory) { | ||
if ( typeof define === 'function' && define.amd ) { | ||
define(['jquery'], factory); | ||
} else { | ||
factory(jQuery); | ||
} | ||
if ( typeof define === 'function' && define.amd ) { | ||
define(['jquery'], factory); | ||
} else { | ||
factory(jQuery); | ||
} | ||
})(this, function(jQuery) { | ||
|
||
(function($) { | ||
|
@@ -68,6 +68,9 @@ | |
if ( typeof options === 'function' ) { | ||
fn = options; | ||
options = {}; | ||
} else if (typeof options === 'string' ) { | ||
fn = options; | ||
options = {}; | ||
} else if ( typeof options !== 'object' ) { | ||
options = {}; | ||
} | ||
|
@@ -76,6 +79,16 @@ | |
options.visibility = true; | ||
} | ||
|
||
if ( typeof fn === 'string' ) { | ||
var evtName = fn; | ||
fn = function(el) { | ||
$(document).trigger({ | ||
type: evtName, | ||
element: el | ||
}); | ||
} | ||
} | ||
|
||
if ( typeof fn !== 'function' ) { | ||
return; | ||
} | ||
|
@@ -94,7 +107,7 @@ | |
for ( var mi = 0; mi < mutations.length; mi++ ) { | ||
var mutation = mutations[mi]; | ||
checkElements(mutation.target); | ||
if ( $.whenLiveElements.length && mutation.addedNodes != null ) { | ||
if ( $.whenLiveElements.length && mutation.addedNodes != null ) { | ||
for ( var ni = 0; ni < mutation.addedNodes.length; ni ++ ) { | ||
var node = mutation.addedNodes[ni]; | ||
checkElements(node); | ||
|