-
Notifications
You must be signed in to change notification settings - Fork 27
/
jquery.fullPage.js
executable file
·2946 lines (2443 loc) · 111 KB
/
jquery.fullPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* fullPage 2.9.6
* https://github.com/alvarotrigo/fullPage.js
* @license MIT licensed
*
* Copyright (C) 2015 alvarotrigo.com - A project by Alvaro Trigo
*/
(function(global, factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
define(['jquery'], function($) {
return factory($, global, global.document, global.Math);
});
} else if (typeof exports === "object" && exports) {
module.exports = factory(require('jquery'), global, global.document, global.Math);
} else {
factory(jQuery, global, global.document, global.Math);
}
})(typeof window !== 'undefined' ? window : this, function($, window, document, Math, undefined) {
'use strict';
// keeping central set of classnames and selectors
var WRAPPER = 'fullpage-wrapper';
var WRAPPER_SEL = '.' + WRAPPER;
// slimscroll
var SCROLLABLE = 'fp-scrollable';
var SCROLLABLE_SEL = '.' + SCROLLABLE;
// util
var RESPONSIVE = 'fp-responsive';
var NO_TRANSITION = 'fp-notransition';
var DESTROYED = 'fp-destroyed';
var ENABLED = 'fp-enabled';
var VIEWING_PREFIX = 'fp-viewing';
var ACTIVE = 'active';
var ACTIVE_SEL = '.' + ACTIVE;
var COMPLETELY = 'fp-completely';
var COMPLETELY_SEL = '.' + COMPLETELY;
// section
var SECTION_DEFAULT_SEL = '.section';
var SECTION = 'fp-section';
var SECTION_SEL = '.' + SECTION;
var SECTION_ACTIVE_SEL = SECTION_SEL + ACTIVE_SEL;
var SECTION_FIRST_SEL = SECTION_SEL + ':first';
var SECTION_LAST_SEL = SECTION_SEL + ':last';
var TABLE_CELL = 'fp-tableCell';
var TABLE_CELL_SEL = '.' + TABLE_CELL;
var AUTO_HEIGHT = 'fp-auto-height';
var AUTO_HEIGHT_SEL = '.fp-auto-height';
var NORMAL_SCROLL = 'fp-normal-scroll';
var NORMAL_SCROLL_SEL = '.fp-normal-scroll';
// section nav
var SECTION_NAV = 'fp-nav';
var SECTION_NAV_SEL = '#' + SECTION_NAV;
var SECTION_NAV_TOOLTIP = 'fp-tooltip';
var SECTION_NAV_TOOLTIP_SEL='.'+SECTION_NAV_TOOLTIP;
var SHOW_ACTIVE_TOOLTIP = 'fp-show-active';
// slide
var SLIDE_DEFAULT_SEL = '.slide';
var SLIDE = 'fp-slide';
var SLIDE_SEL = '.' + SLIDE;
var SLIDE_ACTIVE_SEL = SLIDE_SEL + ACTIVE_SEL;
var SLIDES_WRAPPER = 'fp-slides';
var SLIDES_WRAPPER_SEL = '.' + SLIDES_WRAPPER;
var SLIDES_CONTAINER = 'fp-slidesContainer';
var SLIDES_CONTAINER_SEL = '.' + SLIDES_CONTAINER;
var TABLE = 'fp-table';
// slide nav
var SLIDES_NAV = 'fp-slidesNav';
var SLIDES_NAV_SEL = '.' + SLIDES_NAV;
var SLIDES_NAV_LINK_SEL = SLIDES_NAV_SEL + ' a';
var SLIDES_ARROW = 'fp-controlArrow';
var SLIDES_ARROW_SEL = '.' + SLIDES_ARROW;
var SLIDES_PREV = 'fp-prev';
var SLIDES_PREV_SEL = '.' + SLIDES_PREV;
var SLIDES_ARROW_PREV = SLIDES_ARROW + ' ' + SLIDES_PREV;
var SLIDES_ARROW_PREV_SEL = SLIDES_ARROW_SEL + SLIDES_PREV_SEL;
var SLIDES_NEXT = 'fp-next';
var SLIDES_NEXT_SEL = '.' + SLIDES_NEXT;
var SLIDES_ARROW_NEXT = SLIDES_ARROW + ' ' + SLIDES_NEXT;
var SLIDES_ARROW_NEXT_SEL = SLIDES_ARROW_SEL + SLIDES_NEXT_SEL;
var $window = $(window);
var $document = $(document);
$.fn.fullpage = function(options) {
//only once my friend!
if($('html').hasClass(ENABLED)){ displayWarnings(); return; }
// common jQuery objects
var $htmlBody = $('html, body');
var $body = $('body');
var FP = $.fn.fullpage;
// Creating some defaults, extending them with any options that were provided
options = $.extend({
//ADDED BY ME
considerHeader: false,
header: null,
//navigation
menu: false,
anchors:[],
lockAnchors: false,
navigation: false,
navigationPosition: 'right',
navigationTooltips: [],
showActiveTooltip: false,
slidesNavigation: false,
slidesNavPosition: 'bottom',
scrollBar: false,
hybrid: false,
//scrolling
css3: true,
scrollingSpeed: 700,
autoScrolling: true,
fitToSection: true,
fitToSectionDelay: 1000,
easing: 'easeInOutCubic',
easingcss3: 'ease',
loopBottom: false,
loopTop: false,
loopHorizontal: true,
continuousVertical: false,
continuousHorizontal: false,
scrollHorizontally: false,
interlockedSlides: false,
dragAndMove: false,
offsetSections: false,
resetSliders: false,
fadingEffect: false,
normalScrollElements: null,
scrollOverflow: false,
scrollOverflowReset: false,
scrollOverflowHandler: $.fn.fp_scrolloverflow ? $.fn.fp_scrolloverflow.iscrollHandler : null,
scrollOverflowOptions: null,
touchSensitivity: 5,
normalScrollElementTouchThreshold: 5,
bigSectionsDestination: null,
//Accessibility
keyboardScrolling: true,
animateAnchor: true,
recordHistory: true,
//design
controlArrows: true,
controlArrowColor: '#fff',
verticalCentered: true,
sectionsColor : [],
paddingTop: 0,
paddingBottom: 0,
fixedElements: null,
responsive: 0, //backwards compabitility with responsiveWiddth
responsiveWidth: 0,
responsiveHeight: 0,
responsiveSlides: false,
parallax: false,
parallaxOptions: {
type: 'reveal',
percentage: 62,
property: 'translate'
},
//Custom selectors
sectionSelector: SECTION_DEFAULT_SEL,
slideSelector: SLIDE_DEFAULT_SEL,
//events
afterLoad: null,
onLeave: null,
afterRender: null,
afterResize: null,
afterReBuild: null,
afterSlideLoad: null,
onSlideLeave: null,
afterResponsive: null,
lazyLoading: true
}, options);
//flag to avoid very fast sliding for landscape sliders
var slideMoving = false;
var isTouchDevice = navigator.userAgent.match(/(iPhone|iPod|iPad|Android|playbook|silk|BlackBerry|BB10|Windows Phone|Tizen|Bada|webOS|IEMobile|Opera Mini)/);
var isTouch = (('ontouchstart' in window) || (navigator.msMaxTouchPoints > 0) || (navigator.maxTouchPoints));
var container = $(this);
// MOD BY ME
var windowsHeight = options.considerHeader ? ( $window.height() - $(options.header).height() ) : $window.height();
var isResizing = false;
var isWindowFocused = true;
var lastScrolledDestiny;
var lastScrolledSlide;
var canScroll = true;
var scrollings = [];
var controlPressed;
var startingSection;
var isScrollAllowed = {};
isScrollAllowed.m = { 'up':true, 'down':true, 'left':true, 'right':true };
isScrollAllowed.k = $.extend(true,{}, isScrollAllowed.m);
var MSPointer = getMSPointer();
var events = {
touchmove: 'ontouchmove' in window ? 'touchmove' : MSPointer.move,
touchstart: 'ontouchstart' in window ? 'touchstart' : MSPointer.down
};
var scrollBarHandler;
// taken from https://github.com/udacity/ud891/blob/gh-pages/lesson2-focus/07-modals-and-keyboard-traps/solution/modal.js
var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
//timeouts
var resizeId;
var afterSectionLoadsId;
var afterSlideLoadsId;
var scrollId;
var scrollId2;
var keydownId;
var originals = $.extend(true, {}, options); //deep copy
displayWarnings();
//easeInOutCubic animation included in the plugin
$.extend($.easing,{ easeInOutCubic: function (x, t, b, c, d) {if ((t/=d/2) < 1) return c/2*t*t*t + b;return c/2*((t-=2)*t*t + 2) + b;}});
/**
* Sets the autoScroll option.
* It changes the scroll bar visibility and the history of the site as a result.
*/
function setAutoScrolling(value, type){
//removing the transformation
if(!value){
silentScroll(0);
}
setVariableState('autoScrolling', value, type);
var element = $(SECTION_ACTIVE_SEL);
if(options.autoScrolling && !options.scrollBar){
$htmlBody.css({
'overflow' : 'hidden',
'height' : '100%'
});
setRecordHistory(originals.recordHistory, 'internal');
//for IE touch devices
container.css({
'-ms-touch-action': 'none',
'touch-action': 'none'
});
if(element.length){
//moving the container up
silentScroll(element.position().top);
}
}else{
$htmlBody.css({
'overflow' : 'visible',
'height' : 'initial'
});
setRecordHistory(false, 'internal');
//for IE touch devices
container.css({
'-ms-touch-action': '',
'touch-action': ''
});
//scrolling the page to the section with no animation
if (element.length) {
$htmlBody.scrollTop(element.position().top);
}
}
}
/**
* Defines wheter to record the history for each hash change in the URL.
*/
function setRecordHistory(value, type){
setVariableState('recordHistory', value, type);
}
/**
* Defines the scrolling speed
*/
function setScrollingSpeed(value, type){
setVariableState('scrollingSpeed', value, type);
}
/**
* Sets fitToSection
*/
function setFitToSection(value, type){
setVariableState('fitToSection', value, type);
}
/**
* Sets lockAnchors
*/
function setLockAnchors(value){
options.lockAnchors = value;
}
/**
* Adds or remove the possibility of scrolling through sections by using the mouse wheel or the trackpad.
*/
function setMouseWheelScrolling(value){
if(value){
addMouseWheelHandler();
addMiddleWheelHandler();
}else{
removeMouseWheelHandler();
removeMiddleWheelHandler();
}
}
/**
* Adds or remove the possibility of scrolling through sections by using the mouse wheel/trackpad or touch gestures.
* Optionally a second parameter can be used to specify the direction for which the action will be applied.
*
* @param directions string containing the direction or directions separated by comma.
*/
function setAllowScrolling(value, directions){
if(typeof directions !== 'undefined'){
directions = directions.replace(/ /g,'').split(',');
$.each(directions, function (index, direction){
setIsScrollAllowed(value, direction, 'm');
});
}
else{
setIsScrollAllowed(value, 'all', 'm');
if(value){
setMouseWheelScrolling(true);
addTouchHandler();
}else{
setMouseWheelScrolling(false);
removeTouchHandler();
}
}
}
/**
* Adds or remove the possibility of scrolling through sections by using the keyboard arrow keys
*/
function setKeyboardScrolling(value, directions){
if(typeof directions !== 'undefined'){
directions = directions.replace(/ /g,'').split(',');
$.each(directions, function (index, direction){
setIsScrollAllowed(value, direction, 'k');
});
}else{
setIsScrollAllowed(value, 'all', 'k');
options.keyboardScrolling = value;
}
}
/**
* Moves the page up one section.
*/
function moveSectionUp(){
var prev = $(SECTION_ACTIVE_SEL).prev(SECTION_SEL);
//looping to the bottom if there's no more sections above
if (!prev.length && (options.loopTop || options.continuousVertical)) {
prev = $(SECTION_SEL).last();
}
if (prev.length) {
scrollPage(prev, null, true);
}
}
/**
* Moves the page down one section.
*/
function moveSectionDown(){
var next = $(SECTION_ACTIVE_SEL).next(SECTION_SEL);
//looping to the top if there's no more sections below
if(!next.length &&
(options.loopBottom || options.continuousVertical)){
next = $(SECTION_SEL).first();
}
if(next.length){
scrollPage(next, null, false);
}
}
/**
* Moves the page to the given section and slide with no animation.
* Anchors or index positions can be used as params.
*/
function silentMoveTo(sectionAnchor, slideAnchor){
setScrollingSpeed (0, 'internal');
moveTo(sectionAnchor, slideAnchor);
setScrollingSpeed (originals.scrollingSpeed, 'internal');
}
/**
* Moves the page to the given section and slide.
* Anchors or index positions can be used as params.
*/
function moveTo(sectionAnchor, slideAnchor){
var destiny = getSectionByAnchor(sectionAnchor);
if (typeof slideAnchor !== 'undefined'){
scrollPageAndSlide(sectionAnchor, slideAnchor);
}else if(destiny.length > 0){
scrollPage(destiny);
}
}
/**
* Slides right the slider of the active section.
* Optional `section` param.
*/
function moveSlideRight(section){
moveSlide('right', section);
}
/**
* Slides left the slider of the active section.
* Optional `section` param.
*/
function moveSlideLeft(section){
moveSlide('left', section);
}
/**
* When resizing is finished, we adjust the slides sizes and positions
*/
function reBuild(resizing, isResizingHeader, newHeaderHeight){
if(container.hasClass(DESTROYED)){ return; } //nothing to do if the plugin was destroyed
isResizing = true;
//windowsHeight = $window.height(); //updating global var
// MOD BY ME
windowsHeight = options.considerHeader ? ( $window.height() - $(options.header).height() ) : $window.height();
$(SECTION_SEL).each(function(){
var slidesWrap = $(this).find(SLIDES_WRAPPER_SEL);
var slides = $(this).find(SLIDE_SEL);
//adjusting the height of the table-cell for IE and Firefox
if(options.verticalCentered){
$(this).find(TABLE_CELL_SEL).css('height', getTableHeight($(this)) + 'px');
}
$(this).css('height', windowsHeight + 'px');
// ADDED BY ME
if(isResizingHeader) {
$(this).css('padding-top', newHeaderHeight);
}
//adjusting the position fo the FULL WIDTH slides...
if (slides.length > 1) {
landscapeScroll(slidesWrap, slidesWrap.find(SLIDE_ACTIVE_SEL));
}
});
if(options.scrollOverflow){
scrollBarHandler.createScrollBarForAll();
}
var activeSection = $(SECTION_ACTIVE_SEL);
var sectionIndex = activeSection.index(SECTION_SEL);
//isn't it the first section?
if(sectionIndex){
//adjusting the position for the current section
silentMoveTo(sectionIndex + 1);
}
isResizing = false;
$.isFunction( options.afterResize ) && resizing && options.afterResize.call(container);
$.isFunction( options.afterReBuild ) && !resizing && options.afterReBuild.call(container);
}
/**
* Turns fullPage.js to normal scrolling mode when the viewport `width` or `height`
* are smaller than the set limit values.
*/
function setResponsive(active){
var isResponsive = $body.hasClass(RESPONSIVE);
if(active){
if(!isResponsive){
setAutoScrolling(false, 'internal');
setFitToSection(false, 'internal');
$(SECTION_NAV_SEL).hide();
$body.addClass(RESPONSIVE);
$.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
}
}
else if(isResponsive){
setAutoScrolling(originals.autoScrolling, 'internal');
setFitToSection(originals.autoScrolling, 'internal');
$(SECTION_NAV_SEL).show();
$body.removeClass(RESPONSIVE);
$.isFunction( options.afterResponsive ) && options.afterResponsive.call( container, active);
}
}
if($(this).length){
//public functions
FP.version = '2.9.5';
FP.setAutoScrolling = setAutoScrolling;
FP.setRecordHistory = setRecordHistory;
FP.setScrollingSpeed = setScrollingSpeed;
FP.setFitToSection = setFitToSection;
FP.setLockAnchors = setLockAnchors;
FP.setMouseWheelScrolling = setMouseWheelScrolling;
FP.setAllowScrolling = setAllowScrolling;
FP.setKeyboardScrolling = setKeyboardScrolling;
FP.moveSectionUp = moveSectionUp;
FP.moveSectionDown = moveSectionDown;
FP.silentMoveTo = silentMoveTo;
FP.moveTo = moveTo;
FP.moveSlideRight = moveSlideRight;
FP.moveSlideLeft = moveSlideLeft;
FP.fitToSection = fitToSection;
FP.reBuild = reBuild;
FP.setResponsive = setResponsive;
FP.destroy = destroy;
//functions we want to share across files but which are not
//mean to be used on their own by developers
FP.shared ={
afterRenderActions: afterRenderActions
};
init();
bindEvents();
}
function init(){
//if css3 is not supported, it will use jQuery animations
if(options.css3){
options.css3 = support3d();
}
options.scrollBar = options.scrollBar || options.hybrid;
setOptionsFromDOM();
prepareDom();
setAllowScrolling(true);
setAutoScrolling(options.autoScrolling, 'internal');
responsive();
//setting the class for the body element
setBodyClass();
if(document.readyState === 'complete'){
scrollToAnchor();
}
$window.on('load', scrollToAnchor);
}
function bindEvents(){
$window
//when scrolling...
.on('scroll', scrollHandler)
//detecting any change on the URL to scroll to the given anchor link
//(a way to detect back history button as we play with the hashes on the URL)
.on('hashchange', hashChangeHandler)
//when opening a new tab (ctrl + t), `control` won't be pressed when coming back.
.blur(blurHandler)
//when resizing the site, we adjust the heights of the sections, slimScroll...
.resize(resizeHandler);
$document
//Sliding with arrow keys, both, vertical and horizontal
.keydown(keydownHandler)
//to prevent scrolling while zooming
.keyup(keyUpHandler)
//Scrolls to the section when clicking the navigation bullet
.on('click touchstart', SECTION_NAV_SEL + ' a', sectionBulletHandler)
//Scrolls the slider to the given slide destination for the given section
.on('click touchstart', SLIDES_NAV_LINK_SEL, slideBulletHandler)
.on('click', SECTION_NAV_TOOLTIP_SEL, tooltipTextHandler);
//Scrolling horizontally when clicking on the slider controls.
$(SECTION_SEL).on('click touchstart', SLIDES_ARROW_SEL, slideArrowHandler);
/**
* Applying normalScroll elements.
* Ignoring the scrolls over the specified selectors.
*/
if(options.normalScrollElements){
$document.on('mouseenter touchstart', options.normalScrollElements, function () {
setAllowScrolling(false);
});
$document.on('mouseleave touchend', options.normalScrollElements, function(){
setAllowScrolling(true);
});
}
}
/**
* Setting options from DOM elements if they are not provided.
*/
function setOptionsFromDOM(){
var sections = container.find(options.sectionSelector);
//no anchors option? Checking for them in the DOM attributes
if(!options.anchors.length){
options.anchors = sections.filter('[data-anchor]').map(function(){
return $(this).data('anchor').toString();
}).get();
}
//no tooltips option? Checking for them in the DOM attributes
if(!options.navigationTooltips.length){
options.navigationTooltips = sections.filter('[data-tooltip]').map(function(){
return $(this).data('tooltip').toString();
}).get();
}
}
/**
* Works over the DOM structure to set it up for the current fullpage options.
*/
function prepareDom(){
if(!options.considerHeader) {
container.css({
'height': '100%',
'position': 'relative'
});
}
else {
container.css({
'height': windowsHeight,
'position': 'relative'
});
}
//adding a class to recognize the container internally in the code
container.addClass(WRAPPER);
$('html').addClass(ENABLED);
//due to https://github.com/alvarotrigo/fullPage.js/issues/1502
//windowsHeight = $window.height();
// MOD BY ME
windowsHeight = options.considerHeader ? ( $window.height() - $(options.header).height() ) : $window.height();
container.removeClass(DESTROYED); //in case it was destroyed before initializing it again
addInternalSelectors();
//styling the sections / slides / menu
$(SECTION_SEL).each(function(index){
var section = $(this);
var slides = section.find(SLIDE_SEL);
var numSlides = slides.length;
//caching the original styles to add them back on destroy('all')
section.data('fp-styles', section.attr('style'));
styleSection(section, index);
styleMenu(section, index);
// if there's any slide
if (numSlides > 0) {
styleSlides(section, slides, numSlides);
}else{
if(options.verticalCentered){
addTableClass(section);
}
}
});
//fixed elements need to be moved out of the plugin container due to problems with CSS3.
if(options.fixedElements && options.css3){
$(options.fixedElements).appendTo($body);
}
//vertical centered of the navigation + active bullet
if(options.navigation){
addVerticalNavigation();
}
enableYoutubeAPI();
if(options.scrollOverflow){
scrollBarHandler = options.scrollOverflowHandler.init(options);
}else{
afterRenderActions();
}
}
/**
* Styles the horizontal slides for a section.
*/
function styleSlides(section, slides, numSlides){
var sliderWidth = numSlides * 100;
var slideWidth = 100 / numSlides;
slides.wrapAll('<div class="' + SLIDES_CONTAINER + '" />');
slides.parent().wrap('<div class="' + SLIDES_WRAPPER + '" />');
section.find(SLIDES_CONTAINER_SEL).css('width', sliderWidth + '%');
if(numSlides > 1){
if(options.controlArrows){
createSlideArrows(section);
}
if(options.slidesNavigation){
addSlidesNavigation(section, numSlides);
}
}
slides.each(function(index) {
$(this).css('width', slideWidth + '%');
if(options.verticalCentered){
addTableClass($(this));
}
});
var startingSlide = section.find(SLIDE_ACTIVE_SEL);
//if the slide won't be an starting point, the default will be the first one
//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.
if( startingSlide.length && ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) !== 0 || ($(SECTION_ACTIVE_SEL).index(SECTION_SEL) === 0 && startingSlide.index() !== 0))){
silentLandscapeScroll(startingSlide, 'internal');
}else{
slides.eq(0).addClass(ACTIVE);
}
}
/**
* Styling vertical sections
*/
function styleSection(section, index){
//if no active section is defined, the 1st one will be the default one
if(!index && $(SECTION_ACTIVE_SEL).length === 0) {
section.addClass(ACTIVE);
}
startingSection = $(SECTION_ACTIVE_SEL);
section.css('height', windowsHeight + 'px');
if(options.paddingTop){
section.css('padding-top', options.paddingTop);
}
if(options.paddingBottom){
section.css('padding-bottom', options.paddingBottom);
}
if (typeof options.sectionsColor[index] !== 'undefined') {
section.css('background-color', options.sectionsColor[index]);
}
if (typeof options.anchors[index] !== 'undefined') {
section.attr('data-anchor', options.anchors[index]);
}
}
/**
* Sets the data-anchor attributes to the menu elements and activates the current one.
*/
function styleMenu(section, index){
if (typeof options.anchors[index] !== 'undefined') {
//activating the menu / nav element on load
if(section.hasClass(ACTIVE)){
activateMenuAndNav(options.anchors[index], index);
}
}
//moving the menu outside the main container if it is inside (avoid problems with fixed positions when using CSS3 tranforms)
if(options.menu && options.css3 && $(options.menu).closest(WRAPPER_SEL).length){
$(options.menu).appendTo($body);
}
}
/**
* Adds internal classes to be able to provide customizable selectors
* keeping the link with the style sheet.
*/
function addInternalSelectors(){
container.find(options.sectionSelector).addClass(SECTION);
container.find(options.slideSelector).addClass(SLIDE);
}
/**
* Creates the control arrows for the given section
*/
function createSlideArrows(section){
section.find(SLIDES_WRAPPER_SEL).after('<div class="' + SLIDES_ARROW_PREV + '"></div><div class="' + SLIDES_ARROW_NEXT + '"></div>');
if(options.controlArrowColor!='#fff'){
section.find(SLIDES_ARROW_NEXT_SEL).css('border-color', 'transparent transparent transparent '+options.controlArrowColor);
section.find(SLIDES_ARROW_PREV_SEL).css('border-color', 'transparent '+ options.controlArrowColor + ' transparent transparent');
}
if(!options.loopHorizontal){
section.find(SLIDES_ARROW_PREV_SEL).hide();
}
}
/**
* Creates a vertical navigation bar.
*/
function addVerticalNavigation(){
$body.append('<div id="' + SECTION_NAV + '"><ul></ul></div>');
var nav = $(SECTION_NAV_SEL);
nav.addClass(function() {
return options.showActiveTooltip ? SHOW_ACTIVE_TOOLTIP + ' ' + options.navigationPosition : options.navigationPosition;
});
for (var i = 0; i < $(SECTION_SEL).length; i++) {
var link = '';
if (options.anchors.length) {
link = options.anchors[i];
}
var li = '<li><a href="#' + link + '"><span></span></a>';
// Only add tooltip if needed (defined by user)
var tooltip = options.navigationTooltips[i];
if (typeof tooltip !== 'undefined' && tooltip !== '') {
li += '<div class="' + SECTION_NAV_TOOLTIP + ' ' + options.navigationPosition + '">' + tooltip + '</div>';
}
li += '</li>';
nav.find('ul').append(li);
}
//centering it vertically
$(SECTION_NAV_SEL).css('margin-top', '-' + ($(SECTION_NAV_SEL).height()/2) + 'px');
//activating the current active section
$(SECTION_NAV_SEL).find('li').eq($(SECTION_ACTIVE_SEL).index(SECTION_SEL)).find('a').addClass(ACTIVE);
}
/*
* Enables the Youtube videos API so we can control their flow if necessary.
*/
function enableYoutubeAPI(){
container.find('iframe[src*="youtube.com/embed/"]').each(function(){
addURLParam($(this), 'enablejsapi=1');
});
}
/**
* Adds a new parameter and its value to the `src` of a given element
*/
function addURLParam(element, newParam){
var originalSrc = element.attr('src');
element.attr('src', originalSrc + getUrlParamSign(originalSrc) + newParam);
}
/*
* Returns the prefix sign to use for a new parameter in an existen URL.
*
* @return {String} ? | &
*/
function getUrlParamSign(url){
return ( !/\?/.test( url ) ) ? '?' : '&';
}
/**
* Actions and callbacks to fire afterRender
*/
function afterRenderActions(){
var section = $(SECTION_ACTIVE_SEL);
section.addClass(COMPLETELY);
lazyLoad(section);
playMedia(section);
if(options.scrollOverflow){
options.scrollOverflowHandler.afterLoad();
}
if(isDestinyTheStartingSection()){
$.isFunction( options.afterLoad ) && options.afterLoad.call(section, section.data('anchor'), (section.index(SECTION_SEL) + 1));
}
$.isFunction( options.afterRender ) && options.afterRender.call(container);
}
/**
* Determines if the URL anchor destiny is the starting section (the one using 'active' class before initialization)
*/
function isDestinyTheStartingSection(){
var destinationSection = getSectionByAnchor(getAnchorsURL().section);
return !destinationSection || destinationSection.length && destinationSection.index() === startingSection.index();
}
var isScrolling = false;
var lastScroll = 0;
//when scrolling...
function scrollHandler(){
var currentSection;
if(!options.autoScrolling || options.scrollBar){
var currentScroll = $window.scrollTop();
var scrollDirection = getScrollDirection(currentScroll);
var visibleSectionIndex = 0;
var screen_mid = currentScroll + ($window.height() / 2.0);
var isAtBottom = $body.height() - $window.height() === currentScroll;
var sections = document.querySelectorAll(SECTION_SEL);
//when using `auto-height` for a small last section it won't be centered in the viewport
if(isAtBottom){
visibleSectionIndex = sections.length - 1;
}
//is at top? when using `auto-height` for a small first section it won't be centered in the viewport
else if(!currentScroll){
visibleSectionIndex = 0;
}
//taking the section which is showing more content in the viewport
else{
for (var i = 0; i < sections.length; ++i) {
var section = sections[i];
// Pick the the last section which passes the middle line of the screen.
if (section.offsetTop <= screen_mid)
{
visibleSectionIndex = i;
}
}
}
if(isCompletelyInViewPort(scrollDirection)){
if(!$(SECTION_ACTIVE_SEL).hasClass(COMPLETELY)){
$(SECTION_ACTIVE_SEL).addClass(COMPLETELY).siblings().removeClass(COMPLETELY);
}
}
//geting the last one, the current one on the screen
currentSection = $(sections).eq(visibleSectionIndex);
//setting the visible section as active when manually scrolling
//executing only once the first time we reach the section
if(!currentSection.hasClass(ACTIVE)){
isScrolling = true;
var leavingSection = $(SECTION_ACTIVE_SEL);
var leavingSectionIndex = leavingSection.index(SECTION_SEL) + 1;
var yMovement = getYmovement(currentSection);
var anchorLink = currentSection.data('anchor');
var sectionIndex = currentSection.index(SECTION_SEL) + 1;
var activeSlide = currentSection.find(SLIDE_ACTIVE_SEL);
var slideIndex;
var slideAnchorLink;
if(activeSlide.length){
slideAnchorLink = activeSlide.data('anchor');
slideIndex = activeSlide.index();
}
if(canScroll){
currentSection.addClass(ACTIVE).siblings().removeClass(ACTIVE);
$.isFunction( options.onLeave ) && options.onLeave.call( leavingSection, leavingSectionIndex, sectionIndex, yMovement);
$.isFunction( options.afterLoad ) && options.afterLoad.call( currentSection, anchorLink, sectionIndex);
stopMedia(leavingSection);
lazyLoad(currentSection);
playMedia(currentSection);