1/* 2 * jqModal - Minimalist Modaling with jQuery 3 * 4 * Copyright (c) 2007-2014 Brice Burgess @iceburg_net 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 * 9 * $Version: 1.0.2 (2014.04.10 +r19) 10 * Requires: jQuery 1.2.3+ 11 */ 12 13(function($) { 14 15 /** 16 * Initialize a set of elements as "modals". Modals typically are popup dialogs, 17 * notices, modal windows, &c. 18 * 19 * @name jqm 20 * @param options user defined options, augments defaults. 21 * @type jQuery 22 * @cat Plugins/jqModal 23 */ 24 25 $.fn.jqm=function(options){ 26 27 var o = $.extend({}, $.jqm.params, options); 28 29 return this.each(function(){ 30 var e = $(this), 31 jqm = $(this).data('jqm'); 32 33 if(!jqm) jqm = {ID: I++}; 34 35 // add/extend options to modal and mark as initialized 36 e.data('jqm',$.extend(o,jqm)).addClass('jqm-init'); 37 38 // ... Attach events to trigger showing of this modal 39 o.trigger&&$(this).jqmAddTrigger(o.trigger); 40 }); 41 }; 42 43 44 /** 45 * Matching modals will have their jqmShow() method fired by attaching a 46 * onClick event to elements matching `trigger`. 47 * 48 * @name jqmAddTrigger 49 * @param trigger a selector String, jQuery collection of elements, or a DOM element. 50 */ 51 $.fn.jqmAddTrigger=function(trigger){ 52 return this.each(function(){ 53 if(!addTrigger($(this), 'jqmShow', trigger)) 54 err("jqmAddTrigger must be called on initialized modals") 55 }); 56 }; 57 58 59 /** 60 * Matching modals will have their jqmHide() method fired by attaching an 61 * onClick event to elements matching `trigger`. 62 * 63 * @name jqmAddClose 64 * @param trigger a selector String, jQuery collection of elements, or a DOM element. 65 */ 66 $.fn.jqmAddClose=function(trigger){ 67 return this.each(function(){ 68 if(!addTrigger($(this), 'jqmHide', trigger)) 69 err("jqmAddClose must be called on initialized modals") 70 }); 71 }; 72 73 74 /** 75 * Open matching modals (if not shown) 76 */ 77 $.fn.jqmShow=function(trigger){ 78 return this.each(function(){ !this._jqmShown&&show($(this), trigger); }); 79 }; 80 81 /** 82 * Close matching modals 83 */ 84 $.fn.jqmHide=function(trigger){ 85 return this.each(function(){ this._jqmShown&&hide($(this), trigger); }); 86 }; 87 88 89 // utility functions 90 91 var 92 err = function(msg){ 93 if(window.console && window.console.error) window.console.error(msg); 94 95 96 }, show = function(e, t){ 97 98 /** 99 * e = modal element (as jQuery object) 100 * t = triggering element 101 * 102 * o = options 103 * z = z-index of modal 104 * v = overlay element (as jQuery object) 105 * h = hash (for jqModal <= r15 compatibility) 106 */ 107 108 var o = e.data('jqm'), 109 t = t || window.event, 110 z = (parseInt(e.css('z-index'))), 111 z = (z > 0) ? z : 3000, 112 v = $('<div></div>').addClass(o.overlayClass).css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:o.overlay/100}), 113 114 // maintain legacy "hash" construct 115 h = {w: e, c: o, o: v, t: t}; 116 117 e.css('z-index',z); 118 119 if(o.ajax){ 120 var target = o.target || e, 121 url = o.ajax; 122 123 target = (typeof target == 'string') ? $(target,e) : $(target); 124 if(url.substr(0,1) == '@') url = $(t).attr(url.substring(1)); 125 126 // Load the Ajax Content (and once loaded); 127 // Fire the onLoad callback (if exists), 128 // Attach closing events to elements inside the modal that match the closingClass, 129 // and Execute the jqModal default Open Callback 130 target.html(o.ajaxText).load(url,function(){ 131 o.onLoad && o.onLoad.call(this,h); 132 open(h); 133 }); 134 } 135 else { open(h); } 136 137 }, hide = function(e, t){ 138 /** 139 * e = modal element (as jQuery object) 140 * t = triggering element 141 * 142 * o = options 143 * h = hash (for jqModal <= r15 compatibility) 144 */ 145 146 var o = e.data('jqm'), 147 t = t || window.event, 148 149 // maintain legacy "hash" construct 150 h = {w: e, c: o, o: e.data('jqmv'), t: t}; 151 152 close(h); 153 154 }, onShow = function(hash){ 155 // onShow callback. Responsible for showing a modal and overlay. 156 // return false to stop opening modal. 157 158 // hash object; 159 // w: (jQuery object) The modal element
160 // c: (object) The modal's options object 161 // o: (jQuery object) The overlay element 162 // t: (DOM object) The triggering element 163 164 // display the overlay (prepend to body) if not disabled 165 166 // prevent double click 167 if( hash.w[0]._jqmShown ) 168 return false; 169 170 if(hash.c.overlay > 0) 171 hash.o.prependTo('#popup_iframe_wrapper'); 172 173 // make modal visible 174 hash.w.show(); 175 176 // call focusFunc (attempts to focus on first input in modal) 177 $.jqm.focusFunc(hash.w); 178 179 return true; 180 181 182 }, onHide = function(hash){ 183 // onHide callback. Responsible for hiding a modal and overlay. 184 // return false to stop closing modal. 185 186 // hash object; 187 // w: (jQuery object) The modal element 188 // c: (object) The modal's options object 189 // o: (jQuery object) The overlay element 190 // t: (DOM object) The triggering element 191 192 // hide modal and if overlay, remove overlay. 193 hash.w.hide() && hash.o && hash.o.remove(); 194 195 return true; 196 197 198 }, addTrigger = function(e, key, trigger){ 199 // addTrigger: Adds a jqmShow or jqmHide (key) for a modal (e) 200 // all elements that match trigger string (trigger)\ 201 202 // return false if e is not an initialized modal element 203 if(!e.data('jqm')) return false; 204 205 return $(trigger).each(function(){ 206 // register modal to trigger elements 207 this[key] = this[key] || []; 208 this[key].push(e); 209 210 }).click(function(){ 211 212 var trigger = this; 213 214 // foreadh modal registered to this trigger, call jqmShow || 215 // jqmHide (key) on modal passing trigger element (e) 216 $.each(this[key], function(i, e){ e[key](trigger); }); 217 218 // stop trigger click event from bubbling 219 return false; 220 }); 221 222 223 }, open = function(h){ 224 // open: executes the onOpen callback + performs common tasks if successful 225 226 // transform legacy hash into new var shortcuts 227 var e = h.w, 228 v = h.o, 229 o = h.c; 230 231 // execute onShow callback 232 if(o.onShow(h) !== false){ 233 // mark modal as shown 234 e[0]._jqmShown = true; 235 236 // if modal dialog 237 // 238 // Bind the Keep Focus Function [F] if no other Modals are open (!A[0]) + 239 // Add this modal to the opened modals stack (A) for nested modal support 240 // 241 // else, close dialog when overlay is clicked 242 if(o.modal){ !A[0]&&F('bind'); A.push(e); } 243 else e.jqmAddClose(v); 244 245 // Attach closing events to elements inside the modal that match the closingClass 246 o.closeClass&&e.jqmAddClose($('.' + o.closeClass,e)); 247 248 // IF toTop is true and overlay exists; 249 // Add placeholder element <span id="jqmP#ID_of_modal"/> before modal to 250 // remember it's position in the DOM and move it to a child of the body tag (after overlay) 251 o.toTop&&v&&e.before('<span id="jqmP'+o.ID+'"></span>').insertAfter(v); 252 253 // remember overlay (for closing function) 254 e.data('jqmv',v); 255 } 256 257 258 }, close = function(h){ 259 // close: executes the onHide callback + performs common tasks if successful 260 261 // transform legacy hash into new var shortcuts 262 var e = h.w, 263 v = h.o, 264 o = h.c; 265 266 // execute onShow callback 267 if(o.onHide(h) !== false){ 268 // mark modal as !shown 269 e[0]._jqmShown = false; 270 271 // If modal, remove from modal stack. 272 // If no modals in modal stack, unbind the Keep Focus Function 273 if(o.modal){A.pop();!A[0]&&F('unbind');} 274 275 // IF toTop was passed and an overlay exists; 276 // Move modal back to its "remembered" position. 277 o.toTop&&v&&$('#jqmP'+o.ID).after(e).remove(); 278 } 279 280 281 }, F = function(t){ 282 // F: The Keep Focus Function (for modal: true dialos) 283 // Binds or Unbinds (t) the Focus Examination Function (X) to keypresses and clicks 284 285 $(document)[t]("keypress keydown mousedown",X); 286 287 288 }, X = function(e){ 289 // X: The Focus Examination Function (for modal: true dialogs) 290 291 var modal = $(e.target).data('jqm') || $(e.target).parents('.jqm-init:first').data('jqm'), 292 activeModal = A[A.length-1].data('jqm'); 293 294 // allow bubbling if event target is within active modal dialog 295 if(modal && modal.ID == activeModal.ID) return true; 296 297 // else, trigger focusFunc (focus on first input element and halt bubbling) 298 return $.jqm.focusFunc(activeModal); 299 }, 300 301 I = 0, // modal ID increment (for nested modals) 302 A = []; // array of active modals (used to lock interactivity to appropriate modal) 303 304 305 // $.jqm, overridable defaults 306 $.jqm = { 307 /** 308 * default options 309 * 310 * (Integer) overlay - [0-100] Translucency percentage (opacity) of the body covering overlay. Set to 0 for NO overlay, and up to 100 for a 100% opaque overlay. 311 * (String) overlayClass - Applied to the body covering overlay. Useful for controlling overlay look (tint, background-image, &c) with CSS. 312 * (String) closeClass - Children of the modal element matching `closeClass` will fire the onHide event (to close the modal). 313 * (Mixed) trigger - Matching elements will fire the onShow event (to display the modal). Trigger can be a selector String, a jQuery collection of elements, a DOM element, or a False boolean. 314 * (String) ajax - URL to load content from via an AJAX request. False to disable ajax. If ajax begins with a "@", the URL is extracted from the attribute of the triggering element (e.g. use '@data-url' for; <a href="#" class="jqModal" data-url="modal.html">...) 315 * (Mixed) target - Children of the modal element to load the aja
315x response into. If false, modal content will be overwritten by ajax response. Useful for retaining modal design. 316 * Target may be a selector string, jQuery collection of elements, or a DOM element -- and MUST exist as a child of the modal element. 317 * (String) ajaxText - Text shown while waiting for ajax return. Replaces HTML content of `target` element. 318 * (Boolean) modal - If true, user interactivity will be locked to the modal window until closed. 319 * (Boolean) toTop - If true, modal will be posistioned as a first child of the BODY element when opened, and its DOM posistion restored when closed. Useful for overcoming z-Index container issues. 320 * (Function) onShow - User defined callback function fired when modal opened. 321 * (Function) onHide - User defined callback function fired when modal closed. 322 * (Function) onLoad - User defined callback function fired when ajax content loads. 323 */ 324 params: { 325 overlay: 50, 326 overlayClass: 'jqmOverlay', 327 closeClass: 'jqmClose', 328 trigger: '.jqModal', 329 ajax: false, 330 target: false, 331 ajaxText: '', 332 modal: false, 333 toTop: false, 334 onShow: onShow, 335 onHide: onHide, 336 onLoad: false 337 }, 338 339 // focusFunc is fired when a modal is shown, or when interaction occurs outside 340 // a modal enabled dialog. Passed the modal element. 341 focusFunc: function(e) { $(':input:visible:first',e).focus(); return false; } 342 }; 343 344})( 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.