PageSourceSearch

https://www.pressandappearances.com/wp-content/themes/kurzweilai/js/jquery.frameReady.js?ver=7.1.2

js pressandappearances.com collected 2026-10-02 12:00:27 UTC 9,421 bytes, 270 lines download raw bytes

1/****
2 *
3 * frameReady: Remote function calling for jQuery
4 *
5 * Version 1.2.0
6 *
7 * Copyright (c) 2007 Daemach (John Wilson) <[email protected]>, http://ideamill.synaptrixgroup.com
8 * Licensed under the MIT License:
9 * http://www.opensource.org/licenses/mit-license.php
10 * 
11 *	Credit John Resig and his excellent book for the ready function concepts.
12 *
13 * ============================================================================================
14 * Usage:  	$.frameReady(function (function),target (string)[,options (map/object)]);
15 * 
16 * Function: (function/required) An anonymous function to be run within the target frame.
17 *
18 * Target: (string/required) The target frame.  This must be a window object name (in quotes), 
19 *		so work from the top down.  If you have 3 frames named topFrame, navFrame, mainFrame, and 
20 *		an iframe inside of mainframe named iFrame, use "top.topFrame", "top.navFrame", 
21 *		"top.mainFrame", "top.mainFrame.iFrame" respectively.
22 *
23 *	Options: (object/optional) Map of options in object literal form.  Options include:
24 *
25 * 		remote: (boolean/ default true)  Run the function in the context of the target frame. 
26 *				If true, jQuery will be loaded in the target frame automatically and you can run 
27 *				jQuery selectors in the target frame as if they were local. ie: $("p") instead of 
28 *				$("p",top.mainFrame.document).  If false, jQuery will not be loaded automatically 
29 *				and you must use a context in jquery selectors.
30 *				
31 *			load: (array or object)  jquery is loaded by default. You can pass a single object to 
32 *				frameReady, or an array of objects that will be loaded and tested in order.  2 types 
33 *				of files can be loaded.  Scripts	and stylesheets:
34 *				
35 *				scripts: {type:"script", src:"/js/myscript.js", id:"_ms", test:"afunction"}
36 *				stylesheets: {type:"stylesheet", src:"/css/mycss.css", id:"_ss"}
37 *				
38 *					type: (string/required) "script" for script files, "stylesheet" for stylesheets.
39 *					src: (string/required)  The source of the file, ie: /js/myscript.js.
40 *					id: (string/optional)  An id for the id attribute.  If one isn't provided it 
41 *						will be generated.
42 *					test: (sting/optional) The name of a function that should exist once the script 
43 *						is loaded properly.  Until this function becomes available, the script will 
44 *						be considered not ready and no other files will be loaded.  If a test is not 
45 *						provided, the next file will be loaded immediately.  Tests are not useful 
46 *						with stylesheets.
47 *
48 *	One gotcha: You must have something other than space characters within the body tags of 
49 * 	target frame documents for frameReady to work properly.  A single character is enough.  
50 *		The reason for this is a workaround for an iFrame bug in Firefox, of all things.
51 * ==============================================================================================
52 *
53 * Example: 
54 *
55 *		$.frameReady(function(){
56 *		  $("<div>I am a div element</div>").prependTo("body");
57 *		}, "top.mainFrame", 
58 *		{ load: [ 
59 *			{type:"script",id:"_fr",src:"/js/jquery.frameReady.js",test: "$.frameReady"},
60 *			{type:"stylesheet",id:"_ss",src:"frameReady.css"} 
61 *			] } 
62 *		); 
63 *
64 *
65 * Release Notes:
66 *	
67 *	1.2.0 - Added provision for a local callback function;
68 *	        Added functionality to reset frame information if frame unloads for any reason;
69 *			  
70 *	1.1.0 - Added the ability to load scripts and stylesheets inside the target frame before
71 *					processing function stack;
72 *	
73 ****/
74 
75if (typeof $daemach == "undefined") { 
76	$daemach = {}; 
77	$daemach.debug = false;  // set this to true to enable logging
78	$daemach.log = function() {
79		if (!top.window.console || !top.window.console.log || !$daemach.debug) { 
80			return;
81		} else { 
82			top.window.console.log([].join.call(arguments,'')); 
83		}
84	}
85}
86
87if (typeof $daemach["frameReady"] == "undefined") { 
88	$daemach["frameReady"] = {}; 
89}
90 
91jQuery.frameReady = function(f,t,r,j) {
92	
93	/************************************************************
94		You must specify the path to your jquery.js file below!	
95	*************************************************************/
96	
97	var jQueryPath = "../js/jquery.min.js";
98	
99	var u = "undefined";	
100	var $fr = $daemach["frameReady"];
101	var fn = t.split(".").join("_");	
102	// create a branch
103	if (typeof $fr[fn] == u) { 
104		$fr[fn] = {}; 
105		$fr[fn]["settings"] = {	
106			remote: true,
107			jquery: true,
108			load: [ {type:"script",id:"_jq", src:jQueryPath, test:"jQuery"} ],
109			bLoaded: false,
110			loadInit: [],
111			callback: false
112		};
113		$fr[fn]["target"] = t;
114	}
115	var fr = $fr[fn];	
116	var frs = fr["settings"];
117	
118	if (fr.done) { 
119		$daemach.log(fr.target + " is ready.  Running functions now.");
120		return (frs.remote) ? eval(fr.target).eval("(" + f.toString() + ")()") : f(); 
121	};
122	
123	// process arguments
124
125	for (var a=2;a<arguments.length;a++){
126		var arg = arguments[a];
127		
128		if ($.isFunction(arg)){
129			frs.callback = arg;
130		} else if (typeof arg == "object") {
131			if (typeof arg.remote !== u) { 
132				frs.remote = arg.remote;
133			};
134			if (typeof arg.jquery !== u) { 
135				frs.jquery = arg.jquery;
136			};
137			
138			// if we're not running functions in the remote frame itself, no need for jQuery
139			if (!frs.remote || !frs.jquery) { 
140				frs.load.pop(); 
141			}
142			
143			if (typeof arg.load !== u) {
144				var bl = true;
145				if (arg.load.constructor == Array && arg.load.length){
146					for (var i=0;i<arg.load.length;i++){
147						bl = true;
148						for (var h=0;h<frs.load.length;h++){
149							if (frs.load[h].src == arg.load[i].src) { bl=false; };
150						}
151						if (bl) { frs.load.push(arg.load[i]); }
152					}
153				} else if (typeof arg.load == "object") {
154					for (var h=0;h<frs.load.length;h++){
155						if (frs.load[h].src == arg.load.src) { bl=false; };
156					}
157					if (bl) { frs.load.push(arg.load); }
158				}
159			}
160		}
161	}
162
163	if (fr.timer) {
164		fr.ready.push(f);
165	} else {
166		fr.ready=[f];
167		if (typeof addEvent !== "undefined"){ addEvent(window,"load",function(){ jQuery.isFrameReady(fn); }); };
168		fr.timer = setInterval(function(){ jQuery.isFrameReady(fn); },13);
169	}
170}
171
172jQuery.isFrameReady = function(fn){
173	var u = "undefined";	
174	var $d = $daemach;
175	var fr = $d["frameReady"][fn];
176	var frs = fr["settings"];
177	
178	if (fr.done) { return false; };
179
180	var fx = eval(fr.target);
181	$d.log(fn, ": New Pass. Checking target");
182	// make sure we have a target
183	if (typeof fx !== "undefined") {
184		$d.log(fn, ": Found target.  Checking DOM");
185		var fd = fx.document;
186		
187		// make sure we have a DOM
188		if (fd && fd.getElementsByTagName && fd.getElementById && fd.body && fd.body.innerHTML.length) {
189			
190			$d.log(fn, ": Found DOM");
191			
192			if (frs.load.length && !frs.bLoaded){
193				for (var i=0;i<frs.load.length;i++){
194					var s = frs.load[i];
195					var _test;
196					try { _test = eval('typeof fx.'+s.test+ ' !== "undefined"'); } 
197					catch(ex){ _test = false;}
198					finally { $d.log(fn, ": Running test for script ",i,". ", (_test || !s.test) ? "Passed.":"Failed."); }
199
200					if ((_test || !s.test) && frs.loadInit[i]) {
201						frs.bLoaded = (typeof s.test == u) ? true : _test; 
202						continue; 
203					} else {
204						frs.bLoaded = false;
205						if (typeof frs.loadInit[i] == u){
206							var id = s.id || "frs_"+i;
207							switch (s.type) {
208								case "script" :
209									$d.log(fn, ": Loading script "+ i + " (" + s.src + ")");
210									var ele=fd.createElement('script');
211									ele.setAttribute('id', id);
212									ele.setAttribute('src', s.src);
213									fd.getElementsByTagName("head")[0].appendChild(ele);
214									void(ele);
215									frs.loadInit[i] = true;
216									break
217								case "stylesheet" :
218									$d.log(fn, ": Loading stylesheet "+ i + " (" + s.src + ")");
219									var ele=fd.createElement('link');
220									ele.setAttribute('id', id);
221									ele.setAttribute('href', s.src);
222									ele.setAttribute('rel', "stylesheet");
223									ele.setAttribute('type', "text/css");
224									fd.getElementsByTagName("head")[0].appendChild(ele);
225									void(ele);
226									frs.loadInit[i] = true;
227								break
228								default :
229									$d.log(fn, ": Script "+i+" has a bad or missing type attribute..." );
230							}
231						}
232						break;
233					}
234				}
235			} else {
236				clearInterval(fr.timer);	
237				fr.timer = null;
238
239				fr.ready.push(function(){ window.frameReadyUnload = function(root, fn){ $(window).bind("unload",function(){ root.
239jQuery.frameReady.unload(fn); }); } });
240				
241				$d.log(fn, ": Processing function stack:");
242				for (var i=0; i<fr.ready.length;i++){
243					(frs.remote) ? fx.eval("(" + fr.ready[i].toString() + ")()") : fr.ready[i]();
244				}
245				
246				fx.frameReadyUnload(window,fn);
247				
248				$d.log(fn, ": Function stack processing complete.");
249				
250				// we're done here.  let's have a beer.
251				fr.ready = null;
252				fr.done=true;
253				
254				if (frs.callback){ 
255					$d.log(fn, ": Found a callback.  Executing...");
256					frs.callback(); 
257				}
258			}
259		}
260	} 
261
262	$d.log(fn, ":");
263}
264
265jQuery.frameReady.unload = function(fn){
266	$daemach.log("Frame " + fn + " is unloading.  Resetting state.")
267	$daemach["frameReady"][fn].done = false;
268	$daemach["frameReady"][fn]["settings"].bLoaded = false;
269	$daemach["frameReady"][fn]["settings"].loadInit = [];
270}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.