Completed
Push — master ( 61e59c...44cd18 )
by Xu
507:20 queued 467:22
created

inspinia.js ➔ localStorageSupport   A

Complexity

Conditions 1
Paths 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
/*
2
 *
3
 *   INSPINIA - Responsive Admin Theme
4
 *   version 2.7
5
 *
6
 */
7
8
$(document).ready(function () {
9
10
11
    // Add body-small class if window less than 768px
12
    if ($(this).width() < 769) {
13
        $('body').addClass('body-small')
14
    } else {
15
        $('body').removeClass('body-small')
16
    }
17
18
    // MetisMenu
19
    $('#side-menu').metisMenu();
20
21
    // Collapse ibox function
22
    $('.collapse-link').on('click', function () {
23
        var ibox = $(this).closest('div.ibox');
24
        var button = $(this).find('i');
25
        var content = ibox.children('.ibox-content');
26
        content.slideToggle(200);
27
        button.toggleClass('fa-chevron-up').toggleClass('fa-chevron-down');
28
        ibox.toggleClass('').toggleClass('border-bottom');
29
        setTimeout(function () {
30
            ibox.resize();
31
            ibox.find('[id^=map-]').resize();
32
        }, 50);
33
    });
34
35
    // Close ibox function
36
    $('.close-link').on('click', function () {
37
        var content = $(this).closest('div.ibox');
38
        content.remove();
39
    });
40
41
    // Fullscreen ibox function
42
    $('.fullscreen-link').on('click', function () {
43
        var ibox = $(this).closest('div.ibox');
44
        var button = $(this).find('i');
45
        $('body').toggleClass('fullscreen-ibox-mode');
46
        button.toggleClass('fa-expand').toggleClass('fa-compress');
47
        ibox.toggleClass('fullscreen');
48
        setTimeout(function () {
49
            $(window).trigger('resize');
50
        }, 100);
51
    });
52
53
    // Close menu in canvas mode
54
    $('.close-canvas-menu').on('click', function () {
55
        $("body").toggleClass("mini-navbar");
56
        SmoothlyMenu();
57
    });
58
59
    // Run menu of canvas
60
    $('body.canvas-menu .sidebar-collapse').slimScroll({
61
        height: '100%',
62
        railOpacity: 0.9
63
    });
64
65
    // Open close right sidebar
66
    $('.right-sidebar-toggle').on('click', function () {
67
        $('#right-sidebar').toggleClass('sidebar-open');
68
    });
69
70
    // Initialize slimscroll for right sidebar
71
    $('.sidebar-container').slimScroll({
72
        height: '100%',
73
        railOpacity: 0.4,
74
        wheelStep: 10
75
    });
76
77
    // Open close small chat
78
    $('.open-small-chat').on('click', function () {
79
        $(this).children().toggleClass('fa-comments').toggleClass('fa-remove');
80
        $('.small-chat-box').toggleClass('active');
81
    });
82
83
    // Initialize slimscroll for small chat
84
    $('.small-chat-box .content').slimScroll({
85
        height: '234px',
86
        railOpacity: 0.4
87
    });
88
89
    // Small todo handler
90
    $('.check-link').on('click', function () {
91
        var button = $(this).find('i');
92
        var label = $(this).next('span');
93
        button.toggleClass('fa-check-square').toggleClass('fa-square-o');
94
        label.toggleClass('todo-completed');
95
        return false;
96
    });
97
98
    // Append config box / Only for demo purpose
99
    // Uncomment on server mode to enable XHR calls
100
    // $.get("skin-config.html", function (data) {
101
    //     if (!$('body').hasClass('no-skin-config'))
102
    //         $('body').append(data);
103
    // });
104
105
    // Minimalize menu
106
    $('.navbar-minimalize').on('click', function () {
107
        $("body").toggleClass("mini-navbar");
108
        SmoothlyMenu();
109
110
    });
111
112
    // Tooltips demo
113
    $('.tooltip-demo').tooltip({
114
        selector: "[data-toggle=tooltip]",
115
        container: "body"
116
    });
117
118
119
    // Full height of sidebar
120
    function fix_height() {
121
        var heightWithoutNavbar = $("body > #wrapper").height() - 61;
122
        $(".sidebar-panel").css("min-height", heightWithoutNavbar + "px");
123
124
        var navbarheight = $('nav.navbar-default').height();
125
        var wrapperHeight = $('#page-wrapper').height();
126
127
        if (navbarheight > wrapperHeight) {
128
            $('#page-wrapper').css("min-height", navbarheight + "px");
129
        }
130
131
        if (navbarheight < wrapperHeight) {
132
            $('#page-wrapper').css("min-height", $(window).height() + "px");
133
        }
134
135
        if ($('body').hasClass('fixed-nav')) {
136
            if (navbarheight > wrapperHeight) {
137
                $('#page-wrapper').css("min-height", navbarheight + "px");
138
            } else {
139
                $('#page-wrapper').css("min-height", $(window).height() - 60 + "px");
140
            }
141
        }
142
143
    }
144
145
    fix_height();
146
147
    // Fixed Sidebar
148
    $(window).bind("load", function () {
149
        if ($("body").hasClass('fixed-sidebar')) {
150
            $('.sidebar-collapse').slimScroll({
151
                height: '100%',
152
                railOpacity: 0.9
153
            });
154
        }
155
    });
156
157
    // Move right sidebar top after scroll
158
    $(window).scroll(function () {
159
        if ($(window).scrollTop() > 0 && !$('body').hasClass('fixed-nav')) {
160
            $('#right-sidebar').addClass('sidebar-top');
161
        } else {
162
            $('#right-sidebar').removeClass('sidebar-top');
163
        }
164
    });
165
166
    $(window).bind("load resize scroll", function () {
167
        if (!$("body").hasClass('body-small')) {
168
            fix_height();
169
        }
170
    });
171
172
    $("[data-toggle=popover]")
173
        .popover();
174
175
    // Add slimscroll to element
176
    $('.full-height-scroll').slimscroll({
177
        height: '100%'
178
    })
179
});
180
181
182
// Minimalize menu when screen is less than 768px
183
$(window).bind("resize", function () {
184
    if ($(this).width() < 769) {
185
        $('body').addClass('body-small')
186
    } else {
187
        $('body').removeClass('body-small')
188
    }
189
});
190
191
// Local Storage functions
192
// Set proper body class and plugins based on user configuration
193
$(document).ready(function () {
194
    if (localStorageSupport()) {
195
196
        var collapse = localStorage.getItem("collapse_menu");
0 ignored issues
show
Bug introduced by
The variable localStorage seems to be never declared. If this is a global, consider adding a /** global: localStorage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
197
        var fixedsidebar = localStorage.getItem("fixedsidebar");
198
        var fixednavbar = localStorage.getItem("fixednavbar");
199
        var boxedlayout = localStorage.getItem("boxedlayout");
200
        var fixedfooter = localStorage.getItem("fixedfooter");
201
202
        var body = $('body');
203
204
        if (fixedsidebar == 'on') {
205
            body.addClass('fixed-sidebar');
206
            $('.sidebar-collapse').slimScroll({
207
                height: '100%',
208
                railOpacity: 0.9
209
            });
210
        }
211
212
        if (collapse == 'on') {
213
            if (body.hasClass('fixed-sidebar')) {
214
                if (!body.hasClass('body-small')) {
215
                    body.addClass('mini-navbar');
216
                }
217
            } else {
218
                if (!body.hasClass('body-small')) {
219
                    body.addClass('mini-navbar');
220
                }
221
222
            }
223
        }
224
225
        if (fixednavbar == 'on') {
226
            $(".navbar-static-top").removeClass('navbar-static-top').addClass('navbar-fixed-top');
227
            body.addClass('fixed-nav');
228
        }
229
230
        if (boxedlayout == 'on') {
231
            body.addClass('boxed-layout');
232
        }
233
234
        if (fixedfooter == 'on') {
235
            $(".footer").addClass('fixed');
236
        }
237
    }
238
});
239
240
// check if browser support HTML5 local storage
241
function localStorageSupport() {
242
    return (('localStorage' in window) && window['localStorage'] !== null)
243
}
244
245
// For demo purpose - animation css script
246
function animationHover(element, animation) {
247
    element = $(element);
248
    element.hover(
249
        function () {
250
            element.addClass('animated ' + animation);
251
        },
252
        function () {
253
            //wait for animation to finish before removing classes
254
            window.setTimeout(function () {
255
                element.removeClass('animated ' + animation);
256
            }, 2000);
257
        });
258
}
259
260
function SmoothlyMenu() {
261
    if (!$('body').hasClass('mini-navbar') || $('body').hasClass('body-small')) {
262
        // Hide menu in order to smoothly turn on when maximize menu
263
        $('#side-menu').hide();
264
        // For smoothly turn on menu
265
        setTimeout(
266
            function () {
267
                $('#side-menu').fadeIn(400);
268
            }, 200);
269
    } else if ($('body').hasClass('fixed-sidebar')) {
270
        $('#side-menu').hide();
271
        setTimeout(
272
            function () {
273
                $('#side-menu').fadeIn(400);
274
            }, 100);
275
    } else {
276
        // Remove all inline style from jquery fadeIn function to reset menu state
277
        $('#side-menu').removeAttr('style');
278
    }
279
}
280
281
// Dragable panels
282
function WinMove() {
283
    var element = "[class*=col]";
284
    var handle = ".ibox-title";
285
    var connect = "[class*=col]";
286
    $(element).sortable(
287
        {
288
            handle: handle,
289
            connectWith: connect,
290
            tolerance: 'pointer',
291
            forcePlaceholderSize: true,
292
            opacity: 0.8
293
        })
294
        .disableSelection();
295
}
296
297
298