/* Name: jQuery Koujala Overlay Plugin Version: 1.3 Last Updated: 01/28/2010 Author: Murali Koujala Copyright(c): 2010 License: Dual licensed under the MIT and GPL licenses: http://www.opensource.org/licenses/mit-license.php http://www.gnu.org/licenses/gpl.html Usage: For dynamically created content on DOM set dynamic attribute to true (apply this when the dynamic content is not to be retained on the page) $("selector").koverlay({title: ''title1', dynamic: true}) For static content (renderred by server code) $("selector").koverlay({title: ''title1'}) For hiding the overlay $("selector").koverlay.hide() */ (function($) { $.fn.koverlay = function(options) { //koverlay Plugin CSS Start; var css_koverlay = { "border": "solid 1px gray", "background-color": "#97B9FF", "width": "650px" }; var css_koverlayheader = { "font-family": "Verdana, sans-serif", "font-size": "22px", "font-weight": "normal", "color": "#fff" }; var css_koverlaybutton = { "font-family": "Verdana, sans-serif", "font-size": "14px", "font-weight": "bold", "color": "#000" }; var css_koverlaycontent = { "padding": "5px", "color": "#000", "border": "solid 1px gray", "background-color": "#FFF", "font-family": "Verdana, sans-serif", "font-size": "12px" }; //koverlay Plugin CSS End; function template() { var html = []; html[html.length] = ''; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = ' '; html[html.length] = '
'; html[html.length] = '
'; html[html.length] = '
'; html[html.length] = ' '; html[html.length] = '
'; html[html.length] = '
'; html[html.length] = '
'; return html.join(''); }; if (this.length > 1) { var html = []; html[html.length] = ''; $(document.body).append(html.join('')); $("#__koujalaMessage").koverlay({ title: "Error", background: true }); return; } //defaults; var defaults = { background: true, scroll: false, title: 'Title', dynamic: false }; //apply user settings to defaults; options = $.extend(defaults, options); //disable the window scroll $(document.body).css({ overflow: 'hidden' }); //load the overlay background div element once; var id_background = '__koujalaBackground'; if ($('#' + id_background).size() == 0) { //append the overlay background element to document body; $(document.body).append('
'); $('#' + id_background).css({ 'position': 'absolute', 'top': '0px', 'left': '0px' }); $('#' + id_background).css({ 'display': 'none' }); $('#' + id_background).css({ 'z-index': '9998' }); $('#' + id_background).css({ 'height': $(window).height() }); $('#' + id_background).css({ 'width': $(window).width() }); } //apply background rules for new set of overlays; if (options.background == true) { $('#' + id_background).css({ 'background-color': 'black' }); $('#' + id_background).css({ 'opacity': '0.80' }); } else { $('#' + id_background).css({ 'background-color': 'white' }); $('#' + id_background).css({ 'opacity': '0.0' }); } //check if there are overlay divs loaded already; var id_overlay = '__koujalaOverlay'; var intCount = $('div[id^="__koujalaOverlay"]').size(); if (intCount > 0) { $('#' + id_overlay + eval(intCount - 1)).fadeOut(500); } //Set a new ID for overlay div; id_overlay = '__koujalaOverlay' + intCount; //load the overlay div element; var html = []; html[html.length] = '
'; //append the overlay element to document body; $(document.body).append(html.join('')); //append the html for overlay layout to div overlay; $('#' + id_overlay).html(template()); //now apply css classes to elements $('#' + id_overlay + ' .css_koverlay').css(css_koverlay); $('#' + id_overlay + ' .css_koverlayheader').css(css_koverlayheader); $('#' + id_overlay + ' .css_koverlaybutton').css(css_koverlaybutton); $('#' + id_overlay + ' .css_koverlaycontent').css(css_koverlaycontent); //update the content placeholder element with html from the element; $('#' + id_overlay + ' .css_koverlayheader').html(options.title); //move actual node to inside overlay container node $('#' + id_overlay + ' .css_koverlaycontent').append($(this.selector)); $(this.selector).css("display", "block"); $(this.selector).css("dynamic", options.dynamic); $('#' + id_overlay).css({ 'position': 'absolute', 'display': 'none', 'z-index': '9999' }); //get the height and width of the overlay; var intHeight = $('#' + id_overlay).height(); var intWidth = $('#' + id_overlay).width(); $('#' + id_overlay).css('height', '625px'); $('#' + id_overlay).css('width', intWidth); $('#' + id_overlay).css('top', ($(window).height() - intHeight) / 2); $('#' + id_overlay).css('left', ($(window).width() - intWidth) / 2); $(window).resize(function() { var intTop = $(window).scrollTop(); var scrollTop = $(window).scrollTop(); $('#' + id_overlay).css('top', ($(window).height() - intHeight) / 2 + scrollTop); $('#' + id_overlay).css('left', ($(window).width() - intWidth) / 2); $('#__koujalaBackground').css('height', $(window).height() + intTop); $('#__koujalaBackground').css('width', $(window).width()); }); $(window).scroll(function() { return false; $(window).trigger('resize'); }); //trigger resize to ensure scroll heights are taken into account; $(window).trigger('resize'); $(window).trigger('resize'); //display the overlay background; $('#__koujalaBackground').fadeIn(250); //display the overlay now; $('#' + id_overlay).fadeIn(500); return this; }; $.fn.koverlay.hide = function() { var id_background = '__koujalaBackground'; var id_overlay = '__koujalaOverlay'; var intCount = $('div[id^="__koujalaOverlay"]').size(); if (intCount < 2) { $('#' + id_background).fadeOut(500); //enable the window scroll $(document.body).css({ overflow: 'auto' }); } else { id_overlay = '__koujalaOverlay' + eval(intCount - 2); $('#' + id_overlay).fadeIn(250); } id_overlay = '__koujalaOverlay' + eval(intCount - 1); $('#' + id_overlay).fadeOut(250); //get the id of actual overlay div var id = $('#' + id_overlay + ' .css_koverlaycontent div').attr("id"); //find out if the overlay is meant to be dynamic, if yes we do not need to retain the DIV var blnRemove = $('#' + id).css("dynamic"); if (!blnRemove) { $(document.body).append($('#' + id)); $('#' + id).css("display", "none"); } $('#' + id_overlay).remove(); }; })(jQuery); (function($) { $.fn.kcookie = function() { return this; }; $.fn.kcookie.read = function(strCookieField) { var strCookie = '; ' + document.cookie + '; '; var intBegin = strCookie.indexOf('; ' + strCookieField + '='); if (intBegin !== -1) { var val_begin = (intBegin * -1 - strCookieField.length - 3) * -1; var qs_val = strCookie.substring(val_begin, strCookie.indexOf('; ', val_begin)); if (qs_val !== '') { return unescape(qs_val.replace(/\+/g, ' ')); } else { return ''; } } else { return ''; } }; $.fn.kcookie.create = function(name, value, mins) { var expires = ''; if (mins) { var date = new Date(); date.setTime(date.getTime() + (mins * 60 * 1000)); expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires + '; path=/'; } })(jQuery); (function($) { $.fn.kjson = function(idScript, urlScript) { var elementHead = document.getElementsByTagName("head").item(0); var elementScript = document.getElementById(idScript); if (elementScript) { elementHead.removeChild(elementScript); } elementScript = document.createElement("script"); elementScript.setAttribute("id", idScript); elementScript.setAttribute("type", "text/javascript"); elementScript.setAttribute("charset", "utf-8"); elementScript.setAttribute("src", urlScript); elementHead.appendChild(elementScript); } })(jQuery); (function($) { var logger = []; $.fn.klog = function(strMessage) { logger[logger.length] = strMessage; } $.fn.klog.display = function() { var arrHtml = []; arrHtml[arrHtml.length] = '
'; for (var i = 0; i < logger.length; i++) { arrHtml[arrHtml.length] = logger[i] + '
'; } arrHtml[arrHtml.length] = '
'; $(document.body).append(arrHtml.join('')); $('#id_log1').koverlay({ title: "Log Viewer" }); } })(jQuery); $(document).keyup(function(e) { if (e.ctrlKey && e.shiftKey && e.keyCode == 76) { $().klog.display(); } if (e.keyCode == 27) { $().koverlay.hide(); } });