/*------------------------------------------------------------------------------
JS Document (https://developer.mozilla.org/en/JavaScript)
project: majx JavaScript Library http://code.google.com/p/majx-js/
license: New BSD License http://www.opensource.org/licenses/bsd-license.php
author: Copyright (c) 2009
Yves Van Goethem and Vincent Valentin
All rights reserved.
module: customizable popins (modal boxes)
summary: CONFIG
DOM.READY
POPIN
----------------------------------------------------------------------------- */
/* =CONFIG
------------------------------------------------------------------------------*/
var w = window;
var d = document;
majx.set({
popin1 : {
target : '.popin', // target links with this class (CSS 3 Selectors)
name : {
popin : 'popin', // the popin id
cache : 'cache', // the popin cache id
close : 'close', // the close button idf
content : 'pop-content' // the id where to extract the code in the target page.
},
behaviours : {
closeClick : true, // if true permits to click outside the popin to close it
close : '
', // close button, you can also include HTML code
anim : true, // true by default, false avoids fadeIn
resize : false // experimental to refit the popin when the window is resized
},
style : {
marginMax : 50, // minimum margin between the popin and the window
opacity : 0.50, // cache final opacity
maxWidth : 250, // minimal screen width to open popins
maxHeight : 250 // minimal screen height to open popins
}/*,
callback : { // events
onload : externFnLoad,
onunload : externFnUnload,
onbeforeload : externFnBeforeLoad,
onreload : externFnReload
}*/
}
});
/* =DOM.READY
------------------------------------------------------------------------------*/
jQuery(document).ready(function() {
popin1 = new popin(majx.config.popin1);
});
/* =POPIN
------------------------------------------------------------------------------*/
var popinMemorize = {
activeLink : null
};
function popin(config) {
var targetLink = config.target;
var id_popin = config.name.popin;
var id_cache = config.name.cache;
var id_close = config.name.close;
var id_content = config.name.content;
var marginMax = config.style.marginMax || 50; // popin margin
var marginIE6 = config.style.marginIE6 || 50; // IE 6 fix
var opacity = config.style.opacity;
var maxWidth = config.style.maxWidth;
var maxHeight = config.style.maxHeight;
var pop_hash = config.behaviours.hash || 'pop';
var closeStr = config.behaviours.close;
var innerLoad = config.behaviours.innerLoad || true;
var anim = config.behaviours.anim || true;
var resize = config.behaviours.resize || false; // EXPERIMENTAL /
var anchor = config.behaviours.anchor || false; // EXPERIMENTAL / handling location hash
var closeClick = config.behaviours.closeClick || false;
// var loadImage = new Image();
// if (config.behaviours.loadingImage) {
// loadImage.src = config.behaviours.loadingImage.src || null;
// loadImage.alt = config.behaviours.loadingImage.alt || null;
// loadImage.id = config.name.loadimg || null;
// }
if (config.callback) {
var callOnunload = config.callback.onunload || null;
var callOnload = config.callback.onload || null;
var callReload = config.callback.onreload || null;
var callOnBeforeLoad = config.callback.onbeforeload || null;
}
var popin = null;
var popinCache = null;
var body = jQuery('body');
var url, parametres, paramets, params, iparam = null; // ugly!!!
var globs = {
callerElm : null,
popinLoaded : 0
};
var utils = {
getWindowDimensions : function(dimension) {
var dimension = dimension.substr(0, 1).toUpperCase() + dimension.substr(1);
var result = 0;
if (typeof(w['inner'+dimension]) == "number") {
// Standard Browsers
var result = w['inner'+dimension];
}
else if (d.documentElement && d.documentElement['client'+dimension]) {
// IE 6+ in standard mode
var result = d.documentElement['client'+dimension];
}
return result;
},
fixDimensions : function(dimension, direction) {
if (utils.getWindowDimensions(dimension) < popin[dimension]()) {
popin.css(dimension,(utils.getWindowDimensions(dimension) - marginMax) + "px");
popin.css("margin-"+direction,"-" + Math.round((utils.getWindowDimensions(dimension) - marginMax)/2) + "px");
}
},
getScrollPositions : function(axis) {
var axis = axis.toUpperCase();
var axis2 = (axis == 'Y') ? 'Top' : 'Left';
var result = 0;
if (typeof w['page'+axis+'Offset'] == "number") {
result = w['page'+axis+'Offset'];
}
else if (d.body && d.body['scroll'+axis2]) {
result = d.body['scroll'+axis2];
}
else if (d.documentElement && d.documentElement['scroll'+axis2]) {
result = d.documentElement['scroll'+axis2];
}
return result;
},
setLinks : function(elm, inner) {
// update this to a resolution check, rather than to a window size check ?
if (!((utils.getWindowDimensions('width') < maxWidth)
|| (utils.getWindowDimensions('height') < maxHeight))) {
if (!popin && typeof callOnBeforeLoad == 'function') {
callOnBeforeLoad();
}
var options = {
inner : inner
};
openPopin(jQuery(elm), options);
}
}
};
function openPopin(elm, options) {
var focusElm = null; // a DOM element where the focus is applied on close
var inner = false; // if true permits inner reloads
if (options) {
if (options.focusElm) {
focusElm = options.focusElm;
}
if (options.inner) {
inner = true;
}
}
url = null;
var setUrl = function(){
if (typeof elm == 'string') {
popinMemorize.activeLink = jQuery(focusElm) || body;
url = elm;
}
else if (typeof elm == 'object') {
if (elm[0] && elm[0].action) { // if elm is in DOM and has action
if (!document.getElementById(id_popin)) {
popinMemorize.activeLink = elm;
}
url = elm.attr('action');
globs.callerElm = elm;
}
else if (elm[0] && elm[0].href) { // if elm is in DOM and has href
if (!document.getElementById(id_popin)) {
popinMemorize.activeLink = elm;
}
url = elm.attr('href');
globs.callerElm = elm;
}
else {
throw('Popin : openPopin() Argument Type Error');
return;
}
}
else {
throw('Popin : openPopin() Argument Type Error');
return;
}
}();
// ugly!!!
parametres = (url.slice(url.indexOf("?") + 1)).split("&");
paramets = [];
params = [];
iparam = 0;
var handleWindowLocation = function() {
// ugly!!!
for (var i = 0, n = parametres.length; i < n; i++) {
paramets[iparam] = parametres[i].split("=")[0];
iparam++;
paramets[iparam] = parametres[i].split("=")[1];
iparam++;
}
for (var i = 0, n = paramets.length; i < n; i++) {
var chaine = paramets[i];
i++;
params[chaine] = paramets[i];
}
}();
var setBehaviours = function() {
if (typeof inner != 'undefined' && inner == true) {
var oContent = jQuery('#'+id_content);
oContent.empty();
// oContent.append(loadImage); // breaks focus on Jaws
// oContent.show(); // breaks focus on Jaws
return;
}
if (popin && popinCache) {
closePopin(true);
}
}();
var buildHTML = function() {
if (typeof inner != 'undefined' && inner == true) {
return;
}
body.append('
Message : '+ textStatus + '
' + 'ReadyState : '+ XHR.readyState + '
' + 'Status : '+ XHR.status + '
' + '