1/* 2 _ _ _____ _ _ 3 | | | __ \ | | (_) 4 ___ ___ _ __ ___ | | | |__) |_____ _____ __ _| | _ ___ 5 / __|/ __| '__/ _ \| | | _ // _ \ \ / / _ \/ _` | | | / __| 6 \__ \ (__| | | (_) | | | | \ \ __/\ V / __/ (_| | |_| \__ \ 7 |___/\___|_| \___/|_|_|_| \_\___| \_/ \___|\__,_|_(_) |___/ v.0.1.2 8 _/ | 9 |__/ 10 11 "Declarative on-scroll reveal animations." 12 13/*============================================================================= 14 15 scrollReveal.js was inspired by cbpScroller.js (c) 2014 Codrops. 16 17 Licensed under the MIT license. 18 http://www.opensource.org/licenses/mit-license.php 19 20=============================================================================*/ 21 22/*! scrollReveal.js v0.1.2 (c) 2014 Julian Lloyd | MIT license */ 23 24/*===========================================================================*/ 25 26 27window.scrollReveal = (function (window) { 28 29 'use strict'; 30 31 function scrollReveal(options) { 32 33 this.docElem = window.document.documentElement; 34 this.options = this.extend(this.defaults, options); 35 this.styleBank = []; 36 37 if (this.options.init == true) this.init(); 38 } 39 40 scrollReveal.prototype = { 41 42 defaults: { 43 after: '0s', 44 enter: 'bottom', 45 move: '24px', 46 over: '0.66s', 47 easing: 'ease-in-out', 48 49 // if 0, the element is considered in the viewport as soon as it enters 50 // if 1, the element is considered in the viewport when it's fully visible 51 viewportFactor: 0.33, 52 53 // if false, animations occur only once 54 // if true, animations occur each time an element enters the viewport 55 reset: false, 56 57 // if true, scrollReveal.init() is automaticaly called upon instantiation 58 init: true 59 }, 60 61 /*=============================================================================*/ 62 63 init: function () { 64 65 this.scrolled = false; 66 67 var self = this; 68 69 // Check DOM for the data-scrollReveal attribute 70 // and initialize all found elements. 71 this.elems = Array.prototype.slice.call(this.docElem.querySelectorAll('[data-scroll-reveal]')); 72 this.elems.forEach(function (el, i) { 73 74 // Capture original style attribute 75 if (!self.styleBank[el]) { 76 self.styleBank[el] = el.getAttribute('style'); 77 } 78 79 self.update(el); 80 }); 81 82 var scrollHandler = function () { 83 if (!self.scrolled) { 84 self.scrolled = true; 85 setTimeout(function () { 86 self._scrollPage(); 87 }, 60); 88 } 89 }; 90 91 var resizeHandler = function () { 92 93 // If weâre still waiting for settimeout, reset the timer. 94 if (self.resizeTimeout) { 95 clearTimeout(self.resizeTimeout); 96 } 97 function delayed() { 98 self._scrollPage(); 99 self.resizeTimeout = null; 100 } 101 self.resizeTimeout = setTimeout(delayed, 200); 102 }; 103 104 window.addEventListener('scroll', scrollHandler, false); 105 window.addEventListener('resize', resizeHandler, false); 106 }, 107 108 /*=============================================================================*/ 109 110 _scrollPage: function () { 111 var self = this; 112 113 this.elems.forEach(function (el, i) { 114 self.update(el); 115 }); 116 this.scrolled = false; 117 }, 118 119 /*=============================================================================*/ 120 121 parseLanguage: function (el) { 122 123 // Splits on a sequence of one or more commas or spaces. 124 var words = el.getAttribute('data-scroll-reveal').split(/[, ]+/), 125 parsed = {}; 126 127 function filter (words) { 128 var ret = [], 129 130 blacklist = [ 131 "from", 132 "the", 133 "and", 134 "then", 135 "but", 136 "with" 137 ]; 138 139 words.forEach(function (word, i) { 140 if (blacklist.indexOf(word) > -1) { 141 return; 142 }
143 ret.push(word); 144 }); 145 146 return ret; 147 } 148 149 words = filter(words); 150 151 words.forEach(function (word, i) { 152 153 switch (word) { 154 case "enter": 155 parsed.enter = words[i + 1]; 156 return; 157 158 case "after": 159 parsed.after = words[i + 1]; 160 return; 161 162 case "wait": 163 parsed.after = words[i + 1]; 164 return; 165 166 case "move": 167 parsed.move = words[i + 1]; 168 return; 169 170 case "ease": 171 parsed.move = words[i + 1]; 172 parsed.ease = "ease"; 173 return; 174 175 case "ease-in": 176 parsed.move = words[i + 1]; 177 parsed.easing = "ease-in"; 178 return; 179 180 case "ease-in-out": 181 parsed.move = words[i + 1]; 182 parsed.easing = "ease-in-out"; 183 return; 184 185 case "ease-out": 186 parsed.move = words[i + 1]; 187 parsed.easing = "ease-out"; 188 return; 189 190 case "over": 191 parsed.over = words[i + 1]; 192 return; 193 194 default: 195 return; 196 } 197 }); 198 199 return parsed; 200 }, 201 202 203 /*=============================================================================*/ 204 205 update: function (el) { 206 207 var css = this.genCSS(el); 208 var style = this.styleBank[el]; 209 210 if (style != null) style += ";"; else style = ""; 211 212 if (!el.getAttribute('data-scroll-reveal-initialized')) { 213 el.setAttribute('style', style + css.initial); 214 el.setAttribute('data-scroll-reveal-initialized', true); 215 } 216 217 if (!this.isElementInViewport(el, this.options.viewportFactor)) { 218 if (this.options.reset) { 219 el.setAttribute('style', style + css.initial + css.reset); 220 } 221 return; 222 } 223 224 if (el.getAttribute('data-scroll-reveal-complete')) return; 225 226 if (this.isElementInViewport(el, this.options.viewportFactor)) { 227 el.setAttribute('style', style + css.target + css.transition); 228 // Without reset enabled, we can safely remove the style tag 229 // to prevent CSS specificy wars with authored CSS. 230 if (!this.options.reset) { 231 setTimeout(function () { 232 if (style != "") { 233 el.setAttribute('style', style); 234 } else { 235 el.removeAttribute('style'); 236 } 237 el.setAttribute('data-scroll-reveal-complete',true); 238 }, css.totalDuration); 239 } 240 return; 241 } 242 }, 243 244 /*=============================================================================*/ 245 246 genCSS: function (el) { 247 var parsed = this.parseLanguage(el), 248 enter, 249 axis; 250 251 if (parsed.enter) { 252 253 if (parsed.enter == "top" || parsed.enter == "bottom") { 254 enter = parsed.enter; 255 axis = "y"; 256 } 257 258 if (parsed.enter == "left" || parsed.enter == "right") { 259 enter = parsed.enter; 260 axis = "x"; 261 } 262 263 } else { 264 265 if (this.options.enter == "top" || this.options.enter == "bottom") { 266 enter = this.options.enter 267 axis = "y"; 268 } 269 270 if (this.options.enter == "left" || this.options.enter == "right") { 271 enter = this.options.enter 272 axis = "x"; 273 } 274 } 275 276 // After all values are parsed, letâs make sure our our 277 // pixel distance is negative for top and left entrances. 278 // 279 // ie. "move 25px from top" starts at 'top: -25px' in CSS. 280 281 if (enter == "top" || enter == "left") { 282 if (parsed.move) { 283 parsed.move = "-" + parsed.move; 284 } 285 else { 286 parsed.move = "-" + this.options.move; 287 } 288 } 289 290 var dist = parsed.move || this.options.move, 291 dur = parsed.over || this.options.over, 292 delay = parsed.after || this.options.after, 293 easing = parsed.easing || this.options.easing; 294 295 var transition = "-webkit-transition: -webkit-transform " + dur + " " + easing + " " + delay + ", opacity " + dur + " " + easing + " " + delay + ";" + 296 "transition: transform " + dur + " " + easing + " " + delay + ", opacity " + dur + " " + easing + " " + delay + ";" + 297 "-webkit-perspective: 1000;" + 298 "-webkit-backface-visibility: hidden;"; 299 300 // The same as transition, but removing the delay for elements fading out. 301 var reset = "-webkit-transition: -webkit-transform " + dur + " " + easing + " 0s, opacity " + dur + " " + easing + " " + delay + ";" + 302 "transition: transform " + dur + " " + easing + " 0s, opacity " + dur + " " + easing + " " + delay + ";" + 303 "-webkit-perspective: 1000;" + 304 "-webkit-backface-visibility: hidden;"; 305 306 var initial = "-webkit-transform: translate" + axis + "(" + dist + ");" + 307 "transform: translate" + axis + "(" + dist + ");" + 308 "opacity: 0;"; 309 310 var target = "-webkit-transform: translate" + axis + "(0);" + 311 "transform: translate" + axis + "(0);" + 312 "opacity: 1;"; 313 return { 314 transition: transition, 315 initial: initial, 316 target: target, 317 reset: reset, 318 totalDuration: ((parseFloat(dur) + parseFloat(delay)) * 1000) 319 }; 320 }, 321 322 getViewportH : function () { 323 var client = this.docElem['clientHeight'],
324 inner = window['innerHeight']; 325 326 return (client < inner) ? inner : client; 327 }, 328 329 getOffset : function(el) { 330 var offsetTop = 0, 331 offsetLeft = 0; 332 333 do { 334 if (!isNaN(el.offsetTop)) { 335 offsetTop += el.offsetTop; 336 } 337 if (!isNaN(el.offsetLeft)) { 338 offsetLeft += el.offsetLeft; 339 } 340 } while (el = el.offsetParent) 341 342 return { 343 top: offsetTop, 344 left: offsetLeft 345 } 346 }, 347 348 isElementInViewport : function(el, h) { 349 var scrolled = window.pageYOffset, 350 viewed = scrolled + this.getViewportH(), 351 elH = el.offsetHeight, 352 elTop = this.getOffset(el).top, 353 elBottom = elTop + elH, 354 h = h || 0; 355 356 return (elTop + elH * h) <= viewed 357 && (elBottom) >= scrolled 358 || (el.currentStyle? el.currentStyle : window.getComputedStyle(el, null)).position == 'fixed'; 359 }, 360 361 extend: function (a, b){ 362 for (var key in b) { 363 if (b.hasOwnProperty(key)) { 364 a[key] = b[key]; 365 } 366 } 367 return a; 368 } 369 }; // end scrollReveal.prototype 370 371 return scrollReveal; 372})(window);
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.