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