-
Notifications
You must be signed in to change notification settings - Fork 338
/
view.js
54 lines (47 loc) · 1.36 KB
/
view.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
/**
* TODO: the following methods still need unit test coverage
*/
wysihtml.views.View = Base.extend(
/** @scope wysihtml.views.View.prototype */ {
constructor: function(parent, textareaElement, config) {
this.parent = parent;
this.element = textareaElement;
this.config = config;
if (!this.config.noTextarea) {
this._observeViewChange();
}
},
_observeViewChange: function() {
var that = this;
this.parent.on("beforeload", function() {
that.parent.on("change_view", function(view) {
if (view === that.name) {
that.parent.currentView = that;
that.show();
// Using tiny delay here to make sure that the placeholder is set before focusing
setTimeout(function() { that.focus(); }, 0);
} else {
that.hide();
}
});
});
},
focus: function() {
if (this.element && this.element.ownerDocument && this.element.ownerDocument.querySelector(":focus") === this.element) {
return;
}
try { if(this.element) { this.element.focus(); } } catch(e) {}
},
hide: function() {
this.element.style.display = "none";
},
show: function() {
this.element.style.display = "";
},
disable: function() {
this.element.setAttribute("disabled", "disabled");
},
enable: function() {
this.element.removeAttribute("disabled");
}
});