-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathEvent.js
More file actions
158 lines (137 loc) · 4.71 KB
/
Copy pathEvent.js
File metadata and controls
158 lines (137 loc) · 4.71 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
// Event.js v3.4.0
/* global _doc:readonly */
//---------------------------------------------------------------------------
// ★UIEventsクラス イベント設定の管理を行う
//---------------------------------------------------------------------------
// メニュー描画/取得/html表示系
ui.event = {
resizetimer: null, // resizeタイマー
visibilitystate: null,
visibilityCallbacks: [],
removers: [],
//----------------------------------------------------------------------
// event.addEvent() addEventListener(など)を呼び出す
//----------------------------------------------------------------------
addEvent: function(el, event, self, callback, capt) {
this.removers.push(pzpr.util.addEvent(el, event, self, callback, !!capt));
},
//----------------------------------------------------------------------
// event.removeAllEvents() addEventで登録されたイベントを削除する
//----------------------------------------------------------------------
removeAllEvents: function() {
this.removers.forEach(function(remover) {
remover();
});
this.removers = [];
},
addVisibilityCallback: function(callback) {
if (this.visibilitystate === "visible") {
callback();
} else {
this.visibilityCallbacks.push(callback);
}
},
//---------------------------------------------------------------------------
// event.setWindowEvents() マウス入力、キー入力以外のイベントの設定を行う
//---------------------------------------------------------------------------
setWindowEvents: function() {
// File API+Drag&Drop APIの設定
if (!!ui.reader) {
var DDhandler = function(e) {
ui.reader.readAsText(e.dataTransfer.files[0]);
e.preventDefault();
e.stopPropagation();
};
this.addEvent(
window,
"dragover",
this,
function(e) {
e.preventDefault();
},
true
);
this.addEvent(window, "drop", this, DDhandler, true);
}
// onBlurにイベントを割り当てる
this.addEvent(_doc, "blur", this, this.onblur_func);
// onresizeイベントを割り当てる
var evname = !pzpr.env.OS.iOS ? "resize" : "orientationchange";
this.addEvent(window, evname, this, this.onresize_func);
// onbeforeunloadイベントを割り当てる
this.addEvent(window, "beforeunload", this, this.onbeforeunload_func);
// onunloadイベントを割り当てる
this.addEvent(window, "unload", this, this.onunload_func);
if (!!matchMedia) {
var mqString = "(resolution: 1dppx)";
matchMedia(mqString).addListener(this.onpixelratiochange_func);
}
},
setDocumentEvents: function() {
this.addEvent(
document,
"visibilitychange",
this,
this.onvisibilitychange_func
);
this.onvisibilitychange_func(); // set state
},
//---------------------------------------------------------------------------
// event.onload_func() ウィンドウを開いた時に呼ばれる関数
// event.onunload_func() ウィンドウをクローズする前に呼ばれる関数
//---------------------------------------------------------------------------
onload_func: function(onload_option) {
ui.initFileReadMethod();
ui.urlconfig.init(onload_option);
ui.menuconfig.restore();
ui.listener.setListeners(ui.puzzle);
if (pzpr.env.OS.Android) {
ui.misc.modifyCSS({
"body, .btn": { fontFamily: "Verdana, Arial, sans-serif" }
});
}
},
onunload_func: function() {
ui.menuconfig.save();
},
//---------------------------------------------------------------------------
// event.onresize_func() ウィンドウリサイズ時に呼ばれる関数
// event.onblur_func() ウィンドウからフォーカスが離れた時に呼ばれる関数
// event.onbeforeunload_func() ウィンドウをクローズする前に呼ばれる関数
//---------------------------------------------------------------------------
onresize_func: function() {
if (this.resizetimer) {
clearTimeout(this.resizetimer);
}
this.resizetimer = setTimeout(function() {
ui.adjustcellsize();
}, 250);
},
onblur_func: function() {
ui.puzzle.key.keyreset();
ui.puzzle.mouse.mousereset();
},
onbeforeunload_func: function(e) {
if (ui.puzzle.playeronly || !ui.puzzle.ismodified()) {
return;
}
var msg = ui.selectStr("盤面が更新されています", "The board is edited.");
e.returnValue = msg;
return msg;
},
onvisibilitychange_func: function(e) {
var state = document.visibilityState;
if (state !== this.visibilitystate) {
this.visibilitystate = state;
if (state === "visible") {
for (var i = 0; i < this.visibilityCallbacks.length; i++) {
this.visibilityCallbacks[i]();
}
this.visibilityCallbacks = [];
}
}
},
onpixelratiochange_func: function(e) {
ui.puzzle.redraw(true);
}
};