-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.js
More file actions
86 lines (78 loc) · 3.08 KB
/
application.js
File metadata and controls
86 lines (78 loc) · 3.08 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
/**
* File: application.js
* Description:
* Author: Mirosław Boruta <boruta.miroslaw gmail.com>
* Licence: This program is free software. It comes without any warranty,
* to the extent permitted by applicable law. You can redistribute
* it and/or modify it under the terms of the Do What The Fuck You
* Want To Public License, Version 2, as published by Sam Hocevar.
* See http://sam.zoy.org/wtfpl/COPYING for more details.
* Dependency: jQuery global object
*/
// quick fix for Opera not having console.log() function
if (!window.console) {
window.console = {log: (opera ? opera.postError : alert)};
}
(function($){
var log = {
init: function (rootEl) {
var that = this;
this.preEl = $("<pre/>").appendTo(rootEl);
this.preEl.clear = function() { this.html(""); };
this.preEl.log = function(msg) { this.append("[" + Date() + "] <em>" + msg + "</em>\n"); };
$("<button/>").
appendTo(rootEl).text("Clear").
bind("click", function(){ that.preEl.clear(); });
return this;
},
log: function (msg) {
this.preEl.log(msg);
console.log(msg);
return this;
}
};
//log.init("#log").log("Starting...");
var selectListProto = {
init: function(params) {
var that = this;
this.list = MBO.BREADCRUMB.getList(params.rootElement, params.prefix, function() { that.onSelect.apply(that, arguments); });
this.outEl = params.outputHolder;
this.outEl.bind("change", function(ev) {
$(ev.target).data("sublist").select(ev.target.value);
that.regenerateSelects();
});
this.idEl = params.idHolder;
this.regenerateSelects();
return this;
},
onSelect: function(target, selected) {
this.idEl.val(selected);
},
regenerateSelects: function() {
var sublist,select,i,id,option;
this.outEl.html("");
for (sublist = this.list; sublist; sublist = sublist.selected) {
if (sublist.childIds.length) {
select = $("<select/>").appendTo(this.outEl).data("sublist", sublist);
$("<option/>").appendTo(select);
for (i = 0; i < sublist.childIds.length; i++) {
id = sublist.childIds[i];
$("<option/>").appendTo(select).val(id).text(sublist.dag[id].item.text);
}
select.val(sublist.selected && sublist.selected.value);
}
}
select.focus(); // get focus for last generated select (at last there should be one select, with root options)
return this;
}
};
ss = $.extend({}, selectListProto);
ss.init({
optionElements: $("select"),
prefix: "-",
outputHolder: $("#out"),
idHolder: $("#id")
});
$(function() {
});
})(jQuery);