-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
979 lines (829 loc) · 34.6 KB
/
app.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
/**
Core script to handle the entire layout and base functions
**/
var App = function () {
// IE mode
var isRTL = false;
var isIE8 = false;
var isIE9 = false;
var isIE10 = false;
var sidebarWidth = 225;
var sidebarCollapsedWidth = 35;
var responsiveHandlers = [];
// theme layout color set
var layoutColorCodes = {
'blue': '#4b8df8',
'red': '#e02222',
'green': '#35aa47',
'purple': '#852b99',
'grey': '#555555',
'light-grey': '#fafafa',
'yellow': '#ffb848'
};
// last popep popover
var lastPopedPopover;
var handleInit = function() {
if ($('body').css('direction') === 'rtl') {
isRTL = true;
}
isIE8 = !! navigator.userAgent.match(/MSIE 8.0/);
isIE9 = !! navigator.userAgent.match(/MSIE 9.0/);
isIE10 = !! navigator.userAgent.match(/MSIE 10.0/);
if (isIE10) {
jQuery('html').addClass('ie10'); // detect IE10 version
}
}
var handleDesktopTabletContents = function () {
// loops all page elements with "responsive" class and applies classes for tablet mode
// For Metronic 1280px or less set as tablet mode to display the content properly
if ($(window).width() <= 1280 || $('body').hasClass('page-boxed')) {
$(".responsive").each(function () {
var forTablet = $(this).attr('data-tablet');
var forDesktop = $(this).attr('data-desktop');
if (forTablet) {
$(this).removeClass(forDesktop);
$(this).addClass(forTablet);
}
});
}
// loops all page elements with "responsive" class and applied classes for desktop mode
// For Metronic higher 1280px set as desktop mode to display the content properly
if ($(window).width() > 1280 && $('body').hasClass('page-boxed') === false) {
$(".responsive").each(function () {
var forTablet = $(this).attr('data-tablet');
var forDesktop = $(this).attr('data-desktop');
if (forTablet) {
$(this).removeClass(forTablet);
$(this).addClass(forDesktop);
}
});
}
}
var handleSidebarState = function () {
// remove sidebar toggler if window width smaller than 900(for table and phone mode)
if ($(window).width() < 980) {
$('body').removeClass("page-sidebar-closed");
}
}
var runResponsiveHandlers = function () {
// reinitialize other subscribed elements
for (var i in responsiveHandlers) {
var each = responsiveHandlers[i];
each.call();
}
}
var handleResponsive = function () {
handleTooltips();
handleSidebarState();
handleDesktopTabletContents();
handleSidebarAndContentHeight();
handleChoosenSelect();
handleFixedSidebar();
runResponsiveHandlers();
}
var handleResponsiveOnInit = function () {
handleSidebarState();
handleDesktopTabletContents();
handleSidebarAndContentHeight();
}
var handleResponsiveOnResize = function () {
var resize;
if (isIE8) {
var currheight;
$(window).resize(function() {
if(currheight == document.documentElement.clientHeight) {
return; //quite event since only body resized not window.
}
if (resize) {
clearTimeout(resize);
}
resize = setTimeout(function() {
handleResponsive();
}, 50); // wait 50ms until window resize finishes.
currheight = document.documentElement.clientHeight; // store last body client height
});
} else {
$(window).resize(function() {
if (resize) {
clearTimeout(resize);
}
resize = setTimeout(function() {
handleResponsive();
}, 50); // wait 50ms until window resize finishes.
});
}
}
//* BEGIN:CORE HANDLERS *//
// this function handles responsive layout on screen size resize or mobile device rotate.
var handleSidebarAndContentHeight = function () {
var content = $('.page-content');
var sidebar = $('.page-sidebar');
var body = $('body');
var height;
if (body.hasClass("page-footer-fixed") === true && body.hasClass("page-sidebar-fixed") === false) {
var available_height = $(window).height() - $('.footer').height();
if (content.height() < available_height) {
content.attr('style', 'min-height:' + available_height + 'px !important');
}
} else {
if (body.hasClass('page-sidebar-fixed')) {
height = _calculateFixedSidebarViewportHeight();
} else {
height = sidebar.height() + 20;
}
if (height >= content.height()) {
content.attr('style', 'min-height:' + height + 'px !important');
}
}
}
var handleSidebarMenu = function () {
jQuery('.page-sidebar').on('click', 'li > a', function (e) {
if ($(this).next().hasClass('sub-menu') == false) {
if ($('.btn-navbar').hasClass('collapsed') == false) {
$('.btn-navbar').click();
}
return;
}
var parent = $(this).parent().parent();
var the = $(this);
parent.children('li.open').children('a').children('.arrow').removeClass('open');
parent.children('li.open').children('.sub-menu').slideUp(200);
parent.children('li.open').removeClass('open');
var sub = jQuery(this).next();
var slideOffeset = -200;
var slideSpeed = 200;
if (sub.is(":visible")) {
jQuery('.arrow', jQuery(this)).removeClass("open");
jQuery(this).parent().removeClass("open");
sub.slideUp(slideSpeed, function () {
if ($('body').hasClass('page-sidebar-fixed') == false && $('body').hasClass('page-sidebar-closed') == false) {
App.scrollTo(the, slideOffeset);
}
handleSidebarAndContentHeight();
});
} else {
jQuery('.arrow', jQuery(this)).addClass("open");
jQuery(this).parent().addClass("open");
sub.slideDown(slideSpeed, function () {
if ($('body').hasClass('page-sidebar-fixed') == false && $('body').hasClass('page-sidebar-closed') == false) {
App.scrollTo(the, slideOffeset);
}
handleSidebarAndContentHeight();
});
}
e.preventDefault();
});
// handle ajax links
jQuery('.page-sidebar').on('click', ' li > a.ajaxify', function (e) {
e.preventDefault();
App.scrollTop();
var url = $(this).attr("href");
var menuContainer = jQuery('.page-sidebar ul');
var pageContent = $('.page-content');
var pageContentBody = $('.page-content .page-content-body');
menuContainer.children('li.active').removeClass('active');
menuContainer.children('arrow.open').removeClass('open');
$(this).parents('li').each(function () {
$(this).addClass('active');
$(this).children('a > span.arrow').addClass('open');
});
$(this).parents('li').addClass('active');
App.blockUI(pageContent, false);
$.ajax({
type: "GET",
cache: false,
url: url,
dataType: "html",
success: function(res)
{
App.unblockUI(pageContent);
pageContentBody.html(res);
App.fixContentHeight(); // fix content height
App.initUniform(); // initialize uniform elements
},
error: function(xhr, ajaxOptions, thrownError)
{
pageContentBody.html('<h4>Could not load the requested content.</h4>');
App.unblockUI(pageContent);
},
async: false
});
});
}
var _calculateFixedSidebarViewportHeight = function () {
var sidebarHeight = $(window).height() - $('.header').height() + 1;
if ($('body').hasClass("page-footer-fixed")) {
sidebarHeight = sidebarHeight - $('.footer').height();
}
return sidebarHeight;
}
var handleFixedSidebar = function () {
var menu = $('.page-sidebar-menu');
if (menu.parent('.slimScrollDiv').size() === 1) { // destroy existing instance before updating the height
menu.slimScroll({
destroy: true
});
menu.removeAttr('style');
$('.page-sidebar').removeAttr('style');
}
if ($('.page-sidebar-fixed').size() === 0) {
handleSidebarAndContentHeight();
return;
}
if ($(window).width() >= 980) {
var sidebarHeight = _calculateFixedSidebarViewportHeight();
menu.slimScroll({
size: '7px',
color: '#a1b2bd',
opacity: .3,
position: isRTL ? 'left' : ($('.page-sidebar-on-right').size() === 1 ? 'left' : 'right'),
height: sidebarHeight,
allowPageScroll: false,
disableFadeOut: false
});
handleSidebarAndContentHeight();
}
}
var handleFixedSidebarHoverable = function () {
if ($('body').hasClass('page-sidebar-fixed') === false) {
return;
}
$('.page-sidebar').off('mouseenter').on('mouseenter', function () {
var body = $('body');
if ((body.hasClass('page-sidebar-closed') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
return;
}
body.removeClass('page-sidebar-closed').addClass('page-sidebar-hover-on');
$(this).addClass('page-sidebar-hovering');
$(this).animate({
width: sidebarWidth
}, 400, '', function () {
$(this).removeClass('page-sidebar-hovering');
});
});
$('.page-sidebar').off('mouseleave').on('mouseleave', function () {
var body = $('body');
if ((body.hasClass('page-sidebar-hover-on') === false || body.hasClass('page-sidebar-fixed') === false) || $(this).hasClass('page-sidebar-hovering')) {
return;
}
$(this).addClass('page-sidebar-hovering');
$(this).animate({
width: sidebarCollapsedWidth
}, 400, '', function () {
$('body').addClass('page-sidebar-closed').removeClass('page-sidebar-hover-on');
$(this).removeClass('page-sidebar-hovering');
});
});
}
var handleSidebarToggler = function () {
// handle sidebar show/hide
$('.page-sidebar').on('click', '.sidebar-toggler', function (e) {
var body = $('body');
var sidebar = $('.page-sidebar');
if ((body.hasClass("page-sidebar-hover-on") && body.hasClass('page-sidebar-fixed')) || sidebar.hasClass('page-sidebar-hovering')) {
body.removeClass('page-sidebar-hover-on');
sidebar.css('width', '').hide().show();
e.stopPropagation();
runResponsiveHandlers();
return;
}
$(".sidebar-search", sidebar).removeClass("open");
if (body.hasClass("page-sidebar-closed")) {
body.removeClass("page-sidebar-closed");
if (body.hasClass('page-sidebar-fixed')) {
sidebar.css('width', '');
}
} else {
body.addClass("page-sidebar-closed");
}
runResponsiveHandlers();
});
// handle the search bar close
$('.page-sidebar').on('click', '.sidebar-search .remove', function (e) {
e.preventDefault();
$('.sidebar-search').removeClass("open");
});
// handle the search query submit on enter press
$('.page-sidebar').on('keypress', '.sidebar-search input', function (e) {
if (e.which == 13) {
window.location.href = "extra_search.html";
return false; //<---- Add this line
}
});
// handle the search submit
$('.sidebar-search .submit').on('click', function (e) {
e.preventDefault();
if ($('body').hasClass("page-sidebar-closed")) {
if ($('.sidebar-search').hasClass('open') == false) {
if ($('.page-sidebar-fixed').size() === 1) {
$('.page-sidebar .sidebar-toggler').click(); //trigger sidebar toggle button
}
$('.sidebar-search').addClass("open");
} else {
window.location.href = "extra_search.html";
}
} else {
window.location.href = "extra_search.html";
}
});
}
var handleHorizontalMenu = function () {
//handle hor menu search form toggler click
$('.header').on('click', '.hor-menu .hor-menu-search-form-toggler', function (e) {
if ($(this).hasClass('hide')) {
$(this).removeClass('hide');
$('.header .hor-menu .search-form').hide();
} else {
$(this).addClass('hide');
$('.header .hor-menu .search-form').show();
}
e.preventDefault();
});
//handle hor menu search button click
$('.header').on('click', '.hor-menu .search-form .btn', function (e) {
window.location.href = "extra_search.html";
e.preventDefault();
});
//handle hor menu search form on enter press
$('.header').on('keypress', '.hor-menu .search-form input', function (e) {
if (e.which == 13) {
window.location.href = "extra_search.html";
return false;
}
});
}
var handleGoTop = function () {
/* set variables locally for increased performance */
jQuery('.footer').on('click', '.go-top', function (e) {
App.scrollTo();
e.preventDefault();
});
}
var handlePortletTools = function () {
jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.remove', function (e) {
e.preventDefault();
jQuery(this).closest(".portlet").remove();
});
jQuery('body').on('click', '.portlet > .portlet-title > .tools > a.reload', function (e) {
e.preventDefault();
var el = jQuery(this).closest(".portlet").children(".portlet-body");
App.blockUI(el);
window.setTimeout(function () {
App.unblockUI(el);
}, 1000);
});
jQuery('body').on('click', '.portlet > .portlet-title > .tools > .collapse, .portlet .portlet-title > .tools > .expand', function (e) {
e.preventDefault();
var el = jQuery(this).closest(".portlet").children(".portlet-body");
if (jQuery(this).hasClass("collapse")) {
jQuery(this).removeClass("collapse").addClass("expand");
el.slideUp(200);
} else {
jQuery(this).removeClass("expand").addClass("collapse");
el.slideDown(200);
}
});
}
var handleUniform = function () {
if (!jQuery().uniform) {
return;
}
var test = $("input[type=checkbox]:not(.toggle), input[type=radio]:not(.toggle, .star)");
if (test.size() > 0) {
test.each(function () {
if ($(this).parents(".checker").size() == 0) {
$(this).show();
$(this).uniform();
}
});
}
}
var handleAccordions = function () {
$(".accordion").collapse().height('auto');
var lastClicked;
//add scrollable class name if you need scrollable panes
jQuery('body').on('click', '.accordion.scrollable .accordion-toggle', function () {
lastClicked = jQuery(this);
}); //move to faq section
jQuery('body').on('shown', '.accordion.scrollable', function () {
jQuery('html,body').animate({
scrollTop: lastClicked.offset().top - 150
}, 'slow');
});
}
var handleTabs = function () {
// function to fix left/right tab contents
var fixTabHeight = function(tab) {
$(tab).each(function() {
var content = $($($(this).attr("href")));
var tab = $(this).parent().parent();
if (tab.height() > content.height()) {
content.css('min-height', tab.height());
}
});
}
// fix tab content on tab shown
$('body').on('shown', '.nav.nav-tabs.tabs-left a[data-toggle="tab"], .nav.nav-tabs.tabs-right a[data-toggle="tab"]', function(){
fixTabHeight($(this));
});
$('body').on('shown', '.nav.nav-tabs', function(){
handleSidebarAndContentHeight();
});
//fix tab contents for left/right tabs
fixTabHeight('.nav.nav-tabs.tabs-left > li.active > a[data-toggle="tab"], .nav.nav-tabs.tabs-right > li.active > a[data-toggle="tab"]');
//activate tab if tab id provided in the URL
if(location.hash) {
var tabid = location.hash.substr(1);
$('a[href="#'+tabid+'"]').click();
}
}
var handleScrollers = function () {
$('.scroller').each(function () {
var height;
if ($(this).attr("data-height")) {
height = $(this).attr("data-height");
} else {
height = $(this).css('height');
}
$(this).slimScroll({
size: '7px',
color: '#a1b2bd',
position: isRTL ? 'left' : 'right',
height: height,
alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false),
railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
disableFadeOut: true
});
});
}
var handleTooltips = function () {
if (App.isTouchDevice()) { // if touch device, some tooltips can be skipped in order to not conflict with click events
jQuery('.tooltips:not(.no-tooltip-on-touch-device)').tooltip();
} else {
jQuery('.tooltips').tooltip();
}
}
var handleDropdowns = function () {
$('body').on('click', '.dropdown-menu.hold-on-click', function(e){
e.stopPropagation();
})
}
var handleModal = function () {
// this function adds .modal-open class to body element for select2 and chosen dropdown hacks
if (jQuery().modalmanager) {
return; // skip if Extended Modal plugin is used
}
$('body').on('shown', '.modal', function(e){
$('body').addClass('modal-open');
});
$('body').on('hidden', '.modal', function(e){
if ($('.modal').size() === 0) {
$('body').removeClass('modal-open');
}
});
}
var handlePopovers = function () {
jQuery('.popovers').popover();
// close last poped popover
$(document).on('click.popover.data-api',function(e) {
if(lastPopedPopover){
lastPopedPopover.popover('hide');
}
});
}
var handleChoosenSelect = function () {
if (!jQuery().chosen) {
return;
}
$(".chosen").each(function () {
$(this).chosen({
allow_single_deselect: $(this).attr("data-with-deselect") == "1" ? true : false
});
});
}
var handleFancybox = function () {
if (!jQuery.fancybox) {
return;
}
if (jQuery(".fancybox-button").size() > 0) {
jQuery(".fancybox-button").fancybox({
groupAttr: 'data-rel',
prevEffect: 'none',
nextEffect: 'none',
closeBtn: true,
helpers: {
title: {
type: 'inside'
}
}
});
}
}
var handleTheme = function () {
var panel = $('.color-panel');
if ($('body').hasClass('page-boxed') == false) {
$('.layout-option', panel).val("fluid");
}
$('.sidebar-option', panel).val("default");
$('.header-option', panel).val("fixed");
$('.footer-option', panel).val("default");
//handle theme layout
var resetLayout = function () {
$("body").
removeClass("page-boxed").
removeClass("page-footer-fixed").
removeClass("page-sidebar-fixed").
removeClass("page-header-fixed");
$('.header > .navbar-inner > .container').removeClass("container").addClass("container-fluid");
if ($('.page-container').parent(".container").size() === 1) {
$('.page-container').insertAfter('.header');
}
if ($('.footer > .container').size() === 1) {
$('.footer').html($('.footer > .container').html());
} else if ($('.footer').parent(".container").size() === 1) {
$('.footer').insertAfter('.page-container');
}
$('body > .container').remove();
}
var lastSelectedLayout = '';
var setLayout = function () {
var layoutOption = $('.layout-option', panel).val();
var sidebarOption = $('.sidebar-option', panel).val();
var headerOption = $('.header-option', panel).val();
var footerOption = $('.footer-option', panel).val();
if (sidebarOption == "fixed" && headerOption == "default") {
alert('Default Header with Fixed Sidebar option is not supported. Proceed with Default Header with Default Sidebar.');
$('.sidebar-option', panel).val("default");
sidebarOption = 'default';
}
resetLayout(); // reset layout to default state
if (layoutOption === "boxed") {
$("body").addClass("page-boxed");
// set header
$('.header > .navbar-inner > .container-fluid').removeClass("container-fluid").addClass("container");
var cont = $('.header').after('<div class="container"></div>');
// set content
$('.page-container').appendTo('body > .container');
// set footer
if (footerOption === 'fixed' || sidebarOption === 'default') {
$('.footer').html('<div class="container">'+$('.footer').html()+'</div>');
} else {
$('.footer').appendTo('body > .container');
}
}
if (lastSelectedLayout != layoutOption) {
//layout changed, run responsive handler:
runResponsiveHandlers();
}
lastSelectedLayout = layoutOption;
//header
if (headerOption === 'fixed') {
$("body").addClass("page-header-fixed");
$(".header").removeClass("navbar-static-top").addClass("navbar-fixed-top");
} else {
$("body").removeClass("page-header-fixed");
$(".header").removeClass("navbar-fixed-top").addClass("navbar-static-top");
}
//sidebar
if (sidebarOption === 'fixed') {
$("body").addClass("page-sidebar-fixed");
} else {
$("body").removeClass("page-sidebar-fixed");
}
//footer
if (footerOption === 'fixed') {
$("body").addClass("page-footer-fixed");
} else {
$("body").removeClass("page-footer-fixed");
}
handleSidebarAndContentHeight(); // fix content height
handleFixedSidebar(); // reinitialize fixed sidebar
handleFixedSidebarHoverable(); // reinitialize fixed sidebar hover effect
}
// handle theme colors
var setColor = function (color) {
$('#style_color').attr("href", "assets/css/themes/" + color + ".css");
$.cookie('style_color', color);
}
$('.icon-color', panel).click(function () {
$('.color-mode').show();
$('.icon-color-close').show();
});
$('.icon-color-close', panel).click(function () {
$('.color-mode').hide();
$('.icon-color-close').hide();
});
$('li', panel).click(function () {
var color = $(this).attr("data-style");
setColor(color);
$('.inline li', panel).removeClass("current");
$(this).addClass("current");
});
$('.layout-option, .header-option, .sidebar-option, .footer-option', panel).change(setLayout);
}
var handleFixInputPlaceholderForIE = function () {
//fix html5 placeholder attribute for ie7 & ie8
if (isIE8 || isIE9) { // ie7&ie8
// this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
jQuery('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function () {
var input = jQuery(this);
if(input.val()=='' && input.attr("placeholder") != '') {
input.addClass("placeholder").val(input.attr('placeholder'));
}
input.focus(function () {
if (input.val() == input.attr('placeholder')) {
input.val('');
}
});
input.blur(function () {
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.val(input.attr('placeholder'));
}
});
});
}
}
var handleFullScreenMode = function() {
// mozfullscreenerror event handler
// toggle full screen
function toggleFullScreen() {
if (!document.fullscreenElement && // alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement) { // current working methods
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
}
}
$('#trigger_fullscreen').click(function() {
toggleFullScreen();
});
}
//* END:CORE HANDLERS *//
return {
//main function to initiate template pages
init: function () {
//IMPORTANT!!!: Do not modify the core handlers call order.
//core handlers
handleInit();
handleResponsiveOnResize(); // set and handle responsive
handleUniform();
handleScrollers(); // handles slim scrolling contents
handleResponsiveOnInit(); // handler responsive elements on page load
//layout handlers
handleFixedSidebar(); // handles fixed sidebar menu
handleFixedSidebarHoverable(); // handles fixed sidebar on hover effect
handleSidebarMenu(); // handles main menu
handleHorizontalMenu(); // handles horizontal menu
handleSidebarToggler(); // handles sidebar hide/show
handleFixInputPlaceholderForIE(); // fixes/enables html5 placeholder attribute for IE9, IE8
handleGoTop(); //handles scroll to top functionality in the footer
handleTheme(); // handles style customer tool
//ui component handlers
handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove)
handleDropdowns(); // handle dropdowns
handleTabs(); // handle tabs
handleTooltips(); // handle bootstrap tooltips
handlePopovers(); // handles bootstrap popovers
handleAccordions(); //handles accordions
handleChoosenSelect(); // handles bootstrap chosen dropdowns
handleModal();
App.addResponsiveHandler(handleChoosenSelect); // reinitiate chosen dropdown on main content resize. disable this line if you don't really use chosen dropdowns.
handleFullScreenMode() // handles full screen
},
fixContentHeight: function () {
handleSidebarAndContentHeight();
},
setLastPopedPopover: function (el) {
lastPopedPopover = el;
},
addResponsiveHandler: function (func) {
responsiveHandlers.push(func);
},
// useful function to make equal height for contacts stand side by side
setEqualHeight: function (els) {
var tallestEl = 0;
els = jQuery(els);
els.each(function () {
var currentHeight = $(this).height();
if (currentHeight > tallestEl) {
tallestColumn = currentHeight;
}
});
els.height(tallestEl);
},
// wrapper function to scroll to an element
scrollTo: function (el, offeset) {
pos = el ? el.offset().top : 0;
jQuery('html,body').animate({
scrollTop: pos + (offeset ? offeset : 0)
}, 'slow');
},
scrollTop: function () {
App.scrollTo();
},
// wrapper function to block element(indicate loading)
blockUI: function (el, centerY) {
var el = jQuery(el);
el.block({
message: '<img src="./assets/img/ajax-loading.gif" align="">',
centerY: centerY != undefined ? centerY : true,
css: {
top: '10%',
border: 'none',
padding: '2px',
backgroundColor: 'none'
},
overlayCSS: {
backgroundColor: '#000',
opacity: 0.05,
cursor: 'wait'
}
});
},
// wrapper function to un-block element(finish loading)
unblockUI: function (el) {
jQuery(el).unblock({
onUnblock: function () {
jQuery(el).removeAttr("style");
}
});
},
// initializes uniform elements
initUniform: function (els) {
if (els) {
jQuery(els).each(function () {
if ($(this).parents(".checker").size() == 0) {
$(this).show();
$(this).uniform();
}
});
} else {
handleUniform();
}
},
updateUniform : function(els) {
$.uniform.update(els);
},
// initializes choosen dropdowns
initChosenSelect: function (els) {
$(els).chosen({
allow_single_deselect: true
});
},
initFancybox: function () {
handleFancybox();
},
getActualVal: function (el) {
var el = jQuery(el);
if (el.val() === el.attr("placeholder")) {
return "";
}
return el.val();
},
getURLParameter: function (paramName) {
var searchString = window.location.search.substring(1),
i, val, params = searchString.split("&");
for (i = 0; i < params.length; i++) {
val = params[i].split("=");
if (val[0] == paramName) {
return unescape(val[1]);
}
}
return null;
},
// check for device touch support
isTouchDevice: function () {
try {
document.createEvent("TouchEvent");
return true;
} catch (e) {
return false;
}
},
isIE8: function () {
return isIE8;
},
isRTL: function () {
return isRTL;
},
getLayoutColorCode: function (name) {
if (layoutColorCodes[name]) {
return layoutColorCodes[name];
} else {
return '';
}
}
};
}();