wangrong
2025-09-23 40634ebaf5863a599bba8ca2c0575ca079fb8e15
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
/**
 * UI v1.1.0
 * Copyright 2017-2018 Muyao
 * Licensed under the Muyao License 1.0 
 */
(function (window, document, $) {
    'use strict';
 
    /***
     * 左侧菜单响应式操作
     *
     * **/
 
    $.site.menubar = {
        opened: null,
        folded: null,
        top: false,
        foldAlt: false,
        auto: true,
        init: function () {
            var self = this,
                $body = this.$body = $('body'),
                $html = this.$html = $('html'),
                $instance = this.$instance = $("#admui-navTabs");
 
            $html.removeClass('css-menubar').addClass('js-menubar');
 
            this.tabId = $('#admui-navbar').find('li.active > a').attr('href');
 
            if (this.tabId === '#') {
                this.tabId = $('.nav-tabs li.active').find('ul>li.active>a').attr('href');
            }
 
            if (!$instance.length) {
                return;
            }
 
            // 鼠标经过左侧菜单显示图标
            if ($body.is('.site-menubar-fold-alt')) {
                this.foldAlt = true;
            }
 
            // 鼠标经过左侧菜单显示文字
            if ($body.is('.site-menubar-keep')) {
                if ($body.hasClass('site-menubar-fold')) { // 收起
                    this.auto = 'fold';
                } else if ($body.hasClass('site-menubar-unfold')) { //展开
                    this.auto = 'unfold';
                }
            }
 
            $instance.on('changed.site.menubar', function () {
                self.update();
            });
 
            $('.nav-tabs li:not(.no-menu)').on('shown.bs.tab', function (event) {
                var tabId = self.tabId = $(event.target).attr('href');
 
                if ($body.hasClass('site-menubar-fold')) {
                    self.hoverscroll.enable(tabId);
                } else if ($body.hasClass('site-menubar-unfold')) {
                    self.slimScroll.enable();
                }
            });
 
            this.change();
        },
        change: function () {
            var breakpoint = Breakpoints.current();
 
            if (this.auto !== true) {
                switch (this.auto) {
                    case 'fold':
                        this.reset();
                        if (breakpoint.name === 'xs') {
                            this.hide();
                        } else {
                            this.fold();
                        }
                        return;
                    case 'unfold':
                        this.reset();
                        if (breakpoint.name === 'xs') {
                            this.hide();
                        } else {
                            this.unfold();
                        }
                        return;
                }
            }
 
            this.reset();
 
            if (breakpoint) {
                switch (breakpoint.name) {
                    case 'lg':
                        this.unfold();
                        break;
                    case 'md':
                    case 'sm':
                        this.fold();
                        break;
                    case 'xs':
                        this.hide();
                        break;
                }
            }
            Breakpoints.on('xs', 'leave', function () {
                $('#admui-navbar').responsiveHorizontalTabs({
                    tabParentSelector: '#admui-navTabs',
                    fnCallback: function (el) {
                        if ($('#admui-navbar').is(':visible')) {
                            el.removeClass('is-load');
                        }
                    }
                });
            });
        },
        animate: function (doing, callback) {
            var self = this,
                $body = self.$body;
 
            $body.addClass('site-menubar-changing');
 
            doing.call(self);
            this.$instance.trigger('changing.site.menubar');
 
            callback.call(self);
            $body.removeClass('site-menubar-changing');
 
            self.$instance.trigger('changed.site.menubar');
        },
        reset: function () {
            this.opened = null;
            this.folded = null;
            this.$body.removeClass('site-menubar-hide site-menubar-open site-menubar-fold site-menubar-unfold');
            this.$html.removeClass('disable-scrolling');
        },
        open: function () {
            if (this.opened !== true) {
                this.animate(function () {
                    this.$body.removeClass('site-menubar-hide').addClass('site-menubar-open site-menubar-unfold');
                    this.opened = true;
 
                    this.$html.addClass('disable-scrolling');
 
                }, function () {
                    this.slimScroll.enable();
                });
            }
        },
        hide: function () {
            this.hoverscroll.disable();
 
            if (this.opened !== false) {
                this.animate(function () {
 
                    this.$html.removeClass('disable-scrolling');
                    this.$body.removeClass('site-menubar-open').addClass('site-menubar-hide site-menubar-unfold');
                    this.opened = false;
 
                }, function () {
                    this.slimScroll.enable();
                });
            }
        },
        unfold: function () {
            this.hoverscroll.disable();
 
            if (this.folded !== false) {
                this.animate(function () {
                    this.$body.removeClass('site-menubar-fold').addClass('site-menubar-unfold');
                    this.folded = false;
 
                }, function () {
                    this.slimScroll.enable();
                });
            }
        },
        fold: function () {
            this.slimScroll.destroy();
 
            if (this.folded !== true) {
                this.animate(function () {
                    this.$body.removeClass('site-menubar-unfold').addClass('site-menubar-fold');
                    this.folded = true;
 
                }, function () {
                    this.hoverscroll.enable(this.tabId);
                });
            }
        },
        toggle: function () {
            var breakpoint = Breakpoints.current(),
                folded = this.folded,
                opened = this.opened;
 
            switch (breakpoint.name) {
                case 'lg':
                    if (folded === null || folded === false) {
                        this.fold();
                    } else {
                        this.unfold();
                    }
                    break;
                case 'md':
                case 'sm':
                    if (folded === null || folded === true) {
                        this.unfold();
                    } else {
                        this.fold();
                    }
 
                    $('#admui-navbar').responsiveHorizontalTabs({
                        tabParentSelector: '#admui-navTabs'
                    });
                    break;
                case 'xs':
                    if (opened === null || opened === false) {
                        this.open();
                    } else {
                        this.hide();
                    }
                    break;
            }
        },
        update: function () {
            this.hoverscroll.update();
        },
        slimScroll: {
            api: null,
            native: false,
            init: function () {
                // if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
                //   this.native = true;
                //   $body.addClass('site-menubar-native');
                //   return;
                // }
 
                if ($('body').is('.site-menubar-native')) {
                    this.native = true;
                    return;
                }
 
                $.site.menubar.$instance.slimScroll($.po('slimScroll'));
            },
            enable: function () {
                if (this.native) {
                    return;
                }
                this.init();
            },
            destroy: function () {
                $.site.menubar.$instance.slimScroll({destroy: true});
                $.site.menubar.$instance.removeAttr('style');
            }
        },
        hoverscroll: {
            api: null,
            init: function (tabId) {
                $.site.menubar.$instance.find(tabId).children('div').attr('style', '');
 
                this.api = $.site.menubar.$instance.find(tabId).asHoverScroll({
                    namespace: 'hoverscorll',
                    direction: 'vertical',
                    list: '.site-menu',
                    item: '> li',
                    exception: '.site-menu-sub',
                    fixed: false,
                    boundary: 100,
                    onEnter: function () {
                        //$(this).siblings().removeClass('hover');
                        //$(this).addClass('hover');
                    },
                    onLeave: function () {
                        //$(this).removeClass('hover');
                    }
                }).data('asHoverScroll');
            },
 
            update: function () {
                if (this.api) {
                    this.api.update();
                }
            },
 
            enable: function (tabId) {
                if (tabId !== this.tabId) {
                    this.tabId = tabId;
                    this.init(tabId);
                } else {
                    this.api.enable();
                }
            },
 
            disable: function () {
                if (this.api) {
                    this.api.disable();
                }
            }
        }
    };
 
})(window, document, jQuery);