/**
* The PQ (Persona Quest) module provides widgets and utilities to be used with Monitus.net's PersonaQuest Tool.
*
* @module pq
* @title Persona Quest
* @namespace jMUI
* @requires util
*/
/**
* 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 jMUI
* @static
*/
jMUI.ready = false;
jMUI.pq = jMUI.pq || {};
jMUI.pq._ui = jMUI.pq._ui || function(pCallback) {
if(jQuery.ui) return true;
jMUI.internal._injectScript("https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js", pCallback);
};
jMUI.pq._getOrCreateTarget = jMUI.pq._getOrCreateTarget || function(pSelectorOrHTML) {
var vPopUp = null;
if(jMUI.pq._isQ()) {
if(pSelectorOrHTML.indexOf("[]") == 0) { // HTML snippet
var vSelector = "mui_pq_" + (new Date()).getTime();
jMUI.$("body").append("<span id='" + vSelector + "'>" + pSelectorOrHTML.replace(/^\[\]/i, "") + "</span>");
pSelectorOrHTML = "#" + vSelector;
vPopUp = jMUI.$(pSelectorOrHTML);
} else vPopUp = jMUI.$(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
*/
jMUI.pq.dialog = jMUI.pq.dialog || function(pSelectorOrHTML, pConfig) {
if(jMUI.pq._ui(function() { jMUI.pq.dialog(pSelectorOrHTML, pConfig); })) {
var vConfig = pConfig || {};
var vPopUp = jMUI.pq._getOrCreateTarget(pSelectorOrHTML);
if(!vConfig.buttons) {
var vSelector = "#" + vPopUp.attr("id");
jMUI.$('body').bind('click', function(pEvent) {
if(jMUI.$(vSelector).dialog('isOpen') && !jMUI.$(pEvent.target).is('.ui-dialog, a') && !jMUI.$(pEvent.target).closest('.ui-dialog').length) jMUI.$(vSelector).dialog('close');
});
}
vPopUp.dialog(vConfig);
if(vConfig.fixed) {
var vWidget = vPopUp.dialog("widget");
if(jMUI.$.browser.msie && document.compatMode && document.compatMode.match(/backcompat/i)) { // quirks mode
var vOffset = vWidget.offset();
vWidget.css({"position": "absolute"});
jMUI.$(window).scroll(function() {
var vWindow = jMUI.$(window);
vWidget.css({"top": vWindow.scrollTop() + vOffset.top + "px", "left": vWindow.scrollLeft() + vOffset.left + "px"});
});
} else vWidget.css({"position": "fixed"});
jMUI.$(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
*/
jMUI.pq.lightbox = jMUI.pq.lightbox || function(pSelectorOrHTML, pConfig) {
if(jMUI.pq._ui(function() { jMUI.pq.lightbox(pSelectorOrHTML, pConfig); })) {
var vConfig = pConfig || {autoShow: true};
vConfig.directory = (typeof(jMUI.monitus) != "undefined") ? jMUI.monitus.cdn_domain : "";
if(typeof(vConfig.autoShow) == "undefined") vConfig.autoShow = true;
var vPopUp = jMUI.pq._getOrCreateTarget(pSelectorOrHTML);
var vID = vPopUp.attr("id");
jMUI.$("body").append("<a id='" + vID + "_click'></a>");
var vAnchor = jMUI.$("#" + vID + "_click");
vAnchor.attr("href", "#" + vID);
vAnchor.fancyZoom(vConfig);
if(vConfig.autoShow) vAnchor.click();
return vPopUp;
}
};
jMUI.ready = true;