-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathbootstrap2.js
More file actions
207 lines (195 loc) · 6.38 KB
/
Copy pathbootstrap2.js
File metadata and controls
207 lines (195 loc) · 6.38 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
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
JSONEditor.defaults.themes.bootstrap2 = JSONEditor.AbstractTheme.extend({
getRangeInput: function(min, max, step) {
// TODO: use bootstrap slider
return this._super(min, max, step);
},
getGridContainer: function() {
var el = document.createElement('div');
el.className = 'container-fluid';
return el;
},
getGridRow: function() {
var el = document.createElement('div');
el.className = 'row-fluid';
return el;
},
getFormInputLabel: function(text) {
var el = this._super(text);
el.style.display = 'inline-block';
el.style.fontWeight = 'bold';
return el;
},
setGridColumnSize: function(el,size) {
el.className = 'span'+size;
},
getSelectInput: function(options) {
var input = this._super(options);
input.style.width = 'auto';
input.style.maxWidth = '98%';
return input;
},
getFormInputField: function(type) {
var el = this._super(type);
el.style.width = '98%';
return el;
},
afterInputReady: function(input) {
if(input.controlgroup) return;
input.controlgroup = this.closest(input,'.control-group');
input.controls = this.closest(input,'.controls');
if(this.closest(input,'.compact')) {
input.controlgroup.className = input.controlgroup.className.replace(/control-group/g,'').replace(/[ ]{2,}/g,' ');
input.controls.className = input.controlgroup.className.replace(/controls/g,'').replace(/[ ]{2,}/g,' ');
input.style.marginBottom = 0;
}
// Run callbacks that depend on input.controlgroup
this._emptyControlgroupWaitQueue(input);
// TODO: use bootstrap slider
},
// Call callback when input.controlgroup is ready
_waitForControlgroup: function(input, callback) {
// The wait queue is an array with callbacks that are waiting for
// controlgroup
input._controlGroupWaitQueue = input._controlGroupWaitQueue || [];
input._controlGroupWaitQueue.push(callback);
// controlgroup may already be ready -- try to empty the queue right away
this._emptyControlgroupWaitQueue(input);
},
// If controlgroup is ready, call all callbacks waiting on it
_emptyControlgroupWaitQueue: function(input) {
if (input.controlgroup) {
$each(input._controlGroupWaitQueue, function(i, callback) {
callback(input.controlgroup);
});
}
},
getIndentedPanel: function() {
var el = document.createElement('div');
el.className = 'well well-small';
el.style.paddingBottom = 0;
return el;
},
getFormInputDescription: function(text) {
var el = document.createElement('p');
el.className = 'help-inline';
el.textContent = text;
return el;
},
getFormControl: function(label, input, description) {
var ret = document.createElement('div');
ret.className = 'control-group';
var controls = document.createElement('div');
controls.className = 'controls';
if(label && input.getAttribute('type') === 'checkbox') {
ret.appendChild(controls);
label.className += ' checkbox';
label.appendChild(input);
controls.appendChild(label);
controls.style.height = '30px';
}
else {
if(label) {
label.className += ' control-label';
ret.appendChild(label);
}
controls.appendChild(input);
ret.appendChild(controls);
}
if(description) controls.appendChild(description);
return ret;
},
getHeaderButtonHolder: function() {
var el = this.getButtonHolder();
el.style.marginLeft = '10px';
return el;
},
getButtonHolder: function() {
var el = document.createElement('div');
el.className = 'btn-group';
return el;
},
getButton: function(text, icon, title) {
var el = this._super(text, icon, title);
el.className += ' btn btn-default';
return el;
},
getTable: function() {
var el = document.createElement('table');
el.className = 'table table-bordered';
el.style.width = 'auto';
el.style.maxWidth = 'none';
return el;
},
addInputError: function(input,text) {
// Input errors may be ready before controlgroup is set. We need to wait
// for input.controlgroup. The caveat is that the UI won't be updated until
// after the next invocation of requestAnimationFrame callback
this._waitForControlgroup(input, function (controlgroup) {
if(!controlgroup || !input.controls) return;
controlgroup.className += ' error';
if(!input.errmsg) {
input.errmsg = document.createElement('p');
input.errmsg.className = 'help-block errormsg';
input.controls.appendChild(input.errmsg);
}
else {
input.errmsg.style.display = '';
}
input.errmsg.textContent = text;
});
},
removeInputError: function(input) {
if(!input.errmsg) return;
input.errmsg.style.display = 'none';
input.controlgroup.className = input.controlgroup.className.replace(/\s?error/g,'');
},
getTabHolder: function() {
var el = document.createElement('div');
el.className = 'tabbable tabs-left';
el.innerHTML = "<ul class='nav nav-tabs span2' style='margin-right: 0;'></ul><div class='tab-content span10' style='overflow:visible;'></div>";
return el;
},
getTab: function(text) {
var el = document.createElement('li');
var a = document.createElement('a');
a.setAttribute('href','#');
a.appendChild(text);
el.appendChild(a);
return el;
},
getTabContentHolder: function(tab_holder) {
return tab_holder.children[1];
},
getTabContent: function() {
var el = document.createElement('div');
el.className = 'tab-pane active';
return el;
},
markTabActive: function(tab) {
tab.className += ' active';
},
markTabInactive: function(tab) {
tab.className = tab.className.replace(/\s?active/g,'');
},
addTab: function(holder, tab) {
holder.children[0].appendChild(tab);
},
getProgressBar: function() {
var container = document.createElement('div');
container.className = 'progress';
var bar = document.createElement('div');
bar.className = 'bar';
bar.style.width = '0%';
container.appendChild(bar);
return container;
},
updateProgressBar: function(progressBar, progress) {
if (!progressBar) return;
progressBar.firstChild.style.width = progress + "%";
},
updateProgressBarUnknown: function(progressBar) {
if (!progressBar) return;
progressBar.className = 'progress progress-striped active';
progressBar.firstChild.style.width = '100%';
}
});