-
Notifications
You must be signed in to change notification settings - Fork 0
/
page.js
91 lines (71 loc) · 2.11 KB
/
page.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
/* base class for other pages */
function Page() {
this._init();
}
Page.prototype = {
_init: function(view, active) {
this._view = null;
this._active = false;
this._tag = null;
var me = this;
window.addEventListener("ViewChanged", function(event) {
me._width = event.width;
me._height = event.height;
me.setView(event.view, event.details);
}, false);
},
_log: function(message) {
console.log(this._tag + ": " + message);
},
_ensureViewElement: function() {
this._viewElement = null;
if (!this._tag) {
console.log("You must set a tag!");
return;
}
if (!this._view) {
console.log("No view is set");
return;
}
var id = this._tag + "-" + this._view.toLowerCase();
if ($("#" + id).size() == 0) {
// Create a new view element
$(document.body).append('<div id="' + id + '" class="view-container"></div>');
}
this._viewElement = $("#" + id).get(0);
},
setView: function(view, detail) {
if (this._viewElement) {
$(this._viewElement).hide();
}
this._view = view;
this._viewDetail = detail;
if (this._view) {
this._ensureViewElement();
if (this._active) {
$(this._viewElement).show();
}
if (this._width)
$(this._viewElement).width(this._width);
if (this._height)
$(this._viewElement).height(this._height);
}
},
getView: function() {
return this._view;
},
setActive: function(active) {
if (active && this._view) {
$(this._viewElement).show();
} else if (!active && this._view) {
$(this._viewElement).hide();
}
this._active = active;
},
getActive: function() {
return this._active;
},
isOnScreen: function() {
return this._active && this._viewDetail != OpenChannel.ViewDetail.OFFSCREEN;
},
};