Forked from buu700/jquery.waituntilexists.js
Last active
October 3, 2017 13:36
Revisions
-
cargix1 revised this gist
Oct 3, 2017 . 1 changed file with 2 additions 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 @@ -1,3 +1,5 @@ var jQuery = require('jquery'); (function ($) { /** -
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 @@ -
BrockA 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; } -
BrockA 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; -
BrockA 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; -
BrockA 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; }