1'use strict'; 2/*! 3 * jquery-confirm v1.1.3 (http://craftpip.github.io/jquery-confirm/) 4 * Author: Boniface Pereira 5 * Website: www.craftpip.com 6 * Contact: [email protected] 7 * 8 * Copyright 2013-2014 jquery-confirm 9 * Licensed under MIT (https://github.com/craftpip/jquery-confirm/blob/master/LICENSE) 10 */ 11 12if (typeof jQuery === 'undefined') { 13 throw new Error('jquery-confirm requires jQuery'); 14} 15 16var jconfirm, Jconfirm; 17(function ($) { 18 // Focusable elements selector 19 const FOCUSABLE_ELEMENTS = [ 20 'a[href]', 21 'area[href]', 22 'input:not([disabled]):not([type="hidden"]):not([aria-hidden])', 23 'select:not([disabled]):not([aria-hidden])', 24 'textarea:not([disabled]):not([aria-hidden])', 25 'button:not([disabled]):not([aria-hidden])', 26 'iframe', 27 'object', 28 'embed', 29 '[contenteditable]', 30 '[tabindex]:not([tabindex^="-"])' 31 ].join(','); 32 33 // .closeIcon is display:none when buttons exist; a hidden node is a no-op 34 // to focus and would leak focus out of the dialog if included. 35 function visibleFocusable($el) { 36 return $el.find(FOCUSABLE_ELEMENTS).filter(':visible'); 37 } 38 39 $.confirm = function (options) { 40 /* 41 * Alias of jconfirm 42 */ 43 options.title = options.title || confirmation_box_title; 44 return jconfirm(options); 45 }; 46 $.alert = function (options) { 47 /* 48 * Alias of jconfirm 49 */ 50 51 options.title = options.title || alert_box_title; 52 options.cancelButton = false; 53 options.type = 'alert'; 54 return jconfirm(options); 55 }; 56 $.dialog = function (options) { 57 /* 58 * Alias of jconfirm 59 */ 60 options.cancelButton = false; 61 options.confirmButton = false; 62 return jconfirm(options); 63 }; 64 jconfirm = function (rawOptions) { 65 /* 66 * initial function for calling. 67 */ 68 if (jconfirm.defaults) { 69 /* 70 * Merge global defaults with plugin defaults 71 */ 72 $.extend(jconfirm.pluginDefaults, jconfirm.defaults); 73 } 74 /* 75 * merge options with plugin defaults. 76 */ 77 var options = $.extend({}, jconfirm.pluginDefaults, rawOptions); 78 79 // inert doesn't block scripted clicks. Alerts only â confirm/dialog 80 // reuse the same copy across rows with different callbacks. 81 if (options.type === 'alert') { 82 var existing = jconfirm.openInstances.filter(function (inst) { 83 return inst.type === 'alert' && 84 inst.content === options.content && 85 inst.title === options.title; 86 })[0]; 87 if (existing) { 88 // Check the caller's raw options, not the pluginDefaults-merged 89 // ones â those always have a (no-op) confirm/cancel, which would 90 // otherwise stomp a real callback attached by an earlier caller. 91 if (rawOptions.confirm) existing.confirm = rawOptions.confirm; 92 if (rawOptions.cancel) existing.cancel = rawOptions.cancel; 93 return existing; 94 } 95 } 96 97 return new Jconfirm(options); 98 }; 99 jconfirm.openInstances = []; 100 Jconfirm = function (options) { 101 /* 102 * constructor function Jconfirm, 103 * options = user options. 104 */ 105 $.extend(this, options); 106 this._init(); 107 }; 108 Jconfirm.prototype = { 109 _init: function () { 110 var that = this; 111 jconfirm.openInstances.push(this); 112 this._buildHTML(); 113 this._bindEvents(); 114 setTimeout(function () { 115 that.open(); 116 }, 0); 117 }, 118 animations: ['anim-scale', 'anim-top', 'anim-bottom', 'anim-left', 'anim-right', 'anim-zoom', 'anim-opacity', 'anim-none', 'anim-rotate', 'anim-rotatex', 'anim-rotatey', 'anim-scalex', 'anim-scaley'], 119 _buildHTML: function () { 120 var that = this; 121 /* 122 * Cleaning animations. 123 */ 124 this.animation = 'anim-' + this.animation.toLowerCase(); 125 if (this.animation == 'none') 126 this.animationSpeed = 0; 127 128 /* 129 * Append html to body. 130 */ 131 this.$el = $(this.template).appendTo('body').addClass(this.theme); 132 this.$b = this.$el.find('.jconfirm-box').css({
133 '-webkit-transition-duration': this.animationSpeed / 1000 + 's', 134 'transition-duration': this.animationSpeed / 1000 + 's' 135 }); 136 this.$b = this.$el.find('.jconfirm-box'); 137 this.$b.addClass(this.animation); 138 139 // Set ARIA attributes 140 this.$b.attr('aria-labelledby', 'jconfirm-title'); 141 this.$b.attr('aria-describedby', 'jconfirm-content'); 142 if (this.type === 'alert') { 143 this.$b.attr('role', 'alertdialog'); 144 } 145 146 if(is_mobile_app_mode()) { 147 this.$b.css('top',parseInt(globalScrollTop) + 100); 148 } 149 /* 150 * setup html contents 151 */ 152 if (typeof this.content !== 'string') 153 this.content = this.content == null ? '' : String(this.content); 154 155 this.$el.find('div.title').html(this.title); 156 var contentDiv = this.$el.find('div.content'); 157 158 /* 159 * Settings up buttons 160 */ 161 var $btnc = this.$el.find('.buttons'); 162 // Cancel is appended first so focus order matches the visual order (.btn-confirm is floated right). 163 if (this.cancelButton && this.cancelButton.trim() !== '') { 164 this.$cancelButton = $('<button class="btn">' + this.cancelButton + '</button>').appendTo($btnc); 165 this.$cancelButton.addClass(this.cancelButtonClass); 166 } 167 if (this.confirmButton && this.confirmButton.trim() !== '') { 168 this.$confirmButton = $('<button class="btn">' + this.confirmButton + '</button>').appendTo($btnc); 169 this.$confirmButton.addClass(this.confirmButtonClass); 170 } 171 if (!this.confirmButton && !this.cancelButton) { 172 $btnc.remove(); 173 if (this.closeIcon) 174 this.$closeButton = this.$b.find('.closeIcon').show(); 175 } 176 177 /* 178 * If user provides a Url to load the content from. 179 * Check if it has HTTP protocol. 180 */ 181 if (this.content.substr(0, 4).toLowerCase() === 'url:') { 182 contentDiv.html(''); 183 $btnc.find('button').attr('disabled', 'disabled'); 184 var url = this.content.substring(4, this.content.length); 185 setTimeout(function () { 186 $.get(url, function (html) { 187 contentDiv.html(html); 188 $btnc.find('button').removeAttr('disabled'); 189 that.setDialogCenter(); 190 }); 191 }, 1); 192 } else { 193 contentDiv.html(this.content); 194 } 195 if (this.autoClose) 196 this._startCountDown(); 197 }, 198 _startCountDown: function () { 199 var opt = this.autoClose.split('|'); 200 if (/cancel/.test(opt[0]) && this.type === 'alert') 201 return false; 202 if (/confirm|cancel/.test(opt[0])) { 203 this.$cd = $(' <span class="countdown"></span>').appendTo(this['$' + opt[0] + 'Button']); 204 var that = this; 205 that.$cd.parent().click(); 206 var time = opt[1] / 1000; 207 this.interval = setInterval(function () { 208 that.$cd.html(' [' + (time -= 1) + ']'); 209 if (time === 0) { 210 that.$cd.parent().trigger('click'); 211 clearInterval(that.interval); 212 } 213 }, 1000); 214 } 215 }, 216 _bindEvents: function () { 217 var that = this; 218 this.$el.find('.jconfirm-bg').click(function (e) { 219 if (that.backgroundDismiss) { 220 that._dismiss('cancel'); 221 } else { 222 that.$b.addClass('hilight'); 223 setTimeout(function () { 224 that.$b.removeClass('hilight'); 225 }, 400); 226 } 227 }); 228 if (this.$confirmButton) { 229 this.$confirmButton.click(function (e) { 230 that._dismiss('confirm'); 231 }); 232 } 233 if (this.$cancelButton) { 234 this.$cancelButton.click(function (e) { 235 that._dismiss('cancel'); 236 }); 237 } 238 if (this.$closeButton) { 239 this.$closeButton.click(function (e) { 240 that._dismiss('cancel'); 241 }); 242 this.$closeButton.keydown(function (e) { 243 if (e.key === 'Enter' || e.key === ' ') { 244 e.preventDefault(); 245 that._dismiss('cancel'); 246 } 247 }); 248 } 249 $(window).on('resize', function () { 250 that.setDialogCenter() 251 }); 252 this.setDialogCenter(); 253 }, 254 setDialogCenter: function () { 255 var h = $(window).height();
256 var h2 = this.$b.height(); 257 var mar = (h - h2) / 2; 258 259 this.$b.find('.content').css({ 260 'max-height': h - 200 + 'px' 261 }); 262 this.$b.css({ 263 //'margin-top': mar 264 'margin-top': 100 265 }); 266 }, 267 _dismiss: function (action) { 268 this.unlockBackground(); 269 try { 270 this[action](); 271 } finally { 272 this.close(); 273 } 274 }, 275 close: function () { 276 /* 277 Remove the window resize event. 278 */ 279 $(window).unbind('resize', this.setDialogCenter); 280 var that = this; 281 var idx = jconfirm.openInstances.indexOf(this); 282 if (idx !== -1) jconfirm.openInstances.splice(idx, 1); 283 this.$b.addClass(this.animation); 284 285 $('body').removeClass('jconfirm-noscroll'); 286 287 if (this._keydownNs) { 288 $(document).off(this._keydownNs); 289 this._keydownNs = null; 290 } 291 292 // before restore â focusing an inert node is a silent no-op 293 this.unlockBackground(); 294 295 // Don't reclaim focus a callback deliberately moved elsewhere. 296 var active = document.activeElement; 297 var focusStillOurs = !active || active === document.body || 298 active === this.$el[0] || $.contains(this.$el[0], active); 299 if (focusStillOurs && this.lastFocusedElement && this.lastFocusedElement.focus) { 300 this.lastFocusedElement.focus(); 301 } 302 303 setTimeout(function () { 304 that.$el.remove(); 305 }, this.animationSpeed); 306 }, 307 open: function () { 308 var that = this; 309 $('body').addClass('jconfirm-noscroll'); 310 this.$b.removeClass(this.animations.join(' ')); 311 312 this.lastFocusedElement = document.activeElement; 313 314 this.lockBackground(); 315 316 this.setInitialFocus(); 317 318 this._keydownNs = 'keydown.jconfirm' + Date.now() + Math.floor(Math.random() * 1e6); 319 $(document).on(this._keydownNs, function(e) { 320 if (e.key === 'Tab') { 321 if (that.$el[0] && (that.$el[0] === e.target || $.contains(that.$el[0], e.target))) { 322 that.handleTabKey(e); 323 } 324 } else if (e.key === 'Escape' || e.key === 'Esc') { 325 // Only the topmost stacked instance responds, regardless of 326 // where focus landed (clicking non-focusable chrome blurs to body). 327 if (jconfirm.openInstances[jconfirm.openInstances.length - 1] !== that) return; 328 e.preventDefault(); 329 e.stopImmediatePropagation(); 330 that._dismiss('cancel'); 331 } 332 }); 333 }, 334 lockBackground: function() { 335 var that = this; 336 this._inertedNodes = []; 337 Array.prototype.forEach.call(document.body.children, function(el) { 338 if (el.classList.contains('jconfirm')) { 339 el.inert = false; 340 return; 341 } 342 if (el === that.$el[0] || el.hasAttribute('inert')) return; 343 el.inert = true; 344 that._inertedNodes.push(el); 345 }); 346 }, 347 unlockBackground: function() { 348 (this._inertedNodes || []).forEach(function(el) { 349 el.inert = false; 350 }); 351 this._inertedNodes = []; 352 }, 353 setInitialFocus: function() { 354 // Focus the first control in DOM order: Cancel on confirms (least destructive), OK on alerts. 355 var focusableElements = visibleFocusable(this.$el); 356 if (focusableElements.length > 0) { 357 focusableElements[0].focus(); 358 } 359 }, 360 handleTabKey: function(e) { 361 // Get all focusable elements 362 var focusableElements = visibleFocusable(this.$el); 363
364 // If no focusable elements, do nothing 365 if (focusableElements.length === 0) return; 366 367 // Get the first and last focusable elements 368 var firstFocusableElement = focusableElements[0]; 369 var lastFocusableElement = focusableElements[focusableElements.length - 1]; 370 371 // If shift + tab 372 if (e.shiftKey) { 373 if (document.activeElement === firstFocusableElement) { 374 e.preventDefault(); 375 lastFocusableElement.focus(); 376 } 377 } 378 // If tab 379 else { 380 if (document.activeElement === lastFocusableElement) { 381 e.preventDefault(); 382 firstFocusableElement.focus(); 383 } 384 } 385 }, 386 getFocusableNodes: function() { 387 return visibleFocusable(this.$el); 388 } 389 }; 390 jconfirm.pluginDefaults = { 391 template: '<div class="jconfirm"><div class="jconfirm-bg"></div><div class="container"><div class="row"><div class="col-md-6 col-md-offset-3 span6 offset3"><div class="jconfirm-box" role="dialog" aria-modal="true"><div class="closeIcon" role="button" tabindex="0" aria-label="Close dialog"><span class="glyphicon glyphicon-remove"></span></div><div class="title" id="jconfirm-title" role="heading" aria-level="1"></div><div class="content" id="jconfirm-content"></div><div class="buttons pull-right"></div><div class="jquery-clear"></div></div></div></div></div></div>', 392 title: false, 393 content: 'Are you sure to continue?', 394 icon: '', 395 confirmButton: ok_text, 396 cancelButton: cancel_text, 397 confirmButtonClass: 'btn-default btn-confirm', 398 cancelButtonClass: 'btn-default', 399 theme: 'white', 400 animation: 'scale', 401 animationSpeed: 300, 402 confirm: function () { 403 }, 404 cancel: function () { 405 }, 406 backgroundDismiss: true, 407 autoClose: false, 408 closeIcon: true, 409 }; 410})(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.