/* * jQuery Frame Dialog 1.1.2 * * Copyright (c) 2009 SolutionStream.com & Michael J. Ryan (http://www.solutionstream.com/) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * Requires: * jquery ui dialog * * jQuery.FrameDialog namespaced * .create() function will create an iframe, pass on the options * and return from a jQueryUI Dialog. * additional url option * * TODO: - Add logic to allow for relative URLs. * * CUSTOMIZATION: * see FrameDialog._defaultOptions below for additional changes from ui dialog defaults * Returns a jQuery.dialog extension, with the same options passed in. * * refer to jQueryUI Dialog for more customization options * * * LOCALIZATION: create a window.localization object * localization.OK override text for the OK button * localization.Cancel override text for the Cancel button * * * FROM PARENT WINDOW: use the full url, including protocol://host/ portions * jQuery.FrameDialog * .create({ * url: baseURL + 'framed-modal-test.aspx', * title: 'test title', * ... Other jQueryUI Dialog Options ... * }) * .bind('dialogclose', function(event, ui) { * alert("result: " + event.result); * }); * * INSIDE MODAL: * jQuery.FrameDialog.setResult(value); //sets the result value * jQuery.FrameDialog.clearResult(); //clears the result value * jQuery.FrameDialog.closeDialog(); //close the dialog (same as OK) * jQuery.FrameDialog.cancelDialog(); //cancel the dialot (same as Cancel * * * * !!!!!!!!!! WARNING WARNING WARNING WARNING !!!!!!!!!! * Modal must set the result from the same host address in order to access * the parent for setting the result. */ (function($) { //create FrameDialog namespace $.FrameDialog = $.FrameDialog || {}; //array for return values, placeholder $.FrameDialog._results = $.FrameDialog._results || {}; $.FrameDialog._arguments = $.FrameDialog._arguments || {}; $.FrameDialog._frames = $.FrameDialog._frames || []; //set localized variables var OK = (window.localization && window.localization.OK) || "OK"; var Cancel = (window.localization && window.localization.CANCEL) || "Cancel"; var buttons = {}; //remove default button // buttons[OK] = function() { // $(this).dialog("close"); // } // buttons[Cancel] = function() { // var frame = $(this); // $.FrameDialog.clearResult(frame.attr("id")); // frame.dialog("close"); // } //default options $.FrameDialog._defaultOptions = { modal: true, closeOnEscape: false, position: 'center', buttons: buttons }; var retry = false; $.FrameDialog.create = function(options) { try { //generate unique id var uid = Math.random().toString(16).replace(".", "") + (new Date()).valueOf().toString(16); //extend frame dialog options with passed in options. var opts = $.extend( $.FrameDialog._defaultOptions, options || {} ); var url = (opts && opts.url) || null; if (url === null) throw new Error("MODAL ERROR: Option 'url' not specified!"); //diagnostic error //clean up redundant forward slashes in the url. url = url.replace(/(^|[^:])\/+/g, "$1/"); //remove url argument from options to be passed to dialog. try { delete opts.url; } catch (err) { } // set arguments $.FrameDialog._arguments[uid] = opts.args; $.FrameDialog._frames.push(uid); //create iframe object // object type="text/html doesn't seem to work in IE :( // using iframe, which seems to work cross browser, tested in IE7, and Firefox 3.0.7 var iframe = $("