-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
2963 lines (2282 loc) · 110 KB
/
scripts.js
File metadata and controls
2963 lines (2282 loc) · 110 KB
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
window.mr = window.mr || {};
mr = (function (mr, $, window, document){
"use strict";
mr = mr || {};
var components = {documentReady: [],documentReadyDeferred: [], windowLoad: [], windowLoadDeferred: []};
mr.status = {documentReadyRan: false, windowLoadPending: false};
$(document).ready(documentReady);
$(window).on("load", windowLoad);
function documentReady(context){
context = typeof context === typeof undefined ? $ : context;
components.documentReady.concat(components.documentReadyDeferred).forEach(function(component){
component(context);
});
mr.status.documentReadyRan = true;
if(mr.status.windowLoadPending){
windowLoad(mr.setContext());
}
}
function windowLoad(context){
if(mr.status.documentReadyRan){
mr.status.windowLoadPending = false;
context = typeof context === "object" ? $ : context;
components.windowLoad.concat(components.windowLoadDeferred).forEach(function(component){
component(context);
});
}else{
mr.status.windowLoadPending = true;
}
}
mr.setContext = function (contextSelector){
var context = $;
if(typeof contextSelector !== typeof undefined){
return function(selector){
return $(contextSelector).find(selector);
};
}
return context;
};
mr.components = components;
mr.documentReady = documentReady;
mr.windowLoad = windowLoad;
return mr;
}(window.mr, jQuery, window, document));
//////////////// Utility Functions
mr = (function (mr, $, window, document){
"use strict";
mr.util = {};
mr.util.requestAnimationFrame = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
mr.util.documentReady = function($){
var today = new Date();
var year = today.getFullYear();
$('.update-year').text(year);
};
mr.util.windowLoad = function($){
$('[data-delay-src]').each(function(){
var $el = $(this);
$el.attr('src', $el.attr('data-delay-src'));
$el.removeAttr('data-delay-src');
});
};
mr.util.getURLParameter = function(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [undefined, ""])[1].replace(/\+/g, '%20')) || null;
};
mr.util.capitaliseFirstLetter = function(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
};
mr.util.slugify = function(text, spacesOnly){
if(typeof spacesOnly !== typeof undefined){
return text.replace(/ +/g, '');
}else{
return text
.toLowerCase()
.replace(/[\~\!\@\#\$\%\^\&\*\(\)\-\_\=\+\]\[\}\{\'\"\;\\\:\?\/\>\<\.\,]+/g, '')
.replace(/ +/g, '-');
}
};
mr.util.sortChildrenByText = function(parentElement, reverse){
var $parentElement = $(parentElement);
var items = $parentElement.children().get();
var order = -1;
var order2 = 1;
if(typeof reverse !== typeof undefined){order = 1; order2 = -1;}
items.sort(function(a,b){
var keyA = $(a).text();
var keyB = $(b).text();
if (keyA < keyB) return order;
if (keyA > keyB) return order2;
return 0;
});
// Append back into place
$parentElement.empty();
$(items).each(function(i, itm){
$parentElement.append(itm);
});
};
// Set data-src attribute of element from src to be restored later
mr.util.idleSrc = function(context, selector){
selector = (typeof selector !== typeof undefined) ? selector : '';
var elems = context.is(selector+'[src]') ? context : context.find(selector+'[src]');
elems.each(function(index, elem){
elem = $(elem);
var currentSrc = elem.attr('src'),
dataSrc = elem.attr('data-src');
// If there is no data-src, save current source to it
if(typeof dataSrc === typeof undefined){
elem.attr('data-src', currentSrc);
}
// Clear the src attribute
elem.attr('src', '');
});
};
// Set src attribute of element from its data-src where it was temporarily stored earlier
mr.util.activateIdleSrc = function(context, selector){
selector = (typeof selector !== typeof undefined) ? selector : '';
var elems = context.is(selector+'[data-src]') ? context : context.find(selector+'[data-src]');
elems.each(function(index, elem){
elem = $(elem);
var dataSrc = elem.attr('data-src');
// Write the 'src' attribute using the 'data-src' value
elem.attr('src', dataSrc);
});
};
mr.util.pauseVideo = function(context){
var elems = context.is('video') ? context : context.find('video');
elems.each(function(index, video){
var playingVideo = $(video).get(0);
playingVideo.pause();
});
};
// Take a text value in either px (eg. 150px) or vh (eg. 65vh) and return a number in pixels.
mr.util.parsePixels = function(text){
var windowHeight = $(window).height(), value;
// Text text against regular expression for px value.
if(/^[1-9]{1}[0-9]*[p][x]$/.test(text)){
return parseInt(text.replace('px', ''),10);
}
// Otherwise it is vh value.
else if(/^[1-9]{1}[0-9]*[v][h]$/.test(text)){
value = parseInt(text.replace('vh', ''),10);
// Return conversion to percentage of window height.
return windowHeight * (value/100);
}else{
// If it is not proper text, return -1 to indicate bad value.
return -1;
}
};
mr.util.removeHash = function() {
// Removes hash from URL bar without reloading and without losing search query
history.pushState("", document.title, window.location.pathname + window.location.search);
}
mr.components.documentReady.push(mr.util.documentReady);
mr.components.windowLoad.push(mr.util.windowLoad);
return mr;
}(mr, jQuery, window, document));
//////////////// Window Functions
mr = (function (mr, $, window, document){
"use strict";
mr.window = {};
mr.window.height = $(window).height();
mr.window.width = $(window).width();
$(window).on('resize',function(){
mr.window.height = $(window).height();
mr.window.width = $(window).width();
});
return mr;
}(mr, jQuery, window, document));
//////////////// Scroll Functions
mr = (function (mr, $, window, document){
"use strict";
mr.scroll = {};
var raf = window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame;
mr.scroll.listeners = [];
mr.scroll.busy = false;
mr.scroll.y = 0;
mr.scroll.x = 0;
var documentReady = function($){
//////////////// Capture Scroll Event and fire scroll function
jQuery(window).off('scroll.mr');
jQuery(window).on('scroll.mr', function(evt) {
if(mr.scroll.busy === false){
mr.scroll.busy = true;
raf(function(evt){
mr.scroll.update(evt);
});
}
if(evt.stopPropagation){
evt.stopPropagation();
}
});
};
mr.scroll.update = function(event){
// Loop through all mr scroll listeners
var parallax = typeof window.mr_parallax !== typeof undefined ? true : false;
mr.scroll.y = (parallax ? mr_parallax.mr_getScrollPosition() : window.pageYOffset);
mr.scroll.busy = false;
if(parallax){
mr_parallax.mr_parallaxBackground();
}
if(mr.scroll.listeners.length > 0){
for (var i = 0, l = mr.scroll.listeners.length; i < l; i++) {
mr.scroll.listeners[i](event);
}
}
};
mr.scroll.documentReady = documentReady;
mr.components.documentReady.push(documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Scroll Class Modifier
mr = (function (mr, $, window, document){
"use strict";
mr.scroll.classModifiers = {};
// Globally accessible list of elements/rules
mr.scroll.classModifiers.rules = [];
mr.scroll.classModifiers.parseScrollRules = function(element){
var text = element.attr('data-scroll-class'),
rules = text.split(";");
rules.forEach(function(rule){
var ruleComponents, scrollPoint, ruleObject = {};
ruleComponents = rule.replace(/\s/g, "").split(':');
if(ruleComponents.length === 2){
scrollPoint = mr.util.parsePixels(ruleComponents[0]);
if(scrollPoint > -1){
ruleObject.scrollPoint = scrollPoint;
if(ruleComponents[1].length){
var toggleClass = ruleComponents[1];
ruleObject.toggleClass = toggleClass;
// Set variable in object to indicate that element already has class applied
ruleObject.hasClass = element.hasClass(toggleClass);
ruleObject.element = element.get(0);
mr.scroll.classModifiers.rules.push(ruleObject);
}else{
// Error: toggleClass component does not exist.
//console.log('Error - toggle class not found.');
return false;
}
}else{
// Error: scrollpoint component was malformed
//console.log('Error - Scrollpoint not found.');
return false;
}
}
});
if(mr.scroll.classModifiers.rules.length){
return true;
}else{
return false;
}
};
mr.scroll.classModifiers.update = function(event){
var currentScroll = mr.scroll.y,
scrollRules = mr.scroll.classModifiers.rules,
l = scrollRules.length,
currentRule;
// Given the current scrollPoint, check for necessary changes
while(l--) {
currentRule = scrollRules[l];
if(currentScroll > currentRule.scrollPoint && !currentRule.hasClass){
// Set local copy and glogal copy at the same time;
currentRule.element.classList.add(currentRule.toggleClass);
currentRule.hasClass = mr.scroll.classModifiers.rules[l].hasClass = true;
}
if(currentScroll < currentRule.scrollPoint && currentRule.hasClass){
// Set local copy and glogal copy at the same time;
currentRule.element.classList.remove(currentRule.toggleClass);
currentRule.hasClass = mr.scroll.classModifiers.rules[l].hasClass = false;
}
}
};
var fixedElementSizes = function(){
$('.main-container [data-scroll-class*="pos-fixed"]').each(function(){
var element = $(this);
element.css('max-width',element.parent().outerWidth());
element.parent().css('min-height',element.outerHeight());
});
};
var documentReady = function($){
// Collect info on all elements that require class modification at load time
// Each element has data-scroll-class with a formatted value to represent class to add/remove at a particular scroll point.
$('[data-scroll-class]').each(function(){
var element = $(this);
// Test the rules to be added to an array of rules.
if(!mr.scroll.classModifiers.parseScrollRules(element)){
console.log('Error parsing scroll rules on: '+element);
}
});
// For 'position fixed' elements, give them a max-width for correct fixing behaviour
fixedElementSizes();
$(window).on('resize', fixedElementSizes);
// If there are valid scroll rules add classModifiers update function to the scroll event processing queue.
if(mr.scroll.classModifiers.rules.length){
mr.scroll.listeners.push(mr.scroll.classModifiers.update);
}
};
mr.components.documentReady.push(documentReady);
mr.scroll.classModifiers.documentReady = documentReady;
return mr;
}(mr, jQuery, window, document));
//////////////// Accordions
mr = (function (mr, $, window, document){
"use strict";
mr.accordions = mr.accordions || {};
mr.accordions.documentReady = function($){
$('.accordion__title').on('click', function(){
mr.accordions.activatePanel($(this));
});
$('.accordion').each(function(){
var accordion = $(this);
var minHeight = accordion.outerHeight(true);
accordion.css('min-height',minHeight);
});
if(window.location.hash !== '' && window.location.hash !== '#' && window.location.hash.match(/#\/.*/) === null){
if($('.accordion > li > .accordion__title'+window.location.hash).length){
mr.accordions.activatePanelById(window.location.hash, true);
}
}
jQuery(document).on('click', 'a[href^="#"]:not(a[href="#"])', function(){
if($('.accordion > li > .accordion__title'+$(this).attr('href')).length){
mr.accordions.activatePanelById($(this).attr('href'), true);
}
});
};
mr.accordions.activatePanel = function(panel, forceOpen){
var $panel = $(panel),
accordion = $panel.closest('.accordion'),
li = $panel.closest('li'),
openEvent = document.createEvent('Event'),
closeEvent = document.createEvent('Event');
openEvent.initEvent('panelOpened.accordions.mr', true, true);
closeEvent.initEvent('panelClosed.accordions.mr', true, true);
if(li.hasClass('active')){
if(forceOpen !== true){
li.removeClass('active');
$panel.trigger('panelClosed.accordions.mr').get(0).dispatchEvent(closeEvent);
}
}else{
if(accordion.hasClass('accordion--oneopen')){
var wasActive = accordion.find('li.active');
if(wasActive.length){
wasActive.removeClass('active');
wasActive.trigger('panelClosed.accordions.mr').get(0).dispatchEvent(closeEvent);
}
li.addClass('active');
li.trigger('panelOpened.accordions.mr').get(0).dispatchEvent(openEvent);
}else{
if(!li.is('.active')){
li.trigger('panelOpened.accordions.mr').get(0).dispatchEvent(openEvent);
}
li.addClass('active');
}
}
};
mr.accordions.activatePanelById = function(id, forceOpen){
var panel;
if(id !== '' && id !== '#' && id.match(/#\/.*/) === null){
panel = $('.accordion > li > .accordion__title#'+id.replace('#', ''));
if(panel.length){
$('html, body').stop(true).animate({
scrollTop: (panel.offset().top - 50)
}, 1200);
mr.accordions.activatePanel(panel, forceOpen);
}
}
};
mr.components.documentReady.push(mr.accordions.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Alerts
mr = (function (mr, $, window, document){
"use strict";
mr.alerts = mr.alerts || {};
mr.alerts.documentReady = function($){
$('.alert__close').on('click touchstart', function(){
jQuery(this).closest('.alert').addClass('alert--dismissed');
});
};
mr.components.documentReady.push(mr.alerts.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Backgrounds
mr = (function (mr, $, window, document){
"use strict";
mr.backgrounds = mr.backgrounds || {};
mr.backgrounds.documentReady = function($){
//////////////// 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 + '")').css('background-position', 'initial').css('opacity','1');
});
};
mr.components.documentReady.push(mr.backgrounds.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Bars
mr = (function (mr, $, window, document){
"use strict";
mr.bars = mr.bars || {};
mr.bars.documentReady = function($){
$('.nav-container .bar[data-scroll-class*="fixed"]:not(.bar--absolute)').each(function(){
var bar = $(this),
barHeight = bar.outerHeight(true);
bar.closest('.nav-container').css('min-height',barHeight);
});
};
mr.components.documentReady.push(mr.bars.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Cookies
mr = (function (mr, $, window, document){
"use strict";
mr.cookies = {
getItem: function (sKey) {
if (!sKey) { return null; }
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
},
setItem: function (sKey, sValue, vEnd, sPath, sDomain, bSecure) {
if (!sKey || /^(?:expires|max\-age|path|domain|secure)$/i.test(sKey)) { return false; }
var sExpires = "";
if (vEnd) {
switch (vEnd.constructor) {
case Number:
sExpires = vEnd === Infinity ? "; expires=Fri, 31 Dec 9999 23:59:59 GMT" : "; max-age=" + vEnd;
break;
case String:
sExpires = "; expires=" + vEnd;
break;
case Date:
sExpires = "; expires=" + vEnd.toUTCString();
break;
}
}
document.cookie = encodeURIComponent(sKey) + "=" + encodeURIComponent(sValue) + sExpires + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "") + (bSecure ? "; secure" : "");
return true;
},
removeItem: function (sKey, sPath, sDomain) {
if (!this.hasItem(sKey)) { return false; }
document.cookie = encodeURIComponent(sKey) + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT" + (sDomain ? "; domain=" + sDomain : "") + (sPath ? "; path=" + sPath : "");
return true;
},
hasItem: function (sKey) {
if (!sKey) { return false; }
return (new RegExp("(?:^|;\\s*)" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=")).test(document.cookie);
},
keys: function () {
var aKeys = document.cookie.replace(/((?:^|\s*;)[^\=]+)(?=;|$)|^\s*|\s*(?:\=[^;]*)?(?:\1|$)/g, "").split(/\s*(?:\=[^;]*)?;\s*/);
for (var nLen = aKeys.length, nIdx = 0; nIdx < nLen; nIdx++) { aKeys[nIdx] = decodeURIComponent(aKeys[nIdx]); }
return aKeys;
}
};
return mr;
}(mr, jQuery, window, document));
//////////////// Countdown
mr = (function (mr, $, window, document){
"use strict";
mr.countdown = mr.countdown || {};
mr.countdown.options = mr.countdown.options || {};
mr.countdown.documentReady = function($){
$('.countdown[data-date]').each(function(){
var element = $(this),
date = element.attr('data-date'),
daysText = typeof element.attr('data-days-text') !== typeof undefined ? '%D '+element.attr('data-days-text')+' %H:%M:%S': '%D days %H:%M:%S',
daysText = typeof mr.countdown.options.format !== typeof undefined ? mr.countdown.options.format : daysText,
dateFormat = typeof element.attr('data-date-format') !== typeof undefined ? element.attr('data-date-format'): daysText,
fallback;
if(typeof element.attr('data-date-fallback') !== typeof undefined){
fallback = element.attr('data-date-fallback') || "Timer Done";
}
element.countdown(date, function(event) {
if(event.elapsed){
element.text(fallback);
}else{
element.text(
event.strftime(dateFormat)
);
}
});
});
};
mr.components.documentReadyDeferred.push(mr.countdown.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Datepicker
mr = (function (mr, $, window, document){
"use strict";
mr.datepicker = mr.datepicker || {};
var options = mr.datepicker.options || {};
mr.datepicker.documentReady = function($){
if($('.datepicker').length){
$('.datepicker').pickadate(options);
}
};
mr.components.documentReadyDeferred.push(mr.datepicker.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Dropdowns
mr = (function (mr, $, window, document){
"use strict";
mr.dropdowns = mr.dropdowns || {};
mr.dropdowns.done = false;
mr.dropdowns.documentReady = function($){
var rtl = false;
if($('html[dir="rtl"]').length){
rtl = true;
}
if(!mr.dropdowns.done){
jQuery(document).on('click','body:not(.dropdowns--hover) .dropdown, body.dropdowns--hover .dropdown.dropdown--click',function(event){
var dropdown = jQuery(this);
if(jQuery(event.target).is('.dropdown--active > .dropdown__trigger')){
dropdown.siblings().removeClass('dropdown--active').find('.dropdown').removeClass('dropdown--active');
dropdown.toggleClass('dropdown--active');
}else{
$('.dropdown--active').removeClass('dropdown--active');
dropdown.addClass('dropdown--active');
}
});
jQuery(document).on('click touchstart', 'body:not(.dropdowns--hover)', function(event){
if(!jQuery(event.target).is('[class*="dropdown"], [class*="dropdown"] *')){
$('.dropdown--active').removeClass('dropdown--active');
}
});
jQuery('body.dropdowns--hover .dropdown').on('click', function(event){
event.stopPropagation();
var hoverDropdown = jQuery(this);
hoverDropdown.toggleClass('dropdown--active');
});
// Append a container to the body for measuring purposes
jQuery('body').append('<div class="container containerMeasure" style="opacity:0;pointer-events:none;"></div>');
// Menu dropdown positioning
if(rtl === false){
mr.dropdowns.repositionDropdowns($);
jQuery(window).on('resize', function(){mr.dropdowns.repositionDropdowns($);});
}else{
mr.dropdowns.repositionDropdownsRtl($);
jQuery(window).on('resize', function(){mr.dropdowns.repositionDropdownsRtl($);});
}
mr.dropdowns.done = true;
}
};
mr.dropdowns.repositionDropdowns = function($){
$('.dropdown__container').each(function(){
var container, containerOffset, masterOffset, menuItem, content;
jQuery(this).css('left', '');
container = jQuery(this);
containerOffset = container.offset().left;
masterOffset = jQuery('.containerMeasure').offset().left;
menuItem = container.closest('.dropdown').offset().left;
content = null;
container.css('left',((-containerOffset)+(masterOffset)));
if(container.find('.dropdown__content:not([class*="lg-12"])').length){
content = container.find('.dropdown__content');
content.css('left', ((menuItem)-(masterOffset)));
}
});
$('.dropdown__content').each(function(){
var dropdown, offset, width, offsetRight, winWidth, leftCorrect;
dropdown = jQuery(this);
offset = dropdown.offset().left;
width = dropdown.outerWidth(true);
offsetRight = offset + width;
winWidth = jQuery(window).outerWidth(true);
leftCorrect = jQuery('.containerMeasure').outerWidth() - width;
if(offsetRight > winWidth){
dropdown.css('left', leftCorrect);
}
});
};
mr.dropdowns.repositionDropdownsRtl = function($){
var windowWidth = jQuery(window).width();
$('.dropdown__container').each(function(){
var container, containerOffset, masterOffset, menuItem, content;
jQuery(this).css('left', '');
container = jQuery(this);
containerOffset = windowWidth - (container.offset().left + container.outerWidth(true));
masterOffset = jQuery('.containerMeasure').offset().left;
menuItem = windowWidth - (container.closest('.dropdown').offset().left + container.closest('.dropdown').outerWidth(true));
content = null;
container.css('right',((-containerOffset)+(masterOffset)));
if(container.find('.dropdown__content:not([class*="lg-12"])').length){
content = container.find('.dropdown__content');
content.css('right', ((menuItem)-(masterOffset)));
}
});
$('.dropdown__content').each(function(){
var dropdown, offset, width, offsetRight, winWidth, rightCorrect;
dropdown = jQuery(this);
offset = windowWidth - (dropdown.offset().left + dropdown.outerWidth(true));
width = dropdown.outerWidth(true);
offsetRight = offset + width;
winWidth = jQuery(window).outerWidth(true);
rightCorrect = jQuery('.containerMeasure').outerWidth() - width;
if(offsetRight > winWidth){
dropdown.css('right', rightCorrect);
}
});
};
mr.components.documentReady.push(mr.dropdowns.documentReady);
return mr;
}(mr, jQuery, window, document));
//////////////// Forms
mr = (function (mr, $, window, document){
"use strict";
mr.forms = mr.forms || {};
mr.forms.captcha = {};
mr.forms.captcha.widgets = [];
mr.forms.captcha.done = false;
mr.forms.documentReady = function($){
mr.forms.captcha.widgets = [];
/// Checkbox & Radio Inputs
$('.input-checkbox input[type="checkbox"], .input-radio input[type="radio"]').each(function(index){
var input = $(this),
label = input.siblings('label'),
id = "input-assigned-"+index;
if(typeof input.attr('id') === typeof undefined || input.attr('id') === ""){
input.attr('id',id);
label.attr('for',id);
}else{
id = input.attr('id');
label.attr('for',id);
}
});
//////////////// Number Inputs
$('.input-number__controls > span').off('click.mr').on('click.mr',function(){
var control = jQuery(this),
parent = control.closest('.input-number'),
input = parent.find('input[type="number"]'),
max = input.attr('max'),
min = input.attr('min'),
step = 1,
current = parseInt(input.val(),10);
if(parent.is('[data-step]')){
step = parseInt(parent.attr('data-step'),10);
}
if(control.hasClass('input-number__increase')){
if((current+step) <= max){
input.val(current+step);
}
}else{
if((current-step) >= min){
input.val(current-step);
}
}
});
//////////////// File Uploads
$('.input-file .btn').off('click.mr').on('click.mr',function(){
$(this).siblings('input').trigger('click');
return false;
});
//////////////// Handle Form Submit
$('form.form-email, form[action*="list-manage.com"], form[action*="createsend.com"]').attr('novalidate', true).off('submit').on('submit', mr.forms.submit);
//////////////// Handle Form Submit
$(document).on('change, input, paste, keyup', '.attempted-submit .field-error', function(){
$(this).removeClass('field-error');
});
//////////////// Check forms for Google reCaptcha site keys
$('form[data-recaptcha-sitekey]:not([data-recaptcha-sitekey=""])').each(function(){
var $thisForm = jQuery(this),
$captchaDiv = $thisForm.find('div.recaptcha'),
$insertBefore, $column, widgetObject, $script, scriptSrc, widgetColourTheme, widgetSize;
widgetColourTheme = $thisForm.attr('data-recaptcha-theme');
widgetColourTheme = typeof widgetColourTheme !== typeof undefined ? widgetColourTheme : '';
widgetSize = $thisForm.attr('data-recaptcha-size');
widgetSize = typeof widgetSize !== typeof undefined ? widgetSize : '';
// Store the site key for later use
mr.forms.captcha.sitekey = $thisForm.attr('data-recaptcha-sitekey');
if($captchaDiv.length){
// If a div.recaptcha was already present on this form, do nothing at this stage,
// It will be populated with a captcha widget later.
}else{
// Create a captcha div and insert it before the submit button.
$insertBefore = $thisForm.find('button[type=submit]').closest('[class*="col-"]');
$captchaDiv = jQuery('<div>').addClass('recaptcha');
$column = jQuery('<div>').addClass('col-12').append($captchaDiv);
$column.insertBefore($insertBefore);
}
// Add the widget div to the widgets array
widgetObject = {
element: $captchaDiv.get(0),
parentForm: $thisForm,
theme: widgetColourTheme,
size: widgetSize,
};
mr.forms.captcha.widgets.push(widgetObject);
// mr.forms.captcha.done indicates whether the api script has been appended yet.
if(mr.forms.captcha.done === false){
if(!jQuery('script[src*="recaptcha/api.js"]').length){
$script = jQuery('<script async defer>');
scriptSrc = 'https://www.google.com/recaptcha/api.js?onload=mrFormsCaptchaInit&render=explicit';
$script.attr('src', scriptSrc);
jQuery('body').append($script);
mr.forms.captcha.done = true;
}
}else{
if(typeof grecaptcha !== typeof undefined){
mr.forms.captcha.renderWidgets();
}
}
});
};
mr.forms.submit = function(e){
// return false so form submits through jQuery rather than reloading page.
if (e.preventDefault) e.preventDefault();
else e.returnValue = false;
var body = $('body'),
thisForm = $(e.target).closest('form'),
formAction = typeof thisForm.attr('action') !== typeof undefined ? thisForm.attr('action') : "",
submitButton = thisForm.find('button[type="submit"], input[type="submit"]'),
error = 0,
originalError = thisForm.attr('original-error'),
captchaUsed = thisForm.find('div.recaptcha').length ? true:false,
successRedirect, formError, formSuccess, errorText, successText;
body.find('.form-error, .form-success').remove();
submitButton.attr('data-text', submitButton.text());
errorText = thisForm.attr('data-error') ? thisForm.attr('data-error') : "Please fill all fields correctly";
successText = thisForm.attr('data-success') ? thisForm.attr('data-success') : "Thanks, we'll be in touch shortly";
body.append('<div class="form-error" style="display: none;">' + errorText + '</div>');
body.append('<div class="form-success" style="display: none;">' + successText + '</div>');
formError = body.find('.form-error');
formSuccess = body.find('.form-success');
thisForm.addClass('attempted-submit');
// Do this if the form is intended to be submitted to MailChimp or Campaign Monitor
if (formAction.indexOf('createsend.com') !== -1 || formAction.indexOf('list-manage.com') !== -1 ) {
console.log('Mail list form signup detected.');
if (typeof originalError !== typeof undefined && originalError !== false) {
formError.html(originalError);
}
// validateFields returns 1 on error;
if (mr.forms.validateFields(thisForm) !== 1) {
thisForm.removeClass('attempted-submit');
// Hide the error if one was shown
formError.fadeOut(200);
// Create a new loading spinner in the submit button.
submitButton.addClass('btn--loading');
try{
$.ajax({
url: thisForm.attr('action'),
crossDomain: true,
data: thisForm.serialize(),
method: "GET",
cache: false,
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function(data){
// Request was a success, what was the response?
alert('hi');
if (data.result !== "success" && data.Status !== 200) {
// Got an 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).stop(true).fadeIn(1000);
formSuccess.stop(true).fadeOut(1000);
submitButton.removeClass('btn--loading');
} else {
// Got success from Mail Chimp or Campaign Monitor
submitButton.removeClass('btn--loading');
successRedirect = thisForm.attr('data-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;