common.js
4.62 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
150
151
152
153
154
155
156
157
158
159
160
161
162
(function () {
var commonApp = function () {
/**
* 初始化
* @private
*/
var _init = function () {
// 网页全屏
_fullScreen($('#js-full-screen'), function (isNormalScreen, $e) {
$e.html('<span class="ion ion-arrow-' + (isNormalScreen ? 'expand' : 'shrink') + '">');
});
// 加载侧导航
_navNarrow($('#js-toggle-aside-nav'));
_navCollapse($('#js-aside-collapse'));
};
/**
* 侧导航折叠效果
* @param $element 根<ul>元素
* @private
*/
var _navCollapse = function ($element) {
$element.children('li').each(function (i, n) {
var $this = $(n),
$ul = $this.children('ul'),
$a = $this.children('a');
if ($ul.length > 0) {
var aClass = 'collapsed',
ulClass = '',
thisClass = 'panel';
if ($ul.children('.active').length > 0) {
aClass = '';
ulClass = 'collapse in';
thisClass = 'panel has-children-active';
}
$this.attr({'class': thisClass});
$a.attr({
'href': 'javascript:;',
'data-toggle': 'collapse',
'data-parent': '#' + $element[0].id,
'class': aClass,
'data-target': '#nav-aside-collapse-' + i,
'data-index': i
})
.append('<span class="ion-chevron-right">');
$ul.attr({'id': 'nav-aside-collapse-' + i, 'class': ulClass});
}
});
};
/**
* 侧导航收起
* @param $element
* @private
*/
var _navNarrow = function ($element) {
/*if(localStorage.getItem('navAsideStatus')){
$('body').addClass('dk-nav-aside-narrow');
}*/
$element.click(function () {
var $body = $('body');
if ($body.hasClass('dk-nav-aside-narrow')) {
$body.removeClass('dk-nav-aside-narrow');
//localStorage.removeItem('navAsideStatus');
} else {
$body.addClass('dk-nav-aside-narrow');
//localStorage.setItem('navAsideStatus',true);
}
});
};
/**
* 浏览器全屏
* @private
* @param $element
* @param callback(isNormalScreen,$element)
*/
var _fullScreen = function ($element, callback) {
var isNormalScreen = function () {
return !document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement;
},
fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.webkitFullscreenEnabled;
// 触发全屏切换
$element.click(function () {
if (fullscreenEnabled) {
// 全屏
if (isNormalScreen()) {
var element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
}
// 取消全屏
else {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
}
}
}
});
// 监听全屏事件
var callbackFun = function (event) {
if (typeof callback == "function") {
callback(isNormalScreen(), $element);
}
};
document.onwebkitfullscreenchange = callbackFun;
document.onmozfullscreenchange = callbackFun;
document.onwebkitfullscreenchange = callbackFun;
document.onmsfullscreenchange = callbackFun;
};
/**
* 工具
* @private
*/
var _tools = {};
/**
* 获取表单数据
* @param $form jquery对象
* @returns {{}}
*/
_tools.getFromData = function ($form) {
var o = {};
var a = $form.serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
return {
init: _init,
tools: _tools
}
}();
window.commonApp = commonApp;
})();