質問編集履歴
15
タイトル修正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
coffeescriptからjavascriptのコンパイルでreturnが一つ余計に表示されてしまう。
|
test
CHANGED
File without changes
|
14
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -312,7 +312,155 @@
|
|
312
312
|
|
313
313
|
|
314
314
|
|
315
|
-
④【
|
315
|
+
④【現時点のCoffeeScriptコード】
|
316
|
+
|
317
|
+
```CoffeeScript
|
318
|
+
|
319
|
+
$ ->
|
320
|
+
|
321
|
+
showChar = 100
|
322
|
+
|
323
|
+
ellipsestext = "..."
|
324
|
+
|
325
|
+
moretext = "more"
|
326
|
+
|
327
|
+
lesstext = "less"
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
$('.more').each ->
|
332
|
+
|
333
|
+
content = $(@).html()
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
if content.length > showChar
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
c = content.substr 0, showChar
|
342
|
+
|
343
|
+
h = content.substr showChar, content.length - showChar
|
344
|
+
|
345
|
+
|
346
|
+
|
347
|
+
html = """ #{c}
|
348
|
+
|
349
|
+
<span class="moreellipses">
|
350
|
+
|
351
|
+
#{ellipsestext}
|
352
|
+
|
353
|
+
</span>
|
354
|
+
|
355
|
+
<span class="morecontent">
|
356
|
+
|
357
|
+
<span>#{h}</span>
|
358
|
+
|
359
|
+
<a href="" class="morelink">#{moretext}</a>
|
360
|
+
|
361
|
+
</span>"""
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
$(@).html html
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
$(".morelink").click ->
|
370
|
+
|
371
|
+
if $(@).hasClass "less"
|
372
|
+
|
373
|
+
$(@).removeClass "less"
|
374
|
+
|
375
|
+
$(@).html moretext
|
376
|
+
|
377
|
+
else
|
378
|
+
|
379
|
+
$(@).addClass "less"
|
380
|
+
|
381
|
+
$(@).html lesstext
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
$(@).parent().prev().toggle()
|
386
|
+
|
387
|
+
$(@).prev().toggle()
|
388
|
+
|
389
|
+
return false;
|
390
|
+
|
391
|
+
```
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
⑤【④をコンパイルしたJavaScriptコード】
|
398
|
+
|
399
|
+
```JavaScript
|
400
|
+
|
401
|
+
$(function() {
|
402
|
+
|
403
|
+
var ellipsestext, lesstext, moretext, showChar;
|
404
|
+
|
405
|
+
showChar = 100;
|
406
|
+
|
407
|
+
ellipsestext = "...";
|
408
|
+
|
409
|
+
moretext = "more";
|
410
|
+
|
411
|
+
lesstext = "less";
|
412
|
+
|
413
|
+
$('.more').each(function() {
|
414
|
+
|
415
|
+
var c, content, h, html;
|
416
|
+
|
417
|
+
content = $(this).html();
|
418
|
+
|
419
|
+
if (content.length > showChar) {
|
420
|
+
|
421
|
+
c = content.substr(0, showChar);
|
422
|
+
|
423
|
+
h = content.substr(showChar, content.length - showChar);
|
424
|
+
|
425
|
+
html = " " + c + "\n<span class=\"moreellipses\">\n" + ellipsestext + " \n</span>\n<span class=\"morecontent\">\n <span>" + h + "</span> \n <a href=\"\" class=\"morelink\">" + moretext + "</a>\n</span>";
|
426
|
+
|
427
|
+
return $(this).html(html);
|
428
|
+
|
429
|
+
}
|
430
|
+
|
431
|
+
});
|
432
|
+
|
433
|
+
return $(".morelink").click(function() { ←どうしてもこのreturnを消したい。
|
434
|
+
|
435
|
+
if ($(this).hasClass("less")) {
|
436
|
+
|
437
|
+
$(this).removeClass("less");
|
438
|
+
|
439
|
+
$(this).html(moretext);
|
440
|
+
|
441
|
+
} else {
|
442
|
+
|
443
|
+
$(this).addClass("less");
|
444
|
+
|
445
|
+
$(this).html(lesstext);
|
446
|
+
|
447
|
+
}
|
448
|
+
|
449
|
+
$(this).parent().prev().toggle();
|
450
|
+
|
451
|
+
$(this).prev().toggle();
|
452
|
+
|
453
|
+
return false;
|
454
|
+
|
455
|
+
});
|
456
|
+
|
457
|
+
});
|
458
|
+
|
459
|
+
```
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
⑥【実現したいJavaScriptコード】
|
316
464
|
|
317
465
|
```Javascript
|
318
466
|
|
@@ -326,7 +474,7 @@
|
|
326
474
|
|
327
475
|
moretext = "more";
|
328
476
|
|
329
|
-
|
477
|
+
lesstext = "less"; ←⑤でreturnをjsコードで追加したことで、coffeeではreturnが消えました。
|
330
478
|
|
331
479
|
});
|
332
480
|
|
@@ -354,7 +502,7 @@
|
|
354
502
|
|
355
503
|
|
356
504
|
|
357
|
-
$(".morelink").click(function() {
|
505
|
+
$(".morelink").click(function() {
|
358
506
|
|
359
507
|
if ($(this).hasClass("less")) {
|
360
508
|
|
@@ -376,152 +524,8 @@
|
|
376
524
|
|
377
525
|
return false;
|
378
526
|
|
527
|
+
});
|
528
|
+
|
379
529
|
});
|
380
530
|
|
381
531
|
```
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
これに対応するため、
|
386
|
-
|
387
|
-
lesstextの下にreturnを追加。
|
388
|
-
|
389
|
-
(明示的にreturnを指定すれば、予期しないところでreturnが発生することを防げるから。←たぶん、僕の誤解だと思います…しかしとりあえず試しました。)
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
⑤【元のコードを修正したCoffeeScriptコード】
|
394
|
-
|
395
|
-
```CoffeeScript
|
396
|
-
|
397
|
-
$(document).ready ->
|
398
|
-
|
399
|
-
showChar = 100
|
400
|
-
|
401
|
-
ellipsestext = "..."
|
402
|
-
|
403
|
-
moretext = "more"
|
404
|
-
|
405
|
-
lesstext = "less"
|
406
|
-
|
407
|
-
return ←④のreturnを
|
408
|
-
|
409
|
-
消すためにreturnを追加
|
410
|
-
|
411
|
-
$('.more').each ->
|
412
|
-
|
413
|
-
content = $(trim).$(this).html()
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
if content.length > showChar
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
c = content.substr 0, showChar
|
422
|
-
|
423
|
-
h = content.substr showChar, content.length - showChar
|
424
|
-
|
425
|
-
html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
$(this).html html
|
430
|
-
|
431
|
-
return
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
$(".morelink").click ->
|
436
|
-
|
437
|
-
if $(this).hasClass "less"
|
438
|
-
|
439
|
-
$(this).removeClass "less"
|
440
|
-
|
441
|
-
$(this).html moretext
|
442
|
-
|
443
|
-
else
|
444
|
-
|
445
|
-
$(this).addClass "less"
|
446
|
-
|
447
|
-
$(this).html lesstext
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
$(this).parent().prev().toggle()
|
452
|
-
|
453
|
-
$(this).prev().toggle()
|
454
|
-
|
455
|
-
false
|
456
|
-
|
457
|
-
```
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
⑥【⑤をコンパイルしたコード】
|
462
|
-
|
463
|
-
```Javascript
|
464
|
-
|
465
|
-
$(document).ready(function() {
|
466
|
-
|
467
|
-
var ellipsestext, lesstext, moretext, showChar;
|
468
|
-
|
469
|
-
showChar = 100;
|
470
|
-
|
471
|
-
ellipsestext = "...";
|
472
|
-
|
473
|
-
moretext = "more";
|
474
|
-
|
475
|
-
lesstext = "less"; ←⑤でreturnをjsコードで追加したことで、coffeeではreturnが消えました。
|
476
|
-
|
477
|
-
});
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
$('.more').each(function() {
|
482
|
-
|
483
|
-
var c, content, h, html;
|
484
|
-
|
485
|
-
content = $(trim).$(this).html();
|
486
|
-
|
487
|
-
if (content.length > showChar) {
|
488
|
-
|
489
|
-
c = content.substr(0, showChar);
|
490
|
-
|
491
|
-
h = content.substr(showChar, content.length - showChar);
|
492
|
-
|
493
|
-
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
494
|
-
|
495
|
-
$(this).html(html);
|
496
|
-
|
497
|
-
}
|
498
|
-
|
499
|
-
});
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
$(".morelink").click(function() {
|
504
|
-
|
505
|
-
if ($(this).hasClass("less")) {
|
506
|
-
|
507
|
-
$(this).removeClass("less");
|
508
|
-
|
509
|
-
$(this).html(moretext);
|
510
|
-
|
511
|
-
} else {
|
512
|
-
|
513
|
-
$(this).addClass("less");
|
514
|
-
|
515
|
-
$(this).html(lesstext);
|
516
|
-
|
517
|
-
}
|
518
|
-
|
519
|
-
$(this).parent().prev().toggle();
|
520
|
-
|
521
|
-
$(this).prev().toggle();
|
522
|
-
|
523
|
-
return false;
|
524
|
-
|
525
|
-
});
|
526
|
-
|
527
|
-
```
|
13
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,9 +72,9 @@
|
|
72
72
|
|
73
73
|
①【元のJavaScriptコード】
|
74
74
|
|
75
|
-
②【
|
75
|
+
②【①のJavascriptコードを書き換えたCoffeeScriptコード】
|
76
|
-
|
76
|
+
|
77
|
-
③【http://coffeescript.org/で②をコンパイルしたJavaScriptコード】
|
77
|
+
③【http://coffeescript.org/で②のCoffeeScriptコードをコンパイルしたJavaScriptコード】
|
78
78
|
|
79
79
|
|
80
80
|
|
@@ -152,7 +152,7 @@
|
|
152
152
|
|
153
153
|
|
154
154
|
|
155
|
-
②【
|
155
|
+
②【①のJavascriptコードを書き換えたCoffeeScriptコード】
|
156
156
|
|
157
157
|
|
158
158
|
|
@@ -228,7 +228,7 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
|
231
|
-
③【http://coffeescript.org/で②をコンパイルしたJavaScriptコード】
|
231
|
+
③【http://coffeescript.org/で②のCoffeeScriptコードをコンパイルしたJavaScriptコード】
|
232
232
|
|
233
233
|
|
234
234
|
|
12
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -70,15 +70,15 @@
|
|
70
70
|
|
71
71
|
|
72
72
|
|
73
|
-
①【元の
|
73
|
+
①【元のJavaScriptコード】
|
74
|
-
|
74
|
+
|
75
|
-
②【私が
|
75
|
+
②【私がJavascriptコードをCoffeeScriptコードに書き直すために文法を修正したコード】
|
76
|
-
|
76
|
+
|
77
|
-
③【http://coffeescript.org/で
|
77
|
+
③【http://coffeescript.org/で②をコンパイルしたJavaScriptコード】
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
-
①【元の
|
81
|
+
①【元のJavaScriptコード】
|
82
82
|
|
83
83
|
```JavaScript
|
84
84
|
|
@@ -152,7 +152,7 @@
|
|
152
152
|
|
153
153
|
|
154
154
|
|
155
|
-
②【私が
|
155
|
+
②【私がJavascriptコードをCoffeeScriptコードに書き直すために文法を修正したコード】
|
156
156
|
|
157
157
|
|
158
158
|
|
@@ -228,7 +228,7 @@
|
|
228
228
|
|
229
229
|
|
230
230
|
|
231
|
-
③【http://coffeescript.org/で②をコンパイルしたコード】
|
231
|
+
③【http://coffeescript.org/で②をコンパイルしたJavaScriptコード】
|
232
232
|
|
233
233
|
|
234
234
|
|
11
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
という問題がありますので、
|
25
|
+
という問題がありますので、JavaScriptコードをCoffeeScriptコードに書き換えようと考えました。
|
26
26
|
|
27
27
|
|
28
28
|
|
10
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
処理速度、コードの複雑化を改善するためにjavascriptをcoffeescriptへ移行したい。
|
8
8
|
|
9
|
+
下記番号で言いますと、①=③になるように②のCoffeeScriptを修正したい。
|
10
|
+
|
9
11
|
|
10
12
|
|
11
13
|
javascriptでfacebookのような「続きを見る」機能を苦戦しながらもみなさんのご助力をいただき実装しました。この機能は複数ページに必要な機能でしたので、複数ファイルに同様のjsコードを記述しています。
|
9
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -154,8 +154,244 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
+
```CoffeeScript
|
158
|
+
|
159
|
+
$(document).ready ->
|
160
|
+
|
161
|
+
showChar = 100
|
162
|
+
|
163
|
+
ellipsestext = "..."
|
164
|
+
|
165
|
+
moretext = "more"
|
166
|
+
|
167
|
+
lesstext = "less"
|
168
|
+
|
169
|
+
return
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
$('.more').each ->
|
174
|
+
|
175
|
+
content = $(trim).$(this).html()
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
if content.length > showChar
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
c = content.substr 0, showChar
|
184
|
+
|
185
|
+
h = content.substr showChar, content.length - showChar
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
$(this).html html
|
194
|
+
|
195
|
+
return
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
$(".morelink").click ->
|
200
|
+
|
201
|
+
if $(this).hasClass "less"
|
202
|
+
|
203
|
+
$(this).removeClass "less"
|
204
|
+
|
205
|
+
$(this).html moretext
|
206
|
+
|
207
|
+
return
|
208
|
+
|
209
|
+
else
|
210
|
+
|
211
|
+
$(this).addClass "less"
|
212
|
+
|
213
|
+
$(this).html lesstext
|
214
|
+
|
215
|
+
return
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
$(this).parent().prev().toggle()
|
220
|
+
|
221
|
+
$(this).prev().toggle()
|
222
|
+
|
223
|
+
false
|
224
|
+
|
225
|
+
```
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
③【http://coffeescript.org/で②をコンパイルしたコード】
|
230
|
+
|
231
|
+
|
232
|
+
|
157
233
|
```Javascript
|
158
234
|
|
235
|
+
$(document).ready(function() {
|
236
|
+
|
237
|
+
var ellipsestext, lesstext, moretext, showChar;
|
238
|
+
|
239
|
+
showChar = 100;
|
240
|
+
|
241
|
+
ellipsestext = "...";
|
242
|
+
|
243
|
+
moretext = "more";
|
244
|
+
|
245
|
+
lesstext = "less";
|
246
|
+
|
247
|
+
});
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
$('.more').each(function() {
|
252
|
+
|
253
|
+
var c, content, h, html;
|
254
|
+
|
255
|
+
content = $(trim).$(this).html();
|
256
|
+
|
257
|
+
if (content.length > showChar) {
|
258
|
+
|
259
|
+
c = content.substr(0, showChar);
|
260
|
+
|
261
|
+
h = content.substr(showChar, content.length - showChar);
|
262
|
+
|
263
|
+
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
264
|
+
|
265
|
+
$(this).html(html);
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
});
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
$(".morelink").click(function() {
|
274
|
+
|
275
|
+
if ($(this).hasClass("less")) {
|
276
|
+
|
277
|
+
$(this).removeClass("less");
|
278
|
+
|
279
|
+
$(this).html(moretext);
|
280
|
+
|
281
|
+
return;
|
282
|
+
|
283
|
+
} else {
|
284
|
+
|
285
|
+
$(this).addClass("less");
|
286
|
+
|
287
|
+
$(this).html(lesstext);
|
288
|
+
|
289
|
+
return;
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
$(this).parent().prev().toggle();
|
294
|
+
|
295
|
+
$(this).prev().toggle();
|
296
|
+
|
297
|
+
return false;
|
298
|
+
|
299
|
+
}); ←下にもう一つ});が入るはず。
|
300
|
+
|
301
|
+
```
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
何卒、ご助言お願い致します。
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
###情報追加部分
|
310
|
+
|
311
|
+
|
312
|
+
|
313
|
+
④【当初http://coffeescript.org/でコンパイルされたコードの一部】
|
314
|
+
|
315
|
+
```Javascript
|
316
|
+
|
317
|
+
$(document).ready(function() {
|
318
|
+
|
319
|
+
var ellipsestext, lesstext, moretext, showChar;
|
320
|
+
|
321
|
+
showChar = 100;
|
322
|
+
|
323
|
+
ellipsestext = "...";
|
324
|
+
|
325
|
+
moretext = "more";
|
326
|
+
|
327
|
+
return lesstext = "less"; ←returnが入ってしまっている(①のコードとは違う)
|
328
|
+
|
329
|
+
});
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
$('.more').each(function() {
|
334
|
+
|
335
|
+
var c, content, h, html;
|
336
|
+
|
337
|
+
content = $(trim).$(this).html();
|
338
|
+
|
339
|
+
if (content.length > showChar) {
|
340
|
+
|
341
|
+
c = content.substr(0, showChar);
|
342
|
+
|
343
|
+
h = content.substr(showChar, content.length - showChar);
|
344
|
+
|
345
|
+
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
346
|
+
|
347
|
+
$(this).html(html);
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
});
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
$(".morelink").click(function() {
|
356
|
+
|
357
|
+
if ($(this).hasClass("less")) {
|
358
|
+
|
359
|
+
$(this).removeClass("less");
|
360
|
+
|
361
|
+
$(this).html(moretext);
|
362
|
+
|
363
|
+
} else {
|
364
|
+
|
365
|
+
$(this).addClass("less");
|
366
|
+
|
367
|
+
$(this).html(lesstext);
|
368
|
+
|
369
|
+
}
|
370
|
+
|
371
|
+
$(this).parent().prev().toggle();
|
372
|
+
|
373
|
+
$(this).prev().toggle();
|
374
|
+
|
375
|
+
return false;
|
376
|
+
|
377
|
+
});
|
378
|
+
|
379
|
+
```
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
これに対応するため、
|
384
|
+
|
385
|
+
lesstextの下にreturnを追加。
|
386
|
+
|
387
|
+
(明示的にreturnを指定すれば、予期しないところでreturnが発生することを防げるから。←たぶん、僕の誤解だと思います…しかしとりあえず試しました。)
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
⑤【元のコードを修正したCoffeeScriptコード】
|
392
|
+
|
393
|
+
```CoffeeScript
|
394
|
+
|
159
395
|
$(document).ready ->
|
160
396
|
|
161
397
|
showChar = 100
|
@@ -166,9 +402,9 @@
|
|
166
402
|
|
167
403
|
lesstext = "less"
|
168
404
|
|
405
|
+
return ←④のreturnを
|
406
|
+
|
169
|
-
|
407
|
+
消すためにreturnを追加
|
170
|
-
|
171
|
-
|
172
408
|
|
173
409
|
$('.more').each ->
|
174
410
|
|
@@ -184,8 +420,6 @@
|
|
184
420
|
|
185
421
|
h = content.substr showChar, content.length - showChar
|
186
422
|
|
187
|
-
|
188
|
-
|
189
423
|
html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'
|
190
424
|
|
191
425
|
|
@@ -204,17 +438,13 @@
|
|
204
438
|
|
205
439
|
$(this).html moretext
|
206
440
|
|
207
|
-
return
|
208
|
-
|
209
441
|
else
|
210
442
|
|
211
443
|
$(this).addClass "less"
|
212
444
|
|
213
445
|
$(this).html lesstext
|
214
446
|
|
215
|
-
|
447
|
+
|
216
|
-
|
217
|
-
|
218
448
|
|
219
449
|
$(this).parent().prev().toggle()
|
220
450
|
|
@@ -226,11 +456,9 @@
|
|
226
456
|
|
227
457
|
|
228
458
|
|
229
|
-
|
459
|
+
⑥【⑤をコンパイルしたコード】
|
230
|
-
|
231
|
-
|
232
|
-
|
460
|
+
|
233
|
-
```
|
461
|
+
```Javascript
|
234
462
|
|
235
463
|
$(document).ready(function() {
|
236
464
|
|
@@ -242,7 +470,7 @@
|
|
242
470
|
|
243
471
|
moretext = "more";
|
244
472
|
|
245
|
-
lesstext = "less";
|
473
|
+
lesstext = "less"; ←⑤でreturnをjsコードで追加したことで、coffeeではreturnが消えました。
|
246
474
|
|
247
475
|
});
|
248
476
|
|
@@ -278,16 +506,12 @@
|
|
278
506
|
|
279
507
|
$(this).html(moretext);
|
280
508
|
|
281
|
-
return;
|
282
|
-
|
283
509
|
} else {
|
284
510
|
|
285
511
|
$(this).addClass("less");
|
286
512
|
|
287
513
|
$(this).html(lesstext);
|
288
514
|
|
289
|
-
return;
|
290
|
-
|
291
515
|
}
|
292
516
|
|
293
517
|
$(this).parent().prev().toggle();
|
@@ -296,230 +520,6 @@
|
|
296
520
|
|
297
521
|
return false;
|
298
522
|
|
299
|
-
});
|
300
|
-
|
301
|
-
```
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
何卒、ご助言お願い致します。
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
###情報追加部分
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
④【当初http://coffeescript.org/で出力されたコードの一部】
|
314
|
-
|
315
|
-
```coffeescript
|
316
|
-
|
317
|
-
$(document).ready(function() {
|
318
|
-
|
319
|
-
var ellipsestext, lesstext, moretext, showChar;
|
320
|
-
|
321
|
-
showChar = 100;
|
322
|
-
|
323
|
-
ellipsestext = "...";
|
324
|
-
|
325
|
-
moretext = "more";
|
326
|
-
|
327
|
-
return lesstext = "less"; ←returnが入ってしまっている(①のコードとは違う)
|
328
|
-
|
329
|
-
});
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
$('.more').each(function() {
|
334
|
-
|
335
|
-
var c, content, h, html;
|
336
|
-
|
337
|
-
content = $(trim).$(this).html();
|
338
|
-
|
339
|
-
if (content.length > showChar) {
|
340
|
-
|
341
|
-
c = content.substr(0, showChar);
|
342
|
-
|
343
|
-
h = content.substr(showChar, content.length - showChar);
|
344
|
-
|
345
|
-
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
346
|
-
|
347
|
-
$(this).html(html);
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
});
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
$(".morelink").click(function() {
|
356
|
-
|
357
|
-
if ($(this).hasClass("less")) {
|
358
|
-
|
359
|
-
$(this).removeClass("less");
|
360
|
-
|
361
|
-
$(this).html(moretext);
|
362
|
-
|
363
|
-
} else {
|
364
|
-
|
365
|
-
$(this).addClass("less");
|
366
|
-
|
367
|
-
$(this).html(lesstext);
|
368
|
-
|
369
|
-
}
|
370
|
-
|
371
|
-
$(this).parent().prev().toggle();
|
372
|
-
|
373
|
-
$(this).prev().toggle();
|
374
|
-
|
375
|
-
return false;
|
376
|
-
|
377
|
-
});
|
378
|
-
|
379
|
-
```
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
これに対応するため、
|
384
|
-
|
385
|
-
lesstextの下にreturnを追加。
|
386
|
-
|
387
|
-
(明示的にreturnを指定すれば、予期しないところでreturnが発生することを防げるから。←たぶん、僕の誤解だと思います…しかしとりあえず試しました。)
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
⑤【元のコードを修正したjsコード】
|
392
|
-
|
393
|
-
```JavaScript
|
394
|
-
|
395
|
-
$(document).ready ->
|
396
|
-
|
397
|
-
showChar = 100
|
398
|
-
|
399
|
-
ellipsestext = "..."
|
400
|
-
|
401
|
-
moretext = "more"
|
402
|
-
|
403
|
-
lesstext = "less"
|
404
|
-
|
405
|
-
return ←④のreturnを
|
406
|
-
|
407
|
-
消すためにreturnを追加
|
408
|
-
|
409
|
-
$('.more').each ->
|
410
|
-
|
411
|
-
content = $(trim).$(this).html()
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
if content.length > showChar
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
c = content.substr 0, showChar
|
420
|
-
|
421
|
-
h = content.substr showChar, content.length - showChar
|
422
|
-
|
423
|
-
html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
$(this).html html
|
428
|
-
|
429
|
-
return
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
$(".morelink").click ->
|
434
|
-
|
435
|
-
if $(this).hasClass "less"
|
436
|
-
|
437
|
-
$(this).removeClass "less"
|
438
|
-
|
439
|
-
$(this).html moretext
|
440
|
-
|
441
|
-
else
|
442
|
-
|
443
|
-
$(this).addClass "less"
|
444
|
-
|
445
|
-
$(this).html lesstext
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
$(this).parent().prev().toggle()
|
450
|
-
|
451
|
-
$(this).prev().toggle()
|
452
|
-
|
453
|
-
false
|
454
|
-
|
455
|
-
```
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
⑥【⑤を受けて出力されたcoffee】
|
460
|
-
|
461
|
-
```CoffeeScript
|
462
|
-
|
463
|
-
$(document).ready(function() {
|
464
|
-
|
465
|
-
var ellipsestext, lesstext, moretext, showChar;
|
466
|
-
|
467
|
-
showChar = 100;
|
468
|
-
|
469
|
-
ellipsestext = "...";
|
470
|
-
|
471
|
-
moretext = "more";
|
472
|
-
|
473
|
-
lesstext = "less"; ←⑤でreturnをjsコードで追加したことで、coffeeではreturnが消えました。
|
474
|
-
|
475
|
-
});
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
$('.more').each(function() {
|
480
|
-
|
481
|
-
var c, content, h, html;
|
482
|
-
|
483
|
-
content = $(trim).$(this).html();
|
484
|
-
|
485
|
-
if (content.length > showChar) {
|
486
|
-
|
487
|
-
c = content.substr(0, showChar);
|
488
|
-
|
489
|
-
h = content.substr(showChar, content.length - showChar);
|
490
|
-
|
491
|
-
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
492
|
-
|
493
|
-
$(this).html(html);
|
494
|
-
|
495
|
-
}
|
496
|
-
|
497
|
-
});
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
$(".morelink").click(function() {
|
502
|
-
|
503
|
-
if ($(this).hasClass("less")) {
|
504
|
-
|
505
|
-
$(this).removeClass("less");
|
506
|
-
|
507
|
-
$(this).html(moretext);
|
508
|
-
|
509
|
-
} else {
|
510
|
-
|
511
|
-
$(this).addClass("less");
|
512
|
-
|
513
|
-
$(this).html(lesstext);
|
514
|
-
|
515
|
-
}
|
516
|
-
|
517
|
-
$(this).parent().prev().toggle();
|
518
|
-
|
519
|
-
$(this).prev().toggle();
|
520
|
-
|
521
|
-
return false;
|
522
|
-
|
523
|
-
});
|
524
|
-
|
525
|
-
```
|
523
|
+
});
|
524
|
+
|
525
|
+
```
|
8
情報修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -78,7 +78,7 @@
|
|
78
78
|
|
79
79
|
①【元のjsコード】
|
80
80
|
|
81
|
-
```
|
81
|
+
```JavaScript
|
82
82
|
|
83
83
|
$(document).ready(function() {
|
84
84
|
|
@@ -154,7 +154,7 @@
|
|
154
154
|
|
155
155
|
|
156
156
|
|
157
|
-
```
|
157
|
+
```Javascript
|
158
158
|
|
159
159
|
$(document).ready ->
|
160
160
|
|
@@ -228,7 +228,9 @@
|
|
228
228
|
|
229
229
|
③【http://coffeescript.org/で確かめて出力されたコード】
|
230
230
|
|
231
|
+
|
232
|
+
|
231
|
-
```
|
233
|
+
```CoffeeScript
|
232
234
|
|
233
235
|
$(document).ready(function() {
|
234
236
|
|
@@ -388,7 +390,7 @@
|
|
388
390
|
|
389
391
|
⑤【元のコードを修正したjsコード】
|
390
392
|
|
391
|
-
```
|
393
|
+
```JavaScript
|
392
394
|
|
393
395
|
$(document).ready ->
|
394
396
|
|
@@ -456,7 +458,7 @@
|
|
456
458
|
|
457
459
|
⑥【⑤を受けて出力されたcoffee】
|
458
460
|
|
459
|
-
```
|
461
|
+
```CoffeeScript
|
460
462
|
|
461
463
|
$(document).ready(function() {
|
462
464
|
|
7
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -322,7 +322,55 @@
|
|
322
322
|
|
323
323
|
moretext = "more";
|
324
324
|
|
325
|
-
return lesstext = "less";←returnが
|
325
|
+
return lesstext = "less"; ←returnが入ってしまっている(①のコードとは違う)
|
326
|
+
|
327
|
+
});
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
$('.more').each(function() {
|
332
|
+
|
333
|
+
var c, content, h, html;
|
334
|
+
|
335
|
+
content = $(trim).$(this).html();
|
336
|
+
|
337
|
+
if (content.length > showChar) {
|
338
|
+
|
339
|
+
c = content.substr(0, showChar);
|
340
|
+
|
341
|
+
h = content.substr(showChar, content.length - showChar);
|
342
|
+
|
343
|
+
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
344
|
+
|
345
|
+
$(this).html(html);
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
});
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
$(".morelink").click(function() {
|
354
|
+
|
355
|
+
if ($(this).hasClass("less")) {
|
356
|
+
|
357
|
+
$(this).removeClass("less");
|
358
|
+
|
359
|
+
$(this).html(moretext);
|
360
|
+
|
361
|
+
} else {
|
362
|
+
|
363
|
+
$(this).addClass("less");
|
364
|
+
|
365
|
+
$(this).html(lesstext);
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
$(this).parent().prev().toggle();
|
370
|
+
|
371
|
+
$(this).prev().toggle();
|
372
|
+
|
373
|
+
return false;
|
326
374
|
|
327
375
|
});
|
328
376
|
|
@@ -352,7 +400,55 @@
|
|
352
400
|
|
353
401
|
lesstext = "less"
|
354
402
|
|
355
|
-
return ←
|
403
|
+
return ←④のreturnを
|
404
|
+
|
405
|
+
消すためにreturnを追加
|
406
|
+
|
407
|
+
$('.more').each ->
|
408
|
+
|
409
|
+
content = $(trim).$(this).html()
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
if content.length > showChar
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
c = content.substr 0, showChar
|
418
|
+
|
419
|
+
h = content.substr showChar, content.length - showChar
|
420
|
+
|
421
|
+
html = c + '<span class="moreellipses">' + ellipsestext+ ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>'
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
$(this).html html
|
426
|
+
|
427
|
+
return
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
$(".morelink").click ->
|
432
|
+
|
433
|
+
if $(this).hasClass "less"
|
434
|
+
|
435
|
+
$(this).removeClass "less"
|
436
|
+
|
437
|
+
$(this).html moretext
|
438
|
+
|
439
|
+
else
|
440
|
+
|
441
|
+
$(this).addClass "less"
|
442
|
+
|
443
|
+
$(this).html lesstext
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
$(this).parent().prev().toggle()
|
448
|
+
|
449
|
+
$(this).prev().toggle()
|
450
|
+
|
451
|
+
false
|
356
452
|
|
357
453
|
```
|
358
454
|
|
@@ -372,8 +468,56 @@
|
|
372
468
|
|
373
469
|
moretext = "more";
|
374
470
|
|
375
|
-
lesstext = "less"; ←returnが消えた。
|
471
|
+
lesstext = "less"; ←⑤でreturnをjsコードで追加したことで、coffeeではreturnが消えました。
|
472
|
+
|
376
|
-
|
473
|
+
});
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
$('.more').each(function() {
|
478
|
+
|
479
|
+
var c, content, h, html;
|
480
|
+
|
481
|
+
content = $(trim).$(this).html();
|
482
|
+
|
377
|
-
|
483
|
+
if (content.length > showChar) {
|
484
|
+
|
378
|
-
|
485
|
+
c = content.substr(0, showChar);
|
486
|
+
|
487
|
+
h = content.substr(showChar, content.length - showChar);
|
488
|
+
|
489
|
+
html = c + '<span class="moreellipses">' + ellipsestext + ' </span><span class="morecontent"><span>' + h + '</span> <a href="" class="morelink">' + moretext + '</a></span>';
|
490
|
+
|
491
|
+
$(this).html(html);
|
492
|
+
|
493
|
+
}
|
494
|
+
|
495
|
+
});
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
$(".morelink").click(function() {
|
500
|
+
|
501
|
+
if ($(this).hasClass("less")) {
|
502
|
+
|
503
|
+
$(this).removeClass("less");
|
504
|
+
|
505
|
+
$(this).html(moretext);
|
506
|
+
|
507
|
+
} else {
|
508
|
+
|
509
|
+
$(this).addClass("less");
|
510
|
+
|
511
|
+
$(this).html(lesstext);
|
512
|
+
|
513
|
+
}
|
514
|
+
|
515
|
+
$(this).parent().prev().toggle();
|
516
|
+
|
517
|
+
$(this).prev().toggle();
|
518
|
+
|
519
|
+
return false;
|
520
|
+
|
521
|
+
});
|
522
|
+
|
379
|
-
```
|
523
|
+
```
|
6
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -301,3 +301,79 @@
|
|
301
301
|
|
302
302
|
|
303
303
|
何卒、ご助言お願い致します。
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
###情報追加部分
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
④【当初http://coffeescript.org/で出力されたコードの一部】
|
312
|
+
|
313
|
+
```coffeescript
|
314
|
+
|
315
|
+
$(document).ready(function() {
|
316
|
+
|
317
|
+
var ellipsestext, lesstext, moretext, showChar;
|
318
|
+
|
319
|
+
showChar = 100;
|
320
|
+
|
321
|
+
ellipsestext = "...";
|
322
|
+
|
323
|
+
moretext = "more";
|
324
|
+
|
325
|
+
return lesstext = "less";←returnがへんな位置に発生している
|
326
|
+
|
327
|
+
});
|
328
|
+
|
329
|
+
```
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
これに対応するため、
|
334
|
+
|
335
|
+
lesstextの下にreturnを追加。
|
336
|
+
|
337
|
+
(明示的にreturnを指定すれば、予期しないところでreturnが発生することを防げるから。←たぶん、僕の誤解だと思います…しかしとりあえず試しました。)
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
⑤【元のコードを修正したjsコード】
|
342
|
+
|
343
|
+
```
|
344
|
+
|
345
|
+
$(document).ready ->
|
346
|
+
|
347
|
+
showChar = 100
|
348
|
+
|
349
|
+
ellipsestext = "..."
|
350
|
+
|
351
|
+
moretext = "more"
|
352
|
+
|
353
|
+
lesstext = "less"
|
354
|
+
|
355
|
+
return ←追加
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
⑥【⑤を受けて出力されたcoffee】
|
362
|
+
|
363
|
+
```
|
364
|
+
|
365
|
+
$(document).ready(function() {
|
366
|
+
|
367
|
+
var ellipsestext, lesstext, moretext, showChar;
|
368
|
+
|
369
|
+
showChar = 100;
|
370
|
+
|
371
|
+
ellipsestext = "...";
|
372
|
+
|
373
|
+
moretext = "more";
|
374
|
+
|
375
|
+
lesstext = "less"; ←returnが消えた。
|
376
|
+
|
377
|
+
});←すいません。最初のコードにはありませんでした。見逃してました。
|
378
|
+
|
379
|
+
```
|
5
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
私がフォローしている方々でcoffeescriptタグを持つ人にリクエストを送りました!
|
2
|
+
|
3
|
+
|
4
|
+
|
1
5
|
###前提・実現したいこと
|
2
6
|
|
3
7
|
処理速度、コードの複雑化を改善するためにjavascriptをcoffeescriptへ移行したい。
|
4
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -293,3 +293,7 @@
|
|
293
293
|
}); ←下にもう一つ});が入るはず。
|
294
294
|
|
295
295
|
```
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
何卒、ご助言お願い致します。
|
3
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
①【元のjsコード】
|
68
68
|
|
69
|
-
②【私が
|
69
|
+
②【私がjsをcoffeeへ移すために文法を修正したコード】
|
70
70
|
|
71
71
|
③【http://coffeescript.org/で確かめて出力されたコード】
|
72
72
|
|
@@ -146,7 +146,7 @@
|
|
146
146
|
|
147
147
|
|
148
148
|
|
149
|
-
②【私が
|
149
|
+
②【私がjsをcoffeeへ移すために文法を修正したコード】
|
150
150
|
|
151
151
|
|
152
152
|
|
2
情報削除
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
で、一字一句確認したのですが、1点だけどうしてもうまくいきません。
|
56
56
|
|
57
|
-
・
|
57
|
+
・元のjavascriptコードよりも});が一つ少ない。
|
58
58
|
|
59
59
|
|
60
60
|
|
1
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,9 @@
|
|
12
12
|
|
13
13
|
・同様のコードを書いているために無駄が多く見にくい。
|
14
14
|
|
15
|
-
・(これはご指摘を受けたのですが、)
|
15
|
+
・(これはご指摘を受けたのですが、)jsとrailsの接続をするという二度手間が生じる。
|
16
|
+
|
17
|
+
|
16
18
|
|
17
19
|
という問題がありますので、jsコードをcoffeeに移行しようと考えました。
|
18
20
|
|