fullpage.js 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918
  1. /*!
  2. * fullPage 3.0.3
  3. * https://github.com/alvarotrigo/fullPage.js
  4. *
  5. * @license GPLv3 for open source use only
  6. * or Fullpage Commercial License for commercial use
  7. * http://alvarotrigo.com/fullPage/pricing/
  8. *
  9. * Copyright (C) 2018 http://alvarotrigo.com/fullPage - A project by Alvaro Trigo
  10. */
  11. (function( root, window, document, factory, undefined) {
  12. if( typeof define === 'function' && define.amd ) {
  13. // AMD. Register as an anonymous module.
  14. define( function() {
  15. root.fullpage = factory(window, document);
  16. return root.fullpage;
  17. } );
  18. } else if( typeof exports === 'object' ) {
  19. // Node. Does not work with strict CommonJS.
  20. module.exports = factory(window, document);
  21. } else {
  22. // Browser globals.
  23. window.fullpage = factory(window, document);
  24. }
  25. }(this, window, document, function(window, document){
  26. 'use strict';
  27. // keeping central set of classnames and selectors
  28. var WRAPPER = 'fullpage-wrapper';
  29. var WRAPPER_SEL = '.' + WRAPPER;
  30. // slimscroll
  31. var SCROLLABLE = 'fp-scrollable';
  32. var SCROLLABLE_SEL = '.' + SCROLLABLE;
  33. // util
  34. var RESPONSIVE = 'fp-responsive';
  35. var NO_TRANSITION = 'fp-notransition';
  36. var DESTROYED = 'fp-destroyed';
  37. var ENABLED = 'fp-enabled';
  38. var VIEWING_PREFIX = 'fp-viewing';
  39. var ACTIVE = 'active';
  40. var ACTIVE_SEL = '.' + ACTIVE;
  41. var COMPLETELY = 'fp-completely';
  42. var COMPLETELY_SEL = '.' + COMPLETELY;
  43. // section
  44. var SECTION_DEFAULT_SEL = '.section';
  45. var SECTION = 'fp-section';
  46. var SECTION_SEL = '.' + SECTION;
  47. var SECTION_ACTIVE_SEL = SECTION_SEL + ACTIVE_SEL;
  48. var TABLE_CELL = 'fp-tableCell';
  49. var TABLE_CELL_SEL = '.' + TABLE_CELL;
  50. var AUTO_HEIGHT = 'fp-auto-height';
  51. var AUTO_HEIGHT_SEL = '.' + AUTO_HEIGHT;
  52. var NORMAL_SCROLL = 'fp-normal-scroll';
  53. var NORMAL_SCROLL_SEL = '.' + NORMAL_SCROLL;
  54. // section nav
  55. var SECTION_NAV = 'fp-nav';
  56. var SECTION_NAV_SEL = '#' + SECTION_NAV;
  57. var SECTION_NAV_TOOLTIP = 'fp-tooltip';
  58. var SECTION_NAV_TOOLTIP_SEL='.'+SECTION_NAV_TOOLTIP;
  59. var SHOW_ACTIVE_TOOLTIP = 'fp-show-active';
  60. // slide
  61. var SLIDE_DEFAULT_SEL = '.slide';
  62. var SLIDE = 'fp-slide';
  63. var SLIDE_SEL = '.' + SLIDE;
  64. var SLIDE_ACTIVE_SEL = SLIDE_SEL + ACTIVE_SEL;
  65. var SLIDES_WRAPPER = 'fp-slides';
  66. var SLIDES_WRAPPER_SEL = '.' + SLIDES_WRAPPER;
  67. var SLIDES_CONTAINER = 'fp-slidesContainer';
  68. var SLIDES_CONTAINER_SEL = '.' + SLIDES_CONTAINER;
  69. var TABLE = 'fp-table';
  70. // slide nav
  71. var SLIDES_NAV = 'fp-slidesNav';
  72. var SLIDES_NAV_SEL = '.' + SLIDES_NAV;
  73. var SLIDES_NAV_LINK_SEL = SLIDES_NAV_SEL + ' a';
  74. var SLIDES_ARROW = 'fp-controlArrow';
  75. var SLIDES_ARROW_SEL = '.' + SLIDES_ARROW;
  76. var SLIDES_PREV = 'fp-prev';
  77. var SLIDES_PREV_SEL = '.' + SLIDES_PREV;
  78. var SLIDES_ARROW_PREV = SLIDES_ARROW + ' ' + SLIDES_PREV;
  79. var SLIDES_ARROW_PREV_SEL = SLIDES_ARROW_SEL + SLIDES_PREV_SEL;
  80. var SLIDES_NEXT = 'fp-next';
  81. var SLIDES_NEXT_SEL = '.' + SLIDES_NEXT;
  82. var SLIDES_ARROW_NEXT = SLIDES_ARROW + ' ' + SLIDES_NEXT;
  83. var SLIDES_ARROW_NEXT_SEL = SLIDES_ARROW_SEL + SLIDES_NEXT_SEL;
  84. function initialise(containerSelector, options) {
  85. var isLicenseValid = options && new RegExp('([\\d\\w]{8}-){3}[\\d\\w]{8}|OPEN-SOURCE-GPLV3-LICENSE').test(options.licenseKey) || document.domain.indexOf('alvarotrigo.com') > -1;
  86. //only once my friend!
  87. if(hasClass($('html'), ENABLED)){ displayWarnings(); return; }
  88. // common jQuery objects
  89. var $htmlBody = $('html, body');
  90. var $body = $('body')[0];
  91. var FP = {};
  92. // Creating some defaults, extending them with any options that were provided
  93. options = deepExtend({
  94. //navigation
  95. menu: false,
  96. anchors:[],
  97. lockAnchors: false,
  98. navigation: false,
  99. navigationPosition: 'right',
  100. navigationTooltips: [],
  101. showActiveTooltip: false,
  102. slidesNavigation: false,
  103. slidesNavPosition: 'bottom',
  104. scrollBar: false,
  105. hybrid: false,
  106. //scrolling
  107. css3: true,
  108. scrollingSpeed: 700,
  109. autoScrolling: true,
  110. fitToSection: true,
  111. fitToSectionDelay: 1000,
  112. easing: 'easeInOutCubic',
  113. easingcss3: 'ease',
  114. loopBottom: false,
  115. loopTop: false,
  116. loopHorizontal: true,
  117. continuousVertical: false,
  118. continuousHorizontal: false,
  119. scrollHorizontally: false,
  120. interlockedSlides: false,
  121. dragAndMove: false,
  122. offsetSections: false,
  123. resetSliders: false,
  124. fadingEffect: false,
  125. normalScrollElements: null,
  126. scrollOverflow: false,
  127. scrollOverflowReset: false,
  128. scrollOverflowHandler: window.fp_scrolloverflow ? window.fp_scrolloverflow.iscrollHandler : null,
  129. scrollOverflowOptions: null,
  130. touchSensitivity: 5,
  131. normalScrollElementTouchThreshold: 5,
  132. bigSectionsDestination: null,
  133. //Accessibility
  134. keyboardScrolling: true,
  135. animateAnchor: true,
  136. recordHistory: true,
  137. //design
  138. controlArrows: true,
  139. controlArrowColor: '#fff',
  140. verticalCentered: true,
  141. sectionsColor : [],
  142. paddingTop: 0,
  143. paddingBottom: 0,
  144. fixedElements: null,
  145. responsive: 0, //backwards compabitility with responsiveWiddth
  146. responsiveWidth: 0,
  147. responsiveHeight: 0,
  148. responsiveSlides: false,
  149. parallax: false,
  150. parallaxOptions: {
  151. type: 'reveal',
  152. percentage: 62,
  153. property: 'translate'
  154. },
  155. //Custom selectors
  156. sectionSelector: SECTION_DEFAULT_SEL,
  157. slideSelector: SLIDE_DEFAULT_SEL,
  158. //events
  159. v2compatible: false,
  160. afterLoad: null,
  161. onLeave: null,
  162. afterRender: null,
  163. afterResize: null,
  164. afterReBuild: null,
  165. afterSlideLoad: null,
  166. onSlideLeave: null,
  167. afterResponsive: null,
  168. lazyLoading: true
  169. }, options);
  170. //flag to avoid very fast sliding for landscape sliders
  171. var slideMoving = false;
  172. var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
  173. var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
  174. var container = typeof containerSelector === 'string' ? $(containerSelector)[0] : containerSelector;
  175. var windowsHeight = getWindowHeight();
  176. var isResizing = false;
  177. var isWindowFocused = true;
  178. var lastScrolledDestiny;
  179. var lastScrolledSlide;
  180. var canScroll = true;
  181. var scrollings = [];
  182. var controlPressed;
  183. var startingSection;
  184. var isScrollAllowed = {};
  185. isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
  186. isScrollAllowed.k = deepExtend({}, isScrollAllowed.m);
  187. var MSPointer = getMSPointer();
  188. var events = {
  189. touchmove: 'ontouchmove' in window ? 'touchmove' : MSPointer.move,
  190. touchstart: 'ontouchstart' in window ? 'touchstart' : MSPointer.down
  191. };
  192. var scrollBarHandler;
  193. // taken from https://github.com/udacity/ud891/blob/gh-pages/lesson2-focus/07-modals-and-keyboard-traps/solution/modal.js
  194. var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
  195. //timeouts
  196. var resizeId;
  197. var afterSectionLoadsId;
  198. var afterSlideLoadsId;
  199. var scrollId;
  200. var scrollId2;
  201. var keydownId;
  202. var originals = deepExtend({}, options); //deep copy
  203. var activeAnimation;
  204. displayWarnings();
  205. //easeInOutCubic animation included in the plugin
  206. window.fp_easings = deepExtend(window.fp_easings, {
  207. easeInOutCubic: function (t, b, c, d) {
  208. if ((t/=d/2) < 1) return c/2*t*t*t + b;return c/2*((t-=2)*t*t + 2) + b;
  209. }
  210. });
  211. /**
  212. * Sets the autoScroll option.
  213. * It changes the scroll bar visibility and the history of the site as a result.
  214. */
  215. function setAutoScrolling(value, type){
  216. //removing the transformation
  217. if(!value){
  218. silentScroll(0);
  219. }
  220. setVariableState('autoScrolling', value, type);
  221. var element = $(SECTION_ACTIVE_SEL)[0];
  222. if(options.autoScrolling && !options.scrollBar){
  223. css($htmlBody, {
  224. 'overflow': 'hidden',
  225. 'height': '100%'
  226. });
  227. setRecordHistory(originals.recordHistory, 'internal');
  228. //for IE touch devices
  229. css(container, {
  230. '-ms-touch-action': 'none',
  231. 'touch-action': 'none'
  232. });
  233. if(element != null){
  234. //moving the container up
  235. silentScroll(element.offsetTop);
  236. }
  237. }else{
  238. css($htmlBody, {
  239. 'overflow' : 'visible',
  240. 'height' : 'initial'
  241. });
  242. setRecordHistory(false, 'internal');
  243. //for IE touch devices
  244. css(container, {
  245. '-ms-touch-action': '',
  246. 'touch-action': ''
  247. });
  248. //scrolling the page to the section with no animation
  249. if (element != null) {
  250. var scrollSettings = getScrollSettings(element.offsetTop);
  251. scrollSettings.element.scrollTo(0, scrollSettings.options);
  252. }
  253. }
  254. }
  255. /**
  256. * Defines wheter to record the history for each hash change in the URL.
  257. */
  258. function setRecordHistory(value, type){
  259. setVariableState('recordHistory', value, type);
  260. }
  261. /**
  262. * Defines the scrolling speed
  263. */
  264. function setScrollingSpeed(value, type){
  265. setVariableState('scrollingSpeed', value, type);
  266. }
  267. /**
  268. * Sets fitToSection
  269. */
  270. function setFitToSection(value, type){
  271. setVariableState('fitToSection', value, type);
  272. }
  273. /**
  274. * Sets lockAnchors
  275. */
  276. function setLockAnchors(value){
  277. options.lockAnchors = value;
  278. }
  279. /**
  280. * Adds or remove the possibility of scrolling through sections by using the mouse wheel or the trackpad.
  281. */
  282. function setMouseWheelScrolling(value){
  283. if(value){
  284. addMouseWheelHandler();
  285. addMiddleWheelHandler();
  286. }else{
  287. removeMouseWheelHandler();
  288. removeMiddleWheelHandler();
  289. }
  290. }
  291. /**
  292. * Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures.
  293. * Optionally a second parameter can be used to specify the direction for which the action will be applied.
  294. *
  295. * @param directions string containing the direction or directions separated by comma.
  296. */
  297. function setAllowScrolling(value, directions){
  298. if(typeof directions !== 'undefined'){
  299. directions = directions.replace(/ /g,'').split(',');
  300. directions.forEach(function (direction){
  301. setIsScrollAllowed(value, direction, 'm');
  302. });
  303. }
  304. else{
  305. setIsScrollAllowed(value, 'all', 'm');
  306. }
  307. }
  308. /**
  309. * Adds or remove the mouse wheel hijacking
  310. */
  311. function setMouseHijack(value){
  312. if(value){
  313. setMouseWheelScrolling(true);
  314. addTouchHandler();
  315. }else{
  316. setMouseWheelScrolling(false);
  317. removeTouchHandler();
  318. }
  319. }
  320. /**
  321. * Adds or remove the possibility of scrolling through sections by using the keyboard arrow keys
  322. */
  323. function setKeyboardScrolling(value, directions){
  324. if(typeof directions !== 'undefined'){
  325. directions = directions.replace(/ /g,'').split(',');
  326. directions.forEach(function(direction){
  327. setIsScrollAllowed(value, direction, 'k');
  328. });
  329. }else{
  330. setIsScrollAllowed(value, 'all', 'k');
  331. options.keyboardScrolling = value;
  332. }
  333. }
  334. /**
  335. * Moves the page up one section.
  336. */
  337. function moveSectionUp(){
  338. var prev = prevUntil($(SECTION_ACTIVE_SEL)[0], SECTION_SEL);
  339. //looping to the bottom if there's no more sections above
  340. if (!prev && (options.loopTop || options.continuousVertical)) {
  341. prev = last($(SECTION_SEL));
  342. }
  343. if (prev != null) {
  344. scrollPage(prev, null, true);
  345. }
  346. }
  347. /**
  348. * Moves the page down one section.
  349. */
  350. function moveSectionDown(){
  351. var next = nextUntil($(SECTION_ACTIVE_SEL)[0], SECTION_SEL);
  352. //looping to the top if there's no more sections below
  353. if(!next &&
  354. (options.loopBottom || options.continuousVertical)){
  355. next = $(SECTION_SEL)[0];
  356. }
  357. if(next != null){
  358. scrollPage(next, null, false);
  359. }
  360. }
  361. /**
  362. * Moves the page to the given section and slide with no animation.
  363. * Anchors or index positions can be used as params.
  364. */
  365. function silentMoveTo(sectionAnchor, slideAnchor){
  366. setScrollingSpeed (0, 'internal');
  367. moveTo(sectionAnchor, slideAnchor);
  368. setScrollingSpeed (originals.scrollingSpeed, 'internal');
  369. }
  370. /**
  371. * Moves the page to the given section and slide.
  372. * Anchors or index positions can be used as params.
  373. */
  374. function moveTo(sectionAnchor, slideAnchor){
  375. var destiny = getSectionByAnchor(sectionAnchor);
  376. if (typeof slideAnchor !== 'undefined'){
  377. scrollPageAndSlide(sectionAnchor, slideAnchor);
  378. }else if(destiny != null){
  379. scrollPage(destiny);
  380. }
  381. }
  382. /**
  383. * Slides right the slider of the active section.
  384. * Optional `section` param.
  385. */
  386. function moveSlideRight(section){
  387. moveSlide('right', section);
  388. }
  389. /**
  390. * Slides left the slider of the active section.
  391. * Optional `section` param.
  392. */
  393. function moveSlideLeft(section){
  394. moveSlide('left', section);
  395. }
  396. /**
  397. * When resizing is finished, we adjust the slides sizes and positions
  398. */
  399. function reBuild(resizing){
  400. if(hasClass(container, DESTROYED)){ return; } //nothing to do if the plugin was destroyed
  401. isResizing = true;
  402. windowsHeight = getWindowHeight(); //updating global var
  403. var sections = $(SECTION_SEL);
  404. for (var i = 0; i < sections.length; ++i) {
  405. var section = sections[i];
  406. var slidesWrap = $(SLIDES_WRAPPER_SEL, section)[0];
  407. var slides = $(SLIDE_SEL, section);
  408. //adjusting the height of the table-cell for IE and Firefox
  409. if(options.verticalCentered){
  410. css($(TABLE_CELL_SEL, section), {'height': getTableHeight(section) + 'px'});
  411. }
  412. css(section, {'height': windowsHeight + 'px'});
  413. //adjusting the position fo the FULL WIDTH slides...
  414. if (slides.length > 1) {
  415. landscapeScroll(slidesWrap, $(SLIDE_ACTIVE_SEL, slidesWrap)[0]);
  416. }
  417. }
  418. if(options.scrollOverflow){
  419. scrollBarHandler.createScrollBarForAll();
  420. }
  421. var activeSection = $(SECTION_ACTIVE_SEL)[0];
  422. var sectionIndex = index(activeSection, SECTION_SEL);
  423. //isn't it the first section?
  424. if(sectionIndex){
  425. //adjusting the position for the current section
  426. silentMoveTo(sectionIndex + 1);
  427. }
  428. isResizing = false;
  429. if(isFunction( options.afterResize ) && resizing){
  430. options.afterResize.call(container, window.innerWidth, window.innerHeight);
  431. }
  432. if(isFunction( options.afterReBuild ) && !resizing){
  433. options.afterReBuild.call(container);
  434. }
  435. }
  436. /**
  437. * Turns fullPage.js to normal scrolling mode when the viewport `width` or `height`
  438. * are smaller than the set limit values.
  439. */
  440. function setResponsive(active){
  441. var isResponsive = hasClass($body, RESPONSIVE);
  442. if(active){
  443. if(!isResponsive){
  444. setAutoScrolling(false, 'internal');
  445. setFitToSection(false, 'internal');
  446. hide($(SECTION_NAV_SEL));
  447. addClass($body, RESPONSIVE);
  448. if(isFunction( options.afterResponsive )){
  449. options.afterResponsive.call( container, active);
  450. }
  451. }
  452. }
  453. else if(isResponsive){
  454. setAutoScrolling(originals.autoScrolling, 'internal');
  455. setFitToSection(originals.autoScrolling, 'internal');
  456. show($(SECTION_NAV_SEL));
  457. removeClass($body, RESPONSIVE);
  458. if(isFunction( options.afterResponsive )){
  459. options.afterResponsive.call( container, active);
  460. }
  461. }
  462. }
  463. if(container){
  464. //public functions
  465. FP.version = '3.0.2';
  466. FP.setAutoScrolling = setAutoScrolling;
  467. FP.setRecordHistory = setRecordHistory;
  468. FP.setScrollingSpeed = setScrollingSpeed;
  469. FP.setFitToSection = setFitToSection;
  470. FP.setLockAnchors = setLockAnchors;
  471. FP.setMouseWheelScrolling = setMouseWheelScrolling;
  472. FP.setAllowScrolling = setAllowScrolling;
  473. FP.setKeyboardScrolling = setKeyboardScrolling;
  474. FP.moveSectionUp = moveSectionUp;
  475. FP.moveSectionDown = moveSectionDown;
  476. FP.silentMoveTo = silentMoveTo;
  477. FP.moveTo = moveTo;
  478. FP.moveSlideRight = moveSlideRight;
  479. FP.moveSlideLeft = moveSlideLeft;
  480. FP.fitToSection = fitToSection;
  481. FP.reBuild = reBuild;
  482. FP.setResponsive = setResponsive;
  483. FP.getFullpageData = options;
  484. FP.destroy = destroy;
  485. FP.getActiveSection = getActiveSection;
  486. FP.getActiveSlide = getActiveSlide;
  487. FP.test = {
  488. top: '0px',
  489. translate3d: 'translate3d(0px, 0px, 0px)',
  490. translate3dH: (function(){
  491. var a = [];
  492. for(var i = 0; i < $(options.sectionSelector, container).length; i++){
  493. a.push('translate3d(0px, 0px, 0px)');
  494. }
  495. return a;
  496. })(),
  497. left: (function(){
  498. var a = [];
  499. for(var i = 0; i < $(options.sectionSelector, container).length; i++){
  500. a.push(0);
  501. }
  502. return a;
  503. })(),
  504. options: options,
  505. setAutoScrolling: setAutoScrolling
  506. };
  507. //functions we want to share across files but which are not
  508. //mean to be used on their own by developers
  509. FP.shared = {
  510. afterRenderActions: afterRenderActions
  511. };
  512. window.fullpage_api = FP;
  513. init();
  514. bindEvents();
  515. }
  516. function init(){
  517. //if css3 is not supported, it will use jQuery animations
  518. if(options.css3){
  519. options.css3 = support3d();
  520. }
  521. options.scrollBar = options.scrollBar || options.hybrid;
  522. setOptionsFromDOM();
  523. prepareDom();
  524. setAllowScrolling(true);
  525. setMouseHijack(true);
  526. setAutoScrolling(options.autoScrolling, 'internal');
  527. responsive();
  528. //setting the class for the body element
  529. setBodyClass();
  530. if(document.readyState === 'complete'){
  531. scrollToAnchor();
  532. }
  533. window.addEventListener('load', scrollToAnchor);
  534. }
  535. function bindEvents(){
  536. //when scrolling...
  537. window.addEventListener('scroll', scrollHandler);
  538. //detecting any change on the URL to scroll to the given anchor link
  539. //(a way to detect back history button as we play with the hashes on the URL)
  540. window.addEventListener('hashchange', hashChangeHandler);
  541. //when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
  542. window.addEventListener('blur', blurHandler);
  543. //when resizing the site, we adjust the heights of the sections, slimScroll...
  544. window.addEventListener('resize', resizeHandler);
  545. //Sliding with arrow keys, both, vertical and horizontal
  546. document.addEventListener('keydown', keydownHandler);
  547. //to prevent scrolling while zooming
  548. document.addEventListener('keyup', keyUpHandler);
  549. //Scrolls to the section when clicking the navigation bullet
  550. //simulating the jQuery .on('click') event using delegation
  551. ['click', 'touchstart'].forEach(function(eventName){
  552. document.addEventListener(eventName, delegatedEvents);
  553. });
  554. /**
  555. * Applying normalScroll elements.
  556. * Ignoring the scrolls over the specified selectors.
  557. */
  558. if(options.normalScrollElements){
  559. ['mouseenter', 'touchstart'].forEach(function(eventName){
  560. forMouseLeaveOrTOuch(eventName, false);
  561. });
  562. ['mouseleave', 'touchend'].forEach(function(eventName){
  563. forMouseLeaveOrTOuch(eventName, true);
  564. });
  565. }
  566. }
  567. function delegatedEvents(e){
  568. var target = e.target;
  569. if(target && closest(target, SECTION_NAV_SEL + ' a')){
  570. sectionBulletHandler.call(target, e);
  571. }
  572. else if(matches(target, SECTION_NAV_TOOLTIP_SEL)){
  573. tooltipTextHandler.call(target);
  574. }
  575. else if(matches(target, SLIDES_ARROW_SEL)){
  576. slideArrowHandler.call(target, e);
  577. }
  578. else if(matches(target, SLIDES_NAV_LINK_SEL) || closest(target, SLIDES_NAV_LINK_SEL) != null){
  579. slideBulletHandler.call(target, e);
  580. }
  581. }
  582. function forMouseLeaveOrTOuch(eventName, allowScrolling){
  583. //a way to pass arguments to the onMouseEnterOrLeave function
  584. document['fp_' + eventName] = allowScrolling;
  585. document.addEventListener(eventName, onMouseEnterOrLeave, true); //capturing phase
  586. }
  587. function onMouseEnterOrLeave(e) {
  588. if(e.target == document){
  589. return;
  590. }
  591. var normalSelectors = options.normalScrollElements.split(',');
  592. normalSelectors.forEach(function(normalSelector){
  593. if(matches(e.target, normalSelector)){
  594. setMouseHijack(document['fp_' + e.type]); //e.type = eventName
  595. }
  596. });
  597. }
  598. /**
  599. * Setting options from DOM elements if they are not provided.
  600. */
  601. function setOptionsFromDOM(){
  602. //no anchors option? Checking for them in the DOM attributes
  603. if(!options.anchors.length){
  604. var attrName = '[data-anchor]';
  605. var anchors = $(options.sectionSelector.split(',').join(attrName + ',') + attrName, container);
  606. if(anchors.length){
  607. anchors.forEach(function(item){
  608. options.anchors.push(item.getAttribute('data-anchor').toString());
  609. });
  610. }
  611. }
  612. //no tooltips option? Checking for them in the DOM attributes
  613. if(!options.navigationTooltips.length){
  614. var attrName = '[data-tooltip]';
  615. var tooltips = $(options.sectionSelector.split(',').join(attrName + ',') + attrName, container);
  616. if(tooltips.length){
  617. tooltips.forEach(function(item){
  618. options.navigationTooltips.push(item.getAttribute('data-tooltip').toString());
  619. });
  620. }
  621. }
  622. }
  623. /**
  624. * Works over the DOM structure to set it up for the current fullpage options.
  625. */
  626. function prepareDom(){
  627. css(container, {
  628. 'height': '100%',
  629. 'position': 'relative'
  630. });
  631. //adding a class to recognize the container internally in the code
  632. addClass(container, WRAPPER);
  633. addClass($('html'), ENABLED);
  634. //due to https://github.com/alvarotrigo/fullPage.js/issues/1502
  635. windowsHeight = getWindowHeight();
  636. removeClass(container, DESTROYED); //in case it was destroyed before initializing it again
  637. addInternalSelectors();
  638. var sections = $(SECTION_SEL);
  639. //styling the sections / slides / menu
  640. for(var i = 0; i<sections.length; i++){
  641. var sectionIndex = i;
  642. var section = sections[i];
  643. var slides = $(SLIDE_SEL, section);
  644. var numSlides = slides.length;
  645. //caching the original styles to add them back on destroy('all')
  646. section.setAttribute('data-fp-styles', section.getAttribute('style'));
  647. styleSection(section, sectionIndex);
  648. styleMenu(section, sectionIndex);
  649. // if there's any slide
  650. if (numSlides > 0) {
  651. styleSlides(section, slides, numSlides);
  652. }else{
  653. if(options.verticalCentered){
  654. addTableClass(section);
  655. }
  656. }
  657. }
  658. //fixed elements need to be moved out of the plugin container due to problems with CSS3.
  659. if(options.fixedElements && options.css3){
  660. $(options.fixedElements).forEach(function(item){
  661. $body.appendChild(item);
  662. });
  663. }
  664. //vertical centered of the navigation + active bullet
  665. if(options.navigation){
  666. addVerticalNavigation();
  667. }
  668. enableYoutubeAPI();
  669. if(options.scrollOverflow){
  670. scrollBarHandler = options.scrollOverflowHandler.init(options);
  671. }else{
  672. afterRenderActions();
  673. }
  674. }
  675. /**
  676. * Styles the horizontal slides for a section.
  677. */
  678. function styleSlides(section, slides, numSlides){
  679. var sliderWidth = numSlides * 100;
  680. var slideWidth = 100 / numSlides;
  681. var slidesWrapper = document.createElement('div');
  682. slidesWrapper.className = SLIDES_WRAPPER; //fp-slides
  683. wrapAll(slides, slidesWrapper);
  684. var slidesContainer = document.createElement('div');
  685. slidesContainer.className = SLIDES_CONTAINER; //fp-slidesContainer
  686. wrapAll(slides, slidesContainer);
  687. css($(SLIDES_CONTAINER_SEL, section), {'width': sliderWidth + '%'});
  688. if(numSlides > 1){
  689. if(options.controlArrows){
  690. createSlideArrows(section);
  691. }
  692. if(options.slidesNavigation){
  693. addSlidesNavigation(section, numSlides);
  694. }
  695. }
  696. slides.forEach(function(slide) {
  697. css(slide, {'width': slideWidth + '%'});
  698. if(options.verticalCentered){
  699. addTableClass(slide);
  700. }
  701. });
  702. var startingSlide = $(SLIDE_ACTIVE_SEL, section)[0];
  703. //if the slide won't be an starting point, the default will be the first one
  704. //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.
  705. if( startingSlide != null && (index($(SECTION_ACTIVE_SEL), SECTION_SEL) !== 0 || (index($(SECTION_ACTIVE_SEL), SECTION_SEL) === 0 && index(startingSlide) !== 0))){
  706. silentLandscapeScroll(startingSlide, 'internal');
  707. }else{
  708. addClass(slides[0], ACTIVE);
  709. }
  710. }
  711. /**
  712. * Styling vertical sections
  713. */
  714. function styleSection(section, index){
  715. //if no active section is defined, the 1st one will be the default one
  716. if(!index && $(SECTION_ACTIVE_SEL)[0] == null) {
  717. addClass(section, ACTIVE);
  718. }
  719. startingSection = $(SECTION_ACTIVE_SEL)[0];
  720. css(section, {'height': windowsHeight + 'px'});
  721. if(options.paddingTop){
  722. css(section, {'padding-top': options.paddingTop});
  723. }
  724. if(options.paddingBottom){
  725. css(section, {'padding-bottom': options.paddingBottom});
  726. }
  727. if (typeof options.sectionsColor[index] !== 'undefined') {
  728. css(section, {'background-color': options.sectionsColor[index]});
  729. }
  730. if (typeof options.anchors[index] !== 'undefined') {
  731. section.setAttribute('data-anchor', options.anchors[index]);
  732. }
  733. }
  734. /**
  735. * Sets the data-anchor attributes to the menu elements and activates the current one.
  736. */
  737. function styleMenu(section, index){
  738. if (typeof options.anchors[index] !== 'undefined') {
  739. //activating the menu / nav element on load
  740. if(hasClass(section, ACTIVE)){
  741. activateMenuAndNav(options.anchors[index], index);
  742. }
  743. }
  744. //moving the menu outside the main container if it is inside (avoid problems with fixed positions when using CSS3 tranforms)
  745. if(options.menu && options.css3 && closest($(options.menu)[0], WRAPPER_SEL) != null){
  746. $body.appendChild($(options.menu)[0]);
  747. }
  748. }
  749. /**
  750. * Adds internal classes to be able to provide customizable selectors
  751. * keeping the link with the style sheet.
  752. */
  753. function addInternalSelectors(){
  754. addClass($(options.sectionSelector, container), SECTION);
  755. addClass($(options.slideSelector, container), SLIDE);
  756. }
  757. /**
  758. * Creates the control arrows for the given section
  759. */
  760. function createSlideArrows(section){
  761. var arrows = [createElementFromHTML('<div class="' + SLIDES_ARROW_PREV + '"></div>'), createElementFromHTML('<div class="' + SLIDES_ARROW_NEXT + '"></div>')];
  762. after($(SLIDES_WRAPPER_SEL, section)[0], arrows);
  763. if(options.controlArrowColor !== '#fff'){
  764. css($(SLIDES_ARROW_NEXT_SEL, section), {'border-color': 'transparent transparent transparent '+options.controlArrowColor});
  765. css($(SLIDES_ARROW_PREV_SEL, section), {'border-color': 'transparent '+ options.controlArrowColor + ' transparent transparent'});
  766. }
  767. if(!options.loopHorizontal){
  768. hide($(SLIDES_ARROW_PREV_SEL, section));
  769. }
  770. }
  771. /**
  772. * Creates a vertical navigation bar.
  773. */
  774. function addVerticalNavigation(){
  775. var navigation = document.createElement('div');
  776. navigation.setAttribute('id', SECTION_NAV);
  777. var divUl = document.createElement('ul');
  778. navigation.appendChild(divUl);
  779. appendTo(navigation, $body);
  780. var nav = $(SECTION_NAV_SEL)[0];
  781. addClass(nav, 'fp-' + options.navigationPosition);
  782. if(options.showActiveTooltip){
  783. addClass(nav, SHOW_ACTIVE_TOOLTIP);
  784. }
  785. var li = '';
  786. for (var i = 0; i < $(SECTION_SEL).length; i++) {
  787. var link = '';
  788. if (options.anchors.length) {
  789. link = options.anchors[i];
  790. }
  791. li += '<li><a href="#' + link + '"><span class="fp-sr-only">' + getBulletLinkName(i, 'Section') + '</span><span></span></a>';
  792. // Only add tooltip if needed (defined by user)
  793. var tooltip = options.navigationTooltips[i];
  794. if (typeof tooltip !== 'undefined' && tooltip !== '') {
  795. li += '<div class="' + SECTION_NAV_TOOLTIP + ' fp-' + options.navigationPosition + '">' + tooltip + '</div>';
  796. }
  797. li += '</li>';
  798. }
  799. $('ul', nav)[0].innerHTML = li;
  800. //centering it vertically
  801. css($(SECTION_NAV_SEL), {'margin-top': '-' + ($(SECTION_NAV_SEL)[0].offsetHeight/2) + 'px'});
  802. //activating the current active section
  803. var bullet = $('li', $(SECTION_NAV_SEL)[0])[index($(SECTION_ACTIVE_SEL)[0], SECTION_SEL)];
  804. addClass($('a', bullet), ACTIVE);
  805. }
  806. /**
  807. * Gets the name for screen readers for a section/slide navigation bullet.
  808. */
  809. function getBulletLinkName(i, defaultName){
  810. return options.navigationTooltips[i]
  811. || options.anchors[i]
  812. || defaultName + ' ' + (i+1)
  813. }
  814. /*
  815. * Enables the Youtube videos API so we can control their flow if necessary.
  816. */
  817. function enableYoutubeAPI(){
  818. $('iframe[src*="youtube.com/embed/"]', container).forEach(function(item){
  819. addURLParam(item, 'enablejsapi=1');
  820. });
  821. }
  822. /**
  823. * Adds a new parameter and its value to the `src` of a given element
  824. */
  825. function addURLParam(element, newParam){
  826. var originalSrc = element.getAttribute('src');
  827. element.setAttribute('src', originalSrc + getUrlParamSign(originalSrc) + newParam);
  828. }
  829. /*
  830. * Returns the prefix sign to use for a new parameter in an existen URL.
  831. *
  832. * @return {String} ? | &
  833. */
  834. function getUrlParamSign(url){
  835. return ( !/\?/.test( url ) ) ? '?' : '&';
  836. }
  837. /**
  838. * Actions and callbacks to fire afterRender
  839. */
  840. function afterRenderActions(){
  841. var section = $(SECTION_ACTIVE_SEL)[0];
  842. addClass(section, COMPLETELY);
  843. lazyLoad(section);
  844. playMedia(section);
  845. if(options.scrollOverflow){
  846. options.scrollOverflowHandler.afterLoad();
  847. }
  848. if(isDestinyTheStartingSection() && isFunction(options.afterLoad) ){
  849. fireCallback('afterLoad', {
  850. activeSection: null,
  851. element: section,
  852. direction: null,
  853. //for backwards compatibility callback (to be removed in a future!)
  854. anchorLink: section.getAttribute('data-anchor'),
  855. sectionIndex: index(section, SECTION_SEL)
  856. });
  857. }
  858. if(isFunction(options.afterRender)){
  859. fireCallback('afterRender');
  860. }
  861. }
  862. /**
  863. * Determines if the URL anchor destiny is the starting section (the one using 'active' class before initialization)
  864. */
  865. function isDestinyTheStartingSection(){
  866. var destinationSection = getSectionByAnchor(getAnchorsURL().section);
  867. return !destinationSection || typeof destinationSection !=='undefined' && index(destinationSection) === index(startingSection);
  868. }
  869. var isScrolling = false;
  870. var lastScroll = 0;
  871. //when scrolling...
  872. function scrollHandler(){
  873. var currentSection;
  874. if(!options.autoScrolling || options.scrollBar){
  875. var currentScroll = getScrollTop();
  876. var scrollDirection = getScrollDirection(currentScroll);
  877. var visibleSectionIndex = 0;
  878. var screen_mid = currentScroll + (getWindowHeight() / 2.0);
  879. var isAtBottom = $body.offsetHeight - getWindowHeight() === currentScroll;
  880. var sections = $(SECTION_SEL);
  881. //when using `auto-height` for a small last section it won't be centered in the viewport
  882. if(isAtBottom){
  883. visibleSectionIndex = sections.length - 1;
  884. }
  885. //is at top? when using `auto-height` for a small first section it won't be centered in the viewport
  886. else if(!currentScroll){
  887. visibleSectionIndex = 0;
  888. }
  889. //taking the section which is showing more content in the viewport
  890. else{
  891. for (var i = 0; i < sections.length; ++i) {
  892. var section = sections[i];
  893. // Pick the the last section which passes the middle line of the screen.
  894. if (section.offsetTop <= screen_mid)
  895. {
  896. visibleSectionIndex = i;
  897. }
  898. }
  899. }
  900. if(isCompletelyInViewPort(scrollDirection)){
  901. if(!hasClass($(SECTION_ACTIVE_SEL)[0], COMPLETELY)){
  902. addClass($(SECTION_ACTIVE_SEL)[0], COMPLETELY);
  903. removeClass(siblings($(SECTION_ACTIVE_SEL)[0]), COMPLETELY);
  904. }
  905. }
  906. //geting the last one, the current one on the screen
  907. currentSection = sections[visibleSectionIndex];
  908. //setting the visible section as active when manually scrolling
  909. //executing only once the first time we reach the section
  910. if(!hasClass(currentSection, ACTIVE)){
  911. isScrolling = true;
  912. var leavingSection = $(SECTION_ACTIVE_SEL)[0];
  913. var leavingSectionIndex = index(leavingSection, SECTION_SEL) + 1;
  914. var yMovement = getYmovement(currentSection);
  915. var anchorLink = currentSection.getAttribute('data-anchor');
  916. var sectionIndex = index(currentSection, SECTION_SEL) + 1;
  917. var activeSlide = $(SLIDE_ACTIVE_SEL, currentSection)[0];
  918. var slideIndex;
  919. var slideAnchorLink;
  920. var callbacksParams = {
  921. activeSection: leavingSection,
  922. sectionIndex: sectionIndex -1,
  923. anchorLink: anchorLink,
  924. element: currentSection,
  925. leavingSection: leavingSectionIndex,
  926. direction: yMovement
  927. };
  928. if(activeSlide){
  929. slideAnchorLink = activeSlide.getAttribute('data-anchor');
  930. slideIndex = index(activeSlide);
  931. }
  932. if(canScroll){
  933. addClass(currentSection, ACTIVE);
  934. removeClass(siblings(currentSection), ACTIVE);
  935. if(isFunction( options.onLeave )){
  936. fireCallback('onLeave', callbacksParams);
  937. }
  938. if(isFunction( options.afterLoad )){
  939. fireCallback('afterLoad', callbacksParams);
  940. }
  941. stopMedia(leavingSection);
  942. lazyLoad(currentSection);
  943. playMedia(currentSection);
  944. activateMenuAndNav(anchorLink, sectionIndex - 1);
  945. if(options.anchors.length){
  946. //needed to enter in hashChange event when using the menu with anchor links
  947. lastScrolledDestiny = anchorLink;
  948. }
  949. setState(slideIndex, slideAnchorLink, anchorLink, sectionIndex);
  950. }
  951. //small timeout in order to avoid entering in hashChange event when scrolling is not finished yet
  952. clearTimeout(scrollId);
  953. scrollId = setTimeout(function(){
  954. isScrolling = false;
  955. }, 100);
  956. }
  957. if(options.fitToSection){
  958. //for the auto adjust of the viewport to fit a whole section
  959. clearTimeout(scrollId2);
  960. scrollId2 = setTimeout(function(){
  961. //checking it again in case it changed during the delay
  962. if(options.fitToSection &&
  963. //is the destination element bigger than the viewport?
  964. $(SECTION_ACTIVE_SEL)[0].offsetHeight <= windowsHeight
  965. ){
  966. fitToSection();
  967. }
  968. }, options.fitToSectionDelay);
  969. }
  970. }
  971. }
  972. /**
  973. * Fits the site to the nearest active section
  974. */
  975. function fitToSection(){
  976. //checking fitToSection again in case it was set to false before the timeout delay
  977. if(canScroll){
  978. //allows to scroll to an active section and
  979. //if the section is already active, we prevent firing callbacks
  980. isResizing = true;
  981. scrollPage($(SECTION_ACTIVE_SEL)[0]);
  982. isResizing = false;
  983. }
  984. }
  985. /**
  986. * Determines whether the active section has seen in its whole or not.
  987. */
  988. function isCompletelyInViewPort(movement){
  989. var top = $(SECTION_ACTIVE_SEL)[0].offsetTop;
  990. var bottom = top + getWindowHeight();
  991. if(movement == 'up'){
  992. return bottom >= (getScrollTop() + getWindowHeight());
  993. }
  994. return top <= getScrollTop();
  995. }
  996. /**
  997. * Gets the directon of the the scrolling fired by the scroll event.
  998. */
  999. function getScrollDirection(currentScroll){
  1000. var direction = currentScroll > lastScroll ? 'down' : 'up';
  1001. lastScroll = currentScroll;
  1002. //needed for auto-height sections to determine if we want to scroll to the top or bottom of the destination
  1003. previousDestTop = currentScroll;
  1004. return direction;
  1005. }
  1006. /**
  1007. * Determines the way of scrolling up or down:
  1008. * by 'automatically' scrolling a section or by using the default and normal scrolling.
  1009. */
  1010. function scrolling(type){
  1011. if (!isScrollAllowed.m[type]){
  1012. return;
  1013. }
  1014. var scrollSection = (type === 'down') ? moveSectionDown : moveSectionUp;
  1015. if(options.scrollOverflow){
  1016. var scrollable = options.scrollOverflowHandler.scrollable($(SECTION_ACTIVE_SEL)[0]);
  1017. var check = (type === 'down') ? 'bottom' : 'top';
  1018. if(scrollable != null ){
  1019. //is the scrollbar at the start/end of the scroll?
  1020. if(options.scrollOverflowHandler.isScrolled(check, scrollable)){
  1021. scrollSection();
  1022. }else{
  1023. return true;
  1024. }
  1025. }else{
  1026. // moved up/down
  1027. scrollSection();
  1028. }
  1029. }else{
  1030. // moved up/down
  1031. scrollSection();
  1032. }
  1033. }
  1034. /*
  1035. * Preventing bouncing in iOS #2285
  1036. */
  1037. function preventBouncing(e){
  1038. if(options.autoScrolling && isReallyTouch(e)){
  1039. //preventing the easing on iOS devices
  1040. preventDefault(e);
  1041. }
  1042. }
  1043. var touchStartY = 0;
  1044. var touchStartX = 0;
  1045. var touchEndY = 0;
  1046. var touchEndX = 0;
  1047. /* Detecting touch events
  1048. * As we are changing the top property of the page on scrolling, we can not use the traditional way to detect it.
  1049. * This way, the touchstart and the touch moves shows an small difference between them which is the
  1050. * used one to determine the direction.
  1051. */
  1052. function touchMoveHandler(e){
  1053. var activeSection = closest(e.target, SECTION_SEL);
  1054. // additional: if one of the normalScrollElements isn't within options.normalScrollElementTouchThreshold hops up the DOM chain
  1055. if (isReallyTouch(e) ) {
  1056. if(options.autoScrolling){
  1057. //preventing the easing on iOS devices
  1058. preventDefault(e);
  1059. }
  1060. var touchEvents = getEventsPage(e);
  1061. touchEndY = touchEvents.y;
  1062. touchEndX = touchEvents.x;
  1063. //if movement in the X axys is greater than in the Y and the currect section has slides...
  1064. if ($(SLIDES_WRAPPER_SEL, activeSection).length && Math.abs(touchStartX - touchEndX) > (Math.abs(touchStartY - touchEndY))) {
  1065. //is the movement greater than the minimum resistance to scroll?
  1066. if (!slideMoving && Math.abs(touchStartX - touchEndX) > (window.innerWidth / 100 * options.touchSensitivity)) {
  1067. if (touchStartX > touchEndX) {
  1068. if(isScrollAllowed.m.right){
  1069. moveSlideRight(activeSection); //next
  1070. }
  1071. } else {
  1072. if(isScrollAllowed.m.left){
  1073. moveSlideLeft(activeSection); //prev
  1074. }
  1075. }
  1076. }
  1077. }
  1078. //vertical scrolling (only when autoScrolling is enabled)
  1079. else if(options.autoScrolling && canScroll){
  1080. //is the movement greater than the minimum resistance to scroll?
  1081. if (Math.abs(touchStartY - touchEndY) > (window.innerHeight / 100 * options.touchSensitivity)) {
  1082. if (touchStartY > touchEndY) {
  1083. scrolling('down');
  1084. } else if (touchEndY > touchStartY) {
  1085. scrolling('up');
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. /**
  1092. * As IE >= 10 fires both touch and mouse events when using a mouse in a touchscreen
  1093. * this way we make sure that is really a touch event what IE is detecting.
  1094. */
  1095. function isReallyTouch(e){
  1096. //if is not IE || IE is detecting `touch` or `pen`
  1097. return typeof e.pointerType === 'undefined' || e.pointerType != 'mouse';
  1098. }
  1099. /**
  1100. * Handler for the touch start event.
  1101. */
  1102. function touchStartHandler(e){
  1103. //stopping the auto scroll to adjust to a section
  1104. if(options.fitToSection){
  1105. activeAnimation = false;
  1106. }
  1107. if(isReallyTouch(e)){
  1108. var touchEvents = getEventsPage(e);
  1109. touchStartY = touchEvents.y;
  1110. touchStartX = touchEvents.x;
  1111. }
  1112. }
  1113. /**
  1114. * Gets the average of the last `number` elements of the given array.
  1115. */
  1116. function getAverage(elements, number){
  1117. var sum = 0;
  1118. //taking `number` elements from the end to make the average, if there are not enought, 1
  1119. var lastElements = elements.slice(Math.max(elements.length - number, 1));
  1120. for(var i = 0; i < lastElements.length; i++){
  1121. sum = sum + lastElements[i];
  1122. }
  1123. return Math.ceil(sum/number);
  1124. }
  1125. /**
  1126. * Detecting mousewheel scrolling
  1127. *
  1128. * http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
  1129. * http://www.sitepoint.com/html5-javascript-mouse-wheel/
  1130. */
  1131. var prevTime = new Date().getTime();
  1132. function MouseWheelHandler(e) {
  1133. var curTime = new Date().getTime();
  1134. var isNormalScroll = hasClass($(COMPLETELY_SEL)[0], NORMAL_SCROLL);
  1135. //is scroll allowed?
  1136. if (!isScrollAllowed.m.down && !isScrollAllowed.m.up) {
  1137. preventDefault(e);
  1138. return false;
  1139. }
  1140. //autoscrolling and not zooming?
  1141. if(options.autoScrolling && !controlPressed && !isNormalScroll){
  1142. // cross-browser wheel delta
  1143. e = e || window.event;
  1144. var value = e.wheelDelta || -e.deltaY || -e.detail;
  1145. var delta = Math.max(-1, Math.min(1, value));
  1146. var horizontalDetection = typeof e.wheelDeltaX !== 'undefined' || typeof e.deltaX !== 'undefined';
  1147. var isScrollingVertically = (Math.abs(e.wheelDeltaX) < Math.abs(e.wheelDelta)) || (Math.abs(e.deltaX ) < Math.abs(e.deltaY) || !horizontalDetection);
  1148. //Limiting the array to 150 (lets not waste memory!)
  1149. if(scrollings.length > 149){
  1150. scrollings.shift();
  1151. }
  1152. //keeping record of the previous scrollings
  1153. scrollings.push(Math.abs(value));
  1154. //preventing to scroll the site on mouse wheel when scrollbar is present
  1155. if(options.scrollBar){
  1156. preventDefault(e);
  1157. }
  1158. //time difference between the last scroll and the current one
  1159. var timeDiff = curTime-prevTime;
  1160. prevTime = curTime;
  1161. //haven't they scrolled in a while?
  1162. //(enough to be consider a different scrolling action to scroll another section)
  1163. if(timeDiff > 200){
  1164. //emptying the array, we dont care about old scrollings for our averages
  1165. scrollings = [];
  1166. }
  1167. if(canScroll){
  1168. var averageEnd = getAverage(scrollings, 10);
  1169. var averageMiddle = getAverage(scrollings, 70);
  1170. var isAccelerating = averageEnd >= averageMiddle;
  1171. //to avoid double swipes...
  1172. if(isAccelerating && isScrollingVertically){
  1173. //scrolling down?
  1174. if (delta < 0) {
  1175. scrolling('down');
  1176. //scrolling up?
  1177. }else {
  1178. scrolling('up');
  1179. }
  1180. }
  1181. }
  1182. return false;
  1183. }
  1184. if(options.fitToSection){
  1185. //stopping the auto scroll to adjust to a section
  1186. activeAnimation = false;
  1187. }
  1188. }
  1189. /**
  1190. * Slides a slider to the given direction.
  1191. * Optional `section` param.
  1192. */
  1193. function moveSlide(direction, section){
  1194. var activeSection = section == null ? $(SECTION_ACTIVE_SEL)[0] : section;
  1195. var slides = $(SLIDES_WRAPPER_SEL, activeSection)[0];
  1196. // more than one slide needed and nothing should be sliding
  1197. if (slides == null || slideMoving || $(SLIDE_SEL, slides).length < 2) {
  1198. return;
  1199. }
  1200. var currentSlide = $(SLIDE_ACTIVE_SEL, slides)[0];
  1201. var destiny = null;
  1202. if(direction === 'left'){
  1203. destiny = prevUntil(currentSlide, SLIDE_SEL);
  1204. }else{
  1205. destiny = nextUntil(currentSlide, SLIDE_SEL);
  1206. }
  1207. //isn't there a next slide in the secuence?
  1208. if(destiny == null){
  1209. //respect loopHorizontal settin
  1210. if (!options.loopHorizontal) return;
  1211. var slideSiblings = siblings(currentSlide);
  1212. if(direction === 'left'){
  1213. destiny = slideSiblings[slideSiblings.length - 1]; //last
  1214. }else{
  1215. destiny = slideSiblings[0]; //first
  1216. }
  1217. }
  1218. slideMoving = true && !FP.test.isTesting;
  1219. landscapeScroll(slides, destiny, direction);
  1220. }
  1221. /**
  1222. * Maintains the active slides in the viewport
  1223. * (Because the `scroll` animation might get lost with some actions, such as when using continuousVertical)
  1224. */
  1225. function keepSlidesPosition(){
  1226. var activeSlides = $(SLIDE_ACTIVE_SEL);
  1227. for( var i =0; i<activeSlides.length; i++){
  1228. silentLandscapeScroll(activeSlides[i], 'internal');
  1229. }
  1230. }
  1231. var previousDestTop = 0;
  1232. /**
  1233. * Returns the destination Y position based on the scrolling direction and
  1234. * the height of the section.
  1235. */
  1236. function getDestinationPosition(element){
  1237. var elementHeight = element.offsetHeight;
  1238. var elementTop = element.offsetTop;
  1239. //top of the desination will be at the top of the viewport
  1240. var position = elementTop;
  1241. var isScrollingDown = elementTop > previousDestTop;
  1242. var sectionBottom = position - windowsHeight + elementHeight;
  1243. var bigSectionsDestination = options.bigSectionsDestination;
  1244. //is the destination element bigger than the viewport?
  1245. if(elementHeight > windowsHeight){
  1246. //scrolling up?
  1247. if(!isScrollingDown && !bigSectionsDestination || bigSectionsDestination === 'bottom' ){
  1248. position = sectionBottom;
  1249. }
  1250. }
  1251. //sections equal or smaller than the viewport height && scrolling down? || is resizing and its in the last section
  1252. else if(isScrollingDown || (isResizing && next(element) == null) ){
  1253. //The bottom of the destination will be at the bottom of the viewport
  1254. position = sectionBottom;
  1255. }
  1256. /*
  1257. Keeping record of the last scrolled position to determine the scrolling direction.
  1258. No conventional methods can be used as the scroll bar might not be present
  1259. AND the section might not be active if it is auto-height and didnt reach the middle
  1260. of the viewport.
  1261. */
  1262. previousDestTop = position;
  1263. return position;
  1264. }
  1265. /**
  1266. * Scrolls the site to the given element and scrolls to the slide if a callback is given.
  1267. */
  1268. function scrollPage(element, callback, isMovementUp){
  1269. if(element == null){ return; } //there's no element to scroll, leaving the function
  1270. var dtop = getDestinationPosition(element);
  1271. var slideAnchorLink;
  1272. var slideIndex;
  1273. //local variables
  1274. var v = {
  1275. element: element,
  1276. callback: callback,
  1277. isMovementUp: isMovementUp,
  1278. dtop: dtop,
  1279. yMovement: getYmovement(element),
  1280. anchorLink: element.getAttribute('data-anchor'),
  1281. sectionIndex: index(element, SECTION_SEL),
  1282. activeSlide: $(SLIDE_ACTIVE_SEL, element)[0],
  1283. activeSection: $(SECTION_ACTIVE_SEL)[0],
  1284. leavingSection: index($(SECTION_ACTIVE_SEL), SECTION_SEL) + 1,
  1285. //caching the value of isResizing at the momment the function is called
  1286. //because it will be checked later inside a setTimeout and the value might change
  1287. localIsResizing: isResizing
  1288. };
  1289. //quiting when destination scroll is the same as the current one
  1290. if((v.activeSection == element && !isResizing) || (options.scrollBar && getScrollTop() === v.dtop && !hasClass(element, AUTO_HEIGHT) )){ return; }
  1291. if(v.activeSlide != null){
  1292. slideAnchorLink = v.activeSlide.getAttribute('data-anchor');
  1293. slideIndex = index(v.activeSlide);
  1294. }
  1295. //callback (onLeave) if the site is not just resizing and readjusting the slides
  1296. if(isFunction(options.onLeave) && !v.localIsResizing){
  1297. var direction = v.yMovement;
  1298. //required for continousVertical
  1299. if(typeof isMovementUp !== 'undefined'){
  1300. direction = isMovementUp ? 'up' : 'down';
  1301. }
  1302. //for the callback
  1303. v.direction = direction;
  1304. if(fireCallback('onLeave', v) === false){
  1305. return;
  1306. }
  1307. }
  1308. // If continuousVertical && we need to wrap around
  1309. if (options.autoScrolling && options.continuousVertical && typeof (v.isMovementUp) !== "undefined" &&
  1310. ((!v.isMovementUp && v.yMovement == 'up') || // Intending to scroll down but about to go up or
  1311. (v.isMovementUp && v.yMovement == 'down'))) { // intending to scroll up but about to go down
  1312. v = createInfiniteSections(v);
  1313. }
  1314. //pausing media of the leaving section (if we are not just resizing, as destinatino will be the same one)
  1315. if(!v.localIsResizing){
  1316. stopMedia(v.activeSection);
  1317. }
  1318. if(options.scrollOverflow){
  1319. options.scrollOverflowHandler.beforeLeave();
  1320. }
  1321. addClass(element, ACTIVE);
  1322. removeClass(siblings(element), ACTIVE);
  1323. lazyLoad(element);
  1324. if(options.scrollOverflow){
  1325. options.scrollOverflowHandler.onLeave();
  1326. }
  1327. //preventing from activating the MouseWheelHandler event
  1328. //more than once if the page is scrolling
  1329. canScroll = false || FP.test.isTesting;
  1330. setState(slideIndex, slideAnchorLink, v.anchorLink, v.sectionIndex);
  1331. performMovement(v);
  1332. //flag to avoid callingn `scrollPage()` twice in case of using anchor links
  1333. lastScrolledDestiny = v.anchorLink;
  1334. //avoid firing it twice (as it does also on scroll)
  1335. activateMenuAndNav(v.anchorLink, v.sectionIndex);
  1336. }
  1337. /**
  1338. * Dispatch events & callbacks making sure it does it on the right format, depending on
  1339. * whether v2compatible is being used or not.
  1340. */
  1341. function fireCallback(eventName, v){
  1342. var eventData = getEventData(eventName, v);
  1343. if(!options.v2compatible){
  1344. trigger(container, eventName, eventData);
  1345. if(options[eventName].apply(eventData[Object.keys(eventData)[0]], toArray(eventData)) === false){
  1346. return false;
  1347. }
  1348. }
  1349. else{
  1350. if(options[eventName].apply(eventData[0], eventData.slice(1)) === false){
  1351. return false;
  1352. }
  1353. }
  1354. return true;
  1355. }
  1356. /**
  1357. * Makes sure to only create a Panel object if the element exist
  1358. */
  1359. function nullOrSection(el){
  1360. return el ? new Section(el) : null;
  1361. }
  1362. function nullOrSlide(el){
  1363. return el ? new Slide(el) : null;
  1364. }
  1365. /**
  1366. * Gets the event's data for the given event on the right format. Depending on whether
  1367. * v2compatible is being used or not.
  1368. */
  1369. function getEventData(eventName, v){
  1370. var paramsPerEvent;
  1371. if(!options.v2compatible){
  1372. //using functions to run only the necessary bits within the object
  1373. paramsPerEvent = {
  1374. afterRender: function(){
  1375. return {
  1376. section: nullOrSection($(SECTION_ACTIVE_SEL)[0]),
  1377. slide: nullOrSlide($(SLIDE_ACTIVE_SEL, $(SECTION_ACTIVE_SEL)[0])[0])
  1378. };
  1379. },
  1380. onLeave: function(){
  1381. return {
  1382. origin: nullOrSection(v.activeSection),
  1383. destination: nullOrSection(v.element),
  1384. direction: v.direction
  1385. };
  1386. },
  1387. afterLoad: function(){
  1388. return paramsPerEvent.onLeave();
  1389. },
  1390. afterSlideLoad: function(){
  1391. return {
  1392. section: nullOrSection(v.section),
  1393. origin: nullOrSlide(v.prevSlide),
  1394. destination: nullOrSlide(v.destiny),
  1395. direction: v.direction
  1396. };
  1397. },
  1398. onSlideLeave: function(){
  1399. return paramsPerEvent.afterSlideLoad();
  1400. }
  1401. };
  1402. }
  1403. else{
  1404. paramsPerEvent = {
  1405. afterRender: function(){ return [container]; },
  1406. onLeave: function(){ return [v.activeSection, v.leavingSection, (v.sectionIndex + 1), v.direction]; },
  1407. afterLoad: function(){ return [v.element, v.anchorLink, (v.sectionIndex + 1)]; },
  1408. afterSlideLoad: function(){ return [v.destiny, v.anchorLink, (v.sectionIndex + 1), v.slideAnchor, v.slideIndex]; },
  1409. onSlideLeave: function(){ return [v.prevSlide, v.anchorLink, (v.sectionIndex + 1), v.prevSlideIndex, v.direction, v.slideIndex]; },
  1410. };
  1411. }
  1412. return paramsPerEvent[eventName]();
  1413. }
  1414. /**
  1415. * Performs the vertical movement (by CSS3 or by jQuery)
  1416. */
  1417. function performMovement(v){
  1418. // using CSS3 translate functionality
  1419. if (options.css3 && options.autoScrolling && !options.scrollBar) {
  1420. // The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
  1421. // that's why we round it to 0.
  1422. var translate3d = 'translate3d(0px, -' + Math.round(v.dtop) + 'px, 0px)';
  1423. transformContainer(translate3d, true);
  1424. //even when the scrollingSpeed is 0 there's a little delay, which might cause the
  1425. //scrollingSpeed to change in case of using silentMoveTo();
  1426. if(options.scrollingSpeed){
  1427. clearTimeout(afterSectionLoadsId);
  1428. afterSectionLoadsId = setTimeout(function () {
  1429. afterSectionLoads(v);
  1430. }, options.scrollingSpeed);
  1431. }else{
  1432. afterSectionLoads(v);
  1433. }
  1434. }
  1435. // using JS to animate
  1436. else{
  1437. var scrollSettings = getScrollSettings(v.dtop);
  1438. FP.test.top = -v.dtop + 'px';
  1439. scrollTo(scrollSettings.element, scrollSettings.options, options.scrollingSpeed, function(){
  1440. if(options.scrollBar){
  1441. /* Hack!
  1442. The timeout prevents setting the most dominant section in the viewport as "active" when the user
  1443. scrolled to a smaller section by using the mousewheel (auto scrolling) rather than draging the scroll bar.
  1444. When using scrollBar:true It seems like the scroll events still getting propagated even after the scrolling animation has finished.
  1445. */
  1446. setTimeout(function(){
  1447. afterSectionLoads(v);
  1448. },30);
  1449. }else{
  1450. afterSectionLoads(v);
  1451. }
  1452. });
  1453. }
  1454. }
  1455. /**
  1456. * Gets the scrolling settings depending on the plugin autoScrolling option
  1457. */
  1458. function getScrollSettings(top){
  1459. var scroll = {};
  1460. //top property animation
  1461. if(options.autoScrolling && !options.scrollBar){
  1462. scroll.options = -top;
  1463. scroll.element = $(WRAPPER_SEL)[0];
  1464. }
  1465. //window real scrolling
  1466. else{
  1467. scroll.options = top;
  1468. scroll.element = window;
  1469. }
  1470. return scroll;
  1471. }
  1472. /**
  1473. * Adds sections before or after the current one to create the infinite effect.
  1474. */
  1475. function createInfiniteSections(v){
  1476. // Scrolling down
  1477. if (!v.isMovementUp) {
  1478. // Move all previous sections to after the active section
  1479. after($(SECTION_ACTIVE_SEL)[0], prevAll(v.activeSection, SECTION_SEL).reverse());
  1480. }
  1481. else { // Scrolling up
  1482. // Move all next sections to before the active section
  1483. before($(SECTION_ACTIVE_SEL)[0], nextAll(v.activeSection, SECTION_SEL));
  1484. }
  1485. // Maintain the displayed position (now that we changed the element order)
  1486. silentScroll($(SECTION_ACTIVE_SEL)[0].offsetTop);
  1487. // Maintain the active slides visible in the viewport
  1488. keepSlidesPosition();
  1489. // save for later the elements that still need to be reordered
  1490. v.wrapAroundElements = v.activeSection;
  1491. // Recalculate animation variables
  1492. v.dtop = v.element.offsetTop;
  1493. v.yMovement = getYmovement(v.element);
  1494. //sections will temporally have another position in the DOM
  1495. //updating this values in case we need them
  1496. v.leavingSection = index(v.activeSection, SECTION_SEL) + 1;
  1497. v.sectionIndex = index(v.element, SECTION_SEL);
  1498. return v;
  1499. }
  1500. /**
  1501. * Fix section order after continuousVertical changes have been animated
  1502. */
  1503. function continuousVerticalFixSectionOrder (v) {
  1504. // If continuousVertical is in effect (and autoScrolling would also be in effect then),
  1505. // finish moving the elements around so the direct navigation will function more simply
  1506. if (v.wrapAroundElements == null) {
  1507. return;
  1508. }
  1509. if (v.isMovementUp) {
  1510. before($(SECTION_SEL)[0], v.wrapAroundElements);
  1511. }
  1512. else {
  1513. after($(SECTION_SEL)[$(SECTION_SEL).length-1], v.wrapAroundElements);
  1514. }
  1515. silentScroll($(SECTION_ACTIVE_SEL)[0].offsetTop);
  1516. // Maintain the active slides visible in the viewport
  1517. keepSlidesPosition();
  1518. }
  1519. /**
  1520. * Actions to do once the section is loaded.
  1521. */
  1522. function afterSectionLoads (v){
  1523. continuousVerticalFixSectionOrder(v);
  1524. //callback (afterLoad) if the site is not just resizing and readjusting the slides
  1525. if(isFunction(options.afterLoad) && !v.localIsResizing){
  1526. fireCallback('afterLoad', v);
  1527. }
  1528. if(options.scrollOverflow){
  1529. options.scrollOverflowHandler.afterLoad();
  1530. }
  1531. if(!v.localIsResizing){
  1532. playMedia(v.element);
  1533. }
  1534. addClass(v.element, COMPLETELY);
  1535. removeClass(siblings(v.element), COMPLETELY);
  1536. canScroll = true;
  1537. if(isFunction(v.callback)){
  1538. v.callback();
  1539. }
  1540. }
  1541. /**
  1542. * Sets the value for the given attribute from the `data-` attribute with the same suffix
  1543. * ie: data-srcset ==> srcset | data-src ==> src
  1544. */
  1545. function setSrc(element, attribute){
  1546. element.setAttribute(attribute, element.getAttribute('data-' + attribute));
  1547. element.removeAttribute('data-' + attribute);
  1548. }
  1549. /**
  1550. * Lazy loads image, video and audio elements.
  1551. */
  1552. function lazyLoad(destiny){
  1553. if (!options.lazyLoading){
  1554. return;
  1555. }
  1556. var panel = getSlideOrSection(destiny);
  1557. $('img[data-src], img[data-srcset], source[data-src], source[data-srcset], video[data-src], audio[data-src], iframe[data-src]', panel).forEach(function(element){
  1558. ['src', 'srcset'].forEach(function(type){
  1559. var attribute = element.getAttribute('data-' + type);
  1560. if(attribute != null && attribute){
  1561. setSrc(element, type);
  1562. }
  1563. });
  1564. if(matches(element, 'source')){
  1565. var elementToPlay = closest(element, 'video, audio');
  1566. if(elementToPlay){
  1567. elementToPlay.load();
  1568. }
  1569. }
  1570. });
  1571. }
  1572. /**
  1573. * Plays video and audio elements.
  1574. */
  1575. function playMedia(destiny){
  1576. var panel = getSlideOrSection(destiny);
  1577. //playing HTML5 media elements
  1578. $('video, audio', panel).forEach(function(element){
  1579. if( element.hasAttribute('data-autoplay') && typeof element.play === 'function' ) {
  1580. element.play();
  1581. }
  1582. });
  1583. //youtube videos
  1584. $('iframe[src*="youtube.com/embed/"]', panel).forEach(function(element){
  1585. if ( element.hasAttribute('data-autoplay') ){
  1586. playYoutube(element);
  1587. }
  1588. //in case the URL was not loaded yet. On page load we need time for the new URL (with the API string) to load.
  1589. element.onload = function() {
  1590. if ( element.hasAttribute('data-autoplay') ){
  1591. playYoutube(element);
  1592. }
  1593. };
  1594. });
  1595. }
  1596. /**
  1597. * Plays a youtube video
  1598. */
  1599. function playYoutube(element){
  1600. element.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
  1601. }
  1602. /**
  1603. * Stops video and audio elements.
  1604. */
  1605. function stopMedia(destiny){
  1606. var panel = getSlideOrSection(destiny);
  1607. //stopping HTML5 media elements
  1608. $('video, audio', panel).forEach(function(element){
  1609. if( !element.hasAttribute('data-keepplaying') && typeof element.pause === 'function' ) {
  1610. element.pause();
  1611. }
  1612. });
  1613. //youtube videos
  1614. $('iframe[src*="youtube.com/embed/"]', panel).forEach(function(element){
  1615. if( /youtube\.com\/embed\//.test(element.getAttribute('src')) && !element.hasAttribute('data-keepplaying')){
  1616. element.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}','*');
  1617. }
  1618. });
  1619. }
  1620. /**
  1621. * Gets the active slide (or section) for the given section
  1622. */
  1623. function getSlideOrSection(destiny){
  1624. var slide = $(SLIDE_ACTIVE_SEL, destiny);
  1625. if( slide.length ) {
  1626. destiny = slide[0];
  1627. }
  1628. return destiny;
  1629. }
  1630. /**
  1631. * Scrolls to the anchor in the URL when loading the site
  1632. */
  1633. function scrollToAnchor(){
  1634. var anchors = getAnchorsURL();
  1635. var sectionAnchor = anchors.section;
  1636. var slideAnchor = anchors.slide;
  1637. if(sectionAnchor){ //if theres any #
  1638. if(options.animateAnchor){
  1639. scrollPageAndSlide(sectionAnchor, slideAnchor);
  1640. }else{
  1641. silentMoveTo(sectionAnchor, slideAnchor);
  1642. }
  1643. }
  1644. }
  1645. /**
  1646. * Detecting any change on the URL to scroll to the given anchor link
  1647. * (a way to detect back history button as we play with the hashes on the URL)
  1648. */
  1649. function hashChangeHandler(){
  1650. if(!isScrolling && !options.lockAnchors){
  1651. var anchors = getAnchorsURL();
  1652. var sectionAnchor = anchors.section;
  1653. var slideAnchor = anchors.slide;
  1654. //when moving to a slide in the first section for the first time (first time to add an anchor to the URL)
  1655. var isFirstSlideMove = (typeof lastScrolledDestiny === 'undefined');
  1656. var isFirstScrollMove = (typeof lastScrolledDestiny === 'undefined' && typeof slideAnchor === 'undefined' && !slideMoving);
  1657. if(sectionAnchor && sectionAnchor.length){
  1658. /*in order to call scrollpage() only once for each destination at a time
  1659. It is called twice for each scroll otherwise, as in case of using anchorlinks `hashChange`
  1660. event is fired on every scroll too.*/
  1661. if ((sectionAnchor && sectionAnchor !== lastScrolledDestiny) && !isFirstSlideMove
  1662. || isFirstScrollMove
  1663. || (!slideMoving && lastScrolledSlide != slideAnchor )){
  1664. scrollPageAndSlide(sectionAnchor, slideAnchor);
  1665. }
  1666. }
  1667. }
  1668. }
  1669. //gets the URL anchors (section and slide)
  1670. function getAnchorsURL(){
  1671. var section;
  1672. var slide;
  1673. var hash = window.location.hash;
  1674. if(hash.length){
  1675. //getting the anchor link in the URL and deleting the `#`
  1676. var anchorsParts = hash.replace('#', '').split('/');
  1677. //using / for visual reasons and not as a section/slide separator #2803
  1678. var isFunkyAnchor = hash.indexOf('#/') > -1;
  1679. section = isFunkyAnchor ? '/' + anchorsParts[1] : decodeURIComponent(anchorsParts[0]);
  1680. var slideAnchor = isFunkyAnchor ? anchorsParts[2] : anchorsParts[1];
  1681. if(slideAnchor && slideAnchor.length){
  1682. slide = decodeURIComponent(slideAnchor);
  1683. }
  1684. }
  1685. return {
  1686. section: section,
  1687. slide: slide
  1688. };
  1689. }
  1690. //Sliding with arrow keys, both, vertical and horizontal
  1691. function keydownHandler(e) {
  1692. clearTimeout(keydownId);
  1693. var activeElement = document.activeElement;
  1694. var keyCode = e.keyCode;
  1695. //tab?
  1696. if(keyCode === 9){
  1697. onTab(e);
  1698. }
  1699. else if(!matches(activeElement, 'textarea') && !matches(activeElement, 'input') && !matches(activeElement, 'select') &&
  1700. activeElement.getAttribute('contentEditable') !== "true" && activeElement.getAttribute('contentEditable') !== '' &&
  1701. options.keyboardScrolling && options.autoScrolling){
  1702. //preventing the scroll with arrow keys & spacebar & Page Up & Down keys
  1703. var keyControls = [40, 38, 32, 33, 34];
  1704. if(keyControls.indexOf(keyCode) > -1){
  1705. preventDefault(e);
  1706. }
  1707. controlPressed = e.ctrlKey;
  1708. keydownId = setTimeout(function(){
  1709. onkeydown(e);
  1710. },150);
  1711. }
  1712. }
  1713. function tooltipTextHandler(){
  1714. /*jshint validthis:true */
  1715. trigger(prev(this), 'click');
  1716. }
  1717. //to prevent scrolling while zooming
  1718. function keyUpHandler(e){
  1719. if(isWindowFocused){ //the keyup gets fired on new tab ctrl + t in Firefox
  1720. controlPressed = e.ctrlKey;
  1721. }
  1722. }
  1723. //binding the mousemove when the mouse's middle button is released
  1724. function mouseDownHandler(e){
  1725. //middle button
  1726. if (e.which == 2){
  1727. oldPageY = e.pageY;
  1728. container.addEventListener('mousemove', mouseMoveHandler);
  1729. }
  1730. }
  1731. //unbinding the mousemove when the mouse's middle button is released
  1732. function mouseUpHandler(e){
  1733. //middle button
  1734. if (e.which == 2){
  1735. container.removeEventListener('mousemove', mouseMoveHandler);
  1736. }
  1737. }
  1738. /**
  1739. * Makes sure the tab key will only focus elements within the current section/slide
  1740. * preventing this way from breaking the page.
  1741. * Based on "Modals and keyboard traps"
  1742. * from https://developers.google.com/web/fundamentals/accessibility/focus/using-tabindex
  1743. */
  1744. function onTab(e){
  1745. var isShiftPressed = e.shiftKey;
  1746. var activeElement = document.activeElement;
  1747. var focusableElements = getFocusables(getSlideOrSection($(SECTION_ACTIVE_SEL)[0]));
  1748. function preventAndFocusFirst(e){
  1749. preventDefault(e);
  1750. return focusableElements[0] ? focusableElements[0].focus() : null;
  1751. }
  1752. //outside any section or slide? Let's not hijack the tab!
  1753. if(isFocusOutside(e)){
  1754. return;
  1755. }
  1756. //is there an element with focus?
  1757. if(activeElement){
  1758. if(closest(activeElement, SECTION_ACTIVE_SEL + ',' + SECTION_ACTIVE_SEL + ' ' + SLIDE_ACTIVE_SEL) == null){
  1759. activeElement = preventAndFocusFirst(e);
  1760. }
  1761. }
  1762. //no element if focused? Let's focus the first one of the section/slide
  1763. else{
  1764. preventAndFocusFirst(e);
  1765. }
  1766. //when reached the first or last focusable element of the section/slide
  1767. //we prevent the tab action to keep it in the last focusable element
  1768. if(!isShiftPressed && activeElement == focusableElements[focusableElements.length - 1] ||
  1769. isShiftPressed && activeElement == focusableElements[0]
  1770. ){
  1771. preventDefault(e);
  1772. }
  1773. }
  1774. /**
  1775. * Gets all the focusable elements inside the passed element.
  1776. */
  1777. function getFocusables(el){
  1778. return [].slice.call($(focusableElementsString, el)).filter(function(item) {
  1779. return item.getAttribute('tabindex') !== '-1'
  1780. //are also not hidden elements (or with hidden parents)
  1781. && item.offsetParent !== null;
  1782. });
  1783. }
  1784. /**
  1785. * Determines whether the focus is outside fullpage.js sections/slides or not.
  1786. */
  1787. function isFocusOutside(e){
  1788. var allFocusables = getFocusables(document);
  1789. var currentFocusIndex = allFocusables.indexOf(document.activeElement);
  1790. var focusDestinationIndex = e.shiftKey ? currentFocusIndex - 1 : currentFocusIndex + 1;
  1791. var focusDestination = allFocusables[focusDestinationIndex];
  1792. var destinationItemSlide = nullOrSlide(closest(focusDestination, SLIDE_SEL));
  1793. var destinationItemSection = nullOrSection(closest(focusDestination, SECTION_SEL));
  1794. return !destinationItemSlide && !destinationItemSection;
  1795. }
  1796. //Scrolling horizontally when clicking on the slider controls.
  1797. function slideArrowHandler(){
  1798. /*jshint validthis:true */
  1799. var section = closest(this, SECTION_SEL);
  1800. /*jshint validthis:true */
  1801. if (hasClass(this, SLIDES_PREV)) {
  1802. if(isScrollAllowed.m.left){
  1803. moveSlideLeft(section);
  1804. }
  1805. } else {
  1806. if(isScrollAllowed.m.right){
  1807. moveSlideRight(section);
  1808. }
  1809. }
  1810. }
  1811. //when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
  1812. function blurHandler(){
  1813. isWindowFocused = false;
  1814. controlPressed = false;
  1815. }
  1816. //Scrolls to the section when clicking the navigation bullet
  1817. function sectionBulletHandler(e){
  1818. preventDefault(e);
  1819. /*jshint validthis:true */
  1820. var indexBullet = index(closest(this, SECTION_NAV_SEL + ' li'));
  1821. scrollPage($(SECTION_SEL)[indexBullet]);
  1822. }
  1823. //Scrolls the slider to the given slide destination for the given section
  1824. function slideBulletHandler(e){
  1825. preventDefault(e);
  1826. /*jshint validthis:true */
  1827. var slides = $(SLIDES_WRAPPER_SEL, closest(this, SECTION_SEL))[0];
  1828. var destiny = $(SLIDE_SEL, slides)[index(closest(this, 'li'))];
  1829. landscapeScroll(slides, destiny);
  1830. }
  1831. /**
  1832. * Keydown event
  1833. */
  1834. function onkeydown(e){
  1835. var shiftPressed = e.shiftKey;
  1836. //do nothing if we can not scroll or we are not using horizotnal key arrows.
  1837. if(!canScroll && [37,39].indexOf(e.keyCode) < 0){
  1838. return;
  1839. }
  1840. switch (e.keyCode) {
  1841. //up
  1842. case 38:
  1843. case 33:
  1844. if(isScrollAllowed.k.up){
  1845. moveSectionUp();
  1846. }
  1847. break;
  1848. //down
  1849. case 32: //spacebar
  1850. if(shiftPressed && isScrollAllowed.k.up){
  1851. moveSectionUp();
  1852. break;
  1853. }
  1854. /* falls through */
  1855. case 40:
  1856. case 34:
  1857. if(isScrollAllowed.k.down){
  1858. moveSectionDown();
  1859. }
  1860. break;
  1861. //Home
  1862. case 36:
  1863. if(isScrollAllowed.k.up){
  1864. moveTo(1);
  1865. }
  1866. break;
  1867. //End
  1868. case 35:
  1869. if(isScrollAllowed.k.down){
  1870. moveTo( $(SECTION_SEL).length );
  1871. }
  1872. break;
  1873. //left
  1874. case 37:
  1875. if(isScrollAllowed.k.left){
  1876. moveSlideLeft();
  1877. }
  1878. break;
  1879. //right
  1880. case 39:
  1881. if(isScrollAllowed.k.right){
  1882. moveSlideRight();
  1883. }
  1884. break;
  1885. default:
  1886. return; // exit this handler for other keys
  1887. }
  1888. }
  1889. /**
  1890. * Detecting the direction of the mouse movement.
  1891. * Used only for the middle button of the mouse.
  1892. */
  1893. var oldPageY = 0;
  1894. function mouseMoveHandler(e){
  1895. if(canScroll){
  1896. // moving up
  1897. if (e.pageY < oldPageY && isScrollAllowed.m.up){
  1898. moveSectionUp();
  1899. }
  1900. // moving down
  1901. else if(e.pageY > oldPageY && isScrollAllowed.m.down){
  1902. moveSectionDown();
  1903. }
  1904. }
  1905. oldPageY = e.pageY;
  1906. }
  1907. /**
  1908. * Scrolls horizontal sliders.
  1909. */
  1910. function landscapeScroll(slides, destiny, direction){
  1911. var section = closest(slides, SECTION_SEL);
  1912. var v = {
  1913. slides: slides,
  1914. destiny: destiny,
  1915. direction: direction,
  1916. destinyPos: {left: destiny.offsetLeft},
  1917. slideIndex: index(destiny),
  1918. section: section,
  1919. sectionIndex: index(section, SECTION_SEL),
  1920. anchorLink: section.getAttribute('data-anchor'),
  1921. slidesNav: $(SLIDES_NAV_SEL, section)[0],
  1922. slideAnchor: getAnchor(destiny),
  1923. prevSlide: $(SLIDE_ACTIVE_SEL, section)[0],
  1924. prevSlideIndex: index($(SLIDE_ACTIVE_SEL, section)[0]),
  1925. //caching the value of isResizing at the momment the function is called
  1926. //because it will be checked later inside a setTimeout and the value might change
  1927. localIsResizing: isResizing
  1928. };
  1929. v.xMovement = getXmovement(v.prevSlideIndex, v.slideIndex);
  1930. //important!! Only do it when not resizing
  1931. if(!v.localIsResizing){
  1932. //preventing from scrolling to the next/prev section when using scrollHorizontally
  1933. canScroll = false;
  1934. }
  1935. if(options.onSlideLeave){
  1936. //if the site is not just resizing and readjusting the slides
  1937. if(!v.localIsResizing && v.xMovement!=='none'){
  1938. if(isFunction( options.onSlideLeave )){
  1939. if( fireCallback('onSlideLeave', v) === false){
  1940. slideMoving = false;
  1941. return;
  1942. }
  1943. }
  1944. }
  1945. }
  1946. addClass(destiny, ACTIVE);
  1947. removeClass(siblings(destiny), ACTIVE);
  1948. if(!v.localIsResizing){
  1949. stopMedia(v.prevSlide);
  1950. lazyLoad(destiny);
  1951. }
  1952. if(!options.loopHorizontal && options.controlArrows){
  1953. //hidding it for the fist slide, showing for the rest
  1954. toggle($(SLIDES_ARROW_PREV_SEL, section), v.slideIndex!==0);
  1955. //hidding it for the last slide, showing for the rest
  1956. toggle($(SLIDES_ARROW_NEXT_SEL, section), next(destiny) != null);
  1957. }
  1958. //only changing the URL if the slides are in the current section (not for resize re-adjusting)
  1959. if(hasClass(section, ACTIVE) && !v.localIsResizing){
  1960. setState(v.slideIndex, v.slideAnchor, v.anchorLink, v.sectionIndex);
  1961. }
  1962. performHorizontalMove(slides, v, true);
  1963. }
  1964. function afterSlideLoads(v){
  1965. activeSlidesNavigation(v.slidesNav, v.slideIndex);
  1966. //if the site is not just resizing and readjusting the slides
  1967. if(!v.localIsResizing){
  1968. if(isFunction( options.afterSlideLoad )){
  1969. fireCallback('afterSlideLoad', v);
  1970. }
  1971. //needs to be inside the condition to prevent problems with continuousVertical and scrollHorizontally
  1972. //and to prevent double scroll right after a windows resize
  1973. canScroll = true;
  1974. playMedia(v.destiny);
  1975. }
  1976. //letting them slide again
  1977. slideMoving = false;
  1978. }
  1979. /**
  1980. * Performs the horizontal movement. (CSS3 or jQuery)
  1981. *
  1982. * @param fireCallback {Bool} - determines whether or not to fire the callback
  1983. */
  1984. function performHorizontalMove(slides, v, fireCallback){
  1985. var destinyPos = v.destinyPos;
  1986. if(options.css3){
  1987. var translate3d = 'translate3d(-' + Math.round(destinyPos.left) + 'px, 0px, 0px)';
  1988. FP.test.translate3dH[v.sectionIndex] = translate3d;
  1989. css(addAnimation($(SLIDES_CONTAINER_SEL, slides)), getTransforms(translate3d));
  1990. afterSlideLoadsId = setTimeout(function(){
  1991. if(fireCallback){
  1992. afterSlideLoads(v);
  1993. }
  1994. }, options.scrollingSpeed);
  1995. }else{
  1996. FP.test.left[v.sectionIndex] = Math.round(destinyPos.left);
  1997. scrollTo(slides, Math.round(destinyPos.left), options.scrollingSpeed, function(){
  1998. if(fireCallback){
  1999. afterSlideLoads(v);
  2000. }
  2001. });
  2002. }
  2003. }
  2004. /**
  2005. * Sets the state for the horizontal bullet navigations.
  2006. */
  2007. function activeSlidesNavigation(slidesNav, slideIndex){
  2008. if(options.slidesNavigation && slidesNav != null){
  2009. removeClass($(ACTIVE_SEL, slidesNav), ACTIVE);
  2010. addClass( $('a', $('li', slidesNav)[slideIndex] ), ACTIVE);
  2011. }
  2012. }
  2013. var previousHeight = windowsHeight;
  2014. //when resizing the site, we adjust the heights of the sections, slimScroll...
  2015. function resizeHandler(){
  2016. //checking if it needs to get responsive
  2017. responsive();
  2018. // rebuild immediately on touch devices
  2019. if (isTouchDevice) {
  2020. var activeElement = document.activeElement;
  2021. //if the keyboard is NOT visible
  2022. if (!matches(activeElement, 'textarea') && !matches(activeElement, 'input') && !matches(activeElement, 'select')) {
  2023. var currentHeight = getWindowHeight();
  2024. //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)
  2025. if( Math.abs(currentHeight - previousHeight) > (20 * Math.max(previousHeight, currentHeight) / 100) ){
  2026. reBuild(true);
  2027. previousHeight = currentHeight;
  2028. }
  2029. }
  2030. }else{
  2031. //in order to call the functions only when the resize is finished
  2032. //http://stackoverflow.com/questions/4298612/jquery-how-to-call-resize-event-only-once-its-finished-resizing
  2033. clearTimeout(resizeId);
  2034. resizeId = setTimeout(function(){
  2035. reBuild(true);
  2036. }, 350);
  2037. }
  2038. }
  2039. /**
  2040. * Checks if the site needs to get responsive and disables autoScrolling if so.
  2041. * A class `fp-responsive` is added to the plugin's container in case the user wants to use it for his own responsive CSS.
  2042. */
  2043. function responsive(){
  2044. var widthLimit = options.responsive || options.responsiveWidth; //backwards compatiblity
  2045. var heightLimit = options.responsiveHeight;
  2046. //only calculating what we need. Remember its called on the resize event.
  2047. var isBreakingPointWidth = widthLimit && window.innerWidth < widthLimit;
  2048. var isBreakingPointHeight = heightLimit && window.innerHeight < heightLimit;
  2049. if(widthLimit && heightLimit){
  2050. setResponsive(isBreakingPointWidth || isBreakingPointHeight);
  2051. }
  2052. else if(widthLimit){
  2053. setResponsive(isBreakingPointWidth);
  2054. }
  2055. else if(heightLimit){
  2056. setResponsive(isBreakingPointHeight);
  2057. }
  2058. }
  2059. /**
  2060. * Adds transition animations for the given element
  2061. */
  2062. function addAnimation(element){
  2063. var transition = 'all ' + options.scrollingSpeed + 'ms ' + options.easingcss3;
  2064. removeClass(element, NO_TRANSITION);
  2065. return css(element, {
  2066. '-webkit-transition': transition,
  2067. 'transition': transition
  2068. });
  2069. }
  2070. /**
  2071. * Remove transition animations for the given element
  2072. */
  2073. function removeAnimation(element){
  2074. return addClass(element, NO_TRANSITION);
  2075. }
  2076. /**
  2077. * Activating the vertical navigation bullets according to the given slide name.
  2078. */
  2079. function activateNavDots(name, sectionIndex){
  2080. if(options.navigation && $(SECTION_NAV_SEL)[0] != null){
  2081. removeClass($(ACTIVE_SEL, $(SECTION_NAV_SEL)[0]), ACTIVE);
  2082. if(name){
  2083. addClass( $('a[href="#' + name + '"]', $(SECTION_NAV_SEL)[0]), ACTIVE);
  2084. }else{
  2085. addClass($('a', $('li', $(SECTION_NAV_SEL)[0])[sectionIndex]), ACTIVE);
  2086. }
  2087. }
  2088. }
  2089. /**
  2090. * Activating the website main menu elements according to the given slide name.
  2091. */
  2092. function activateMenuElement(name){
  2093. var menu = $(options.menu)[0];
  2094. if(options.menu && menu != null){
  2095. removeClass($(ACTIVE_SEL, menu), ACTIVE);
  2096. addClass($('[data-menuanchor="'+name+'"]', menu), ACTIVE);
  2097. }
  2098. }
  2099. /**
  2100. * Sets to active the current menu and vertical nav items.
  2101. */
  2102. function activateMenuAndNav(anchor, index){
  2103. activateMenuElement(anchor);
  2104. activateNavDots(anchor, index);
  2105. }
  2106. /**
  2107. * Retuns `up` or `down` depending on the scrolling movement to reach its destination
  2108. * from the current section.
  2109. */
  2110. function getYmovement(destiny){
  2111. var fromIndex = index($(SECTION_ACTIVE_SEL)[0], SECTION_SEL);
  2112. var toIndex = index(destiny, SECTION_SEL);
  2113. if( fromIndex == toIndex){
  2114. return 'none';
  2115. }
  2116. if(fromIndex > toIndex){
  2117. return 'up';
  2118. }
  2119. return 'down';
  2120. }
  2121. /**
  2122. * Retuns `right` or `left` depending on the scrolling movement to reach its destination
  2123. * from the current slide.
  2124. */
  2125. function getXmovement(fromIndex, toIndex){
  2126. if( fromIndex == toIndex){
  2127. return 'none';
  2128. }
  2129. if(fromIndex > toIndex){
  2130. return 'left';
  2131. }
  2132. return 'right';
  2133. }
  2134. function addTableClass(element){
  2135. //In case we are styling for the 2nd time as in with reponsiveSlides
  2136. if(!hasClass(element, TABLE)){
  2137. var wrapper = document.createElement('div');
  2138. wrapper.className = TABLE_CELL;
  2139. wrapper.style.height = getTableHeight(element) + 'px';
  2140. addClass(element, TABLE);
  2141. wrapInner(element, wrapper);
  2142. }
  2143. }
  2144. function getTableHeight(element){
  2145. var sectionHeight = windowsHeight;
  2146. if(options.paddingTop || options.paddingBottom){
  2147. var section = element;
  2148. if(!hasClass(section, SECTION)){
  2149. section = closest(element, SECTION_SEL);
  2150. }
  2151. var paddings = parseInt(getComputedStyle(section)['padding-top']) + parseInt(getComputedStyle(section)['padding-bottom']);
  2152. sectionHeight = (windowsHeight - paddings);
  2153. }
  2154. return sectionHeight;
  2155. }
  2156. /**
  2157. * Adds a css3 transform property to the container class with or without animation depending on the animated param.
  2158. */
  2159. function transformContainer(translate3d, animated){
  2160. if(animated){
  2161. addAnimation(container);
  2162. }else{
  2163. removeAnimation(container);
  2164. }
  2165. css(container, getTransforms(translate3d));
  2166. FP.test.translate3d = translate3d;
  2167. //syncronously removing the class after the animation has been applied.
  2168. setTimeout(function(){
  2169. removeClass(container, NO_TRANSITION);
  2170. },10);
  2171. }
  2172. /**
  2173. * Gets a section by its anchor / index
  2174. */
  2175. function getSectionByAnchor(sectionAnchor){
  2176. var section = $(SECTION_SEL + '[data-anchor="'+sectionAnchor+'"]', container)[0];
  2177. if(!section){
  2178. var sectionIndex = typeof sectionAnchor !== 'undefined' ? sectionAnchor -1 : 0;
  2179. section = $(SECTION_SEL)[sectionIndex];
  2180. }
  2181. return section;
  2182. }
  2183. /**
  2184. * Gets a slide inside a given section by its anchor / index
  2185. */
  2186. function getSlideByAnchor(slideAnchor, section){
  2187. var slide = $(SLIDE_SEL + '[data-anchor="'+slideAnchor+'"]', section)[0];
  2188. if(slide == null){
  2189. slideAnchor = typeof slideAnchor !== 'undefined' ? slideAnchor : 0;
  2190. slide = $(SLIDE_SEL, section)[slideAnchor];
  2191. }
  2192. return slide;
  2193. }
  2194. /**
  2195. * Scrolls to the given section and slide anchors
  2196. */
  2197. function scrollPageAndSlide(sectionAnchor, slideAnchor){
  2198. var section = getSectionByAnchor(sectionAnchor);
  2199. //do nothing if there's no section with the given anchor name
  2200. if(section == null) return;
  2201. var slide = getSlideByAnchor(slideAnchor, section);
  2202. //we need to scroll to the section and then to the slide
  2203. if (getAnchor(section) !== lastScrolledDestiny && !hasClass(section, ACTIVE)){
  2204. scrollPage(section, function(){
  2205. scrollSlider(slide);
  2206. });
  2207. }
  2208. //if we were already in the section
  2209. else{
  2210. scrollSlider(slide);
  2211. }
  2212. }
  2213. /**
  2214. * Scrolls the slider to the given slide destination for the given section
  2215. */
  2216. function scrollSlider(slide){
  2217. if(slide != null){
  2218. landscapeScroll(closest(slide, SLIDES_WRAPPER_SEL), slide);
  2219. }
  2220. }
  2221. /**
  2222. * Creates a landscape navigation bar with dots for horizontal sliders.
  2223. */
  2224. function addSlidesNavigation(section, numSlides){
  2225. appendTo(createElementFromHTML('<div class="' + SLIDES_NAV + '"><ul></ul></div>'), section);
  2226. var nav = $(SLIDES_NAV_SEL, section)[0];
  2227. //top or bottom
  2228. addClass(nav, 'fp-' + options.slidesNavPosition);
  2229. for(var i=0; i< numSlides; i++){
  2230. appendTo(createElementFromHTML('<li><a href="#"><span class="fp-sr-only">'+ getBulletLinkName(i, 'Slide') +'</span><span></span></a></li>'), $('ul', nav)[0] );
  2231. }
  2232. //centering it
  2233. css(nav, {'margin-left': '-' + (nav.innerWidth/2) + 'px'});
  2234. addClass($('a', $('li', nav)[0] ), ACTIVE);
  2235. }
  2236. /**
  2237. * Sets the state of the website depending on the active section/slide.
  2238. * It changes the URL hash when needed and updates the body class.
  2239. */
  2240. function setState(slideIndex, slideAnchor, anchorLink, sectionIndex){
  2241. var sectionHash = '';
  2242. if(options.anchors.length && !options.lockAnchors){
  2243. //isn't it the first slide?
  2244. if(slideIndex){
  2245. if(anchorLink != null){
  2246. sectionHash = anchorLink;
  2247. }
  2248. //slide without anchor link? We take the index instead.
  2249. if(slideAnchor == null){
  2250. slideAnchor = slideIndex;
  2251. }
  2252. lastScrolledSlide = slideAnchor;
  2253. setUrlHash(sectionHash + '/' + slideAnchor);
  2254. //first slide won't have slide anchor, just the section one
  2255. }else if(slideIndex != null){
  2256. lastScrolledSlide = slideAnchor;
  2257. setUrlHash(anchorLink);
  2258. }
  2259. //section without slides
  2260. else{
  2261. setUrlHash(anchorLink);
  2262. }
  2263. }
  2264. setBodyClass();
  2265. }
  2266. /**
  2267. * Sets the URL hash.
  2268. */
  2269. function setUrlHash(url){
  2270. if(options.recordHistory){
  2271. location.hash = url;
  2272. }else{
  2273. //Mobile Chrome doesn't work the normal way, so... lets use HTML5 for phones :)
  2274. if(isTouchDevice || isTouch){
  2275. window.history.replaceState(undefined, undefined, '#' + url);
  2276. }else{
  2277. var baseUrl = window.location.href.split('#')[0];
  2278. window.location.replace( baseUrl + '#' + url );
  2279. }
  2280. }
  2281. }
  2282. /**
  2283. * Gets the anchor for the given slide / section. Its index will be used if there's none.
  2284. */
  2285. function getAnchor(element){
  2286. if(!element){
  2287. return null;
  2288. }
  2289. var anchor = element.getAttribute('data-anchor');
  2290. var elementIndex = index(element);
  2291. //Slide without anchor link? We take the index instead.
  2292. if(anchor == null){
  2293. anchor = elementIndex;
  2294. }
  2295. return anchor;
  2296. }
  2297. /**
  2298. * Sets a class for the body of the page depending on the active section / slide
  2299. */
  2300. function setBodyClass(){
  2301. var section = $(SECTION_ACTIVE_SEL)[0];
  2302. var slide = $(SLIDE_ACTIVE_SEL, section)[0];
  2303. var sectionAnchor = getAnchor(section);
  2304. var slideAnchor = getAnchor(slide);
  2305. var text = String(sectionAnchor);
  2306. if(slide){
  2307. text = text + '-' + slideAnchor;
  2308. }
  2309. //changing slash for dash to make it a valid CSS style
  2310. text = text.replace('/', '-').replace('#','');
  2311. //removing previous anchor classes
  2312. var classRe = new RegExp('\\b\\s?' + VIEWING_PREFIX + '-[^\\s]+\\b', "g");
  2313. $body.className = $body.className.replace(classRe, '');
  2314. //adding the current anchor
  2315. addClass($body, VIEWING_PREFIX + '-' + text);
  2316. }
  2317. /**
  2318. * Checks for translate3d support
  2319. * @return boolean
  2320. * http://stackoverflow.com/questions/5661671/detecting-transform-translate3d-support
  2321. */
  2322. function support3d() {
  2323. var el = document.createElement('p'),
  2324. has3d,
  2325. transforms = {
  2326. 'webkitTransform':'-webkit-transform',
  2327. 'OTransform':'-o-transform',
  2328. 'msTransform':'-ms-transform',
  2329. 'MozTransform':'-moz-transform',
  2330. 'transform':'transform'
  2331. };
  2332. //preventing the style p:empty{display: none;} from returning the wrong result
  2333. el.style.display = 'block'
  2334. // Add it to the body to get the computed style.
  2335. document.body.insertBefore(el, null);
  2336. for (var t in transforms) {
  2337. if (el.style[t] !== undefined) {
  2338. el.style[t] = 'translate3d(1px,1px,1px)';
  2339. has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
  2340. }
  2341. }
  2342. document.body.removeChild(el);
  2343. return (has3d !== undefined && has3d.length > 0 && has3d !== 'none');
  2344. }
  2345. /**
  2346. * Removes the auto scrolling action fired by the mouse wheel and trackpad.
  2347. * After this function is called, the mousewheel and trackpad movements won't scroll through sections.
  2348. */
  2349. function removeMouseWheelHandler(){
  2350. if (document.addEventListener) {
  2351. document.removeEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
  2352. document.removeEventListener('wheel', MouseWheelHandler, false); //Firefox
  2353. document.removeEventListener('MozMousePixelScroll', MouseWheelHandler, false); //old Firefox
  2354. } else {
  2355. document.detachEvent('onmousewheel', MouseWheelHandler); //IE 6/7/8
  2356. }
  2357. }
  2358. /**
  2359. * Adds the auto scrolling action for the mouse wheel and trackpad.
  2360. * After this function is called, the mousewheel and trackpad movements will scroll through sections
  2361. * https://developer.mozilla.org/en-US/docs/Web/Events/wheel
  2362. */
  2363. function addMouseWheelHandler(){
  2364. var prefix = '';
  2365. var _addEventListener;
  2366. if (window.addEventListener){
  2367. _addEventListener = "addEventListener";
  2368. }else{
  2369. _addEventListener = "attachEvent";
  2370. prefix = 'on';
  2371. }
  2372. // detect available wheel event
  2373. var support = 'onwheel' in document.createElement('div') ? 'wheel' : // Modern browsers support "wheel"
  2374. document.onmousewheel !== undefined ? 'mousewheel' : // Webkit and IE support at least "mousewheel"
  2375. 'DOMMouseScroll'; // let's assume that remaining browsers are older Firefox
  2376. if(support == 'DOMMouseScroll'){
  2377. document[ _addEventListener ](prefix + 'MozMousePixelScroll', MouseWheelHandler, false);
  2378. }
  2379. //handle MozMousePixelScroll in older Firefox
  2380. else{
  2381. document[ _addEventListener ](prefix + support, MouseWheelHandler, false);
  2382. }
  2383. }
  2384. /**
  2385. * Binding the mousemove when the mouse's middle button is pressed
  2386. */
  2387. function addMiddleWheelHandler(){
  2388. container.addEventListener('mousedown', mouseDownHandler);
  2389. container.addEventListener('mouseup', mouseUpHandler);
  2390. }
  2391. /**
  2392. * Unbinding the mousemove when the mouse's middle button is released
  2393. */
  2394. function removeMiddleWheelHandler(){
  2395. container.removeEventListener('mousedown', mouseDownHandler);
  2396. container.removeEventListener('mouseup', mouseUpHandler);
  2397. }
  2398. /**
  2399. * Adds the possibility to auto scroll through sections on touch devices.
  2400. */
  2401. function addTouchHandler(){
  2402. if(isTouchDevice || isTouch){
  2403. if(options.autoScrolling){
  2404. $body.removeEventListener(events.touchmove, preventBouncing, {passive: false});
  2405. $body.addEventListener(events.touchmove, preventBouncing, {passive: false});
  2406. }
  2407. $(WRAPPER_SEL)[0].removeEventListener(events.touchstart, touchStartHandler);
  2408. $(WRAPPER_SEL)[0].removeEventListener(events.touchmove, touchMoveHandler, {passive: false});
  2409. $(WRAPPER_SEL)[0].addEventListener(events.touchstart, touchStartHandler);
  2410. $(WRAPPER_SEL)[0].addEventListener(events.touchmove, touchMoveHandler, {passive: false});
  2411. }
  2412. }
  2413. /**
  2414. * Removes the auto scrolling for touch devices.
  2415. */
  2416. function removeTouchHandler(){
  2417. if(isTouchDevice || isTouch){
  2418. // normalScrollElements requires it off #2691
  2419. if(options.autoScrolling){
  2420. $body.removeEventListener(events.touchmove, touchMoveHandler, {passive: false});
  2421. $body.removeEventListener(events.touchmove, preventBouncing, {passive: false});
  2422. }
  2423. $(WRAPPER_SEL)[0].removeEventListener(events.touchstart, touchStartHandler);
  2424. $(WRAPPER_SEL)[0].removeEventListener(events.touchmove, touchMoveHandler, {passive: false});
  2425. }
  2426. }
  2427. /*
  2428. * Returns and object with Microsoft pointers (for IE<11 and for IE >= 11)
  2429. * http://msdn.microsoft.com/en-us/library/ie/dn304886(v=vs.85).aspx
  2430. */
  2431. function getMSPointer(){
  2432. var pointer;
  2433. //IE >= 11 & rest of browsers
  2434. if(window.PointerEvent){
  2435. pointer = { down: 'pointerdown', move: 'pointermove'};
  2436. }
  2437. //IE < 11
  2438. else{
  2439. pointer = { down: 'MSPointerDown', move: 'MSPointerMove'};
  2440. }
  2441. return pointer;
  2442. }
  2443. /**
  2444. * Gets the pageX and pageY properties depending on the browser.
  2445. * https://github.com/alvarotrigo/fullPage.js/issues/194#issuecomment-34069854
  2446. */
  2447. function getEventsPage(e){
  2448. var events = [];
  2449. events.y = (typeof e.pageY !== 'undefined' && (e.pageY || e.pageX) ? e.pageY : e.touches[0].pageY);
  2450. events.x = (typeof e.pageX !== 'undefined' && (e.pageY || e.pageX) ? e.pageX : e.touches[0].pageX);
  2451. //in touch devices with scrollBar:true, e.pageY is detected, but we have to deal with touch events. #1008
  2452. if(isTouch && isReallyTouch(e) && options.scrollBar && typeof e.touches !== 'undefined'){
  2453. events.y = e.touches[0].pageY;
  2454. events.x = e.touches[0].pageX;
  2455. }
  2456. return events;
  2457. }
  2458. /**
  2459. * Slides silently (with no animation) the active slider to the given slide.
  2460. * @param noCallback {bool} true or defined -> no callbacks
  2461. */
  2462. function silentLandscapeScroll(activeSlide, noCallbacks){
  2463. setScrollingSpeed(0, 'internal');
  2464. if(typeof noCallbacks !== 'undefined'){
  2465. //preventing firing callbacks afterSlideLoad etc.
  2466. isResizing = true;
  2467. }
  2468. landscapeScroll(closest(activeSlide, SLIDES_WRAPPER_SEL), activeSlide);
  2469. if(typeof noCallbacks !== 'undefined'){
  2470. isResizing = false;
  2471. }
  2472. setScrollingSpeed(originals.scrollingSpeed, 'internal');
  2473. }
  2474. /**
  2475. * Scrolls silently (with no animation) the page to the given Y position.
  2476. */
  2477. function silentScroll(top){
  2478. // The first section can have a negative value in iOS 10. Not quite sure why: -0.0142822265625
  2479. // that's why we round it to 0.
  2480. var roundedTop = Math.round(top);
  2481. if (options.css3 && options.autoScrolling && !options.scrollBar){
  2482. var translate3d = 'translate3d(0px, -' + roundedTop + 'px, 0px)';
  2483. transformContainer(translate3d, false);
  2484. }
  2485. else if(options.autoScrolling && !options.scrollBar){
  2486. css(container, {'top': -roundedTop + 'px'});
  2487. FP.test.top = -roundedTop + 'px';
  2488. }
  2489. else{
  2490. var scrollSettings = getScrollSettings(roundedTop);
  2491. setScrolling(scrollSettings.element, scrollSettings.options);
  2492. }
  2493. }
  2494. /**
  2495. * Returns the cross-browser transform string.
  2496. */
  2497. function getTransforms(translate3d){
  2498. return {
  2499. '-webkit-transform': translate3d,
  2500. '-moz-transform': translate3d,
  2501. '-ms-transform':translate3d,
  2502. 'transform': translate3d
  2503. };
  2504. }
  2505. /**
  2506. * Allowing or disallowing the mouse/swipe scroll in a given direction. (not for keyboard)
  2507. * @type m (mouse) or k (keyboard)
  2508. */
  2509. function setIsScrollAllowed(value, direction, type){
  2510. //up, down, left, right
  2511. if(direction !== 'all'){
  2512. isScrollAllowed[type][direction] = value;
  2513. }
  2514. //all directions?
  2515. else{
  2516. Object.keys(isScrollAllowed[type]).forEach(function(key){
  2517. isScrollAllowed[type][key] = value;
  2518. });
  2519. }
  2520. }
  2521. /*
  2522. * Destroys fullpage.js plugin events and optinally its html markup and styles
  2523. */
  2524. function destroy(all){
  2525. setAutoScrolling(false, 'internal');
  2526. setAllowScrolling(true);
  2527. setMouseHijack(false);
  2528. setKeyboardScrolling(false);
  2529. addClass(container, DESTROYED);
  2530. clearTimeout(afterSlideLoadsId);
  2531. clearTimeout(afterSectionLoadsId);
  2532. clearTimeout(resizeId);
  2533. clearTimeout(scrollId);
  2534. clearTimeout(scrollId2);
  2535. window.removeEventListener('scroll', scrollHandler);
  2536. window.removeEventListener('hashchange', hashChangeHandler);
  2537. window.removeEventListener('resize', resizeHandler);
  2538. document.removeEventListener('keydown', keydownHandler);
  2539. document.removeEventListener('keyup', keyUpHandler);
  2540. ['click', 'touchstart'].forEach(function(eventName){
  2541. document.removeEventListener(eventName, delegatedEvents);
  2542. });
  2543. ['mouseenter', 'touchstart', 'mouseleave', 'touchend'].forEach(function(eventName){
  2544. document.removeEventListener(eventName, onMouseEnterOrLeave, true); //true is required!
  2545. });
  2546. clearTimeout(afterSlideLoadsId);
  2547. clearTimeout(afterSectionLoadsId);
  2548. //lets make a mess!
  2549. if(all){
  2550. destroyStructure();
  2551. }
  2552. }
  2553. /*
  2554. * Removes inline styles added by fullpage.js
  2555. */
  2556. function destroyStructure(){
  2557. //reseting the `top` or `translate` properties to 0
  2558. silentScroll(0);
  2559. //loading all the lazy load content
  2560. $('img[data-src], source[data-src], audio[data-src], iframe[data-src]', container).forEach(function(item){
  2561. setSrc(item, 'src');
  2562. });
  2563. $('img[data-srcset]').forEach(function(item){
  2564. setSrc(item, 'srcset');
  2565. });
  2566. remove($(SECTION_NAV_SEL + ', ' + SLIDES_NAV_SEL + ', ' + SLIDES_ARROW_SEL));
  2567. //removing inline styles
  2568. css($(SECTION_SEL), {
  2569. 'height': '',
  2570. 'background-color' : '',
  2571. 'padding': ''
  2572. });
  2573. css($(SLIDE_SEL), {
  2574. 'width': ''
  2575. });
  2576. css(container, {
  2577. 'height': '',
  2578. 'position': '',
  2579. '-ms-touch-action': '',
  2580. 'touch-action': ''
  2581. });
  2582. css($htmlBody, {
  2583. 'overflow': '',
  2584. 'height': ''
  2585. });
  2586. // remove .fp-enabled class
  2587. removeClass($('html'), ENABLED);
  2588. // remove .fp-responsive class
  2589. removeClass($body, RESPONSIVE);
  2590. // remove all of the .fp-viewing- classes
  2591. $body.className.split(/\s+/).forEach(function (className) {
  2592. if (className.indexOf(VIEWING_PREFIX) === 0) {
  2593. removeClass($body, className);
  2594. }
  2595. });
  2596. //removing added classes
  2597. $(SECTION_SEL + ', ' + SLIDE_SEL).forEach(function(item){
  2598. if(options.scrollOverflowHandler){
  2599. options.scrollOverflowHandler.remove(item);
  2600. }
  2601. removeClass(item, TABLE + ' ' + ACTIVE + ' ' + COMPLETELY);
  2602. var previousStyles = item.getAttribute('data-fp-styles');
  2603. if(previousStyles){
  2604. item.setAttribute('style', item.getAttribute('data-fp-styles'));
  2605. }
  2606. });
  2607. //removing the applied transition from the fullpage wrapper
  2608. removeAnimation(container);
  2609. //Unwrapping content
  2610. [TABLE_CELL_SEL, SLIDES_CONTAINER_SEL,SLIDES_WRAPPER_SEL].forEach(function(selector){
  2611. $(selector, container).forEach(function(item){
  2612. //unwrap not being use in case there's no child element inside and its just text
  2613. item.outerHTML = item.innerHTML;
  2614. });
  2615. });
  2616. //removing the applied transition from the fullpage wrapper
  2617. css(container, {
  2618. '-webkit-transition': 'none',
  2619. 'transition': 'none'
  2620. });
  2621. //scrolling the page to the top with no animation
  2622. window.scrollTo(0, 0);
  2623. //removing selectors
  2624. var usedSelectors = [SECTION, SLIDE, SLIDES_CONTAINER];
  2625. usedSelectors.forEach(function(item){
  2626. removeClass($('.' + item), item);
  2627. });
  2628. }
  2629. /*
  2630. * Sets the state for a variable with multiple states (original, and temporal)
  2631. * Some variables such as `autoScrolling` or `recordHistory` might change automatically its state when using `responsive` or `autoScrolling:false`.
  2632. * This function is used to keep track of both states, the original and the temporal one.
  2633. * If type is not 'internal', then we assume the user is globally changing the variable.
  2634. */
  2635. function setVariableState(variable, value, type){
  2636. options[variable] = value;
  2637. if(type !== 'internal'){
  2638. originals[variable] = value;
  2639. }
  2640. }
  2641. /**
  2642. * Displays warnings
  2643. */
  2644. function displayWarnings(){
  2645. if(!isLicenseValid){
  2646. showError('error', 'Fullpage.js version 3 has changed its license to GPLv3 and it requires a `licenseKey` option. Read about it here:');
  2647. showError('error', 'https://github.com/alvarotrigo/fullPage.js#options.');
  2648. }
  2649. var extensions = ['fadingEffect', 'continuousHorizontal', 'scrollHorizontally', 'interlockedSlides', 'resetSliders', 'responsiveSlides', 'offsetSections', 'dragAndMove', 'scrollOverflowReset', 'parallax'];
  2650. if(hasClass($('html'), ENABLED)){
  2651. showError('error', 'Fullpage.js can only be initialized once and you are doing it multiple times!');
  2652. return;
  2653. }
  2654. // Disable mutually exclusive settings
  2655. if (options.continuousVertical &&
  2656. (options.loopTop || options.loopBottom)) {
  2657. options.continuousVertical = false;
  2658. showError('warn', 'Option `loopTop/loopBottom` is mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
  2659. }
  2660. if(options.scrollOverflow &&
  2661. (options.scrollBar || !options.autoScrolling)){
  2662. showError('warn', 'Options scrollBar:true and autoScrolling:false are mutually exclusive with scrollOverflow:true. Sections with scrollOverflow might not work well in Firefox');
  2663. }
  2664. if(options.continuousVertical && (options.scrollBar || !options.autoScrolling)){
  2665. options.continuousVertical = false;
  2666. showError('warn', 'Scroll bars (`scrollBar:true` or `autoScrolling:false`) are mutually exclusive with `continuousVertical`; `continuousVertical` disabled');
  2667. }
  2668. if(options.scrollOverflow && options.scrollOverflowHandler == null){
  2669. options.scrollOverflow = false;
  2670. showError('error', 'The option `scrollOverflow:true` requires the file `scrolloverflow.min.js`. Please include it before fullPage.js.');
  2671. }
  2672. //using extensions? Wrong file!
  2673. extensions.forEach(function(extension){
  2674. //is the option set to true?
  2675. if(options[extension]){
  2676. showError('warn', 'fullpage.js extensions require fullpage.extensions.min.js file instead of the usual fullpage.js. Requested: '+ extension);
  2677. }
  2678. });
  2679. //anchors can not have the same value as any element ID or NAME
  2680. options.anchors.forEach(function(name){
  2681. //case insensitive selectors (http://stackoverflow.com/a/19465187/1081396)
  2682. var nameAttr = [].slice.call($('[name]')).filter(function(item) {
  2683. return item.getAttribute('name') && item.getAttribute('name').toLowerCase() == name.toLowerCase();
  2684. });
  2685. var idAttr = [].slice.call($('[id]')).filter(function(item) {
  2686. return item.getAttribute('id') && item.getAttribute('id').toLowerCase() == name.toLowerCase();
  2687. });
  2688. if(idAttr.length || nameAttr.length ){
  2689. showError('error', 'data-anchor tags can not have the same value as any `id` element on the site (or `name` element for IE).');
  2690. if(idAttr.length){
  2691. showError('error', '"' + name + '" is is being used by another element `id` property');
  2692. }
  2693. if(nameAttr.length){
  2694. showError('error', '"' + name + '" is is being used by another element `name` property');
  2695. }
  2696. }
  2697. });
  2698. }
  2699. /**
  2700. * Getting the position of the element to scroll when using jQuery animations
  2701. */
  2702. function getScrolledPosition(element){
  2703. var position;
  2704. //is not the window element and is a slide?
  2705. if(element.self != window && hasClass(element, SLIDES_WRAPPER)){
  2706. position = element.scrollLeft;
  2707. }
  2708. else if(!options.autoScrolling || options.scrollBar){
  2709. position = getScrollTop();
  2710. }
  2711. else{
  2712. position = element.offsetTop;
  2713. }
  2714. //gets the top property of the wrapper
  2715. return position;
  2716. }
  2717. /**
  2718. * Simulates the animated scrollTop of jQuery. Used when css3:false or scrollBar:true or autoScrolling:false
  2719. * http://stackoverflow.com/a/16136789/1081396
  2720. */
  2721. function scrollTo(element, to, duration, callback) {
  2722. var start = getScrolledPosition(element);
  2723. var change = to - start;
  2724. var currentTime = 0;
  2725. var increment = 20;
  2726. activeAnimation = true;
  2727. var animateScroll = function(){
  2728. if(activeAnimation){ //in order to stope it from other function whenever we want
  2729. var val = to;
  2730. currentTime += increment;
  2731. if(duration){
  2732. val = window.fp_easings[options.easing](currentTime, start, change, duration);
  2733. }
  2734. setScrolling(element, val);
  2735. if(currentTime < duration) {
  2736. setTimeout(animateScroll, increment);
  2737. }else if(typeof callback !== 'undefined'){
  2738. callback();
  2739. }
  2740. }else if (currentTime < duration){
  2741. callback();
  2742. }
  2743. };
  2744. animateScroll();
  2745. }
  2746. /**
  2747. * Scrolls the page / slider the given number of pixels.
  2748. * It will do it one or another way dependiong on the library's config.
  2749. */
  2750. function setScrolling(element, val){
  2751. if(!options.autoScrolling || options.scrollBar || (element.self != window && hasClass(element, SLIDES_WRAPPER))){
  2752. //scrolling horizontally through the slides?
  2753. if(element.self != window && hasClass(element, SLIDES_WRAPPER)){
  2754. element.scrollLeft = val;
  2755. }
  2756. //vertical scroll
  2757. else{
  2758. element.scrollTo(0, val);
  2759. }
  2760. }else{
  2761. element.style.top = val + 'px';
  2762. }
  2763. }
  2764. /**
  2765. * Gets the active slide.
  2766. */
  2767. function getActiveSlide(){
  2768. var activeSlide = $(SLIDE_ACTIVE_SEL, $(SECTION_ACTIVE_SEL)[0])[0];
  2769. return nullOrSlide(activeSlide);
  2770. }
  2771. /**
  2772. * Gets the active section.
  2773. */
  2774. function getActiveSection(){
  2775. return new Section($(SECTION_ACTIVE_SEL)[0]);
  2776. }
  2777. /**
  2778. * Item. Slide or Section objects share the same properties.
  2779. */
  2780. function Item(el, selector){
  2781. this.anchor = el.getAttribute('data-anchor');
  2782. this.item = el;
  2783. this.index = index(el, selector);
  2784. this.isLast = this.index === $(selector).length -1;
  2785. this.isFirst = !this.index;
  2786. }
  2787. /**
  2788. * Section object
  2789. */
  2790. function Section(el){
  2791. Item.call(this, el, SECTION_SEL);
  2792. }
  2793. /**
  2794. * Slide object
  2795. */
  2796. function Slide(el){
  2797. Item.call(this, el, SLIDE_SEL);
  2798. }
  2799. return FP;
  2800. } //end of $.fn.fullpage
  2801. //utils
  2802. /**
  2803. * Shows a message in the console of the given type.
  2804. */
  2805. function showError(type, text){
  2806. window.console && window.console[type] && window.console[type]('fullPage: ' + text);
  2807. }
  2808. /**
  2809. * Equivalent or jQuery function $().
  2810. */
  2811. function $(selector, context){
  2812. context = arguments.length > 1 ? context : document;
  2813. return context ? context.querySelectorAll(selector) : null;
  2814. }
  2815. /**
  2816. * Extends a given Object properties and its childs.
  2817. */
  2818. function deepExtend(out) {
  2819. out = out || {};
  2820. for (var i = 1; i < arguments.length; i++) {
  2821. var obj = arguments[i];
  2822. if (!obj)
  2823. continue;
  2824. for (var key in obj) {
  2825. if (obj.hasOwnProperty(key)) {
  2826. if (typeof obj[key] === 'object' && obj[key] != null)
  2827. out[key] = deepExtend(out[key], obj[key]);
  2828. else
  2829. out[key] = obj[key];
  2830. }
  2831. }
  2832. }
  2833. return out;
  2834. }
  2835. /**
  2836. * Checks if the passed element contains the passed class.
  2837. */
  2838. function hasClass(el, className){
  2839. if(el == null){
  2840. return false;
  2841. }
  2842. if (el.classList){
  2843. return el.classList.contains(className);
  2844. }
  2845. return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
  2846. }
  2847. /**
  2848. * Gets the window height. Crossbrowser.
  2849. */
  2850. function getWindowHeight(){
  2851. return 'innerHeight' in window ? window.innerHeight : document.documentElement.offsetHeight;
  2852. }
  2853. /**
  2854. * Set's the CSS properties for the passed item/s.
  2855. * @param {NodeList|HTMLElement} items
  2856. * @param {Object} props css properties and values.
  2857. */
  2858. function css(items, props) {
  2859. items = getList(items);
  2860. var key;
  2861. for (key in props) {
  2862. if (props.hasOwnProperty(key)) {
  2863. if (key !== null) {
  2864. for (var i = 0; i < items.length; i++) {
  2865. var item = items[i];
  2866. item.style[key] = props[key];
  2867. }
  2868. }
  2869. }
  2870. }
  2871. return items;
  2872. }
  2873. /**
  2874. * Generic function to get the previous or next element.
  2875. */
  2876. function until(item, selector, fn){
  2877. var sibling = item[fn];
  2878. while(sibling && !matches(sibling, selector)){
  2879. sibling = sibling[fn];
  2880. }
  2881. return sibling;
  2882. }
  2883. /**
  2884. * Gets the previous element to the passed element that matches the passed selector.
  2885. */
  2886. function prevUntil(item, selector){
  2887. return until(item, selector, 'previousElementSibling');
  2888. }
  2889. /**
  2890. * Gets the next element to the passed element that matches the passed selector.
  2891. */
  2892. function nextUntil(item, selector){
  2893. return until(item, selector, 'nextElementSibling');
  2894. }
  2895. /**
  2896. * Gets the previous element to the passed element.
  2897. */
  2898. function prev(item){
  2899. return item.previousElementSibling;
  2900. }
  2901. /**
  2902. * Gets the next element to the passed element.
  2903. */
  2904. function next(item){
  2905. return item.nextElementSibling;
  2906. }
  2907. /**
  2908. * Gets the last element from the passed list of elements.
  2909. */
  2910. function last(item){
  2911. return item[item.length-1];
  2912. }
  2913. /**
  2914. * Gets index from the passed element.
  2915. * @param {String} selector is optional.
  2916. */
  2917. function index(item, selector) {
  2918. item = isArrayOrList(item) ? item[0] : item;
  2919. var children = selector != null? $(selector, item.parentNode) : item.parentNode.childNodes;
  2920. var num = 0;
  2921. for (var i=0; i<children.length; i++) {
  2922. if (children[i] == item) return num;
  2923. if (children[i].nodeType==1) num++;
  2924. }
  2925. return -1;
  2926. }
  2927. /**
  2928. * Gets an iterable element for the passed element/s
  2929. */
  2930. function getList(item){
  2931. return !isArrayOrList(item) ? [item] : item;
  2932. }
  2933. /**
  2934. * Adds the display=none property for the passed element/s
  2935. */
  2936. function hide(el){
  2937. el = getList(el);
  2938. for(var i = 0; i<el.length; i++){
  2939. el[i].style.display = 'none';
  2940. }
  2941. return el;
  2942. }
  2943. /**
  2944. * Adds the display=block property for the passed element/s
  2945. */
  2946. function show(el){
  2947. el = getList(el);
  2948. for(var i = 0; i<el.length; i++){
  2949. el[i].style.display = 'block';
  2950. }
  2951. return el;
  2952. }
  2953. /**
  2954. * Checks if the passed element is an iterable element or not
  2955. */
  2956. function isArrayOrList(el){
  2957. return Object.prototype.toString.call( el ) === '[object Array]' ||
  2958. Object.prototype.toString.call( el ) === '[object NodeList]';
  2959. }
  2960. /**
  2961. * Adds the passed class to the passed element/s
  2962. */
  2963. function addClass(el, className) {
  2964. el = getList(el);
  2965. for(var i = 0; i<el.length; i++){
  2966. var item = el[i];
  2967. if (item.classList){
  2968. item.classList.add(className);
  2969. }
  2970. else{
  2971. item.className += ' ' + className;
  2972. }
  2973. }
  2974. return el;
  2975. }
  2976. /**
  2977. * Removes the passed class to the passed element/s
  2978. * @param {String} `className` can be multiple classnames separated by whitespace
  2979. */
  2980. function removeClass(el, className){
  2981. el = getList(el);
  2982. var classNames = className.split(' ');
  2983. for(var a = 0; a<classNames.length; a++){
  2984. className = classNames[a];
  2985. for(var i = 0; i<el.length; i++){
  2986. var item = el[i];
  2987. if (item.classList){
  2988. item.classList.remove(className);
  2989. }
  2990. else{
  2991. item.className = item.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
  2992. }
  2993. }
  2994. }
  2995. return el;
  2996. }
  2997. /**
  2998. * Appends the given element ot the given parent.
  2999. */
  3000. function appendTo(el, parent){
  3001. parent.appendChild(el);
  3002. }
  3003. /**
  3004. Usage:
  3005. var wrapper = document.createElement('div');
  3006. wrapper.className = 'fp-slides';
  3007. wrap($('.slide'), wrapper);
  3008. https://jsfiddle.net/qwzc7oy3/15/ (vanilla)
  3009. https://jsfiddle.net/oya6ndka/1/ (jquery equivalent)
  3010. */
  3011. function wrap(toWrap, wrapper, isWrapAll) {
  3012. var newParent;
  3013. wrapper = wrapper || document.createElement('div');
  3014. for(var i = 0; i < toWrap.length; i++){
  3015. var item = toWrap[i];
  3016. if(isWrapAll && !i || !isWrapAll){
  3017. newParent = wrapper.cloneNode(true);
  3018. item.parentNode.insertBefore(newParent, item);
  3019. }
  3020. newParent.appendChild(item);
  3021. }
  3022. return toWrap;
  3023. }
  3024. /**
  3025. Usage:
  3026. var wrapper = document.createElement('div');
  3027. wrapper.className = 'fp-slides';
  3028. wrap($('.slide'), wrapper);
  3029. https://jsfiddle.net/qwzc7oy3/27/ (vanilla)
  3030. https://jsfiddle.net/oya6ndka/4/ (jquery equivalent)
  3031. */
  3032. function wrapAll(toWrap, wrapper) {
  3033. wrap(toWrap, wrapper, true);
  3034. }
  3035. /**
  3036. * Usage:
  3037. * wrapInner(document.querySelector('#pepe'), '<div class="test">afdas</div>');
  3038. * wrapInner(document.querySelector('#pepe'), element);
  3039. *
  3040. * https://jsfiddle.net/zexxz0tw/6/
  3041. *
  3042. * https://stackoverflow.com/a/21817590/1081396
  3043. */
  3044. function wrapInner(parent, wrapper) {
  3045. if (typeof wrapper === "string"){
  3046. wrapper = createElementFromHTML(wrapper);
  3047. }
  3048. parent.appendChild(wrapper);
  3049. while(parent.firstChild !== wrapper){
  3050. wrapper.appendChild(parent.firstChild);
  3051. }
  3052. }
  3053. /**
  3054. * http://stackoverflow.com/questions/22100853/dom-pure-javascript-solution-to-jquery-closest-implementation
  3055. * Returns the element or `false` if there's none
  3056. */
  3057. function closest(el, selector) {
  3058. if(el && el.nodeType === 1){
  3059. if(matches(el, selector)){
  3060. return el;
  3061. }
  3062. return closest(el.parentNode, selector);
  3063. }
  3064. return null;
  3065. }
  3066. /**
  3067. * Places one element (rel) after another one or group of them (reference).
  3068. * @param {HTMLElement} reference
  3069. * @param {HTMLElement|NodeList|String} el
  3070. * https://jsfiddle.net/9s97hhzv/1/
  3071. */
  3072. function after(reference, el) {
  3073. insertBefore(reference, reference.nextSibling, el);
  3074. }
  3075. /**
  3076. * Places one element (rel) before another one or group of them (reference).
  3077. * @param {HTMLElement} reference
  3078. * @param {HTMLElement|NodeList|String} el
  3079. * https://jsfiddle.net/9s97hhzv/1/
  3080. */
  3081. function before(reference, el) {
  3082. insertBefore(reference, reference, el);
  3083. }
  3084. /**
  3085. * Based in https://stackoverflow.com/a/19316024/1081396
  3086. * and https://stackoverflow.com/a/4793630/1081396
  3087. */
  3088. function insertBefore(reference, beforeElement, el){
  3089. if(!isArrayOrList(el)){
  3090. if(typeof el == 'string'){
  3091. el = createElementFromHTML(el);
  3092. }
  3093. el = [el];
  3094. }
  3095. for(var i = 0; i<el.length; i++){
  3096. reference.parentNode.insertBefore(el[i], beforeElement);
  3097. }
  3098. }
  3099. //http://stackoverflow.com/questions/3464876/javascript-get-window-x-y-position-for-scroll
  3100. function getScrollTop(){
  3101. var doc = document.documentElement;
  3102. return (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
  3103. }
  3104. /**
  3105. * Gets the siblings of the passed element
  3106. */
  3107. function siblings(el){
  3108. return Array.prototype.filter.call(el.parentNode.children, function(child){
  3109. return child !== el;
  3110. });
  3111. }
  3112. //for IE 9 ?
  3113. function preventDefault(event){
  3114. if(event.preventDefault){
  3115. event.preventDefault();
  3116. }
  3117. else{
  3118. event.returnValue = false;
  3119. }
  3120. }
  3121. /**
  3122. * Determines whether the passed item is of function type.
  3123. */
  3124. function isFunction(item) {
  3125. if (typeof item === 'function') {
  3126. return true;
  3127. }
  3128. var type = Object.prototype.toString(item);
  3129. return type === '[object Function]' || type === '[object GeneratorFunction]';
  3130. }
  3131. /**
  3132. * Trigger custom events
  3133. */
  3134. function trigger(el, eventName, data){
  3135. var event;
  3136. data = typeof data === 'undefined' ? {} : data;
  3137. // Native
  3138. if(typeof window.CustomEvent === "function" ){
  3139. event = new CustomEvent(eventName, {detail: data});
  3140. }
  3141. else{
  3142. event = document.createEvent('CustomEvent');
  3143. event.initCustomEvent(eventName, true, true, data);
  3144. }
  3145. el.dispatchEvent(event);
  3146. }
  3147. /**
  3148. * Polyfill of .matches()
  3149. */
  3150. function matches(el, selector) {
  3151. return (el.matches || el.matchesSelector || el.msMatchesSelector || el.mozMatchesSelector || el.webkitMatchesSelector || el.oMatchesSelector).call(el, selector);
  3152. }
  3153. /**
  3154. * Toggles the visibility of the passed element el.
  3155. */
  3156. function toggle(el, value){
  3157. if(typeof value === "boolean"){
  3158. for(var i = 0; i<el.length; i++){
  3159. el[i].style.display = value ? 'block' : 'none';
  3160. }
  3161. }
  3162. //we don't use it in other way, so no else :)
  3163. return el;
  3164. }
  3165. /**
  3166. * Creates a HTMLElement from the passed HTML string.
  3167. * https://stackoverflow.com/a/494348/1081396
  3168. */
  3169. function createElementFromHTML(htmlString) {
  3170. var div = document.createElement('div');
  3171. div.innerHTML = htmlString.trim();
  3172. // Change this to div.childNodes to support multiple top-level nodes
  3173. return div.firstChild;
  3174. }
  3175. /**
  3176. * Removes the passed item/s from the DOM.
  3177. */
  3178. function remove(items){
  3179. items = getList(items);
  3180. for(var i = 0; i<items.length; i++){
  3181. var item = items[i];
  3182. if(item && item.parentElement) {
  3183. item.parentNode.removeChild(item);
  3184. }
  3185. }
  3186. }
  3187. /**
  3188. * Filters an array by the passed filter funtion.
  3189. */
  3190. function filter(el, filterFn){
  3191. Array.prototype.filter.call(el, filterFn);
  3192. }
  3193. //https://jsfiddle.net/w1rktecz/
  3194. function untilAll(item, selector, fn){
  3195. var sibling = item[fn];
  3196. var siblings = [];
  3197. while(sibling){
  3198. if(matches(sibling, selector) || selector == null) {
  3199. siblings.push(sibling);
  3200. }
  3201. sibling = sibling[fn];
  3202. }
  3203. return siblings;
  3204. }
  3205. /**
  3206. * Gets all next elements matching the passed selector.
  3207. */
  3208. function nextAll(item, selector){
  3209. return untilAll(item, selector, 'nextElementSibling');
  3210. }
  3211. /**
  3212. * Gets all previous elements matching the passed selector.
  3213. */
  3214. function prevAll(item, selector){
  3215. return untilAll(item, selector, 'previousElementSibling');
  3216. }
  3217. /**
  3218. * Converts an object to an array.
  3219. */
  3220. function toArray(objectData){
  3221. return Object.keys(objectData).map(function(key) {
  3222. return objectData[key];
  3223. });
  3224. }
  3225. /**
  3226. * forEach polyfill for IE
  3227. * https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach#Browser_Compatibility
  3228. */
  3229. if (window.NodeList && !NodeList.prototype.forEach) {
  3230. NodeList.prototype.forEach = function (callback, thisArg) {
  3231. thisArg = thisArg || window;
  3232. for (var i = 0; i < this.length; i++) {
  3233. callback.call(thisArg, this[i], i, this);
  3234. }
  3235. };
  3236. }
  3237. //utils are public, so we can use it wherever we want
  3238. window.fp_utils = {
  3239. $: $,
  3240. deepExtend: deepExtend,
  3241. hasClass: hasClass,
  3242. getWindowHeight: getWindowHeight,
  3243. css: css,
  3244. until: until,
  3245. prevUntil: prevUntil,
  3246. nextUntil: nextUntil,
  3247. prev: prev,
  3248. next: next,
  3249. last: last,
  3250. index: index,
  3251. getList: getList,
  3252. hide: hide,
  3253. show: show,
  3254. isArrayOrList: isArrayOrList,
  3255. addClass: addClass,
  3256. removeClass: removeClass,
  3257. appendTo: appendTo,
  3258. wrap: wrap,
  3259. wrapAll: wrapAll,
  3260. wrapInner: wrapInner,
  3261. closest: closest,
  3262. after: after,
  3263. before: before,
  3264. insertBefore: insertBefore,
  3265. getScrollTop: getScrollTop,
  3266. siblings: siblings,
  3267. preventDefault: preventDefault,
  3268. isFunction: isFunction,
  3269. trigger: trigger,
  3270. matches: matches,
  3271. toggle: toggle,
  3272. createElementFromHTML: createElementFromHTML,
  3273. remove: remove,
  3274. filter: filter,
  3275. untilAll: untilAll,
  3276. nextAll: nextAll,
  3277. prevAll: prevAll,
  3278. showError: showError
  3279. };
  3280. return initialise;
  3281. }));
  3282. /**
  3283. * jQuery adapter for fullPage.js 3.0.0
  3284. */
  3285. if(window.jQuery && window.fullpage){
  3286. (function ($, fullpage) {
  3287. 'use strict';
  3288. // No jQuery No Go
  3289. if (!$ || !fullpage) {
  3290. window.fp_utils.showError('error', 'jQuery is required to use the jQuery fullpage adapter!');
  3291. return;
  3292. }
  3293. $.fn.fullpage = function(options) {
  3294. var FP = new fullpage('#' + $(this).attr('id'), options);
  3295. //Static API
  3296. Object.keys(FP).forEach(function (key) {
  3297. $.fn.fullpage[key] = FP[key];
  3298. });
  3299. };
  3300. })(window.jQuery, window.fullpage);
  3301. }