1(function($){ 2 var $window = $(window), 3 $page = $('#page'); 4 5 $.fn.parallaxVertical = function(xpos, options) { 6 7 var windowHeight = $window.height(), 8 perspectiveOpened = false; 9 10 options = options || {}; 11 12 this.each(function() { 13 var $this = $(this), 14 speedFactor, 15 offsetFactor = 0, 16 getHeight, 17 topOffset = 0, 18 containerHeight = 0, 19 containerWidth = 0, 20 disableParallax = false, 21 parallaxIsDisabled = false, 22 baseImgHeight = 0, 23 baseImgWidth = 0, 24 isBgCover = ($this.css('background-size') == 'cover'), 25 curImgHeight = 0, 26 reversed = $this.hasClass('parallax-reversed'), 27 baseSpeedFactor = reversed ? -0.1 : 0.3, 28 outerHeight = true; 29 30 if (xpos === undefined) xpos = "50%"; 31 32 if (outerHeight){ 33 getHeight = function(jqo){ 34 return jqo.parent().outerHeight(true); 35 }; 36 } else { 37 getHeight = function(jqo){ 38 return jqo.parent().height(); 39 }; 40 } 41 42 function getBackgroundSize(callback){ 43 var img = new Image(), 44 // here we will place image's width and height 45 width, height, 46 // here we get the size of the background and split it to array 47 backgroundSize = ($this.css('background-size') || ' ').split(' '); 48 49 // checking if width was set to pixel value 50 if (/px/.test(backgroundSize[0])) width = parseInt(backgroundSize[0]); 51 // checking if width was set to percent value 52 if (/%/.test(backgroundSize[0])) width = $this.parent().width() * (parseInt(backgroundSize[0]) / 100); 53 // checking if height was set to pixel value 54 if (/px/.test(backgroundSize[1])) height = parseInt(backgroundSize[1]); 55 // checking if height was set to percent value 56 if (/%/.test(backgroundSize[1])) height = $this.parent().height() * (parseInt(backgroundSize[0]) / 100); 57 58 if (width !== undefined && height !== undefined){ 59 // Image is not needed 60 return callback({ width: width, height: height }); 61 } 62 63 // Image is needed 64 img.onload = function () { 65 // check if width was set earlier, if not then set it now 66 if (typeof width == 'undefined') width = this.width; 67 // do the same with height 68 if (typeof height == 'undefined') height = this.height; 69 // call the callback 70 callback({ width: width, height: height }); 71 }; 72 // extract image source from css using one, simple regex 73 // src should be set AFTER onload handler 74 img.src = ($this.css('background-image') || '').replace(/url\(['"]*(.*?)['"]*\)/g, '$1'); 75 } 76 77 function update(){ 78 if (disableParallax){ 79 if ( ! parallaxIsDisabled){ 80 $this.css('backgroundPosition', ''); 81 if(!$this.is('.page-title-block')) { 82 $this.removeClass('fullwidth-block-parallax-vertical'); 83 } 84 parallaxIsDisabled = true; 85 } 86 return; 87 }else{ 88 if (parallaxIsDisabled){ 89 if(!$this.is('.page-title-block')) { 90 $this.addClass('fullwidth-block-parallax-vertical'); 91 } 92 parallaxIsDisabled = false; 93 } 94 } 95 if (isNaN(speedFactor)) 96 return; 97 98 var pos = getScrollTop(); 99 100 // Check if totally above or totally below viewport 101 if ((topOffset + containerHeight < pos) || (pos < topOffset - windowHeight)) return; 102 103 var ypos = offsetFactor + speedFactor * (topOffset - pos); 104 105 if (ypos > 0) { 106 ypos = 0; 107 } else if (curImgHeight + ypos < containerHeight) { 108 ypos = containerHeight - curImgHeight; 109 } 110 111 if (curImgHeight > 0) { 112 $this.css('height', curImgHeight+'px'); 113 } 114 115 var translate = 'translate3d(0, ' + ypos + 'px' + ', 0)'; 116 $this[0].style['-webkit-transform'] = translate; 117 $this[0].style['-moz-transform'] = translate; 118 $this[0].style['transform'] = translate; 119 } 120 121 function getScrollTop() { 122 return perspectiveOpened ? $page.scrollTop() : $window.scrollTop(); 123 } 124 125 function resize(){ 126 setTimeout(function(){ 127 if (perspectiveOpened) { 128 windowHeight = $page.height(); 129 } else { 130 windowHeight = $window.height(); 131 } 132 133 containerHeight = getHeight($this); 134 containerWidth = $this.parent().width(); 135 136 if (isBgCover){ 137 if (baseImgWidth / baseImgHeight <= containerWidth / containerHeight){ 138 curImgHeight = baseImgHeight * (containerWidth / baseImgWidth); 139 } else { 140 curImgHeight = containerHeight*1.2; 141 } 142 } 143 144 topOffset = $this.parent().offset().top; 145 146 // Improving speed factor to prevent showing image limits 147 if (curImgHeight !== 0) { 148 if (baseSpeedFactor >= 0) { 149 if (options.position !== undefined && options.position == 'top') { 150 speedFactor = Math.min(0.25, (curImgHeight - containerHeight) / (containerHeight + topOffset)); 151 offsetFactor = -speedFactor * topOffset; 152 } else { 153 speedFactor = -Math.min(baseSpeedFactor, (curImgHeight - containerHeight) / (windowHeight + containerHeight)); 154 offsetFactor = containerHeight * speedFactor; 155 } 156 } else { 157 speedFactor = Math.min(baseSpeedFactor, (windowHeight - containerHeight) / (windowHeight + containerHeight)); 158 offsetFactor = Math.max(0, speedFactor * containerHeight); 159 } 160 } else { 161 speedFactor = baseSpeedFactor; 162 offsetFactor = 0; 163 } 164 165 update(); 166 }, 10); 167 } 168
169 getBackgroundSize(function(sz){ 170 curImgHeight = baseImgHeight = sz.height; 171 baseImgWidth = sz.width; 172 resize(); 173 }); 174 175 $window.on({scroll: update, load: resize, resize: resize, touchmove: update}); 176 177 var tgpliVisibleTimeout = false; 178 $window.on('tgpliVisible', function(e) { 179 if (tgpliVisibleTimeout) { 180 clearTimeout(tgpliVisibleTimeout); 181 } 182 183 tgpliVisibleTimeout = setTimeout(function() { 184 resize(); 185 }, 100); 186 }); 187 //$page.bind({scroll: update, resize: resize}); 188 resize(); 189 }); 190 191 $(window).on('perspective-modalview-opened', function() { 192 perspectiveOpened = true; 193 windowHeight = $page.height(); 194 }); 195 $(window).on('perspective-modalview-closed', function() { 196 perspectiveOpened = false; 197 windowHeight = $window.height(); 198 }); 199 }; 200})(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.