jquery.fullPage.min.js 145 KB

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