/**** * * frameReady: Remote function calling for jQuery * * Version 1.2.1 * * Copyright (c) 2007 Daemach (John Wilson) , http://ideamill.synaptrixgroup.com * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * Credit John Resig and his excellent book for the ready function concepts. * * Credit to Mike Alsup for the logging code. * ============================================================================================ * Usage: $.frameReady(function (function),target (string)[,options (map)][,callback (function)]); * * Function: (function/required) An anonymous function to be run within the target frame. * * Target: (string/required) The target frame. This must be a window object name (in quotes), * so work from the top down. If you have 3 frames named topFrame, navFrame, mainFrame, and * an iframe inside of mainframe named iFrame, use "top.topFrame", "top.navFrame", * "top.mainFrame", "top.mainFrame.iFrame" respectively. * * Options: (object/optional) Map of options in object literal form. Options include: * * remote: (boolean/ default true) Run the function in the context of the target frame. * If true, jQuery will be loaded in the target frame automatically and you can run * jQuery selectors in the target frame as if they were local. ie: $("p") instead of * $("p",top.mainFrame.document). If false, jQuery will not be loaded automatically * and you must use a context in jquery selectors. * * data: (object) An object to be passed as-is to the target frame. This is where you pass * variable data, rather than in a closure. * * load: (object or array of objects) jquery is loaded by default. You can pass a single object to * frameReady, or an array of objects that will be loaded and tested in order. 2 types * of files can be loaded. Scripts and stylesheets: * * scripts: {type:"script", src:"/js/myscript.js", id:"_ms", test:"afunction"} * stylesheets: {type:"stylesheet", src:"/css/mycss.css", id:"_ss"} * * type: (string/required) "script" for script files, "stylesheet" for stylesheets. * src: (string/required) The source of the file, ie: /js/myscript.js. * id: (string/optional) An id for the id attribute. If one isn't provided it * will be generated. * test: (sting/optional) The name of a function that should exist once the script * is loaded properly. Until this function becomes available, the script will * be considered not ready and no other files will be loaded. If a test is not * provided, the next file will be loaded immediately. Tests are not useful * with stylesheets. * * One gotcha: You must have something other than space characters within the body tags of * target frame documents for frameReady to work properly. A single character is enough. * The reason for this is a workaround for an iFrame bug in Firefox, of all things. * ============================================================================================== * * Example: * * $.frameReady(function(){ * $("
I am a div element
").prependTo("body"); * }, "top.mainFrame", * { load: [ * {type:"script",id:"_fr",src:"/js/jquery.frameReady.js",test: "$.frameReady"}, * {type:"stylesheet",id:"_ss",src:"frameReady.css"} * ] } * ); * * * Release Notes: * * 1.2.0 - Added provision for a local callback function; * Added functionality to reset frame information if frame unloads for any reason; * * 1.1.0 - Added the ability to load scripts and stylesheets inside the target frame before * processing function stack; * ****/ if (typeof $daemach == "undefined") { $daemach = {}; $daemach.debug = false; // set this to true to enable logging $daemach.log = function() { if (!top.window.console || !top.window.console.log || !$daemach.debug) { return; } else { top.window.console.log([].join.call(arguments,'')); }; }; $daemach.time = function() { if (!top.window.console || !top.window.console.time || !$daemach.debug) { return; } else { top.window.console.time([].join.call(arguments,'')); }; }; $daemach.timeEnd = function() { if (!top.window.console || !top.window.console.timeEnd || !$daemach.debug) { return; } else { top.window.console.timeEnd([].join.call(arguments,'')); }; }; }; if (typeof $daemach["frameReady"] == "undefined") { $daemach["frameReady"] = {}; }; jQuery.frameReady = function(f,t,r,j) { /************************************************************ You must specify the path to your jquery.js file below! *************************************************************/ //var jQueryPath = "/main/inc/lib/javascript/jquery.js"; var jQueryPath = jQueryFrameReadyConfigPath; // Define this configuration parameter before loading this script. var u = "undefined"; var $fr = $daemach["frameReady"]; var fn = t.split(".").join("_"); // create a branch if (typeof $fr[fn] == u) { $fr[fn] = {}; $fr[fn]["settings"] = { remote: true, jquery: true, load: [ {type:"script",id:"_jq", src:jQueryPath, test:"jQuery"} ], bLoaded: false, loadInit: [], data: {}, callback: false }; $fr[fn]["target"] = t; }; var fr = $fr[fn]; var frs = fr["settings"]; if (fr.done) { $daemach.log(fr.target + " is ready. Running functions now."); return (frs.remote) ? eval(fr.target).eval("(" + f.toString() + ")()") : f(); }; // process arguments for (var a=2;a