1/** 2 * CodeLights: Modal Popup 3 */ 4!function($){ 5 "use strict"; 6 var CLPopup = function(container){ 7 this.$container = $(container); 8 9 this._events = { 10 show: this.show.bind(this), 11 afterShow: this.afterShow.bind(this), 12 hide: this.hide.bind(this), 13 preventHide: function(e){ 14 e.stopPropagation(); 15 }, 16 afterHide: this.afterHide.bind(this), 17 resize: this.resize.bind(this), 18 keypress: function(e){ 19 if (e.keyCode == 27) this.hide(); 20 }.bind(this) 21 }; 22 23 // Event name for triggering CSS transition finish 24 this.transitionEndEvent = (navigator.userAgent.search(/webkit/i)>0) ? 'webkitTransitionEnd' : 'transitionend'; 25 this.isFixed = !$cl.isMobile; 26 27 this.$trigger = this.$container.find('.cl-popup-trigger'); 28 this.triggerType = this.$trigger.clMod('type'); 29 if (this.triggerType == 'load'){ 30 var delay = this.$trigger.data('delay') || 2; 31 setTimeout(this.show.bind(this), delay * 1000); 32 } else if (this.triggerType == 'selector') { 33 var selector = this.$trigger.data('selector'); 34 if (selector) $cl.$body.on('click', selector, this._events.show); 35 } else { 36 this.$trigger.on('click', this._events.show); 37 } 38 this.$wrap = this.$container.find('.cl-popup-wrap') 39 .clMod('pos', this.isFixed ? 'fixed' : 'absolute') 40 .on('click', this._events.hide); 41 this.$box = this.$container.find('.cl-popup-box'); 42 this.$overlay = this.$container.find('.cl-popup-overlay') 43 .clMod('pos', this.isFixed ? 'fixed' : 'absolute') 44 .on('click', this._events.hide); 45 this.$container.find('.cl-popup-closer, .cl-popup-box-closer').on('click', this._events.hide); 46 this.$box.on('click', this._events.preventHide); 47 this.size = this.$box.clMod('size'); 48 49 this.timer = null; 50 }; 51 CLPopup.prototype = { 52 _hasScrollbar: function(){ 53 return document.documentElement.scrollHeight > document.documentElement.clientHeight; 54 }, 55 _getScrollbarSize: function(){ 56 if ($cl.scrollbarSize === undefined) { 57 var scrollDiv = document.createElement('div'); 58 scrollDiv.style.cssText = 'width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;'; 59 document.body.appendChild(scrollDiv); 60 $cl.scrollbarSize = scrollDiv.offsetWidth - scrollDiv.clientWidth; 61 document.body.removeChild(scrollDiv); 62 } 63 return $cl.scrollbarSize; 64 }, 65 show: function(){ 66 clearTimeout(this.timer); 67 this.$overlay.appendTo($cl.$body).show(); 68 this.$wrap.appendTo($cl.$body).show(); 69 if (this.size != 'f') { 70 this.resize(); 71 } 72 if (this.isFixed) { 73 $cl.$html.addClass('cloverlay_fixed'); 74 // Storing the value for the whole popup visibility session 75 this.windowHasScrollbar = this._hasScrollbar(); 76 if (this.windowHasScrollbar && this._getScrollbarSize()) { 77 $cl.$html.css('margin-right', this._getScrollbarSize()); 78 } 79 } else { 80 this.$overlay.css({ 81 height: $cl.$document.height() 82 }); 83 this.$wrap.css('top', $cl.$window.scrollTop()); 84 } 85 $cl.$body.on('keypress', this._events.keypress); 86 this.timer = setTimeout(this._events.afterShow, 25); 87 }, 88 afterShow: function(){ 89 clearTimeout(this.timer); 90 this.$overlay.addClass('active'); 91 this.$box.addClass('active'); 92 // UpSolution Themes Compatibility 93 // TODO Move to themes 94 if (window.$us !== undefined && $us.$canvas !== undefined) { 95 $us.$canvas.trigger('contentChange'); 96 } 97 $cl.$window.trigger('resize'); 98 if (this.size != 'f') { 99 $cl.$window.on('resize', this._events.resize); 100 } 101 }, 102 hide: function(){ 103 clearTimeout(this.timer); 104 if (this.size != 'f') { 105 $cl.$window.off('resize', this._events.resize); 106 } 107 $cl.$body.off('keypress', this._events.keypress); 108 this.$box.on(this.transitionEndEvent, this._events.afterHide); 109 this.$overlay.removeClass('active'); 110 this.$box.removeClass('active'); 111 // Closing it anyway 112 this.timer = setTimeout(this._events.afterHide, 1000); 113 }, 114 afterHide: function(){ 115 clearTimeout(this.timer); 116 this.$box.off(this.transitionEndEvent, this._events.afterHide); 117 this.$overlay.appendTo(this.$container).hide(); 118 this.$wrap.appendTo(this.$container).hide(); 119 if (this.isFixed) { 120 $cl.$html.removeClass('cloverlay_fixed'); 121 if (this.windowHasScrollbar) $cl.$html.css('margin-right', ''); 122 // To properly resize 3-rd party elements 123 $cl.$window.trigger('resize'); 124 } 125 }, 126 resize: function(){ 127 var animation = this.$box.clMod('animation'), 128 padding = parseInt(this.$box.css('padding-top')), 129 winHeight = $cl.$window.height(), 130 popupHeight = this.$box.height(); 131 if (!this.isFixed) { 132 this.$overlay.css('height', $cl.$document.height()); 133 } 134 this.$box.css('top', Math.max(0, (winHeight - popupHeight) / 2 - padding)); 135 } 136 }; 137 if (window.$cl === undefined) window.$cl = {}; 138 if ($cl.elements === undefined) $cl.elements = {}; 139 $cl.elements['cl-popup'] = CLPopup; 140 if ($cl.maybeInit !== undefined) $cl.maybeInit(); 141}(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.