1/*! 2 * jquery-confirm v3.3.4 (http://craftpip.github.io/jquery-confirm/) 3 * Author: Boniface Pereira 4 * Website: www.craftpip.com 5 * Contact: [email protected] 6 * 7 * Copyright 2013-2019 jquery-confirm 8 * Licensed under MIT (https://github.com/craftpip/jquery-confirm/blob/master/LICENSE) 9 */ 10 11 12/** 13 * UMD (Universal Module Definition) to support CommonJS, AMD and browser 14 * Thanks to https://github.com/umdjs/umd 15 */ 16(function(factory){ 17 if(typeof define === 'function' && define.amd){ 18 // AMD. Register as an anonymous module. 19 define(['jquery'], factory); 20 }else if(typeof module === 'object' && module.exports){ 21 // Node/CommonJS 22 module.exports = function(root, jQuery){ 23 if(jQuery === undefined){ 24 // require('jQuery') returns a factory that requires window to 25 // build a jQuery instance, we normalize how we use modules 26 // that require this pattern but the window provided is a noop 27 // if it's defined (how jquery works) 28 if(typeof window !== 'undefined'){ 29 jQuery = require('jquery'); 30 } 31 else{ 32 jQuery = require('jquery')(root); 33 } 34 } 35 factory(jQuery); 36 return jQuery; 37 }; 38 }else{ 39 // Browser globals 40 factory(jQuery); 41 } 42}(function($){ 43 "use strict"; 44 45 // locally assign window 46 var w = window; 47 // w.jconfirm 48 // w.Jconfirm; 49 50 $.fn.confirm = function(options, option2){ 51 if(typeof options === 'undefined') options = {}; 52 if(typeof options === 'string'){ 53 options = { 54 content: options, 55 title: (option2) ? option2 : false 56 }; 57 } 58 /* 59 * Alias of $.confirm to emulate native confirm() 60 */ 61 $(this).each(function(){ 62 var $this = $(this); 63 if($this.attr('jc-attached')){ 64 console.warn('jConfirm has already been attached to this element ', $this[0]); 65 return; 66 } 67 68 $this.on('click', function(e){ 69 e.preventDefault(); 70 var jcOption = $.extend({}, options); 71 if($this.attr('data-title')) 72 jcOption['title'] = $this.attr('data-title'); 73 if($this.attr('data-content')) 74 jcOption['content'] = $this.attr('data-content'); 75 if(typeof jcOption['buttons'] === 'undefined') 76 jcOption['buttons'] = {}; 77 78 jcOption['$target'] = $this; 79 if($this.attr('href') && Object.keys(jcOption['buttons']).length === 0){ 80 var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {}); 81 var firstBtn = Object.keys(buttons)[0]; 82 jcOption['buttons'] = buttons; 83 jcOption.buttons[firstBtn].action = function(){ 84 location.href = $this.attr('href'); 85 }; 86 } 87 jcOption['closeIcon'] = false; 88 var instance = $.confirm(jcOption); 89 }); 90 91 $this.attr('jc-attached', true); 92 }); 93 return $(this); 94 }; 95 $.confirm = function(options, option2){ 96 if(typeof options === 'undefined') options = {}; 97 if(typeof options === 'string'){ 98 options = { 99 content: options, 100 title: (option2) ? option2 : false 101 }; 102 } 103 104 var putDefaultButtons = !(options['buttons'] === false); 105 106 if(typeof options['buttons'] !== 'object') 107 options['buttons'] = {}; 108 109 if(Object.keys(options['buttons']).length === 0 && putDefaultButtons){ 110 var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {}); 111 options['buttons'] = buttons; 112 } 113 114 /* 115 * Alias of jconfirm 116 */ 117 return w.jconfirm(options); 118 }; 119 $.alert = function(options, option2){ 120 if(typeof options === 'undefined') options = {}; 121 if(typeof options === 'string'){ 122 options = { 123 content: options, 124 title: (option2) ? option2 : false 125 }; 126 } 127 128 var putDefaultButtons = !(options['buttons'] === false); 129 130 if(typeof options.buttons !== 'object') 131 options.buttons = {}; 132 133 if(Object.keys(options['buttons']).length === 0 && putDefaultButtons){ 134 var buttons = $.extend(true, {}, w.jconfirm.pluginDefaults.defaultButtons, (w.jconfirm.defaults || {}).defaultButtons || {}); 135 var firstBtn = Object.keys(buttons)[0]; 136 options['buttons'][firstBtn] = buttons[firstBtn]; 137 } 138 /* 139 * Alias of jconfirm 140 */ 141 return w.jconfirm(options); 142 }; 143 $.dialog = function(options, option2){ 144 if(typeof options === 'undefined') options = {}; 145 if(typeof options === 'string'){ 146 options = { 147 content: options, 148 title: (option2) ? option2 : false, 149 closeIcon: function(){ 150 // Just close the modal 151 } 152 }; 153 } 154 155 options['buttons'] = {}; // purge buttons 156 157 if(typeof options['closeIcon'] === 'undefined'){ 158 // Dialog must have a closeIcon. 159 options['closeIcon'] = function(){ 160 } 161 } 162 /* 163 * Alias of jconfirm 164 */ 165 options.confirmKeys = [13]; 166 return w.jconfirm(options); 167 }; 168 169 w.jconfirm = function(options){ 170 if(typeof options === 'undefined') options = {}; 171 /* 172 * initial function for calling. 173 */ 174 var pluginOptions = $.extend(true, {}, w.jconfirm.pluginDefaults); 175 if(w.jconfirm.defaults){ 176 pluginOptions = $.extend(true, pluginOptions, w.jconfirm.defaults); 177 } 178 179 /* 180 * merge options with plugin defaults. 181 */ 182 pluginOptions = $.extend(true, {}, pluginOptions, options); 183 var instance = new w.Jconfirm(pluginOptions); 184 w.jconfirm.instances.push(instance); 185 return instance; 186 }; 187 w.Jconfirm = function(options){ 188 /*
189 * constructor function Jconfirm, 190 * options = user options. 191 */ 192 $.extend(this, options); 193 this._init(); 194 }; 195 w.Jconfirm.prototype = { 196 _init: function(){ 197 var that = this; 198 199 if(!w.jconfirm.instances.length) 200 w.jconfirm.lastFocused = $('body').find(':focus'); 201 202 this._id = Math.round(Math.random() * 99999); 203 /** 204 * contentParsed maintains the contents for $content, before it is put in DOM 205 */ 206 this.contentParsed = $(document.createElement('div')); 207 208 if(!this.lazyOpen){ 209 setTimeout(function(){ 210 that.open(); 211 }, 0); 212 } 213 }, 214 _buildHTML: function(){ 215 var that = this; 216 217 // prefix the animation string and store in animationParsed 218 this._parseAnimation(this.animation, 'o'); 219 this._parseAnimation(this.closeAnimation, 'c'); 220 this._parseBgDismissAnimation(this.backgroundDismissAnimation); 221 this._parseColumnClass(this.columnClass); 222 this._parseTheme(this.theme); 223 this._parseType(this.type); 224 225 /* 226 * Append html. 227 */ 228 var template = $(this.template); 229 template.find('.jconfirm-box').addClass(this.animationParsed).addClass(this.backgroundDismissAnimationParsed).addClass(this.typeParsed); 230 231 if(this.typeAnimated) 232 template.find('.jconfirm-box').addClass('jconfirm-type-animated'); 233 234 if(this.useBootstrap){ 235 template.find('.jc-bs3-row').addClass(this.bootstrapClasses.row); 236 template.find('.jc-bs3-row').addClass('justify-content-md-center justify-content-sm-center justify-content-xs-center justify-content-lg-center'); 237 238 template.find('.jconfirm-box-container').addClass(this.columnClassParsed); 239 240 if(this.containerFluid) 241 template.find('.jc-bs3-container').addClass(this.bootstrapClasses.containerFluid); 242 else 243 template.find('.jc-bs3-container').addClass(this.bootstrapClasses.container); 244 }else{ 245 template.find('.jconfirm-box').css('width', this.boxWidth); 246 } 247 248 if(this.titleClass) 249 template.find('.jconfirm-title-c').addClass(this.titleClass); 250 251 template.addClass(this.themeParsed); 252 var ariaLabel = 'jconfirm-box' + this._id; 253 template.find('.jconfirm-box').attr('aria-labelledby', ariaLabel).attr('tabindex', -1); 254 template.find('.jconfirm-content').attr('id', ariaLabel); 255 if(this.bgOpacity !== null) 256 template.find('.jconfirm-bg').css('opacity', this.bgOpacity); 257 if(this.rtl) 258 template.addClass('jconfirm-rtl'); 259 260 this.$el = template.appendTo(this.container); 261 this.$jconfirmBoxContainer = this.$el.find('.jconfirm-box-container'); 262 this.$jconfirmBox = this.$body = this.$el.find('.jconfirm-box'); 263 this.$jconfirmBg = this.$el.find('.jconfirm-bg'); 264 this.$title = this.$el.find('.jconfirm-title'); 265 this.$titleContainer = this.$el.find('.jconfirm-title-c'); 266 this.$content = this.$el.find('div.jconfirm-content'); 267 this.$contentPane = this.$el.find('.jconfirm-content-pane'); 268 this.$icon = this.$el.find('.jconfirm-icon-c'); 269 this.$closeIcon = this.$el.find('.jconfirm-closeIcon'); 270 this.$holder = this.$el.find('.jconfirm-holder'); 271 // this.$content.css(this._getCSS(this.animationSpeed, this.animationBounce)); 272 this.$btnc = this.$el.find('.jconfirm-buttons'); 273 this.$scrollPane = this.$el.find('.jconfirm-scrollpane'); 274 275 that.setStartingPoint(); 276 277 // for loading content via URL 278 this._contentReady = $.Deferred(); 279 this._modalReady = $.Deferred(); 280 this.$holder.css({ 281 'padding-top': this.offsetTop, 282 'padding-bottom': this.offsetBottom, 283 }); 284 285 this.setTitle(); 286 this.setIcon(); 287 this._setButtons(); 288 this._parseContent(); 289 this.initDraggable(); 290 291 if(this.isAjax) 292 this.showLoading(false); 293 294 $.when(this._contentReady, this._modalReady).then(function(){ 295 if(that.isAjaxLoading) 296 setTimeout(function(){ 297 that.isAjaxLoading = false; 298 that.setContent(); 299 that.setTitle(); 300 that.setIcon(); 301 setTimeout(function(){
vendor: 41,394 bytes, lines 302-1378
302 that.hideLoading(false); 303 that._updateContentMaxHeight(); 304 }, 100); 305 if(typeof that.onContentReady === 'function') 306 that.onContentReady(); 307 }, 50); 308 else{ 309 // that.setContent(); 310 that._updateContentMaxHeight(); 311 that.setTitle(); 312 that.setIcon(); 313 if(typeof that.onContentReady === 'function') 314 that.onContentReady(); 315 } 316 317 // start countdown after content has loaded. 318 if(that.autoClose) 319 that._startCountDown(); 320 }).then(function(){ 321 that._watchContent(); 322 }); 323 324 if(this.animation === 'none'){ 325 this.animationSpeed = 1; 326 this.animationBounce = 1; 327 } 328 329 this.$body.css(this._getCSS(this.animationSpeed, this.animationBounce)); 330 this.$contentPane.css(this._getCSS(this.animationSpeed, 1)); 331 this.$jconfirmBg.css(this._getCSS(this.animationSpeed, 1)); 332 this.$jconfirmBoxContainer.css(this._getCSS(this.animationSpeed, 1)); 333 }, 334 _typePrefix: 'jconfirm-type-', 335 typeParsed: '', 336 _parseType: function(type){ 337 this.typeParsed = this._typePrefix + type; 338 }, 339 setType: function(type){ 340 var oldClass = this.typeParsed; 341 this._parseType(type); 342 this.$jconfirmBox.removeClass(oldClass).addClass(this.typeParsed); 343 }, 344 themeParsed: '', 345 _themePrefix: 'jconfirm-', 346 setTheme: function(theme){ 347 var previous = this.theme; 348 this.theme = theme || this.theme; 349 this._parseTheme(this.theme); 350 if(previous) 351 this.$el.removeClass(previous); 352 this.$el.addClass(this.themeParsed); 353 this.theme = theme; 354 }, 355 _parseTheme: function(theme){ 356 var that = this; 357 theme = theme.split(','); 358 $.each(theme, function(k, a){ 359 if(a.indexOf(that._themePrefix) === -1) 360 theme[k] = that._themePrefix + $.trim(a); 361 }); 362 this.themeParsed = theme.join(' ').toLowerCase(); 363 }, 364 backgroundDismissAnimationParsed: '', 365 _bgDismissPrefix: 'jconfirm-hilight-', 366 _parseBgDismissAnimation: function(bgDismissAnimation){ 367 var animation = bgDismissAnimation.split(','); 368 var that = this; 369 $.each(animation, function(k, a){ 370 if(a.indexOf(that._bgDismissPrefix) === -1) 371 animation[k] = that._bgDismissPrefix + $.trim(a); 372 }); 373 this.backgroundDismissAnimationParsed = animation.join(' ').toLowerCase(); 374 }, 375 animationParsed: '', 376 closeAnimationParsed: '', 377 _animationPrefix: 'jconfirm-animation-', 378 setAnimation: function(animation){ 379 this.animation = animation || this.animation; 380 this._parseAnimation(this.animation, 'o'); 381 }, 382 _parseAnimation: function(animation, which){ 383 which = which || 'o'; // parse what animation and store where. open or close? 384 var animations = animation.split(','); 385 var that = this; 386 $.each(animations, function(k, a){ 387 if(a.indexOf(that._animationPrefix) === -1) 388 animations[k] = that._animationPrefix + $.trim(a); 389 }); 390 var a_string = animations.join(' ').toLowerCase(); 391 if(which === 'o') 392 this.animationParsed = a_string; 393 else 394 this.closeAnimationParsed = a_string; 395 396 return a_string; 397 }, 398 setCloseAnimation: function(closeAnimation){ 399 this.closeAnimation = closeAnimation || this.closeAnimation; 400 this._parseAnimation(this.closeAnimation, 'c'); 401 }, 402 setAnimationSpeed: function(speed){ 403 this.animationSpeed = speed || this.animationSpeed; 404 // this.$body.css(this._getCSS(this.animationSpeed, this.animationBounce)); 405 }, 406 columnClassParsed: '', 407 setColumnClass: function(colClass){ 408 if(!this.useBootstrap){ 409 console.warn("cannot set columnClass, useBootstrap is set to false"); 410 return; 411 } 412 this.columnClass = colClass || this.columnClass; 413 this._parseColumnClass(this.columnClass); 414 this.$jconfirmBoxContainer.addClass(this.columnClassParsed); 415 }, 416 _updateContentMaxHeight: function(){ 417 var height = $(window).height() - (this.$jconfirmBox.outerHeight() - this.$contentPane.outerHeight()) - (this.offsetTop + this.offsetBottom); 418 this.$contentPane.css({ 419 'max-height': height + 'px' 420 }); 421 }, 422 setBoxWidth: function(width){ 423 if(this.useBootstrap){ 424 console.warn("cannot set boxWidth, useBootstrap is set to true"); 425 return; 426 } 427 this.boxWidth = width; 428 this.$jconfirmBox.css('width', width); 429 }, 430 _parseColumnClass: function(colClass){ 431 colClass = colClass.toLowerCase(); 432 var p; 433 switch(colClass){ 434 case 'xl': 435 case 'xlarge': 436 p = 'col-md-12'; 437 break; 438 case 'l': 439 case 'large': 440 p = 'col-md-8 col-md-offset-2'; 441 break; 442 case 'm': 443 case 'medium': 444 p = 'col-md-6 col-md-offset-3'; 445 break; 446 case 's': 447 case 'small': 448 p = 'col-md-4 col-md-offset-4'; 449 break; 450 case 'xs': 451 case 'xsmall': 452 p = 'col-md-2 col-md-offset-5'; 453 break; 454 default: 455 p = colClass; 456 } 457 this.columnClassParsed = p; 458 }, 459 initDraggable: function(){ 460 var that = this; 461 var $t = this.$titleContainer; 462 463 this.resetDrag(); 464 if(this.draggable){ 465 $t.on('mousedown', function(e){ 466 $t.addClass('jconfirm-hand'); 467 that.mouseX = e.clientX; 468 that.mouseY = e.clientY; 469 that.isDrag = true; 470 }); 471 $(window).on('mousemove.' + this._id, function(e){ 472 if(that.isDrag){ 473 that.movingX = e.clientX - that.mouseX + that.initialX; 474 that.movingY = e.clientY - that.mouseY + that.initialY; 475 that.setDrag(); 476 } 477 }); 478 479 $(window).on('mouseup.' + this._id, function(){ 480 $t.removeClass('jconfirm-hand'); 481 if(that.isDrag){ 482 that.isDrag = false; 483 that.initialX = that.movingX; 484 that.initialY = that.movingY; 485 } 486 }) 487 } 488 }, 489 resetDrag: function(){ 490 this.isDrag = false; 491 this.initialX = 0; 492 this.initialY = 0; 493 this.movingX = 0; 494 this.movingY = 0; 495 this.mouseX = 0; 496 this.mouseY = 0; 497 this.$jconfirmBoxContainer.css('transform', 'translate(' + 0 + 'px, ' + 0 + 'px)'); 498 }, 499 setDrag: function(){ 500 if(!this.draggable) 501 return; 502 503 this.alignMiddle = false; 504 var boxWidth = this.$jconfirmBox.outerWidth(); 505 var boxHeight = this.$jconfirmBox.outerHeight(); 506 var windowWidth = $(window).width(); 507 var windowHeight = $(window).height(); 508 var that = this; 509 var dragUpdate = 1; 510 if(that.movingX % dragUpdate === 0 || that.movingY % dragUpdate === 0){ 511 if(that.dragWindowBorder){ 512 var leftDistance = (windowWidth / 2) - boxWidth / 2; 513 var topDistance = (windowHeight / 2) - boxHeight / 2; 514 topDistance -= that.dragWindowGap; 515 leftDistance -= that.dragWindowGap; 516 517 if(leftDistance + that.movingX < 0){ 518 that.movingX = -leftDistance; 519 }else if(leftDistance - that.movingX < 0){ 520 that.movingX = leftDistance; 521 } 522 523 if(topDistance + that.movingY < 0){ 524 that.movingY = -topDistance; 525 }else if(topDistance - that.movingY < 0){ 526 that.movingY = topDistance; 527 } 528 } 529 530 that.$jconfirmBoxContainer.css('transform', 'translate(' + that.movingX + 'px, ' + that.movingY + 'px)'); 531 } 532 }, 533 _scrollTop: function(){ 534 if(typeof pageYOffset !== 'undefined'){ 535 //most browsers except IE before #9 536 return pageYOffset; 537 } 538 else{ 539 var B = document.body; //IE 'quirks' 540 var D = document.documentElement; //IE with doctype 541 D = (D.clientHeight) ? D : B; 542 return D.scrollTop; 543 } 544 }, 545 _watchContent: function(){ 546 var that = this; 547 if(this._timer) clearInterval(this._timer); 548 549 var prevContentHeight = 0; 550 this._timer = setInterval(function(){ 551 if(that.smoothContent){ 552 var contentHeight = that.$content.outerHeight() || 0; 553 if(contentHeight !== prevContentHeight){ 554 555 // Commented out to prevent scroll to top when updating the content 556 // (for example when using ajax in forms in content) 557 // that.$contentPane.css({ 558 // 'height': contentHeight 559 // }).scrollTop(0); 560 prevContentHeight = contentHeight; 561 } 562 var wh = $(window).height(); 563 var total = that.offsetTop + that.offsetBottom + that.$jconfirmBox.height() - that.$contentPane.height() + that.$content.height(); 564 if(total < wh){ 565 that.$contentPane.addClass('no-scroll'); 566 }else{ 567 that.$contentPane.removeClass('no-scroll'); 568 } 569 } 570 }, this.watchInterval); 571 }, 572 _overflowClass: 'jconfirm-overflow', 573 _hilightAnimating: false, 574 highlight: function(){ 575 this.hiLightModal(); 576 }, 577 hiLightModal: function(){ 578 var that = this; 579 if(this._hilightAnimating) 580 return; 581 582 that.$body.addClass('hilight'); 583 var duration = parseFloat(that.$body.css('animation-duration')) || 2; 584 this._hilightAnimating = true; 585 setTimeout(function(){ 586 that._hilightAnimating = false; 587 that.$body.removeClass('hilight'); 588 }, duration * 1000); 589 }, 590 _bindEvents: function(){ 591 var that = this; 592 this.boxClicked = false; 593 594 this.$scrollPane.click(function(e){ // Ignore propagated clicks 595 if(!that.boxClicked){ // Background clicked 596 /* 597 If backgroundDismiss is a function and its return value is truthy 598 proceed to close the modal. 599 */ 600 var buttonName = false; 601 var shouldClose = false; 602 var str; 603 604 if(typeof that.backgroundDismiss === 'function') 605 str = that.backgroundDismiss(); 606 else 607 str = that.backgroundDismiss; 608 609 if(typeof str === 'string' && typeof that.buttons[str] !== 'undefined'){ 610 buttonName = str; 611 shouldClose = false; 612 }else if(typeof str === 'undefined' || !!(str) === true){ 613 shouldClose = true; 614 }else{ 615 shouldClose = false; 616 } 617 618 if(buttonName){ 619 var btnResponse = that.buttons[buttonName].action.apply(that); 620 shouldClose = (typeof btnResponse === 'undefined') || !!(btnResponse); 621 } 622 623 if(shouldClose) 624 that.close(); 625 else 626 that.hiLightModal(); 627 } 628 that.boxClicked = false; 629 }); 630 631 this.$jconfirmBox.click(function(e){ 632 that.boxClicked = true; 633 }); 634 635 var isKeyDown = false; 636 $(window).on('jcKeyDown.' + that._id, function(e){ 637 if(!isKeyDown){ 638 isKeyDown = true; 639 } 640 }); 641 $(window).on('keyup.' + that._id, function(e){ 642 if(isKeyDown){ 643 that.reactOnKey(e); 644 isKeyDown = false; 645 } 646 }); 647 648 $(window).on('resize.' + this._id, function(){ 649 that._updateContentMaxHeight(); 650 setTimeout(function(){ 651 that.resetDrag(); 652 }, 100); 653 }); 654 }, 655 _cubic_bezier: '0.36, 0.55, 0.19', 656 _getCSS: function(speed, bounce){ 657 return { 658 '-webkit-transition-duration': speed / 1000 + 's', 659 'transition-duration': speed / 1000 + 's', 660 '-webkit-transition-timing-function': 'cubic-bezier(' + this._cubic_bezier + ', ' + bounce + ')', 661 'transition-timing-function': 'cubic-bezier(' + this._cubic_bezier + ', ' + bounce + ')' 662 }; 663 }, 664 _setButtons: function(){ 665 var that = this; 666 /* 667 * Settings up buttons 668 */ 669 670 var total_buttons = 0; 671 if(typeof this.buttons !== 'object') 672 this.buttons = {}; 673 674 $.each(this.buttons, function(key, button){ 675 total_buttons += 1; 676 if(typeof button === 'function'){ 677 that.buttons[key] = button = { 678 action: button 679 }; 680 } 681 682 that.buttons[key].text = button.text || key; 683 that.buttons[key].btnClass = button.btnClass || 'btn-default'; 684 that.buttons[key].action = button.action || function(){ 685 }; 686 that.buttons[key].keys = button.keys || []; 687 that.buttons[key].isHidden = button.isHidden || false; 688 that.buttons[key].isDisabled = button.isDisabled || false; 689 690 $.each(that.buttons[key].keys, function(i, a){ 691 that.buttons[key].keys[i] = a.toLowerCase(); 692 }); 693 694 var button_element = $('<button type="button" class="btn"></button>') 695 .html(that.buttons[key].text) 696 .addClass(that.buttons[key].btnClass) 697 .prop('disabled', that.buttons[key].isDisabled) 698 .css('display', that.buttons[key].isHidden ? 'none' : '') 699 .click(function(e){ 700 e.preventDefault(); 701 var res = that.buttons[key].action.apply(that, [that.buttons[key]]); 702 that.onAction.apply(that, [key, that.buttons[key]]); 703 that._stopCountDown(); 704 if(typeof res === 'undefined' || res) 705 that.close(); 706 }); 707 708 that.buttons[key].el = button_element; 709 that.buttons[key].setText = function(text){ 710 button_element.html(text); 711 }; 712 that.buttons[key].addClass = function(className){ 713 button_element.addClass(className); 714 }; 715 that.buttons[key].removeClass = function(className){ 716 button_element.removeClass(className); 717 }; 718 that.buttons[key].disable = function(){ 719 that.buttons[key].isDisabled = true; 720 button_element.prop('disabled', true); 721 }; 722 that.buttons[key].enable = function(){ 723 that.buttons[key].isDisabled = false; 724 button_element.prop('disabled', false); 725 }; 726 that.buttons[key].show = function(){ 727 that.buttons[key].isHidden = false; 728 button_element.css('display', ''); 729 }; 730 that.buttons[key].hide = function(){ 731 that.buttons[key].isHidden = true; 732 button_element.css('display', 'none'); 733 }; 734 /* 735 Buttons are prefixed with $_ or $$ for quick access 736 */ 737 that['$_' + key] = that['$$' + key] = button_element; 738 that.$btnc.append(button_element); 739 }); 740 741 if(total_buttons === 0) this.$btnc.hide(); 742 if(this.closeIcon === null && total_buttons === 0){ 743 /* 744 in case when no buttons are present & closeIcon is null, closeIcon is set to true, 745 set closeIcon to true to explicitly tell to hide the close icon 746 */ 747 this.closeIcon = true; 748 } 749 750 if(this.closeIcon){ 751 if(this.closeIconClass){ 752 // user requires a custom class. 753 var closeHtml = '<i class="' + this.closeIconClass + '"></i>'; 754 this.$closeIcon.html(closeHtml); 755 } 756 757 this.$closeIcon.click(function(e){ 758 e.preventDefault(); 759 760 var buttonName = false; 761 var shouldClose = false; 762 var str; 763 764 if(typeof that.closeIcon === 'function'){ 765 str = that.closeIcon(); 766 }else{ 767 str = that.closeIcon; 768 } 769 770 if(typeof str === 'string' && typeof that.buttons[str] !== 'undefined'){ 771 buttonName = str; 772 shouldClose = false; 773 }else if(typeof str === 'undefined' || !!(str) === true){ 774 shouldClose = true; 775 }else{ 776 shouldClose = false; 777 } 778 if(buttonName){ 779 var btnResponse = that.buttons[buttonName].action.apply(that); 780 shouldClose = (typeof btnResponse === 'undefined') || !!(btnResponse); 781 } 782 if(shouldClose){ 783 that.close(); 784 } 785 }); 786 this.$closeIcon.show(); 787 }else{ 788 this.$closeIcon.hide(); 789 } 790 }, 791 setTitle: function(string, force){ 792 force = force || false; 793 794 if(typeof string !== 'undefined') 795 if(typeof string === 'string') 796 this.title = string; 797 else if(typeof string === 'function'){ 798 if(typeof string.promise === 'function') 799 console.error('Promise was returned from title function, this is not supported.'); 800 801 var response = string(); 802 if(typeof response === 'string') 803 this.title = response; 804 else 805 this.title = false; 806 }else 807 this.title = false; 808 809 if(this.isAjaxLoading && !force) 810 return; 811 812 this.$title.html(this.title || ''); 813 this.updateTitleContainer(); 814 }, 815 setIcon: function(iconClass, force){ 816 force = force || false; 817 818 if(typeof iconClass !== 'undefined') 819 if(typeof iconClass === 'string') 820 this.icon = iconClass; 821 else if(typeof iconClass === 'function'){ 822 var response = iconClass(); 823 if(typeof response === 'string') 824 this.icon = response; 825 else 826 this.icon = false; 827 } 828 else 829 this.icon = false; 830 831 if(this.isAjaxLoading && !force) 832 return; 833 834 this.$icon.html(this.icon ? '<i class="' + this.icon + '"></i>' : ''); 835 this.updateTitleContainer(); 836 }, 837 updateTitleContainer: function(){ 838 if(!this.title && !this.icon){ 839 this.$titleContainer.hide(); 840 }else{ 841 this.$titleContainer.show(); 842 } 843 }, 844 setContentPrepend: function(content, force){ 845 if(!content) 846 return; 847 848 this.contentParsed.prepend(content); 849 }, 850 setContentAppend: function(content){ 851 if(!content) 852 return; 853 854 this.contentParsed.append(content); 855 }, 856 setContent: function(content, force){ 857 force = !!force; 858 var that = this; 859 if(content) 860 this.contentParsed.html('').append(content); 861 if(this.isAjaxLoading && !force) 862 return; 863 864 this.$content.html(''); 865 this.$content.append(this.contentParsed); 866 setTimeout(function(){ 867 that.$body.find('input[autofocus]:visible:first').focus(); 868 }, 100); 869 }, 870 loadingSpinner: false, 871 showLoading: function(disableButtons){ 872 this.loadingSpinner = true; 873 this.$jconfirmBox.addClass('loading'); 874 if(disableButtons) 875 this.$btnc.find('button').prop('disabled', true); 876 877 }, 878 hideLoading: function(enableButtons){ 879 this.loadingSpinner = false; 880 this.$jconfirmBox.removeClass('loading'); 881 if(enableButtons) 882 this.$btnc.find('button').prop('disabled', false); 883 884 }, 885 ajaxResponse: false, 886 contentParsed: '', 887 isAjax: false, 888 isAjaxLoading: false, 889 _parseContent: function(){ 890 var that = this; 891 var e = ' '; 892 893 if(typeof this.content === 'function'){ 894 var res = this.content.apply(this); 895 if(typeof res === 'string'){ 896 this.content = res; 897 } 898 else if(typeof res === 'object' && typeof res.always === 'function'){ 899 // this is ajax loading via promise 900 this.isAjax = true; 901 this.isAjaxLoading = true; 902 res.always(function(data, status, xhr){ 903 that.ajaxResponse = { 904 data: data, 905 status: status, 906 xhr: xhr 907 }; 908 that._contentReady.resolve(data, status, xhr); 909 if(typeof that.contentLoaded === 'function') 910 that.contentLoaded(data, status, xhr); 911 }); 912 this.content = e; 913 }else{ 914 this.content = e; 915 } 916 } 917 918 if(typeof this.content === 'string' && this.content.substr(0, 4).toLowerCase() === 'url:'){ 919 this.isAjax = true; 920 this.isAjaxLoading = true; 921 var u = this.content.substring(4, this.content.length); 922 $.get(u).done(function(html){ 923 that.contentParsed.html(html); 924 }).always(function(data, status, xhr){ 925 that.ajaxResponse = { 926 data: data, 927 status: status, 928 xhr: xhr 929 }; 930 that._contentReady.resolve(data, status, xhr); 931 if(typeof that.contentLoaded === 'function') 932 that.contentLoaded(data, status, xhr); 933 }); 934 } 935 936 if(!this.content) 937 this.content = e; 938 939 if(!this.isAjax){ 940 this.contentParsed.html(this.content); 941 this.setContent(); 942 that._contentReady.resolve(); 943 } 944 }, 945 _stopCountDown: function(){ 946 clearInterval(this.autoCloseInterval); 947 if(this.$cd) 948 this.$cd.remove(); 949 }, 950 _startCountDown: function(){ 951 var that = this; 952 var opt = this.autoClose.split('|'); 953 if(opt.length !== 2){ 954 console.error('Invalid option for autoClose. example \'close|10000\''); 955 return false; 956 } 957 958 var button_key = opt[0]; 959 var time = parseInt(opt[1]); 960 if(typeof this.buttons[button_key] === 'undefined'){ 961 console.error('Invalid button key \'' + button_key + '\' for autoClose'); 962 return false; 963 } 964 965 var seconds = Math.ceil(time / 1000); 966 this.$cd = $('<span class="countdown"> (' + seconds + ')</span>') 967 .appendTo(this['$_' + button_key]); 968 969 this.autoCloseInterval = setInterval(function(){ 970 that.$cd.html(' (' + (seconds -= 1) + ') '); 971 if(seconds <= 0){ 972 that['$$' + button_key].trigger('click'); 973 that._stopCountDown(); 974 } 975 }, 1000); 976 }, 977 _getKey: function(key){ 978 // very necessary keys. 979 switch(key){ 980 case 192: 981 return 'tilde'; 982 case 13: 983 return 'enter'; 984 case 16: 985 return 'shift'; 986 case 9: 987 return 'tab'; 988 case 20: 989 return 'capslock'; 990 case 17: 991 return 'ctrl'; 992 case 91: 993 return 'win'; 994 case 18: 995 return 'alt'; 996 case 27: 997 return 'esc'; 998 case 32: 999 return 'space'; 1000 } 1001 1002 // only trust alphabets with this. 1003 var initial = String.fromCharCode(key); 1004 if(/^[A-z0-9]+$/.test(initial)) 1005 return initial.toLowerCase(); 1006 else 1007 return false; 1008 }, 1009 reactOnKey: function(e){ 1010 var that = this; 1011 1012 /* 1013 Prevent keyup event if the dialog is not last! 1014 */ 1015 var a = $('.jconfirm'); 1016 if(a.eq(a.length - 1)[0] !== this.$el[0]) 1017 return false; 1018 1019 var key = e.which; 1020 /* 1021 Do not react if Enter or Space is pressed on input elements 1022 */ 1023 if(this.$content.find(':input').is(':focus') && /13|32/.test(key)) 1024 return false; 1025 1026 var keyChar = this._getKey(key); 1027 1028 // If esc is pressed 1029 if(keyChar === 'esc' && this.escapeKey){ 1030 if(this.escapeKey === true){ 1031 this.$scrollPane.trigger('click'); 1032 } 1033 else if(typeof this.escapeKey === 'string' || typeof this.escapeKey === 'function'){ 1034 var buttonKey; 1035 if(typeof this.escapeKey === 'function'){ 1036 buttonKey = this.escapeKey(); 1037 }else{ 1038 buttonKey = this.escapeKey; 1039 } 1040 1041 if(buttonKey) 1042 if(typeof this.buttons[buttonKey] === 'undefined'){ 1043 console.warn('Invalid escapeKey, no buttons found with key ' + buttonKey); 1044 }else{ 1045 this['$_' + buttonKey].trigger('click'); 1046 } 1047 } 1048 } 1049 1050 // check if any button is listening to this key. 1051 $.each(this.buttons, function(key, button){ 1052 if(button.keys.indexOf(keyChar) !== -1){ 1053 that['$_' + key].trigger('click'); 1054 } 1055 }); 1056 }, 1057 setDialogCenter: function(){ 1058 console.info('setDialogCenter is deprecated, dialogs are centered with CSS3 tables'); 1059 }, 1060 _unwatchContent: function(){ 1061 clearInterval(this._timer); 1062 }, 1063 close: function(onClosePayload){ 1064 var that = this; 1065 1066 if(typeof this.onClose === 'function') 1067 this.onClose(onClosePayload); 1068 1069 this._unwatchContent(); 1070 1071 /* 1072 unbind the window resize & keyup event. 1073 */ 1074 $(window).unbind('resize.' + this._id); 1075 $(window).unbind('keyup.' + this._id); 1076 $(window).unbind('jcKeyDown.' + this._id); 1077 1078 if(this.draggable){ 1079 $(window).unbind('mousemove.' + this._id); 1080 $(window).unbind('mouseup.' + this._id); 1081 this.$titleContainer.unbind('mousedown'); 1082 } 1083 1084 that.$el.removeClass(that.loadedClass); 1085 $('body').removeClass('jconfirm-no-scroll-' + that._id); 1086 that.$jconfirmBoxContainer.removeClass('jconfirm-no-transition'); 1087 1088 setTimeout(function(){ 1089 that.$body.addClass(that.closeAnimationParsed); 1090 that.$jconfirmBg.addClass('jconfirm-bg-h'); 1091 var closeTimer = (that.closeAnimation === 'none') ? 1 : that.animationSpeed; 1092 1093 setTimeout(function(){ 1094 that.$el.remove(); 1095 1096 var l = w.jconfirm.instances; 1097 var i = w.jconfirm.instances.length - 1; 1098 for(i; i >= 0; i--){ 1099 if(w.jconfirm.instances[i]._id === that._id){ 1100 w.jconfirm.instances.splice(i, 1); 1101 } 1102 } 1103 1104 // Focusing a element, scrolls automatically to that element. 1105 // no instances should be open, lastFocused should be true, the lastFocused element must exists in DOM 1106 if(!w.jconfirm.instances.length){ 1107 if(that.scrollToPreviousElement && w.jconfirm.lastFocused && w.jconfirm.lastFocused.length && $.contains(document, w.jconfirm.lastFocused[0])){ 1108 var $lf = w.jconfirm.lastFocused; 1109 if(that.scrollToPreviousElementAnimate){ 1110 var st = $(window).scrollTop(); 1111 var ot = w.jconfirm.lastFocused.offset().top; 1112 var wh = $(window).height(); 1113 if(!(ot > st && ot < (st + wh))){ 1114 var scrollTo = (ot - Math.round((wh / 3))); 1115 $('html, body').animate({ 1116 scrollTop: scrollTo 1117 }, that.animationSpeed, 'swing', function(){ 1118 // gracefully scroll and then focus. 1119 $lf.focus(); 1120 }); 1121 }else{ 1122 // the element to be focused is already in view. 1123 $lf.focus(); 1124 } 1125 }else{ 1126 $lf.focus(); 1127 } 1128 w.jconfirm.lastFocused = false; 1129 } 1130 } 1131 1132 if(typeof that.onDestroy === 'function') 1133 that.onDestroy(); 1134 1135 }, closeTimer * 0.40); 1136 }, 50); 1137 1138 return true; 1139 }, 1140 open: function(){ 1141 if(this.isOpen()) 1142 return false; 1143 1144 // var that = this; 1145 this._buildHTML(); 1146 this._bindEvents(); 1147 this._open(); 1148 1149 return true; 1150 }, 1151 setStartingPoint: function(){ 1152 var el = false; 1153 1154 if(this.animateFromElement !== true && this.animateFromElement){ 1155 el = this.animateFromElement; 1156 w.jconfirm.lastClicked = false; 1157 }else if(w.jconfirm.lastClicked && this.animateFromElement === true){ 1158 el = w.jconfirm.lastClicked; 1159 w.jconfirm.lastClicked = false; 1160 }else{ 1161 return false; 1162 } 1163 1164 if(!el) 1165 return false; 1166 1167 var offset = el.offset(); 1168 1169 var iTop = el.outerHeight() / 2; 1170 var iLeft = el.outerWidth() / 2; 1171 1172 // placing position of jconfirm modal in center of clicked element 1173 iTop -= this.$jconfirmBox.outerHeight() / 2; 1174 iLeft -= this.$jconfirmBox.outerWidth() / 2; 1175 1176 // absolute position on screen 1177 var sourceTop = offset.top + iTop; 1178 sourceTop = sourceTop - this._scrollTop(); 1179 var sourceLeft = offset.left + iLeft; 1180 1181 // window halved 1182 var wh = $(window).height() / 2; 1183 var ww = $(window).width() / 2; 1184 1185 var targetH = wh - this.$jconfirmBox.outerHeight() / 2; 1186 var targetW = ww - this.$jconfirmBox.outerWidth() / 2; 1187 1188 sourceTop -= targetH; 1189 sourceLeft -= targetW; 1190 1191 // Check if the element is inside the viewable window. 1192 if(Math.abs(sourceTop) > wh || Math.abs(sourceLeft) > ww) 1193 return false; 1194 1195 this.$jconfirmBoxContainer.css('transform', 'translate(' + sourceLeft + 'px, ' + sourceTop + 'px)'); 1196 }, 1197 _open: function(){ 1198 var that = this; 1199 if(typeof that.onOpenBefore === 'function') 1200 that.onOpenBefore(); 1201 1202 this.$body.removeClass(this.animationParsed); 1203 this.$jconfirmBg.removeClass('jconfirm-bg-h'); 1204 this.$body.focus(); 1205 1206 that.$jconfirmBoxContainer.css('transform', 'translate(' + 0 + 'px, ' + 0 + 'px)'); 1207 1208 setTimeout(function(){ 1209 that.$body.css(that._getCSS(that.animationSpeed, 1)); 1210 that.$body.css({ 1211 'transition-property': that.$body.css('transition-property') + ', margin' 1212 }); 1213 that.$jconfirmBoxContainer.addClass('jconfirm-no-transition'); 1214 that._modalReady.resolve(); 1215 if(typeof that.onOpen === 'function') 1216 that.onOpen(); 1217 1218 that.$el.addClass(that.loadedClass); 1219 }, this.animationSpeed); 1220 }, 1221 loadedClass: 'jconfirm-open', 1222 isClosed: function(){ 1223 return !this.$el || this.$el.parent().length === 0; 1224 }, 1225 isOpen: function(){ 1226 return !this.isClosed(); 1227 }, 1228 toggle: function(){ 1229 if(!this.isOpen()) 1230 this.open(); 1231 else 1232 this.close(); 1233 } 1234 }; 1235 1236 w.jconfirm.instances = []; 1237 w.jconfirm.lastFocused = false; 1238 w.jconfirm.pluginDefaults = { 1239 template: '' + 1240 '<div class="jconfirm">' + 1241 '<div class="jconfirm-bg jconfirm-bg-h"></div>' + 1242 '<div class="jconfirm-scrollpane">' + 1243 '<div class="jconfirm-row">' + 1244 '<div class="jconfirm-cell">' + 1245 '<div class="jconfirm-holder">' + 1246 '<div class="jc-bs3-container">' + 1247 '<div class="jc-bs3-row">' + 1248 '<div class="jconfirm-box-container jconfirm-animated">' + 1249 '<div class="jconfirm-box" role="dialog" aria-labelledby="labelled" tabindex="-1">' + 1250 '<div class="jconfirm-closeIcon">×</div>' + 1251 '<div class="jconfirm-title-c">' + 1252 '<span class="jconfirm-icon-c"></span>' + 1253 '<span class="jconfirm-title"></span>' + 1254 '</div>' + 1255 '<div class="jconfirm-content-pane">' + 1256 '<div class="jconfirm-content"></div>' + 1257 '</div>' + 1258 '<div class="jconfirm-buttons">' + 1259 '</div>' + 1260 '<div class="jconfirm-clear">' + 1261 '</div>' + 1262 '</div>' + 1263 '</div>' + 1264 '</div>' + 1265 '</div>' + 1266 '</div>' + 1267 '</div>' + 1268 '</div>' + 1269 '</div></div>', 1270 title: 'Hello', 1271 titleClass: '', 1272 type: 'default', 1273 typeAnimated: true, 1274 draggable: true, 1275 dragWindowGap: 15, 1276 dragWindowBorder: true, 1277 animateFromElement: true, 1278 /** 1279 * @deprecated 1280 */ 1281 alignMiddle: true, 1282 smoothContent: true, 1283 content: 'Are you sure to continue?', 1284 buttons: {}, 1285 defaultButtons: { 1286 ok: { 1287 action: function(){ 1288 } 1289 }, 1290 close: { 1291 action: function(){ 1292 } 1293 } 1294 }, 1295 contentLoaded: function(){ 1296 }, 1297 icon: '', 1298 lazyOpen: false, 1299 bgOpacity: null, 1300 theme: 'light', 1301 animation: 'scale', 1302 closeAnimation: 'scale', 1303 animationSpeed: 400, 1304 animationBounce: 1, 1305 escapeKey: true, 1306 rtl: false, 1307 container: 'body', 1308 containerFluid: false, 1309 backgroundDismiss: false, 1310 backgroundDismissAnimation: 'shake', 1311 autoClose: false, 1312 closeIcon: null, 1313 closeIconClass: false, 1314 watchInterval: 100, 1315 columnClass: 'col-md-4 col-md-offset-4 col-sm-6 col-sm-offset-3 col-xs-10 col-xs-offset-1', 1316 boxWidth: '50%', 1317 scrollToPreviousElement: true, 1318 scrollToPreviousElementAnimate: true, 1319 useBootstrap: true, 1320 offsetTop: 40, 1321 offsetBottom: 40, 1322 bootstrapClasses: { 1323 container: 'container', 1324 containerFluid: 'container-fluid', 1325 row: 'row' 1326 }, 1327 onContentReady: function(){ 1328 1329 }, 1330 onOpenBefore: function(){ 1331 1332 }, 1333 onOpen: function(){ 1334 1335 }, 1336 onClose: function(){ 1337 1338 }, 1339 onDestroy: function(){ 1340 1341 }, 1342 onAction: function(){ 1343 1344 } 1345 }; 1346 1347 /** 1348 * This refers to the issue #241 and #246 1349 * 1350 * Problem: 1351 * Button A is clicked (keydown) using the Keyboard ENTER key 1352 * A opens the jconfirm modal B, 1353 * B has registered ENTER key for one of its button C 1354 * A is released (keyup), B gets the keyup event and triggers C. 1355 * 1356 * Solution: 1357 * Register a global keydown event, that tells jconfirm if the keydown originated inside jconfirm 1358 */ 1359 var keyDown = false; 1360 $(window).on('keydown', function(e){ 1361 if(!keyDown){ 1362 var $target = $(e.target); 1363 var pass = false; 1364 if($target.closest('.jconfirm-box').length) 1365 pass = true; 1366 if(pass) 1367 $(window).trigger('jcKeyDown'); 1368 1369 keyDown = true; 1370 } 1371 }); 1372 $(window).on('keyup', function(){ 1373 keyDown = false; 1374 }); 1375 w.jconfirm.lastClicked = false; 1376 $(document).on('mousedown', 'button, a, [jc-source]', function(){ 1377 w.jconfirm.lastClicked = $(this); 1378 });
1379})); 1380 1381 1382/*! 1383 * jquery-confirm revival compatibility patch 1384 * 1385 * Load after jquery-confirm.js in browsers, or require this file as the package 1386 * entry point in CommonJS builds. This intentionally patches the existing 1387 * v3.x runtime instead of replacing the project with another rewrite. 1388 */ 1389(function(factory){ 1390 if(typeof define === 'function' && define.amd){ 1391 define(['jquery', './jquery-confirm'], factory); 1392 }else if(typeof module === 'object' && module.exports){ 1393 module.exports = function(root, jQuery){ 1394 if(jQuery === undefined){ 1395 if(typeof window !== 'undefined'){ 1396 jQuery = require('jquery'); 1397 root = window; 1398 }else{ 1399 jQuery = require('jquery')(root); 1400 } 1401 } 1402 1403 var jqueryConfirm = require('./jquery-confirm'); 1404 if(typeof jqueryConfirm === 'function'){ 1405 jqueryConfirm(root, jQuery); 1406 } 1407 1408 factory(jQuery, root || (typeof window !== 'undefined' ? window : undefined)); 1409 return jQuery; 1410 }; 1411 }else{ 1412 factory(jQuery, window); 1413 } 1414}(function($, w){ 1415 "use strict"; 1416 1417 if(!$ || !w || !w.Jconfirm){ 1418 if(w && w.console && typeof w.console.warn === 'function'){ 1419 w.console.warn('jquery-confirm-revival.js must be loaded after jquery-confirm.js'); 1420 } 1421 return; 1422 } 1423 1424 var proto = w.Jconfirm.prototype; 1425 if(proto._revivalPatchApplied){ 1426 return; 1427 } 1428 1429 function trim(value){ 1430 return (value === null || typeof value === 'undefined') ? '' : String(value).trim(); 1431 } 1432 1433 function addSafeIcon($container, className){ 1434 $container.empty(); 1435 className = trim(className); 1436 if(className){ 1437 $('<i></i>').addClass(className).appendTo($container); 1438 } 1439 } 1440 1441 proto._revivalPatchApplied = true; 1442 1443 proto._parseTheme = function(theme){ 1444 var that = this; 1445 theme = (theme || '').split(','); 1446 $.each(theme, function(k, a){ 1447 if(a.indexOf(that._themePrefix) === -1) 1448 theme[k] = that._themePrefix + trim(a); 1449 }); 1450 this.themeParsed = theme.join(' ').toLowerCase(); 1451 }; 1452 1453 proto._parseBgDismissAnimation = function(bgDismissAnimation){ 1454 var animation = (bgDismissAnimation || '').split(','); 1455 var that = this; 1456 $.each(animation, function(k, a){ 1457 if(a.indexOf(that._bgDismissPrefix) === -1) 1458 animation[k] = that._bgDismissPrefix + trim(a); 1459 }); 1460 this.backgroundDismissAnimationParsed = animation.join(' ').toLowerCase(); 1461 }; 1462 1463 proto._parseAnimation = function(animation, which){ 1464 which = which || 'o'; 1465 var animations = (animation || '').split(','); 1466 var that = this; 1467 $.each(animations, function(k, a){ 1468 if(a.indexOf(that._animationPrefix) === -1) 1469 animations[k] = that._animationPrefix + trim(a); 1470 }); 1471 var a_string = animations.join(' ').toLowerCase(); 1472 if(which === 'o') 1473 this.animationParsed = a_string; 1474 else 1475 this.closeAnimationParsed = a_string; 1476 1477 return a_string; 1478 }; 1479 1480 proto.setIcon = function(iconClass, force){ 1481 force = force || false; 1482 1483 if(typeof iconClass !== 'undefined'){ 1484 if(typeof iconClass === 'string'){ 1485 this.icon = iconClass; 1486 }else if(typeof iconClass === 'function'){ 1487 var response = iconClass(); 1488 this.icon = (typeof response === 'string') ? response : false; 1489 }else{ 1490 this.icon = false; 1491 } 1492 } 1493 1494 if(this.isAjaxLoading && !force) 1495 return; 1496 1497 addSafeIcon(this.$icon, this.icon); 1498 this.updateTitleContainer(); 1499 }; 1500 1501 proto._isButtonActionable = function(buttonKey){ 1502 var button = this.buttons && this.buttons[buttonKey]; 1503 var $button = this['$_' + buttonKey]; 1504 1505 if(!button || !$button || !$button.length) 1506 return false; 1507 1508 if(button.isDisabled || button.isHidden) 1509 return false; 1510 1511 if($button.prop('disabled') || $button.css('display') === 'none') 1512 return false; 1513 1514 return true; 1515 }; 1516 1517 proto._triggerButtonAction = function(buttonKey){ 1518 if(!this._isButtonActionable(buttonKey)) 1519 return false; 1520 1521 this['$_' + buttonKey].trigger('click'); 1522 return true; 1523 }; 1524 1525 proto._setButtons = function(){ 1526 var that = this; 1527 var total_buttons = 0; 1528 if(typeof this.buttons !== 'object') 1529 this.buttons = {}; 1530 1531 $.each(this.buttons, function(key, button){ 1532 total_buttons += 1;
1533 if(typeof button === 'function'){ 1534 that.buttons[key] = button = { 1535 action: button 1536 }; 1537 } 1538 1539 that.buttons[key].text = button.text || key; 1540 that.buttons[key].btnClass = button.btnClass || 'btn-default'; 1541 that.buttons[key].action = button.action || function(){ 1542 }; 1543 that.buttons[key].keys = button.keys || []; 1544 that.buttons[key].isHidden = button.isHidden || false; 1545 that.buttons[key].isDisabled = button.isDisabled || false; 1546 1547 $.each(that.buttons[key].keys, function(i, a){ 1548 that.buttons[key].keys[i] = String(a).toLowerCase(); 1549 }); 1550 1551 var button_element = $('<button type="button" class="btn"></button>') 1552 .html(that.buttons[key].text) 1553 .addClass(that.buttons[key].btnClass) 1554 .prop('disabled', that.buttons[key].isDisabled) 1555 .css('display', that.buttons[key].isHidden ? 'none' : '') 1556 .click(function(e){ 1557 e.preventDefault(); 1558 1559 if(!that._isButtonActionable(key)) 1560 return false; 1561 1562 var res = that.buttons[key].action.apply(that, [that.buttons[key]]); 1563 that.onAction.apply(that, [key, that.buttons[key]]); 1564 that._stopCountDown(); 1565 if(typeof res === 'undefined' || res) 1566 that.close(); 1567 }); 1568 1569 that.buttons[key].el = button_element; 1570 that.buttons[key].setText = function(text){ 1571 button_element.html(text); 1572 }; 1573 that.buttons[key].addClass = function(className){ 1574 button_element.addClass(className); 1575 }; 1576 that.buttons[key].removeClass = function(className){ 1577 button_element.removeClass(className); 1578 }; 1579 that.buttons[key].disable = function(){ 1580 that.buttons[key].isDisabled = true; 1581 button_element.prop('disabled', true); 1582 }; 1583 that.buttons[key].enable = function(){ 1584 that.buttons[key].isDisabled = false; 1585 button_element.prop('disabled', false); 1586 }; 1587 that.buttons[key].show = function(){ 1588 that.buttons[key].isHidden = false; 1589 button_element.css('display', ''); 1590 }; 1591 that.buttons[key].hide = function(){ 1592 that.buttons[key].isHidden = true; 1593 button_element.css('display', 'none'); 1594 }; 1595 1596 that['$_' + key] = that['$$' + key] = button_element; 1597 that.$btnc.append(button_element); 1598 }); 1599 1600 if(total_buttons === 0) this.$btnc.hide(); 1601 if(this.closeIcon === null && total_buttons === 0){ 1602 this.closeIcon = true; 1603 } 1604 1605 if(this.closeIcon){ 1606 if(this.closeIconClass){ 1607 addSafeIcon(this.$closeIcon, this.closeIconClass); 1608 } 1609 1610 this.$closeIcon.click(function(e){ 1611 e.preventDefault(); 1612 1613 var buttonName = false; 1614 var shouldClose = false; 1615 var str; 1616 1617 if(typeof that.closeIcon === 'function'){ 1618 str = that.closeIcon(); 1619 }else{ 1620 str = that.closeIcon; 1621 } 1622 1623 if(typeof str === 'string' && typeof that.buttons[str] !== 'undefined'){ 1624 buttonName = str; 1625 shouldClose = false; 1626 }else if(typeof str === 'undefined' || !!(str) === true){ 1627 shouldClose = true; 1628 }else{ 1629 shouldClose = false; 1630 } 1631 if(buttonName){ 1632 if(that._isButtonActionable(buttonName)){ 1633 var btnResponse = that.buttons[buttonName].action.apply(that, [that.buttons[buttonName]]); 1634 that.onAction.apply(that, [buttonName, that.buttons[buttonName]]); 1635 that._stopCountDown(); 1636 shouldClose = (typeof btnResponse === 'undefined') || !!(btnResponse); 1637 }else{ 1638 shouldClose = false; 1639 } 1640 } 1641 if(shouldClose){ 1642 that.close(); 1643 } 1644 }); 1645 this.$closeIcon.show(); 1646 }else{ 1647 this.$closeIcon.hide(); 1648 } 1649 }; 1650 1651 proto._ensureContentMounted = function(){ 1652 if(!this.$content || !this.$content.length) 1653 return; 1654 1655 if(this.contentParsed.parent()[0] !== this.$content[0]){ 1656 this.$content.html(''); 1657 this.$content.append(this.contentParsed); 1658 } 1659 }; 1660 1661 proto.setContentPrepend = function(content, force){ 1662 if(typeof content === 'undefined' || content === null) 1663 return this; 1664 1665 this.contentParsed.prepend(content); 1666 if(!(this.isAjaxLoading && !force)){ 1667 this._ensureContentMounted(); 1668 this._updateContentMaxHeight(); 1669 } 1670 return this; 1671 }; 1672 1673 proto.setContentAppend = function(content, force){ 1674 if(typeof content === 'undefined' || content === null) 1675 return this; 1676 1677 this.contentParsed.append(content); 1678 if(!(this.isAjaxLoading && !force)){ 1679 this._ensureContentMounted(); 1680 this._updateContentMaxHeight(); 1681 } 1682 return this; 1683 }; 1684 1685 proto.setContent = function(content, force){ 1686 force = !!force; 1687 var that = this; 1688 if(typeof content !== 'undefined') 1689 this.contentParsed.html('').append(content); 1690 if(this.isAjaxLoading && !force) 1691 return this; 1692 1693 this._ensureContentMounted(); 1694 this._updateContentMaxHeight(); 1695 setTimeout(function(){ 1696 that.$body.find('input[autofocus]:visible:first').focus(); 1697 }, 100); 1698 return this; 1699 }; 1700 1701 proto._bindEvents = function(){ 1702 var that = this; 1703 this.boxClicked = false; 1704 1705 this.$scrollPane.click(function(e){
vendor: 3,578 bytes, lines 1706-1810
1706 if(!that.boxClicked){ 1707 var buttonName = false; 1708 var shouldClose = false; 1709 var str; 1710 1711 if(typeof that.backgroundDismiss === 'function') 1712 str = that.backgroundDismiss(); 1713 else 1714 str = that.backgroundDismiss; 1715 1716 if(typeof str === 'string' && typeof that.buttons[str] !== 'undefined'){ 1717 buttonName = str; 1718 shouldClose = false; 1719 }else if(typeof str === 'undefined' || !!(str) === true){ 1720 shouldClose = true; 1721 }else{ 1722 shouldClose = false; 1723 } 1724 1725 if(buttonName){ 1726 if(that._isButtonActionable(buttonName)){ 1727 var btnResponse = that.buttons[buttonName].action.apply(that, [that.buttons[buttonName]]); 1728 that.onAction.apply(that, [buttonName, that.buttons[buttonName]]); 1729 that._stopCountDown(); 1730 shouldClose = (typeof btnResponse === 'undefined') || !!(btnResponse); 1731 }else{ 1732 shouldClose = false; 1733 } 1734 } 1735 1736 if(shouldClose) 1737 that.close(); 1738 else 1739 that.hiLightModal(); 1740 } 1741 that.boxClicked = false; 1742 }); 1743 1744 this.$jconfirmBox.click(function(e){ 1745 that.boxClicked = true; 1746 }); 1747 1748 var isKeyDown = false; 1749 $(window).on('jcKeyDown.' + that._id, function(e){ 1750 if(!isKeyDown){ 1751 isKeyDown = true; 1752 } 1753 }); 1754 $(window).on('keyup.' + that._id, function(e){ 1755 if(isKeyDown){ 1756 that.reactOnKey(e); 1757 isKeyDown = false; 1758 } 1759 }); 1760 1761 $(window).on('resize.' + this._id, function(){ 1762 that._updateContentMaxHeight(); 1763 setTimeout(function(){ 1764 that.resetDrag(); 1765 }, 100); 1766 }); 1767 }; 1768 1769 proto.reactOnKey = function(e){ 1770 var that = this; 1771 1772 var a = $('.jconfirm'); 1773 if(a.eq(a.length - 1)[0] !== this.$el[0]) 1774 return false; 1775 1776 var key = e.which; 1777 if(this.$content.find(':input').is(':focus') && /13|32/.test(key)) 1778 return false; 1779 1780 var keyChar = this._getKey(key); 1781 1782 if(keyChar === 'esc' && this.escapeKey){ 1783 if(this.escapeKey === true){ 1784 this.$scrollPane.trigger('click'); 1785 } 1786 else if(typeof this.escapeKey === 'string' || typeof this.escapeKey === 'function'){ 1787 var buttonKey; 1788 if(typeof this.escapeKey === 'function'){ 1789 buttonKey = this.escapeKey(); 1790 }else{ 1791 buttonKey = this.escapeKey; 1792 } 1793 1794 if(buttonKey){ 1795 if(typeof this.buttons[buttonKey] === 'undefined'){ 1796 console.warn('Invalid escapeKey, no buttons found with key ' + buttonKey); 1797 }else{ 1798 this._triggerButtonAction(buttonKey); 1799 } 1800 } 1801 } 1802 } 1803 1804 $.each(this.buttons, function(key, button){ 1805 if(button.keys.indexOf(keyChar) !== -1){ 1806 that._triggerButtonAction(key); 1807 } 1808 }); 1809 }; 1810}));
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.