forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathace.js
2805 lines (2170 loc) · 105 KB
/
ace.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
/*
Ace Admin Theme v1.4
Copyright (c) 2016 Mohsen - (twitter.com/responsiweb)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* Ace v1.4.0
*/
if (typeof jQuery === 'undefined') { throw new Error('Ace\'s JavaScript requires jQuery') }
/**
Required. Ace's Basic File to Initiliaze Different Parts and Some Variables.
*/
//some basic variables
(function(undefined) {
if( !('ace' in window) ) window['ace'] = {}
if( !('helper' in window['ace']) ) window['ace'].helper = {}
if( !('vars' in window['ace']) ) window['ace'].vars = {}
window['ace'].vars['icon'] = ' ace-icon ';
window['ace'].vars['.icon'] = '.ace-icon';
ace.vars['touch'] = ('ontouchstart' in window);//(('ontouchstart' in document.documentElement) || (window.DocumentTouch && document instanceof DocumentTouch));
//sometimes the only good way to work around browser's pecularities is to detect them using user-agents
//though it's not accurate
var agent = navigator.userAgent
ace.vars['webkit'] = !!agent.match(/AppleWebKit/i)
ace.vars['safari'] = !!agent.match(/Safari/i) && !agent.match(/Chrome/i);
ace.vars['android'] = ace.vars['safari'] && !!agent.match(/Android/i)
ace.vars['ios_safari'] = !!agent.match(/OS ([4-9])(_\d)+ like Mac OS X/i) && !agent.match(/CriOS/i)
ace.vars['ie'] = window.navigator.msPointerEnabled || (document.all && document.querySelector);//8-11
ace.vars['old_ie'] = document.all && !document.addEventListener;//8 and below
ace.vars['very_old_ie'] = document.all && !document.querySelector;//7 and below
ace.vars['firefox'] = 'MozAppearance' in document.documentElement.style;
ace.vars['non_auto_fixed'] = ace.vars['android'] || ace.vars['ios_safari'];
//sometimes we try to use 'tap' event instead of 'click' if jquery mobile plugin is available
ace['click_event'] = ace.vars['touch'] && jQuery.fn.tap ? 'tap' : 'click';
})();
//some ace helper functions
(function($$ , undefined) {//$$ is ace.helper
$$.unCamelCase = function(str) {
return str.replace(/([a-z])([A-Z])/g, function(match, c1, c2){ return c1+'-'+c2.toLowerCase() })
}
$$.strToVal = function(str) {
var res = str.match(/^(?:(true)|(false)|(null)|(\-?[\d]+(?:\.[\d]+)?)|(\[.*\]|\{.*\}))$/i);
var val = str;
if(res) {
if(res[1]) val = true;
else if(res[2]) val = false;
else if(res[3]) val = null;
else if(res[4]) val = parseFloat(str);
else if(res[5]) {
try { val = JSON.parse(str) }
catch (err) {}
}
}
return val;
}
$$.getAttrSettings = function(elem, attr_list, prefix) {
if(!elem) return;
var list_type = attr_list instanceof Array ? 1 : 2;
//attr_list can be Array or Object(key/value)
var prefix = prefix ? prefix.replace(/([^\-])$/ , '$1-') : '';
prefix = 'data-' + prefix;
var settings = {}
for(var li in attr_list) if(attr_list.hasOwnProperty(li)) {
var name = list_type == 1 ? attr_list[li] : li;
var attr_val, attr_name = $$.unCamelCase(name.replace(/[^A-Za-z0-9]{1,}/g , '-')).toLowerCase()
if( ! ((attr_val = elem.getAttribute(prefix + attr_name)) ) ) continue;
settings[name] = $$.strToVal(attr_val);
}
return settings;
}
$$.scrollTop = function() {
return document.scrollTop || document.documentElement.scrollTop || document.body.scrollTop
}
$$.winHeight = function() {
return window.innerHeight || document.documentElement.clientHeight;
}
$$.redraw = function(elem, force) {
if(!elem) return;
var saved_val = elem.style['display'];
elem.style.display = 'none';
elem.offsetHeight;
if(force !== true) {
elem.style.display = saved_val;
}
else {
//force redraw for example in old IE
setTimeout(function() {
elem.style.display = saved_val;
}, 10);
}
}
})(ace.helper);
/**
<b>Scroll to top button</b>.
*/
(function($ , undefined) {
//the scroll to top button
var scroll_btn = $('.btn-scroll-up');
if(scroll_btn.length > 0) {
var is_visible = false;
$(window).on('scroll.scroll_btn', function() {
var scroll = ace.helper.scrollTop();
var h = ace.helper.winHeight();
var body_sH = document.body.scrollHeight;
if(scroll > parseInt(h / 4) || (scroll > 0 && body_sH >= h && h + scroll >= body_sH - 1)) {//|| for smaller pages, when reached end of page
if(!is_visible) {
scroll_btn.addClass('display');
is_visible = true;
}
} else {
if(is_visible) {
scroll_btn.removeClass('display');
is_visible = false;
}
}
}).triggerHandler('scroll.scroll_btn');
scroll_btn.on(ace.click_event, function(){
var duration = Math.min(500, Math.max(100, parseInt(ace.helper.scrollTop() / 3)));
$('html,body').animate({scrollTop: 0}, duration);
return false;
});
}
})(window.jQuery);
/**
<b>Load content via Ajax </b>. For more information please refer to documentation #basics/ajax
*/
(function($ , undefined) {
var ajax_loaded_scripts = {}
function AceAjax(contentArea, settings) {
var $contentArea = $(contentArea);
var self = this;
$contentArea.attr('data-ajax-content', 'true');
//get a list of 'data-*' attributes that override 'defaults' and 'settings'
var attrib_values = ace.helper.getAttrSettings(contentArea, $.fn.ace_ajax.defaults);
this.settings = $.extend({}, $.fn.ace_ajax.defaults, settings, attrib_values);
var working = false;
var $overlay = $();//empty set
this.force_reload = false;//set jQuery ajax's cache option to 'false' to reload content
this.loadUrl = function(hash, cache, manual_trigger) {
var url = false;
hash = hash.replace(/^(\#\!)?\#/, '');
this.force_reload = (cache === false)
if(typeof this.settings.content_url === 'function') url = this.settings.content_url(hash);
if(typeof url === 'string') this.getUrl(url, hash, manual_trigger);
}
this.loadAddr = function(url, hash, cache) {
this.force_reload = (cache === false);
this.getUrl(url, hash, false);
}
this.reload = function() {
var hash = $.trim(window.location.hash);
if(!hash && this.settings.default_url) hash = this.settings.default_url;
this.loadUrl(hash, false);
}
this.post = function(url, data, updateView, extraParams) {
var url = url || $.trim(location.href.replace(location.hash,''));
if(!url) return;
var data = data || {}
var updateView = updateView || false;
this.getUrl(url, null, false, 'POST', data, updateView, extraParams);
}
this.getUrl = function(url, hash, manual_trigger, method, data, updateView, extraParams) {
if(working) {
return;
}
var method = method || 'GET';
var updateView = (method == 'GET') || (method == 'POST' && updateView == true)
var data = data || null;
var event
$contentArea.trigger(event = $.Event('ajaxloadstart'), {url: url, hash: hash, method: method, data: data})
if (event.isDefaultPrevented()) return;
self.startLoading();
var ajax_params = method == 'GET' ? {'url': url, 'cache': !this.force_reload} : {'url': url, 'method' : 'POST', 'data': data}
if(method == 'POST' && typeof extraParams == 'object') ajax_params = $.extend({}, ajax_params, extraParams);
$.ajax(ajax_params)
.error(function() {
$contentArea.trigger('ajaxloaderror', {url: url, hash: hash, method: method, data: data});
self.stopLoading(true);
})
.done(function(result) {
$contentArea.trigger('ajaxloaddone', {url: url, hash: hash, method: method, data: data});
if(method == 'POST') {
var event
$contentArea.trigger(event = $.Event('ajaxpostdone', {url: url, data: data, result: result}))
if( event.isDefaultPrevented() ) updateView = false;
}
var link_element = null, link_text = '';
if(typeof self.settings.update_active === 'function') {
link_element = self.settings.update_active.call(null, hash, url, method, updateView);
}
else if(self.settings.update_active === true && hash) {
link_element = $('a[data-url="'+hash+'"]');
if(link_element.length > 0) {
var nav = link_element.closest('.nav');
if(nav.length > 0) {
nav.find('.active').each(function(){
var $class = 'active';
if( $(this).hasClass('hover') || self.settings.close_active ) $class += ' open';
$(this).removeClass($class);
if(self.settings.close_active) {
$(this).find(' > .submenu').css('display', '');
}
})
var active_li = link_element.closest('li').addClass('active').parents('.nav li').addClass('active open');
nav.closest('.sidebar[data-sidebar-scroll=true]').each(function() {
var $this = $(this);
$this.ace_sidebar_scroll('reset');
if(manual_trigger == true) $this.ace_sidebar_scroll('scroll_to_active');//first time only
})
}
}
}
/////////
if(typeof self.settings.update_breadcrumbs === 'function') {
link_text = self.settings.update_breadcrumbs.call(null, hash, url, link_element, method, updateView);
}
else if(self.settings.update_breadcrumbs === true && link_element != null && link_element.length > 0) {
link_text = updateBreadcrumbs(link_element);
}
/////////
$overlay.addClass('content-loaded').detach();
if(updateView) {
//convert "title" and "link" tags to "div" tags for later processing
result = String(result)
.replace(/<(title|link)([\s\>])/gi,'<div class="hidden ajax-append-$1"$2')
.replace(/<\/(title|link)\>/gi,'</div>')
$contentArea.empty().html(result);
}
$(self.settings.loading_overlay || $contentArea).append($overlay);
//remove previous stylesheets inserted via ajax
if(updateView) setTimeout(function() {
$('head').find('link.ace-ajax-stylesheet').remove();
var main_selectors = ['link.ace-main-stylesheet', 'link#main-ace-style', 'link[href*="/ace.min.css"]', 'link[href*="/ace.css"]']
var ace_style = [];
for(var m = 0; m < main_selectors.length; m++) {
ace_style = $('head').find(main_selectors[m]).first();
if(ace_style.length > 0) break;
}
$contentArea.find('.ajax-append-link').each(function(e) {
var $link = $(this);
if ( $link.attr('href') ) {
var new_link = jQuery('<link />', {type : 'text/css', rel: 'stylesheet', 'class': 'ace-ajax-stylesheet'})
if( ace_style.length > 0 ) new_link.insertBefore(ace_style);
else new_link.appendTo('head');
new_link.attr('href', $link.attr('href'));//we set "href" after insertion, for IE to work
}
$link.remove();
})
}, 10);
//////////////////////
if(typeof self.settings.update_title === 'function') {
self.settings.update_title.call(null, hash, url, link_text, method, updateView);
}
else if(self.settings.update_title === true && method == 'GET') {
updateTitle(link_text);
}
if( !manual_trigger && updateView ) {
$('html,body').animate({scrollTop: 0}, 250);
}
//////////////////////
$contentArea.trigger('ajaxloadcomplete', {url: url, hash: hash, method: method, data:data});
//////////////////////
//if result contains call to "loadScripts" then don't stopLoading now
var re = /\.(?:\s*)ace(?:_a|A)jax(?:\s*)\((?:\s*)(?:\'|\")loadScripts(?:\'|\")/;
if(result.match(re)) self.stopLoading();
else self.stopLoading(true);
})
}
///////////////////////
var fixPos = false;
var loadTimer = null;
this.startLoading = function() {
if(working) return;
working = true;
if(!this.settings.loading_overlay && $contentArea.css('position') == 'static') {
$contentArea.css('position', 'relative');//for correct icon positioning
fixPos = true;
}
$overlay.remove();
$overlay = $('<div class="ajax-loading-overlay"><i class="ajax-loading-icon '+(this.settings.loading_icon || '')+'"></i> '+this.settings.loading_text+'</div>')
if(this.settings.loading_overlay == 'body') $('body').append($overlay.addClass('ajax-overlay-body'));
else if(this.settings.loading_overlay) $(this.settings.loading_overlay).append($overlay);
else $contentArea.append($overlay);
if(this.settings.max_load_wait !== false)
loadTimer = setTimeout(function() {
loadTimer = null;
if(!working) return;
var event
$contentArea.trigger(event = $.Event('ajaxloadlong'))
if (event.isDefaultPrevented()) return;
self.stopLoading(true);
}, this.settings.max_load_wait * 1000);
}
this.stopLoading = function(stopNow) {
if(stopNow === true) {
working = false;
$overlay.remove();
if(fixPos) {
$contentArea.css('position', '');//restore previous 'position' value
fixPos = false;
}
if(loadTimer != null) {
clearTimeout(loadTimer);
loadTimer = null;
}
}
else {
$overlay.addClass('almost-loaded');
$contentArea.one('ajaxscriptsloaded.inner_call', function() {
self.stopLoading(true);
/**
if(window.Pace && Pace.running == true) {
Pace.off('done');
Pace.once('done', function() { self.stopLoading(true) })
}
else self.stopLoading(true);
*/
})
}
}
this.working = function() {
return working;
}
///////////////////////
function updateBreadcrumbs(link_element) {
var link_text = '';
//update breadcrumbs
var breadcrumbs = $('.breadcrumb');
if(breadcrumbs.length > 0 && breadcrumbs.is(':visible')) {
breadcrumbs.find('> li:not(:first-child)').remove();
var i = 0;
link_element.parents('.nav li').each(function() {
var link = $(this).find('> a');
var link_clone = link.clone();
link_clone.find('i,.fa,.glyphicon,.ace-icon,.menu-icon,.badge,.label').remove();
var text = link_clone.text();
link_clone.remove();
var href = link.attr('href');
if(i == 0) {
var li = $('<li class="active"></li>').appendTo(breadcrumbs);
li.text(text);
link_text = text;
}
else {
var li = $('<li><a /></li>').insertAfter(breadcrumbs.find('> li:first-child'));
li.find('a').attr('href', href).text(text);
}
i++;
})
}
return link_text;
}
function updateTitle(link_text) {
var $title = $contentArea.find('.ajax-append-title');
if($title.length > 0) {
document.title = $title.text();
$title.remove();
}
else if(link_text.length > 0) {
var extra = $.trim(String(document.title).replace(/^(.*)[\-]/, ''));//for example like " - Ace Admin"
if(extra) extra = ' - ' + extra;
link_text = $.trim(link_text) + extra;
}
}
this.loadScripts = function(scripts, callback) {
var scripts = scripts || [];
$.ajaxPrefilter('script', function(opts) {opts.cache = true});
setTimeout(function() {
//let's keep a list of loaded scripts so that we don't load them more than once!
function finishLoading() {
if(typeof callback === 'function') callback();
$('.btn-group[data-toggle="buttons"] > .btn').button();
$contentArea.trigger('ajaxscriptsloaded');
}
//var deferreds = [];
var deferred_count = 0;//deferreds count
var resolved = 0;
for(var i = 0; i < scripts.length; i++) if(scripts[i]) {
(function() {
var script_name = "js-"+scripts[i].replace(/[^\w\d\-]/g, '-').replace(/\-\-/g, '-');
if( ajax_loaded_scripts[script_name] !== true ) deferred_count++;
})()
}
function nextScript(index) {
index += 1;
if(index < scripts.length) loadScript(index);
else {
finishLoading();
}
}
function loadScript(index) {
index = index || 0;
if(!scripts[index]) {//could be null sometimes
return nextScript(index);
}
var script_name = "js-"+scripts[index].replace(/[^\w\d\-]/g, '-').replace(/\-\-/g, '-');
//only load scripts that are not loaded yet!
if( ajax_loaded_scripts[script_name] !== true ) {
$.getScript(scripts[index])
.done(function() {
ajax_loaded_scripts[script_name] = true;
})
//.fail(function() {
//})
.complete(function() {
resolved++;
if(resolved >= deferred_count && working) {
finishLoading();
}
else {
nextScript(index);
}
})
}
else {//script previoisly loaded
nextScript(index);
}
}
if (deferred_count > 0) {
loadScript();
}
else {
finishLoading();
}
}, 10)
}
/////////////////
$(window)
.off('hashchange.ace_ajax')
.on('hashchange.ace_ajax', function(e, manual_trigger) {
var hash = $.trim(window.location.hash);
if(!hash || hash.length == 0) return;
if(self.settings.close_mobile_menu) {
try {$(self.settings.close_mobile_menu).ace_sidebar('mobileHide')} catch(e){}
}
if(self.settings.close_dropdowns) {
$('.dropdown.open .dropdown-toggle').dropdown('toggle');
}
self.loadUrl(hash, null, manual_trigger);
}).trigger('hashchange.ace_ajax', [true]);
var hash = $.trim(window.location.hash);
if(!hash && this.settings.default_url) window.location.hash = this.settings.default_url;
}//AceAjax
$.fn.aceAjax = $.fn.ace_ajax = function (option, value, value2, value3, value4) {
var method_call;
var $set = this.each(function () {
var $this = $(this);
var data = $this.data('ace_ajax');
var options = typeof option === 'object' && option;
if (!data) $this.data('ace_ajax', (data = new AceAjax(this, options)));
if (typeof option === 'string' && typeof data[option] === 'function') {
if(value4 !== undefined) method_call = data[option](value, value2, value3, value4);
else if(value3 !== undefined) method_call = data[option](value, value2, value3);
else if(value2 !== undefined) method_call = data[option](value, value2);
else method_call = data[option](value);
}
});
return (method_call === undefined) ? $set : method_call;
}
$.fn.aceAjax.defaults = $.fn.ace_ajax.defaults = {
content_url: false,
default_url: false,
loading_icon: 'fa fa-spin fa-spinner fa-2x orange',
loading_text: '',
loading_overlay: null,
update_breadcrumbs: true,
update_title: true,
update_active: true,
close_active: false,
max_load_wait: false,
close_mobile_menu: false,
close_dropdowns: false
}
})(window.jQuery);
/**
<b>Sidebar functions</b>. Collapsing/expanding, toggling mobile view menu and other sidebar functions.
*/
(function($ , undefined) {
var sidebar_count = 0;
function Sidebar(sidebar, settings) {
var self = this;
this.$sidebar = $(sidebar);
this.$sidebar.attr('data-sidebar', 'true');
if( !this.$sidebar.attr('id') ) this.$sidebar.attr( 'id' , 'id-sidebar-'+(++sidebar_count) )
//get a list of 'data-*' attributes that override 'defaults' and 'settings'
var attrib_values = ace.helper.getAttrSettings(sidebar, $.fn.ace_sidebar.defaults, 'sidebar-');
this.settings = $.extend({}, $.fn.ace_sidebar.defaults, settings, attrib_values);
//some vars
this.minimized = false;//will be initialized later
this.collapsible = false;//...
this.horizontal = false;//...
this.mobile_view = false;//
//return an array containing sidebar state variables
this.vars = function() {
return {'minimized': this.minimized, 'collapsible': this.collapsible, 'horizontal': this.horizontal, 'mobile_view': this.mobile_view}
}
this.get = function(name) {
if(this.hasOwnProperty(name)) return this[name];
}
this.set = function(name, value) {
if(this.hasOwnProperty(name)) this[name] = value;
}
//return a reference to self (sidebar instance)
this.ref = function() {
return this;
}
//toggle icon for sidebar collapse/expand button
var toggleIcon = function(minimized, save) {
var icon = $(this).find(ace.vars['.icon']), icon1, icon2;
if(icon.length > 0) {
icon1 = icon.attr('data-icon1');//the icon for expanded state
icon2 = icon.attr('data-icon2');//the icon for collapsed state
if(typeof minimized !== "undefined") {
if(minimized) icon.removeClass(icon1).addClass(icon2);
else icon.removeClass(icon2).addClass(icon1);
}
else {
icon.toggleClass(icon1).toggleClass(icon2);
}
try {
if(save !== false) ace.settings.saveState(icon.get(0));
} catch(e) {}
}
}
//if not specified, find the toggle button related to this sidebar
var findToggleBtn = function() {
var toggle_btn = self.$sidebar.find('.sidebar-collapse');
if(toggle_btn.length == 0) toggle_btn = $('.sidebar-collapse[data-target="#'+(self.$sidebar.attr('id')||'')+'"]');
if(toggle_btn.length != 0) toggle_btn = toggle_btn[0];
else toggle_btn = null;
return toggle_btn;
}
//collapse/expand sidebar
this.toggleMenu = function(toggle_btn, save) {
if(this.collapsible) return false;
this.minimized = !this.minimized;
var save = !(toggle_btn === false || save === false);
if(this.minimized) this.$sidebar.addClass('menu-min');
else this.$sidebar.removeClass('menu-min');
try {
if(save) ace.settings.saveState(sidebar, 'class', 'menu-min', this.minimized);
} catch(e) {}
if( !toggle_btn ) {
toggle_btn = findToggleBtn();
}
if(toggle_btn) {
toggleIcon.call(toggle_btn, this.minimized, save);
}
//force redraw for ie8
if(ace.vars['old_ie']) ace.helper.redraw(sidebar);
$(document).trigger('settings.ace', ['sidebar_collapsed' , this.minimized, sidebar, save]);
if( this.minimized ) this.$sidebar.trigger($.Event('collapse.ace.sidebar'));
else this.$sidebar.trigger($.Event('expand.ace.sidebar'));
return true;
}
this.collapse = function(toggle_btn, save) {
if(this.collapsible) return;
this.minimized = false;
this.toggleMenu(toggle_btn, save)
}
this.expand = function(toggle_btn, save) {
if(this.collapsible) return;
this.minimized = true;
this.toggleMenu(toggle_btn, save);
}
this.showResponsive = function() {
this.$sidebar.removeClass(responsive_min_class).removeClass(responsive_max_class);
}
//collapse/expand in 2nd mobile style
this.toggleResponsive = function(toggle_btn, showMenu) {
if( !this.mobile_view || this.mobile_style != 3 ) return;
if( this.$sidebar.hasClass('menu-min') ) {
//remove menu-min because it interferes with responsive-max
this.$sidebar.removeClass('menu-min');
var btn = findToggleBtn();
if(btn) toggleIcon.call(btn);
}
var showMenu = typeof showMenu === 'boolean' ? showMenu : (typeof toggle_btn === 'boolean' ? toggle_btn : this.$sidebar.hasClass(responsive_min_class));
if(showMenu) {
this.$sidebar.addClass(responsive_max_class).removeClass(responsive_min_class);
}
else {
this.$sidebar.removeClass(responsive_max_class).addClass(responsive_min_class);
}
this.minimized = !showMenu;
if( !toggle_btn || typeof toggle_btn !== 'object' ) {
toggle_btn = this.$sidebar.find('.sidebar-expand');
if(toggle_btn.length == 0) toggle_btn = $('.sidebar-expand[data-target="#'+(this.$sidebar.attr('id')||'')+'"]');
if(toggle_btn.length != 0) toggle_btn = toggle_btn[0];
else toggle_btn = null;
}
if(toggle_btn) {
var icon = $(toggle_btn).find(ace.vars['.icon']), icon1, icon2;
if(icon.length > 0) {
icon1 = icon.attr('data-icon1');//the icon for expanded state
icon2 = icon.attr('data-icon2');//the icon for collapsed state
if(!showMenu) icon.removeClass(icon2).addClass(icon1);
else icon.removeClass(icon1).addClass(icon2);
}
}
if(showMenu) self.$sidebar.trigger($.Event('mobileShow.ace.sidebar'));
else self.$sidebar.trigger($.Event('mobileHide.ace.sidebar'));
$(document).triggerHandler('settings.ace', ['sidebar_collapsed' , this.minimized]);
}
//some helper functions
//determine if we have 4th mobile style responsive sidebar and we are in mobile view
this.is_collapsible = function() {
var toggle
return (this.$sidebar.hasClass('navbar-collapse'))
&& ((toggle = $('.navbar-toggle[data-target="#'+(this.$sidebar.attr('id')||'')+'"]').get(0)) != null)
&& toggle.scrollHeight > 0
//sidebar is collapsible and collapse button is visible?
}
//determine if we are in mobile view
this.is_mobile_view = function() {
var toggle
return ((toggle = $('.menu-toggler[data-target="#'+(this.$sidebar.attr('id')||'')+'"]').get(0)) != null)
&& toggle.scrollHeight > 0
}
var submenu_working = false;
//show submenu
this.show = function(sub, $duration, shouldWait) {
//'shouldWait' indicates whether to wait for previous transition (submenu toggle) to be complete or not?
shouldWait = (shouldWait !== false);
if(shouldWait && submenu_working) return false;
var $sub = $(sub);
var event;
$sub.trigger(event = $.Event('show.ace.submenu'))
if (event.isDefaultPrevented()) {
return false;
}
if(shouldWait) submenu_working = true;
$duration = typeof $duration !== 'undefined' ? $duration : this.settings.duration;
$sub.css({
height: 0,
overflow: 'hidden',
display: 'block'
})
.removeClass('nav-hide').addClass('nav-show')//only for window < @grid-float-breakpoint and .navbar-collapse.menu-min
.parent().addClass('open');
sub.scrollTop = 0;//this is for submenu_hover when sidebar is minimized and a submenu is scrollTop'ed using scrollbars ...
var complete = function(ev, trigger) {
ev && ev.stopPropagation();
$sub
.css({'transition-property': '', 'transition-duration': '', overflow:'', height: ''})
//if(ace.vars['webkit']) ace.helper.redraw(sub);//little Chrome issue, force redraw ;)
if(trigger !== false) $sub.trigger($.Event('shown.ace.submenu'))
if(shouldWait) submenu_working = false;
}
var finalHeight = sub.scrollHeight;
if($duration == 0 || finalHeight == 0 || !$.support.transition.end) {
//(if duration is zero || element is hidden (scrollHeight == 0) || CSS3 transitions are not available)
complete();
}
else {
$sub
.css({
'height': finalHeight,
'transition-property': 'height',
'transition-duration': ($duration/1000)+'s'
}
)
.one($.support.transition.end, complete);
//there is sometimes a glitch, so maybe retry
if(ace.vars['android'] ) {
setTimeout(function() {
complete(null, false);
ace.helper.redraw(sub);
}, $duration + 20);
}
}
return true;
}
//hide submenu
this.hide = function(sub, $duration, shouldWait) {
//'shouldWait' indicates whether to wait for previous transition (submenu toggle) to be complete or not?
shouldWait = (shouldWait !== false);
if(shouldWait && submenu_working) return false;
var $sub = $(sub);
var event;
$sub.trigger(event = $.Event('hide.ace.submenu'))
if (event.isDefaultPrevented()) {
return false;
}
if(shouldWait) submenu_working = true;
$duration = typeof $duration !== 'undefined' ? $duration : this.settings.duration;
var initialHeight = sub.scrollHeight;
$sub.css({
height: initialHeight,
overflow: 'hidden',
display: 'block'
})
.parent().removeClass('open');
sub.offsetHeight;
//forces the "sub" to re-consider the new 'height' before transition
var complete = function(ev, trigger) {
ev && ev.stopPropagation();
$sub
.css({display: 'none', overflow:'', height: '', 'transition-property': '', 'transition-duration': ''})
.removeClass('nav-show').addClass('nav-hide')//only for window < @grid-float-breakpoint and .navbar-collapse.menu-min
if(trigger !== false) $sub.trigger($.Event('hidden.ace.submenu'))
if(shouldWait) submenu_working = false;
}
if( $duration == 0 || initialHeight == 0 || !$.support.transition.end) {
//(if duration is zero || element is hidden (scrollHeight == 0) || CSS3 transitions are not available)
complete();
}
else {
$sub
.css({
'height': 0,
'transition-property': 'height',
'transition-duration': ($duration/1000)+'s'
}
)
.one($.support.transition.end, complete);
//there is sometimes a glitch, so maybe retry
if(ace.vars['android'] ) {
setTimeout(function() {
complete(null, false);
ace.helper.redraw(sub);
}, $duration + 20);
}
}
return true;
}
//toggle submenu
this.toggle = function(sub, $duration) {
$duration = $duration || self.settings.duration;
if( sub.scrollHeight == 0 ) {//if an element is hidden scrollHeight becomes 0
if( this.show(sub, $duration) ) return 1;
} else {
if( this.hide(sub, $duration) ) return -1;
}
return 0;
}
//toggle mobile menu
this.mobileToggle = function(showMenu) {
if(this.mobile_view) {
if(this.mobile_style == 1 || this.mobile_style == 2) {
this.toggleMobile(typeof showMenu === 'object' ? showMenu : null, typeof showMenu === 'boolean' ? showMenu : null);
}
else if(this.mobile_style == 3) {
this.toggleResponsive(typeof showMenu === 'object' ? showMenu : null, typeof showMenu === 'boolean' ? showMenu : null);
}
//return true;
}
else if(this.collapsible) {
this.toggleCollapsible(typeof showMenu === 'object' ? showMenu : null, typeof showMenu === 'boolean' ? showMenu : null);
//return true;
}
//return true;
}
this.mobileShow = function() {
this.mobileToggle(true);
}
this.mobileHide = function() {
this.mobileToggle(false);
}
this.toggleMobile = function(toggle_btn, showMenu) {
if(!(this.mobile_style == 1 || this.mobile_style == 2)) return;
var showMenu = typeof showMenu === 'boolean' ? showMenu : (typeof toggle_btn === 'boolean' ? toggle_btn : !this.$sidebar.hasClass('display'));
if( !toggle_btn || typeof toggle_btn !== 'object' ) {
toggle_btn = $('.menu-toggler[data-target="#'+(this.$sidebar.attr('id')||'')+'"]');
if(toggle_btn.length != 0) toggle_btn = toggle_btn[0];
else toggle_btn = null;
}
if(showMenu) {
this.$sidebar.addClass('display');
if(toggle_btn) $(toggle_btn).addClass('display');
}
else {