MediaWiki:Common.js: Διαφορά μεταξύ των αναθεωρήσεων

Από Trace Project
Χωρίς σύνοψη επεξεργασίας
Χωρίς σύνοψη επεξεργασίας
Γραμμή 1: Γραμμή 1:
/*
(function (global,factory) {
"use strict";
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], function($) {
return factory($, global, global.document);
});
} else if (typeof module === 'object' && module.exports) {
// Node/CommonJS
module.exports = factory(require('jquery'), global, global.document);
} else {
// Browser globals
factory(jQuery, global, global.document);
}
}(typeof window !== 'undefined' ? window : this, function ($, window, document, undefined) {
"use strict";
var heights = [],
names = [],
elements = [],
overflow = [],
index = 0,
currentIndex = 0,
interstitialIndex = 1,
hasLocation = false,
timeoutId,
timeoutId2,
$window = $(window),
top = $window.scrollTop(),
scrollable = false,
locked = false,
scrolled = false,
manualScroll,
swipeScroll,
util,
disabled = false,
scrollSamples = [],
scrollTime = new Date().getTime(),
firstLoad = true,
initialised = false,
destination = 0,
wheelEvent = 'onwheel' in document ? 'wheel' : document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll',
settings = {
//section should be an identifier that is the same for each section
section: ".section",
sectionName: "section-name",
interstitialSection: "",
easing: "easeOutExpo",
scrollSpeed: 1100,
offset : 0,
scrollbars: true,
target:"html,body",
standardScrollElements: false,
setHeights: true,
overflowScroll:true,
updateHash: true,
touchScroll:true,
before:function() {},
after:function() {},
afterResize:function() {},
afterRender:function() {}
};
function animateScroll(index,instant,callbacks,toTop) {
if(currentIndex===index) {
callbacks = false;
}
if(disabled===true) {
return true;
}
if(names[index]) {
scrollable = false;
if(callbacks) {
settings.before(index,elements);
}
interstitialIndex = 1;
destination = heights[index];
if(firstLoad===false && currentIndex>index && toTop===false) {
//We're going backwards
if(overflow[index]) {
 
interstitialIndex = parseInt(elements[index].outerHeight()/$window.height());
 
destination = parseInt(heights[index])+(elements[index].outerHeight()-$window.height());
}
}
 
 
if(settings.updateHash && settings.sectionName && !(firstLoad===true && index===0)) {
if(history.pushState) {
    try {
history.replaceState(null, null, names[index]


!function(t,o){"use strict";"function"==typeof define&&define.amd?define(["jquery"],function(e){return o(e,t,t.document)}):"object"==typeof module&&module.exports?module.exports=o(require("jquery"),t,t.document):o(jQuery,t,t.document)}("undefined"!=typeof window?window:this,function(r,s,i,t){"use strict";var u,l,h,f,d,p,m=[],g=[],v=[],y=[],w=0,a=0,S=1,E=!1,H=r(s),b=H.scrollTop(),M=!1,x=!1,T=!1,D=!1,I=[],L=(new Date).getTime(),c=!0,N=!1,k=0,O="onwheel"in i?"wheel":i.onmousewheel!==t?"mousewheel":"DOMMouseScroll",z={passive:!1},R={section:".section",sectionName:"section-name",interstitialSection:"",easing:"easeOutExpo",scrollSpeed:1100,offset:0,scrollbars:!0,target:"html,body",standardScrollElements:!1,setHeights:!0,overflowScroll:!0,updateHash:!0,touchScroll:!0,before:function(){},after:function(){},afterResize:function(){},afterRender:function(){}};function j(){return s.innerHeight+R.offset}function C(e,t,o,n){if(a===e&&(o=!1),!0===D)return 1;if(g[e]){if(M=!1,!0===c&&(c=!1,R.afterRender()),o&&"function"==typeof R.before&&!1===R.before(e,v))return 1;if(S=1,k=e?m[e]:0,!1===c&&e<a&&!1===n&&y[e]&&(h=j(),S=parseInt(v[e].outerHeight()/h),k=parseInt(m[e])+(v[e].outerHeight()-h)),R.updateHash&&R.sectionName&&(!0!==c||0!==e))if(history.pushState)try{history.replaceState(null,null,g[e])}catch(e){s.console&&console.warn("Scrollify warning: Page must be hosted to manipulate the hash value.")}else s.location.hash=g[e];if(a=e,t)r(R.target).stop().scrollTop(k),o&&R.after(e,v);else{if(x=!0,r().velocity?r(R.target).stop().velocity("scroll",{duration:R.scrollSpeed,easing:R.easing,offset:k,mobileHA:!1}):r(R.target).stop().animate({scrollTop:k},R.scrollSpeed,R.easing),s.location.hash.length&&R.sectionName&&s.console)try{r(s.location.hash).length&&console.warn("Scrollify warning: ID matches hash value - this will cause the page to anchor.")}catch(e){}r(R.target).promise().done(function(){c=x=!1,o&&R.after(e,v)})}}}function Y(r){function e(e){for(var t=0,o=r.slice(Math.max(r.length-e,1)),n=0;n<o.length;n++)t+=o[n];return Math.ceil(t/e)}var t=e(10);return e(70)<=t}function e(e){function t(e){r().velocity?r(R.target).stop().velocity("scroll",{duration:R.scrollSpeed,easing:R.easing,offset:e,mobileHA:!1}):r(R.target).stop().animate({scrollTop:e},R.scrollSpeed,R.easing)}function o(e){e&&(b=H.scrollTop());var t=R.section;y=[],R.interstitialSection.length&&(t+=","+R.interstitialSection),!1===R.scrollbars&&(R.overflowScroll=!1),h=j(),r(t).each(function(e){var t=r(this);R.setHeights?t.is(R.interstitialSection)?y[e]=!1:t.css("height","auto").outerHeight()<h||"hidden"===t.css("overflow")?(t.css({height:h}),y[e]=!1):(t.css({height:t.outerHeight()}),R.overflowScroll?y[e]=!0:y[e]=!1):t.outerHeight()<h||!1===R.overflowScroll?y[e]=!1:y[e]=!0}),e&&H.scrollTop(b)}function n(e){var o=R.section;R.interstitialSection.length&&(o+=","+R.interstitialSection),m=[],g=[],v=[],r(o).each(function(e){var t=r(this);m[e]=0<e?parseInt(t.offset().top)+R.offset:parseInt(t.offset().top),R.sectionName&&t.data(R.sectionName)?g[e]="#"+t.data(R.sectionName).toString().replace(/ /g,"-"):!1===t.is(R.interstitialSection)?g[e]="#"+(e+1):(g[e]="#",e===r(o).length-1&&1<e&&(m[e]=m[e-1]+(parseInt(r(r(o)[e-1]).outerHeight())-parseInt(r(s).height()))+parseInt(t.outerHeight()))),v[e]=t;try{r(g[e]).length&&s.console&&console.warn("Scrollify warning: Section names can't match IDs - this will cause the browser to anchor.")}catch(e){}s.location.hash===g[e]&&(w=e,E=!0)}),!0===e&&C(w,!1,!1,!1)}function a(){return y[w]&&(b=H.scrollTop())>parseInt(m[w])?void 0:1}function c(){return!y[w]||(b=H.scrollTop(),h=j(),b<parseInt(m[w])+(v[w].outerHeight()-h)-28?void 0:1)}N=!0,r.easing.easeOutExpo=function(e,t,o,n,r){return t==r?o+n:n*(1-Math.pow(2,-10*t/r))+o},d={touches:{touchstart:{y:-1,x:-1},touchmove:{y:-1,x:-1},touchend:!(f={handleMousedown:function(){if(!0===D)return!0;T=M=!1},handleMouseup:function(){if(!0===D)return!0;M=!0,T&&f.calculateNearest(!1,!0)},handleScroll:function(){if(!0===D)return!0;u&&clearTimeout(u),u=setTimeout(function(){return!(T=!0)!==M&&(M=!1,void f.calculateNearest(!1,!0))},200)},calculateNearest:function(e,t){b=H.scrollTop();for(var o,n=1,r=m.length,s=0,i=Math.abs(m[0]-b);n<r;n++)(o=Math.abs(m[n]-b))<i&&(i=o,s=n);(c()&&w<s||a())&&C(w=s,e,t,!1)},wheelHandler:function(e){if(!0===D)return!0;if(R.standardScrollElements&&(r(e.target).is(R.standardScrollElements)||r(e.target).closest(R.standardScrollElements).length))return!0;y[w]||e.preventDefault();var t=(new Date).getTime(),o=(e=e||s.event).originalEvent?e.originalEvent.wheelDelta||-e.originalEvent.deltaY||-e.originalEvent.detail:e.wheelDelta||-e.deltaY||-e.detail,n=Math.max(-1,Math.min(1,o));if(149<I.length&&I.shift(),I.push(Math.abs(o)),200<t-L&&(I=[]),L=t,x)return!1;if(n<0){if(w<m.length-1&&c()){if(!Y(I))return!1;e.preventDefault(),C(++w,!(x=!0),!0,!1)}}else if(0<n&&0<w&&a()){if(!Y(I))return!1;e.preventDefault(),C(--w,!(x=!0),!0,!1)}},keyHandler:function(e){return!0===D||!1===i.activeElement.readOnly||(!(!R.standardScrollElements||!r(e.target).is(R.standardScrollElements)&&!r(e.target).closest(R.standardScrollElements).length)||!0!==x&&void(38==e.keyCode||33==e.keyCode?0<w&&a()&&(e.preventDefault(),C(--w,!1,!0,!1)):40!=e.keyCode&&34!=e.keyCode||w<m.length-1&&c()&&(e.preventDefault(),C(++w,!1,!0,!1))))},init:function(){R.scrollbars?(H.on("mousedown",f.handleMousedown),H.on("mouseup",f.handleMouseup),H.on("scroll",f.handleScroll)):r("body").css({overflow:"hidden"}),s.addEventListener(O,f.wheelHandler,{passive:!1}),H.on("keydown",f.keyHandler)}}),direction:"undetermined"},options:{distance:30,timeGap:800,timeStamp:(new Date).getTime()},touchHandler:function(e){if(!0===D)return!0;if(R.standardScrollElements&&(r(e.target).is(R.standardScrollElements)||r(e.target).closest(R.standardScrollElements).length))return!0;var t;if(void 0!==e&&void 0!==e.touches)switch(t=e.touches[0],e.type){case"touchstart":d.touches.touchstart.y=t.pageY,d.touches.touchmove.y=-1,d.touches.touchstart.x=t.pageX,d.touches.touchmove.x=-1,d.options.timeStamp=(new Date).getTime(),d.touches.touchend=!1;case"touchmove":d.touches.touchmove.y=t.pageY,d.touches.touchmove.x=t.pageX,d.touches.touchstart.y!==d.touches.touchmove.y&&Math.abs(d.touches.touchstart.y-d.touches.touchmove.y)>Math.abs(d.touches.touchstart.x-d.touches.touchmove.x)&&(e.preventDefault(),d.touches.direction="y",d.options.timeStamp+d.options.timeGap<(new Date).getTime()&&0==d.touches.touchend&&(d.touches.touchend=!0,-1<d.touches.touchstart.y&&Math.abs(d.touches.touchmove.y-d.touches.touchstart.y)>d.options.distance&&(d.touches.touchstart.y<d.touches.touchmove.y?d.up():d.down())));break;case"touchend":!1===d.touches[e.type]&&(d.touches[e.type]=!0,-1<d.touches.touchstart.y&&-1<d.touches.touchmove.y&&"y"===d.touches.direction&&(Math.abs(d.touches.touchmove.y-d.touches.touchstart.y)>d.options.distance&&(d.touches.touchstart.y<d.touches.touchmove.y?d.up():d.down()),d.touches.touchstart.y=-1,d.touches.touchstart.x=-1,d.touches.direction="undetermined"))}},down:function(){w<m.length&&(c()&&w<m.length-1?C(++w,!1,!0,!1):(h=j(),Math.floor(v[w].height()/h)>S?(t(parseInt(m[w])+h*S),S+=1):t(parseInt(m[w])+(v[w].outerHeight()-h))))},up:function(){0<=w&&(a()&&0<w?C(--w,!1,!0,!1):2<S?(h=j(),--S,t(parseInt(m[w])+h*S)):(S=1,t(parseInt(m[w]))))},init:function(){i.addEventListener&&R.touchScroll&&(i.addEventListener("touchstart",d.touchHandler,z),i.addEventListener("touchmove",d.touchHandler,z),i.addEventListener("touchend",d.touchHandler,z))}},p={refresh:function(e,t){clearTimeout(l),l=setTimeout(function(){o(!0),n(t),e&&R.afterResize()},400)},handleUpdate:function(){p.refresh(!1,!1)},handleResize:function(){p.refresh(!0,!1)},handleOrientation:function(){p.refresh(!0,!0)}},R=r.extend(R,e),o(!1),n(!1),!0===E?C(w,!1,!0,!0):setTimeout(function(){f.calculateNearest(!0,!1)},200),m.length&&(f.init(),d.init(),H.on("resize",p.handleResize),i.addEventListener&&s.addEventListener("orientationchange",p.handleOrientation,!1))}function o(e,t){for(var o=g.length;0<=o;o--)"string"==typeof e?g[o]===e&&C(w=o,t,!0,!0):o===e&&C(w=o,t,!0,!0)}return e.move=function(e){if(e===t)return!1;"number"!=typeof e&&e.originalEvent&&(e=r(this).attr("href")),o(e,!1)},e.instantMove=function(e){if(e===t)return!1;o(e,!0)},e.next=function(){w<g.length&&C(w+=1,!1,!0,!0)},e.previous=function(){0<w&&C(--w,!1,!0,!0)},e.instantNext=function(){w<g.length&&C(w+=1,!0,!0,!0)},e.instantPrevious=function(){0<w&&C(--w,!0,!0,!0)},e.destroy=function(){if(!N)return!1;R.setHeights&&r(R.section).each(function(){r(this).css("height","auto")}),H.off("resize",p.handleResize),R.scrollbars&&(H.off("mousedown",f.handleMousedown),H.off("mouseup",f.handleMouseup),H.off("scroll",f.handleScroll)),s.removeEventListener(O,f.wheelHandler),H.off("keydown",f.keyHandler),i.addEventListener&&R.touchScroll&&(i.removeEventListener("touchstart",d.touchHandler,z),i.removeEventListener("touchmove",d.touchHandler,z),i.removeEventListener("touchend",d.touchHandler,z)),m=[],g=[],v=[],y=[],N=!(c=!0)},e.update=function(){if(!N)return!1;p.handleUpdate()},e.current=function(){return v[w]},e.currentIndex=function(){return w},e.disable=function(){D=!0},e.enable=function(){D=!1,N&&f.calculateNearest(!1,!1)},e.isDisabled=function(){return D},e.setOptions=function(e){if(!N)return!1;"object"==typeof e?(R=r.extend(R,e),p.handleUpdate()):s.console&&console.warn("Scrollify warning: setOptions expects an object.")},r.scrollify=e});


$(document).ready(function () {
$(document).ready(function () {

Αναθεώρηση της 21:55, 15 Φεβρουαρίου 2023

(function (global,factory) {
	"use strict";
	if (typeof define === 'function' && define.amd) {
		// AMD. Register as an anonymous module.
		define(['jquery'], function($) {
			return factory($, global, global.document);
		});
	} else if (typeof module === 'object' && module.exports) {
		// Node/CommonJS
		module.exports = factory(require('jquery'), global, global.document);
	} else {
		// Browser globals
		factory(jQuery, global, global.document);
	}
}(typeof window !== 'undefined' ? window : this, function ($, window, document, undefined) {
	"use strict";
	var heights = [],
		names = [],
		elements = [],
		overflow = [],
		index = 0,
		currentIndex = 0,
		interstitialIndex = 1,
		hasLocation = false,
		timeoutId,
		timeoutId2,
		$window = $(window),
		top = $window.scrollTop(),
		scrollable = false,
		locked = false,
		scrolled = false,
		manualScroll,
		swipeScroll,
		util,
		disabled = false,
		scrollSamples = [],
		scrollTime = new Date().getTime(),
		firstLoad = true,
		initialised = false,
		destination = 0,
		wheelEvent = 'onwheel' in document ? 'wheel' : document.onmousewheel !== undefined ? 'mousewheel' : 'DOMMouseScroll',
		settings = {
			//section should be an identifier that is the same for each section
			section: ".section",
			sectionName: "section-name",
			interstitialSection: "",
			easing: "easeOutExpo",
			scrollSpeed: 1100,
			offset : 0,
			scrollbars: true,
			target:"html,body",
			standardScrollElements: false,
			setHeights: true,
			overflowScroll:true,
			updateHash: true,
			touchScroll:true,
			before:function() {},
			after:function() {},
			afterResize:function() {},
			afterRender:function() {}
		};
	function animateScroll(index,instant,callbacks,toTop) {
		if(currentIndex===index) {
			callbacks = false;
		}
		if(disabled===true) {
			return true;
		}
		if(names[index]) {
			scrollable = false;
			if(callbacks) {
				settings.before(index,elements);
			}
			interstitialIndex = 1;
			destination = heights[index];
			if(firstLoad===false && currentIndex>index && toTop===false) {
				//We're going backwards
				if(overflow[index]) {

					interstitialIndex = parseInt(elements[index].outerHeight()/$window.height());

					destination = parseInt(heights[index])+(elements[index].outerHeight()-$window.height());
				}
			}


			if(settings.updateHash && settings.sectionName && !(firstLoad===true && index===0)) {
				if(history.pushState) {
				    try {
							history.replaceState(null, null, names[index]);
				    } catch (e) {
				    	if(window.console) {
				    		console.warn("Scrollify warning: Page must be hosted to manipulate the hash value.");
				    	}
				    }

				} else {
					window.location.hash = names[index];
				}
			}
			if(firstLoad) {
					settings.afterRender();
					firstLoad = false;
			}


			currentIndex = index;
			if(instant) {
				$(settings.target).stop().scrollTop(destination);
				if(callbacks) {
					settings.after(index,elements);
				}
			} else {
				locked = true;
				if( $().velocity ) {
					$(settings.target).stop().velocity('scroll', {
					  duration: settings.scrollSpeed,
					  easing: settings.easing,
					  offset: destination,
					  mobileHA: false
				  });
				} else {
					$(settings.target).stop().animate({
						scrollTop: destination
					}, settings.scrollSpeed,settings.easing);
				}

				if(window.location.hash.length && settings.sectionName && window.console) {
					try {
						if($(window.location.hash).length) {
							console.warn("Scrollify warning: ID matches hash value - this will cause the page to anchor.");
						}
					} catch (e) {}
				}
				$(settings.target).promise().done(function(){
					locked = false;
					firstLoad = false;
					if(callbacks) {
						settings.after(index,elements);
					}
				});
			}

		}
	}

	function isAccelerating(samples) {
				function average(num) {
					var sum = 0;

					var lastElements = samples.slice(Math.max(samples.length - num, 1));

          for(var i = 0; i < lastElements.length; i++){
              sum += lastElements[i];
          }

          return Math.ceil(sum/num);
				}

				var avEnd = average(10);
        var avMiddle = average(70);

        if(avEnd >= avMiddle) {
					return true;
				} else {
					return false;
				}
	}
	var scrollify = function(options) {
		initialised = true;
		$.easing['easeOutExpo'] = function(x, t, b, c, d) {
			return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
		};

		manualScroll = {
			handleMousedown:function() {
				if(disabled===true) {
					return true;
				}
				scrollable = false;
				scrolled = false;
			},
			handleMouseup:function() {
				if(disabled===true) {
					return true;
				}
				scrollable = true;
				if(scrolled) {
					//instant,callbacks
					manualScroll.calculateNearest(false,true);
				}
			},
			handleScroll:function() {
				if(disabled===true) {
					return true;
				}
				if(timeoutId){
					clearTimeout(timeoutId);
				}

				timeoutId = setTimeout(function(){
					scrolled = true;
					if(scrollable===false) {
						return false;
					}
					scrollable = false;
					//instant,callbacks
					manualScroll.calculateNearest(false,true);
				}, 200);
			},
			calculateNearest:function(instant,callbacks) {
				top = $window.scrollTop();
				var i =1,
					max = heights.length,
					closest = 0,
					prev = Math.abs(heights[0] - top),
					diff;
				for(;i<max;i++) {
					diff = Math.abs(heights[i] - top);

					if(diff < prev) {
						prev = diff;
						closest = i;
					}
				}
				if((atBottom() && closest>index) || atTop()) {
					index = closest;
					//index, instant, callbacks, toTop
					animateScroll(closest,instant,callbacks,false);
				}
			},
			wheelHandler:function(e) {
				if(disabled===true) {
					return true;
				} else if(settings.standardScrollElements) {
					if($(e.target).is(settings.standardScrollElements) || $(e.target).closest(settings.standardScrollElements).length) {
						return true;
					}
				}
				if(!overflow[index]) {
					e.preventDefault();
				}
				var currentScrollTime = new Date().getTime();



				e = e || window.event;
				var value = e.originalEvent.wheelDelta || -e.originalEvent.deltaY || -e.originalEvent.detail;
				var delta = Math.max(-1, Math.min(1, value));



				//delta = delta || -e.originalEvent.detail / 3 || e.originalEvent.wheelDelta / 120;


				if(scrollSamples.length > 149){
					scrollSamples.shift();
				}
				//scrollSamples.push(Math.abs(delta*10));
				scrollSamples.push(Math.abs(value));

				if((currentScrollTime-scrollTime) > 200){
					scrollSamples = [];
				}
				scrollTime = currentScrollTime;


				if(locked) {
					return false;
				}
				if(delta<0) {
					if(index<heights.length-1) {						
						if(atBottom()) {
							if(isAccelerating(scrollSamples)) {
								e.preventDefault();
								index++;
								locked = true;
								//index, instant, callbacks, toTop
								animateScroll(index,false,true, false);
							} else {
								return false;
							}
						}
					}
				} else if(delta>0) {
					if(index>0) {
						if(atTop()) {
							if(isAccelerating(scrollSamples)) {
								e.preventDefault();
								index--;
								locked = true;
								//index, instant, callbacks, toTop
								animateScroll(index,false,true, false);
							} else {
								return false
							}
						}
					}
				}

			},
			keyHandler:function(e) {
				if(disabled===true) {
					return true;
				}
				if(locked===true) {
					return false;
				}
				if(e.keyCode==38 || e.keyCode==33) {
					if(index>0) {
						if(atTop()) {
							e.preventDefault();
							index--;
							//index, instant, callbacks, toTop
							animateScroll(index,false,true,false);
						}
					}
				} else if(e.keyCode==40 || e.keyCode==34) {
					if(index<heights.length-1) {
						if(atBottom()) {
							e.preventDefault();
							index++;
							//index, instant, callbacks, toTop
							animateScroll(index,false,true,false);
						}
					}
				}
			},
			init:function() {
				if(settings.scrollbars) {
					$window.on('mousedown', manualScroll.handleMousedown);
					$window.on('mouseup', manualScroll.handleMouseup);
					$window.on('scroll', manualScroll.handleScroll);
				} else {
					$("body").css({"overflow":"hidden"});
				}
				$window.on(wheelEvent,manualScroll.wheelHandler);
				//$(document).bind(wheelEvent,manualScroll.wheelHandler);
				$window.on('keydown', manualScroll.keyHandler);
			}
		};

		swipeScroll = {
			touches : {
				"touchstart": {"y":-1,"x":-1},
				"touchmove" : {"y":-1,"x":-1},
				"touchend"  : false,
				"direction" : "undetermined"
			},
			options:{
				"distance" : 30,
				"timeGap" : 800,
				"timeStamp" : new Date().getTime()
			},
			touchHandler: function(event) {
				if(disabled===true) {
					return true;
				} else if(settings.standardScrollElements) {
					if($(event.target).is(settings.standardScrollElements) || $(event.target).closest(settings.standardScrollElements).length) {
						return true;
					}
				}
				var touch;
				if (typeof event !== 'undefined'){
					if (typeof event.touches !== 'undefined') {
						touch = event.touches[0];
						switch (event.type) {
							case 'touchstart':
								swipeScroll.touches.touchstart.y = touch.pageY;
								swipeScroll.touches.touchmove.y = -1;

								swipeScroll.touches.touchstart.x = touch.pageX;
								swipeScroll.touches.touchmove.x = -1;

								swipeScroll.options.timeStamp = new Date().getTime();
								swipeScroll.touches.touchend = false;
							case 'touchmove':
								swipeScroll.touches.touchmove.y = touch.pageY;
								swipeScroll.touches.touchmove.x = touch.pageX;
								if(swipeScroll.touches.touchstart.y!==swipeScroll.touches.touchmove.y && (Math.abs(swipeScroll.touches.touchstart.y-swipeScroll.touches.touchmove.y)>Math.abs(swipeScroll.touches.touchstart.x-swipeScroll.touches.touchmove.x))) {
									//if(!overflow[index]) {
										event.preventDefault();
									//}
									swipeScroll.touches.direction = "y";
									if((swipeScroll.options.timeStamp+swipeScroll.options.timeGap)<(new Date().getTime()) && swipeScroll.touches.touchend == false) {

										swipeScroll.touches.touchend = true;
										if (swipeScroll.touches.touchstart.y > -1) {

											if(Math.abs(swipeScroll.touches.touchmove.y-swipeScroll.touches.touchstart.y)>swipeScroll.options.distance) {
												if(swipeScroll.touches.touchstart.y < swipeScroll.touches.touchmove.y) {

													swipeScroll.up();

												} else {
													swipeScroll.down();

												}
											}
										}
									}
								}
								break;
							case 'touchend':
								if(swipeScroll.touches[event.type]===false) {
									swipeScroll.touches[event.type] = true;
									if (swipeScroll.touches.touchstart.y > -1 && swipeScroll.touches.touchmove.y > -1 && swipeScroll.touches.direction==="y") {

										if(Math.abs(swipeScroll.touches.touchmove.y-swipeScroll.touches.touchstart.y)>swipeScroll.options.distance) {
											if(swipeScroll.touches.touchstart.y < swipeScroll.touches.touchmove.y) {
												swipeScroll.up();

											} else {
												swipeScroll.down();

											}
										}
										swipeScroll.touches.touchstart.y = -1;
										swipeScroll.touches.touchstart.x = -1;
										swipeScroll.touches.direction = "undetermined";
									}
								}
							default:
								break;
						}
					}
				}
			},
			down: function() {

				if(index<heights.length-1) {

					if(atBottom() && index<heights.length-1) {

						index++;
						//index, instant, callbacks, toTop
						animateScroll(index,false,true,false);
					} else {
						if(Math.floor(elements[index].height()/$window.height())>interstitialIndex) {

							interstitialScroll(parseInt(heights[index])+($window.height()*interstitialIndex));
							interstitialIndex += 1;

						} else {
							interstitialScroll(parseInt(heights[index])+(elements[index].outerHeight()-$window.height()));
						}

					}
				}
			},
			up: function() {
				if(index>=0) {
					if(atTop() && index>0) {

						index--;
						//index, instant, callbacks, toTop
						animateScroll(index,false,true,false);
					} else {

						if(interstitialIndex>2) {

							interstitialIndex -= 1;
							interstitialScroll(parseInt(heights[index])+($window.height()*interstitialIndex));

						} else {

							interstitialIndex = 1;
							interstitialScroll(parseInt(heights[index]));
						}
					}

				}
			},
			init: function() {
				if (document.addEventListener && settings.touchScroll) {
					document.addEventListener('touchstart', swipeScroll.touchHandler, false);
					document.addEventListener('touchmove', swipeScroll.touchHandler, false);
					document.addEventListener('touchend', swipeScroll.touchHandler, false);
				}
			}
		};


		util = {
			refresh:function(withCallback,scroll) {
				clearTimeout(timeoutId2);
				timeoutId2 = setTimeout(function() {
					//retain position
					sizePanels(true);
					//scroll, firstLoad
					calculatePositions(scroll,false);
					if(withCallback) {
							settings.afterResize();
					}
				},400);
			},
			handleUpdate:function() {
				//callbacks, scroll
				//changed from false,true to false,false
				util.refresh(false,false);
			},
			handleResize:function() {
				//callbacks, scroll
				util.refresh(true,false);
			},
			handleOrientation:function() {
				//callbacks, scroll
				util.refresh(true,true);
			}
		};
		settings = $.extend(settings, options);

		//retain position
		sizePanels(false);

		calculatePositions(false,true);

		if(true===hasLocation) {
			//index, instant, callbacks, toTop
			animateScroll(index,false,true,true);
		} else {
			setTimeout(function() {
				//instant,callbacks
				manualScroll.calculateNearest(true,false);
			},200);
		}
		if(heights.length) {
			manualScroll.init();
			swipeScroll.init();

			$window.on("resize",util.handleResize);
			if (document.addEventListener) {
				window.addEventListener("orientationchange", util.handleOrientation, false);
			}
		}
		function interstitialScroll(pos) {
			if( $().velocity ) {
				$(settings.target).stop().velocity('scroll', {
					duration: settings.scrollSpeed,
					easing: settings.easing,
					offset: pos,
					mobileHA: false
				});
			} else {
				$(settings.target).stop().animate({
					scrollTop: pos
				}, settings.scrollSpeed,settings.easing);
			}
		}

		function sizePanels(keepPosition) {
			if(keepPosition) {
				top = $window.scrollTop();				
			}

			var selector = settings.section;
			overflow = [];
			if(settings.interstitialSection.length) {
				selector += "," + settings.interstitialSection;
			}
			if(settings.scrollbars===false) {
				settings.overflowScroll = false;
			}
			$(selector).each(function(i) {
				var $this = $(this);

				if(settings.setHeights) {
					if($this.is(settings.interstitialSection)) {
						overflow[i] = false;
					} else {
						if(($this.css("height","auto").outerHeight()<$window.height()) || $this.css("overflow")==="hidden") {
							$this.css({"height":$window.height()});

							overflow[i] = false;
						} else {
							
							$this.css({"height":$this.height()});

							if(settings.overflowScroll) {
								overflow[i] = true;
							} else {
								overflow[i] = false;
							}
						}

					}

				} else {

					if(($this.outerHeight()<$window.height()) || (settings.overflowScroll===false)) {
						overflow[i] = false;
					} else {
						overflow[i] = true;
					}
				}
			});
			if(keepPosition) {
				$window.scrollTop(top);
			}
		}
		function calculatePositions(scroll,firstLoad) {
			var selector = settings.section;
			if(settings.interstitialSection.length) {
				selector += "," + settings.interstitialSection;
			}
			heights = [];
			names = [];
			elements = [];
			$(selector).each(function(i){
					var $this = $(this);
					if(i>0) {
						heights[i] = parseInt($this.offset().top) + settings.offset;
					} else {
						heights[i] = parseInt($this.offset().top);
					}
					if(settings.sectionName && $this.data(settings.sectionName)) {
						names[i] = "#" + $this.data(settings.sectionName).toString().replace(/ /g,"-");
					} else {
						if($this.is(settings.interstitialSection)===false) {
							names[i] = "#" + (i + 1);
						} else {
							names[i] = "#";
							if(i===$(selector).length-1 && i>1) {

								heights[i] = heights[i-1]+(parseInt($($(selector)[i-1]).outerHeight())-parseInt($(window).height()))+parseInt($this.outerHeight());
							}
						}
					}
					elements[i] = $this;
					try {
						if($(names[i]).length && window.console) {
							console.warn("Scrollify warning: Section names can't match IDs - this will cause the browser to anchor.");
						}
					} catch (e) {}

					if(window.location.hash===names[i]) {
						index = i;
						hasLocation = true;
					}

			});

			if(true===scroll) {
				//index, instant, callbacks, toTop
				animateScroll(index,false,false,false);
			}
		}

		function atTop() {
			if(!overflow[index]) {
				return true;
			}
			top = $window.scrollTop();
			if(top>parseInt(heights[index])) {
				return false;
			} else {
				return true;
			}
		}
		function atBottom() {
			if(!overflow[index]) {
				return true;
			}
			top = $window.scrollTop();

			if(top<parseInt(heights[index])+(elements[index].outerHeight()-$window.height())-28) {

				return false;

			} else {
				return true;
			}
		}
	}

	function move(panel,instant) {
		var z = names.length;
		for(;z>=0;z--) {
			if(typeof panel === 'string') {
				if (names[z]===panel) {
					index = z;
					//index, instant, callbacks, toTop
					animateScroll(z,instant,true,true);
				}
			} else {
				if(z===panel) {
					index = z;
					//index, instant, callbacks, toTop
					animateScroll(z,instant,true,true);
				}
			}
		}
	}
	scrollify.move = function(panel) {
		if(panel===undefined) {
			return false;
		}
		if(panel.originalEvent) {
			panel = $(this).attr("href");
		}
		move(panel,false);
	};
	scrollify.instantMove = function(panel) {
		if(panel===undefined) {
			return false;
		}
		move(panel,true);
	};
	scrollify.next = function() {
		if(index<names.length) {
			index += 1;
			//index, instant, callbacks, toTop
			animateScroll(index,false,true,true);
		}
	};
	scrollify.previous = function() {
		if(index>0) {
			index -= 1;
			//index, instant, callbacks, toTop
			animateScroll(index,false,true,true);
		}
	};
	scrollify.instantNext = function() {
		if(index<names.length) {
			index += 1;
			//index, instant, callbacks, toTop
			animateScroll(index,true,true,true);
		}
	};
	scrollify.instantPrevious = function() {
		if(index>0) {
			index -= 1;
			//index, instant, callbacks, toTop
			animateScroll(index,true,true,true);
		}
	};
	scrollify.destroy = function() {
		if(!initialised) {
			return false;
		}
		if(settings.setHeights) {
			$(settings.section).each(function() {
				$(this).css("height","auto");
			});
		}
		$window.off("resize",util.handleResize);
		if(settings.scrollbars) {
			$window.off('mousedown', manualScroll.handleMousedown);
			$window.off('mouseup', manualScroll.handleMouseup);
			$window.off('scroll', manualScroll.handleScroll);
		}
		$window.off(wheelEvent,manualScroll.wheelHandler);
		$window.off('keydown', manualScroll.keyHandler);

		if (document.addEventListener && settings.touchScroll) {
			document.removeEventListener('touchstart', swipeScroll.touchHandler, false);
			document.removeEventListener('touchmove', swipeScroll.touchHandler, false);
			document.removeEventListener('touchend', swipeScroll.touchHandler, false);
		}
		heights = [];
		names = [];
		elements = [];
		overflow = [];
	};
	scrollify.update = function() {
		if(!initialised) {
			return false;
		}
		util.handleUpdate();
	};
	scrollify.current = function() {
		return elements[index];
	};
	scrollify.disable = function() {
		disabled = true;
	};
	scrollify.enable = function() {
		disabled = false;
		if (initialised) {
			//instant,callbacks
			manualScroll.calculateNearest(false,false);
		}
	};
	scrollify.isDisabled = function() {
		return disabled;
	};
	scrollify.setOptions = function(updatedOptions) {
		if(!initialised) {
			return false;
		}
		if(typeof updatedOptions === "object") {
			settings = $.extend(settings, updatedOptions);
			util.handleUpdate();
		} else if(window.console) {
			console.warn("Scrollify warning: setOptions expects an object.");
		}
	};
	$.scrollify = scrollify;
	return scrollify;
}));



$(document).ready(function () {
screenCheck();
$('.scroll-control .one').click(function () {
$.scrollify.move('#s-one');
});
$('.scroll-control .two').click(function () {
$.scrollify.move('#s-two');
});
$('.scroll-control .three').click(function () {
$.scrollify.move('#s-three');
});
});

$(window).on('resize', function () {
screenCheck();
});

function applyScroll() {
$.scrollify({
section: '.scroll',
sectionName: 'section-name',
//standardScrollElements: 'section',
easing: 'easeOutExpo',
scrollSpeed: 1100,
offset: 0,
scrollbars: true,
setHeights: true,
overflowScroll: true,
updateHash: false,
touchScroll: true,
});
}

function screenCheck() {
var deviceAgent = navigator.userAgent.toLowerCase();
var agentID = deviceAgent.match(/(iphone|ipod|ipad)/);
if (agentID || $(window).width() <= 1024) {
// its mobile screen
$.scrollify.destroy();
$('section').removeClass('scroll').removeAttr('style');
$.scrollify.disable();
} else {
// its desktop
$('section').addClass('scroll');
applyScroll();
$.scrollify.enable();
}
}