(function($){ //closeDOMWindow $.fn.closeDOMWindow = function(settings){ if(!settings){settings={};} var run = function(passingThis){ if(settings.anchoredClassName){ var $anchorClassName = $('.'+settings.anchoredClassName); $anchorClassName.fadeOut('fast',function(){ if($.fn.draggable){ $anchorClassName.draggable('destory').trigger("unload").remove(); }else{ $anchorClassName.trigger("unload").remove(); } }); if(settings.functionCallOnClose){settings.functionCallAfterClose();} }else{ var $DOMWindowOverlay = $('#DOMWindowOverlay'); var $DOMWindow = $('#DOMWindow'); $DOMWindowOverlay.fadeOut('fast',function(){ $DOMWindowOverlay.trigger('unload').unbind().remove(); }); $DOMWindow.fadeOut('fast',function(){ if($.fn.draggable){ $DOMWindow.draggable("destroy").trigger("unload").remove(); }else{ $DOMWindow.trigger("unload").remove(); } }); $(window).unbind('scroll.DOMWindow'); $(window).unbind('resize.DOMWindow'); if($.fn.openDOMWindow.isIE6){$('#DOMWindowIE6FixIframe').remove();} if(settings.functionCallOnClose){settings.functionCallAfterClose();} } }; if(settings.eventType){//if used with $(). return this.each(function(index){ $(this).bind(settings.eventType, function(){ run(this); return false; }); }); }else{//else called as $.function run(); } }; //allow for public call, pass settings $.closeDOMWindow = function(s){$.fn.closeDOMWindow(s);}; //openDOMWindow $.fn.openDOMWindow = function(instanceSettings){ var shortcut = $.fn.openDOMWindow; //default settings combined with callerSettings//////////////////////////////////////////////////////////////////////// shortcut.defaultsSettings = { anchoredClassName:'', anchoredSelector:'', borderColor:'#ccc', borderSize:'4', draggable:0, eventType:null, //click, blur, change, dblclick, error, focus, load, mousedown, mouseout, mouseup etc... fixedWindowY:100, functionCallOnOpen:null, functionCallOnClose:null, height:500, loader:0, loaderHeight:0, loaderImagePath:'', loaderWidth:0, modal:0, overlay:1, overlayColor:'#000', overlayOpacity:'85', positionLeft:0, positionTop:0, positionType:'centered', // centered, anchored, absolute, fixed width:500, windowBGColor:'#fff', windowBGImage:null, // http path windowHTTPType:'get', windowPadding:10, windowSource:'inline', //inline, ajax, iframe windowSourceID:'', windowSourceURL:'', windowSourceAttrURL:'href' }; var settings = $.extend({}, $.fn.openDOMWindow.defaultsSettings , instanceSettings || {}); //Public functions shortcut.viewPortHeight = function(){ return self.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;}; shortcut.viewPortWidth = function(){ return self.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;}; shortcut.scrollOffsetHeight = function(){ return self.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;}; shortcut.scrollOffsetWidth = function(){ return self.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft;}; shortcut.isIE6 = typeof document.body.style.maxHeight === "undefined"; //Private Functions///////////////////////////////////////////////////////////////////////////////////////////////////////// var sizeOverlay = function(){ var $DOMWindowOverlay = $('#DOMWindowOverlay'); if(shortcut.isIE6){//if IE 6 var overlayViewportHeight = document.documentElement.offsetHeight + document.documentElement.scrollTop - 4; var overlayViewportWidth = document.documentElement.offsetWidth - 21; $DOMWindowOverlay.css({'height':overlayViewportHeight +'px','width':overlayViewportWidth+'px'}); }else{//else Firefox, safari, opera, IE 7+ $DOMWindowOverlay.css({'height':'100%','width':'100%','position':'fixed'}); } }; var sizeIE6Iframe = function(){ var overlayViewportHeight = document.documentElement.offsetHeight + document.documentElement.scrollTop - 4; var overlayViewportWidth = document.documentElement.offsetWidth - 21; $('#DOMWindowIE6FixIframe').css({'height':overlayViewportHeight +'px','width':overlayViewportWidth+'px'}); }; var centerDOMWindow = function() { var $DOMWindow = $('#DOMWindow'); if(settings.height + 50 > shortcut.viewPortHeight()){//added 50 to be safe $DOMWindow.css('left',Math.round(shortcut.viewPortWidth()/2) + shortcut.scrollOffsetWidth() - Math.round(($DOMWindow.outerWidth())/2)); }else{ $DOMWindow.css('left',Math.round(shortcut.viewPortWidth()/2) + shortcut.scrollOffsetWidth() - Math.round(($DOMWindow.outerWidth())/2)); $DOMWindow.css('top',Math.round(shortcut.viewPortHeight()/2) + shortcut.scrollOffsetHeight() - Math.round(($DOMWindow.outerHeight())/2)); } }; var centerLoader = function() { var $DOMWindowLoader = $('#DOMWindowLoader'); if(shortcut.isIE6){//if IE 6 $DOMWindowLoader.css({'left':Math.round(shortcut.viewPortWidth()/2) + shortcut.scrollOffsetWidth() - Math.round(($DOMWindowLoader.innerWidth())/2),'position':'absolute'}); $DOMWindowLoader.css({'top':Math.round(shortcut.viewPortHeight()/2) + shortcut.scrollOffsetHeight() - Math.round(($DOMWindowLoader.innerHeight())/2),'position':'absolute'}); }else{ $DOMWindowLoader.css({'left':'50%','top':'50%','position':'fixed'}); } }; var fixedDOMWindow = function(){ var $DOMWindow = $('#DOMWindow'); $DOMWindow.css('left', settings.positionLeft + shortcut.scrollOffsetWidth()); $DOMWindow.css('top', + settings.positionTop + shortcut.scrollOffsetHeight()); }; var showDOMWindow = function(instance){ if(arguments[0]){ $('.'+instance+' #DOMWindowLoader').remove(); $('.'+instance+' #DOMWindowContent').fadeIn('fast',function(){if(settings.functionCallOnOpen){settings.functionCallOnOpen();}}); $('.'+instance+ '.closeDOMWindow').click(function(){ $.closeDOMWindow(); return false; }); }else{ $('#DOMWindowLoader').remove(); $('#DOMWindow').fadeIn('fast',function(){if(settings.functionCallOnOpen){settings.functionCallOnOpen();}}); $('#DOMWindow .closeDOMWindow').click(function(){ $.closeDOMWindow(); return false; }); } }; var urlQueryToObject = function(s){ var query = {}; s.replace(/b([^&=]*)=([^&=]*)b/g, function (m, a, d) { if (typeof query[a] != 'undefined') { query[a] += ',' + d; } else { query[a] = d; } }); return query; }; //Run Routine /////////////////////////////////////////////////////////////////////////////////////////////////////////////// var run = function(passingThis){ //get values from element clicked, or assume its passed as an option settings.windowSourceID = $(passingThis).attr('href') || settings.windowSourceID; settings.windowSourceURL = $(passingThis).attr(settings.windowSourceAttrURL) || settings.windowSourceURL; settings.windowBGImage = settings.windowBGImage ? 'background-image:url('+settings.windowBGImage+')' : ''; var urlOnly, urlQueryObject; if(settings.positionType == 'anchored'){//anchored DOM window var anchoredPositions = $(settings.anchoredSelector).position(); var anchoredPositionX = anchoredPositions.left + settings.positionLeft; var anchoredPositionY = anchoredPositions.top + settings.positionTop; $('body').append('