skinDesigner.jsp
14.7 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%@ page import="com.weaver.formmodel.mobile.utils.MobileCommonUtil"%>
<%@ include file="/mobilemode/admin/init.jsp"%>
<%
String skinid = Util.null2String(request.getParameter("skinid"), "");
%>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,height=device-height,maximum-scale=1.0,user-scalable=no">
<link type="text/css" rel="stylesheet" href="./src/common/css/common.css">
<link type="text/css" rel="stylesheet" href="./src/skindesigner/skinDesigner.css">
</head>
<body>
<div class="skin-designer-wrapper">
<div class="preview">
<div class="iphone">
<div class="header">
<span class="camera"></span>
<!-- 传感器 -->
<span class="sensor"></span>
<span class="speaker"></span>
</div>
<div class="buttons power-button"></div>
<div class="buttons voice-toogle"></div>
<div class="buttons voice-plus"></div>
<div class="buttons voice-minus"></div>
<div class="screen">
</div>
<div class="home-button"><span></span></div>
</div>
</div>
<div class="content">
<div>
<header>
<div>
<a href="javascript:;" class="left-square"><i class="iconfont fa"></i></a>
<div class="plugin-search">
<div class="plugin-type"><span><%=MobileCommonUtil.getHtmlLabelName(82857,user.getLanguage(),"全部")%></span><i class="iconfont fa-small"></i></div>
<div class="ad-dropdown">
<ul class="ad-dropdown-menu"></ul>
</div>
<div class="designer-search-wrapper">
<input type="text"/>
<a href="javascript:;"><i class="del"></i></a>
<a href="javascript:;"><i class="search-icon"></i></a>
</div>
</div>
<a href="javascript:;" id="skin-save" class="btn-primary btn"><i class="iconfont icon-save2 fa fa-small"></i><%=MobileCommonUtil.getHtmlLabelName(384114,user.getLanguage(),"保存")%></a>
</div>
</header>
<div class="skin-editor-warper">
<div class="plugin-list">
<div><ul></ul></div>
</div>
<div class="skin-editor-wrapper">
<div id="skin-editor"></div>
</div>
</div>
</div>
</div>
<div class="message"><i class="iconfont"></i><%=MobileCommonUtil.getHtmlLabelName(18758,user.getLanguage(),"保存成功")%></div>
</div>
<script type="text/x-template" id="plug-tmpl">
<li data-category="{{categoryName}}">
{{
items.reduce(function(prev, item) {
prev += "<i class=\"iconfont icon-"+item.id+"\" data-type=\""+item.id+"\" data-text=\""+item.text+"\" data-py=\""+item.text_py+"\" data-tip=\""+item.text+"\"></i>";
return prev;
}, "")
}}
</li>
</script>
<script type="text/javascript">
var skinid = "<%=skinid%>";
(function(){
var prefix = ".wev-comp-";
var skinEditor = {
editor: null,
init: function(callback) {
var that = this;
require(["htmlEditor"], function(htmlEditor) {
that.editor = htmlEditor.editor('skin-editor', 'css');
callback && callback();
});
},
setValue: function(cssCode) {
var that = this;
var _setValue = function() {
that.editor.setValue(cssCode, true);
};
if(that.editor) return _setValue();
that.init(_setValue);
},
getValue: function() {
return this.editor && this.editor.getValue();
},
search: function(text) {
var editor = this.editor;
if(!editor) return;
return editor.find(text);
},
insertToEnd: function(text) {
var editor = this.editor;
if(!editor) return;
editor.navigateFileEnd();
editor.insertSnippet(text);
},
resize: function() {
this.editor && this.editor.resize();
}
};
skinEditor.init();
require(["components/common"], function(common) {
var plugins = {
render: function(coms) {
var template = $("#plug-tmpl").html(),
typeTmpl = "<li class='ad-dropdown-menu-item' data-index='{{index}}'>{{categoryText}}</li>";
template = coms.reduce(function(prev, plug) {
prev += common.tempEngine(template, plug);
return prev;
}, "");
typeTmpl = coms.reduce(function(prev, plug, index) {
plug.index = index + 1;
prev += common.tempEngine(typeTmpl, plug);
return prev;
}, "<li class='ad-dropdown-menu-item selected' data-index='0'>"+ SystemEnv.getHtmlNoteName(3407) +"</li>"); // 全部
$(".plugin-list").find("ul").html(template);
$(".ad-dropdown-menu").html(typeTmpl);
return this;
},
bindEvent: function() {
var $plugList = $(".plugin-list");
$plugList.on("click.active", "i", function(e) {
var $target = $(this);
$plugList.find(".active").removeClass("active");
$target.addClass("active");
var className = prefix + $target.data("type"),
editor = skinEditor.editor,
session = editor.session,
isexist = skinEditor.search(prefix + $target.data("type"));
var enter = "\n\n",
lastRow = editor.getLastVisibleRow();
if(!session.getLine(lastRow)) {
enter = lastRow == 0 ? "" : "\n";
}
if(!isexist) {
var classTmpl = enter + "/* "+$target.data("text")+" */\n" + className + " {\n ::focus\n}";
skinEditor.insertToEnd(classTmpl);
$target.removeClass("disabled");
}
});
var $plugSearch = $(".plugin-search"),
$pluginType = $(".plugin-type"),
$dropdown = $(".ad-dropdown");
// 控制类型下拉
$pluginType.on("click", function(e) {
$(this).toggleClass("open");
$dropdown.toggleClass("show");
e.stopPropagation();
});
// 类型过滤
$dropdown.on("click", ".ad-dropdown-menu-item", function(e) {
var $target = $(this);
$target.addClass("selected").siblings(".selected").removeClass("selected");
$pluginType.toggleClass("open").data("type", $target.data("index"))
.find("span").html($target.html());
$dropdown.toggleClass("show");
plugfilter();
e.stopPropagation();
});
// 搜索过滤
$plugSearch.on("click.del", ".del", function() {
$(".designer-search-wrapper").removeClass("active").find("input").val("");
plugfilter();
}).find("input").on("input", function() {
$(this).parent().toggleClass("active", !!$(this).val());
plugfilter();
});
$("body").on("click.dropdown", function() {
$dropdown.removeClass("show");
$pluginType.removeClass("open");
});
function plugfilter() {
var type = +$pluginType.data("type") || 0,
searchText = $plugSearch.find("input").val().toLowerCase();
var $visiblePlug;
if(type == 0) {
$plugList.find("li").show();
$visiblePlug = $plugList.find("i");
} else {
$visiblePlug = $plugList.find("li").hide().eq(type - 1).show().find("i");
}
$visiblePlug.each(function() {
var $plug = $(this),
ismatch = ~$plug.data("py").toLowerCase().indexOf(searchText) || ~$plug.data("tip").indexOf(searchText);
$plug.toggle(!!ismatch);
});
}
}
};
// 初始化插件分类与列表
var pluginChain = common.api("designer", {
action: "getComponents",
type: "get"
}).then(function(res) {
var data = res.data || [];
if(!data.length) return;
plugins.render(data).bindEvent();
return data;
});
// 初始化皮肤样式的编辑器
var editorChain = common.api("skin", {
action: "css",
data: { id: skinid },
type: "get"
}, function(res) {
skinEditor.setValue(res.data.css || "");
});
var allComs = [];
pluginChain.then(function(data) {
data.forEach(function(category, index) {
allComs.push.apply(allComs, category.items);
});
return editorChain;
}).then(function(res) {
comsDisabledFilter(res.css || "");
});
// 插件disabled过滤
function comsDisabledFilter(cssCode) {
var $coms = $(".plugin-list").find("i");
allComs.forEach(function(com, index) {
var className = prefix + com.id;
$coms.eq(index).toggleClass("disabled", !~cssCode.indexOf(className));
});
}
// 控制编辑器的收缩
$(".left-square").on("click", function() {
$(".skin-designer-wrapper").toggleClass("full-editor");
setTimeout(function() {
skinEditor.resize();
}, 300);//transition延时
});
$("#skin-save").on("click", function() {
var css = skinEditor.getValue();
var $savebtn = $(this);
var _toggle = function(flag) {
$savebtn.toggleClass("disabled", flag);
};
if($savebtn.hasClass("disabled")) return;
if(css === undefined) return;
_toggle(true);
common.api("skin", {
action: "saveCss",
data: {
id: skinid,
css: css
}
}, function() {
$(".message").addClass("show");
setTimeout(function() {
$(".message").removeClass("show");
}, 1000);
_toggle(false);
comsDisabledFilter(css);
}).fail(function() {
_toggle(false);
});
})
});
//初始化tip
require(["modal"], function(modal) {
$('body').on("mouseover", "[data-tip]", function() {
var that = $(this),
content = that.attr('data-tip');
modal.tips(content, that, "right");
}).on("mouseout", "[data-tip]", function() {
modal.closeAll('tips'); // 鼠标离开关闭tips
});
});
}());
</script>
</body>
</html>