forked from vitmalina/w2ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
363 lines (351 loc) · 20.5 KB
/
index.js
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
$(function () {
// init layout
var main_layout = $('#main_layout').w2layout({
name: 'main_layout',
panels: [
{ type: 'top', size: 45, style: 'border: 0px; border-bottom: 1px solid silver; background-color: #fff; color: #555;', overflow: 'hidden'},
{ type: 'left', size: 240, resizable: true, style: 'border-right: 1px solid silver;' },
{ type: 'main', style: 'background-color: white;' }
]
});
w2ui['main_layout'].content('top', '<div style="padding: 12px 20px; font-size: 18px;">W2UI 1.5 Demos</div>');
// w2ui['main_layout'].content('top', '<div style="padding: 9px;">'+
// 'Theme: '+
// '<select onchange="$(\'#mainCSS\').attr(\'href\', this.value);">'+
// ' <option value="../css/w2ui.min.css">Default Theme</option>'+
// ' <option value="../css/w2ui-dark.min.css">Dark Theme</option>'+
// '</select> '+
// 'Locale: '+
// '<select onchange="w2utils.locale({ path: \'../\', lang: this.value }); alert(\'Localization is only internal functions. You need to refresh to see it.\')">'+
// ' <option value="en-us">en-US</option>'+
// ' <option value="fr-fr">fr-FR</option>'+
// ' <option value="ru-ru">ru-RU</option>'+
// '</select>'+
// '</div>');
// init sidebar
w2ui['main_layout'].content('left', $().w2sidebar({
name: 'demo-sidebar',
img: null,
nodes: [
{ id: 'combo', text: 'Combinations', img: 'icon-folder', group1: true,
nodes: [
{ id: 'combo-1', text: 'Sidebar & Grid', icon: 'fa fa-star-o' },
{ id: 'combo-2', text: 'Grid & Edit', icon: 'fa fa-star-o' },
{ id: 'combo-3', text: 'Spreadsheet Like Grid', icon: 'fa fa-star-o' },
{ id: 'combo-4', text: 'Buffered Scroll', icon: 'fa fa-star-o' },
{ id: 'combo-9', text: 'Infinite Scroll', icon: 'fa fa-star-o' },
{ id: 'combo-5', text: 'Tabs With Content', icon: 'fa fa-star-o' },
{ id: 'combo-6', text: 'Layout & Dynamic Tabs', icon: 'fa fa-star-o' },
{ id: 'combo-7', text: 'Popup & Grid', icon: 'fa fa-star-o' },
{ id: 'combo-8', text: 'Popup & Layout', icon: 'fa fa-star-o' },
{ id: 'combo-10', text: 'Dependent Fields', icon: 'fa fa-star-o' }
]
},
{ id: 'layout', text: 'Layout', img: 'icon-folder', group1: true,
nodes: [
{ id: 'layout-1', text: 'Simple Layout', icon: 'fa fa-columns' },
{ id: 'layout-2', text: 'Resizable Panels', icon: 'fa fa-columns' },
{ id: 'layout-3', text: 'Show/Hide Panels', icon: 'fa fa-columns' },
{ id: 'layout-4', text: 'Load Content', icon: 'fa fa-columns' },
{ id: 'layout-5', text: 'Transitions', icon: 'fa fa-columns' },
{ id: 'layout-6', text: 'Event Listeners', icon: 'fa fa-columns' },
{ id: 'layout-7', text: 'Nested Layouts', icon: 'fa fa-columns' },
{ id: 'layout-8', text: 'Panel With Tabs', icon: 'fa fa-columns' },
{ id: 'layout-9', text: 'Panel With Toolbar', icon: 'fa fa-columns' },
{ id: 'layout-10', text: 'Panel With Title', icon: 'fa fa-columns' },
{ id: 'layout-11', text: 'Panel Messages (1.5+)', icon: 'fa fa-columns' }
]
},
{ id: 'grid', text: 'Grid', img: 'icon-folder', group1: true,
nodes: [
{ id: 'grid-1', text: 'Simple Grid', icon: 'fa fa-table' },
{ id: 'grid-3', text: 'Grid Elements', icon: 'fa fa-table' },
{ id: 'grid-2', text: 'Row Formatting', icon: 'fa fa-table' },
{ id: 'grid-23',text: 'Cell Formatting', icon: 'fa fa-table' },
{ id: 'grid-4', text: 'Data Source', icon: 'fa fa-table' },
{ id: 'grid-5', text: 'Load Data Once', icon: 'fa fa-table' },
{ id: 'grid-6', text: 'Single or Multi Select', icon: 'fa fa-table' },
{ id: 'grid-8', text: 'Show/Hide Columns', icon: 'fa fa-table' },
{ id: 'grid-9', text: 'Add/Remove Records', icon: 'fa fa-table' },
{ id: 'grid-10', text: 'Select/Unselect Records', icon: 'fa fa-table' },
{ id: 'grid-11', text: 'Fixed/Resizable', icon: 'fa fa-table' },
{ id: 'grid-12', text: 'Column Sort', icon: 'fa fa-table' },
{ id: 'grid-13', text: 'Column Groups', icon: 'fa fa-table' },
{ id: 'grid-14', text: 'Summary Records', icon: 'fa fa-table' },
{ id: 'grid-15', text: 'Simple Search', icon: 'fa fa-table' },
{ id: 'grid-16', text: 'Advanced Search', icon: 'fa fa-table' },
{ id: 'grid-17', text: 'Grid Toolbar', icon: 'fa fa-table' },
{ id: 'grid-18', text: 'Master -> Detail', icon: 'fa fa-table' },
{ id: 'grid-19', text: 'Two Grids', icon: 'fa fa-table' },
{ id: 'grid-20', text: 'Render to a New Box', icon: 'fa fa-table' },
{ id: 'grid-21', text: 'Inline Editing', icon: 'fa fa-table' },
{ id: 'grid-22', text: 'Resizable Columns', icon: 'fa fa-table' },
{ id: 'grid-24', text: 'Lock/Unlock Grid', icon: 'fa fa-table' },
{ id: 'grid-25', text: 'Re-Order Columns', icon: 'fa fa-table' },
{ id: 'grid-26', text: 'Re-Order Records', icon: 'fa fa-table' },
{ id: 'grid-7', text: 'Tree-Like Grid (1.5+)', icon: 'fa fa-table' },
{ id: 'grid-27', text: 'Frozen Columns (1.5+)', icon: 'fa fa-table' },
{ id: 'grid-28', text: 'Info Bubble (1.5+)', icon: 'fa fa-table' }
]
},
{ id: 'toolbar', text: 'Toolbar', img: 'icon-folder', group1: true,
nodes: [
{ id: 'toolbar-1', text: 'Simple Toolbar', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-2', text: 'More Buttons Type', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-3', text: 'Add/Remove Buttons', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-4', text: 'Show/Hide Buttons', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-5', text: 'Enable/Disable Buttons', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-6', text: 'Menu Buttons (1.5+)', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-7', text: 'Color Buttons (1.5+)', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-8', text: 'Tooltips (1.5+)', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-9', text: 'Custom Buttons (1.5+)', icon: 'fa fa-hand-o-up' },
{ id: 'toolbar-10', text: 'Toolbar Overflow (1.5+)', icon: 'fa fa-hand-o-up' }
]
},
{ id: 'sidebar', text: 'Sidebar', img: 'icon-folder', group1: true,
nodes: [
{ id: 'sidebar-1', text: 'Simple Sidebar', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-2', text: 'Add/Remove', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-3', text: 'Show/Hide', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-4', text: 'Enable/Disable', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-5', text: 'Expand/Collapse', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-6', text: 'Select/Unselect', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-8', text: 'Top & Bottom HTML', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-7', text: 'Events', icon: 'fa fa-hand-o-left' },
{ id: 'sidebar-9', text: 'Flat Sidebar (1.5+)', icon: 'fa fa-hand-o-up' },
{ id: 'sidebar-10', text: 'In/Out of Focus (1.5+)', icon: 'fa fa-hand-o-up' }
]
},
{ id: 'tabs', text: 'Tabs', img: 'icon-folder', group1: true,
nodes: [
{ id: 'tabs-1', text: 'Simple Tabs', icon: 'fa fa-folder-o' },
{ id: 'tabs-2', text: 'Set a Tab Active', icon: 'fa fa-folder-o' },
{ id: 'tabs-3', text: 'Closeable Tabs', icon: 'fa fa-folder-o' },
{ id: 'tabs-4', text: 'Add/Remove Tabs', icon: 'fa fa-folder-o' },
{ id: 'tabs-5', text: 'Enable/Disabled Tabs', icon: 'fa fa-folder-o' },
{ id: 'tabs-6', text: 'Show/Hide Tabs', icon: 'fa fa-folder-o' },
{ id: 'tabs-7', text: 'Tabs Overflow (1.5+)', icon: 'fa fa-folder-o' },
{ id: 'tabs-8', text: 'Tooltips (1.5+)', icon: 'fa fa-folder-o' }
]
},
{ id: 'forms', text: 'Forms', img: 'icon-folder', group1: true,
nodes: [
{ id: 'forms-1', text: 'Simple Form', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-10',text: 'Auto Templates', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-2', text: 'Field Types', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-3', text: 'Large Form', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-4', text: 'Multi Page Form', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-5', text: 'Form Tabs', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-9', text: 'Form Toolbar', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-8', text: 'Form in a Popup', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-6', text: 'Events', icon: 'fa fa-pencil-square-o' },
{ id: 'forms-11', text: 'Form Columns (1.5+)', icon: 'fa fa-pencil-square-o' }
]
},
{ id: 'fields', text: 'Fields', img: 'icon-folder', group1: true,
nodes: [
{ id: 'fields-1', text: 'Numeric', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-2', text: 'Date, Time & Datetime', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-3', text: 'Drop Down Lists', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-4', text: 'Multi Selects', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-5', text: 'File Upload', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-6', text: 'Remote Source', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-7', text: 'Get/Set Value (1.5+)', icon: 'fa fa-pencil-square-o' },
{ id: 'fields-8', text: 'Color Picker (1.5+)', icon: 'fa fa-pencil-square-o' }
]
},
{ id: 'popup', text: 'Popup', img: 'icon-folder', group1: true,
nodes: [
{ id: 'popup-1', text: 'Simple Popup', icon: 'fa fa-list-alt' },
{ id: 'popup-2', text: 'More Options', icon: 'fa fa-list-alt' },
{ id: 'popup-3', text: 'Popup Elements', icon: 'fa fa-list-alt' },
{ id: 'popup-4', text: 'Based on Markup', icon: 'fa fa-list-alt' },
{ id: 'popup-5', text: 'Load Content', icon: 'fa fa-list-alt' },
{ id: 'popup-6', text: 'Transitions', icon: 'fa fa-list-alt' },
{ id: 'popup-7', text: 'Slide a Message', icon: 'fa fa-list-alt' },
{ id: 'popup-9', text: 'Lock Content', icon: 'fa fa-list-alt' },
{ id: 'popup-8', text: 'Dialogs (1.5+)', icon: 'fa fa-list-alt' },
{ id: 'popup-10', text: 'Keyboard (1.5+)', icon: 'fa fa-list-alt' },
{ id: 'popup-11', text: 'Messages (1.5+)', icon: 'fa fa-list-alt' }
]
},
{ id: 'utils', text: 'Utilities', img: 'icon-folder', group1: true,
nodes: [
{ id: 'utils-1', text: 'Validation', icon: 'fa fa-star-o' },
{ id: 'utils-2', text: 'Encoding', icon: 'fa fa-star-o' },
{ id: 'utils-3', text: 'Transitions', icon: 'fa fa-star-o' },
{ id: 'utils-4', text: 'Tags (1.5+)', icon: 'fa fa-star-o' },
{ id: 'utils-5', text: 'Overlays (1.5+)', icon: 'fa fa-star-o' },
{ id: 'utils-6', text: 'Formatters (1.5+)', icon: 'fa fa-star-o' },
]
}
],
onClick: function (event) {
var cmd = event.target;
if (parseInt(cmd.substr(cmd.length-1)) != cmd.substr(cmd.length-1)) return;
var tmp = w2ui['demo-sidebar'].get(cmd);
document.title = tmp.parent.text + ': ' + tmp.text + ' | w2ui';
// delete previously created items
for (var widget in w2ui) {
var nm = w2ui[widget].name;
if (['main_layout', 'demo-sidebar'].indexOf(nm) == -1) $().w2destroy(nm);
}
// set hash
if (tmp.parent && tmp.parent.id != '') {
var pid = w2ui['demo-sidebar'].get(cmd).parent.id;
document.location.hash = '!'+ pid + '/' + cmd;
}
// load example
$.get('examples/'+ cmd +'.html', function (data) {
var tmp = data.split('<!--CODE-->');
if (tmp.length == 1) {
alert('ERROR: cannot parse example.');
console.log('ERROR: cannot parse example.', data);
return;
}
var w2ui_js = 'http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.js';
var w2ui_css = 'http://rawgit.com/vitmalina/w2ui/master/dist/w2ui.min.css';
var html = tmp[1] ? $.trim(tmp[1]) : '';
var js = tmp[2] ? $.trim(tmp[2]) : '';
var css = tmp[3] ? $.trim(tmp[3]) : '';
var json = tmp[4] ? $.trim(tmp[4]) : '';
js = js.replace(/^<script[^>]*>/, '').replace(/<\/script>$/, '');
js = $.trim(js);
css = css.replace(/^<style[^>]*>/, '').replace(/<\/style>$/, '');
css = $.trim(css);
json = json.replace(/^<script[^>]*>/, '').replace(/<\/script>$/, '');
json = $.trim(json);
w2ui['main_layout'].content('main', tmp[0]);
$('#example_view').html(
'<h2>Preview</h2>'+ html +
'<script type="text/javascript">' + js + '</script>' +
'<style>' + css + '</style>');
var code = '<!DOCTYPE html>\n'+
'<html>\n'+
'<head>\n'+
' <title>W2UI Demo: '+ cmd +'</title>\n'+
' <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>\n'+
' <script type="text/javascript" src="'+ w2ui_js +'"></script>\n'+
' <link rel="stylesheet" type="text/css" href="'+ w2ui_css +'" />\n'+
'</head>\n'+
'<body>\n\n'+
html + '\n\n'+
(js != '' ? '<script type="text/javascript">\n' + js + '\n</script>\n\n' : '') +
(css != '' ? '<style>\n' + css + '</style>\n\n' : '') +
'</body>\n'+
'</html>';
$('#example_code').html('<a href="javascript:" onclick="$(this).next().show(); initCode(); $(this).hide();" class="btn-source">Show Source Code</a>'+
'<div id="sourcecode" style="display: none;">'+
'<h2>Complete Code '+
'<span style="font-weight: normal; padding-left: 10px;">- Copy & paste into your editor or <a href="javascript:" class="jsfiddle">fiddle with code online</a></span> </h2>'+
'<textarea class="preview" id="code">'+
code.replace(/<textarea/gi, '<textarea').replace(/<\/textarea>/gi, '</textarea>') +
'</textarea>'+
(json != '' ?
'<h2>JSON file</h2>'+
'<textarea class="json" id="json">'+ json +'</textarea>'
:
'')+
'</div>'+
'<div style="display: none">'+
'<form id="fiddleForm" target="_blank" action="http://jsfiddle.net/api/post/jquery/2.1/" method="post">'+
' <textarea name="title">W2UI Demo: '+ cmd +'</textarea>'+
' <textarea name="resources">'+ w2ui_js +','+ w2ui_css +'</textarea>'+
' <textarea name="html">'+ html.replace(/<textarea/gi, '<textarea').replace(/<\/textarea>/gi, '</textarea>') +'</textarea>'+
' <textarea name="js">'+ js +'</textarea>'+
' <textarea name="css">'+ css +'</textarea>'+
' <textarea name="wrap">l</textarea>'+
'</form>'+
'</div>');
});
}
}));
// check hash
setTimeout(function () {
var tmp = String(document.location.hash).split('/');
switch (tmp[0]) {
default:
case '#!combo':
w2ui['demo-sidebar'].expand('combo');
w2ui['demo-sidebar'].click(tmp[1] || 'combo-1');
break;
case '#!layout':
w2ui['demo-sidebar'].expand('layout');
w2ui['demo-sidebar'].click(tmp[1] || 'layout-1');
break;
case '#!grid':
w2ui['demo-sidebar'].expand('grid');
w2ui['demo-sidebar'].click(tmp[1] || 'grid-1');
break;
case '#!toolbar':
w2ui['demo-sidebar'].expand('toolbar');
w2ui['demo-sidebar'].click(tmp[1] || 'toolbar-1');
break;
case '#!sidebar':
w2ui['demo-sidebar'].expand('sidebar');
w2ui['demo-sidebar'].click(tmp[1] || 'sidebar-1');
break;
// case '#!listview':
// w2ui['demo-sidebar'].expand('listview');
// w2ui['demo-sidebar'].click(tmp[1] || 'listview-1');
// break;
case '#!tabs':
w2ui['demo-sidebar'].expand('tabs');
w2ui['demo-sidebar'].click(tmp[1] || 'tabs-1');
break;
case '#!popup':
w2ui['demo-sidebar'].expand('popup');
w2ui['demo-sidebar'].click(tmp[1] || 'popup-1');
break;
case '#!forms':
w2ui['demo-sidebar'].expand('forms');
w2ui['demo-sidebar'].click(tmp[1] || 'forms-1');
break;
case '#!fields':
w2ui['demo-sidebar'].expand('fields');
w2ui['demo-sidebar'].click(tmp[1] || 'fields-1');
break;
case '#!utils':
w2ui['demo-sidebar'].expand('utils');
w2ui['demo-sidebar'].click(tmp[1] || 'utils-1');
break;
}
}, 100);
});
function initCode() {
// CodeMirror
var text = $('#example_code .preview');
if (text.length > 0) {
var cm = CodeMirror(
function(elt) { text[0].parentNode.replaceChild(elt, text[0]); },
{
value : $.trim(text.val()),
mode : "text/html",
readOnly : true,
gutter : true,
lineNumbers : true
}
);
cm.setSize(null, cm.doc.height + 15);
}
var text = $('#example_code .json');
if (text.length > 0) {
var cm = CodeMirror(
function(elt) { text[0].parentNode.replaceChild(elt, text[0]); },
{
value : $.trim(text.val()),
mode : "javascript",
readOnly : true,
gutter : true,
lineNumbers : true
}
);
cm.setSize(null, cm.doc.height + 15);
}
$('#example_code .jsfiddle').on('click', function () {
// $('#fiddleForm textarea[name=html]').val(html || '');
// $('#fiddleForm textarea[name=js]').val(js || '');
// $('#fiddleForm textarea[name=css]').val(css || '');
$('#fiddleForm').submit();
});
}