Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
9 lars 1
/**
2
Core script to handle the entire theme and core functions
3
**/
4
var Layout = function() {
5
 
6
    var layoutImgPath = 'layouts/layout6/img/';
7
 
8
    var layoutCssPath = 'layouts/layout6/css/';
9
 
10
    var resBreakpointMd = App.getResponsiveBreakpoint('md'); //992px
11
    var resBreakpointSm = App.getResponsiveBreakpoint('sm'); //768px
12
 
13
    var handleQuickSearch = function() {
14
        // handle search box expand/collapse
15
        $('.page-header').on('click', '.search-form', function(e) {
16
            $(this).addClass("open");
17
            $(this).find('.form-control').focus();
18
 
19
            $('.page-header .search-form .form-control').on('blur', function(e) {
20
                $(this).closest('.search-form').removeClass("open");
21
                $(this).unbind("blur");
22
            });
23
        });
24
 
25
        // handle hor menu search form on enter press
26
        $('.page-header').on('keypress', '.hor-menu .search-form .form-control', function(e) {
27
            if (e.which == 13) {
28
                $(this).closest('.search-form').submit();
29
                return false;
30
            }
31
        });
32
 
33
        // handle header search button click
34
        $('.page-header').on('mousedown', '.search-form.open .submit', function(e) {
35
            e.preventDefault();
36
            e.stopPropagation();
37
            $(this).closest('.search-form').submit();
38
        });
39
    };
40
 
41
    // handle go to top button
42
    var handleGo2Top = function () {
43
        var Go2TopOperation = function(){
44
            var CurrentWindowPosition = $(window).scrollTop();// current vertical position
45
            if (CurrentWindowPosition > 100) {
46
                $(".go2top").show();
47
            } else {
48
                $(".go2top").hide();
49
            }
50
        };
51
 
52
        Go2TopOperation();// call headerFix() when the page was loaded
53
        if (navigator.userAgent.match(/iPhone|iPad|iPod/i)) {
54
            $(window).bind("touchend touchcancel touchleave", function(e){
55
                Go2TopOperation();
56
            });
57
        } else {
58
            $(window).scroll(function() {
59
                Go2TopOperation();
60
            });
61
        }
62
 
63
        $(".go2top").click(function(e) {
64
            e.preventDefault();
65
             $("html, body").animate({ scrollTop: 0 }, 600);
66
        });
67
    };
68
 
69
    // Handle sidebar menu
70
    var handleSidebarMenu = function() {
71
        $('.page-sidebar').on('click', 'li > a', function(e) {
72
 
73
            if (App.getViewPort().width >= resBreakpointMd && $(this).parents('.page-sidebar-menu-hover-submenu').size() === 1) { // exit of hover sidebar menu
74
                return;
75
            }
76
 
77
            if ($(this).next().hasClass('sub-menu') === false) {
78
                if (App.getViewPort().width < resBreakpointMd && $('.page-sidebar').hasClass("in")) { // close the menu on mobile view while laoding a page
79
                    $('.page-header .responsive-toggler').click();
80
                }
81
                return;
82
            }
83
 
84
            var parent = $(this).parent().parent();
85
            var the = $(this);
86
            var menu = $('.page-sidebar-menu');
87
            var sub = $(this).next();
88
 
89
            var autoScroll = menu.data("auto-scroll");
90
            var slideSpeed = parseInt(menu.data("slide-speed"));
91
            var keepExpand = menu.data("keep-expanded");
92
 
93
            if (keepExpand !== true) {
94
                parent.children('li.open').children('a').children('.arrow').removeClass('open');
95
                parent.children('li.open').children('.sub-menu:not(.always-open)').slideUp(slideSpeed);
96
                parent.children('li.open').removeClass('open');
97
            }
98
 
99
            var slideOffeset = -200;
100
 
101
            if (sub.is(":visible")) {
102
                $('.arrow', $(this)).removeClass("open");
103
                $(this).parent().removeClass("open");
104
                sub.slideUp(slideSpeed, function() {
105
                    if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) {
106
                        if ($('body').hasClass('page-sidebar-fixed')) {
107
                            menu.slimScroll({
108
                                'scrollTo': (the.position()).top
109
                            });
110
                        } else {
111
                            App.scrollTo(the, slideOffeset);
112
                        }
113
                    }
114
                });
115
            } else {
116
                $('.arrow', $(this)).addClass("open");
117
                $(this).parent().addClass("open");
118
                sub.slideDown(slideSpeed, function() {
119
                    if (autoScroll === true && $('body').hasClass('page-sidebar-closed') === false) {
120
                        if ($('body').hasClass('page-sidebar-fixed')) {
121
                            menu.slimScroll({
122
                                'scrollTo': (the.position()).top
123
                            });
124
                        } else {
125
                            App.scrollTo(the, slideOffeset);
126
                        }
127
                    }
128
                });
129
            }
130
 
131
            e.preventDefault();
132
        });
133
 
134
        // handle ajax links within sidebar menu
135
        $('.page-sidebar').on('click', ' li > a.ajaxify', function(e) {
136
            e.preventDefault();
137
            App.scrollTop();
138
 
139
            var url = $(this).attr("href");
140
            var menuContainer = $('.page-sidebar ul');
141
            var pageContent = $('.page-content');
142
            var pageContentBody = $('.page-content .page-content-body');
143
 
144
            menuContainer.children('li.active').removeClass('active');
145
            menuContainer.children('arrow.open').removeClass('open');
146
 
147
            $(this).parents('li').each(function() {
148
                $(this).addClass('active');
149
                $(this).children('a > span.arrow').addClass('open');
150
            });
151
            $(this).parents('li').addClass('active');
152
 
153
            if (App.getViewPort().width < resBreakpointMd && $('.page-sidebar').hasClass("in")) { // close the menu on mobile view while laoding a page
154
                $('.page-header .responsive-toggler').click();
155
            }
156
 
157
            App.startPageLoading();
158
 
159
            var the = $(this);
160
 
161
            $.ajax({
162
                type: "GET",
163
                cache: false,
164
                url: url,
165
                dataType: "html",
166
                success: function(res) {
167
 
168
                    if (the.parents('li.open').size() === 0) {
169
                        $('.page-sidebar-menu > li.open > a').click();
170
                    }
171
 
172
                    App.stopPageLoading();
173
                    pageContentBody.html(res);
174
                    Layout.fixContentHeight(); // fix content height
175
                    App.initAjax(); // initialize core stuff
176
                },
177
                error: function(xhr, ajaxOptions, thrownError) {
178
                    App.stopPageLoading();
179
                    pageContentBody.html('<h4>Could not load the requested content.</h4>');
180
                }
181
            });
182
        });
183
 
184
        // handle ajax link within main content
185
        $('.page-content').on('click', '.ajaxify', function(e) {
186
            e.preventDefault();
187
            App.scrollTop();
188
 
189
            var url = $(this).attr("href");
190
            var pageContent = $('.page-content');
191
            var pageContentBody = $('.page-content .page-content-body');
192
 
193
            App.startPageLoading();
194
 
195
            if (App.getViewPort().width < resBreakpointMd && $('.page-sidebar').hasClass("in")) { // close the menu on mobile view while laoding a page
196
                $('.page-header .responsive-toggler').click();
197
            }
198
 
199
            $.ajax({
200
                type: "GET",
201
                cache: false,
202
                url: url,
203
                dataType: "html",
204
                success: function(res) {
205
                    App.stopPageLoading();
206
                    pageContentBody.html(res);
207
                    Layout.fixContentHeight(); // fix content height
208
                    App.initAjax(); // initialize core stuff
209
                },
210
                error: function(xhr, ajaxOptions, thrownError) {
211
                    pageContentBody.html('<h4>Could not load the requested content.</h4>');
212
                    App.stopPageLoading();
213
                }
214
            });
215
        });
216
 
217
        // handle scrolling to top on responsive menu toggler click when header is fixed for mobile view
218
        $(document).on('click', '.page-header-fixed-mobile .responsive-toggler', function(){
219
            App.scrollTop();
220
        });
221
    };
222
 
223
    return {
224
 
225
        // Main init methods to initialize the layout
226
        // IMPORTANT!!!: Do not modify the core handlers call order.
227
 
228
        init: function () {
229
            handleQuickSearch();
230
            handleGo2Top();
231
            handleSidebarMenu();
232
        },
233
 
234
        getLayoutImgPath: function() {
235
            return App.getAssetsPath() + layoutImgPath;
236
        },
237
 
238
        getLayoutCssPath: function() {
239
            return App.getAssetsPath() + layoutCssPath;
240
        }
241
    };
242
 
243
}();
244
 
245
jQuery(document).ready(function() {
246
   Layout.init(); // init metronic core componets
247
});