scripts.js
3.87 KB
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
$(function($) {
setTimeout(function() {
$('#content-wrapper > .row').css({
opacity: 1
});
}, 200);
$('#sidebar-nav,#nav-col-submenu').on('click', '.dropdown-toggle', function (e) {
e.preventDefault();
var $item = $(this).parent();
if (!$item.hasClass('open')) {
$item.parent().find('.open .submenu').slideUp('fast');
$item.parent().find('.open').toggleClass('open');
}
$item.toggleClass('open');
if ($item.hasClass('open')) {
$item.children('.submenu').slideDown('fast');
}
else {
$item.children('.submenu').slideUp('fast');
}
});
$('body').on('mouseenter', '#page-wrapper.nav-small #sidebar-nav .dropdown-toggle', function (e) {
if ($( document ).width() >= 992) {
var $item = $(this).parent();
if ($('body').hasClass('fixed-leftmenu')) {
var topPosition = $item.position().top;
if ((topPosition + 4*$(this).outerHeight()) >= $(window).height()) {
topPosition -= 6*$(this).outerHeight();
}
$('#nav-col-submenu').html($item.children('.submenu').clone());
$('#nav-col-submenu > .submenu').css({'top' : topPosition});
}
$item.addClass('open');
$item.children('.submenu').slideDown('fast');
}
});
$('body').on('mouseleave', '#page-wrapper.nav-small #sidebar-nav > .nav-pills > li', function (e) {
if ($( document ).width() >= 992) {
var $item = $(this);
if ($item.hasClass('open')) {
$item.find('.open .submenu').slideUp('fast');
$item.find('.open').removeClass('open');
$item.children('.submenu').slideUp('fast');
}
$item.removeClass('open');
}
});
$('body').on('mouseenter', '#page-wrapper.nav-small #sidebar-nav a:not(.dropdown-toggle)', function (e) {
if ($('body').hasClass('fixed-leftmenu')) {
$('#nav-col-submenu').html('');
}
});
$('body').on('mouseleave', '#page-wrapper.nav-small #nav-col', function (e) {
if ($('body').hasClass('fixed-leftmenu')) {
$('#nav-col-submenu').html('');
}
});
$('#make-small-nav').click(function (e) {
$('#page-wrapper').toggleClass('nav-small');
});
$(window).smartresize(function(){
if ($( document ).width() <= 991) {
$('#page-wrapper').removeClass('nav-small');
}
});
$('.mobile-search').click(function(e) {
e.preventDefault();
$('.mobile-search').addClass('active');
$('.mobile-search form input.form-control').focus();
});
$(document).mouseup(function (e) {
var container = $('.mobile-search');
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.removeClass('active');
}
});
// $('.fixed-leftmenu #col-left').nanoScroller({
// alwaysVisible: false,
// iOSNativeScrolling: false,
// preventPageScrolling: true,
// contentClass: 'col-left-nano-content'
// });
// build all tooltips from data-attributes
$("[data-toggle='tooltip']").each(function (index, el) {
$(el).tooltip({
placement: $(this).data("placement") || 'top'
});
});
});
$.fn.removeClassPrefix = function(prefix) {
this.each(function(i, el) {
var classes = el.className.split(" ").filter(function(c) {
return c.lastIndexOf(prefix, 0) !== 0;
});
el.className = classes.join(" ");
});
return this;
};
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
};
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
// smartresize
$.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
})($,'smartresize');