-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.js
403 lines (388 loc) · 9.55 KB
/
sample.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*************************************************************************
(c) 2008-2012 Martin Wendt
*************************************************************************/
/*******************************************************************************
* jQuery.skinswitcher plugin.
*
* Change CSS include when combobox selection changes.
* Copyright (c) 2012 Martin Wendt
*
* Usage:
$("select#skinswitcher").skinswitcher({
base: "../src/",
choices: [{name: "XP", value: "xp", href: "skin/ui.fancytree.css"},
{name: "Vista", value: "vista", href: "skin-vista/ui.fancytree.css"},
{name: "Lion", value: "lion", href: "skin-lion/ui.fancytree.css"}
],
init: "lion"
});
*/
/* globals prettyPrint */
/* eslint-disable no-alert */
(function($) {
var PLUGIN_NAME = "skinswitcher",
defaultOptions = {
/**RegEx that returns prefix, tag, and suffix of the CSS href.*/
// skinPattern: "^(\W/skin-)().css$",
// mode: "combo", // {String} mode 'combo' or 'radio'
base: "",
choices: [],
// extraChoices: [],
// Events:
change: $.noop,
},
methods = {
init: function(options) {
var i,
opts = $.extend({}, defaultOptions, options),
hrefs = [],
$link = null,
initialChoice;
// $('').skinswitcher did not match a selector
if (!this.length) {
return this;
}
// Attach options to skinswitcher combobox for later access
this.data("options", opts);
// Find the <link> tag that is used to includes our skin CSS.
// Add a class for later access.
$.each(opts.choices, function() {
hrefs.push(this.href.toLowerCase());
});
$("head link").each(function() {
for (i = 0; i < hrefs.length; i++) {
if (this.href.toLowerCase().indexOf(hrefs[i]) >= 0) {
$link = $(this);
$link.addClass(PLUGIN_NAME);
initialChoice = opts.choices[i];
}
}
});
if (!$link) {
$link = $("link." + PLUGIN_NAME);
}
if (!$link.length) {
$.error(
"Unable to find <link> tag for skinswitcher. Either set `href` to a known skin url or add a `skinswitcher` class."
);
}
//
return this.each(function() {
// Add options to dropdown list
var $combo = $(this);
$combo
.empty()
.skinswitcher("addChoices", opts.choices)
.change(function(event) {
var choice = $(":selected", this).data("choice");
$("link." + PLUGIN_NAME).attr(
"href",
opts.base + choice.href
);
opts.change(choice);
});
// Find out initial selection
if (opts.init) {
$combo.val(opts.init).change();
} else if (initialChoice) {
// select combobox value to match current <link> tag
// decouple this call to prevent IE6 exception
setTimeout(function() {
$combo.val(initialChoice.value);
opts.change(initialChoice);
}, 100);
}
});
},
option: function(name, value) {
var opts = this.data("options");
if (typeof value !== "undefined") {
opts[name] = value;
return this;
}
return opts[name];
},
addChoices: function(choices) {
var $combo = $(this);
if ($.isPlainObject(choices)) {
choices = [choices];
}
$.each(choices, function(i, choice) {
var $opt = $("<option>", {
text: choice.name,
value: choice.value,
}).data("choice", choice);
$combo.append($opt);
});
return this;
},
change: function(value) {
$(this)
.val(value)
.change();
return this;
},
reset: function() {
$(this)
.val("")
.change();
return this;
},
};
$.fn[PLUGIN_NAME] = function(method) {
// Method calling logic
if (methods[method]) {
return methods[method].apply(
this,
Array.prototype.slice.call(arguments, 1)
);
} else if (typeof method === "object" || !method) {
return methods.init.apply(this, arguments);
}
$.error(
"Method " + method + " does not exist on jQuery." + PLUGIN_NAME
);
};
})(jQuery);
/**
* Replacement for $().toggle(func1, func2), which was deprecated with jQuery 1.8
* and removed in 1.9.;
* Taken from http://stackoverflow.com/a/4911660/19166
* By Felix Kling
*/
(function($) {
var SAMPLE_BUTTON_DEFAULTS = {
id: undefined,
label: "Sample",
newline: true,
code: function() {
alert("not implemented");
},
};
$.fn.clickToggle = function(func1, func2) {
var funcs = [func1, func2];
this.data("toggleclicked", 0);
this.click(function() {
var data = $(this).data(),
tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
window.addSampleButton = function(options) {
var sourceCode,
opts = $.extend({}, SAMPLE_BUTTON_DEFAULTS, options),
$buttonBar = $("#sampleButtons"),
$container = $("<span />", {
class: "sampleButtonContainer",
});
$("<button />", {
id: opts.id,
title: opts.tooltip,
text: opts.label,
})
.click(function(e) {
e.preventDefault();
opts.code();
})
.appendTo($container);
$("<a />", {
text: "Source code",
href: "#",
class: "showCode",
})
.appendTo($container)
.click(function(e) {
try {
prettyPrint();
} catch (e2) {
alert(e2);
}
var $pre = $container.find("pre");
if ($pre.is(":visible")) {
$(this).text("Source code");
} else {
$(this).text("Hide source");
}
$pre.toggle("slow");
return false;
});
sourceCode = "" + opts.code;
// Remove outer function(){ CODE }
// sourceCode = sourceCode.match(/[]\{(.*)\}/);
sourceCode = sourceCode.substring(
sourceCode.indexOf("{") + 1,
sourceCode.lastIndexOf("}")
);
// sourceCode = $.trim(sourceCode);
// Reduce tabs from 8 to 2 characters
sourceCode = sourceCode.replace(/\t/g, " ");
// Format code samples
$("<pre />", {
text: sourceCode,
class: "prettyprint",
})
.hide()
.appendTo($container);
if (opts.newline) {
$container.append($("<br />"));
}
if (opts.header) {
$("<h5 />", { text: opts.header }).appendTo($("p#sampleButtons"));
}
if (!$("#sampleButtons").length) {
$.error(
"addSampleButton() needs a container with id #sampleButtons"
);
}
$container.appendTo($buttonBar);
};
function initCodeSamples() {
var info,
$source = $("#sourceCode");
$("#codeExample").clickToggle(
function() {
$source.show("fast");
if (!this.old) {
this.old = $(this).html();
$.get(
this.href,
function(code) {
// Remove <!-- Start_Exclude [...] End_Exclude --> blocks:
code = code.replace(
/<!-- Start_Exclude(.|\n|\r)*?End_Exclude -->/gi,
"<!-- (Irrelevant source removed.) -->"
);
// Reduce tabs from 8 to 2 characters
code = code.replace(/\t/g, " ");
$source.text(code);
// Format code samples
try {
prettyPrint();
} catch (e) {
alert(e);
}
},
"html"
);
}
$(this).html("Hide source code");
},
function() {
$(this).html(this.old);
$source.hide("fast");
}
);
if (jQuery.ui) {
info =
"Fancytree " +
jQuery.ui.fancytree.version +
", jQuery UI " +
jQuery.ui.version +
", jQuery " +
jQuery.fn.jquery;
/*
info += "\n<br>";
info += "document.compatMode: " + document.compatMode + "\n";
for(e in jQuery.support){
info += "<br>\n" + e + ": " + jQuery.support[e];
}
*/
$("p.sample-links").after(
"<p class='version-info'>" + info + "</p>"
);
}
}
$(function() {
// Log to Google Analytics, when not running locally
if (document.URL.toLowerCase().indexOf("wwwendt.de/") >= 0) {
/* eslint-disable */
(function(i, s, o, g, r, a, m) {
i["GoogleAnalyticsObject"] = r;
(i[r] =
i[r] ||
function() {
(i[r].q = i[r].q || []).push(arguments);
}),
(i[r].l = 1 * new Date());
(a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(
window,
document,
"script",
"https://www.google-analytics.com/analytics.js",
"ga"
);
ga("create", "UA-316028-1", "auto");
ga("send", "pageview");
/* eslint-enable */
}
// Show some elements only, if (not) inside the Example Browser
if (top.location === window.location) {
$(".hideOutsideFS").hide();
} else {
$(".hideInsideFS").hide();
}
initCodeSamples();
$("select#skinswitcher")
.skinswitcher({
base: "../src/",
choices: [
{
name: "XP",
value: "xp",
href: "skin-xp/ui.fancytree.css",
},
{
name: "Vista (classic Dynatree)",
value: "vista",
href: "skin-vista/ui.fancytree.css",
},
{
name: "Win7",
value: "win7",
href: "skin-win7/ui.fancytree.css",
},
{
name: "Win8",
value: "win8",
href: "skin-win8/ui.fancytree.css",
},
{
name: "Win8-N",
value: "win8n",
href: "skin-win8-n/ui.fancytree.css",
},
{
name: "Win8 xxl",
value: "win8xxl",
href: "skin-win8-xxl/ui.fancytree.css",
},
{
name: "Lion",
value: "lion",
href: "skin-lion/ui.fancytree.css",
},
],
change: function(choice) {
// console.log("choice: " + choice.value)
$("#connectorsSwitch").toggle(choice.value !== "xp");
},
})
.after(
$(
"<label id='connectorsSwitch'><input name='cbConnectors' type='checkbox'>Connectors</label>"
)
);
$("input[name=cbConnectors]").on("change", function(e) {
$(".fancytree-container").toggleClass(
"fancytree-connectors",
$(this).is(":checked")
);
});
});
})(jQuery);