1/* =========================================================== 2 * jquery-onepage-scroll.js v1.3.1 3 * =========================================================== 4 * Copyright 2013 Pete Rojwongsuriya. 5 * http://www.thepetedesign.com 6 * 7 * Create an Apple-like website that let user scroll 8 * one page at a time 9 * 10 * Credit: Eike Send for the awesome swipe event 11 * https://github.com/peachananr/onepage-scroll 12 * 13 * License: GPL v3 14 * 15 * ========================================================== */ 16 17!function($){ 18 19 var defaults = { 20 sectionContainer: "section", 21 easing: "ease", 22 animationTime: 1000, 23 pagination: true, 24 updateURL: false, 25 keyboard: true, 26 beforeMove: null, 27 afterMove: null, 28 loop: false, 29 responsiveFallback: false, 30 direction : 'vertical' 31 }; 32 33 /*------------------------------------------------*/ 34 /* Credit: Eike Send for the awesome swipe event */ 35 /*------------------------------------------------*/ 36 37 $.fn.swipeEvents = function() { 38 return this.each(function() { 39 40 var startX, 41 startY, 42 $this = $(this); 43 44 $this.bind('touchstart', touchstart); 45 46 function touchstart(event) { 47 var touches = event.originalEvent.touches; 48 if (touches && touches.length) { 49 startX = touches[0].pageX; 50 startY = touches[0].pageY; 51 $this.bind('touchmove', touchmove); 52 } 53 } 54 55 function touchmove(event) { 56 var touches = event.originalEvent.touches; 57 if (touches && touches.length) { 58 var deltaX = startX - touches[0].pageX; 59 var deltaY = startY - touches[0].pageY; 60 61 if (deltaX >= 50) { 62 $this.trigger("swipeLeft"); 63 } 64 if (deltaX <= -50) { 65 $this.trigger("swipeRight"); 66 } 67 if (deltaY >= 50) { 68 $this.trigger("swipeUp"); 69 } 70 if (deltaY <= -50) { 71 $this.trigger("swipeDown"); 72 } 73 if (Math.abs(deltaX) >= 50 || Math.abs(deltaY) >= 50) { 74 $this.unbind('touchmove', touchmove); 75 } 76 } 77 } 78 79 }); 80 }; 81 82 83 $.fn.onepage_scroll = function(options){ 84 var settings = $.extend({}, defaults, options), 85 el = $(this), 86 sections = $(settings.sectionContainer) 87 total = sections.length, 88 status = "off", 89 topPos = 0, 90 leftPos = 0, 91 lastAnimation = 0, 92 quietPeriod = 500, 93 paginationList = ""; 94 95 $.fn.transformPage = function(settings, pos, index) { 96 if (typeof settings.beforeMove == 'function') settings.beforeMove(index); 97 98 // Just a simple edit that makes use of modernizr to detect an IE8 browser and changes the transform method into 99 // an top animate so IE8 users can also use this script. 100 if($('html').hasClass('ie8')){ 101 if (settings.direction == 'horizontal') { 102 var toppos = (el.width()/100)*pos; 103 $(this).animate({left: toppos+'px'},settings.animationTime); 104 } else { 105 var toppos = (el.height()/100)*pos; 106 $(this).animate({top: toppos+'px'},settings.animationTime); 107 } 108 } else{ 109 $(this).css({ 110 "-webkit-transform": ( settings.direction == 'horizontal' ) ? "translate3d(" + pos + "%, 0, 0)" : "translate3d(0, " + pos + "%, 0)", 111 "-webkit-transition": "all " + settings.animationTime + "ms " + settings.easing, 112 "-moz-transform": ( settings.direction == 'horizontal' ) ? "translate3d(" + pos + "%, 0, 0)" : "translate3d(0, " + pos + "%, 0)", 113 "-moz-transition": "all " + settings.animationTime + "ms " + settings.easing, 114 "-ms-transform": ( settings.direction == 'horizontal' ) ? "translate3d(" + pos + "%, 0, 0)" : "translate3d(0, " + pos + "%, 0)", 115 "-ms-transition": "all " + settings.animationTime + "ms " + settings.easing, 116 "transform": ( settings.direction == 'horizontal' ) ? "translate3d(" + pos + "%, 0, 0)" : "translate3d(0, " + pos + "%, 0)", 117 "transition": "all " + settings.animationTime + "ms " + settings.easing 118 }); 119 } 120 $(this).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function(e) { 121 if (typeof settings.afterMove == 'function') settings.afterMove(index); 122 }); 123 } 124 125 $.fn.moveDown = function() { 126 var el = $(this) 127 index = $(settings.sectionContainer +".active").data("index"); 128 current = $(settings.sectionContainer + "[data-index='" + index + "']"); 129 next = $(settings.sectionContainer + "[data-index='" + (index + 1) + "']"); 130 if(next.length < 1) { 131 if (settings.loop == true) { 132 pos = 0; 133 next = $(settings.sectionContainer + "[data-index='1']"); 134 } else { 135 return 136 } 137 138 }else { 139 pos = (index * 100) * -1; 140 } 141 if (typeof settings.beforeMove == 'function') settings.beforeMove( next.data("index")); 142 current.removeClass("active") 143 next.addClass("active"); 144 if(settings.pagination == true) { 145 $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 146 $(".onepage-pagination li a" + "[data-index='" + next.data("index") + "']").addClass("active"); 147 } 148 149 $("body")[0].className = $("body")[0].className.replace(/\bviewing-page-\d.*?\b/g, ''); 150 $("body").addClass("viewing-page-"+next.data("index")) 151 152 if (history.replaceState && settings.updateURL == true) { 153 var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (index + 1); 154 history.pushState( {}, document.title, href ); 155 }
156 el.transformPage(settings, pos, next.data("index")); 157 } 158 159 $.fn.moveUp = function() { 160 var el = $(this) 161 index = $(settings.sectionContainer +".active").data("index"); 162 current = $(settings.sectionContainer + "[data-index='" + index + "']"); 163 next = $(settings.sectionContainer + "[data-index='" + (index - 1) + "']"); 164 165 if(next.length < 1) { 166 if (settings.loop == true) { 167 pos = ((total - 1) * 100) * -1; 168 next = $(settings.sectionContainer + "[data-index='"+total+"']"); 169 } 170 else { 171 return 172 } 173 }else { 174 pos = ((next.data("index") - 1) * 100) * -1; 175 } 176 if (typeof settings.beforeMove == 'function') settings.beforeMove(next.data("index")); 177 current.removeClass("active") 178 next.addClass("active") 179 if(settings.pagination == true) { 180 $(".onepage-pagination li a" + "[data-index='" + index + "']").removeClass("active"); 181 $(".onepage-pagination li a" + "[data-index='" + next.data("index") + "']").addClass("active"); 182 } 183 $("body")[0].className = $("body")[0].className.replace(/\bviewing-page-\d.*?\b/g, ''); 184 $("body").addClass("viewing-page-"+next.data("index")) 185 186 if (history.replaceState && settings.updateURL == true) { 187 var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (index - 1); 188 history.pushState( {}, document.title, href ); 189 } 190 el.transformPage(settings, pos, next.data("index")); 191 } 192 193 $.fn.moveTo = function(page_index) { 194 current = $(settings.sectionContainer + ".active") 195 next = $(settings.sectionContainer + "[data-index='" + (page_index) + "']"); 196 if(next.length > 0) { 197 if (typeof settings.beforeMove == 'function') settings.beforeMove(next.data("index")); 198 current.removeClass("active") 199 next.addClass("active") 200 $(".onepage-pagination li a" + ".active").removeClass("active"); 201 $(".onepage-pagination li a" + "[data-index='" + (page_index) + "']").addClass("active"); 202 $("body")[0].className = $("body")[0].className.replace(/\bviewing-page-\d.*?\b/g, ''); 203 $("body").addClass("viewing-page-"+next.data("index")) 204 205 pos = ((page_index - 1) * 100) * -1; 206 207 if (history.replaceState && settings.updateURL == true) { 208 var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (page_index - 1); 209 history.pushState( {}, document.title, href ); 210 } 211 el.transformPage(settings, pos, page_index); 212 } 213 } 214 215 function responsive() { 216 //start modification 217 var valForTest = false; 218 var typeOfRF = typeof settings.responsiveFallback 219 220 if(typeOfRF == "number"){ 221 valForTest = $(window).width() < settings.responsiveFallback; 222 } 223 if(typeOfRF == "boolean"){ 224 valForTest = settings.responsiveFallback; 225 } 226 if(typeOfRF == "function"){ 227 valFunction = settings.responsiveFallback(); 228 valForTest = valFunction; 229 typeOFv = typeof valForTest; 230 if(typeOFv == "number"){ 231 valForTest = $(window).width() < valFunction; 232 } 233 } 234 235 //end modification 236 if (valForTest) { 237 $("body").addClass("disabled-onepage-scroll"); 238 $(document).unbind('mousewheel DOMMouseScroll MozMousePixelScroll'); 239 el.swipeEvents().unbind("swipeDown swipeUp"); 240 } else { 241 if($("body").hasClass("disabled-onepage-scroll")) { 242 $("body").removeClass("disabled-onepage-scroll"); 243 $("html, body, .wrapper").animate({ scrollTop: 0 }, "fast"); 244 } 245 246 247 el.swipeEvents().bind("swipeDown", function(event){ 248 if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 249 el.moveUp(); 250 }).bind("swipeUp", function(event){ 251 if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 252 el.moveDown(); 253 }); 254 255 $(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(event) { 256 event.preventDefault(); 257 var delta = event.originalEvent.wheelDelta || -event.originalEvent.detail; 258 init_scroll(event, delta); 259 }); 260 } 261 } 262 263 264 function init_scroll(event, delta) { 265 deltaOfInterest = delta; 266 var timeNow = new Date().getTime(); 267 // Cancel scroll if currently animating or within quiet period 268 if(timeNow - lastAnimation < quietPeriod + settings.animationTime) { 269 event.preventDefault(); 270 return; 271 } 272 273 if (deltaOfInterest < 0) { 274 el.moveDown() 275 } else { 276 el.moveUp() 277 } 278 lastAnimation = timeNow; 279 } 280 281 // Prepare everything before binding wheel scroll 282 283 el.addClass("onepage-wrapper").css("position","relative"); 284 $.each( sections, function(i) { 285 $(this).css({ 286 position: "absolute",
287 top: topPos + "%" 288 }).addClass("section").attr("data-index", i+1); 289 290 291 $(this).css({ 292 position: "absolute", 293 left: ( settings.direction == 'horizontal' ) 294 ? leftPos + "%" 295 : 0, 296 top: ( settings.direction == 'vertical' || settings.direction != 'horizontal' ) 297 ? topPos + "%" 298 : 0 299 }); 300 301 if (settings.direction == 'horizontal') 302 leftPos = leftPos + 100; 303 else 304 topPos = topPos + 100; 305 306 307 if(settings.pagination == true) { 308 if(i==0){ 309 paginationList += "<li><a data-index='"+(i+1)+"' href='#" + (i+1) + "' style='position:relative;z-index:999;color:#fff;font-size:20px;font-family: cursive;'><i class='fa fa-home'></i></a></li>" 310 } 311 312 if(i==1){ 313 paginationList += "<li><a data-index='"+(i+1)+"' href='#" + (i+1) + "' style='position:relative;z-index:999;color:#fff;font-size:20px;font-family: cursive;'><i class='fa fa-cloud'></i></a></li>" 314 } 315 316 if(i==2){ 317 paginationList += "<li><a data-index='"+(i+1)+"' href='#" + (i+1) + "' style='position:relative;z-index:999;color:#fff;font-size:20px;font-family: cursive;'><i class='fa fa-info-circle'></i></i></a></li>" 318 } 319 320 } 321 }); 322 323 el.swipeEvents().bind("swipeDown", function(event){ 324 if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 325 el.moveUp(); 326 }).bind("swipeUp", function(event){ 327 if (!$("body").hasClass("disabled-onepage-scroll")) event.preventDefault(); 328 el.moveDown(); 329 }); 330 331 // Create Pagination and Display Them 332 if (settings.pagination == true) { 333 if ($('ul.onepage-pagination').length < 1) $("<ul class='onepage-pagination'></ul>").prependTo("body"); 334 335 if( settings.direction == 'horizontal' ) { 336 posLeft = (el.find(".onepage-pagination").width() / 2) * -1; 337 el.find(".onepage-pagination").css("margin-left", posLeft); 338 } else { 339 posTop = (el.find(".onepage-pagination").height() / 2) * -1; 340 el.find(".onepage-pagination").css("margin-top", posTop); 341 } 342 $('ul.onepage-pagination').html(paginationList); 343 344 } 345 346 if(window.location.hash != "" && window.location.hash != "#1") { 347 init_index = window.location.hash.replace("#", "") 348 349 if (parseInt(init_index) <= total && parseInt(init_index) > 0) { 350 $(settings.sectionContainer + "[data-index='" + init_index + "']").addClass("active") 351 $("body").addClass("viewing-page-"+ init_index) 352 if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + init_index + "']").addClass("active"); 353 354 next = $(settings.sectionContainer + "[data-index='" + (init_index) + "']"); 355 if(next) { 356 next.addClass("active") 357 if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='" + (init_index) + "']").addClass("active"); 358 $("body")[0].className = $("body")[0].className.replace(/\bviewing-page-\d.*?\b/g, ''); 359 $("body").addClass("viewing-page-"+next.data("index")) 360 if (history.replaceState && settings.updateURL == true) { 361 var href = window.location.href.substr(0,window.location.href.indexOf('#')) + "#" + (init_index); 362 history.pushState( {}, document.title, href ); 363 } 364 } 365 pos = ((init_index - 1) * 100) * -1; 366 el.transformPage(settings, pos, init_index); 367 } else { 368 $(settings.sectionContainer + "[data-index='1']").addClass("active") 369 $("body").addClass("viewing-page-1") 370 if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='1']").addClass("active"); 371 } 372 }else{ 373 $(settings.sectionContainer + "[data-index='1']").addClass("active") 374 $("body").addClass("viewing-page-1") 375 if(settings.pagination == true) $(".onepage-pagination li a" + "[data-index='1']").addClass("active"); 376 } 377 378 if(settings.pagination == true) { 379 $(".onepage-pagination li a").click(function (){ 380 var page_index = $(this).data("index");
381 el.moveTo(page_index); 382 }); 383 } 384 385 386 $(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(event) { 387 event.preventDefault(); 388 var delta = event.originalEvent.wheelDelta || -event.originalEvent.detail; 389 if(!$("body").hasClass("disabled-onepage-scroll")) init_scroll(event, delta); 390 }); 391 392 393 if(settings.responsiveFallback != false) { 394 $(window).resize(function() { 395 responsive(); 396 }); 397 398 responsive(); 399 } 400 401 if(settings.keyboard == true) { 402 $(document).keydown(function(e) { 403 var tag = e.target.tagName.toLowerCase(); 404 405 if (!$("body").hasClass("disabled-onepage-scroll")) { 406 switch(e.which) { 407 case 38: 408 if (tag != 'input' && tag != 'textarea') el.moveUp() 409 break; 410 case 40: 411 if (tag != 'input' && tag != 'textarea') el.moveDown() 412 break; 413 case 32: //spacebar 414 if (tag != 'input' && tag != 'textarea') el.moveDown() 415 break; 416 case 33: //page up 417 if (tag != 'input' && tag != 'textarea') el.moveUp() 418 break; 419 case 34: //page dwn 420 if (tag != 'input' && tag != 'textarea') el.moveDown() 421 break; 422 case 36: //home 423 el.moveTo(1); 424 break; 425 case 35: //end 426 el.moveTo(total); 427 break; 428 default: return; 429 } 430 } 431 432 }); 433 } 434 return false; 435 } 436 437 438}(window.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.