Skip to content

Commit a035613

Browse files
committed
JSLintある程度通るぐらいにした logWatchをthisに置き換えた
1 parent 80de1d1 commit a035613

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

viewlog.ejs

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -106,58 +106,58 @@ logWatch.url = "ws://" + logWatch.host + ":" + logWatch.port + "/";
106106
107107
// ログの変更関連
108108
logWatch.clear = function() {
109-
logWatch.dom.logs.children().remove();
109+
this.dom.logs.children().remove();
110110
};
111111
logWatch.changeLog = function() {
112-
ws.send(logWatch.dom.logfile.val());
112+
ws.send(this.dom.logfile.val());
113113
this.clear ();
114114
};
115115
logWatch.showIndicator = function() {
116-
if ( logWatch.isPause ) {
117-
logWatch.dom.indicator.addClass("pause");
116+
if ( this.isPause ) {
117+
this.dom.indicator.addClass("pause");
118118
}
119119
else {
120-
logWatch.dom.indicator.removeClass("pause");
120+
this.dom.indicator.removeClass("pause");
121121
}
122122
};
123123
124124
// ログ表示の一時停止・再開関連
125125
// ポーズチェックボックスの確認
126126
logWatch.pauseIsChecked = function() {
127-
return $(logWatch.dom.pause).is(":checked");
128-
}
127+
return $(this.dom.pause).is(":checked");
128+
};
129129
// ポーズ解除
130130
logWatch.resume = function() {
131-
logWatch.isPause = false;
131+
this.isPause = false;
132132
$(".paused").fadeIn().removeClass("paused").removeClass("hidden");
133-
logWatch.showIndicator();
134-
logWatch.clearHiddenCount();
135-
logWatch.showHiddenCount();
133+
this.showIndicator();
134+
this.clearHiddenCount();
135+
this.showHiddenCount();
136136
};
137137
// ポーズ
138138
logWatch.pause = function() {
139-
logWatch.isPause = true;
140-
logWatch.showIndicator();
139+
this.isPause = true;
140+
this.showIndicator();
141141
};
142142
// チェックボックス操作によるポーズ・ポーズ解除
143143
logWatch.checkbox = function() {
144-
if ( logWatch.pauseIsChecked() ) {
145-
logWatch.pause();
144+
if ( this.pauseIsChecked() ) {
145+
this.pause();
146146
}
147147
else {
148-
logWatch.resume();
148+
this.resume();
149149
}
150-
}
150+
};
151151
// マウス操作によるポーズ
152152
logWatch.mouseOver = function() {
153-
logWatch.pause();
154-
}
153+
this.pause();
154+
};
155155
// マウス操作によるポーズ解除
156156
logWatch.mouseOut = function() {
157-
if (! logWatch.pauseIsChecked() ) {
158-
logWatch.resume();
157+
if (! this.pauseIsChecked() ) {
158+
this.resume();
159159
}
160-
}
160+
};
161161
162162
// ログの更新関連
163163
// ステージへ追加
@@ -167,46 +167,47 @@ logWatch.append = function(data) {
167167
data = data.replace(/</g, "&lt;"); // HTML表示用に不等号を文字参照に
168168
data = data.replace(/>/g, "&gt;"); // HTML表示用に不等号を文字参照に
169169
var item = $('<li class="log hidden">' + data + "</li>");
170-
if ( logWatch.odd ) {
170+
if ( this.odd ) {
171171
item.addClass("odd");
172172
}
173-
if ( logWatch.isPause ) {
173+
if ( this.isPause ) {
174174
item.addClass("paused");
175175
}
176-
item.mouseover( function() { logWatch.mouseOver() } );
177-
item.mouseout ( function() { logWatch.mouseOut () } );
176+
var self = this;
177+
item.mouseover( function() { self.mouseOver(); } );
178+
item.mouseout ( function() { self.mouseOut (); } );
178179
this.dom.logs.prepend(item);
179-
if ( !logWatch.isPause ) {
180+
if ( !this.isPause ) {
180181
item.fadeIn(60).removeClass("hidden");
181182
} else {
182-
logWatch.incHiddenCount();
183-
logWatch.showHiddenCount();
183+
this.incHiddenCount();
184+
this.showHiddenCount();
184185
}
185186
};
186187
187188
// カウント関連
188189
logWatch.incHiddenCount = function() {
189-
logWatch.hiddenCount++;
190+
this.hiddenCount++;
190191
};
191192
logWatch.getHiddenCount = function() {
192-
return logWatch.hiddenCount;
193-
}
193+
return this.hiddenCount;
194+
};
194195
logWatch.clearHiddenCount = function() {
195-
logWatch.hiddenCount = 0;
196-
}
196+
this.hiddenCount = 0;
197+
};
197198
logWatch.showHiddenCount = function() {
198-
var count = logWatch.getHiddenCount();
199+
var count = this.getHiddenCount();
199200
if ( count == 0 ) {
200201
count = "";
201202
}
202-
logWatch.dom.indicator.text( count );
203-
}
203+
this.dom.indicator.text( count );
204+
};
204205
logWatch.addCount = function() {
205-
logWatch.odd = ++logWatch.odd % 2;
206-
}
206+
this.odd = ++this.odd % 2;
207+
};
207208
208209
// WebSocketオブジェクト
209-
var WebSocket = window.WebSocket || Window.MozWebSocket;
210+
var WebSocket = window.WebSocket || window.MozWebSocket;
210211
try {
211212
ws = new WebSocket (logWatch.url);
212213
}
@@ -220,22 +221,22 @@ $( function() {
220221
221222
ws.onopen = function() {
222223
logWatch.append( logWatch.url + "へ接続しました");
223-
}
224+
};
224225
ws.onerror = function(event){
225226
//エラー処理
226227
console.log(event);
227-
}
228+
};
228229
// データが着信すると動作するonmessageイベント
229230
ws.onmessage = function(msg) {
230231
var data = JSON.parse( msg.data );
231232
logWatch.append( data );
232233
logWatch.addCount();
233-
}
234+
};
234235
ws.onclose = function() {
235236
logWatch.append("接続が切れました(" + logWatch.url + ")<br />"
236237
+ "サーバ側にnode.jsが設置され、サーバスクリプトが"
237238
+ "動いていることを確認してください。");
238-
}
239+
};
239240
});
240241
</script>
241242
</html>

0 commit comments

Comments
 (0)