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