1/* 2 * jqModal - Minimalist Modaling with jQuery 3 * 4 * Copyright (c) 2007-2016 Brice Burgess @IceburgBrice 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.4.2 (2016.04.16 +r27) 10 * Requires: jQuery 1.2.3+ 11 */ 12 13(function (factory) { 14 if (typeof module === 'object' && typeof module.exports === 'object') { 15 // Node/CommonJS 16 module.exports = factory(require('jquery')); 17 } else { 18 // Browser globals 19 factory(jQuery); 20 } 21}(function ($) { 22 23 /** 24 * Initialize elements as "modals". Modals typically are popup dialogs, 25 * notices, modal windows, &c. 26 * 27 * @name jqm 28 * @param options user defined options, augments defaults. 29 * @type jQuery 30 * @cat Plugins/jqModal 31 */ 32 33 $.fn.jqm=function(options){ 34 return this.each(function(){ 35 var jqm = $(this).data('jqm') || $.extend({ID: I++}, $.jqm.params), 36 o = $.extend(jqm,options); 37 38 // add/extend options to modal and mark as initialized 39 $(this).data('jqm',o).addClass('jqm-init')[0]._jqmID = o.ID; 40 41 // ... Attach events to trigger showing of this modal 42 $(this).jqmAddTrigger(o.trigger); 43 }); 44 }; 45 46 /** 47 * Matching modals will have their jqmShow() method fired by attaching a 48 * onClick event to elements matching `trigger`. 49 * 50 * @name jqmAddTrigger 51 * @param trigger a a string selector, jQuery collection, or DOM element. 52 */ 53 $.fn.jqmAddTrigger=function(trigger){ 54 if(trigger){
55 return this.each(function(){ 56 if (!addTrigger($(this), 'jqmShow', trigger)) { 57 err("jqmAddTrigger must be called on initialized modals"); 58 } 59 }); 60 } 61 }; 62 63 /** 64 * Matching modals will have their jqmHide() method fired by attaching an 65 * onClick event to elements matching `trigger`. 66 * 67 * @name jqmAddClose 68 * @param trigger a string selector, jQuery collection, or DOM element. 69 */ 70 $.fn.jqmAddClose=function(trigger){ 71 if(trigger){ 72 return this.each(function(){ 73 if(!addTrigger($(this), 'jqmHide', trigger)) { 74 err ("jqmAddClose must be called on initialized modals"); 75 } 76 }); 77 } 78 }; 79 80 /** 81 * Open matching modals (if not shown) 82 */ 83 $.fn.jqmShow=function(trigger){ 84 return this.each(function(){ 85 if(!this._jqmShown) { show($(this), trigger); } 86 }); 87 }; 88 89 /** 90 * Close matching modals 91 */ 92 $.fn.jqmHide=function(trigger){ 93 return this.each(function(){ 94 if(this._jqmShown) { hide($(this), trigger); } 95 }); 96 }; 97 98 // utility functions 99 100 var 101 err = function(msg){ 102 if(window.console && window.console.error) { window.console.error(msg); } 103 104 }, show = function(m, t){ 105 106 /** 107 * m = modal element (as jQuery object) 108 * t = triggering element 109 * 110 * o = options 111 * z = z-index of modal 112 * v = overlay element (as jQuery object) 113 * h = hash (for jqModal <= r15 compatibility) 114 */ 115 116 t = t || window.event; 117 118 var o = m.data('jqm'), 119 z = (parseInt(m.css('z-index'),10)) || 3000, 120 v = $('<div></div>').addClass(o.overlayClass).css({ 121 height:'100%', 122 width:'100%', 123 position:'fixed', 124 left:0, 125 top:0, 126 'z-index':z-1, 127 opacity:o.overlay/100 128 }), 129 130 // maintain legacy "hash" construct 131 h = {w: m, c: o, o: v, t: t}; 132 133 m.css('z-index',z); 134 135 if(o.ajax){ 136 var target = o.target || m, 137 url = o.ajax; 138 139 target = (typeof target === 'string') ? $(target,m) : $(target); 140 if(url.substr(0,1) === '@') { 141 url = $(t).attr(url.substring(1)); 142 } 143 144 // load remote contents 145 target.load(url,function(){ 146 if(o.onLoad) { 147 o.onLoad.call(this,h); 148 } 149 parseModalContents.call(m,o,target); 150 }); 151 152 // show modal 153 if(o.ajaxText) { 154 target.html(o.ajaxText); 155 } 156 open(h); 157 } 158 else { open(h); } 159 160 }, hide = function(m, t){ 161 /** 162 * m = modal element (as jQuery object) 163 * t = triggering element 164 * 165 * o = options 166 * h = hash (for jqModal <= r15 compatibility) 167 */ 168 169 t = t || window.event; 170 var o = m.data('jqm'), 171 // maintain legacy "hash" construct 172 h = {w: m, c: o, o: m.data('jqmv'), t: t}; 173 174 close(h); 175 176 }, onShow = function(hash){ 177 // onShow callback. Responsible for showing a modal and overlay. 178 // return false to stop opening modal. 179 180 // hash object; 181 // w: (jQuery object) The modal element 182 // c: (object) The modal's options object 183 // o: (jQuery object) The overlay element 184 // t: (DOM object) The triggering element 185 186 // if overlay not disabled, prepend to body 187 if(hash.c.overlay > 0) { 188 hash.o.prependTo('body'); 189 } 190 191 // make modal visible 192 hash.w.show(); 193 194 // call focusFunc (attempts to focus on first input in modal) 195 $.jqm.focusFunc(hash.w,true); 196 197 return true; 198 199 }, onHide = function(hash){ 200 // onHide callback. Responsible for hiding a modal and overlay. 201 // return false to stop closing modal. 202 203 // hash object; 204 // w: (jQuery object) The modal element 205 // c: (object) The modal's options object 206 // o: (jQuery object) The overlay element 207 // t: (DOM object) The triggering element 208 209 // hide modal and if overlay, remove overlay. 210 if(hash.w.hide() && hash.o) { 211 hash.o.remove(); 212 } 213 214 return true; 215 216 }, addTrigger = function(m, key, trigger){ 217 // addTrigger: Adds a jqmShow/jqmHide (key) event click on modal (m) 218 // to all elements that match trigger string (trigger) 219 220 var jqm = m.data('jqm'); 221 if(jqm) { 222 return $(trigger).each(function(){ 223 this[key] = this[key] || []; 224 // register this modal with this trigger only once 225 if($.inArray(jqm.ID,this[key]) < 0) { 226 this[key].push(jqm.ID); 227 228 // register trigger click event for this modal 229 // allows cancellation of show/hide event from 230 $(this).click(function(e){
231 if(!e.isDefaultPrevented()) { m[key](this); } 232 return false; 233 }); 234 } 235 }); 236 } 237 238 }, open = function(h){ 239 // open: executes the onOpen callback + performs common tasks if successful 240 241 // transform legacy hash into new var shortcuts 242 var m = h.w, 243 v = h.o, 244 o = h.c; 245 246 // execute onShow callback 247 if(o.onShow(h) !== false){ 248 // mark modal as shown 249 m[0]._jqmShown = true; 250 251 // if modal:true dialog 252 // Bind the Keep Focus Function [F] if no other Modals are active 253 // else, 254 // trigger closing of dialog when overlay is clicked 255 if(o.modal){ 256 if(!ActiveModals[0]){ F('bind'); } 257 ActiveModals.push(m[0]); 258 } 259 else { 260 m.jqmAddClose(v); 261 } 262 263 // parse modal contents and add behavior 264 parseModalContents.call(m,o); 265 266 // if toTop is true and overlay exists; 267 // remember modal DOM position with <span> placeholder element, and move 268 // the modal to a direct child of the body tag (after overlyay) 269 if(o.toTop && v) { 270 m.before('<span id="jqmP'+o.ID+'"></span>').insertAfter(v); 271 } 272 273 // remember overlay (for closing function) 274 m.data('jqmv',v); 275 276 // close modal if the esc key is pressed and closeOnEsc is set to true 277 m.unbind("keydown",$.jqm.closeOnEscFunc); 278 if(o.closeOnEsc) { 279 m.attr("tabindex", 0).bind("keydown",$.jqm.closeOnEscFunc).focus(); 280 } 281 } 282 283 }, close = function(h){ 284 // close: executes the onHide callback + performs common tasks if successful 285 286 // transform legacy hash into new var shortcuts 287 var m = h.w, 288 v = h.o, 289 o = h.c; 290 291 // execute onHide callback 292 if(o.onHide(h) !== false){ 293 // mark modal as !shown 294 m[0]._jqmShown = false; 295 296 // If modal, remove from modal stack. 297 // If no modals in modal stack, unbind the Keep Focus Function 298 if(o.modal){ 299 ActiveModals.pop(); 300 if(!ActiveModals[0]) { 301 F('unbind'); 302 } 303 } 304 305 // IF toTop was passed and an overlay exists; 306 // Move modal back to its "remembered" position. 307 if(o.toTop && v) { 308 $('#jqmP'+o.ID).after(m).remove(); 309 } 310 } 311 312 }, F = function(t){ 313 // F: The Keep Focus Function (for modal: true dialos) 314 // Binds or Unbinds (t) the Focus Examination Function (X) 315 316 $(document)[t]("keypress keydown mousedown",X); 317 318 }, X = function(e){ 319 // X: The Focus Examination Function (for modal: true dialogs) 320 321 var targetModal = $(e.target).data('jqm') || 322 $(e.target).parents('.jqm-init:first').data('jqm'); 323 var activeModal = ActiveModals[ActiveModals.length-1]; 324 325 // allow bubbling if event target is within active modal dialog 326 return (targetModal && targetModal.ID === activeModal._jqmID) ? 327 true : $.jqm.focusFunc(activeModal,e); 328 329 }, parseModalContents = function(o, context){ 330 context = context || this; 331 332 // Attach events to elements inside the modal matching closingClass 333 if(o.closeClass) { 334 this.jqmAddClose($('.' + o.closeClass,context)); 335 } 336 337 }, 338 I = 0, // modal ID increment (for nested modals) 339 ActiveModals = []; // array of active modals 340 341 // $.jqm, overridable defaults 342 $.jqm = { 343 /** 344 * default options 345 * 346 * (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. 347 * (String) overlayClass - Applied to the body covering overlay. Useful for controlling overlay look (tint, background-image, &c) with CSS. 348 * (String) closeClass - Children of the modal element matching `closeClass` will fire the onHide event (to close the modal). 349 * (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. 350 * (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">...) 351 * (Mixed) target - Children of the modal element to load the aja
351x response into. If false, modal content will be overwritten by ajax response. Useful for retaining modal design. 352 * Target may be a selector string, jQuery collection of elements, or a DOM element -- and MUST exist as a child of the modal element. 353 * (String) ajaxText - Text shown while waiting for ajax return. Replaces HTML content of `target` element. 354 * (Boolean) modal - If true, user interactivity will be locked to the modal window until closed. 355 * (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. 356 * (Function) onShow - User defined callback function fired when modal opened. 357 * (Function) onHide - User defined callback function fired when modal closed. 358 * (Function) onLoad - User defined callback function fired when ajax content loads. 359 */ 360 params: { 361 overlay: 50, 362 overlayClass: 'jqmOverlay', 363 closeClass: 'jqmClose', 364 closeOnEsc: false, 365 trigger: '.jqModal', 366 ajax: false, 367 target: false, 368 ajaxText: '', 369 modal: false, 370 toTop: false, 371 onShow: onShow, 372 onHide: onHide, 373 onLoad: false 374 }, 375 376 // focusFunc is fired: 377 // a) when a modal:true dialog is shown, 378 // b) when an event occurs outside an active modal:true dialog 379 // It is passed the active modal:true dialog as well as event 380 focusFunc: function(activeModal, e) { 381 382 // if the event occurs outside the activeModal, focus on first element 383 if(e) { $(':input:visible:first',activeModal).focus(); } 384 385 // lock interactions to the activeModal 386 return false; 387 }, 388 389 // closeOnEscFunc is attached to modals where closeOnEsc param true. 390 closeOnEscFunc: function(e){ 391 if (e.keyCode === 27) { 392 $(this).jqmHide(); 393 return false; 394 } 395 } 396 }; 397 398 return $.jqm; 399 400}));
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.