fullPage.js 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923
  1. /*!
  2. * fullPage 2.9.7
  3. * https://github.com/alvarotrigo/fullPage.js
  4. * @license MIT licensed
  5. *
  6. * Copyright (C) 2015 alvarotrigo.com - A project by Alvaro Trigo
  7. */
  8. (function(global, factory) {
  9. 'use strict';
  10. if (typeof define === 'function' && define.amd) {
  11. define(['jquery'], function($) {
  12. return factory($, global, global.document, global.Math);
  13. });
  14. } else if (typeof exports === "object" && exports) {
  15. module.exports = factory(require('jquery'), global, global.document, global.Math);
  16. } else {
  17. factory(jQuery, global, global.document, global.Math);
  18. }
  19. })(typeof window !== 'undefined' ? window : this, function($, window, document, Math, undefined) {
  20. 'use strict';
  21. // keeping central set of classnames and selectors
  22. var WRAPPER = 'fullpage-wrapper';
  23. var WRAPPER_SEL = '.' + WRAPPER;
  24. // slimscroll
  25. var SCROLLABLE = 'fp-scrollable';
  26. var SCROLLABLE_SEL = '.' + SCROLLABLE;
  27. // util
  28. var RESPONSIVE = 'fp-responsive';
  29. var NO_TRANSITION = 'fp-notransition';
  30. var DESTROYED = 'fp-destroyed';
  31. var ENABLED = 'fp-enabled';
  32. var VIEWING_PREFIX = 'fp-viewing';
  33. var ACTIVE = 'active';
  34. var ACTIVE_SEL = '.' + ACTIVE;
  35. var COMPLETELY = 'fp-completely';
  36. var COMPLETELY_SEL = '.' + COMPLETELY;
  37. // section
  38. var SECTION_DEFAULT_SEL = '.section';
  39. var SECTION = 'fp-section';
  40. var SECTION_SEL = '.' + SECTION;
  41. var SECTION_ACTIVE_SEL = SECTION_SEL + ACTIVE_SEL;
  42. var SECTION_FIRST_SEL = SECTION_SEL + ':first';
  43. var SECTION_LAST_SEL = SECTION_SEL + ':last';
  44. var TABLE_CELL = 'fp-tableCell';
  45. var TABLE_CELL_SEL = '.' + TABLE_CELL;
  46. var AUTO_HEIGHT = 'fp-auto-height';
  47. var AUTO_HEIGHT_SEL = '.fp-auto-height';
  48. var NORMAL_SCROLL = 'fp-normal-scroll';
  49. var NORMAL_SCROLL_SEL = '.fp-normal-scroll';
  50. // section nav
  51. var SECTION_NAV = 'fp-nav';
  52. var SECTION_NAV_SEL = '#' + SECTION_NAV;
  53. var SECTION_NAV_TOOLTIP = 'fp-tooltip';
  54. var SECTION_NAV_TOOLTIP_SEL='.'+SECTION_NAV_TOOLTIP;
  55. var SHOW_ACTIVE_TOOLTIP = 'fp-show-active';
  56. // slide
  57. var SLIDE_DEFAULT_SEL = '.slide';
  58. var SLIDE = 'fp-slide';
  59. var SLIDE_SEL = '.' + SLIDE;
  60. var SLIDE_ACTIVE_SEL = SLIDE_SEL + ACTIVE_SEL;
  61. var SLIDES_WRAPPER = 'fp-slides';
  62. var SLIDES_WRAPPER_SEL = '.' + SLIDES_WRAPPER;
  63. var SLIDES_CONTAINER = 'fp-slidesContainer';
  64. var SLIDES_CONTAINER_SEL = '.' + SLIDES_CONTAINER;
  65. var TABLE = 'fp-table';
  66. // slide nav
  67. var SLIDES_NAV = 'fp-slidesNav';
  68. var SLIDES_NAV_SEL = '.' + SLIDES_NAV;
  69. var SLIDES_NAV_LINK_SEL = SLIDES_NAV_SEL + ' a';
  70. var SLIDES_ARROW = 'fp-controlArrow';
  71. var SLIDES_ARROW_SEL = '.' + SLIDES_ARROW;
  72. var SLIDES_PREV = 'fp-prev';
  73. var SLIDES_PREV_SEL = '.' + SLIDES_PREV;
  74. var SLIDES_ARROW_PREV = SLIDES_ARROW + ' ' + SLIDES_PREV;
  75. var SLIDES_ARROW_PREV_SEL = SLIDES_ARROW_SEL + SLIDES_PREV_SEL;
  76. var SLIDES_NEXT = 'fp-next';
  77. var SLIDES_NEXT_SEL = '.' + SLIDES_NEXT;
  78. var SLIDES_ARROW_NEXT = SLIDES_ARROW + ' ' + SLIDES_NEXT;
  79. var SLIDES_ARROW_NEXT_SEL = SLIDES_ARROW_SEL + SLIDES_NEXT_SEL;
  80. var $window = $(window);
  81. var $document = $(document);
  82. $.fn.fullpage = function(options) {
  83. //only once my friend!
  84. if($('html').hasClass(ENABLED)){ displayWarnings(); return; }
  85. // common jQuery objects
  86. var $htmlBody = $('html, body');
  87. var $body = $('body');
  88. var FP = $.fn.fullpage;
  89. // Creating some defaults, extending them with any options that were provided
  90. options = $.extend({
  91. //navigation
  92. menu: false,
  93. anchors:[],
  94. lockAnchors: false,
  95. navigation: false,
  96. navigationPosition: 'right',
  97. navigationTooltips: [],
  98. showActiveTooltip: false,
  99. slidesNavigation: false,
  100. slidesNavPosition: 'bottom',
  101. scrollBar: false,
  102. hybrid: false,
  103. //scrolling
  104. css3: true,
  105. scrollingSpeed: 700,
  106. autoScrolling: true,
  107. fitToSection: true,
  108. fitToSectionDelay: 1000,
  109. easing: 'easeInOutCubic',
  110. easingcss3: 'ease',
  111. loopBottom: false,
  112. loopTop: false,
  113. loopHorizontal: true,
  114. continuousVertical: false,
  115. continuousHorizontal: false,
  116. scrollHorizontally: false,
  117. interlockedSlides: false,
  118. dragAndMove: false,
  119. offsetSections: false,
  120. resetSliders: false,
  121. fadingEffect: false,
  122. normalScrollElements: null,
  123. scrollOverflow: false,
  124. scrollOverflowReset: false,
  125. scrollOverflowHandler: $.fn.fp_scrolloverflow ? $.fn.fp_scrolloverflow.iscrollHandler : null,
  126. scrollOverflowOptions: null,
  127. touchSensitivity: 5,
  128. normalScrollElementTouchThreshold: 5,
  129. bigSectionsDestination: null,
  130. //Accessibility
  131. keyboardScrolling: true,
  132. animateAnchor: true,
  133. recordHistory: true,
  134. //design
  135. controlArrows: true,
  136. controlArrowColor: '#fff',
  137. verticalCentered: true,
  138. sectionsColor : [],
  139. paddingTop: 0,
  140. paddingBottom: 0,
  141. fixedElements: null,
  142. responsive: 0, //backwards compabitility with responsiveWiddth
  143. responsiveWidth: 0,
  144. responsiveHeight: 0,
  145. responsiveSlides: false,
  146. parallax: false,
  147. parallaxOptions: {
  148. type: 'reveal',
  149. percentage: 62,
  150. property: 'translate'
  151. },
  152. //Custom selectors
  153. sectionSelector: SECTION_DEFAULT_SEL,
  154. slideSelector: SLIDE_DEFAULT_SEL,
  155. //events
  156. afterLoad: null,
  157. onLeave: null,
  158. afterRender: null,
  159. afterResize: null,
  160. afterReBuild: null,
  161. afterSlideLoad: null,
  162. onSlideLeave: null,
  163. afterResponsive: null,
  164. lazyLoading: true
  165. }, options);
  166. //flag to avoid very fast sliding for landscape sliders
  167. var slideMoving = false;
  168. var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
  169. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
  170. var container = $(this);
  171. var windowsHeight = $window.height();
  172. var isResizing = false;
  173. var isWindowFocused = true;
  174. var lastScrolledDestiny;
  175. var lastScrolledSlide;
  176. var canScroll = true;
  177. var scrollings = [];
  178. var controlPressed;
  179. var startingSection;
  180. var isScrollAllowed = {};
  181. isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
  182. isScrollAllowed.k = $.extend(true,{}, isScrollAllowed.m);
  183. var MSPointer = getMSPointer();
  184. var events = {
  185. touchmove: 'ontouchmove' in window ? 'touchmove' : MSPointer.move,
  186. touchstart: 'ontouchstart' in window ? 'touchstart' : MSPointer.down
  187. };
  188. var scrollBarHandler;
  189. // taken from https://github.com/udacity/ud891/blob/gh-pages/lesson2-focus/07-modals-and-keyboard-traps/solution/modal.js
  190. var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
  191. //timeouts
  192. var resizeId;
  193. var afterSectionLoadsId;
  194. var afterSlideLoadsId;
  195. var scrollId;
  196. var scrollId2;
  197. var keydownId;
  198. var originals = $.extend(true, {}, options); //deep copy
  199. displayWarnings();
  200. //easeInOutCubic animation included in the plugin
  201. $.extend($.easing,{ easeInOutCubic: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t + b;return c/2*((t-=2)*t*t + 2) + b;}});
  202. /**
  203. * Sets the autoScroll option.
  204. * It changes the scroll bar visibility and the history of the site as a result.
  205. */
  206. function setAutoScrolling(value, type){
  207. //removing the transformation
  208. if(!value){
  209. silentScroll(0);
  210. }
  211. setVariableState('autoScrolling', value, type);
  212. var element = $(SECTION_ACTIVE_SEL);
  213. if(options.autoScrolling && !options.scrollBar){
  214. $htmlBody.css({
  215. 'overflow' : 'hidden',
  216. 'height' : '100%'
  217. });
  218. setRecordHistory(originals.recordHistory, 'internal');
  219. //for IE touch devices
  220. container.css({
  221. '-ms-touch-action': 'none',
  222. 'touch-action': 'none'
  223. });
  224. if(element.length){
  225. //moving the container up
  226. silentScroll(element.position().top);
  227. }
  228. }else{
  229. $htmlBody.css({
  230. 'overflow' : 'visible',
  231. 'height' : 'initial'
  232. });
  233. setRecordHistory(false, 'internal');
  234. //for IE touch devices
  235. container.css({
  236. '-ms-touch-action': '',
  237. 'touch-action': ''
  238. });
  239. //scrolling the page to the section with no animation
  240. if (element.length) {
  241. $htmlBody.scrollTop(element.position().top);
  242. }
  243. }
  244. }
  245. /**
  246. * Defines wheter to record the history for each hash change in the URL.
  247. */
  248. function setRecordHistory(value, type){
  249. setVariableState('recordHistory', value, type);
  250. }
  251. /**
  252. * Defines the scrolling speed
  253. */
  254. function setScrollingSpeed(value, type){
  255. setVariableState('scrollingSpeed', value, type);
  256. }
  257. /**
  258. * Sets fitToSection
  259. */
  260. function setFitToSection(value, type){
  261. setVariableState('fitToSection', value, type);
  262. }
  263. /**
  264. * Sets lockAnchors
  265. */
  266. function setLockAnchors(value){
  267. options.lockAnchors = value;
  268. }
  269. /**
  270. * Adds or remove the possibility of scrolling through sections by using the mouse wheel or the trackpad.
  271. */
  272. function setMouseWheelScrolling(value){
  273. if(value){
  274. addMouseWheelHandler();
  275. addMiddleWheelHandler();
  276. }else{
  277. removeMouseWheelHandler();
  278. removeMiddleWheelHandler();
  279. }
  280. }
  281. /**
  282. * Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures.
  283. * Optionally a second parameter can be used to specify the direction for which the action will be applied.
  284. *
  285. * @param directions string containing the direction or directions separated by comma.
  286. */
  287. function setAllowScrolling(value, directions){
  288. if(typeof directions !== 'undefined'){
  289. directions = directions.replace(/ /g,'').split(',');
  290. $.each(directions, function (index, direction){
  291. setIsScrollAllowed(value, direction, 'm');
  292. });
  293. }
  294. else{
  295. setIsScrollAllowed(value, 'all', 'm');
  296. if(value){
  297. setMouseWheelScrolling(true);
  298. addTouchHandler();
  299. }else{
  300. setMouseWheelScrolling(false);
  301. removeTouchHandler();
  302. }
  303. }
  304. }
  305. /**
  306. * Adds or remove the possibility of scrolling through sections by using the keyboard arrow keys
  307. */
  308. function setKeyboardScrolling(value, directions){
  309. if(typeof directions !== 'undefined'){
  310. directions = directions.replace(/ /g,'').split(',');
  311. $.each(directions, function (index, direction){
  312. setIsScrollAllowed(value, direction, 'k');
  313. });
  314. }else{
  315. setIsScrollAllowed(value, 'all', 'k');
  316. options.keyboardScrolling = value;
  317. }
  318. }
  319. /**
  320. * Moves the page up one section.
  321. */
  322. function moveSectionUp(){
  323. var prev = $(SECTION_ACTIVE_SEL).prev(SECTION_SEL);
  324. //looping to the bottom if there's no more sections above
  325. if (!prev.length && (options.loopTop || options.continuousVertical)) {
  326. prev = $(SECTION_SEL).last();
  327. }
  328. if (prev.length) {
  329. scrollPage(prev, null, true);
  330. }
  331. }
  332. /**
  333. * Moves the page down one section.
  334. */
  335. function moveSectionDown(){
  336. var next = $(SECTION_ACTIVE_SEL).next(SECTION_SEL);
  337. //looping to the top if there's no more sections below
  338. if(!next.length &&
  339. (options.loopBottom || options.continuousVertical)){
  340. next = $(SECTION_SEL).first();
  341. }
  342. if(next.length){
  343. scrollPage(next, null, false);
  344. }
  345. }
  346. /**
  347. * Moves the page to the given section and slide with no animation.
  348. * Anchors or index positions can be used as params.
  349. */
  350. function silentMoveTo(sectionAnchor, slideAnchor){
  351. setScrollingSpeed (0, 'internal');
  352. moveTo(sectionAnchor, slideAnchor);
  353. setScrollingSpeed (originals.scrollingSpeed, 'internal');
  354. }
  355. /**
  356. * Moves the page to the given section and slide.
  357. * Anchors or index positions can be used as params.
  358. */
  359. function moveTo(sectionAnchor, slideAnchor){
  360. var destiny = getSectionByAnchor(sectionAnchor);
  361. if (typeof slideAnchor !== 'undefined'){
  362. scrollPageAndSlide(sectionAnchor, slideAnchor);
  363. }else if(destiny.length > 0){
  364. scrollPage(destiny);
  365. }
  366. }
  367. /**
  368. * Slides right the slider of the active section.
  369. * Optional `section` param.
  370. */
  371. function moveSlideRight(section){
  372. moveSlide('right', section);
  373. }
  374. /**
  375. * Slides left the slider of the active section.
  376. * Optional `section` param.
  377. */
  378. function moveSlideLeft(section){
  379. moveSlide('left', section);
  380. }
  381. /**
  382. * When resizing is finished, we adjust the slides sizes and positions
  383. */
  384. function reBuild(resizing){
  385. if(container.hasClass(DESTROYED)){ return; } //nothing to do if the plugin was destroyed
  386. isResizing = true;
  387. windowsHeight = $window.height(); //updating global var
  388. $(SECTION_SEL).each(function(){
  389. var slidesWrap = $(this).find(SLIDES_WRAPPER_SEL);
  390. var slides = $(this).find(SLIDE_SEL);
  391. //adjusting the height of the table-cell for IE and Firefox
  392. if(options.verticalCentered){
  393. $(this).find(TABLE_CELL_SEL).css('height', getTableHeight($(this)) + 'px');
  394. }
  395. $(this).css('height', windowsHeight + 'px');
  396. //adjusting the position fo the FULL WIDTH slides...
  397. if (slides.length > 1) {
  398. landscapeScroll(slidesWrap, slidesWrap.find(SLIDE_ACTIVE_SEL));
  399. }
  400. });
  401. if(options.scrollOverflow){
  402. scrollBarHandler.createScrollBarForAll();
  403. }
  404. var activeSection = $(SECTION_ACTIVE_SEL);
  405. var sectionIndex = activeSection.index(SECTION_SEL);
  406. //isn't it the first section?
  407. if(sectionIndex){
  408. //adjusting the position for the current section
  409. silentMoveTo(sectionIndex + 1);
  410. }
  411. isResizing = false;
  412. $.isFunction( options.afterResize ) && resizing && options.afterResize.call(container);
  413. $.isFunction( options.afterReBuild ) && !resizing && options.afterReBuild.call(container);
  414. }
  415. /**
  416. * Turns fullPage.js to normal scrolling mode when the viewport `width` or `height`
  417. * are smaller than the set limit values.
  418. */
  419. function setResponsive(active){
  420. var isResponsive = $body.hasClass(RESPONSIVE);
  421. if(active){
  422. if(!isResponsive){
  423. setAutoScrolling(false, 'internal');
  424. setFitToSection(false, 'internal');
  425. $(SECTION_NAV_SEL).hide();
  426. $body.addClass(RESPONSIVE);
  427. $.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
  428. }
  429. }
  430. else if(isResponsive){
  431. setAutoScrolling(originals.autoScrolling, 'internal');
  432. setFitToSection(originals.autoScrolling, 'internal');
  433. $(SECTION_NAV_SEL).show();
  434. $body.removeClass(RESPONSIVE);
  435. $.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
  436. }
  437. }
  438. if($(this).length){
  439. //public functions
  440. FP.version = '2.9.7';
  441. FP.setAutoScrolling = setAutoScrolling;
  442. FP.setRecordHistory = setRecordHistory;
  443. FP.setScrollingSpeed = setScrollingSpeed;
  444. FP.setFitToSection = setFitToSection;
  445. FP.setLockAnchors = setLockAnchors;
  446. FP.setMouseWheelScrolling = setMouseWheelScrolling;
  447. FP.setAllowScrolling = setAllowScrolling;
  448. FP.setKeyboardScrolling = setKeyboardScrolling;
  449. FP.moveSectionUp = moveSectionUp;
  450. FP.moveSectionDown = moveSectionDown;
  451. FP.silentMoveTo = silentMoveTo;
  452. FP.moveTo = moveTo;
  453. FP.moveSlideRight = moveSlideRight;
  454. FP.moveSlideLeft = moveSlideLeft;
  455. FP.fitToSection = fitToSection;
  456. FP.reBuild = reBuild;
  457. FP.setResponsive = setResponsive;
  458. FP.destroy = destroy;
  459. //functions we want to share across files but which are not
  460. //mean to be used on their own by developers
  461. FP.shared ={
  462. afterRenderActions: afterRenderActions
  463. };
  464. init();
  465. bindEvents();
  466. }
  467. function init(){
  468. //if css3 is not supported, it will use jQuery animations
  469. if(options.css3){
  470. options.css3 = support3d();
  471. }
  472. options.scrollBar = options.scrollBar || options.hybrid;
  473. setOptionsFromDOM();
  474. prepareDom();
  475. setAllowScrolling(true);
  476. setAutoScrolling(options.autoScrolling, 'internal');
  477. responsive();
  478. //setting the class for the body element
  479. setBodyClass();
  480. if(document.readyState === 'complete'){
  481. scrollToAnchor();
  482. }
  483. $window.on('load', scrollToAnchor);
  484. }
  485. function bindEvents(){
  486. $window
  487. //when scrolling...
  488. .on('scroll', scrollHandler)
  489. //detecting any change on the URL to scroll to the given anchor link
  490. //(a way to detect back history button as we play with the hashes on the URL)
  491. .on('hashchange', hashChangeHandler)
  492. //when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
  493. .blur(blurHandler)
  494. //when resizing the site, we adjust the heights of the sections, slimScroll...
  495. .resize(resizeHandler);
  496. $document
  497. //Sliding with arrow keys, both, vertical and horizontal
  498. .keydown(keydownHandler)
  499. //to prevent scrolling while zooming
  500. .keyup(keyUpHandler)
  501. //Scrolls to the section when clicking the navigation bullet
  502. .on('click touchstart', SECTION_NAV_SEL + ' a', sectionBulletHandler)
  503. //Scrolls the slider to the given slide destination for the given section
  504. .on('click touchstart', SLIDES_NAV_LINK_SEL, slideBulletHandler)
  505. .on('click', SECTION_NAV_TOOLTIP_SEL, tooltipTextHandler);
  506. //Scrolling horizontally when clicking on the slider controls.
  507. $(SECTION_SEL).on('click touchstart', SLIDES_ARROW_SEL, slideArrowHandler);
  508. /**
  509. * Applying normalScroll elements.
  510. * Ignoring the scrolls over the specified selectors.
  511. */
  512. if(options.normalScrollElements){
  513. $document.on('mouseenter touchstart', options.normalScrollElements, function () {
  514. setAllowScrolling(false);
  515. });
  516. $document.on('mouseleave touchend', options.normalScrollElements, function(){
  517. setAllowScrolling(true);
  518. });
  519. }
  520. }
  521. /**
  522. * Setting options from DOM elements if they are not provided.
  523. */
  524. function setOptionsFromDOM(){
  525. var sections = container.find(options.sectionSelector);
  526. //no anchors option? Checking for them in the DOM attributes
  527. if(!options.anchors.length){
  528. options.anchors = sections.filter('[data-anchor]').map(function(){
  529. return $(this).data('anchor').toString();
  530. }).get();
  531. }
  532. //no tooltips option? Checking for them in the DOM attributes
  533. if(!options.navigationTooltips.length){
  534. options.navigationTooltips = sections.filter('[data-tooltip]').map(function(){
  535. return $(this).data('tooltip').toString();
  536. }).get();
  537. }
  538. }
  539. /**
  540. * Works over the DOM structure to set it up for the current fullpage options.
  541. */
  542. function prepareDom(){
  543. container.css({
  544. 'height': '100%',
  545. 'position': 'relative'
  546. });
  547. //adding a class to recognize the container internally in the code
  548. container.addClass(WRAPPER);
  549. $('html').addClass(ENABLED);
  550. //due to https://github.com/alvarotrigo/fullPage.js/issues/1502
  551. windowsHeight = $window.height();
  552. container.removeClass(DESTROYED); //in case it was destroyed before initializing it again
  553. addInternalSelectors();
  554. //styling the sections / slides / menu
  555. $(SECTION_SEL).each(function(index){
  556. var section = $(this);
  557. var slides = section.find(SLIDE_SEL);
  558. var numSlides = slides.length;
  559. //caching the original styles to add them back on destroy('all')
  560. section.data('fp-styles', section.attr('style'));
  561. styleSection(section, index);
  562. styleMenu(section, index);
  563. // if there's any slide
  564. if (numSlides > 0) {
  565. styleSlides(section, slides, numSlides);
  566. }else{
  567. if(options.verticalCentered){
  568. addTableClass(section);
  569. }
  570. }
  571. });
  572. //fixed elements need to be moved out of the plugin container due to problems with CSS3.
  573. if(options.fixedElements && options.css3){
  574. $(options.fixedElements).appendTo($body);
  575. }
  576. //vertical centered of the navigation + active bullet
  577. if(options.navigation){
  578. addVerticalNavigation();
  579. }
  580. enableYoutubeAPI();
  581. if(options.scrollOverflow){
  582. scrollBarHandler = options.scrollOverflowHandler.init(options);
  583. }else{
  584. afterRenderActions();
  585. }
  586. }
  587. /**
  588. * Styles the horizontal slides for a section.
  589. */
  590. function styleSlides(section, slides, numSlides){
  591. var sliderWidth = numSlides * 100;
  592. var slideWidth = 100 / numSlides;
  593. slides.wrapAll('<div class="' + SLIDES_CONTAINER + '" />');
  594. slides.parent().wrap('<div class="' + SLIDES_WRAPPER + '" />');
  595. section.find(SLIDES_CONTAINER_SEL).css('width', sliderWidth + '%');
  596. if(numSlides > 1){
  597. if(options.controlArrows){
  598. createSlideArrows(section);
  599. }
  600. if(options.slidesNavigation){
  601. addSlidesNavigation(section, numSlides);
  602. }
  603. }
  604. slides.each(function(index) {
  605. $(this).css('width', slideWidth + '%');
  606. if(options.verticalCentered){
  607. addTableClass($(this));
  608. }
  609. });
  610. var startingSlide = section.find(SLIDE_ACTIVE_SEL);
  611. //if the slide won't be an starting point, the default will be the first one
  612. //the active section isn't the first one? Is not the first slide of the first section? Then we load that section/slide by default.
  613. if( startingSlide.length && ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) !== 0 || ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) === 0 && startingSlide.index() !== 0))){
  614. silentLandscapeScroll(startingSlide, 'internal');
  615. }else{
  616. slides.eq(0).addClass(ACTIVE);
  617. }
  618. }
  619. /**
  620. * Styling vertical sections
  621. */
  622. function styleSection(section, index){
  623. //if no active section is defined, the 1st one will be the default one
  624. if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
  625. section.addClass(ACTIVE);
  626. }
  627. startingSection = $(SECTION_ACTIVE_SEL);
  628. section.css('height', windowsHeight + 'px');
  629. if(options.paddingTop){
  630. section.css('padding-top', options.paddingTop);
  631. }
  632. if(options.paddingBottom){
  633. section.css('padding-bottom', options.paddingBottom);
  634. }
  635. if (typeof options.sectionsColor[index] !== 'undefined') {
  636. section.css('background-color', options.sectionsColor[index]);
  637. }
  638. if (typeof options.anchors[index] !== 'undefined') {
  639. section.attr('data-anchor', options.anchors[index]);
  640. }
  641. }
  642. /**
  643. * Sets the data-anchor attributes to the menu elements and activates the current one.
  644. */
  645. function styleMenu(section, index){
  646. if (typeof options.anchors[index] !== 'undefined') {
  647. //activating the menu / nav element on load
  648. if(section.hasClass(ACTIVE)){
  649. activateMenuAndNav(options.anchors[index], index);
  650. }
  651. }
  652. //moving the menu outside the main container if it is inside (avoid problems with fixed positions when using CSS3 tranforms)
  653. if(options.menu && options.css3 && $(options.menu).closest(WRAPPER_SEL).length){
  654. $(options.menu).appendTo($body);
  655. }
  656. }
  657. /**
  658. * Adds internal classes to be able to provide customizable selectors
  659. * keeping the link with the style sheet.
  660. */
  661. function addInternalSelectors(){
  662. container.find(options.sectionSelector).addClass(SECTION);
  663. container.find(options.slideSelector).addClass(SLIDE);
  664. }
  665. /**
  666. * Creates the control arrows for the given section
  667. */
  668. function createSlideArrows(section){
  669. section.find(SLIDES_WRAPPER_SEL).after('<div class="' + SLIDES_ARROW_PREV + '"></div><div class="' + SLIDES_ARROW_NEXT + '"></div>');
  670. if(options.controlArrowColor!='#fff'){
  671. section.find(SLIDES_ARROW_NEXT_SEL).css('border-color', 'transparent transparent transparent '+options.controlArrowColor);
  672. section.find(SLIDES_ARROW_PREV_SEL).css('border-color', 'transparent '+ options.controlArrowColor + ' transparent transparent');
  673. }
  674. if(!options.loopHorizontal){
  675. section.find(SLIDES_ARROW_PREV_SEL).hide();
  676. }
  677. }
  678. /**
  679. * Creates a vertical navigation bar.
  680. */
  681. function addVerticalNavigation(){
  682. $body.append('<div id="' + SECTION_NAV + '"><ul></ul></div>');
  683. var nav = $(SECTION_NAV_SEL);
  684. nav.addClass(function() {
  685. return options.showActiveTooltip ? SHOW_ACTIVE_TOOLTIP + ' ' + options.navigationPosition : options.navigationPosition;
  686. });
  687. for (var i = 0; i < $(SECTION_SEL).length; i++) {
  688. var link = '';
  689. if (options.anchors.length) {
  690. link = options.anchors[i];
  691. }
  692. var li = '<li><a href="#' + link + '"><span></span></a>';
  693. // Only add tooltip if needed (defined by user)
  694. var tooltip = options.navigationTooltips[i];
  695. if (typeof tooltip !== 'undefined' && tooltip !== '') {
  696. li += '<div class="' + SECTION_NAV_TOOLTIP + ' ' + options.navigationPosition + '">' + tooltip + '</div>';
  697. }
  698. li += '</li>';
  699. nav.find('ul').append(li);
  700. }
  701. //centering it vertically
  702. $(SECTION_NAV_SEL).css('margin-top', '-' + ($(SECTION_NAV_SEL).height()/2) + 'px');
  703. //activating the current active section
  704. $(SECTION_NAV_SEL).find('li').eq($(SECTION_ACTIVE_SEL).index(SECTION_SEL)).find('a').addClass(ACTIVE);
  705. }
  706. /*
  707. * Enables the Youtube videos API so we can control their flow if necessary.
  708. */
  709. function enableYoutubeAPI(){
  710. container.find('iframe[src*="youtube.com/embed/"]').each(function(){
  711. addURLParam($(this), 'enablejsapi=1');
  712. });
  713. }
  714. /**
  715. * Adds a new parameter and its value to the `src` of a given element
  716. */
  717. function addURLParam(element, newParam){
  718. var originalSrc = element.attr('src');
  719. element.attr('src', originalSrc + getUrlParamSign(originalSrc) + newParam);
  720. }
  721. /*
  722. * Returns the prefix sign to use for a new parameter in an existen URL.
  723. *
  724. * @return {String} ? | &
  725. */
  726. function getUrlParamSign(url){
  727. return ( !/\?/.test( url ) ) ? '?' : '&';
  728. }
  729. /**
  730. * Actions and callbacks to fire afterRender
  731. */
  732. function afterRenderActions(){
  733. var section = $(SECTION_ACTIVE_SEL);
  734. section.addClass(COMPLETELY);
  735. lazyLoad(section);
  736. playMedia(section);
  737. if(options.scrollOverflow){
  738. options.scrollOverflowHandler.afterLoad();
  739. }
  740. if(isDestinyTheStartingSection()){
  741. $.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
  742. }
  743. $.isFunction( options.afterRender ) && options.afterRender.call(container);
  744. }
  745. /**
  746. * Determines if the URL anchor destiny is the starting section (the one using 'active' class before initialization)
  747. */
  748. function isDestinyTheStartingSection(){
  749. var destinationSection = getSectionByAnchor(getAnchorsURL().section);
  750. return !destinationSection || destinationSection.length && destinationSection.index() === startingSection.index();
  751. }
  752. var isScrolling = false;
  753. var lastScroll = 0;
  754. //when scrolling...
  755. function scrollHandler(){
  756. var currentSection;
  757. if(!options.autoScrolling || options.scrollBar){
  758. var currentScroll = $window.scrollTop();
  759. var scrollDirection = getScrollDirection(currentScroll);
  760. var visibleSectionIndex = 0;
  761. var screen_mid = currentScroll + ($window.height() / 2.0);
  762. var isAtBottom = $body.height() - $window.height() === currentScroll;
  763. var sections = document.querySelectorAll(SECTION_SEL);
  764. //when using `auto-height` for a small last section it won't be centered in the viewport
  765. if(isAtBottom){
  766. visibleSectionIndex = sections.length - 1;
  767. }
  768. //is at top? when using `auto-height` for a small first section it won't be centered in the viewport
  769. else if(!currentScroll){
  770. visibleSectionIndex = 0;
  771. }
  772. //taking the section which is showing more content in the viewport
  773. else{
  774. for (var i = 0; i < sections.length; ++i) {
  775. var section = sections[i];
  776. // Pick the the last section which passes the middle line of the screen.
  777. if (section.offsetTop <= screen_mid)
  778. {
  779. visibleSectionIndex = i;
  780. }
  781. }
  782. }
  783. if(isCompletelyInViewPort(scrollDirection)){
  784. if(!$(SECTION_ACTIVE_SEL).hasClass(COMPLETELY)){
  785. $(SECTION_ACTIVE_SEL).addClass(COMPLETELY).siblings().removeClass(COMPLETELY);
  786. }
  787. }
  788. //geting the last one, the current one on the screen
  789. currentSection = $(sections).eq(visibleSectionIndex);
  790. //setting the visible section as active when manually scrolling
  791. //executing only once the first time we reach the section
  792. if(!currentSection.hasClass(ACTIVE)){
  793. isScrolling = true;
  794. var leavingSection = $(SECTION_ACTIVE_SEL);
  795. var leavingSectionIndex = leavingSection.index(SECTION_SEL) + 1;
  796. var yMovement = getYmovement(currentSection);
  797. var anchorLink = currentSection.data('anchor');
  798. var sectionIndex = currentSection.index(SECTION_SEL) + 1;
  799. var activeSlide = currentSection.find(SLIDE_ACTIVE_SEL);
  800. var slideIndex;
  801. var slideAnchorLink;
  802. if(activeSlide.length){
  803. slideAnchorLink = activeSlide.data('anchor');
  804. slideIndex = activeSlide.index();
  805. }
  806. if(canScroll){
  807. currentSection.addClass(ACTIVE).siblings().removeClass(ACTIVE);
  808. $.isFunction( options.onLeave ) && options.onLeave.call( leavingSection, leavingSectionIndex, sectionIndex, yMovement);
  809. $.isFunction( options.afterLoad ) && options.afterLoad.call( currentSection, anchorLink, sectionIndex);
  810. stopMedia(leavingSection);
  811. lazyLoad(currentSection);
  812. playMedia(currentSection);
  813. activateMenuAndNav(anchorLink, sectionIndex - 1);
  814. if(options.anchors.length){
  815. //needed to enter in hashChange event when using the menu with anchor links
  816. lastScrolledDestiny = anchorLink;
  817. }
  818. setState(slideIndex, slideAnchorLink, anchorLink, sectionIndex);
  819. }
  820. //small timeout in order to avoid entering in hashChange event when scrolling is not finished yet
  821. clearTimeout(scrollId);
  822. scrollId = setTimeout(function(){
  823. isScrolling = false;
  824. }, 100);
  825. }
  826. if(options.fitToSection){
  827. //for the auto adjust of the viewport to fit a whole section
  828. clearTimeout(scrollId2);
  829. scrollId2 = setTimeout(function(){
  830. //checking it again in case it changed during the delay
  831. if(options.fitToSection &&
  832. //is the destination element bigger than the viewport?
  833. $(SECTION_ACTIVE_SEL).outerHeight() <= windowsHeight
  834. ){
  835. fitToSection();
  836. }
  837. }, options.fitToSectionDelay);
  838. }
  839. }
  840. }
  841. /**
  842. * Fits the site to the nearest active section
  843. */
  844. function fitToSection(){
  845. //checking fitToSection again in case it was set to false before the timeout delay
  846. if(canScroll){
  847. //allows to scroll to an active section and
  848. //if the section is already active, we prevent firing callbacks
  849. isResizing = true;
  850. scrollPage($(SECTION_ACTIVE_SEL));
  851. isResizing = false;
  852. }
  853. }
  854. /**
  855. * Determines whether the active section has seen in its whole or not.
  856. */
  857. function isCompletelyInViewPort(movement){
  858. var top = $(SECTION_ACTIVE_SEL).position().top;
  859. var bottom = top + $window.height();
  860. if(movement == 'up'){
  861. return bottom >= ($window.scrollTop() + $window.height());
  862. }
  863. return top <= $window.scrollTop();
  864. }
  865. /**
  866. * Gets the directon of the the scrolling fired by the scroll event.
  867. */
  868. function getScrollDirection(currentScroll){
  869. var direction = currentScroll > lastScroll ? 'down' : 'up';
  870. lastScroll = currentScroll;
  871. //needed for auto-height sections to determine if we want to scroll to the top or bottom of the destination
  872. previousDestTop = currentScroll;
  873. return direction;
  874. }
  875. /**
  876. * Determines the way of scrolling up or down:
  877. * by 'automatically' scrolling a section or by using the default and normal scrolling.
  878. */
  879. function scrolling(type){
  880. if (!isScrollAllowed.m[type]){
  881. return;
  882. }
  883. var scrollSection = (type === 'down') ? moveSectionDown : moveSectionUp;
  884. if(options.scrollOverflow){
  885. var scrollable = options.scrollOverflowHandler.scrollable($(SECTION_ACTIVE_SEL));
  886. var check = (type === 'down') ? 'bottom' : 'top';
  887. if(scrollable.length > 0 ){
  888. //is the scrollbar at the start/end of the scroll?
  889. if(options.scrollOverflowHandler.isScrolled(check, scrollable)){
  890. scrollSection();
  891. }else{
  892. return true;
  893. }
  894. }else{
  895. // moved up/down
  896. scrollSection();
  897. }
  898. }else{
  899. // moved up/down
  900. scrollSection();
  901. }
  902. }
  903. /*
  904. * Preventing bouncing in iOS #2285
  905. */
  906. function preventBouncing(event){
  907. var e = event.originalEvent;
  908. if(options.autoScrolling && isReallyTouch(e)){
  909. //preventing the easing on iOS devices
  910. event.preventDefault();
  911. }
  912. }
  913. var touchStartY = 0;
  914. var touchStartX = 0;
  915. var touchEndY = 0;
  916. var touchEndX = 0;
  917. /* Detecting touch events
  918. * As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it.
  919. * This way, the touchstart and the touch moves shows an small difference between them which is the
  920. * used one to determine the direction.
  921. */
  922. function touchMoveHandler(event){
  923. var e = event.originalEvent;
  924. var activeSection = $(e.target).closest(SECTION_SEL);
  925. // additional: if one of the normalScrollElements isn't within options.normalScrollElementTouchThreshold hops up the DOM chain
  926. if (isReallyTouch(e) ) {
  927. if(options.autoScrolling){
  928. //preventing the easing on iOS devices
  929. event.preventDefault();
  930. }
  931. var touchEvents = getEventsPage(e);
  932. touchEndY = touchEvents.y;
  933. touchEndX = touchEvents.x;
  934. //if movement in the X axys is greater than in the Y and the currect section has slides...
  935. if (activeSection.find(SLIDES_WRAPPER_SEL).length && Math.abs(touchStartX - touchEndX) > (Math.abs(touchStartY - touchEndY))) {
  936. //is the movement greater than the minimum resistance to scroll?
  937. if (!slideMoving && Math.abs(touchStartX - touchEndX) > ($window.outerWidth() / 100 * options.touchSensitivity)) {
  938. if (touchStartX > touchEndX) {
  939. if(isScrollAllowed.m.right){
  940. moveSlideRight(activeSection); //next
  941. }
  942. } else {
  943. if(isScrollAllowed.m.left){
  944. moveSlideLeft(activeSection); //prev
  945. }
  946. }
  947. }
  948. }
  949. //vertical scrolling (only when autoScrolling is enabled)
  950. else if(options.autoScrolling && canScroll){
  951. //is the movement greater than the minimum resistance to scroll?
  952. if (Math.abs(touchStartY - touchEndY) > ($window.height() / 100 * options.touchSensitivity)) {
  953. if (touchStartY > touchEndY) {
  954. scrolling('down');
  955. } else if (touchEndY > touchStartY) {
  956. scrolling('up');
  957. }
  958. }
  959. }
  960. }
  961. }
  962. /**
  963. * As IE >= 10 fires both touch and mouse events when using a mouse in a touchscreen
  964. * this way we make sure that is really a touch event what IE is detecting.
  965. */
  966. function isReallyTouch(e){
  967. //if is not IE || IE is detecting `touch` or `pen`
  968. return typeof e.pointerType === 'undefined' || e.pointerType != 'mouse';
  969. }
  970. /**
  971. * Handler for the touch start event.
  972. */
  973. function touchStartHandler(event){
  974. var e = event.originalEvent;
  975. //stopping the auto scroll to adjust to a section
  976. if(options.fitToSection){
  977. $htmlBody.stop();
  978. }
  979. if(isReallyTouch(e)){
  980. var touchEvents = getEventsPage(e);
  981. touchStartY = touchEvents.y;
  982. touchStartX = touchEvents.x;
  983. }
  984. }
  985. /**
  986. * Gets the average of the last `number` elements of the given array.
  987. */
  988. function getAverage(elements, number){
  989. var sum = 0;
  990. //taking `number` elements from the end to make the average, if there are not enought, 1
  991. var lastElements = elements.slice(Math.max(elements.length - number, 1));
  992. for(var i = 0; i < lastElements.length; i++){
  993. sum = sum + lastElements[i];
  994. }
  995. return Math.ceil(sum/number);
  996. }
  997. /**
  998. * Detecting mousewheel scrolling
  999. *
  1000. * http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
  1001. * http://www.sitepoint.com/html5-javascript-mouse-wheel/
  1002. */
  1003. var prevTime = new Date().getTime();
  1004. function MouseWheelHandler(e) {
  1005. var curTime = new Date().getTime();
  1006. var isNormalScroll = $(COMPLETELY_SEL).hasClass(NORMAL_SCROLL);
  1007. //autoscrolling and not zooming?
  1008. if(options.autoScrolling && !controlPressed && !isNormalScroll){
  1009. // cross-browser wheel delta
  1010. e = e || window.event;
  1011. var value = e.wheelDelta || -e.deltaY || -e.detail;
  1012. var delta = Math.max(-1, Math.min(1, value));
  1013. var horizontalDetection = typeof e.wheelDeltaX !== 'undefined' || typeof e.deltaX !== 'undefined';
  1014. var isScrollingVertically = (Math.abs(e.wheelDeltaX) < Math.abs(e.wheelDelta)) || (Math.abs(e.deltaX ) < Math.abs(e.deltaY) || !horizontalDetection);
  1015. //Limiting the array to 150 (lets not waste memory!)
  1016. if(scrollings.length > 149){
  1017. scrollings.shift();
  1018. }
  1019. //keeping record of the previous scrollings
  1020. scrollings.push(Math.abs(value));
  1021. //preventing to scroll the site on mouse wheel when scrollbar is present
  1022. if(options.scrollBar){
  1023. e.preventDefault ? e.preventDefault() : e.returnValue = false;
  1024. }
  1025. //time difference between the last scroll and the current one
  1026. var timeDiff = curTime-prevTime;
  1027. prevTime = curTime;
  1028. //haven't they scrolled in a while?
  1029. //(enough to be consider a different scrolling action to scroll another section)
  1030. if(timeDiff > 200){
  1031. //emptying the array, we dont care about old scrollings for our averages
  1032. scrollings = [];
  1033. }
  1034. if(canScroll){
  1035. var averageEnd = getAverage(scrollings, 10);
  1036. var averageMiddle = getAverage(scrollings, 70);
  1037. var isAccelerating = averageEnd >= averageMiddle;
  1038. //to avoid double swipes...
  1039. if(isAccelerating && isScrollingVertically){
  1040. //scrolling down?
  1041. if (delta < 0) {
  1042. scrolling('down');
  1043. //scrolling up?
  1044. }else {
  1045. scrolling('up');
  1046. }
  1047. }
  1048. }
  1049. return false;
  1050. }
  1051. if(options.fitToSection){
  1052. //stopping the auto scroll to adjust to a section
  1053. $htmlBody.stop();
  1054. }
  1055. }
  1056. /**
  1057. * Slides a slider to the given direction.
  1058. * Optional `section` param.
  1059. */
  1060. function moveSlide(direction, section){
  1061. var activeSection = typeof section === 'undefined' ? $(SECTION_ACTIVE_SEL) : section;
  1062. var slides = activeSection.find(SLIDES_WRAPPER_SEL);
  1063. var numSlides = slides.find(SLIDE_SEL).length;
  1064. // more than one slide needed and nothing should be sliding
  1065. if (!slides.length || slideMoving || numSlides < 2) {
  1066. return;
  1067. }
  1068. var currentSlide = slides.find(SLIDE_ACTIVE_SEL);
  1069. var destiny = null;
  1070. if(direction === 'left'){
  1071. destiny = currentSlide.prev(SLIDE_SEL);
  1072. }else{
  1073. destiny = currentSlide.next(SLIDE_SEL);
  1074. }
  1075. //isn't there a next slide in the secuence?
  1076. if(!destiny.length){
  1077. //respect loopHorizontal settin
  1078. if (!options.loopHorizontal) return;
  1079. if(direction === 'left'){
  1080. destiny = currentSlide.siblings(':last');
  1081. }else{
  1082. destiny = currentSlide.siblings(':first');
  1083. }
  1084. }
  1085. slideMoving = true;
  1086. landscapeScroll(slides, destiny, direction);
  1087. }
  1088. /**
  1089. * Maintains the active slides in the viewport
  1090. * (Because the `scroll` animation might get lost with some actions, such as when using continuousVertical)
  1091. */
  1092. function keepSlidesPosition(){
  1093. $(SLIDE_ACTIVE_SEL).each(function(){
  1094. silentLandscapeScroll($(this), 'internal');
  1095. });
  1096. }
  1097. var previousDestTop = 0;
  1098. /**
  1099. * Returns the destination Y position based on the scrolling direction and
  1100. * the height of the section.
  1101. */
  1102. function getDestinationPosition(element){
  1103. var elemPosition = element.position();
  1104. //top of the desination will be at the top of the viewport
  1105. var position = elemPosition.top;
  1106. var isScrollingDown = elemPosition.top > previousDestTop;
  1107. var sectionBottom = position - windowsHeight + element.outerHeight();
  1108. var bigSectionsDestination = options.bigSectionsDestination;
  1109. //is the destination element bigger than the viewport?
  1110. if(element.outerHeight() > windowsHeight){
  1111. //scrolling up?
  1112. if(!isScrollingDown && !bigSectionsDestination || bigSectionsDestination === 'bottom' ){
  1113. position = sectionBottom;
  1114. }
  1115. }
  1116. //sections equal or smaller than the viewport height && scrolling down? || is resizing and its in the last section
  1117. else if(isScrollingDown || (isResizing && element.is(':last-child')) ){
  1118. //The bottom of the destination will be at the bottom of the viewport
  1119. position = sectionBottom;
  1120. }
  1121. /*
  1122. Keeping record of the last scrolled position to determine the scrolling direction.
  1123. No conventional methods can be used as the scroll bar might not be present
  1124. AND the section might not be active if it is auto-height and didnt reach the middle
  1125. of the viewport.
  1126. */
  1127. previousDestTop = position;
  1128. return position;
  1129. }
  1130. /**
  1131. * Scrolls the site to the given element and scrolls to the slide if a callback is given.
  1132. */
  1133. function scrollPage(element, callback, isMovementUp){
  1134. if(typeof element === 'undefined'){ return; } //there's no element to scroll, leaving the function
  1135. var dtop = getDestinationPosition(element);
  1136. var slideAnchorLink;
  1137. var slideIndex;
  1138. //local variables
  1139. var v = {
  1140. element: element,
  1141. callback: callback,
  1142. isMovementUp: isMovementUp,
  1143. dtop: dtop,
  1144. yMovement: getYmovement(element),
  1145. anchorLink: element.data('anchor'),
  1146. sectionIndex: element.index(SECTION_SEL),
  1147. activeSlide: element.find(SLIDE_ACTIVE_SEL),
  1148. activeSection: $(SECTION_ACTIVE_SEL),
  1149. leavingSection: $(SECTION_ACTIVE_SEL).index(SECTION_SEL) + 1,
  1150. //caching the value of isResizing at the momment the function is called
  1151. //because it will be checked later inside a setTimeout and the value might change
  1152. localIsResizing: isResizing
  1153. };
  1154. //quiting when destination scroll is the same as the current one
  1155. if((v.activeSection.is(element) && !isResizing) || (options.scrollBar && $window.scrollTop() === v.dtop && !element.hasClass(AUTO_HEIGHT) )){ return; }
  1156. if(v.activeSlide.length){
  1157. slideAnchorLink = v.activeSlide.data('anchor');
  1158. slideIndex = v.activeSlide.index();
  1159. }
  1160. //callback (onLeave) if the site is not just resizing and readjusting the slides
  1161. if($.isFunction(options.onLeave) && !v.localIsResizing){
  1162. var direction = v.yMovement;
  1163. //required for continousVertical
  1164. if(typeof isMovementUp !== 'undefined'){
  1165. direction = isMovementUp ? 'up' : 'down';
  1166. }
  1167. if(options.onLeave.call(v.activeSection, v.leavingSection, (v.sectionIndex + 1), direction) === false){
  1168. return;
  1169. }
  1170. }
  1171. // If continuousVertical && we need to wrap around
  1172. if (options.autoScrolling && options.continuousVertical && typeof (v.isMovementUp) !== "undefined" &&
  1173. ((!v.isMovementUp && v.yMovement == 'up') || // Intending to scroll down but about to go up or
  1174. (v.isMovementUp && v.yMovement == 'down'))) { // intending to scroll up but about to go down
  1175. v = createInfiniteSections(v);
  1176. }
  1177. //pausing media of the leaving section (if we are not just resizing, as destinatino will be the same one)
  1178. if(!v.localIsResizing){
  1179. stopMedia(v.activeSection);
  1180. }
  1181. if(options.scrollOverflow){
  1182. options.scrollOverflowHandler.beforeLeave();
  1183. }
  1184. element.addClass(ACTIVE).siblings().removeClass(ACTIVE);
  1185. lazyLoad(element);
  1186. if(options.scrollOverflow){
  1187. options.scrollOverflowHandler.onLeave();
  1188. }
  1189. //preventing from activating the MouseWheelHandler event
  1190. //more than once if the page is scrolling
  1191. canScroll = false;
  1192. setState(slideIndex, slideAnchorLink, v.anchorLink, v.sectionIndex);
  1193. performMovement(v);
  1194. //flag to avoid callingn `scrollPage()` twice in case of using anchor links
  1195. lastScrolledDestiny = v.anchorLink;
  1196. //avoid firing it twice (as it does also on scroll)
  1197. activateMenuAndNav(v.anchorLink, v.sectionIndex);
  1198. }
  1199. /**
  1200. * Performs the vertical movement (by CSS3 or by jQuery)
  1201. */
  1202. function performMovement(v){
  1203. // using CSS3 translate functionality
  1204. if (options.css3 && options.autoScrolling && !options.scrollBar) {
  1205. // The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
  1206. // that's why we round it to 0.
  1207. var translate3d = 'translate3d(0px, -' + Math.round(v.dtop) + 'px, 0px)';
  1208. transformContainer(translate3d, true);
  1209. //even when the scrollingSpeed is 0 there's a little delay, which might cause the
  1210. //scrollingSpeed to change in case of using silentMoveTo();
  1211. if(options.scrollingSpeed){
  1212. clearTimeout(afterSectionLoadsId);
  1213. afterSectionLoadsId = setTimeout(function () {
  1214. afterSectionLoads(v);
  1215. }, options.scrollingSpeed);
  1216. }else{
  1217. afterSectionLoads(v);
  1218. }
  1219. }
  1220. // using jQuery animate
  1221. else{
  1222. var scrollSettings = getScrollSettings(v);
  1223. $(scrollSettings.element).animate(
  1224. scrollSettings.options,
  1225. options.scrollingSpeed, options.easing).promise().done(function () { //only one single callback in case of animating `html, body`
  1226. if(options.scrollBar){
  1227. /* Hack!
  1228. The timeout prevents setting the most dominant section in the viewport as "active" when the user
  1229. scrolled to a smaller section by using the mousewheel (auto scrolling) rather than draging the scroll bar.
  1230. When using scrollBar:true It seems like the scroll events still getting propagated even after the scrolling animation has finished.
  1231. */
  1232. setTimeout(function(){
  1233. afterSectionLoads(v);
  1234. },30);
  1235. }else{
  1236. afterSectionLoads(v);
  1237. }
  1238. });
  1239. }
  1240. }
  1241. /**
  1242. * Gets the scrolling settings depending on the plugin autoScrolling option
  1243. */
  1244. function getScrollSettings(v){
  1245. var scroll = {};
  1246. if(options.autoScrolling && !options.scrollBar){
  1247. scroll.options = { 'top': -v.dtop};
  1248. scroll.element = WRAPPER_SEL;
  1249. }else{
  1250. scroll.options = { 'scrollTop': v.dtop};
  1251. scroll.element = 'html, body';
  1252. }
  1253. return scroll;
  1254. }
  1255. /**
  1256. * Adds sections before or after the current one to create the infinite effect.
  1257. */
  1258. function createInfiniteSections(v){
  1259. // Scrolling down
  1260. if (!v.isMovementUp) {
  1261. // Move all previous sections to after the active section
  1262. $(SECTION_ACTIVE_SEL).after(v.activeSection.prevAll(SECTION_SEL).get().reverse());
  1263. }
  1264. else { // Scrolling up
  1265. // Move all next sections to before the active section
  1266. $(SECTION_ACTIVE_SEL).before(v.activeSection.nextAll(SECTION_SEL));
  1267. }
  1268. // Maintain the displayed position (now that we changed the element order)
  1269. silentScroll($(SECTION_ACTIVE_SEL).position().top);
  1270. // Maintain the active slides visible in the viewport
  1271. keepSlidesPosition();
  1272. // save for later the elements that still need to be reordered
  1273. v.wrapAroundElements = v.activeSection;
  1274. // Recalculate animation variables
  1275. v.dtop = v.element.position().top;
  1276. v.yMovement = getYmovement(v.element);
  1277. //sections will temporally have another position in the DOM
  1278. //updating this values in case we need them
  1279. v.leavingSection = v.activeSection.index(SECTION_SEL) + 1;
  1280. v.sectionIndex = v.element.index(SECTION_SEL);
  1281. return v;
  1282. }
  1283. /**
  1284. * Fix section order after continuousVertical changes have been animated
  1285. */
  1286. function continuousVerticalFixSectionOrder (v) {
  1287. // If continuousVertical is in effect (and autoScrolling would also be in effect then),
  1288. // finish moving the elements around so the direct navigation will function more simply
  1289. if (!v.wrapAroundElements || !v.wrapAroundElements.length) {
  1290. return;
  1291. }
  1292. if (v.isMovementUp) {
  1293. $(SECTION_FIRST_SEL).before(v.wrapAroundElements);
  1294. }
  1295. else {
  1296. $(SECTION_LAST_SEL).after(v.wrapAroundElements);
  1297. }
  1298. silentScroll($(SECTION_ACTIVE_SEL).position().top);
  1299. // Maintain the active slides visible in the viewport
  1300. keepSlidesPosition();
  1301. }
  1302. /**
  1303. * Actions to do once the section is loaded.
  1304. */
  1305. function afterSectionLoads (v){
  1306. continuousVerticalFixSectionOrder(v);
  1307. //callback (afterLoad) if the site is not just resizing and readjusting the slides
  1308. $.isFunction(options.afterLoad) && !v.localIsResizing && options.afterLoad.call(v.element, v.anchorLink, (v.sectionIndex + 1));
  1309. if(options.scrollOverflow){
  1310. options.scrollOverflowHandler.afterLoad();
  1311. }
  1312. if(!v.localIsResizing){
  1313. playMedia(v.element);
  1314. }
  1315. v.element.addClass(COMPLETELY).siblings().removeClass(COMPLETELY);
  1316. canScroll = true;
  1317. $.isFunction(v.callback) && v.callback.call(this);
  1318. }
  1319. /**
  1320. * Sets the value for the given attribute from the `data-` attribute with the same suffix
  1321. * ie: data-srcset ==> srcset | data-src ==> src
  1322. */
  1323. function setSrc(element, attribute){
  1324. element
  1325. .attr(attribute, element.data(attribute))
  1326. .removeAttr('data-' + attribute);
  1327. }
  1328. /**
  1329. * Lazy loads image, video and audio elements.
  1330. */
  1331. function lazyLoad(destiny){
  1332. if (!options.lazyLoading){
  1333. return;
  1334. }
  1335. var panel = getSlideOrSection(destiny);
  1336. var element;
  1337. panel.find('img[data-src], img[data-srcset], source[data-src], source[data-srcset], video[data-src], audio[data-src], iframe[data-src]').each(function(){
  1338. element = $(this);
  1339. $.each(['src', 'srcset'], function(index, type){
  1340. var attribute = element.attr('data-' + type);
  1341. if(typeof attribute !== 'undefined' && attribute){
  1342. setSrc(element, type);
  1343. }
  1344. });
  1345. if(element.is('source') && !element.closest('picture').length) {
  1346. var typeToPlay = element.closest('video').length ? 'video' : 'audio';
  1347. element.closest(typeToPlay).get(0).load();
  1348. }
  1349. });
  1350. }
  1351. /**
  1352. * Plays video and audio elements.
  1353. */
  1354. function playMedia(destiny){
  1355. var panel = getSlideOrSection(destiny);
  1356. //playing HTML5 media elements
  1357. panel.find('video, audio').each(function(){
  1358. var element = $(this).get(0);
  1359. if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) {
  1360. element.play();
  1361. }
  1362. });
  1363. //youtube videos
  1364. panel.find('iframe[src*="youtube.com/embed/"]').each(function(){
  1365. var element = $(this).get(0);
  1366. if ( element.hasAttribute('data-autoplay') ){
  1367. playYoutube(element);
  1368. }
  1369. //in case the URL was not loaded yet. On page load we need time for the new URL (with the API string) to load.
  1370. element.onload = function() {
  1371. if ( element.hasAttribute('data-autoplay') ){
  1372. playYoutube(element);
  1373. }
  1374. };
  1375. });
  1376. }
  1377. /**
  1378. * Plays a youtube video
  1379. */
  1380. function playYoutube(element){
  1381. element.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1382. }
  1383. /**
  1384. * Stops video and audio elements.
  1385. */
  1386. function stopMedia(destiny){
  1387. var panel = getSlideOrSection(destiny);
  1388. //stopping HTML5 media elements
  1389. panel.find('video, audio').each(function(){
  1390. var element = $(this).get(0);
  1391. if( !element.hasAttribute('data-keepplaying') && typeof element.pause === 'function' ) {
  1392. element.pause();
  1393. }
  1394. });
  1395. //youtube videos
  1396. panel.find('iframe[src*="youtube.com/embed/"]').each(function(){
  1397. var element = $(this).get(0);
  1398. if( /youtube\.com\/embed\//.test($(this).attr('src')) && !element.hasAttribute('data-keepplaying')){
  1399. $(this).get(0).contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*');
  1400. }
  1401. });
  1402. }
  1403. /**
  1404. * Gets the active slide (or section) for the given section
  1405. */
  1406. function getSlideOrSection(destiny){
  1407. var slide = destiny.find(SLIDE_ACTIVE_SEL);
  1408. if( slide.length ) {
  1409. destiny = $(slide);
  1410. }
  1411. return destiny;
  1412. }
  1413. /**
  1414. * Scrolls to the anchor in the URL when loading the site
  1415. */
  1416. function scrollToAnchor(){
  1417. var anchors = getAnchorsURL();
  1418. var sectionAnchor = anchors.section;
  1419. var slideAnchor = anchors.slide;
  1420. if(sectionAnchor){ //if theres any #
  1421. if(options.animateAnchor){
  1422. scrollPageAndSlide(sectionAnchor, slideAnchor);
  1423. }else{
  1424. silentMoveTo(sectionAnchor, slideAnchor);
  1425. }
  1426. }
  1427. }
  1428. /**
  1429. * Detecting any change on the URL to scroll to the given anchor link
  1430. * (a way to detect back history button as we play with the hashes on the URL)
  1431. */
  1432. function hashChangeHandler(){
  1433. if(!isScrolling && !options.lockAnchors){
  1434. var anchors = getAnchorsURL();
  1435. var sectionAnchor = anchors.section;
  1436. var slideAnchor = anchors.slide;
  1437. //when moving to a slide in the first section for the first time (first time to add an anchor to the URL)
  1438. var isFirstSlideMove = (typeof lastScrolledDestiny === 'undefined');
  1439. var isFirstScrollMove = (typeof lastScrolledDestiny === 'undefined' && typeof slideAnchor === 'undefined' && !slideMoving);
  1440. if(sectionAnchor && sectionAnchor.length){
  1441. /*in order to call scrollpage() only once for each destination at a time
  1442. It is called twice for each scroll otherwise, as in case of using anchorlinks `hashChange`
  1443. event is fired on every scroll too.*/
  1444. if ((sectionAnchor && sectionAnchor !== lastScrolledDestiny) && !isFirstSlideMove
  1445. || isFirstScrollMove
  1446. || (!slideMoving && lastScrolledSlide != slideAnchor )){
  1447. scrollPageAndSlide(sectionAnchor, slideAnchor);
  1448. }
  1449. }
  1450. }
  1451. }
  1452. //gets the URL anchors (section and slide)
  1453. function getAnchorsURL(){
  1454. var section;
  1455. var slide;
  1456. var hash = window.location.hash;
  1457. if(hash.length){
  1458. //getting the anchor link in the URL and deleting the `#`
  1459. var anchorsParts = hash.replace('#', '').split('/');
  1460. //using / for visual reasons and not as a section/slide separator #2803
  1461. var isFunkyAnchor = hash.indexOf('#/') > -1;
  1462. section = isFunkyAnchor ? '/' + anchorsParts[1] : decodeURIComponent(anchorsParts[0]);
  1463. var slideAnchor = isFunkyAnchor ? anchorsParts[2] : anchorsParts[1];
  1464. if(slideAnchor && slideAnchor.length){
  1465. slide = decodeURIComponent(slideAnchor);
  1466. }
  1467. }
  1468. return {
  1469. section: section,
  1470. slide: slide
  1471. }
  1472. }
  1473. //Sliding with arrow keys, both, vertical and horizontal
  1474. function keydownHandler(e) {
  1475. clearTimeout(keydownId);
  1476. var activeElement = $(':focus');
  1477. var keyCode = e.which;
  1478. //tab?
  1479. if(keyCode === 9){
  1480. onTab(e);
  1481. }
  1482. else if(!activeElement.is('textarea') && !activeElement.is('input') && !activeElement.is('select') &&
  1483. activeElement.attr('contentEditable') !== "true" && activeElement.attr('contentEditable') !== '' &&
  1484. options.keyboardScrolling && options.autoScrolling){
  1485. //preventing the scroll with arrow keys & spacebar & Page Up & Down keys
  1486. var keyControls = [40, 38, 32, 33, 34];
  1487. if($.inArray(keyCode, keyControls) > -1){
  1488. e.preventDefault();
  1489. }
  1490. controlPressed = e.ctrlKey;
  1491. keydownId = setTimeout(function(){
  1492. onkeydown(e);
  1493. },150);
  1494. }
  1495. }
  1496. function tooltipTextHandler(){
  1497. $(this).prev().trigger('click');
  1498. }
  1499. //to prevent scrolling while zooming
  1500. function keyUpHandler(e){
  1501. if(isWindowFocused){ //the keyup gets fired on new tab ctrl + t in Firefox
  1502. controlPressed = e.ctrlKey;
  1503. }
  1504. }
  1505. //binding the mousemove when the mouse's middle button is released
  1506. function mouseDownHandler(e){
  1507. //middle button
  1508. if (e.which == 2){
  1509. oldPageY = e.pageY;
  1510. container.on('mousemove', mouseMoveHandler);
  1511. }
  1512. }
  1513. //unbinding the mousemove when the mouse's middle button is released
  1514. function mouseUpHandler(e){
  1515. //middle button
  1516. if (e.which == 2){
  1517. container.off('mousemove');
  1518. }
  1519. }
  1520. //Scrolling horizontally when clicking on the slider controls.
  1521. function slideArrowHandler(){
  1522. var section = $(this).closest(SECTION_SEL);
  1523. if ($(this).hasClass(SLIDES_PREV)) {
  1524. if(isScrollAllowed.m.left){
  1525. moveSlideLeft(section);
  1526. }
  1527. } else {
  1528. if(isScrollAllowed.m.right){
  1529. moveSlideRight(section);
  1530. }
  1531. }
  1532. }
  1533. //when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
  1534. function blurHandler(){
  1535. isWindowFocused = false;
  1536. controlPressed = false;
  1537. }
  1538. //Scrolls to the section when clicking the navigation bullet
  1539. function sectionBulletHandler(e){
  1540. e.preventDefault();
  1541. var index = $(this).parent().index();
  1542. scrollPage($(SECTION_SEL).eq(index));
  1543. }
  1544. //Scrolls the slider to the given slide destination for the given section
  1545. function slideBulletHandler(e){
  1546. e.preventDefault();
  1547. var slides = $(this).closest(SECTION_SEL).find(SLIDES_WRAPPER_SEL);
  1548. var destiny = slides.find(SLIDE_SEL).eq($(this).closest('li').index());
  1549. landscapeScroll(slides, destiny);
  1550. }
  1551. /**
  1552. * Keydown event
  1553. */
  1554. function onkeydown(e){
  1555. var shiftPressed = e.shiftKey;
  1556. //do nothing if we can not scroll or we are not using horizotnal key arrows.
  1557. if(!canScroll && [37,39].indexOf(e.which) < 0){
  1558. return;
  1559. }
  1560. switch (e.which) {
  1561. //up
  1562. case 38:
  1563. case 33:
  1564. if(isScrollAllowed.k.up){
  1565. moveSectionUp();
  1566. }
  1567. break;
  1568. //down
  1569. case 32: //spacebar
  1570. if(shiftPressed && isScrollAllowed.k.up){
  1571. moveSectionUp();
  1572. break;
  1573. }
  1574. /* falls through */
  1575. case 40:
  1576. case 34:
  1577. if(isScrollAllowed.k.down){
  1578. moveSectionDown();
  1579. }
  1580. break;
  1581. //Home
  1582. case 36:
  1583. if(isScrollAllowed.k.up){
  1584. moveTo(1);
  1585. }
  1586. break;
  1587. //End
  1588. case 35:
  1589. if(isScrollAllowed.k.down){
  1590. moveTo( $(SECTION_SEL).length );
  1591. }
  1592. break;
  1593. //left
  1594. case 37:
  1595. if(isScrollAllowed.k.left){
  1596. moveSlideLeft();
  1597. }
  1598. break;
  1599. //right
  1600. case 39:
  1601. if(isScrollAllowed.k.right){
  1602. moveSlideRight();
  1603. }
  1604. break;
  1605. default:
  1606. return; // exit this handler for other keys
  1607. }
  1608. }
  1609. /**
  1610. * Makes sure the tab key will only focus elements within the current section/slide
  1611. * preventing this way from breaking the page.
  1612. * Based on "Modals and keyboard traps"
  1613. * from https://developers.google.com/web/fundamentals/accessibility/focus/using-tabindex
  1614. */
  1615. function onTab(e){
  1616. var isShiftPressed = e.shiftKey;
  1617. var activeElement = $(':focus');
  1618. var activeSection = $(SECTION_ACTIVE_SEL);
  1619. var activeSlide = activeSection.find(SLIDE_ACTIVE_SEL);
  1620. var focusableWrapper = activeSlide.length ? activeSlide : activeSection;
  1621. var focusableElements = focusableWrapper.find(focusableElementsString).not('[tabindex="-1"]');
  1622. function preventAndFocusFirst(e){
  1623. e.preventDefault();
  1624. return focusableElements.first().focus();
  1625. }
  1626. //is there an element with focus?
  1627. if(activeElement.length){
  1628. if(!activeElement.closest(SECTION_ACTIVE_SEL, SLIDE_ACTIVE_SEL).length){
  1629. activeElement = preventAndFocusFirst(e);
  1630. }
  1631. }
  1632. //no element if focused? Let's focus the first one of the section/slide
  1633. else{
  1634. preventAndFocusFirst(e);
  1635. }
  1636. //when reached the first or last focusable element of the section/slide
  1637. //we prevent the tab action to keep it in the last focusable element
  1638. if(!isShiftPressed && activeElement.is(focusableElements.last()) ||
  1639. isShiftPressed && activeElement.is(focusableElements.first())
  1640. ){
  1641. e.preventDefault();
  1642. }
  1643. }
  1644. /**
  1645. * Detecting the direction of the mouse movement.
  1646. * Used only for the middle button of the mouse.
  1647. */
  1648. var oldPageY = 0;
  1649. function mouseMoveHandler(e){
  1650. if(canScroll){
  1651. // moving up
  1652. if (e.pageY < oldPageY && isScrollAllowed.m.up){
  1653. moveSectionUp();
  1654. }
  1655. // moving down
  1656. else if(e.pageY > oldPageY && isScrollAllowed.m.down){
  1657. moveSectionDown();
  1658. }
  1659. }
  1660. oldPageY = e.pageY;
  1661. }
  1662. /**
  1663. * Scrolls horizontal sliders.
  1664. */
  1665. function landscapeScroll(slides, destiny, direction){
  1666. var section = slides.closest(SECTION_SEL);
  1667. var v = {
  1668. slides: slides,
  1669. destiny: destiny,
  1670. direction: direction,
  1671. destinyPos: destiny.position(),
  1672. slideIndex: destiny.index(),
  1673. section: section,
  1674. sectionIndex: section.index(SECTION_SEL),
  1675. anchorLink: section.data('anchor'),
  1676. slidesNav: section.find(SLIDES_NAV_SEL),
  1677. slideAnchor: getAnchor(destiny),
  1678. prevSlide: section.find(SLIDE_ACTIVE_SEL),
  1679. prevSlideIndex: section.find(SLIDE_ACTIVE_SEL).index(),
  1680. //caching the value of isResizing at the momment the function is called
  1681. //because it will be checked later inside a setTimeout and the value might change
  1682. localIsResizing: isResizing
  1683. };
  1684. v.xMovement = getXmovement(v.prevSlideIndex, v.slideIndex);
  1685. //important!! Only do it when not resizing
  1686. if(!v.localIsResizing){
  1687. //preventing from scrolling to the next/prev section when using scrollHorizontally
  1688. canScroll = false;
  1689. }
  1690. if(options.onSlideLeave){
  1691. //if the site is not just resizing and readjusting the slides
  1692. if(!v.localIsResizing && v.xMovement!=='none'){
  1693. if($.isFunction( options.onSlideLeave )){
  1694. if(options.onSlideLeave.call( v.prevSlide, v.anchorLink, (v.sectionIndex + 1), v.prevSlideIndex, v.direction, v.slideIndex ) === false){
  1695. slideMoving = false;
  1696. return;
  1697. }
  1698. }
  1699. }
  1700. }
  1701. destiny.addClass(ACTIVE).siblings().removeClass(ACTIVE);
  1702. if(!v.localIsResizing){
  1703. stopMedia(v.prevSlide);
  1704. lazyLoad(destiny);
  1705. }
  1706. if(!options.loopHorizontal && options.controlArrows){
  1707. //hidding it for the fist slide, showing for the rest
  1708. section.find(SLIDES_ARROW_PREV_SEL).toggle(v.slideIndex!==0);
  1709. //hidding it for the last slide, showing for the rest
  1710. section.find(SLIDES_ARROW_NEXT_SEL).toggle(!destiny.is(':last-child'));
  1711. }
  1712. //only changing the URL if the slides are in the current section (not for resize re-adjusting)
  1713. if(section.hasClass(ACTIVE) && !v.localIsResizing){
  1714. setState(v.slideIndex, v.slideAnchor, v.anchorLink, v.sectionIndex);
  1715. }
  1716. performHorizontalMove(slides, v, true);
  1717. }
  1718. function afterSlideLoads(v){
  1719. activeSlidesNavigation(v.slidesNav, v.slideIndex);
  1720. //if the site is not just resizing and readjusting the slides
  1721. if(!v.localIsResizing){
  1722. $.isFunction( options.afterSlideLoad ) && options.afterSlideLoad.call( v.destiny, v.anchorLink, (v.sectionIndex + 1), v.slideAnchor, v.slideIndex);
  1723. //needs to be inside the condition to prevent problems with continuousVertical and scrollHorizontally
  1724. //and to prevent double scroll right after a windows resize
  1725. canScroll = true;
  1726. playMedia(v.destiny);
  1727. }
  1728. //letting them slide again
  1729. slideMoving = false;
  1730. }
  1731. /**
  1732. * Performs the horizontal movement. (CSS3 or jQuery)
  1733. *
  1734. * @param fireCallback {Bool} - determines whether or not to fire the callback
  1735. */
  1736. function performHorizontalMove(slides, v, fireCallback){
  1737. var destinyPos = v.destinyPos;
  1738. if(options.css3){
  1739. var translate3d = 'translate3d(-' + Math.round(destinyPos.left) + 'px, 0px, 0px)';
  1740. addAnimation(slides.find(SLIDES_CONTAINER_SEL)).css(getTransforms(translate3d));
  1741. afterSlideLoadsId = setTimeout(function(){
  1742. fireCallback && afterSlideLoads(v);
  1743. }, options.scrollingSpeed, options.easing);
  1744. }else{
  1745. slides.animate({
  1746. scrollLeft : Math.round(destinyPos.left)
  1747. }, options.scrollingSpeed, options.easing, function() {
  1748. fireCallback && afterSlideLoads(v);
  1749. });
  1750. }
  1751. }
  1752. /**
  1753. * Sets the state for the horizontal bullet navigations.
  1754. */
  1755. function activeSlidesNavigation(slidesNav, slideIndex){
  1756. slidesNav.find(ACTIVE_SEL).removeClass(ACTIVE);
  1757. slidesNav.find('li').eq(slideIndex).find('a').addClass(ACTIVE);
  1758. }
  1759. var previousHeight = windowsHeight;
  1760. //when resizing the site, we adjust the heights of the sections, slimScroll...
  1761. function resizeHandler(){
  1762. //checking if it needs to get responsive
  1763. responsive();
  1764. // rebuild immediately on touch devices
  1765. if (isTouchDevice) {
  1766. var activeElement = $(document.activeElement);
  1767. //if the keyboard is NOT visible
  1768. if (!activeElement.is('textarea') && !activeElement.is('input') && !activeElement.is('select')) {
  1769. var currentHeight = $window.height();
  1770. //making sure the change in the viewport size is enough to force a rebuild. (20 % of the window to avoid problems when hidding scroll bars)
  1771. if( Math.abs(currentHeight - previousHeight) > (20 * Math.max(previousHeight, currentHeight) / 100) ){
  1772. reBuild(true);
  1773. previousHeight = currentHeight;
  1774. }
  1775. }
  1776. }else{
  1777. //in order to call the functions only when the resize is finished
  1778. //http://stackoverflow.com/questions/4298612/jquery-how-to-call-resize-event-only-once-its-finished-resizing
  1779. clearTimeout(resizeId);
  1780. resizeId = setTimeout(function(){
  1781. reBuild(true);
  1782. }, 350);
  1783. }
  1784. }
  1785. /**
  1786. * Checks if the site needs to get responsive and disables autoScrolling if so.
  1787. * A class `fp-responsive` is added to the plugin's container in case the user wants to use it for his own responsive CSS.
  1788. */
  1789. function responsive(){
  1790. var widthLimit = options.responsive || options.responsiveWidth; //backwards compatiblity
  1791. var heightLimit = options.responsiveHeight;
  1792. //only calculating what we need. Remember its called on the resize event.
  1793. var isBreakingPointWidth = widthLimit && $window.outerWidth() < widthLimit;
  1794. var isBreakingPointHeight = heightLimit && $window.height() < heightLimit;
  1795. if(widthLimit && heightLimit){
  1796. setResponsive(isBreakingPointWidth || isBreakingPointHeight);
  1797. }
  1798. else if(widthLimit){
  1799. setResponsive(isBreakingPointWidth);
  1800. }
  1801. else if(heightLimit){
  1802. setResponsive(isBreakingPointHeight);
  1803. }
  1804. }
  1805. /**
  1806. * Adds transition animations for the given element
  1807. */
  1808. function addAnimation(element){
  1809. var transition = 'all ' + options.scrollingSpeed + 'ms ' + options.easingcss3;
  1810. element.removeClass(NO_TRANSITION);
  1811. return element.css({
  1812. '-webkit-transition': transition,
  1813. 'transition': transition
  1814. });
  1815. }
  1816. /**
  1817. * Remove transition animations for the given element
  1818. */
  1819. function removeAnimation(element){
  1820. return element.addClass(NO_TRANSITION);
  1821. }
  1822. /**
  1823. * Activating the vertical navigation bullets according to the given slide name.
  1824. */
  1825. function activateNavDots(name, sectionIndex){
  1826. if(options.navigation){
  1827. $(SECTION_NAV_SEL).find(ACTIVE_SEL).removeClass(ACTIVE);
  1828. if(name){
  1829. $(SECTION_NAV_SEL).find('a[href="#' + name + '"]').addClass(ACTIVE);
  1830. }else{
  1831. $(SECTION_NAV_SEL).find('li').eq(sectionIndex).find('a').addClass(ACTIVE);
  1832. }
  1833. }
  1834. }
  1835. /**
  1836. * Activating the website main menu elements according to the given slide name.
  1837. */
  1838. function activateMenuElement(name){
  1839. if(options.menu){
  1840. $(options.menu).find(ACTIVE_SEL).removeClass(ACTIVE);
  1841. $(options.menu).find('[data-menuanchor="'+name+'"]').addClass(ACTIVE);
  1842. }
  1843. }
  1844. /**
  1845. * Sets to active the current menu and vertical nav items.
  1846. */
  1847. function activateMenuAndNav(anchor, index){
  1848. activateMenuElement(anchor);
  1849. activateNavDots(anchor, index);
  1850. }
  1851. /**
  1852. * Retuns `up` or `down` depending on the scrolling movement to reach its destination
  1853. * from the current section.
  1854. */
  1855. function getYmovement(destiny){
  1856. var fromIndex = $(SECTION_ACTIVE_SEL).index(SECTION_SEL);
  1857. var toIndex = destiny.index(SECTION_SEL);
  1858. if( fromIndex == toIndex){
  1859. return 'none';
  1860. }
  1861. if(fromIndex > toIndex){
  1862. return 'up';
  1863. }
  1864. return 'down';
  1865. }
  1866. /**
  1867. * Retuns `right` or `left` depending on the scrolling movement to reach its destination
  1868. * from the current slide.
  1869. */
  1870. function getXmovement(fromIndex, toIndex){
  1871. if( fromIndex == toIndex){
  1872. return 'none';
  1873. }
  1874. if(fromIndex > toIndex){
  1875. return 'left';
  1876. }
  1877. return 'right';
  1878. }
  1879. function addTableClass(element){
  1880. //In case we are styling for the 2nd time as in with reponsiveSlides
  1881. if(!element.hasClass(TABLE)){
  1882. var wrapper = $('<div class="' + TABLE_CELL + '" />').height(getTableHeight(element));
  1883. element.addClass(TABLE).wrapInner(wrapper);
  1884. }
  1885. }
  1886. function getTableHeight(element){
  1887. var sectionHeight = windowsHeight;
  1888. if(options.paddingTop || options.paddingBottom){
  1889. var section = element;
  1890. if(!section.hasClass(SECTION)){
  1891. section = element.closest(SECTION_SEL);
  1892. }
  1893. var paddings = parseInt(section.css('padding-top')) + parseInt(section.css('padding-bottom'));
  1894. sectionHeight = (windowsHeight - paddings);
  1895. }
  1896. return sectionHeight;
  1897. }
  1898. /**
  1899. * Adds a css3 transform property to the container class with or without animation depending on the animated param.
  1900. */
  1901. function transformContainer(translate3d, animated){
  1902. if(animated){
  1903. addAnimation(container);
  1904. }else{
  1905. removeAnimation(container);
  1906. }
  1907. container.css(getTransforms(translate3d));
  1908. //syncronously removing the class after the animation has been applied.
  1909. setTimeout(function(){
  1910. container.removeClass(NO_TRANSITION);
  1911. },10);
  1912. }
  1913. /**
  1914. * Gets a section by its anchor / index
  1915. */
  1916. function getSectionByAnchor(sectionAnchor){
  1917. var section = container.find(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]');
  1918. if(!section.length){
  1919. var sectionIndex = typeof sectionAnchor !== 'undefined' ? sectionAnchor -1 : 0;
  1920. section = $(SECTION_SEL).eq(sectionIndex);
  1921. }
  1922. return section;
  1923. }
  1924. /**
  1925. * Gets a slide inside a given section by its anchor / index
  1926. */
  1927. function getSlideByAnchor(slideAnchor, section){
  1928. var slide = section.find(SLIDE_SEL + '[data-anchor="'+slideAnchor+'"]');
  1929. if(!slide.length){
  1930. slideAnchor = typeof slideAnchor !== 'undefined' ? slideAnchor : 0;
  1931. slide = section.find(SLIDE_SEL).eq(slideAnchor);
  1932. }
  1933. return slide;
  1934. }
  1935. /**
  1936. * Scrolls to the given section and slide anchors
  1937. */
  1938. function scrollPageAndSlide(sectionAnchor, slideAnchor){
  1939. var section = getSectionByAnchor(sectionAnchor);
  1940. //do nothing if there's no section with the given anchor name
  1941. if(!section.length) return;
  1942. var slide = getSlideByAnchor(slideAnchor, section);
  1943. //we need to scroll to the section and then to the slide
  1944. if (sectionAnchor !== lastScrolledDestiny && !section.hasClass(ACTIVE)){
  1945. scrollPage(section, function(){
  1946. scrollSlider(slide);
  1947. });
  1948. }
  1949. //if we were already in the section
  1950. else{
  1951. scrollSlider(slide);
  1952. }
  1953. }
  1954. /**
  1955. * Scrolls the slider to the given slide destination for the given section
  1956. */
  1957. function scrollSlider(slide){
  1958. if(slide.length){
  1959. landscapeScroll(slide.closest(SLIDES_WRAPPER_SEL), slide);
  1960. }
  1961. }
  1962. /**
  1963. * Creates a landscape navigation bar with dots for horizontal sliders.
  1964. */
  1965. function addSlidesNavigation(section, numSlides){
  1966. section.append('<div class="' + SLIDES_NAV + '"><ul></ul></div>');
  1967. var nav = section.find(SLIDES_NAV_SEL);
  1968. //top or bottom
  1969. nav.addClass(options.slidesNavPosition);
  1970. for(var i=0; i< numSlides; i++){
  1971. nav.find('ul').append('<li><a href="#"><span></span></a></li>');
  1972. }
  1973. //centering it
  1974. nav.css('margin-left', '-' + (nav.width()/2) + 'px');
  1975. nav.find('li').first().find('a').addClass(ACTIVE);
  1976. }
  1977. /**
  1978. * Sets the state of the website depending on the active section/slide.
  1979. * It changes the URL hash when needed and updates the body class.
  1980. */
  1981. function setState(slideIndex, slideAnchor, anchorLink, sectionIndex){
  1982. var sectionHash = '';
  1983. if(options.anchors.length && !options.lockAnchors){
  1984. //isn't it the first slide?
  1985. if(slideIndex){
  1986. if(typeof anchorLink !== 'undefined'){
  1987. sectionHash = anchorLink;
  1988. }
  1989. //slide without anchor link? We take the index instead.
  1990. if(typeof slideAnchor === 'undefined'){
  1991. slideAnchor = slideIndex;
  1992. }
  1993. lastScrolledSlide = slideAnchor;
  1994. setUrlHash(sectionHash + '/' + slideAnchor);
  1995. //first slide won't have slide anchor, just the section one
  1996. }else if(typeof slideIndex !== 'undefined'){
  1997. lastScrolledSlide = slideAnchor;
  1998. setUrlHash(anchorLink);
  1999. }
  2000. //section without slides
  2001. else{
  2002. setUrlHash(anchorLink);
  2003. }
  2004. }
  2005. setBodyClass();
  2006. }
  2007. /**
  2008. * Sets the URL hash.
  2009. */
  2010. function setUrlHash(url){
  2011. if(options.recordHistory){
  2012. location.hash = url;
  2013. }else{
  2014. //Mobile Chrome doesn't work the normal way, so... lets use HTML5 for phones :)
  2015. if(isTouchDevice || isTouch){
  2016. window.history.replaceState(undefined, undefined, '#' + url);
  2017. }else{
  2018. var baseUrl = window.location.href.split('#')[0];
  2019. window.location.replace( baseUrl + '#' + url );
  2020. }
  2021. }
  2022. }
  2023. /**
  2024. * Gets the anchor for the given slide / section. Its index will be used if there's none.
  2025. */
  2026. function getAnchor(element){
  2027. var anchor = element.data('anchor');
  2028. var index = element.index();
  2029. //Slide without anchor link? We take the index instead.
  2030. if(typeof anchor === 'undefined'){
  2031. anchor = index;
  2032. }
  2033. return anchor;
  2034. }
  2035. /**
  2036. * Sets a class for the body of the page depending on the active section / slide
  2037. */
  2038. function setBodyClass(){
  2039. var section = $(SECTION_ACTIVE_SEL);
  2040. var slide = section.find(SLIDE_ACTIVE_SEL);
  2041. var sectionAnchor = getAnchor(section);
  2042. var slideAnchor = getAnchor(slide);
  2043. var text = String(sectionAnchor);
  2044. if(slide.length){
  2045. text = text + '-' + slideAnchor;
  2046. }
  2047. //changing slash for dash to make it a valid CSS style
  2048. text = text.replace('/', '-').replace('#','');
  2049. //removing previous anchor classes
  2050. var classRe = new RegExp('\\b\\s?' + VIEWING_PREFIX + '-[^\\s]+\\b', "g");
  2051. $body[0].className = $body[0].className.replace(classRe, '');
  2052. //adding the current anchor
  2053. $body.addClass(VIEWING_PREFIX + '-' + text);
  2054. }
  2055. /**
  2056. * Checks for translate3d support
  2057. * @return boolean
  2058. * http://stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
  2059. */
  2060. function support3d() {
  2061. var el = document.createElement('p'),
  2062. has3d,
  2063. transforms = {
  2064. 'webkitTransform':'-webkit-transform',
  2065. 'OTransform':'-o-transform',
  2066. 'msTransform':'-ms-transform',
  2067. 'MozTransform':'-moz-transform',
  2068. 'transform':'transform'
  2069. };
  2070. // Add it to the body to get the computed style.
  2071. document.body.insertBefore(el, null);
  2072. for (var t in transforms) {
  2073. if (el.style[t] !== undefined) {
  2074. el.style[t] = 'translate3d(1px,1px,1px)';
  2075. has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
  2076. }
  2077. }
  2078. document.body.removeChild(el);
  2079. return (has3d !== undefined && has3d.length > 0 && has3d !== 'none');
  2080. }
  2081. /**
  2082. * Removes the auto scrolling action fired by the mouse wheel and trackpad.
  2083. * After this function is called, the mousewheel and trackpad movements won't scroll through sections.
  2084. */
  2085. function removeMouseWheelHandler(){
  2086. if (document.addEventListener) {
  2087. document.removeEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
  2088. document.removeEventListener('wheel', MouseWheelHandler, false); //Firefox
  2089. document.removeEventListener('MozMousePixelScroll', MouseWheelHandler, false); //old Firefox
  2090. } else {
  2091. document.detachEvent('onmousewheel', MouseWheelHandler); //IE 6/7/8
  2092. }
  2093. }
  2094. /**
  2095. * Adds the auto scrolling action for the mouse wheel and trackpad.
  2096. * After this function is called, the mousewheel and trackpad movements will scroll through sections
  2097. * https://developer.mozilla.org/en-US/docs/Web/Events/wheel
  2098. */
  2099. function addMouseWheelHandler(){
  2100. var prefix = '';
  2101. var _addEventListener;
  2102. if (window.addEventListener){
  2103. _addEventListener = "addEventListener";
  2104. }else{
  2105. _addEventListener = "attachEvent";
  2106. prefix = 'on';
  2107. }
  2108. // detect available wheel event
  2109. var support = 'onwheel' in document.createElement('div') ? 'wheel' : // Modern browsers support "wheel"
  2110. document.onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least "mousewheel"
  2111. 'DOMMouseScroll'; // let's assume that remaining browsers are older Firefox
  2112. if(support == 'DOMMouseScroll'){
  2113. document[ _addEventListener ](prefix + 'MozMousePixelScroll', MouseWheelHandler, false);
  2114. }
  2115. //handle MozMousePixelScroll in older Firefox
  2116. else{
  2117. document[ _addEventListener ](prefix + support, MouseWheelHandler, false);
  2118. }
  2119. }
  2120. /**
  2121. * Binding the mousemove when the mouse's middle button is pressed
  2122. */
  2123. function addMiddleWheelHandler(){
  2124. container
  2125. .on('mousedown', mouseDownHandler)
  2126. .on('mouseup', mouseUpHandler);
  2127. }
  2128. /**
  2129. * Unbinding the mousemove when the mouse's middle button is released
  2130. */
  2131. function removeMiddleWheelHandler(){
  2132. container
  2133. .off('mousedown', mouseDownHandler)
  2134. .off('mouseup', mouseUpHandler);
  2135. }
  2136. /**
  2137. * Adds the possibility to auto scroll through sections on touch devices.
  2138. */
  2139. function addTouchHandler(){
  2140. if(isTouchDevice || isTouch){
  2141. if(options.autoScrolling){
  2142. $body.off(events.touchmove).on(events.touchmove, preventBouncing);
  2143. }
  2144. $(WRAPPER_SEL)
  2145. .off(events.touchstart).on(events.touchstart, touchStartHandler)
  2146. .off(events.touchmove).on(events.touchmove, touchMoveHandler);
  2147. }
  2148. }
  2149. /**
  2150. * Removes the auto scrolling for touch devices.
  2151. */
  2152. function removeTouchHandler(){
  2153. if(isTouchDevice || isTouch){
  2154. if(options.autoScrolling){
  2155. $body.off(events.touchmove);
  2156. }
  2157. $(WRAPPER_SEL)
  2158. .off(events.touchstart)
  2159. .off(events.touchmove);
  2160. }
  2161. }
  2162. /*
  2163. * Returns and object with Microsoft pointers (for IE<11 and for IE >= 11)
  2164. * http://msdn.microsoft.com/en-us/library/ie/dn304886(v=vs.85).aspx
  2165. */
  2166. function getMSPointer(){
  2167. var pointer;
  2168. //IE >= 11 & rest of browsers
  2169. if(window.PointerEvent){
  2170. pointer = { down: 'pointerdown', move: 'pointermove'};
  2171. }
  2172. //IE < 11
  2173. else{
  2174. pointer = { down: 'MSPointerDown', move: 'MSPointerMove'};
  2175. }
  2176. return pointer;
  2177. }
  2178. /**
  2179. * Gets the pageX and pageY properties depending on the browser.
  2180. * https://github.com/alvarotrigo/fullPage.js/issues/194#issuecomment-34069854
  2181. */
  2182. function getEventsPage(e){
  2183. var events = [];
  2184. events.y = (typeof e.pageY !== 'undefined' && (e.pageY || e.pageX) ? e.pageY : e.touches[0].pageY);
  2185. events.x = (typeof e.pageX !== 'undefined' && (e.pageY || e.pageX) ? e.pageX : e.touches[0].pageX);
  2186. //in touch devices with scroll bar, e.pageY is detected, but we have to deal with touch events. #1008
  2187. if(isTouch && isReallyTouch(e) && (options.scrollBar || !options.autoScrolling)){
  2188. events.y = e.touches[0].pageY;
  2189. events.x = e.touches[0].pageX;
  2190. }
  2191. return events;
  2192. }
  2193. /**
  2194. * Slides silently (with no animation) the active slider to the given slide.
  2195. * @param noCallback {bool} true or defined -> no callbacks
  2196. */
  2197. function silentLandscapeScroll(activeSlide, noCallbacks){
  2198. setScrollingSpeed (0, 'internal');
  2199. if(typeof noCallbacks !== 'undefined'){
  2200. //preventing firing callbacks afterSlideLoad etc.
  2201. isResizing = true;
  2202. }
  2203. landscapeScroll(activeSlide.closest(SLIDES_WRAPPER_SEL), activeSlide);
  2204. if(typeof noCallbacks !== 'undefined'){
  2205. isResizing = false;
  2206. }
  2207. setScrollingSpeed(originals.scrollingSpeed, 'internal');
  2208. }
  2209. /**
  2210. * Scrolls silently (with no animation) the page to the given Y position.
  2211. */
  2212. function silentScroll(top){
  2213. // The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
  2214. // that's why we round it to 0.
  2215. var roundedTop = Math.round(top);
  2216. if (options.css3 && options.autoScrolling && !options.scrollBar){
  2217. var translate3d = 'translate3d(0px, -' + roundedTop + 'px, 0px)';
  2218. transformContainer(translate3d, false);
  2219. }
  2220. else if(options.autoScrolling && !options.scrollBar){
  2221. container.css('top', -roundedTop);
  2222. }
  2223. else{
  2224. $htmlBody.scrollTop(roundedTop);
  2225. }
  2226. }
  2227. /**
  2228. * Returns the cross-browser transform string.
  2229. */
  2230. function getTransforms(translate3d){
  2231. return {
  2232. '-webkit-transform': translate3d,
  2233. '-moz-transform': translate3d,
  2234. '-ms-transform':translate3d,
  2235. 'transform': translate3d
  2236. };
  2237. }
  2238. /**
  2239. * Allowing or disallowing the mouse/swipe scroll in a given direction. (not for keyboard)
  2240. * @type m (mouse) or k (keyboard)
  2241. */
  2242. function setIsScrollAllowed(value, direction, type){
  2243. //up, down, left, right
  2244. if(direction !== 'all'){
  2245. isScrollAllowed[type][direction] = value;
  2246. }
  2247. //all directions?
  2248. else{
  2249. $.each(Object.keys(isScrollAllowed[type]), function(index, key){
  2250. isScrollAllowed[type][key] = value;
  2251. });
  2252. }
  2253. }
  2254. /*
  2255. * Destroys fullpage.js plugin events and optinally its html markup and styles
  2256. */
  2257. function destroy(all){
  2258. setAutoScrolling(false, 'internal');
  2259. setAllowScrolling(false);
  2260. setKeyboardScrolling(false);
  2261. container.addClass(DESTROYED);
  2262. clearTimeout(afterSlideLoadsId);
  2263. clearTimeout(afterSectionLoadsId);
  2264. clearTimeout(resizeId);
  2265. clearTimeout(scrollId);
  2266. clearTimeout(scrollId2);
  2267. $window
  2268. .off('scroll', scrollHandler)
  2269. .off('hashchange', hashChangeHandler)
  2270. .off('resize', resizeHandler);
  2271. $document
  2272. .off('keydown', keydownHandler)
  2273. .off('keyup', keyUpHandler)
  2274. .off('click touchstart', SECTION_NAV_SEL + ' a')
  2275. .off('mouseenter', SECTION_NAV_SEL + ' li')
  2276. .off('mouseleave', SECTION_NAV_SEL + ' li')
  2277. .off('click touchstart', SLIDES_NAV_LINK_SEL)
  2278. .off('mouseover', options.normalScrollElements)
  2279. .off('mouseout', options.normalScrollElements);
  2280. $(SECTION_SEL)
  2281. .off('click touchstart', SLIDES_ARROW_SEL);
  2282. clearTimeout(afterSlideLoadsId);
  2283. clearTimeout(afterSectionLoadsId);
  2284. //lets make a mess!
  2285. if(all){
  2286. destroyStructure();
  2287. }
  2288. }
  2289. /*
  2290. * Removes inline styles added by fullpage.js
  2291. */
  2292. function destroyStructure(){
  2293. //reseting the `top` or `translate` properties to 0
  2294. silentScroll(0);
  2295. //loading all the lazy load content
  2296. container.find('img[data-src], source[data-src], audio[data-src], iframe[data-src]').each(function(){
  2297. setSrc($(this), 'src');
  2298. });
  2299. container.find('img[data-srcset]').each(function(){
  2300. setSrc($(this), 'srcset');
  2301. });
  2302. $(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL).remove();
  2303. //removing inline styles
  2304. $(SECTION_SEL).css( {
  2305. 'height': '',
  2306. 'background-color' : '',
  2307. 'padding': ''
  2308. });
  2309. $(SLIDE_SEL).css( {
  2310. 'width': ''
  2311. });
  2312. container.css({
  2313. 'height': '',
  2314. 'position': '',
  2315. '-ms-touch-action': '',
  2316. 'touch-action': ''
  2317. });
  2318. $htmlBody.css({
  2319. 'overflow': '',
  2320. 'height': ''
  2321. });
  2322. // remove .fp-enabled class
  2323. $('html').removeClass(ENABLED);
  2324. // remove .fp-responsive class
  2325. $body.removeClass(RESPONSIVE);
  2326. // remove all of the .fp-viewing- classes
  2327. $.each($body.get(0).className.split(/\s+/), function (index, className) {
  2328. if (className.indexOf(VIEWING_PREFIX) === 0) {
  2329. $body.removeClass(className);
  2330. }
  2331. });
  2332. //removing added classes
  2333. $(SECTION_SEL + ', ' + SLIDE_SEL).each(function(){
  2334. if(options.scrollOverflowHandler){
  2335. options.scrollOverflowHandler.remove($(this));
  2336. }
  2337. $(this).removeClass(TABLE + ' ' + ACTIVE);
  2338. $(this).attr('style', $(this).data('fp-styles'));
  2339. });
  2340. removeAnimation(container);
  2341. //Unwrapping content
  2342. container.find(TABLE_CELL_SEL + ', ' + SLIDES_CONTAINER_SEL + ', ' + SLIDES_WRAPPER_SEL).each(function(){
  2343. //unwrap not being use in case there's no child element inside and its just text
  2344. $(this).replaceWith(this.childNodes);
  2345. });
  2346. //removing the applied transition from the fullpage wrapper
  2347. container.css({
  2348. '-webkit-transition': 'none',
  2349. 'transition': 'none'
  2350. });
  2351. //scrolling the page to the top with no animation
  2352. $htmlBody.scrollTop(0);
  2353. //removing selectors
  2354. var usedSelectors = [SECTION, SLIDE, SLIDES_CONTAINER];
  2355. $.each(usedSelectors, function(index, value){
  2356. $('.' + value).removeClass(value);
  2357. });
  2358. }
  2359. /*
  2360. * Sets the state for a variable with multiple states (original, and temporal)
  2361. * Some variables such as `autoScrolling` or `recordHistory` might change automatically its state when using `responsive` or `autoScrolling:false`.
  2362. * This function is used to keep track of both states, the original and the temporal one.
  2363. * If type is not 'internal', then we assume the user is globally changing the variable.
  2364. */
  2365. function setVariableState(variable, value, type){
  2366. options[variable] = value;
  2367. if(type !== 'internal'){
  2368. originals[variable] = value;
  2369. }
  2370. }
  2371. /**
  2372. * Displays warnings
  2373. */
  2374. function displayWarnings(){
  2375. var extensions = ['fadingEffect', 'continuousHorizontal', 'scrollHorizontally', 'interlockedSlides', 'resetSliders', 'responsiveSlides', 'offsetSections', 'dragAndMove', 'scrollOverflowReset', 'parallax'];
  2376. if($('html').hasClass(ENABLED)){
  2377. showError('error', 'Fullpage.js can only be initialized once and you are doing it multiple times!');
  2378. return;
  2379. }
  2380. // Disable mutually exclusive settings
  2381. if (options.continuousVertical &&
  2382. (options.loopTop || options.loopBottom)) {
  2383. options.continuousVertical = false;
  2384. showError('warn', 'Option `loopTop/loopBottom` is mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
  2385. }
  2386. if(options.scrollBar && options.scrollOverflow){
  2387. showError('warn', 'Option `scrollBar` is mutually exclusive with `scrollOverflow`. Sections with scrollOverflow might not work well in Firefox');
  2388. }
  2389. if(options.continuousVertical && (options.scrollBar || !options.autoScrolling)){
  2390. options.continuousVertical = false;
  2391. showError('warn', 'Scroll bars (`scrollBar:true` or `autoScrolling:false`) are mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
  2392. }
  2393. if(options.scrollOverflow && !options.scrollOverflowHandler){
  2394. options.scrollOverflow = false;
  2395. showError('error', 'The option `scrollOverflow:true` requires the file `scrolloverflow.min.js`. Please include it before fullPage.js.');
  2396. }
  2397. //using extensions? Wrong file!
  2398. $.each(extensions, function(index, extension){
  2399. //is the option set to true?
  2400. if(options[extension]){
  2401. showError('warn', 'fullpage.js extensions require jquery.fullpage.extensions.min.js file instead of the usual jquery.fullpage.js. Requested: '+ extension);
  2402. }
  2403. });
  2404. //anchors can not have the same value as any element ID or NAME
  2405. $.each(options.anchors, function(index, name){
  2406. //case insensitive selectors (http://stackoverflow.com/a/19465187/1081396)
  2407. var nameAttr = $document.find('[name]').filter(function() {
  2408. return $(this).attr('name') && $(this).attr('name').toLowerCase() == name.toLowerCase();
  2409. });
  2410. var idAttr = $document.find('[id]').filter(function() {
  2411. return $(this).attr('id') && $(this).attr('id').toLowerCase() == name.toLowerCase();
  2412. });
  2413. if(idAttr.length || nameAttr.length ){
  2414. showError('error', 'data-anchor tags can not have the same value as any `id` element on the site (or `name` element for IE).');
  2415. idAttr.length && showError('error', '"' + name + '" is is being used by another element `id` property');
  2416. nameAttr.length && showError('error', '"' + name + '" is is being used by another element `name` property');
  2417. }
  2418. });
  2419. }
  2420. /**
  2421. * Shows a message in the console of the given type.
  2422. */
  2423. function showError(type, text){
  2424. console && console[type] && console[type]('fullPage: ' + text);
  2425. }
  2426. }; //end of $.fn.fullpage
  2427. });