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 * e = modal element (as jQuery object) 99 * t = triggering element 100 * 101 * o = options 102 * z = z-index of modal 103 * v = overlay element (as jQuery object) 104 * h = hash (for jqModal <= r15 compatibility) 105 */ 106 107 var o = e.data('jqm'), 108 t = t || window.event, 109 z = (parseInt(e.css('z-index'))); 110 111 if(o.noOverlay === undefined || (o.noOverlay !== undefined && !o.noOverlay) ) { 112 if( isNaN(z) ) { 113 if( window['lastJqmZindex'] ) { 114 window['lastJqmZindex'] = z = window['lastJqmZindex'] + 2; 115 } else { 116 z = 3000; 117 } 118 } 119 window['lastJqmZindex'] = z; 120 var 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}); 121 e.css('z-index',z); 122 } else { 123 var v = $(''); 124 e.css('z-index',2999); 125 } 126 127 // maintain legacy "hash" construct 128 h = {w: e, c: o, o: v, t: t}; 129 130 131 if(o.ajax){ 132 var target = o.target || e, 133 url = o.ajax; 134 135 target = (typeof target == 'string') ? $(target,e) : $(target); 136 if(url.substr(0,1) == '@') url = $(t).attr(url.substring(1)); 137 138 // Load the Ajax Content (and once loaded); 139 // Fire the onLoad callback (if exists), 140 // Attach closing events to elements inside the modal that match the closingClass, 141 // and Execute the jqModal default Open Callback 142 target.html(o.ajaxText).load(url,function(){ 143 o.onLoad && o.onLoad.call(this,h); 144 open(h); 145 }); 146 } 147 else { open(h); } 148 149 }, hide = function(e, t){ 150 /** 151 * e = modal element (as jQuery object) 152 * t = triggering element 153 * 154 * o = options 155 * h = hash (for jqModal <= r15 compatibility) 156 */ 157 158 var o = e.data('jqm'), 159 t = t || window.event, 160 161 // maintain legacy "hash" construct 162 h = {w: e, c: o, o: e.data('jqmv'), t: t}; 163 164 close(h); 165 166 }, onShow = function(hash){ 167 // onShow callback. Responsible for showing a modal and overlay. 168 // return false to stop opening modal. 169 170 // hash object; 171 // w: (jQuery object) The modal element
172 // c: (object) The modal's options object 173 // o: (jQuery object) The overlay element 174 // t: (DOM object) The triggering element 175 176 // display the overlay (prepend to body) if not disabled 177 178 // prevent double click 179 if( hash.w[0]._jqmShown ) 180 return false; 181 182 if(hash.c.overlay > 0) 183 hash.o.prependTo('#popup_iframe_wrapper'); 184 185 // make modal visible 186 hash.w.show(); 187 188 // call focusFunc (attempts to focus on first input in modal) 189 $.jqm.focusFunc(hash.w); 190 191 return true; 192 193 194 }, onHide = function(hash){ 195 // onHide callback. Responsible for hiding a modal and overlay. 196 // return false to stop closing modal. 197 198 // hash object; 199 // w: (jQuery object) The modal element 200 // c: (object) The modal's options object 201 // o: (jQuery object) The overlay element 202 // t: (DOM object) The triggering element 203 204 // hide modal and if overlay, remove overlay. 205 hash.w.hide() && hash.o && hash.o.remove(); 206 207 return true; 208 209 210 }, addTrigger = function(e, key, trigger){ 211 // addTrigger: Adds a jqmShow or jqmHide (key) for a modal (e) 212 // all elements that match trigger string (trigger)\ 213 214 // return false if e is not an initialized modal element 215 if(!e.data('jqm')) return false; 216 217 return $(trigger).each(function(){ 218 // register modal to trigger elements 219 this[key] = this[key] || []; 220 this[key].push(e); 221 222 }).click(function(){ 223 224 var trigger = this; 225 226 // foreadh modal registered to this trigger, call jqmShow || 227 // jqmHide (key) on modal passing trigger element (e) 228 $.each(this[key], function(i, e){ e[key](trigger); }); 229 230 // stop trigger click event from bubbling 231 return false; 232 }); 233 234 235 }, open = function(h){ 236 // open: executes the onOpen callback + performs common tasks if successful 237 238 // transform legacy hash into new var shortcuts 239 var e = h.w, 240 v = h.o, 241 o = h.c; 242 243 // execute onShow callback 244 if(o.onShow(h) !== false){ 245 // mark modal as shown 246 e[0]._jqmShown = true; 247 248 // if modal dialog 249 // 250 // Bind the Keep Focus Function [F] if no other Modals are open (!A[0]) + 251 // Add this modal to the opened modals stack (A) for nested modal support 252 // 253 // else, close dialog when overlay is clicked 254 if(o.modal){ !A[0]&&F('bind'); A.push(e); } 255 else e.jqmAddClose(v); 256 257 // Attach closing events to elements inside the modal that match the closingClass 258 o.closeClass&&e.jqmAddClose($('.' + o.closeClass,e)); 259 260 // IF toTop is true and overlay exists; 261 // Add placeholder element <span id="jqmP#ID_of_modal"/> before modal to 262 // remember it's position in the DOM and move it to a child of the body tag (after overlay) 263 o.toTop&&v&&e.before('<span id="jqmP'+o.ID+'"></span>').insertAfter(v); 264 265 // remember overlay (for closing function) 266 e.data('jqmv',v); 267 } 268 269 270 }, close = function(h){ 271 // close: executes the onHide callback + performs common tasks if successful 272 273 // transform legacy hash into new var shortcuts 274 var e = h.w, 275 v = h.o, 276 o = h.c; 277 278 // execute onShow callback 279 if(o.onHide(h) !== false){ 280 // mark modal as !shown 281 e[0]._jqmShown = false; 282 283 // If modal, remove from modal stack. 284 // If no modals in modal stack, unbind the Keep Focus Function 285 if(o.modal){A.pop();!A[0]&&F('unbind');} 286 287 // IF toTop was passed and an overlay exists; 288 // Move modal back to its "remembered" position. 289 o.toTop&&v&&$('#jqmP'+o.ID).after(e).remove(); 290 } 291 292 293 }, F = function(t){ 294 // F: The Keep Focus Function (for modal: true dialos) 295 // Binds or Unbinds (t) the Focus Examination Function (X) to keypresses and clicks 296 297 $(document)[t]("keypress keydown mousedown",X); 298 299 300 }, X = function(e){ 301 // X: The Focus Examination Function (for modal: true dialogs) 302 303 var modal = $(e.target).data('jqm') || $(e.target).parents('.jqm-init:first').data('jqm'), 304 activeModal = A[A.length-1].data('jqm'); 305 306 // allow bubbling if event target is within active modal dialog 307 if(modal && modal.ID == activeModal.ID) return true; 308 309 // else, trigger focusFunc (focus on first input element and halt bubbling) 310 return $.jqm.focusFunc(activeModal); 311 }, 312 313 I = 0, // modal ID increment (for nested modals) 314 A = []; // array of active modals (used to lock interactivity to appropriate modal) 315 316 317 // $.jqm, overridable defaults 318 $.jqm = { 319 /** 320 * default options 321 * 322 * (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. 323 * (String) overlayClass - Applied to the body covering overlay. Useful for controlling overlay look (tint, background-image, &c) with CSS. 324 * (String) closeClass - Children of the modal element matching `closeClass` will fire the onHide event (to close the modal). 325 * (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. 326 * (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">...) 327 * (Mixed) target - Children of the modal element to load the aja
327x response into. If false, modal content will be overwritten by ajax response. Useful for retaining modal design. 328 * Target may be a selector string, jQuery collection of elements, or a DOM element -- and MUST exist as a child of the modal element. 329 * (String) ajaxText - Text shown while waiting for ajax return. Replaces HTML content of `target` element. 330 * (Boolean) modal - If true, user interactivity will be locked to the modal window until closed. 331 * (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. 332 * (Function) onShow - User defined callback function fired when modal opened. 333 * (Function) onHide - User defined callback function fired when modal closed. 334 * (Function) onLoad - User defined callback function fired when ajax content loads. 335 */ 336 params: { 337 overlay: 50, 338 overlayClass: 'jqmOverlay', 339 closeClass: 'jqmClose', 340 trigger: '.jqModal', 341 ajax: false, 342 target: false, 343 ajaxText: '', 344 modal: false, 345 toTop: false, 346 onShow: onShow, 347 onHide: onHide, 348 onLoad: false 349 }, 350 351 // focusFunc is fired when a modal is shown, or when interaction occurs outside 352 // a modal enabled dialog. Passed the modal element. 353 focusFunc: function(e) { $(':input:visible:first',e).focus(); return false; } 354 }; 355 356})( 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.