1(function( global, factory ) { 2 if ( typeof exports === 'object' && typeof module !== 'undefined' ) { 3 module.exports = factory(); 4 } else if ( typeof define === 'function' && define.amd ) { 5 define(factory); 6 } else { 7 global.Custombox = factory(); 8 } 9}(this, function() { 10 'use strict'; 11 /* 12 ---------------------------- 13 Settings 14 ---------------------------- 15 */ 16 var _defaults = { 17 target: null, // Set the URL, ID or Class. 18 cache: false, // If set to false, it will force requested pages not to be cached by the browser only when send by AJAX. 19 escKey: true, // Allows the user to close the modal by pressing 'ESC'. 20 zIndex: 9999, // Overlay z-index: Auto or number. 21 overlay: true, // Show the overlay. 22 overlayColor: '#000', // Overlay color. 23 overlayOpacity: 0.8, // The overlay opacity level. Range: 0 to 1. 24 overlayClose: true, // Allows the user to close the modal by clicking the overlay. 25 overlaySpeed: 300, // Sets the speed of the overlay, in milliseconds. 26 overlayEffect: 'auto', // Combine any of the effects. 27 width: null, // Set a fixed total width or 'full'. 28 effect: 'fadein', // fadein | slide | newspaper | fall | sidefall | blur | flip | sign | superscaled | slit | rotate | letmein | makeway | slip | corner | slidetogether | scale | door | push | contentscale | swell | rotatedown | flash. 29 position: ['center', 'center'], // Set position of modal. First position 'x': left, center and right. Second position 'y': top, center, bottom. 30 animation: null, // Only with effects: slide, flip and rotate (top, right, bottom, left and center) | (vertical or horizontal) and output position. Example: ['top', 'bottom']. 31 speed: 500, // Sets the speed of the transitions, in milliseconds. 32 loading: false, // Show loading. 33 open: null, // Callback that fires right before begins to open. 34 complete: null, // Callback that fires right after loaded content is displayed. 35 close: null // Callback that fires once is closed. 36 }, 37 /* 38 ---------------------------- 39 Config 40 ---------------------------- 41 */ 42 _config = { 43 oldIE: navigator.appVersion.indexOf('MSIE 8.') > -1 || navigator.appVersion.indexOf('MSIE 9.') > -1, // Check if is a old IE. 44 oldMobile: /(iPhone|iPad|iPod)\sOS\s6/.test(navigator.userAgent), // Check if is a old browser mobile. 45 overlay: { 46 perspective: ['letmein', 'makeway', 'slip'], // Custom effects overlay. 47 together: ['corner', 'slidetogether', 'scale', 'door', 'push', 'contentscale', 'simplegenie', 'slit', 'slip'] // Animation together (overlay and modal). 48 }, 49 modal: { 50 position: ['slide', 'flip', 'rotate'], // Custom animation of the modal. 51 animationend: ['swell', 'rotatedown', 'flash'] // Type of animation. 52 } 53 }, 54 /* 55 ---------------------------- 56 Private methods 57 ---------------------------- 58 */ 59 _private = { 60 set: function( val ) { 61 if ( !this.cb || !this.cb.length ) { 62 this.cb = []; 63 this.item = -1; 64 } 65 66 this.item++; 67 68 if ( val && val.zIndex === 'auto' ) { 69 for ( var zIndex = 0, x = 0, elements = document.getElementsByTagName('*'), xLen = elements.length; x < xLen; x += 1 ) { 70 var value = window.getComputedStyle(elements[x]).getPropertyValue('z-index'); 71 if ( value ) { 72 value =+ value; 73 if ( value > zIndex ) { 74 zIndex = value; 75 } 76 } 77 } 78 val.zIndex = zIndex; 79 } 80 81 this.cb.push({ 82 settings: _config.oldIE && typeof cbExtendObjects !== 'undefined' ? cbExtendObjects( {}, _defaults, val ) : Object.assign( {}, _defaults, val ) 83 }); 84 85 if ( this.cb[this.item].settings.overlayEffect === 'auto' ) { 86 this.cb[this.item].settings.overlayEffect = this.cb[this.item].settings.effect; 87 } 88 }, 89 get: function() { 90 return this.cb[this.cb.length - 1] || null; 91 }, 92 init: function() { 93 // Add class open. 94 document.documentElement.classList.add('custombox-open'); 95 document.documentElement.classList.add('custombox-open-' + this.cb[this.item].settings.overlayEffect); 96 97 // Add class perspective.
98 if ( _config.overlay.perspective.indexOf( this.cb[this.item].settings.overlayEffect ) > -1 ) { 99 this.cb[this.item].scroll = document.documentElement && document.documentElement.scrollTop || document.body && document.body.scrollTop || 0; 100 document.documentElement.classList.add('custombox-perspective'); 101 window.scrollTo(0, 0); 102 } 103 104 // Create main. 105 if ( !this.main ) { 106 this.built('container'); 107 } 108 109 // Create loading. 110 if ( this.cb[this.item].settings.loading && this.cb[this.item].settings.loading.parent ) { 111 this.built('loading'); 112 } 113 114 // Create overlay. 115 if ( this.cb[this.item].settings.overlay ) { 116 this.built('overlay').built('modal').open(); 117 } else { 118 this.built('modal').open(); 119 } 120 121 // Listeners. 122 this.binds(); 123 }, 124 built: function( item ) { 125 var cb; 126 if ( typeof this.item !== 'undefined' ) { 127 cb = this.cb[this.item]; 128 } 129 130 // Container. 131 switch ( item ) { 132 case 'container': 133 this.main = document.createElement('div'); 134 while ( document.body.firstChild ) { 135 this.main.appendChild(document.body.firstChild); 136 } 137 document.body.appendChild(this.main); 138 break; 139 case 'overlay': 140 if ( !cb.overlay ) { 141 cb.overlay = {}; 142 } 143 cb.overlay = document.createElement('div'); 144 cb.overlay.classList.add('custombox-overlay'); 145 cb.overlay.classList.add('custombox-overlay-' + cb.settings.overlayEffect); 146 cb.overlay.style.zIndex = cb.settings.zIndex + 2; 147 cb.overlay.style.backgroundColor = cb.settings.overlayColor; 148 149 // Add class perspective. 150 if ( _config.overlay.perspective.indexOf( cb.settings.overlayEffect ) > -1 || _config.overlay.together.indexOf( cb.settings.overlayEffect ) > -1 ) { 151 cb.overlay.style.opacity = cb.settings.overlayOpacity; 152 } else { 153 cb.overlay.classList.add('custombox-overlay-default'); 154 } 155 156 if ( _config.overlay.together.indexOf( cb.settings.overlayEffect ) > -1 ) { 157 cb.overlay.style.transitionDuration = cb.settings.speed + 'ms'; 158 } else { 159 cb.overlay.style.transitionDuration = cb.settings.overlaySpeed + 'ms'; 160 } 161 162 // Append overlay in to the DOM. 163 document.body.insertBefore(cb.overlay, document.body.lastChild.nextSibling); 164 break; 165 case 'modal': 166 if ( cb.settings.overlayEffect === 'push' ) { 167 this.main.style.transitionDuration = cb.settings.speed + 'ms'; 168 } 169 170 this.main.classList.add('custombox-container'); 171 this.main.classList.add('custombox-container-' + cb.settings.overlayEffect); 172 173 cb.wrapper = document.createElement('div'); 174 cb.wrapper.classList.add('custombox-modal-wrapper'); 175 cb.wrapper.classList.add('custombox-modal-wrapper-' + cb.settings.effect); 176 cb.wrapper.style.zIndex = cb.settings.zIndex + 3; 177 document.body.insertBefore(cb.wrapper, document.body.lastChild.nextSibling); 178 179 cb.container = document.createElement('div'); 180 cb.container.classList.add('custombox-modal-container'); 181 cb.container.classList.add('custombox-modal-container-' + cb.settings.effect); 182 cb.container.style.zIndex = cb.settings.zIndex + 4; 183
184 if ( _config.modal.position.indexOf(cb.settings.effect) > -1 && cb.settings.animation === null ) { 185 // Defaults. 186 if ( cb.settings.effect === 'slide' ) { 187 cb.settings.animation = ['top']; 188 } else if ( cb.settings.effect === 'flip' ) { 189 cb.settings.animation = ['horizontal']; 190 } else { 191 cb.settings.animation = ['bottom']; 192 } 193 } 194 195 cb.modal = document.createElement('div'); 196 cb.modal.classList.add('custombox-modal'); 197 cb.modal.classList.add( 198 'custombox-modal-' + cb.settings.effect + ( _config.modal.position.indexOf( cb.settings.effect ) > -1 ? '-' + cb.settings.animation[0].trim() : '' ) 199 ); 200 cb.modal.style.transitionDuration = cb.settings.speed + 'ms'; 201 cb.modal.style.zIndex = cb.settings.zIndex + 4; 202 cb.wrapper.appendChild(cb.container).appendChild(cb.modal); 203 break; 204 case 'loading': 205 this.loading = document.createElement('div'); 206 this.loading.classList.add('custombox-loading'); 207 208 var wrapper = document.createElement('div'); 209 for ( var i = 0, t = this.cb[this.item].settings.loading.parent.length; i < t; i++ ) { 210 wrapper.classList.add(this.cb[this.item].settings.loading.parent[i]); 211 } 212 213 this.loading.appendChild(wrapper); 214 this.loading.style.zIndex = cb.settings.zIndex + 3; 215 216 if ( this.cb[this.item].settings.loading.childrens ) { 217 for ( var e = 0, te = this.cb[this.item].settings.loading.childrens.length; e < te; e++ ) { 218 var tmp = document.createElement('div'); 219 for ( var r = 0, tr = this.cb[this.item].settings.loading.childrens[e].length; r < tr; r++ ) { 220 tmp.classList.add(this.cb[this.item].settings.loading.childrens[e][r]); 221 } 222 wrapper.appendChild(tmp); 223 } 224 } 225 226 document.body.appendChild(this.loading); 227 break; 228 } 229 230 return this; 231 }, 232 load: function() { 233 var cb = this.cb[this.item]; 234 235 // Check if callback 'open'. 236 if ( typeof cb.settings.open === 'function' ) { 237 cb.settings.open.call(); 238 } 239 240 // Trigger open. 241 if ( document.createEvent ) { 242 var topen = document.createEvent('Event'); 243 topen.initEvent('custombox.open', true, true); 244 document.dispatchEvent(topen); 245 } 246 247 // Convert the string to array. 248 if ( cb.settings.target !== null && Array.isArray(cb.settings.position) ) { 249 if ( cb.settings.target.charAt(0) === '#' || ( cb.settings.target.charAt(0) === '.' && cb.settings.target.charAt(1) !== '/' ) ) { 250 if ( document.querySelector(cb.settings.target) ) { 251 cb.inline = document.createElement('div'); 252 cb.content = document.querySelector(cb.settings.target); 253 cb.display = cb.content.style.display === 'none'; 254 cb.content.style.display = 'block'; 255 cb.content.parentNode.insertBefore(cb.inline, cb.content); 256 this.size(); 257 } else { 258 this.error(); 259 } 260 } else { 261 this.ajax(); 262 } 263 } else { 264 this.error(); 265 } 266 return this; 267 }, 268 size: function() { 269 var cb = this.cb[this.item], 270 customw = cb.content.offsetWidth; 271
272 if ( _config.oldIE ) { 273 window.innerHeight = document.documentElement.clientHeight; 274 } 275 276 if ( !cb.inline ) { 277 if ( _config.oldIE ) { 278 cb.content.style.styleFloat = 'none'; 279 } else { 280 cb.content.style.cssFloat = 'none'; 281 } 282 } 283 284 // Check width. 285 if ( cb.settings.width !== null ) { 286 if ( !isNaN( cb.settings.width ) ) { 287 customw = parseInt( cb.settings.width, 0); 288 } else { 289 customw = window.innerWidth; 290 cb.content.style.height = window.innerHeight + 'px'; 291 } 292 } 293 294 // Storage. 295 cb.size = customw; 296 297 // Width. 298 if ( cb.size + 60 >= window.innerWidth ) { 299 cb.container.style.width = 'auto'; 300 if ( cb.settings.width !== 'full' ) { 301 cb.container.style.margin = '5%'; 302 } 303 cb.wrapper.style.width = window.innerWidth + 'px'; 304 for ( var i = 0, elements = cb.content.querySelectorAll(':scope > *'), t = elements.length; i < t; i++ ) { 305 if ( elements[i].offsetWidth > window.innerWidth ) { 306 elements[i].style.width = 'auto'; 307 } 308 } 309 } else { 310 switch ( cb.settings.position[0].trim() ) { 311 case 'left': 312 cb.container.style.marginLeft = 0; 313 break; 314 case 'right': 315 cb.container.style.marginRight = 0; 316 break; 317 } 318 cb.container.style.width = cb.size + 'px'; 319 } 320 321 cb.content.style.width = 'auto'; 322 cb.modal.appendChild(cb.content); 323 324 // Top. 325 if ( cb.content.offsetHeight >= window.innerHeight && cb.settings.width !== 'full' ) { 326 cb.container.style.marginTop = '5%'; 327 cb.container.style.marginBottom = '5%'; 328 } else { 329 var result; 330 switch ( cb.settings.position[1].trim() ) { 331 case 'top': 332 result = 0; 333 break; 334 case 'bottom': 335 result = window.innerHeight - cb.content.offsetHeight + 'px'; 336 break; 337 default: 338 result = window.innerHeight / 2 - cb.content.offsetHeight / 2 + 'px'; 339 break; 340 } 341 cb.container.style.marginTop = result; 342 } 343 344 if ( this.loading ) { 345 document.body.removeChild(this.loading); 346 delete this.loading; 347 } 348 cb.wrapper.classList.add('custombox-modal-open'); 349 }, 350 ajax: function() { 351 var _this = this, 352 cb = _this.cb[_this.item], 353 xhr = new XMLHttpRequest(), 354 modal = document.createElement('div'); 355 356 xhr.onreadystatechange = function() { 357 if ( xhr.readyState === 4 ) { 358 if( xhr.status === 200 ) { 359 modal.innerHTML = xhr.responseText; 360 cb.content = modal; 361 cb.content.style.display = 'block'; 362 if ( _config.oldIE ) { 363 cb.content.style.styleFloat = 'left'; 364 } else { 365 cb.content.style.cssFloat = 'left'; 366 } 367 cb.container.appendChild(cb.content); 368 _this.size(); 369 } else { 370 _this.error(); 371 } 372 } 373 }; 374 xhr.open('GET', cb.settings.target + ( cb.settings.cache ? '' : ( /[?].+=/.test(cb.settings.target) ? '&_=' : '?_=' ) + Date.now() ), true); 375 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 376 xhr.send(null); 377 }, 378 scrollbar: function() { 379 var scrollDiv = document.createElement('div'); 380 scrollDiv.classList.add('custombox-scrollbar'); 381 document.body.appendChild(scrollDiv); 382 var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth; 383 document.body.removeChild(scrollDiv); 384 return scrollbarWidth; 385 }, 386 open: function() { 387 var _this = this,
388 delay = 0, 389 cb = _this.cb[_this.item], 390 scrollbar = _this.scrollbar(); 391 392 if ( scrollbar ) { 393 document.body.style.paddingRight = scrollbar + 'px'; 394 } 395 396 _this.main.classList.add('custombox-container-open'); 397 398 // Loading delay. 399 if ( _this.cb[_this.item].settings.loading ) { 400 if ( _this.cb[_this.item].settings.loading.delay && !isNaN( _this.cb[_this.item].settings.loading.delay * 1 ) ) { 401 delay = _this.cb[_this.item].settings.loading.delay * 1; 402 } else { 403 delay = 1000; 404 } 405 } 406 407 var open = function(listener) { 408 if ( listener ) { 409 cb.overlay.removeEventListener('transitionend', open); 410 } 411 412 // Load target. 413 _this.load(); 414 415 if ( cb.inline) { 416 cb.wrapper.classList.add('custombox-modal-open'); 417 } 418 }; 419 420 if ( cb.settings.overlay ) { 421 if ( _config.overlay.perspective.indexOf(cb.settings.overlayEffect) > -1 || _config.overlay.together.indexOf( cb.settings.overlayEffect ) > -1 ) { 422 // Add class perspective. 423 cb.overlay.classList.add('custombox-overlay-open'); 424 } else { 425 cb.overlay.style.opacity = cb.settings.overlayOpacity; 426 } 427 428 if ( _this.cb[_this.item].settings.loading ) { 429 setTimeout(open, delay); 430 } else { 431 if ( _config.overlay.together.indexOf( cb.settings.overlayEffect ) > -1 || _config.oldIE ) { 432 open(false); 433 } else { 434 cb.overlay.addEventListener('transitionend', open, false); 435 } 436 } 437 } else { 438 if ( _this.cb[_this.item].settings.loading ) { 439 setTimeout(open, delay); 440 } else { 441 open(false); 442 } 443 } 444 return _this; 445 }, 446 clean: function( item ) { 447 var _this = this, 448 cb = this.cb[item]; 449 450 document.documentElement.classList.remove('custombox-open-' + cb.settings.overlayEffect); 451 452 if ( cb.settings.overlay ) { 453 if ( cb.overlay.style.opacity ) { 454 cb.overlay.style.opacity = 0; 455 } 456 457 cb.overlay.classList.remove('custombox-overlay-open'); 458 _this.main.classList.remove('custombox-container-open'); 459 } 460 461 // Listener overlay. 462 if ( _config.oldIE || _config.oldMobile || !cb.overlay ) { 463 _this.remove(item); 464 } else { 465 var overlay = function() { 466 cb.overlay.removeEventListener('transitionend', overlay); 467 _this.remove(item); 468 }; 469 cb.overlay.addEventListener('transitionend', overlay, false); 470 } 471 }, 472 remove: function( item ) { 473 var _this = this, 474 cb = this.cb[item]; 475 476 if ( !cb ) { 477 return; 478 } 479 480 // Remove classes from html tag. 481 if ( _this.cb.length === 1 ) { 482 document.documentElement.classList.remove('custombox-open', 'custombox-perspective'); 483 if ( _this.scrollbar() ) { 484 document.body.style.paddingRight = 0; 485 } 486 487 if ( typeof cb.scroll !== 'undefined' ) { 488 window.scrollTo(0, cb.scroll); 489 } 490 } 491 492 if ( cb.inline ) { 493 // Remove property width and display. 494 if ( _config.oldIE ) { 495 cb.content.style.removeAttribute('width'); 496 cb.content.style.removeAttribute('height'); 497 cb.content.style.removeAttribute('display'); 498 } else { 499 cb.content.style.removeProperty('width'); 500 cb.content.style.removeProperty('height'); 501 cb.content.style.removeProperty('display'); 502 } 503 504 if ( cb.display ) { 505 cb.content.style.display = 'none'; 506 } 507 508 // Insert restore div. 509 cb.inline.parentNode.replaceChild(cb.content, cb.inline); 510 } 511 512 _this.main.classList.remove('custombox-container-' + cb.settings.overlayEffect); 513 514 // Remove modal. 515 cb.wrapper.parentNode.removeChild(cb.wrapper); 516 517 // Remove overlay. 518 if ( cb.settings.overlay ) { 519 cb.overlay.parentNode.removeChild(cb.overlay); 520 } 521 522 // Trigger close. 523 if ( document.createEvent ) { 524 var tclose = document.createEvent('Event'); 525 tclose.initEvent('custombox.close', true, true); 526 document.dispatchEvent(tclose); 527 } 528 529 // Unwrap. 530 if ( _this.cb.length === 1 ) { 531 for ( var contents = document.querySelectorAll('.custombox-container > *'), i = 0, t = contents.length; i < t; i++ ) { 532 document.body.insertBefore(contents[i], _this.main); 533 } 534 if ( _this.main.parentNode ) { 535 _this.main.parentNode.removeChild(_this.main); 536 } 537 delete _this.main; 538 } 539 540 // Remove items. 541 _this.cb.splice(item, 1); 542 543 // Callback close. 544 if ( typeof cb.settings.close === 'function' ) { 545 cb.settings.close.call(); 546 } 547 }, 548 close: function( target, callback ) { 549 var _this = this, 550 item; 551 552 if ( target ) { 553 for ( var i = 0, t = this.cb.length; i < t; i++ ) { 554 if ( this.cb[i].settings.target === target ) { 555 item = i; 556 break; 557 } 558 } 559 } else { 560 item = _this.cb.length - 1; 561 } 562 563 var cb = _this.cb[item]; 564 565 if ( typeof callback === 'function' ) { 566 cb.settings.close = callback; 567 } 568 569 // Modal
570 if ( _config.modal.position.indexOf( cb.settings.effect ) > -1 && cb.settings.animation.length > 1 ) { 571 cb.modal.classList.remove('custombox-modal-' + cb.settings.effect + '-' + cb.settings.animation[0]); 572 cb.modal.classList.add('custombox-modal-' + cb.settings.effect + '-' + cb.settings.animation[1].trim()); 573 } 574 575 // Remove classes. 576 cb.wrapper.classList.remove('custombox-modal-open'); 577 578 if ( _config.oldIE || _config.oldMobile || _config.overlay.together.indexOf( cb.settings.overlayEffect ) > -1 ) { 579 _this.clean(item); 580 } else { 581 // Listener wrapper. 582 var wrapper = function() { 583 cb.wrapper.removeEventListener('transitionend', wrapper); 584 _this.clean(item); 585 }; 586 587 if ( _config.modal.animationend.indexOf(cb.settings.effect) > -1 ) { 588 cb.wrapper.addEventListener('animationend', wrapper, false); 589 } else { 590 cb.wrapper.addEventListener('transitionend', wrapper, false); 591 } 592 } 593 }, 594 responsive: function() { 595 if ( _config.oldIE ) { 596 window.innerHeight = document.documentElement.clientHeight; 597 } 598 599 for ( var i = 0, t = this.cb.length, result; i < t; i++ ) {
600 // Width. 601 if ( this.cb[i].size + 60 >= window.innerWidth ) { 602 if ( this.cb[i].settings.width !== 'full' ) { 603 this.cb[i].container.style.marginLeft = '5%'; 604 this.cb[i].container.style.marginRight = '5%'; 605 } else if ( this.cb[i].content.offsetWidth <= window.innerWidth ) { 606 this.cb[i].content.style.width = 'auto'; 607 } 608 this.cb[i].container.style.width = 'auto'; 609 this.cb[i].wrapper.style.width = window.innerWidth + 'px'; 610 } else { 611 switch ( this.cb[i].settings.position[0].trim() ) { 612 case 'left': 613 this.cb[i].container.style.marginLeft = 0; 614 break; 615 case 'right': 616 this.cb[i].container.style.marginRight = 0; 617 break; 618 default: 619 this.cb[i].container.style.marginLeft = 'auto'; 620 this.cb[i].container.style.marginRight = 'auto'; 621 break; 622 } 623 this.cb[i].container.style.width = this.cb[i].size + 'px'; 624 this.cb[i].wrapper.style.width = 'auto'; 625 } 626 627 // Top. 628 if ( this.cb[i].content.offsetHeight >= window.innerHeight && this.cb[i].settings.width !== 'full' ) { 629 this.cb[i].container.style.marginTop = '5%'; 630 this.cb[i].container.style.marginBottom = '5%'; 631 } else { 632 if ( this.cb[i].settings.width === 'full' ) { 633 this.cb[i].settings.position[1] = 'top'; 634 if ( this.cb[i].content.offsetHeight <= window.innerHeight ) { 635 this.cb[i].content.style.height = window.innerHeight + 'px'; 636 } 637 } 638 switch ( this.cb[i].settings.position[1].trim() ) { 639 case 'top': 640 result = 0; 641 break; 642 case 'bottom': 643 result = window.innerHeight - this.cb[i].content.offsetHeight + 'px'; 644 break; 645 default: 646 result = window.innerHeight / 2 - this.cb[i].content.offsetHeight / 2 + 'px'; 647 break; 648 } 649 this.cb[i].container.style.marginTop = result; 650 } 651 } 652 }, 653 binds: function() { 654 var _this = this, 655 cb = _this.cb[_this.item], 656 stop = false; 657 658 // Esc. 659 if ( _this.cb.length === 1 ) { 660 _this.esc = function( event ) { 661 if ( _this.cb.length === 1 ) { 662 document.removeEventListener('keydown', _this.esc); 663 } 664 event = event || window.event; 665 if ( !stop && event.keyCode === 27 && _this.get() && _this.get().settings.escKey ) { 666 stop = true; 667 _this.close(); 668 } 669 }; 670 document.addEventListener('keydown', _this.esc, false); 671 672 // Listener responsive. 673 window.addEventListener('onorientationchange' in window ? 'orientationchange' : 'resize', function() { 674 _this.responsive(); 675 }, false); 676 } 677 678 // Overlay close. 679 cb.wrapper.event = function ( event ) { 680 if ( _this.cb.length === 1 ) { 681 document.removeEventListener('keydown', cb.wrapper.event); 682 } 683 if ( !stop && event.target === cb.wrapper && _this.get() && _this.get().settings.overlayClose ) { 684 stop = true; 685 _this.close(); 686 } 687 }; 688 cb.wrapper.addEventListener('click', cb.wrapper.event, false); 689 690 document.addEventListener('custombox.close', function() { 691 stop = false;
692 }); 693 694 var callback = function() { 695 // Execute the scripts. 696 if ( !cb.inline ) { 697 for ( var i = 0, script = cb.modal.getElementsByTagName('script'), t = script.length; i < t; i++ ) { 698 new Function( script[i].text )(); 699 } 700 } 701 702 if ( cb.settings && typeof cb.settings.complete === 'function' ) { 703 cb.settings.complete.call(); 704 } 705 706 // Trigger complete. 707 if ( document.createEvent ) { 708 var tcomplete = document.createEvent('Event'); 709 tcomplete.initEvent('custombox.complete', true, true); 710 document.dispatchEvent(tcomplete); 711 } 712 }; 713 714 // Callback complete. 715 var complete = function() { 716 callback(); 717 cb.modal.removeEventListener('transitionend', complete); 718 }; 719 720 if ( _config.oldIE || _config.oldMobile ) { 721 setTimeout(function() { 722 callback(); 723 }, cb.settings.overlaySpeed); 724 } else { 725 if ( cb.settings.effect !== 'slit' ) { 726 cb.modal.addEventListener('transitionend', complete, false); 727 } else { 728 cb.modal.addEventListener('animationend', complete, false); 729 } 730 } 731 }, 732 error: function() { 733 var _this = this, 734 item = _this.cb.length - 1; 735 736 alert('Error to load this target: ' + _this.cb[item].settings.target); 737 _this.remove(item); 738 } 739 }; 740 741 return { 742 /** 743 * @desc Set options defaults. 744 * @param {object} options - Auto built. 745 */ 746 set: function( options ) { 747 if ( options.autobuild ) { 748 _private.built('container'); 749 } 750 }, 751 /** 752 * @desc Open Custombox. 753 * @param {object} options - Options for the custombox. 754 */ 755 open: function( options ) { 756 _private.set( options ); 757 _private.init(); 758 }, 759 /** 760 * @desc Close Custombox. 761 * @param {string} options - Target. 762 * @param {function} callback. 763 */ 764 close: function( target, callback ) { 765 if ( typeof target === 'function' ) { 766 callback = target; 767 target = false;
768 } 769 _private.close( target, callback ); 770 } 771 }; 772}));
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.