This repository has been archived by the owner on Nov 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
377 lines (347 loc) · 11.1 KB
/
index.html
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="http://yui.yahooapis.com/3.5.1/build/yui/yui.js"></script>
<link REL=stylesheet type="text/css" HREF="style.css">
</head>
<body class="yui3-skin-sam">
<a href="http://satyam.github.com/apiDocsGallery/">API docs</a>
<h1>A simple Tree:</h1>
<div id="container"></div>
<h1>A dynamic tree with multiple node types:</h1>
<p>The nodes of this tree are read from YQL, any replies rely on that service.
The long connecting lines might look funny sometimes because they are borrowed from YUI2 TreeView and
they assumed limits on the height of a line so for lengthy lines, the sprite overflows into the next element.
With a proper sprite, this will not happen.</p>
<div id="dynTree"></div>
<h1>A tree with checkboxes for selection</h1>
<p>This tree is built dynamically with randomized file/folder names just to simulate a file manager.
The Save button will list in the container below the JSON for those files/folders marked as selected.</p>
<div id="selContainer" class="yui3-fw-treeview-checkbox"></div>
<button id="save">Save</button>
<div id="output"></div>
<h1>A form:</h1>
<div id="form"></div>
<script>
YUI({
filter:'raw',
combine: false,
groups: {
local: {
base:'./',
modules: {
flyweightmanager: {
path:'flyweightmanager.js',
requires:['classnamemanager']
},
flyweightnode: {
path: 'flyweightnode.js',
requires: ['base-core', 'base-build','flyweightmanager']
},
treeview: {
path: 'treeview.js',
requires: ['flyweightmanager', 'widget','base-build', 'treenode']
},
treenode: {
path: 'treenode.js',
requires: ['flyweightnode','base-build']
},
form: {
path: 'form.js',
requires: ['flyweightmanager', 'widget','base-build','input-field']
},
"input-field": {
path: 'input-field.js',
requires: ['flyweightnode','base-build']
},
"field-set": {
path: 'field-set.js',
requires: ['flyweightnode','base-build']
}
}
},
gallery: {
base:'http://satyam.github.com/yui3-gallery/build/',
modules: {
'gallery-flyweight-tree': {
path:'gallery-flyweight-tree/gallery-flyweight-tree.js',
requires:["base-base","base-build","classnamemanager"]
},
'gallery-fwt-treeview': {
path: 'gallery-fwt-treeview/gallery-fwt-treeview.js',
requires: ["gallery-flyweight-tree","widget","base-build"],
skinnable: true
}
}
}
},
lang:'es'
}).use('gallery-fwt-treeview', 'form', 'input-field','field-set','yql','json', function (Y) {
'use strict';
/*jslint white:true*/
var Lang = Y.Lang,
tv = new Y.FWTreeView({tree: [
{
label:'label 0',
children: [
{
label: 'label 0-0',
expanded: false,
children: [
{
label: 'label 0-0-0'
},
{
label: 'label 0-0-1',
children: [
{label: 'label 0-0-1'}
]
}
]
},
{
label: 'label 0-1'
}
]
},
{
label: 'label 1'
}
]
});
tv.render('#container');
var ArtistNode = Y.Base.create(
'artist-node',
Y.FWTreeNode,
[],
{
},{
TEMPLATE: '<li id="{id}" class="artistnode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content"><a href="{url}">{label}<\/a><\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
ATTRS: {
url: {
},
artistId: {
}
}
}
);
var AlbumNode = Y.Base.create(
'album-node',
Y.FWTreeNode,
[],
{
},{
TEMPLATE: '<li id="{id}" class="albumnode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content"><a href="{url}">{label}<\/a> ({publisher})<\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
ATTRS: {
url: {
},
albumId: {
},
publisher: {
}
}
}
);
var TrackNode = Y.Base.create(
'track-node',
Y.FWTreeNode,
[],
{
},{
// {"Track":{"discNumber":"1","duration":"0","popularity":"3","title":"Karaoke: Crazy For You","trackNumber":"1"}}
TEMPLATE: '<li id="{id}" class="tracknode {cname_node}"><div class="yui3-fw-treeview-toggle"><\/div><div class="yui3-fw-treeview-content">[disc:{discNumber} - track:{trackNumber} - duration: {duration}]: {label}<\/div><ul class="{cname_children}">{children}<\/ul><\/li>',
ATTRS: {
discNumber: {
},
trackNumber: {
},
duration: {
}
}
}
);
Y.YQL('select id, name, url from music.artist.search where keyword="Madonna" | sort(field="trackCount", descending="true")', function(response) {
if (!response.query.count) {
Y.one('#dynTree').setContent('YQL query for Madonna returned no records or failed');
return;
}
var cfg = [],
results = response.query.results.Artist || [];
if (!Lang.isArray(results)) {
results = [results];
}
Y.Array.each(results, function (entry) {
cfg.push( {
label: entry.name,
artistId: entry.id,
url: entry.url,
type:ArtistNode
});
});
(new Y.FWTreeView({
dynamicLoader: function (node, callback) {
if (node instanceof ArtistNode) {
Y.YQL(Lang.sub('select id, title, releaseYear, label, url from music.release.artist where id="{artistId}" | sort(field="releaseYear", descending="true")', node.getAttrs()), function (response) {
if (!response.query.count) {
alert(Lang.sub('YQL query for albums by {label} failed or returned no results', node.getAttrs()));
callback();
return;
}
var cfg = [],
results = response.query.results.Release || [];
if (!Lang.isArray(results)) {
results = [results];
}
Y.Array.each(results, function (entry) {
cfg.push( {
label: entry.title || ' ',
publisher: entry.label || 'unknown publisher',
albumId: entry.id,
url: entry.url || '#',
type:AlbumNode
});
});
callback(cfg);
return;
});
}
if (node instanceof AlbumNode) {
Y.YQL(Lang.sub('select Track.discNumber, Track.trackNumber, Track.duration, Track.title, Track.popularity from music.release.id where ids="{albumId}" and response="tracks"', node.getAttrs()), function (response) {
if (!response.query.count) {
alert(Lang.sub('YQL query for album "{label}" failed or returned no results', node.getAttrs()));
callback();
return;
}
var cfg = [],
results = response.query.results.Release || [];
if (!Lang.isArray(results)) {
results = [results];
}
Y.Array.each(results, function (entry) {
entry = entry.Track;
// {"Track":{"discNumber":"1","duration":"0","popularity":"3","title":"Karaoke: Crazy For You","trackNumber":"1"}}
cfg.push( {
label: entry.title || '- no title -',
discNumber: entry.discNumber || 1,
trackNumber: entry.trackNumber || '-',
duration: entry.duration || '--:--',
type:TrackNode,
isLeaf:true
});
});
callback(cfg);
return;
});
}
},
tree: cfg
})).render('#dynTree');
});
var sampleString = ("In computer programming, flyweight is a software design pattern. " +
"A flyweight is an object that minimizes memory use by sharing as much data as possible with other similar objects; " +
"it is a way to use objects in large numbers when a simple repeated representation would use an unacceptable amount of memory." +
" Often some parts of the object state can be shared, and it is common practice to hold them in external data structures and pass " +
"them to the flyweight objects temporarily when they are used." +
"A classic example usage of the flyweight pattern is the data structures for graphical representation of characters in a word processor. " +
"It might be desirable to have, for each character in a document, a glyph object containing its font outline, font metrics, " +
"and other formatting data, but this would amount to hundreds or thousands of bytes for each character. " +
"Instead, for every character there might be a reference to a flyweight glyph object shared by " +
"every instance of the same character in the document; only the position of each character " +
"(in the document and/or the page) would need to be stored internally.Another example is string interning." +
"In other contexts the idea of sharing identical data structures is called hash consing.").replace(/\W/g,'');
var FileNode = Y.Base.create(
'file-node',
Y.FWTreeNode,
[],
{
},
{
ATTRS: {
path: {}
}
}
);
var tv = new Y.FWTreeView({
tree: [
{
label:'nice files',
children: [
{
label: 'really nice',
path:'reallyNiceFiles'
},
{
label: 'so-so files',
path:'mediocreFiles'
}
]
},
{
label: 'ugly files',
path: 'nastyFiles'
}
],
dynamicLoader: function (node, callback) {
var returnFakeJSON = function(path) {
var i, l, f, reply = [];
for (i = 0,l = Math.random() * 5;i < l; i+=1) {
f = sampleString.substr(Math.random() * sampleString.length, Math.ceil(Math.random() * 10));
reply.push({
label:f,
path:path + '/' + f,
isLeaf:Math.random() > .3
})
}
return reply;
}
var reply = returnFakeJSON(node.get('path'));
callback(reply);
return;
},
defaultType: FileNode,
toggleOnLabelClick:true
});
tv.render('#selContainer');
Y.one('#save').on('click', function() {
var output = [];
tv.forSomeNodes(function (node) {
if (node.get('selected')=== Y.FWTreeNode.FULLY_SELECTED) {
output.push({
path:node.get('path'),
isFolder: !node.get('isLeaf')
});
}
});
Y.one('#output').setContent(Y.JSON.stringify(output));
});
var f = new Y.Form({fields: [
{
label: 'First Field',
name: 'firstField',
value: 1
},
{
label: 'Second Field',
name: 'secondField',
value: 2
},
{
type:'FieldSet',
label:'Set of Fields',
children: [
{
label: 'First Child Field'
},
{
label: 'Second Child field'
}
]
}
]});
f.render('#form');
});
</script>
</body>
</html>