Subversion Repositories Integrator Subversion

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 espaco 1
/**
2
Core script to handle the entire theme and core functions
3
**/
4
var Metronic = function() {
5
 
6
    // IE mode
7
    var isRTL = false;
8
    var isIE8 = false;
9
    var isIE9 = false;
10
    var isIE10 = false;
11
 
12
    var resizeHandlers = [];
13
 
14
    var assetsPath = '../../assets/';
15
 
16
    var globalImgPath = 'global/img/';
17
 
18
    var globalPluginsPath = 'global/plugins/';
19
 
20
    var globalCssPath = 'global/css/';
21
 
22
    // theme layout color set
23
 
24
    var brandColors = {
25
        'blue': '#89C4F4',
26
        'red': '#F3565D',
27
        'green': '#1bbc9b',
28
        'purple': '#9b59b6',
29
        'grey': '#95a5a6',
30
        'yellow': '#F8CB00'
31
    };
32
 
33
    // initializes main settings
34
    var handleInit = function() {
35
 
36
        if ($('body').css('direction') === 'rtl') {
37
            isRTL = true;
38
        }
39
 
40
        isIE8 = !!navigator.userAgent.match(/MSIE 8.0/);
41
        isIE9 = !!navigator.userAgent.match(/MSIE 9.0/);
42
        isIE10 = !!navigator.userAgent.match(/MSIE 10.0/);
43
 
44
        if (isIE10) {
45
            $('html').addClass('ie10'); // detect IE10 version
46
        }
47
 
48
        if (isIE10 || isIE9 || isIE8) {
49
            $('html').addClass('ie'); // detect IE10 version
50
        }
51
    };
52
 
53
    // runs callback functions set by Metronic.addResponsiveHandler().
54
    var _runResizeHandlers = function() {
55
        // reinitialize other subscribed elements
56
        for (var i = 0; i < resizeHandlers.length; i++) {
57
            var each = resizeHandlers[i];
58
            each.call();
59
        }
60
    };
61
 
62
    // handle the layout reinitialization on window resize
63
    var handleOnResize = function() {
64
        var resize;
65
        if (isIE8) {
66
            var currheight;
67
            $(window).resize(function() {
68
                if (currheight == document.documentElement.clientHeight) {
69
                    return; //quite event since only body resized not window.
70
                }
71
                if (resize) {
72
                    clearTimeout(resize);
73
                }
74
                resize = setTimeout(function() {
75
                    _runResizeHandlers();
76
                }, 50); // wait 50ms until window resize finishes.                
77
                currheight = document.documentElement.clientHeight; // store last body client height
78
            });
79
        } else {
80
            $(window).resize(function() {
81
                if (resize) {
82
                    clearTimeout(resize);
83
                }
84
                resize = setTimeout(function() {
85
                    _runResizeHandlers();
86
                }, 50); // wait 50ms until window resize finishes.
87
            });
88
        }
89
    };
90
 
91
    // Handles portlet tools & actions
92
    var handlePortletTools = function() {
93
        // handle portlet remove
94
        $('body').on('click', '.portlet > .portlet-title > .tools > a.remove', function(e) {
95
            e.preventDefault();
96
            var portlet = $(this).closest(".portlet");
97
 
98
            if ($('body').hasClass('page-portlet-fullscreen')) {
99
                $('body').removeClass('page-portlet-fullscreen');
100
            }
101
 
102
            portlet.find('.portlet-title .fullscreen').tooltip('destroy');
103
            portlet.find('.portlet-title > .tools > .reload').tooltip('destroy');
104
            portlet.find('.portlet-title > .tools > .remove').tooltip('destroy');
105
            portlet.find('.portlet-title > .tools > .config').tooltip('destroy');
106
            portlet.find('.portlet-title > .tools > .collapse, .portlet > .portlet-title > .tools > .expand').tooltip('destroy');
107
 
108
            portlet.remove();
109
        });
110
 
111
        // handle portlet fullscreen
112
        $('body').on('click', '.portlet > .portlet-title .fullscreen', function(e) {
113
            e.preventDefault();
114
            var portlet = $(this).closest(".portlet");
115
            if (portlet.hasClass('portlet-fullscreen')) {
116
                $(this).removeClass('on');
117
                portlet.removeClass('portlet-fullscreen');
118
                $('body').removeClass('page-portlet-fullscreen');
119
                portlet.children('.portlet-body').css('height', 'auto');
120
            } else {
121
                var height = Metronic.getViewPort().height -
122
                    portlet.children('.portlet-title').outerHeight() -
123
                    parseInt(portlet.children('.portlet-body').css('padding-top')) -
124
                    parseInt(portlet.children('.portlet-body').css('padding-bottom'));
125
 
126
                $(this).addClass('on');
127
                portlet.addClass('portlet-fullscreen');
128
                $('body').addClass('page-portlet-fullscreen');
129
                portlet.children('.portlet-body').css('height', height);
130
            }
131
        });
132
 
133
        $('body').on('click', '.portlet > .portlet-title > .tools > a.reload', function(e) {
134
            e.preventDefault();
135
            var el = $(this).closest(".portlet").children(".portlet-body");
136
            var url = $(this).attr("data-url");
137
            var error = $(this).attr("data-error-display");
138
            if (url) {
139
                Metronic.blockUI({
140
                    target: el,
141
                    animate: true,
142
                    overlayColor: 'none'
143
                });
144
                $.ajax({
145
                    type: "GET",
146
                    cache: false,
147
                    url: url,
148
                    dataType: "html",
149
                    success: function(res) {
150
                        Metronic.unblockUI(el);
151
                        el.html(res);
152
                    },
153
                    error: function(xhr, ajaxOptions, thrownError) {
154
                        Metronic.unblockUI(el);
155
                        var msg = 'Error on reloading the content. Please check your connection and try again.';
156
                        if (error == "toastr" && toastr) {
157
                            toastr.error(msg);
158
                        } else if (error == "notific8" && $.notific8) {
159
                            $.notific8('zindex', 11500);
160
                            $.notific8(msg, {
161
                                theme: 'ruby',
162
                                life: 3000
163
                            });
164
                        } else {
165
                            alert(msg);
166
                        }
167
                    }
168
                });
169
            } else {
170
                // for demo purpose
171
                Metronic.blockUI({
172
                    target: el,
173
                    animate: true,
174
                    overlayColor: 'none'
175
                });
176
                window.setTimeout(function() {
177
                    Metronic.unblockUI(el);
178
                }, 1000);
179
            }
180
        });
181
 
182
        // load ajax data on page init
183
        $('.portlet .portlet-title a.reload[data-load="true"]').click();
184
 
185
        $('body').on('click', '.portlet > .portlet-title > .tools > .collapse, .portlet .portlet-title > .tools > .expand', function(e) {
186
            e.preventDefault();
187
            var el = $(this).closest(".portlet").children(".portlet-body");
188
            if ($(this).hasClass("collapse")) {
189
                $(this).removeClass("collapse").addClass("expand");
190
                el.slideUp(200);
191
            } else {
192
                $(this).removeClass("expand").addClass("collapse");
193
                el.slideDown(200);
194
            }
195
        });
196
    };
197
 
198
    // Handles custom checkboxes & radios using jQuery Uniform plugin
199
    var handleUniform = function() {
200
        if (!$().uniform) {
201
            return;
202
        }
203
        var test = $("input[type=checkbox]:not(.toggle, .make-switch, .icheck), input[type=radio]:not(.toggle, .star, .make-switch, .icheck)");
204
        if (test.size() > 0) {
205
            test.each(function() {
206
                if ($(this).parents(".checker").size() === 0) {
207
                    $(this).show();
208
                    $(this).uniform();
209
                }
210
            });
211
        }
212
    };
213
 
214
    // Handles custom checkboxes & radios using jQuery iCheck plugin
215
    var handleiCheck = function() {
216
        if (!$().iCheck) {
217
            return;
218
        }
219
 
220
        $('.icheck').each(function() {
221
            var checkboxClass = $(this).attr('data-checkbox') ? $(this).attr('data-checkbox') : 'icheckbox_minimal-grey';
222
            var radioClass = $(this).attr('data-radio') ? $(this).attr('data-radio') : 'iradio_minimal-grey';
223
 
224
            if (checkboxClass.indexOf('_line') > -1 || radioClass.indexOf('_line') > -1) {
225
                $(this).iCheck({
226
                    checkboxClass: checkboxClass,
227
                    radioClass: radioClass,
228
                    insert: '<div class="icheck_line-icon"></div>' + $(this).attr("data-label")
229
                });
230
            } else {
231
                $(this).iCheck({
232
                    checkboxClass: checkboxClass,
233
                    radioClass: radioClass
234
                });
235
            }
236
        });
237
    };
238
 
239
    // Handles Bootstrap switches
240
    var handleBootstrapSwitch = function() {
241
        if (!$().bootstrapSwitch) {
242
            return;
243
        }
244
        $('.make-switch').bootstrapSwitch();
245
    };
246
 
247
    // Handles Bootstrap confirmations
248
    var handleBootstrapConfirmation = function() {
249
        if (!$().confirmation) {
250
            return;
251
        }
252
        $('[data-toggle=confirmation]').confirmation({ container: 'body', btnOkClass: 'btn-xs btn-success', btnCancelClass: 'btn-xs btn-danger'});
253
    }
254
 
255
    // Handles Bootstrap Accordions.
256
    var handleAccordions = function() {
257
        $('body').on('shown.bs.collapse', '.accordion.scrollable', function(e) {
258
            Metronic.scrollTo($(e.target));
259
        });
260
    };
261
 
262
    // Handles Bootstrap Tabs.
263
    var handleTabs = function() {
264
        //activate tab if tab id provided in the URL
265
        if (location.hash) {
266
            var tabid = location.hash.substr(1);
267
            $('a[href="#' + tabid + '"]').parents('.tab-pane:hidden').each(function() {
268
                var tabid = $(this).attr("id");
269
                $('a[href="#' + tabid + '"]').click();
270
            });
271
            $('a[href="#' + tabid + '"]').click();
272
        }
273
    };
274
 
275
    // Handles Bootstrap Modals.
276
    var handleModals = function() {        
277
        // fix stackable modal issue: when 2 or more modals opened, closing one of modal will remove .modal-open class. 
278
        $('body').on('hide.bs.modal', function() {
279
            if ($('.modal:visible').size() > 1 && $('html').hasClass('modal-open') === false) {
280
                $('html').addClass('modal-open');
281
            } else if ($('.modal:visible').size() <= 1) {
282
                $('html').removeClass('modal-open');
283
            }
284
        });
285
 
286
        // fix page scrollbars issue
287
        $('body').on('show.bs.modal', '.modal', function() {
288
            if ($(this).hasClass("modal-scroll")) {
289
                $('body').addClass("modal-open-noscroll");
290
            }
291
        });
292
 
293
        // fix page scrollbars issue
294
        $('body').on('hide.bs.modal', '.modal', function() {
295
            $('body').removeClass("modal-open-noscroll");
296
        });
297
 
298
        // remove ajax content and remove cache on modal closed 
299
        $('body').on('hidden.bs.modal', '.modal:not(.modal-cached)', function () {
300
            $(this).removeData('bs.modal');
301
        });
302
    };
303
 
304
    // Handles Bootstrap Tooltips.
305
    var handleTooltips = function() {
306
        // global tooltips
307
        $('.tooltips').tooltip();
308
 
309
        // portlet tooltips
310
        $('.portlet > .portlet-title .fullscreen').tooltip({
311
            container: 'body',
312
            title: 'Fullscreen'
313
        });
314
        $('.portlet > .portlet-title > .tools > .reload').tooltip({
315
            container: 'body',
316
            title: 'Reload'
317
        });
318
        $('.portlet > .portlet-title > .tools > .remove').tooltip({
319
            container: 'body',
320
            title: 'Remove'
321
        });
322
        $('.portlet > .portlet-title > .tools > .config').tooltip({
323
            container: 'body',
324
            title: 'Settings'
325
        });
326
        $('.portlet > .portlet-title > .tools > .collapse, .portlet > .portlet-title > .tools > .expand').tooltip({
327
            container: 'body',
328
            title: 'Collapse/Expand'
329
        });
330
    };
331
 
332
    // Handles Bootstrap Dropdowns
333
    var handleDropdowns = function() {
334
        /*
335
          Hold dropdown on click  
336
        */
337
        $('body').on('click', '.dropdown-menu.hold-on-click', function(e) {
338
            e.stopPropagation();
339
        });
340
    };
341
 
342
    var handleAlerts = function() {
343
        $('body').on('click', '[data-close="alert"]', function(e) {
344
            $(this).parent('.alert').hide();
345
            $(this).closest('.note').hide();
346
            e.preventDefault();
347
        });
348
 
349
        $('body').on('click', '[data-close="note"]', function(e) {
350
            $(this).closest('.note').hide();
351
            e.preventDefault();
352
        });
353
 
354
        $('body').on('click', '[data-remove="note"]', function(e) {
355
            $(this).closest('.note').remove();
356
            e.preventDefault();
357
        });
358
    };
359
 
360
    // Handle Hower Dropdowns
361
    var handleDropdownHover = function() {
362
        $('[data-hover="dropdown"]').not('.hover-initialized').each(function() {
363
            $(this).dropdownHover();
364
            $(this).addClass('hover-initialized');
365
        });
366
    };
367
 
368
    // Handles Bootstrap Popovers
369
 
370
    // last popep popover
371
    var lastPopedPopover;
372
 
373
    var handlePopovers = function() {
374
        $('.popovers').popover();
375
 
376
        // close last displayed popover
377
 
378
        $(document).on('click.bs.popover.data-api', function(e) {
379
            if (lastPopedPopover) {
380
                lastPopedPopover.popover('hide');
381
            }
382
        });
383
    };
384
 
385
    // Handles scrollable contents using jQuery SlimScroll plugin.
386
    var handleScrollers = function() {
387
        Metronic.initSlimScroll('.scroller');
388
    };
389
 
390
    // Handles Image Preview using jQuery Fancybox plugin
391
    var handleFancybox = function() {
392
        if (!jQuery.fancybox) {
393
            return;
394
        }
395
 
396
        if ($(".fancybox-button").size() > 0) {
397
            $(".fancybox-button").fancybox({
398
                groupAttr: 'data-rel',
399
                prevEffect: 'none',
400
                nextEffect: 'none',
401
                closeBtn: true,
402
                helpers: {
403
                    title: {
404
                        type: 'inside'
405
                    }
406
                }
407
            });
408
        }
409
    };
410
 
411
    // Fix input placeholder issue for IE8 and IE9
412
    var handleFixInputPlaceholderForIE = function() {
413
        //fix html5 placeholder attribute for ie7 & ie8
414
        if (isIE8 || isIE9) { // ie8 & ie9
415
            // this is html5 placeholder fix for inputs, inputs with placeholder-no-fix class will be skipped(e.g: we need this for password fields)
416
            $('input[placeholder]:not(.placeholder-no-fix), textarea[placeholder]:not(.placeholder-no-fix)').each(function() {
417
                var input = $(this);
418
 
419
                if (input.val() === '' && input.attr("placeholder") !== '') {
420
                    input.addClass("placeholder").val(input.attr('placeholder'));
421
                }
422
 
423
                input.focus(function() {
424
                    if (input.val() == input.attr('placeholder')) {
425
                        input.val('');
426
                    }
427
                });
428
 
429
                input.blur(function() {
430
                    if (input.val() === '' || input.val() == input.attr('placeholder')) {
431
                        input.val(input.attr('placeholder'));
432
                    }
433
                });
434
            });
435
        }
436
    };
437
 
438
    // Handle Select2 Dropdowns
439
    var handleSelect2 = function() {
440
        if ($().select2) {
441
            $('.select2me').select2({
442
                placeholder: "Select",
443
                allowClear: true
444
            });
445
        }
446
    };
447
 
448
    //* END:CORE HANDLERS *//
449
 
450
    return {
451
 
452
        //main function to initiate the theme
453
        init: function() {
454
            //IMPORTANT!!!: Do not modify the core handlers call order.
455
 
456
            //Core handlers
457
            handleInit(); // initialize core variables
458
            handleOnResize(); // set and handle responsive    
459
 
460
            //UI Component handlers            
461
            handleUniform(); // hanfle custom radio & checkboxes
462
            handleiCheck(); // handles custom icheck radio and checkboxes
463
            handleBootstrapSwitch(); // handle bootstrap switch plugin
464
            handleScrollers(); // handles slim scrolling contents 
465
            handleFancybox(); // handle fancy box
466
            handleSelect2(); // handle custom Select2 dropdowns
467
            handlePortletTools(); // handles portlet action bar functionality(refresh, configure, toggle, remove)
468
            handleAlerts(); //handle closabled alerts
469
            handleDropdowns(); // handle dropdowns
470
            handleTabs(); // handle tabs
471
            handleTooltips(); // handle bootstrap tooltips
472
            handlePopovers(); // handles bootstrap popovers
473
            handleAccordions(); //handles accordions 
474
            handleModals(); // handle modals
475
            handleBootstrapConfirmation(); // handle bootstrap confirmations
476
 
477
            // Hacks
478
            handleFixInputPlaceholderForIE(); //IE8 & IE9 input placeholder issue fix
479
        },
480
 
481
        //main function to initiate core javascript after ajax complete
482
        initAjax: function() {
483
            handleUniform(); // handles custom radio & checkboxes     
484
            handleiCheck(); // handles custom icheck radio and checkboxes
485
            handleBootstrapSwitch(); // handle bootstrap switch plugin
486
            handleDropdownHover(); // handles dropdown hover       
487
            handleScrollers(); // handles slim scrolling contents 
488
            handleSelect2(); // handle custom Select2 dropdowns
489
            handleFancybox(); // handle fancy box
490
            handleDropdowns(); // handle dropdowns
491
            handleTooltips(); // handle bootstrap tooltips
492
            handlePopovers(); // handles bootstrap popovers
493
            handleAccordions(); //handles accordions 
494
            handleBootstrapConfirmation(); // handle bootstrap confirmations
495
        },
496
 
497
        //init main components 
498
        initComponents: function() {
499
            this.initAjax();
500
        },
501
 
502
        //public function to remember last opened popover that needs to be closed on click
503
        setLastPopedPopover: function(el) {
504
            lastPopedPopover = el;
505
        },
506
 
507
        //public function to add callback a function which will be called on window resize
508
        addResizeHandler: function(func) {
509
            resizeHandlers.push(func);
510
        },
511
 
512
        //public functon to call _runresizeHandlers
513
        runResizeHandlers: function() {
514
            _runResizeHandlers();
515
        },
516
 
517
        // wrMetronicer function to scroll(focus) to an element
518
        scrollTo: function(el, offeset) {
519
            var pos = (el && el.size() > 0) ? el.offset().top : 0;
520
 
521
            if (el) {
522
                if ($('body').hasClass('page-header-fixed')) {
523
                    pos = pos - $('.page-header').height();
524
                }
525
                pos = pos + (offeset ? offeset : -1 * el.height());
526
            }
527
 
528
            $('html,body').animate({
529
                scrollTop: pos
530
            }, 'slow');
531
        },
532
 
533
        initSlimScroll: function(el) {
534
            $(el).each(function() {
535
                if ($(this).attr("data-initialized")) {
536
                    return; // exit
537
                }
538
 
539
                var height;
540
 
541
                if ($(this).attr("data-height")) {
542
                    height = $(this).attr("data-height");
543
                } else {
544
                    height = $(this).css('height');
545
                }
546
 
547
                $(this).slimScroll({
548
                    allowPageScroll: true, // allow page scroll when the element scroll is ended
549
                    size: '7px',
550
                    color: ($(this).attr("data-handle-color") ? $(this).attr("data-handle-color") : '#bbb'),
551
                    wrapperClass: ($(this).attr("data-wrapper-class") ? $(this).attr("data-wrapper-class") : 'slimScrollDiv'),
552
                    railColor: ($(this).attr("data-rail-color") ? $(this).attr("data-rail-color") : '#eaeaea'),
553
                    position: isRTL ? 'left' : 'right',
554
                    height: height,
555
                    alwaysVisible: ($(this).attr("data-always-visible") == "1" ? true : false),
556
                    railVisible: ($(this).attr("data-rail-visible") == "1" ? true : false),
557
                    disableFadeOut: true
558
                });
559
 
560
                $(this).attr("data-initialized", "1");
561
            });
562
        },
563
 
564
        destroySlimScroll: function(el) {
565
            $(el).each(function() {
566
                if ($(this).attr("data-initialized") === "1") { // destroy existing instance before updating the height
567
                    $(this).removeAttr("data-initialized");
568
                    $(this).removeAttr("style");
569
 
570
                    var attrList = {};
571
 
572
                    // store the custom attribures so later we will reassign.
573
                    if ($(this).attr("data-handle-color")) {
574
                        attrList["data-handle-color"] = $(this).attr("data-handle-color");
575
                    }
576
                    if ($(this).attr("data-wrapper-class")) {
577
                        attrList["data-wrapper-class"] = $(this).attr("data-wrapper-class");
578
                    }
579
                    if ($(this).attr("data-rail-color")) {
580
                        attrList["data-rail-color"] = $(this).attr("data-rail-color");
581
                    }
582
                    if ($(this).attr("data-always-visible")) {
583
                        attrList["data-always-visible"] = $(this).attr("data-always-visible");
584
                    }
585
                    if ($(this).attr("data-rail-visible")) {
586
                        attrList["data-rail-visible"] = $(this).attr("data-rail-visible");
587
                    }
588
 
589
                    $(this).slimScroll({
590
                        wrapperClass: ($(this).attr("data-wrapper-class") ? $(this).attr("data-wrapper-class") : 'slimScrollDiv'),
591
                        destroy: true
592
                    });
593
 
594
                    var the = $(this);
595
 
596
                    // reassign custom attributes
597
                    $.each(attrList, function(key, value) {
598
                        the.attr(key, value);
599
                    });
600
 
601
                }
602
            });
603
        },
604
 
605
        // function to scroll to the top
606
        scrollTop: function() {
607
            Metronic.scrollTo();
608
        },
609
 
610
        // wrMetronicer function to  block element(indicate loading)
611
        blockUI: function(options) {
612
            options = $.extend(true, {}, options);
613
            var html = '';
614
            if (options.animate) {
615
                html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '') + '">' + '<div class="block-spinner-bar"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>' + '</div>';
616
            } else if (options.iconOnly) {
617
                html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '') + '"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""></div>';
618
            } else if (options.textOnly) {
619
                html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '') + '"><span>&nbsp;&nbsp;' + (options.message ? options.message : 'LOADING...') + '</span></div>';
620
            } else {
621
                html = '<div class="loading-message ' + (options.boxed ? 'loading-message-boxed' : '') + '"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif" align=""><span>&nbsp;&nbsp;' + (options.message ? options.message : 'LOADING...') + '</span></div>';
622
            }
623
 
624
            if (options.target) { // element blocking
625
                var el = $(options.target);
626
                if (el.height() <= ($(window).height())) {
627
                    options.cenrerY = true;
628
                }
629
                el.block({
630
                    message: html,
631
                    baseZ: options.zIndex ? options.zIndex : 1000,
632
                    centerY: options.cenrerY !== undefined ? options.cenrerY : false,
633
                    css: {
634
                        top: '10%',
635
                        border: '0',
636
                        padding: '0',
637
                        backgroundColor: 'none'
638
                    },
639
                    overlayCSS: {
640
                        backgroundColor: options.overlayColor ? options.overlayColor : '#555',
641
                        opacity: options.boxed ? 0.05 : 0.1,
642
                        cursor: 'wait'
643
                    }
644
                });
645
            } else { // page blocking
646
                $.blockUI({
647
                    message: html,
648
                    baseZ: options.zIndex ? options.zIndex : 1000,
649
                    css: {
650
                        border: '0',
651
                        padding: '0',
652
                        backgroundColor: 'none'
653
                    },
654
                    overlayCSS: {
655
                        backgroundColor: options.overlayColor ? options.overlayColor : '#555',
656
                        opacity: options.boxed ? 0.05 : 0.1,
657
                        cursor: 'wait'
658
                    }
659
                });
660
            }
661
        },
662
 
663
        // wrMetronicer function to  un-block element(finish loading)
664
        unblockUI: function(target) {
665
            if (target) {
666
                $(target).unblock({
667
                    onUnblock: function() {
668
                        $(target).css('position', '');
669
                        $(target).css('zoom', '');
670
                    }
671
                });
672
            } else {
673
                $.unblockUI();
674
            }
675
        },
676
 
677
        startPageLoading: function(options) {
678
            if (options && options.animate) {
679
                $('.page-spinner-bar').remove();
680
                $('body').append('<div class="page-spinner-bar"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>');
681
            } else {
682
                $('.page-loading').remove();
683
                $('body').append('<div class="page-loading"><img src="' + this.getGlobalImgPath() + 'loading-spinner-grey.gif"/>&nbsp;&nbsp;<span>' + (options && options.message ? options.message : 'Loading...') + '</span></div>');
684
            }
685
        },
686
 
687
        stopPageLoading: function() {
688
            $('.page-loading, .page-spinner-bar').remove();
689
        },
690
 
691
        alert: function(options) {
692
 
693
            options = $.extend(true, {
694
                container: "", // alerts parent container(by default placed after the page breadcrumbs)
695
                place: "append", // "append" or "prepend" in container 
696
                type: 'success', // alert's type
697
                message: "", // alert's message
698
                close: true, // make alert closable
699
                reset: true, // close all previouse alerts first
700
                focus: true, // auto scroll to the alert after shown
701
                closeInSeconds: 0, // auto close after defined seconds
702
                icon: "" // put icon before the message
703
            }, options);
704
 
705
            var id = Metronic.getUniqueID("Metronic_alert");
706
 
707
            var html = '<div id="' + id + '" class="Metronic-alerts alert alert-' + options.type + ' fade in">' + (options.close ? '<button type="button" class="close" data-dismiss="alert" aria-hidden="true"></button>' : '') + (options.icon !== "" ? '<i class="fa-lg fa fa-' + options.icon + '"></i>  ' : '') + options.message + '</div>';
708
 
709
            if (options.reset) {
710
                $('.Metronic-alerts').remove();
711
            }
712
 
713
            if (!options.container) {
714
                if ($('body').hasClass("page-container-bg-solid")) {
715
                    $('.page-title').after(html);
716
                } else {
717
                    if ($('.page-bar').size() > 0) {
718
                        $('.page-bar').after(html);
719
                    } else {
720
                        $('.page-breadcrumb').after(html);
721
                    }
722
                }
723
            } else {
724
                if (options.place == "append") {
725
                    $(options.container).append(html);
726
                } else {
727
                    $(options.container).prepend(html);
728
                }
729
            }
730
 
731
            if (options.focus) {
732
                Metronic.scrollTo($('#' + id));
733
            }
734
 
735
            if (options.closeInSeconds > 0) {
736
                setTimeout(function() {
737
                    $('#' + id).remove();
738
                }, options.closeInSeconds * 1000);
739
            }
740
 
741
            return id;
742
        },
743
 
744
        // initializes uniform elements
745
        initUniform: function(els) {
746
            if (els) {
747
                $(els).each(function() {
748
                    if ($(this).parents(".checker").size() === 0) {
749
                        $(this).show();
750
                        $(this).uniform();
751
                    }
752
                });
753
            } else {
754
                handleUniform();
755
            }
756
        },
757
 
758
        //wrMetronicer function to update/sync jquery uniform checkbox & radios
759
        updateUniform: function(els) {
760
            $.uniform.update(els); // update the uniform checkbox & radios UI after the actual input control state changed
761
        },
762
 
763
        //public function to initialize the fancybox plugin
764
        initFancybox: function() {
765
            handleFancybox();
766
        },
767
 
768
        //public helper function to get actual input value(used in IE9 and IE8 due to placeholder attribute not supported)
769
        getActualVal: function(el) {
770
            el = $(el);
771
            if (el.val() === el.attr("placeholder")) {
772
                return "";
773
            }
774
            return el.val();
775
        },
776
 
777
        //public function to get a paremeter by name from URL
778
        getURLParameter: function(paramName) {
779
            var searchString = window.location.search.substring(1),
780
                i, val, params = searchString.split("&");
781
 
782
            for (i = 0; i < params.length; i++) {
783
                val = params[i].split("=");
784
                if (val[0] == paramName) {
785
                    return unescape(val[1]);
786
                }
787
            }
788
            return null;
789
        },
790
 
791
        // check for device touch support
792
        isTouchDevice: function() {
793
            try {
794
                document.createEvent("TouchEvent");
795
                return true;
796
            } catch (e) {
797
                return false;
798
            }
799
        },
800
 
801
        // To get the correct viewport width based on  http://andylangton.co.uk/articles/javascript/get-viewport-size-javascript/
802
        getViewPort: function() {
803
            var e = window,
804
                a = 'inner';
805
            if (!('innerWidth' in window)) {
806
                a = 'client';
807
                e = document.documentElement || document.body;
808
            }
809
 
810
            return {
811
                width: e[a + 'Width'],
812
                height: e[a + 'Height']
813
            };
814
        },
815
 
816
        getUniqueID: function(prefix) {
817
            return 'prefix_' + Math.floor(Math.random() * (new Date()).getTime());
818
        },
819
 
820
        // check IE8 mode
821
        isIE8: function() {
822
            return isIE8;
823
        },
824
 
825
        // check IE9 mode
826
        isIE9: function() {
827
            return isIE9;
828
        },
829
 
830
        //check RTL mode
831
        isRTL: function() {
832
            return isRTL;
833
        },
834
 
835
        // check IE8 mode
836
        isAngularJsApp: function() {
837
            return (typeof angular == 'undefined') ? false : true;
838
        },
839
 
840
        getAssetsPath: function() {
841
            return assetsPath;
842
        },
843
 
844
        setAssetsPath: function(path) {
845
            assetsPath = path;
846
        },
847
 
848
        setGlobalImgPath: function(path) {
849
            globalImgPath = path;
850
        },
851
 
852
        getGlobalImgPath: function() {
853
            return assetsPath + globalImgPath;
854
        },
855
 
856
        setGlobalPluginsPath: function(path) {
857
            globalPluginsPath = path;
858
        },
859
 
860
        getGlobalPluginsPath: function() {
861
            return assetsPath + globalPluginsPath;
862
        },
863
 
864
        getGlobalCssPath: function() {
865
            return assetsPath + globalCssPath;
866
        },
867
 
868
        // get layout color code by color name
869
        getBrandColor: function(name) {
870
            if (brandColors[name]) {
871
                return brandColors[name];
872
            } else {
873
                return '';
874
            }
875
        },
876
 
877
        getResponsiveBreakpoint: function(size) {
878
            // bootstrap responsive breakpoints
879
            var sizes = {
880
                'xs' : 480,     // extra small
881
                'sm' : 768,     // small
882
                'md' : 992,     // medium
883
                'lg' : 1200     // large
884
            };
885
 
886
            return sizes[size] ? sizes[size] : 0;
887
        }
888
    };
889
 
890
}();