-
-
Save PizzaBrandon/5709010 to your computer and use it in GitHub Desktop.
Revisions
-
PizzaBrandon revised this gist
Jun 5, 2013 . 2 changed files with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ ;(function ($, window) { var intervals = {}; var removeListener = function(selector) { @@ -59,4 +59,4 @@ $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) { return $this; }; }(jQuery, window)); This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1 +1 @@ (function(e,f){var b={},g=function(a){b[a]&&(f.clearInterval(b[a]),b[a]=null)};e.fn.waitUntilExists=function(a,h,j){var c=this.selector,d=e(c),k=d.not(function(){return e(this).data("waitUntilExists.found")});"remove"===a?g(c):(k.each(a).data("waitUntilExists.found",!0),h&&d.length?g(c):j||(b[c]=f.setInterval(function(){d.waitUntilExists(a,h,!0)},500)));return d}})(jQuery,window); -
PizzaBrandon revised this gist
Jun 5, 2013 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ (function(e){var b={},f=function(a){b[a]&&(window.clearInterval(b[a]),b[a]=null)};e.fn.waitUntilExists=function(a,g,h){var c=this.selector,d=e(c),j=d.not(function(){return e(this).data("waitUntilExists.found")});"remove"===a?f(c):(j.each(a).data("waitUntilExists.found",!0),g&&d.length?f(c):h||(b[c]=window.setInterval(function(){d.waitUntilExists(a,g,!0)},500)));return d}})(jQuery); -
PizzaBrandon revised this gist
Jun 4, 2013 . 1 changed file with 12 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -12,12 +12,16 @@ var removeListener = function(selector) { var found = 'waitUntilExists.found'; /** * @function * @property {object} jQuery plugin which runs handler function once specified * element is inserted into the DOM * @param {function|string} handler * A function to execute at the time when the element is inserted or * string "remove" to remove the listener from the given selector * @param {bool} shouldRunHandlerOnce * Optional: if true, handler is unbound after its first invocation * @example jQuery(selector).waitUntilExists(function); */ $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) { @@ -32,11 +36,8 @@ $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) { } else { // Run the handler on all found elements and mark as found $elements.each(handler).data(found, true); if (shouldRunHandlerOnce && $this.length) { -
PizzaBrandon revised this gist
Jun 4, 2013 . 1 changed file with 47 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,30 +1,61 @@ ;(function ($) { var intervals = {}; var removeListener = function(selector) { if (intervals[selector]) { window.clearInterval(intervals[selector]); intervals[selector] = null; } }; var found = 'waitUntilExists.found'; /** * @function * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM * @param {function|string} handler A function to execute at the time when the element is inserted or string "remove" to remove the listener from the given selector * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example jQuery(selector).waitUntilExists(function); */ $.fn.waitUntilExists = function(handler, shouldRunHandlerOnce, isChild) { var selector = this.selector; var $this = $(selector); var $elements = $this.not(function() { return $(this).data(found); }); if (handler === 'remove') { // Hijack and remove interval immediately if the code requests removeListener(selector); } else { if ($elements.length) { // $elements.each(handler).data(found, true); } if (shouldRunHandlerOnce && $this.length) { // Element was found, implying the handler already ran for all // matched elements removeListener(selector); } else if (!isChild) { // If this is a recurring search or if the target has not yet been // found, create an interval to continue searching for the target intervals[selector] = window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500); } } return $this; }; }(jQuery)); -
PizzaBrandon revised this gist
Jun 4, 2013 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,9 @@ ;(function ($) { /** * @function * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM * @param {function|string} handler A function to execute at the time when the element is inserted or string "remove" to remove the listener from the given selector * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $(selector).waitUntilExists(function); */ @@ -19,7 +19,7 @@ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500) ; } else if (handler === "remove" || (shouldRunHandlerOnce && $elements.length)) { window.clearInterval(window.waitUntilExists_Intervals[this.selector]); } -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ (function ($) { /** * @function * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM @@ -23,4 +25,6 @@ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { } return $this; } }(jQuery)); -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ /** * @function * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM * @param {function} handler A function to execute at the time when the element is inserted * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $(selector).waitUntilExists(function); */ @@ -23,4 +23,4 @@ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { } return $this; } -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM * @param {function} handler * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $(selector).waitUntilExists(function); */ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -7,8 +7,8 @@ */ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { var found = 'found'; var $this = $(this.selector); var $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true); if (!isChild) -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,9 +6,9 @@ * @example $('div.comments').waitUntilExists(commentCallbackFunction || function () { alert('function does not exist.'); }) */ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { var found = 'found'; var $this = $(this.selector); var $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true); if (!isChild) -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 5 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /** * @function * @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM * @param {function} handler * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $('div.comments').waitUntilExists(commentCallbackFunction || function () { alert('function does not exist.'); }) @@ -9,14 +9,13 @@ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { var found = 'found'; var $this = $(this.selector); var $elements = $this.not(function () { return $(this).data(found); }).each(handler).data(found, true); if (!isChild) { (window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {})[this.selector] = window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500) ; } else if (shouldRunHandlerOnce && $elements.length) { -
buu700 revised this gist
Dec 4, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ /** * @function * @property {object} jQuery plugin which runs handler function when specified element is inserted into the DOM * @param {function} handler * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $('div.comments').waitUntilExists(commentCallbackFunction || function () { alert('function does not exist.'); }) -
buu700 revised this gist
Dec 4, 2012 . 2 changed files with 27 additions and 92 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ /** * @function * @property {string} jQuery plugin which runs handler function when specified element is inserted into the DOM * @param {function} handler * @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation * @example $('div.comments').waitUntilExists(commentCallbackFunction || function () { alert('function does not exist.'); }) */ $.fn.waitUntilExists = function (handler, shouldRunHandlerOnce, isChild) { var found = 'found'; var $this = $(this.selector); var $elements = $this.not(function () { return $(this).data(found); }); $elements.each(function () { handler(this); $(this).data(found, true); }); if (!isChild) { window.waitUntilExists_Intervals = window.waitUntilExists_Intervals || {}; window.waitUntilExists_Intervals[this.selector] = window.setInterval(function () { $this.waitUntilExists(handler, shouldRunHandlerOnce, true); }, 500); } else if (shouldRunHandlerOnce && $elements.length) { window.clearInterval(window.waitUntilExists_Intervals[this.selector]); } return $this; } This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,92 +0,0 @@ -
Brock revised this gist
Nov 16, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -83,7 +83,7 @@ function waitForKeyElements ( iframeSelector ); }, 300 ); controlObj [controlKey] = timeControl; } -
Brock revised this gist
May 18, 2012 . 1 changed file with 6 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,7 @@ function waitForKeyElements ( .find (selectorTxt); if (targetNodes && targetNodes.length > 0) { btargetsFound = true; /*--- Found target node(s). Go through each and act if they are new. */ @@ -49,11 +50,13 @@ function waitForKeyElements ( if (!alreadyFound) { //--- Call the payload function. var cancelFound = actionFunction (jThis); if (cancelFound) btargetsFound = false; else jThis.data ('alreadyFound', true); } } ); } else { btargetsFound = false; -
Brock revised this gist
May 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -49,8 +49,8 @@ function waitForKeyElements ( if (!alreadyFound) { //--- Call the payload function. jThis.data ('alreadyFound', true); actionFunction (jThis); } } ); btargetsFound = true; -
Brock created this gist
May 7, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,89 @@ /*--- waitForKeyElements(): A utility function, for Greasemonkey scripts, that detects and handles AJAXed content. Usage example: waitForKeyElements ( "div.comments" , commentCallbackFunction ); //--- Page-specific function to do what we want when the node is found. function commentCallbackFunction (jNode) { jNode.text ("This comment changed by waitForKeyElements()."); } IMPORTANT: This function requires your script to have loaded jQuery. */ function waitForKeyElements ( selectorTxt, /* Required: The jQuery selector string that specifies the desired element(s). */ actionFunction, /* Required: The code to run when elements are found. It is passed a jNode to the matched element. */ bWaitOnce, /* Optional: If false, will continue to scan for new elements even after the first match is found. */ iframeSelector /* Optional: If set, identifies the iframe to search. */ ) { var targetNodes, btargetsFound; if (typeof iframeSelector == "undefined") targetNodes = $(selectorTxt); else targetNodes = $(iframeSelector).contents () .find (selectorTxt); if (targetNodes && targetNodes.length > 0) { /*--- Found target node(s). Go through each and act if they are new. */ targetNodes.each ( function () { var jThis = $(this); var alreadyFound = jThis.data ('alreadyFound') || false; if (!alreadyFound) { //--- Call the payload function. actionFunction (jThis); jThis.data ('alreadyFound', true); } } ); btargetsFound = true; } else { btargetsFound = false; } //--- Get the timer-control variable for this selector. var controlObj = waitForKeyElements.controlObj || {}; var controlKey = selectorTxt.replace (/[^\w]/g, "_"); var timeControl = controlObj [controlKey]; //--- Now set or clear the timer as appropriate. if (btargetsFound && bWaitOnce && timeControl) { //--- The only condition where we need to clear the timer. clearInterval (timeControl); delete controlObj [controlKey] } else { //--- Set a timer, if needed. if ( ! timeControl) { timeControl = setInterval ( function () { waitForKeyElements ( selectorTxt, actionFunction, bWaitOnce, iframeSelector ); }, 500 ); controlObj [controlKey] = timeControl; } } waitForKeyElements.controlObj = controlObj; }