1/* 2 * jQuery Modal Dialog plugin 1.0 3 * Released: July 14, 2008 4 * 5 * Copyright (c) 2008 Chris Winberry 6 * Email: [email protected] 7 * 8 * Original Design: Michael Leigeber 9 * http://www.leigeber.com/2008/04/custom-javascript-dialog-boxes/ 10 * 11 * This program is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation, either version 3 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * Dual licensed under the MIT and GPL licenses: 22 * http://www.opensource.org/licenses/mit-license.php 23 * http://www.gnu.org/licenses/gpl.html 24 * 25 * @license http://www.opensource.org/licenses/mit-license.php 26 * @license http://www.gnu.org/licenses/gpl.html 27 * @project jquery.modaldialog 28 */ 29(function ($) { 30 31 var modaldialog = {} 32 33 // Creates and shows the modal dialog 34 function showDialog(msg, options) { 35 // Make sure the dialog type is valid. If not assign the default one (the first) 36 if (!$.inArray(options.type, modaldialog.DialogTypes)) { 37 options.type = modaldialog.DialogTypes[0] 38 }; 39 40 // Merge default title (per type), default settings, and user defined settings 41 var settings = $.extend({ title: modaldialog.DialogTitles[options.type] }, modaldialog.defaults, options) 42 43 // If there's no timeout, make sure the close button is show (or the dialog can't close) 44 settings.timeout = (typeof (settings.timeout) == "undefined") ? 0 : settings.timeout 45 settings.showClose = ((typeof (settings.showClose) == "undefined") | !settings.timeout) ? true : !!settings.showClose 46 settings.dlgType = (typeof (settings.dlgType) == "undefined") ? 1 : settings.dlgType 47 settings.mask = (typeof (settings.mask) == "undefined") ? 0 : settings.mask 48 49 // Check if the dialog elements exist and create them if not 50 if (!document.getElementById('dialog')) { 51 dialog = document.createElement('div') 52 dialog.id = 'dialog' 53 } 54 else { 55 $(dialog).empty() 56 57 //remove previuos callback 58 delete modaldialog.callbackFnc 59 } 60 61 htmlString = "<div id='dialog-header'>" + 62 "<div id='dialog-title'></div>" + 63 "<div id='dialog-close'></div>" + 64 "</div>" + 65 "<div id='dialog-content'>" + 66 "<div id='dialog-content-inner' />" + 67 "<div id='dialog-button-container'>" 68 69 if (typeof (settings.callbackFnc) != "undefined") { 70 htmlString += "<input type='button' id='dialog-button_callback' value='Si'>" + 71 "<input type='button' id='dialog-button' value='No'>" 72 } else if (typeof (settings.callbackFncOK) != "undefined") { 73 htmlString += "<input type='button' id='dialog-button_callback' value='OK'>" 74 } 75 else { 76 htmlString += "<input type='button' id='dialog-button' value='Chiudi'>" 77 } 78
79 // if (typeof(settings.callbackFnc) != "undefined") { 80 // htmlString+="<input type='button' id='dialog-button_callback' value='Si'>" + 81 // "<input type='button' id='dialog-button' value='No'>"; 82 // } 83 // else { 84 // htmlString+="<input type='button' id='dialog-button' value='Chiudi'>"; 85 // } 86 87 htmlString += "</div>" + 88 "</div>" 89 90 $(dialog).html(htmlString) 91 92 dialogmask = document.createElement('div') 93 dialogmask.id = 'dialog-mask' 94 95 $(dialogmask).hide() 96 $(dialog).hide() 97 98 document.body.appendChild(dialogmask) 99 document.body.appendChild(dialog) 100 101 // Set the click event for the "x" and "Close" buttons 102 $("#dialog-close").click(function(){ 103 modaldialog.hide(); 104 if (typeof (settings.callbackFnClose) != "undefined") settings.callbackFnClose(); 105 }) 106 $("#dialog-button").click(modaldialog.hide) 107 108 $("#dialog-button_callback").click(modaldialog.hide_callback) 109 110 if (typeof (settings.callbackFnc) != "undefined") 111 modaldialog.callbackFnc = settings.callbackFnc 112 if (typeof (settings.callbackFncOK) != "undefined") 113 modaldialog.callbackFnc = settings.callbackFncOK 114 115 modaldialog.mask = settings.mask 116 117 var dl = $('#dialog') 118 var dlh = $('#dialog-header') 119 var dlc = $('#dialog-content') 120 var dlb = $('#dialog-button') 121 var dlb2 = $('#dialog-button_callback') 122 123 $('#dialog-title').html(settings.title) 124 $('#dialog-content-inner').html(msg) 125 126 // Center the dialog in the window but make sure it's at least 25 pixels from the top 127 // Without that check, dialogs that are taller than the visible window risk 128 // having the close buttons off-screen, rendering the dialog unclosable 129 dl.css('width', settings.width) 130 131 if (typeof (settings.height) != "undefined") 132 dl.css('height', settings.height) 133 134 var dialogTop = Math.abs($(window).height() - dl.height()) / 2 135 136 dl.css('left', ($(window).width() - dl.width()) / 2) 137 if (typeof (settings.top) == "undefined" || settings.top == 0) 138 dl.css('top', (dialogTop >= 25) ? dialogTop : 25) 139 else 140 dl.css('top', settings.top + 'px') 141 142 // Clear the dialog-type classes and add the current dialog-type class 143 if (typeof (dlc.attr('class')) != "undefined") 144 dlc.removeClass(dlc.attr('class')) 145 146 if (typeof (dlh.attr('class')) != "undefined") 147 dlh.removeClass(dlh.attr('class')) 148 149 if (typeof (dlb.attr('class')) != "undefined") 150 dlb.removeClass(dlb.attr('class')) 151 152 if (typeof (dlb2.attr('class')) != "undefined") 153 dlb2.removeClass(dlb.attr('class')) 154 155 dlh.addClass(settings.type + "header") 156 dlc.addClass(settings.type) 157 dlb.addClass(settings.type + "button") 158 dlb2.addClass(settings.type + "button") 159 160 161 if (!settings.showClose) { 162 $('#dialog-close').hide() 163 $('#dialog-button-container').hide() 164 } else { 165 $('#dialog-close').show() 166 $('#dialog-button-container').show() 167 } 168 169 if (settings.timeout) { 170 window.setTimeout("$('#dialog').fadeOut('slow', 0); $('#dialog-mask').fadeOut('normal', 0);", (settings.timeout * 1000)) 171 } 172 173 dl.fadeIn("slow") 174 //$('#dialog-mask').fadeIn("slow",function() {$('#dialog-mask').attr("style","zoom: 1; display: block;");}); 175 //patch error IE 176 $('#dialog-mask').show().attr("style", "zoom: 1; display: block;") 177 dl.draggable() 178 }; 179 180 modaldialog.error = function $$modaldialog$error(msg, options) { 181 if (typeof (options) == "undefined") { 182 options = {} 183 } 184 options['type'] = "error" 185 return (showDialog(msg, options)) 186 } 187 modaldialog.warning = function $$modaldialog$error(msg, options) { 188 if (typeof (options) == "undefined") { 189 options = {} 190 } 191 options['type'] = "warning" 192 return (showDialog(msg, options)) 193 } 194 modaldialog.success = function $$modaldialog$error(msg, options) { 195 if (typeof (options) == "undefined") { 196 options = {} 197 } 198 options['type'] = "success" 199 return (showDialog(msg, options)) 200 } 201 modaldialog.prompt = function $$modaldialog$error(msg, options) { 202 if (typeof (options) == "undefined") { 203 options = {} 204 } 205 options['type'] = "prompt" 206 return (showDialog(msg, options)) 207 } 208 modaldialog.info = function $$modaldialog$error(msg, options) { 209 if (typeof (options) == "undefined") { 210 options = {} 211 } 212 options['type'] = "info" 213 return (showDialog(msg, options)) 214 } 215 modaldialog.hide = function $$modaldialog$hide() { 216 $('#dialog').fadeOut("slow", function () { $(this).hide(0) }) 217 $('#dialog-mask').fadeOut("normal", function () { $(this).hide(0) }) 218 $('#dialog-content').empty() 219 } 220 221 modaldialog.hide_callback = function $$modaldialog$hide_callback() { 222 $('#dialog').fadeOut("slow", function () { 223 224 $(this).hide(0, function () { 225 if (typeof (modaldialog.callbackFnc) != "undefined") 226 modaldialog.callbackFnc() 227 }) 228 }) 229 230 if (modaldialog.mask == 0) 231 $('#dialog-mask').fadeOut("normal", function () { $(this).hide(0) }) 232 } 233 234 modaldialog.DialogTypes = new Array("error", "warning", "success", "prompt", "info") 235 modaldialog.DialogTitles = { 236 "error": "Errore", 237 "warning": "Attenzione", 238 "success": "Successo", 239 "prompt": "Scelta utente", 240 "info": "Nota informativa" 241 } 242 243 modaldialog.defaults = { 244 timeout: 0, 245 showClose: true, 246 width: 525 247 } 248 249 $.extend({ modaldialog: modaldialog }) 250})(jQuery)
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.