Monitus UI Library

Persona Quest  4

Monitus UI Library > pq > mui_pq.js (source view)
Search:
 
Filters
/**
 * The PQ (Persona Quest) module provides widgets and utilities to be used with Monitus.net's PersonaQuest Tool. NOTE: It requires the ldn.monitus.net/jquery.css and ldn.monitus.net/jquery.js files
 * 
 * @module pq
 * @title Persona Quest
 * @namespace MUI
 * @requires util
 */

if(typeof(MUI) != "undefined") {
	if(typeof(MUI.pq) == "undefined") {
		/**
		 * The PQ (Persona Quest) module provides widgets and utilities to be used with Monitus.net's PersonaQuest Tool. NOTE: It requires the ldn.monitus.net/jquery.css and ldn.monitus.net/jquery.js files
		 *
		 * @class pq
		 * @namespace MUI
		 * @static
		 */
		MUI.pq = {
			_q: null,
			_isQ : function() {
				if(MUI.pq._q) return true;
				if(typeof(monitus_jquery) != "undefined") {
					MUI.pq._q = monitus_jquery;
					return true;
				}
				return false;
			},
			_getOrCreateTarget: function(pSelectorOrHTML) {
				var vPopUp = null;
				if(MUI.pq._isQ()) {
					if(pSelectorOrHTML.indexOf("[]") == 0) {
						var vSelector = "mui_pq_" + (new Date()).getTime();
						MUI.pq._q("body").append("<span id='" + vSelector + "'>" + pSelectorOrHTML.replace(/^\[\]/i, "") + "</span>");
						pSelectorOrHTML = "#" + vSelector;
						vPopUp = MUI.pq._q(pSelectorOrHTML);
					} else vPopUp = MUI.pq._q(pSelectorOrHTML);
				}
				return vPopUp;
			},
			
			/**
			 * Creates (and optionally displays) a non-blockable dialog.
			 *
			 * @method dialog
			 *
			 * @param {string} pSelectorOrHTML a jQuery selector of the element to use as the dialog OR HTML to use as the dialog's content. (for HTML content, prepend your content with [])
			 * @param {object} pConfig the configuration to apply to the dialog. Optional. (See http://jqueryui.com/demos/dialog for parameters) NOTE: the special "fixed" configuration option will make the dialog a fixed element on the page.
			 *
			 * @return {dialog object} returns the dialog object.
			 *
			 * @static
			 */
			dialog: function(pSelectorOrHTML, pConfig) {
				if(MUI.pq._isQ()) {
					var vConfig = pConfig || {};
					var vPopUp = MUI.pq._getOrCreateTarget(pSelectorOrHTML);
					if(!vConfig.buttons) {
						var vSelector = "#" + vPopUp.attr("id");
						MUI.pq._q('body').bind('click', function(pEvent) {
							if(MUI.pq._q(vSelector).dialog('isOpen') && !MUI.pq._q(pEvent.target).is('.ui-dialog, a') && !MUI.pq._q(pEvent.target).closest('.ui-dialog').length) MUI.pq._q(vSelector).dialog('close');
						});
					}
					vPopUp.dialog(vConfig);
					
					if(vConfig.fixed) {
						var vWidget = vPopUp.dialog("widget");
						if(MUI.pq._q.browser.msie && document.compatMode && document.compatMode.match(/backcompat/i)) { // quirks mode
							window.monitus_browser_mode = "quirskmode";
							var vOffset = vWidget.offset();
							vWidget.css({"position": "absolute"});
							MUI.pq._q(window).scroll(function() {
								var vWindow = MUI.pq._q(window);
								vWidget.css({"top": vWindow.scrollTop() + vOffset.top + "px", "left": vWindow.scrollLeft() + vOffset.left + "px"});
							});
						} else vWidget.css({"position": "fixed"});
						MUI.pq._q(window).resize(function() { vPopUp.dialog("option", "position", vPopUp.dialog("option", "position")); });
					}
					
					return vPopUp;
				}
			},
			/**
			 * Creates and displays a lightbox that can be closed by clicking anywhere outside of it.
			 *
			 * @method lightbox
			 *
			 * @param {string} pSelectorOrHTML a jQuery selector of the element to use as the dialog OR HTML to use as the dialog's content. (for HTML content, prepend your content with [])
			 * @param {object} pConfig the configuration to apply to the dialog. Optional. (See http://orderedlist.com/blog/articles/fancyzoom-meet-jquery/ for parameters)
			 *
			 * @return {dialog object} returns the dialog object.
			 *
			 * @static
			 */
			lightbox: function(pSelectorOrHTML, pConfig) {
				if(MUI.pq._isQ()) {
					var vConfig = pConfig || {autoShow: true};
					vConfig.directory = monitus_script_domain;
					if(typeof(vConfig.autoShow) == "undefined") vConfig.autoShow = true;
					
					var vPopUp = MUI.pq._getOrCreateTarget(pSelectorOrHTML);
					var vID = vPopUp.attr("id");
					MUI.pq._q("body").append("<a id='" + vID + "_click'></a>");
					var vAnchor = MUI.pq._q("#" + vID + "_click");
					vAnchor.attr("href", "#" + vID);
					vAnchor.fancyZoom(vConfig);
					if(vConfig.autoShow) vAnchor.click();
					
					return vPopUp;
				}
			}
		};
	}
}

Copyright © 2013 Yahoo! Inc. All rights reserved.