-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
78 lines (69 loc) · 1.98 KB
/
util.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
var Enumeration = function(keys) {
keys.words((function(key) {
this[key] = key;
}).bind(this));
};
var ButtonManager = function(buttonIds) {
var byId = this.byId = {};
this.buttons = buttonIds.words(function(id) {
return byId[id] = $('#'+id);
});
};
ButtonManager.prototype.disableAll = function() {
this.buttons.each(function(el) {
el.attr("disabled", true);
});
};
ButtonManager.prototype.enable = function(ids) {
var toEnable = ids.words();
this.buttons.each(function(button) {
button.attr("disabled", toEnable.indexOf(button.attr("id"))==-1);
});
};
var Sections = function(headers, panes) {
this.headers = headers;
this.panes = panes;
this.onShows = [];
headers.each((function(i, el) {
var $el = $(el),
show = this.showSection.bind(this, i),
isVisible = this.isVisible.bind(this, i);
this[$el.text().trim().camelize()] = {
show : show,
isVisible : isVisible,
addOnShow : this.addOnShowSection.bind(this, i)
};
$el.click(function(ev) {
ev.preventDefault();
if (ev.target.href) {
var parts = ev.target.href.split('#');
if ( parts.length>1 ) {
document.location.hash = parts.last();
}
}
show();
});
}).bind(this));
};
Sections.prototype.showSection = function(index) {
this.headers.removeClass("active");
$(this.headers[index]).addClass("active");
this.panes.removeClass("active");
$(this.panes[index]).addClass("active");
$("html").animate({scrollTop : 0}, 0);
this.onShows[index] && this.onShows[index].each(function(handler) {
handler();
});
};
Sections.prototype.isVisible = function(index) {
return $(this.headers[index]).hasClass("active");
};
Sections.prototype.addOnShowSection = function(index, handler) {
this.onShows[index] = this.onShows[index] || [];
this.onShows[index].push(handler);
};
var Util = {
makeEscapedSpecialCharactersReal : function(text) {
return text.replace(/\\n/g, '\n').replace(/\\t/g, '\t');
}
}