forked from fossasia/gci17.fossasia.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
1578 lines (1328 loc) · 57.2 KB
/
scripts.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
var mr_firstSectionHeight,
mr_nav,
mr_fixedAt,
mr_navOuterHeight,
mr_navScrolled = false,
mr_navFixed = false,
mr_outOfSight = false,
mr_floatingProjectSections,
mr_scrollTop = 0;
$(document).ready(function() {
"use strict";
// Diplsay no projects if there are no projects
var html = '<div class="row"><div class="col-sm-12 text-center">';
html += '<h4 class="uppercase mb16">No Student Projects</h4>';
html += '<p class="lead mb64">There are no student projects uploaded to website yet</p></div></div>';
if ($(".student_project").length == 0) {
$("#project_holder").append(html);
}
// Smooth scroll to inner links
var innerLinks = $('a.inner-link');
if (innerLinks.length) {
innerLinks.each(function() {
var link = $(this);
var href = link.attr('href');
if (href.charAt(0) !== "#") {
link.removeClass('inner-link');
}
});
var offset = 0;
if ($('body[data-smooth-scroll-offset]').length) {
offset = $('body').attr('data-smooth-scroll-offset');
offset = offset * 1;
}
smoothScroll.init({
selector: '.inner-link',
selectorHeader: null,
speed: 750,
easing: 'easeInOutCubic',
offset: offset
});
}
// Update scroll variable for scrolling functions
addEventListener('scroll', function() {
mr_scrollTop = window.pageYOffset;
}, false);
// Append .background-image-holder <img>'s as CSS backgrounds
$('.background-image-holder').each(function() {
var imgSrc = $(this).children('img').attr('src');
$(this).css('background', 'url("' + imgSrc + '")');
$(this).children('img').hide();
$(this).css('background-position', 'initial');
});
// Fade in background images
setTimeout(function() {
$('.background-image-holder').each(function() {
$(this).addClass('fadeIn');
});
}, 200);
// Initialize Tooltips
$('[data-toggle="tooltip"]').tooltip();
//Initialize popover
$("[data-toggle=popover]").popover({
html: true
})
// Icon bulleted lists
$('ul[data-bullet]').each(function() {
var bullet = $(this).attr('data-bullet');
$(this).find('li').prepend('<i class="' + bullet + '"></i>');
});
// Progress Bars
$('.progress-bar').each(function() {
$(this).css('width', $(this).attr('data-progress') + '%');
});
// Navigation
if (!$('nav').hasClass('fixed') && !$('nav').hasClass('absolute')) {
// Make nav container height of nav
$('.nav-container').css('min-height', $('nav').outerHeight(true));
$(window).resize(function() {
$('.nav-container').css('min-height', $('nav').outerHeight(true));
});
// Compensate the height of parallax element for inline nav
if ($(window).width() > 768) {
$('.parallax:nth-of-type(1) .background-image-holder').css('top', -($('nav').outerHeight(true)));
}
// Adjust fullscreen elements
if ($(window).width() > 768) {
$('section.fullscreen:nth-of-type(1)').css('height', ($(window).height() - $('nav').outerHeight(true)));
}
} else {
$('body').addClass('nav-is-overlay');
}
if ($('nav').hasClass('bg-dark')) {
$('.nav-container').addClass('bg-dark');
}
// Fix nav to top while scrolling
mr_nav = $('body .nav-container nav:first');
mr_navOuterHeight = $('body .nav-container nav:first').outerHeight();
mr_fixedAt = typeof mr_nav.attr('data-fixed-at') !== typeof undefined ? parseInt(mr_nav.attr('data-fixed-at').replace('px', '')) : parseInt($('section:nth-of-type(1)').outerHeight());
window.addEventListener("scroll", updateNav, false);
// Menu dropdown positioning
$('.menu > li > ul').each(function() {
var menu = $(this).offset();
var farRight = menu.left + $(this).outerWidth(true);
if (farRight > $(window).width() && !$(this).hasClass('mega-menu')) {
$(this).addClass('make-right');
} else if (farRight > $(window).width() && $(this).hasClass('mega-menu')) {
var isOnScreen = $(window).width() - menu.left;
var difference = $(this).outerWidth(true) - isOnScreen;
$(this).css('margin-left', -(difference));
}
});
// Mobile Menu
$('.mobile-toggle').click(function() {
$('.nav-bar').toggleClass('nav-open');
$(this).toggleClass('active');
});
$('.menu li').click(function(e) {
if (!e) e = window.event;
e.stopPropagation();
if ($(this).find('ul').length) {
$(this).toggleClass('toggle-sub');
} else {
$(this).parents('.toggle-sub').removeClass('toggle-sub');
}
});
$('.menu li a').click(function() {
if ($(this).hasClass('inner-link')) {
$(this).closest('.nav-bar').removeClass('nav-open');
}
});
$('.module.widget-handle').click(function() {
$(this).toggleClass('toggle-widget-handle');
});
$('.search-widget-handle .search-form input').click(function(e) {
if (!e) e = window.event;
e.stopPropagation();
});
// Offscreen Nav
if ($('.offscreen-toggle').length) {
$('body').addClass('has-offscreen-nav');
} else {
$('body').removeClass('has-offscreen-nav');
}
$('.offscreen-toggle').click(function() {
$('.main-container').toggleClass('reveal-nav');
$('nav').toggleClass('reveal-nav');
$('.offscreen-container').toggleClass('reveal-nav');
});
$('.main-container').click(function() {
if ($(this).hasClass('reveal-nav')) {
$(this).removeClass('reveal-nav');
$('.offscreen-container').removeClass('reveal-nav');
$('nav').removeClass('reveal-nav');
}
});
$('.offscreen-container a').click(function() {
$('.offscreen-container').removeClass('reveal-nav');
$('.main-container').removeClass('reveal-nav');
$('nav').removeClass('reveal-nav');
});
// Populate filters
$('.projects').each(function() {
var filters = "";
$(this).find('.project').each(function() {
var filterTags = $(this).attr('data-filter').split(',');
filterTags.forEach(function(tagName) {
if (filters.indexOf(tagName) == -1) {
filters += '<li data-filter="' + tagName + '">' + capitaliseFirstLetter(tagName) + '</li>';
}
});
$(this).closest('.projects')
.find('ul.filters').empty().append('<li data-filter="all" class="active">All</li>').append(filters);
});
});
$('.filters li').click(function() {
var filter = $(this).attr('data-filter');
$(this).closest('.filters').find('li').removeClass('active');
$(this).addClass('active');
$(this).closest('.projects').find('.project').each(function() {
var filters = $(this).attr('data-filter');
if (filters.indexOf(filter) == -1) {
$(this).addClass('inactive');
} else {
$(this).removeClass('inactive');
}
});
if (filter == 'all') {
$(this).closest('.projects').find('.project').removeClass('inactive');
}
});
// Twitter Feed
$('.tweets-feed').each(function(index) {
jQuery(this).attr('id', 'tweets-' + index);
}).each(function(index) {
var element = $('#tweets-' + index);
var TweetConfig = {
"domId": '',
"maxTweets": element.attr('data-amount'),
"enableLinks": true,
"showUser": true,
"showTime": true,
"dateFunction": '',
"showRetweet": false,
"customCallback": handleTweets
};
if (typeof element.attr('data-widget-id') !== typeof undefined) {
TweetConfig.id = element.attr('data-widget-id');
} else if (typeof element.attr('data-feed-name') !== typeof undefined && element.attr('data-feed-name') !== "") {
TweetConfig.profile = {
"screenName": element.attr('data-feed-name').replace('@', '')
};
} else {
TweetConfig.profile = {
"screenName": 'twitter'
};
}
function handleTweets(tweets) {
var x = tweets.length;
var n = 0;
var element = document.getElementById('tweets-' + index);
var html = '<ul class="slides">';
while (n < x) {
html += '<li>' + tweets[n] + '</li>';
n++;
}
html += '</ul>';
element.innerHTML = html;
if ($('.tweets-slider').length) {
$('.tweets-slider').flexslider({
directionNav: false,
controlNav: false
});
}
return html;
}
twitterFetcher.fetch(TweetConfig);
});
// Instagram Feed
if ($('.instafeed').length) {
jQuery.fn.spectragram.accessData = {
accessToken: '1406933036.dc95b96.2ed56eddc62f41cbb22c1573d58625a2',
clientID: '87e6d2b8a0ef4c7ab8bc45e80ddd0c6a'
};
$('.instafeed').each(function() {
var feedID = $(this).attr('data-user-name');
$(this).children('ul').spectragram('getUserFeed', {
query: feedID,
max: 12
});
});
}
// Flickr Feeds
if ($('.flickr-feed').length) {
$('.flickr-feed').each(function() {
var userID = $(this).attr('data-user-id');
var albumID = $(this).attr('data-album-id');
$(this).flickrPhotoStream({
id: userID,
setId: albumID,
container: '<li class="masonry-item" />'
});
setTimeout(function() {
initializeMasonry();
window.dispatchEvent(new Event('resize'));
}, 1000);
});
}
// Image Sliders
if ($('.slider-all-controls, .slider-paging-controls, .slider-arrow-controls, .slider-thumb-controls, .logo-carousel').length) {
$('.slider-all-controls').flexslider({
start: function(slider) {
if (slider.find('.slides li:first-child').find('.fs-vid-background video').length) {
slider.find('.slides li:first-child').find('.fs-vid-background video').get(0).play();
}
},
after: function(slider) {
if (slider.find('.fs-vid-background video').length) {
if (slider.find('li:not(.flex-active-slide)').find('.fs-vid-background video').length) {
slider.find('li:not(.flex-active-slide)').find('.fs-vid-background video').get(0).pause();
}
if (slider.find('.flex-active-slide').find('.fs-vid-background video').length) {
slider.find('.flex-active-slide').find('.fs-vid-background video').get(0).play();
}
}
}
});
$('.slider-paging-controls').flexslider({
animation: "slide",
directionNav: false
});
$('.slider-arrow-controls').flexslider({
controlNav: false
});
$('.slider-thumb-controls .slides li').each(function() {
var imgSrc = $(this).find('img').attr('src');
$(this).attr('data-thumb', imgSrc);
});
$('.slider-thumb-controls').flexslider({
animation: "slide",
controlNav: "thumbnails",
directionNav: true
});
$('.logo-carousel').flexslider({
minItems: 1,
maxItems: 4,
move: 1,
itemWidth: 200,
itemMargin: 0,
animation: "slide",
slideshow: true,
slideshowSpeed: 3000,
directionNav: false,
controlNav: false
});
}
// Lightbox gallery titles
$('.lightbox-grid li a').each(function() {
var galleryTitle = $(this).closest('.lightbox-grid').attr('data-gallery-title');
$(this).attr('data-lightbox', galleryTitle);
});
// Prepare embedded video modals
$('iframe[data-provider]').each(function() {
var provider = jQuery(this).attr('data-provider');
var videoID = jQuery(this).attr('data-video-id');
var autoplay = jQuery(this).attr('data-autoplay');
var vidURL = '';
if (provider == 'vimeo') {
vidURL = "https://player.vimeo.com/video/" + videoID + "?badge=0&title=0&byline=0&title=0&autoplay=" + autoplay;
$(this).attr('data-src', vidURL);
} else if (provider == 'youtube') {
vidURL = "https://www.youtube.com/embed/" + videoID + "?showinfo=0&autoplay=" + autoplay;
$(this).attr('data-src', vidURL);
} else {
console.log('Only Vimeo and Youtube videos are supported at this time');
}
});
// Multipurpose Modals
jQuery('.foundry_modal[modal-link]').remove();
if ($('.foundry_modal').length && (!jQuery('.modal-screen').length)) {
// Add a div.modal-screen if there isn't already one there.
var modalScreen = jQuery('<div />').addClass('modal-screen').appendTo('body');
}
jQuery('.foundry_modal').click(function() {
jQuery(this).addClass('modal-acknowledged');
});
jQuery(document).on('wheel mousewheel scroll', '.foundry_modal, .modal-screen', function(evt) {
$(this).get(0).scrollTop += (evt.originalEvent.deltaY);
return false;
});
$('.modal-container:not([modal-link])').each(function(index) {
if (jQuery(this).find('iframe[src]').length) {
jQuery(this).find('.foundry_modal').addClass('iframe-modal');
var iframe = jQuery(this).find('iframe');
iframe.attr('data-src', iframe.attr('src'));
iframe.attr('src', '');
}
jQuery(this).find('.btn-modal').attr('modal-link', index);
// Only clone and append to body if there isn't already one there
if (!jQuery('.foundry_modal[modal-link="' + index + '"]').length) {
jQuery(this).find('.foundry_modal').clone().appendTo('body').attr('modal-link', index).prepend(jQuery('<i class="ti-close close-modal">'));
}
});
$('.btn-modal').unbind('click').click(function() {
var linkedModal = jQuery('.foundry_modal[modal-link="' + jQuery(this).attr('modal-link') + '"]'),
autoplayMsg = "";
jQuery('.modal-screen').toggleClass('reveal-modal');
if (linkedModal.find('iframe').length) {
if (linkedModal.find('iframe').attr('data-autoplay') === '1') {
var autoplayMsg = '&autoplay=1'
}
linkedModal.find('iframe').attr('src', (linkedModal.find('iframe').attr('data-src') + autoplayMsg));
}
if (linkedModal.find('video').length) {
linkedModal.find('video').get(0).play();
}
linkedModal.toggleClass('reveal-modal');
return false;
});
// Autoshow modals
$('.foundry_modal[data-time-delay]').each(function() {
var modal = $(this);
var delay = modal.attr('data-time-delay');
modal.prepend($('<i class="ti-close close-modal">'));
if (typeof modal.attr('data-cookie') != "undefined") {
if (!mr_cookies.hasItem(modal.attr('data-cookie'))) {
setTimeout(function() {
modal.addClass('reveal-modal');
$('.modal-screen').addClass('reveal-modal');
}, delay);
}
} else {
setTimeout(function() {
modal.addClass('reveal-modal');
$('.modal-screen').addClass('reveal-modal');
}, delay);
}
});
// Exit modals
$('.foundry_modal[data-show-on-exit]').each(function() {
var modal = $(this);
var exitSelector = $(modal.attr('data-show-on-exit'));
// If a valid selector is found, attach leave event to show modal.
if ($(exitSelector).length) {
modal.prepend($('<i class="ti-close close-modal">'));
$(document).on('mouseleave', exitSelector, function() {
if (!$('body .reveal-modal').length) {
if (typeof modal.attr('data-cookie') !== typeof undefined) {
if (!mr_cookies.hasItem(modal.attr('data-cookie'))) {
modal.addClass('reveal-modal');
$('.modal-screen').addClass('reveal-modal');
}
} else {
modal.addClass('reveal-modal');
$('.modal-screen').addClass('reveal-modal');
}
}
});
}
});
// Autoclose modals
$('.foundry_modal[data-hide-after]').each(function() {
var modal = $(this);
var delay = modal.attr('data-hide-after');
if (typeof modal.attr('data-cookie') != "undefined") {
if (!mr_cookies.hasItem(modal.attr('data-cookie'))) {
setTimeout(function() {
if (!modal.hasClass('modal-acknowledged')) {
modal.removeClass('reveal-modal');
$('.modal-screen').removeClass('reveal-modal');
}
}, delay);
}
} else {
setTimeout(function() {
if (!modal.hasClass('modal-acknowledged')) {
modal.removeClass('reveal-modal');
$('.modal-screen').removeClass('reveal-modal');
}
}, delay);
}
});
jQuery('.close-modal:not(.modal-strip .close-modal)').unbind('click').click(function() {
var modal = jQuery(this).closest('.foundry_modal');
modal.toggleClass('reveal-modal');
if (typeof modal.attr('data-cookie') !== "undefined") {
mr_cookies.setItem(modal.attr('data-cookie'), "true", Infinity);
}
if (modal.find('iframe').length) {
modal.find('iframe').attr('src', '');
}
jQuery('.modal-screen').removeClass('reveal-modal');
});
jQuery('.modal-screen').unbind('click').click(function() {
if (jQuery('.foundry_modal.reveal-modal').find('iframe').length) {
jQuery('.foundry_modal.reveal-modal').find('iframe').attr('src', '');
}
jQuery('.foundry_modal.reveal-modal').toggleClass('reveal-modal');
jQuery(this).toggleClass('reveal-modal');
});
jQuery(document).keyup(function(e) {
if (e.keyCode == 27) { // escape key maps to keycode `27`
if (jQuery('.foundry_modal').find('iframe').length) {
jQuery('.foundry_modal').find('iframe').attr('src', '');
}
jQuery('.foundry_modal').removeClass('reveal-modal');
jQuery('.modal-screen').removeClass('reveal-modal');
}
});
// Modal Strips
jQuery('.modal-strip').each(function() {
if (!jQuery(this).find('.close-modal').length) {
jQuery(this).append(jQuery('<i class="ti-close close-modal">'));
}
var modal = jQuery(this);
if (typeof modal.attr('data-cookie') != "undefined") {
if (!mr_cookies.hasItem(modal.attr('data-cookie'))) {
setTimeout(function() {
modal.addClass('reveal-modal');
}, 1000);
}
} else {
setTimeout(function() {
modal.addClass('reveal-modal');
}, 1000);
}
});
jQuery('.modal-strip .close-modal').click(function() {
var modal = jQuery(this).closest('.modal-strip');
if (typeof modal.attr('data-cookie') != "undefined") {
mr_cookies.setItem(modal.attr('data-cookie'), "true", Infinity);
}
jQuery(this).closest('.modal-strip').removeClass('reveal-modal');
return false;
});
// Video Modals
jQuery('.close-iframe').click(function() {
jQuery(this).closest('.modal-video').removeClass('reveal-modal');
jQuery(this).siblings('iframe').attr('src', '');
jQuery(this).siblings('video').get(0).pause();
});
// Checkboxes
$('.checkbox-option').on("click", function() {
$(this).toggleClass('checked');
var checkbox = $(this).find('input');
if (checkbox.prop('checked') === false) {
checkbox.prop('checked', true);
} else {
checkbox.prop('checked', false);
}
});
// Radio Buttons
$('.radio-option').click(function() {
var checked = $(this).hasClass('checked'); // Get the current status of the radio
var name = $(this).find('input').attr('name'); // Get the name of the input clicked
if (!checked) {
$('input[name="' + name + '"]').parent().removeClass('checked');
$(this).addClass('checked');
$(this).find('input').prop('checked', true);
}
});
// Accordions
$('.accordion li').click(function() {
if ($(this).closest('.accordion').hasClass('one-open')) {
$(this).closest('.accordion').find('li').removeClass('active');
$(this).addClass('active');
} else {
$(this).toggleClass('active');
}
if (typeof window.mr_parallax !== "undefined") {
setTimeout(mr_parallax.windowLoad, 500);
}
});
// Tabbed Content
$('.tabbed-content').each(function() {
$(this).append('<ul class="content"></ul>');
});
$('.tabs li').each(function() {
var originalTab = $(this),
activeClass = "";
if (originalTab.is('.tabs>li:first-child')) {
activeClass = ' class="active"';
}
var tabContent = originalTab.find('.tab-content').detach().wrap('<li' + activeClass + '></li>').parent();
originalTab.closest('.tabbed-content').find('.content').append(tabContent);
});
$('.tabs li').click(function() {
$(this).closest('.tabs').find('li').removeClass('active');
$(this).addClass('active');
var liIndex = $(this).index() + 1;
$(this).closest('.tabbed-content').find('.content>li').removeClass('active');
$(this).closest('.tabbed-content').find('.content>li:nth-of-type(' + liIndex + ')').addClass('active');
});
// Local Videos
$('section').closest('body').find('.local-video-container .play-button').click(function() {
$(this).siblings('.background-image-holder').removeClass('fadeIn');
$(this).siblings('.background-image-holder').css('z-index', -1);
$(this).css('opacity', 0);
$(this).siblings('video').get(0).play();
});
// Youtube Videos
$('section').closest('body').find('.player').each(function() {
var section = $(this).closest('section');
section.find('.container').addClass('fadeOut');
var src = $(this).attr('data-video-id');
var startat = $(this).attr('data-start-at');
$(this).attr('data-property', "{videoURL:'https://youtu.be/" + src + "',containment:'self',autoPlay:true, mute:true, startAt:" + startat + ", opacity:1, showControls:false}");
});
if ($('.player').length) {
$('.player').each(function() {
var section = $(this).closest('section');
var player = section.find('.player');
player.YTPlayer();
player.on("YTPStart", function(e) {
section.find('.container').removeClass('fadeOut');
section.find('.masonry-loader').addClass('fadeOut');
});
});
}
// Interact with Map once the user has clicked (to prevent scrolling the page = zooming the map
$('.map-holder').click(function() {
$(this).addClass('interact');
});
if ($('.map-holder').length) {
$(window).scroll(function() {
if ($('.map-holder.interact').length) {
$('.map-holder.interact').removeClass('interact');
}
});
}
// Countdown Timers
if ($('.countdown').length) {
$('.countdown').each(function() {
var date = $(this).attr('data-date');
$(this).countdown(date, function(event) {
$(this).text(
event.strftime('%D days %H:%M:%S')
);
});
});
}
// //
// //
// Contact form code //
// //
// //
$('form.form-email, form.form-newsletter').submit(function(e) {
// return false so form submits through jQuery rather than reloading page.
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
var thisForm = $(this).closest('form.form-email, form.form-newsletter'),
submitButton = thisForm.find('button[type="submit"]'),
error = 0,
originalError = thisForm.attr('original-error'),
preparedForm, iFrame, userEmail, userFullName, userFirstName, userLastName, successRedirect, formError, formSuccess;
// Mailchimp/Campaign Monitor Mail List Form Scripts
iFrame = $(thisForm).find('iframe.mail-list-form');
thisForm.find('.form-error, .form-success').remove();
submitButton.attr('data-text', submitButton.text());
thisForm.append('<div class="form-error" style="display: none;">' + thisForm.attr('data-error') + '</div>');
thisForm.append('<div class="form-success" style="display: none;">' + thisForm.attr('data-success') + '</div>');
formError = thisForm.find('.form-error');
formSuccess = thisForm.find('.form-success');
thisForm.addClass('attempted-submit');
// Do this if there is an iframe, and it contains usable Mail Chimp / Campaign Monitor iframe embed code
if ((iFrame.length) && (typeof iFrame.attr('srcdoc') !== "undefined") && (iFrame.attr('srcdoc') !== "")) {
console.log('Mail list form signup detected.');
if (typeof originalError !== typeof undefined && originalError !== false) {
formError.html(originalError);
}
userEmail = $(thisForm).find('.signup-email-field').val();
userFullName = $(thisForm).find('.signup-name-field').val();
if ($(thisForm).find('input.signup-first-name-field').length) {
userFirstName = $(thisForm).find('input.signup-first-name-field').val();
} else {
userFirstName = $(thisForm).find('.signup-name-field').val();
}
userLastName = $(thisForm).find('.signup-last-name-field').val();
// validateFields returns 1 on error;
if (validateFields(thisForm) !== 1) {
preparedForm = prepareSignup(iFrame);
preparedForm.find('#mce-EMAIL, #fieldEmail').val(userEmail);
preparedForm.find('#mce-LNAME, #fieldLastName').val(userLastName);
preparedForm.find('#mce-FNAME, #fieldFirstName').val(userFirstName);
preparedForm.find('#mce-NAME, #fieldName').val(userFullName);
thisForm.removeClass('attempted-submit');
// Hide the error if one was shown
formError.fadeOut(200);
// Create a new loading spinner in the submit button.
submitButton.html(jQuery('<div />').addClass('form-loading')).attr('disabled', 'disabled');
try {
$.ajax({
url: preparedForm.attr('action'),
crossDomain: true,
data: preparedForm.serialize(),
method: "GET",
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data) {
// Request was a success, what was the response?
if (data.result != "success" && data.Status != 200) {
// Error from Mail Chimp or Campaign Monitor
// Keep the current error text in a data attribute on the form
formError.attr('original-error', formError.text());
// Show the error with the returned error text.
formError.html(data.msg).fadeIn(1000);
formSuccess.fadeOut(1000);
submitButton.html(submitButton.attr('data-text')).removeAttr('disabled');
} else {
// Got Success from Mail Chimp
submitButton.html(submitButton.attr('data-text')).removeAttr('disabled');
successRedirect = thisForm.attr('success-redirect');
// For some browsers, if empty `successRedirect` is undefined; for others,
// `successRedirect` is false. Check for both.
if (typeof successRedirect !== typeof undefined && successRedirect !== false && successRedirect !== "") {
window.location = successRedirect;
}
thisForm.find('input[type="text"]').val("");
thisForm.find('textarea').val("");
formSuccess.fadeIn(1000);
formError.fadeOut(1000);
setTimeout(function() {
formSuccess.fadeOut(500);
}, 5000);
}
}
});
} catch (err) {
// Keep the current error text in a data attribute on the form
formError.attr('original-error', formError.text());
// Show the error with the returned error text.
formError.html(err.message).fadeIn(1000);
formSuccess.fadeOut(1000);
setTimeout(function() {
formError.fadeOut(500);
}, 5000);
submitButton.html(submitButton.attr('data-text')).removeAttr('disabled');
}
} else {
formError.fadeIn(1000);
setTimeout(function() {
formError.fadeOut(500);
}, 5000);
}
} else {
// If no iframe detected then this is treated as an email form instead.
console.log('Send email form detected.');
if (typeof originalError !== typeof undefined && originalError !== false) {
formError.text(originalError);
}
error = validateFields(thisForm);
if (error === 1) {
formError.fadeIn(200);
setTimeout(function() {
formError.fadeOut(500);
}, 3000);
} else {
thisForm.removeClass('attempted-submit');
// Hide the error if one was shown
formError.fadeOut(200);
// Create a new loading spinner in the submit button.
submitButton.html(jQuery('<div />').addClass('form-loading')).attr('disabled', 'disabled');
jQuery.ajax({
type: "POST",
url: "mail/mail.php",
data: thisForm.serialize() + "&url=" + window.location.href,
success: function(response) {
// Swiftmailer always sends back a number representing numner of emails sent.
// If this is numeric (not Swift Mailer error text) AND greater than 0 then show success message.
submitButton.html(submitButton.attr('data-text')).removeAttr('disabled');
if ($.isNumeric(response)) {
if (parseInt(response) > 0) {
// For some browsers, if empty 'successRedirect' is undefined; for others,
// 'successRedirect' is false. Check for both.
successRedirect = thisForm.attr('success-redirect');
if (typeof successRedirect !== typeof undefined && successRedirect !== false && successRedirect !== "") {
window.location = successRedirect;
}
thisForm.find('input[type="text"]').val("");
thisForm.find('textarea').val("");
thisForm.find('.form-success').fadeIn(1000);
formError.fadeOut(1000);
setTimeout(function() {
formSuccess.fadeOut(500);
}, 5000);
}
}
// If error text was returned, put the text in the .form-error div and show it.
else {
// Keep the current error text in a data attribute on the form
formError.attr('original-error', formError.text());
// Show the error with the returned error text.
formError.text(response).fadeIn(1000);
formSuccess.fadeOut(1000);
}
},
error: function(errorObject, errorText, errorHTTP) {
// Keep the current error text in a data attribute on the form
formError.attr('original-error', formError.text());
// Show the error with the returned error text.
formError.text(errorHTTP).fadeIn(1000);
formSuccess.fadeOut(1000);
submitButton.html(submitButton.attr('data-text')).removeAttr('disabled');
}
});
}
}
return false;
});
$('.validate-required, .validate-email').on('blur change', function() {
validateFields($(this).closest('form'));
});
$('form').each(function() {
if ($(this).find('.form-error').length) {
$(this).attr('original-error', $(this).find('.form-error').text());
}
});
function validateFields(form) {
var name, error, originalErrorMessage;
$(form).find('.validate-required[type="checkbox"]').each(function() {
if (!$('[name="' + $(this).attr('name') + '"]:checked').length) {
error = 1;
name = $(this).attr('name').replace('[]', '');
form.find('.form-error').text('Please tick at least one ' + name + ' box.');
}
});
$(form).find('.validate-required').each(function() {
if ($(this).val() === '') {
$(this).addClass('field-error');
error = 1;
} else {
$(this).removeClass('field-error');
}
});
$(form).find('.validate-email').each(function() {
if (!(/(.+)@(.+){2,}\.(.+){2,}/.test($(this).val()))) {
$(this).addClass('field-error');
error = 1;
} else {
$(this).removeClass('field-error');
}
});
if (!form.find('.field-error').length) {
form.find('.form-error').fadeOut(1000);
}
return error;
}
//
//
// End contact form code
//
//
// Get referrer from URL string
if (getURLParameter("ref")) {
$('form.form-email').append('<input type="text" name="referrer" class="hidden" value="' + getURLParameter("ref") + '"/>');
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
}
// Disable parallax on mobile
if ((/Android|iPhone|iPad|iPod|BlackBerry|Windows Phone/i).test(navigator.userAgent || navigator.vendor || window.opera)) {