-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
3011 lines (2885 loc) · 145 KB
/
index.html
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original slides: Marcin Wichary ([email protected])
Modifications: Chrome DevRel Team ([email protected])
Alex Russell ([email protected])
Brad Neuberg
-->
<html manifest="cache.appcache">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
<title>
HTML5 Presentation
</title>
<link href="http://fonts.googleapis.com/css?family=Droid+Sans|Droid+Sans+Mono" rel="stylesheet" type="text/css">
<link id="prettify-link" href="src/prettify/prettify.css" rel="stylesheet" disabled type="text/css">
<link href="styles/fonts.css" rel="stylesheet" type="text/css" media="screen">
<link href="styles/presentation.css" rel="stylesheet" type="text/css" media="screen">
<link href="styles/common.css" rel="stylesheet" type="text/css" media="screen">
<link class="theme" href="styles/default.css" rel="stylesheet" type="text/css" media="screen">
<link class="theme" href="styles/moon.css" rel="stylesheet" type="text/css" media="screen">
<link class="theme" href="styles/sand.css" rel="stylesheet" type="text/css" media="screen">
<link class="theme" href="styles/sea_wave.css" rel="stylesheet" type="text/css" media="screen">
<style type="text/css">
#quota-api table {
width: 100%;
border-collapse: collapse;
margin-top: 40px;
}
#quota-api th {
font-weight: 600;
text-align: left;
}
#quota-api td,
#quota-api th {
border: 1px solid #222;
padding: 5px 10px;
vertical-align: top;
}
.quota-info-bubble {
background-color: #FCFCE4;
border: 1px solid yellow;
font-size: 80%;
padding: 5px;
}
.quota-info-bubble input, .quota-info-bubble button {
font-size: 12px;
}
.quota-info-bubble span {
display: block;
}
</style>
<style type="text/css" media="screen">
#form-types-mobile div {
float: left;
width: 24%;
padding-right: 1%;
text-align: center;
}
#form-types-mobile img {
width: 90%;
-webkit-box-shadow: rgba(0, 0, 0, 0.3) 0 4px 6px;
}
</style>
<style type="text/css">
#video-column {
float: left;
width: 50%;
margin-top: 20px;
}
#reflection-button {
margin: 20px 0;
}
#track-column {
float: left;
width: 45%;
margin-top: 20px;
}
</style>
<style type="text/css">
:-webkit-full-screen {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
box-sizing: border-box;
margin: 0;
width: 100%;
height: 100%;
}
:-webkit-full-screen-ancestor:root {
overflow: hidden;
}
:-webkit-full-screen-ancestor {
z-index: auto;
opacity: 1;
mask: none;
clip: auto;
filter: none;
-webkit-transform: none;
-webkit-transition: none;
}
pre:-webkit-full-screen {
background-color: white;
}
pre:-webkit-full-screen:after {
content: 'Only one element can be targeted for full screen';
}
.tohide {
display: none;
}
:-webkit-full-screen .tohide {
display: block;
}
</style>
<style type="text/css">
/* put the keyframes rule here cuz ExCss currently doesn't support '@-webkit-keyframes' */
@-webkit-keyframes pulse {
from {
opacity: 0.0;
font-size: 50px;
}
to {
opacity: 1.0;
font-size: 100px;
}
}
#animation-example {
-webkit-animation-name: pulse;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: ease-in-out;
-webkit-animation-direction: alternate;
}
</style>
</head>
<body>
<div id="flex-container">
<nav id="helpers">
<button title="Previous slide" id="nav-prev" class="nav-prev">⇽</button> <button title="Jump to a random slide" id="slide-no">5</button> <button title="Next slide" id="nav-next" class="nav-next">⇾</button>
<ul>
<li style="list-style: none">
<button type="checkbox" data-command="toc" title="Table of Contents" class="toc">TOC</button> <!-- <button type="checkbox" data-command="resources" title="View Related Resources">☆</button> -->
<button type="checkbox" data-command="notes" title="View Slide Notes">✏</button> <button type="checkbox" data-command="source" title="View slide source">↻</button> <button type="checkbox" data-command="help" title="View Help">?</button>
</li>
</ul>
</nav>
<div class="slides">
<div id="presentation-counter">
Loading...
</div>
<div class="slide" id="landing-slide">
<section class="middle">
<p>
This presentation is an HTML5 website
</p>
<p>
Press <span id="left-init-key" class="key">→</span> key to advance.
</p>
<p id="disclaimer-message">
Having issues seeing the presentation? Read the <a href="disclaimer.html">disclaimer</a>
</p>
</section>
<aside class="note">
<section>
Welcome! (This field is for speaker notes and commentary.)
</section>
</aside>
</div>
<div class="slide" id="controls-slide">
<header>
Slides controls
</header>
<section>
<ul>
<li>
<span class="key">←</span> and <span class="key">→</span> to move around.
</li>
<li>
<span class="key">Ctrl/Command</span> and <span class="key">+</span> or <span class="key">-</span> to zoom in and out if slides don’t fit.
</li>
<li>
<span class="key">S</span> to view page source.
</li>
<li>
<span class="key">T</span> to change the theme.
</li>
<li>
<span class="key">H</span> to toggle syntax highlight.
</li>
<li>
<span class="key">N</span> to toggle speaker notes.
</li>
<li>
<span class="key">3</span> to toggle 3D effect.
</li>
<li>
<span class="key">0</span> to toggle help.
</li>
</ul>
</section>
</div>
<div class="slide" id="title-slide">
<section class="middle">
<hgroup>
<h1>
HTML5*
</h1>
<h2>
Web Development to the next level
</h2>
</hgroup>
<p>
*Including other next generation technologies of the Web Development stack
</p>
</section>
</div>
<div class="slide" id="commonoperation-slide">
<header>
<h2>PHP 中的常用操作</h2>
</header>
<section>
<ul id="timeline">
<li data-auto="">
<span class="year">String</span> <span class="html">字符串操作</span>
</li>
<li style="list-style: none">
<br>
</li>
<li data-auto="">
<span class="year">Array</span> <span class="js">数组操作</span>
</li>
<li style="list-style: none">
<br>
</li>
<li>
<span class="year"><em class="stroke">Date</em></span><span class="js">Date</span> + <span class="css">Time</span>
</li>
</ul>
</section>
</div>
<div class="slide" id="php-string">
<header>
判断字符串为空
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Undefined</th>
<th>Null</th>
<th>False</th>
<th>Empty string</th>
<th>String "0"</th>
<th>String "1"</th>
<th>Long string</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>if (!$var)</code></td><td>4 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>>0 ms</td><td>>0 ms</td><td>7 ms</td><td class="incomplete">219</td></tr><tr><td><code>if (empty($var))</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>>0 ms</td><td>1 ms</td><td>5 ms</td><td class="almost">147</td></tr><tr><td><code>if ($var == "")</code></td><td>4 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>40 ms</td><td>48 ms</td><td class="buggy">1432</td></tr><tr><td><code>if ("" == $var)</code></td><td>2 ms</td><td>>0 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>>0 ms</td><td>6 ms</td><td class="almost">176</td></tr><tr><td><code>if ($var === "")</code></td><td>2 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>3 ms</td><td class="yes">100</td></tr><tr><td><code>if ("" === $var)</code></td><td>2 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>4 ms</td><td class="almost">112</td></tr><tr><td><code>if (strcmp($var, "") == 0)</code></td><td>4 ms</td><td>2 ms</td><td>2 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>12 ms</td><td class="incomplete">346</td></tr><tr><td><code>if (strcmp("", $var) == 0)</code></td><td>4 ms</td><td>2 ms</td><td>2 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>12 ms</td><td class="incomplete">352</td></tr><tr><td><code>if (strlen($var) == 0)</code></td><td>3 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>9 ms</td><td class="incomplete">271</td></tr><tr><td><code>if (!strlen($var))</code></td><td>3 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>9 ms</td><td class="incomplete">257</td></tr></tbody>
</table>
</section>
<section>
判断字符为空的最快方式就是 if($str === ""),当然这限定了类型。字符串为空的边界情况。$str=0,$str='0',这类边界情况最好是用empty($str),这种情况返回真;
empty() 有一个好处是对undefined 变量不会引发error。
</section>
</div>
<div class="slide" id="phpstring-compare">
<header>
判断字符串的相等
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Equal</th>
<th>First character not equal</th>
<th>Last character not equal</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>$a == $b</code></td><td>2 ms</td><td>1 ms</td><td>2 ms</td><td>6 ms</td><td class="yes">100</td></tr><tr><td><code>!strcmp($a, $b)</code></td><td>4 ms</td><td>3 ms</td><td>4 ms</td><td>11 ms</td><td class="almost">194</td></tr><tr><td><code>strcmp($a, $b) == 0</code></td><td>4 ms</td><td>3 ms</td><td>4 ms</td><td>11 ms</td><td class="almost">197</td></tr><tr><td><code>strcmp($a, $b) === 0</code></td><td>4 ms</td><td>3 ms</td><td>4 ms</td><td>11 ms</td><td class="almost">189</td></tr><tr><td><code>strcasecmp($a, $b) === 0</code></td><td>9 ms</td><td>3 ms</td><td>9 ms</td><td>21 ms</td><td class="incomplete">382</td></tr></tbody></table>
</section>
<section>
if($a == $b); 最佳方式
</section>
</div>
<div class="slide" id="phpstring-find">
<header>
<h1>
字符串查找
</h1>
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Not found</th>
<th>Found at the start</th>
<th>Found in the middle</th>
<th>Found at the end</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>strstr($haystack, $needle)</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>4 ms</td><td class="yes">100</td></tr><tr><td><code>strpos($haystack, $needle) !== false</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>4 ms</td><td class="almost">103</td></tr><tr><td><code>strstr($haystack, $needle) !== false</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>4 ms</td><td class="almost">109</td></tr><tr><td><code>stristr($haystack, $needle)</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>8 ms</td><td class="almost">198</td></tr><tr><td><code>preg_match("/$needle/", $haystack)</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>8 ms</td><td class="almost">194</td></tr><tr><td><code>preg_match("/$needle/i", $haystack)</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>8 ms</td><td class="almost">196</td></tr><tr><td><code>preg_match("/$needle/S", $haystack)</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>8 ms</td><td class="almost">190</td></tr><tr><td><code>ereg($needle, $haystack)</code></td><td>2 ms</td><td>2 ms</td><td>9 ms</td><td>17 ms</td><td>30 ms</td><td class="buggy">745</td></tr></tbody>
</table>
</section>
<section>
strstr($haystack,$needle),strpos($haystack,$needle)!==false 最佳方案
</section>
</div>
<div class="slide offline-storage" id="phpstring-start">
<header>
判断字符串是否以另一个字符串开始
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Not found</th>
<th>Found at the start</th>
<th>Found in the middle</th>
<th>Found at the end</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>strncmp($haystack, $needle, strlen($needle)) === 0</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>6 ms</td><td class="almost">155</td></tr><tr><td><code>strncmp($haystack, "Test", 4) === 0</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>4 ms</td><td class="almost">101</td></tr><tr><td><code>strncasecmp($haystack, $needle, strlen($needle)) === 0</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>6 ms</td><td class="almost">170</td></tr><tr><td><code>strpos($haystack, $needle) === 0</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>4 ms</td><td class="yes">100</td></tr><tr><td><code>substr($haystack, 0, strlen($needle)) === $needle</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>6 ms</td><td class="almost">170</td></tr><tr><td><code>strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>9 ms</td><td class="incomplete">242</td></tr><tr><td><code>preg_match("/^" . preg_quote($needle, "/") . "/", $haystack)</code></td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>12 ms</td><td class="incomplete">325</td></tr></tbody>
</table>
</section>
<section>
strpos($haystack, $needle) === 0 是最佳的方式
</section>
</div>
<div class="slide offline-storage" id="phpstring-end">
<header>
判断字符串的结束标记
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Not found</th>
<th>Found at the start</th>
<th>Found in the middle</th>
<th>Found at the end</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>substr($haystack, strlen($haystack) - strlen($needle)) === $needle</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>8 ms</td><td class="almost">125</td></tr><tr><td><code>substr($haystack, -strlen($needle)) === $needle</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>6 ms</td><td class="yes">100</td></tr><tr><td><code>strcmp(substr($haystack, -strlen($needle)), $needle) === 0</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>9 ms</td><td class="almost">140</td></tr><tr><td><code>preg_match("/" . preg_quote($needle, "/") . "$/", $haystack)</code></td><td>3 ms</td><td>4 ms</td><td>4 ms</td><td>4 ms</td><td>14 ms</td><td class="incomplete">223</td></tr></tbody>
</table>
</section>
<section>
substr($haystack, -strlen($needle)) === $needle 最佳方式
</section>
</div>
<div class="slide offline-storage" id="phpstring-replace">
<header>
字符串替换
</header>
<section>
<table>
<tbody><tr>
<th>Method</th>
<th>Not found</th>
<th>Found at the start</th>
<th>Found in the middle</th>
<th>Found at the end</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>str_replace($search, $replace, $subject)</code></td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>2 ms</td><td>7 ms</td><td class="yes">100</td></tr><tr><td><code>preg_replace("/$search/", $replace, $subject)</code></td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>13 ms</td><td class="almost">177</td></tr><tr><td><code>preg_replace("/$search/S", $replace, $subject)</code></td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>3 ms</td><td>13 ms</td><td class="almost">174</td></tr><tr><td><code>ereg_replace($search, $replace, $subject)</code></td><td>3 ms</td><td>6 ms</td><td>12 ms</td><td>19 ms</td><td>40 ms</td><td class="buggy">556</td></tr><tr><td><code>strtr($subject, $array)</code></td><td>13 ms</td><td>12 ms</td><td>13 ms</td><td>12 ms</td><td>50 ms</td><td class="buggy">695</td></tr></tbody>
</table>
</section>
<section>
str_replace($search, $replace, $subject) 为最佳方案
</section>
</div>
<div class="slide offline-storage" id="phpstring-trim">
<header>
修剪字符串两端
</header>
<section class="appcache-examples">
<table>
<tbody><tr>
<th>Method</th>
<th>Not found</th>
<th>Found at start</th>
<th>Found at end</th>
<th>Found at both sides</th>
<th>Summary</th>
<th>Index</th>
</tr>
<tr><td><code>trim($string, ",")</code></td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>1 ms</td><td class="yes">100</td></tr><tr><td><code>preg_replace('/^,*|,*$/', "", $string)</code></td><td>7 ms</td><td>7 ms</td><td>7 ms</td><td>7 ms</td><td>29 ms</td><td class="buggy">3616</td></tr><tr><td><code>preg_replace('/^,*|,*$/m', "", $string)</code></td><td>12 ms</td><td>12 ms</td><td>12 ms</td><td>12 ms</td><td>47 ms</td><td class="no">5928</td></tr><tr><td><code>preg_replace('/^,+|,+$/', "", $string)</code></td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>2 ms</td><td class="incomplete">228</td></tr><tr><td><code>preg_replace('/^,+|,+$/m', "", $string)</code></td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>>0 ms</td><td>2 ms</td><td class="incomplete">224</td></tr><tr><td><code>preg_replace('/^,+/', "", preg_replace('/,+$/', "", …))</code></td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>1 ms</td><td>3 ms</td><td class="incomplete">376</td></tr></tbody>
</table>
</section>
<section>
trim($string, ",") 为最佳方案
</section>
</div>
<div class="slide offline-storage" id="quota-api">
<header>
<span class="js">JS</span>
<h1>
Quota API
</h1>
</header>
<section>
<pre style="font-size: 80%">
// Request Status
<b>webkitStorageInfo</b>.<b>queryUsageAndQuota</b>(webkitStorageInfo.TEMPORARY, function(used, remaining) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
}
);
// Request Quota (only for File System API)
<b>webkitStorageInfo</b>.<b>requestQuota</b>(webkitStorageInfo.PERSISTENT, 10 * 1024 * 1024, function(used) {
console.log("Used quota: " + used + ", remaining quota: " + remaining);
}
);
</pre>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<th></th>
<th>
Default (Temporary)
</th>
<th>
Quota Requested (Persistent)
</th>
</tr>
<tr>
<td>
Web Storage
</td>
<td>
5Mb
</td>
<td rowspan="4">
N/A
</td>
</tr>
<tr>
<td>
App Cache
</td>
<td rowspan="4">
10% of available disk in total
<div class="quota-info-bubble">
<button id="temp-query">Show Usage</button><span>Used:</span>
<output>
<span>--</span>
</output><span>Bytes</span><span>Remaining:</span>
<output>
<span>--</span>
</output><span>Bytes</span>
</div>
</td>
</tr>
<tr>
<td>
IndexedDB
</td>
</tr>
<tr>
<td>
WebSQL
</td>
</tr>
<tr>
<td>
File System API
</td>
<td>
Arbitrary
<div class="quota-info-bubble">
<input id="requested-quota" type="text" placeholder="Request quota amount..."> in Bytes <button id="perm-request" style="margin-left: 5px">Request Quota</button><span>Used:</span>
<output>
<span>--</span>
</output><span>Bytes</span>
</div>
</td>
</tr>
</table>
</section><script type="text/javascript">
(function() {
var outputs = document.querySelectorAll('#quota-api output');
document.querySelector('#temp-query').addEventListener(
'click', function() {
webkitStorageInfo.queryUsageAndQuota(
webkitStorageInfo.TEMPORARY,
function(used, remaining) {
outputs[0].textContent = used;
outputs[1].textContent = remaining;
}, function(error) { alert(error) });
}, false);
document.querySelector('#perm-request').addEventListener(
'click', function() {
webkitStorageInfo.requestQuota(
webkitStorageInfo.PERSISTENT,
document.querySelector('#requested-quota').value,
function(used) {
outputs[2].textContent = used;
}, function(error) { alert(error) });
}, false);
}())
</script>
</div>
<div class="slide transitionSlide" id="realtime-title">
<section class="middle">
<h2>
Realtime / Communication
</h2>
<p>
Stay connected
</p><img src="http://www.html5rocks.com/static/images/identity/classes_64/HTML5_Connectivity_64.png" title="HTML5 Realtime & Communication" alt="HTML5 Realtime & Communication">
</section>
</div>
<div class="slide realtime-communication" id="web-workers">
<header>
<span class="js">JS</span>
<h1>
Web Workers
</h1>
</header>
<section>
main.js:
<pre>
var worker = new <b>Worker</b>('task.js');
worker.<b>onmessage</b> = function(event) { alert(event.data); };
worker.<b>postMessage</b>('data');
</pre>task.js:
<pre>
self.<b>onmessage</b> = function(event) {
// Do some work.
self.<b>postMessage</b>("recv'd: " + event.data);
};
</pre>
<div id="w-wrapper">
<div id="wmap" class="gmap example">
<img src="http://maps.google.com/maps/api/staticmap?center=13,13&zoom=3&size=680x200&sensor=false">
</div>
<div style="margin-top:5px">
<button id="find-route-y">Find route with Workers</button> <button id="find-route-n">Find route without Workers</button>
<p id="w-loading">
Loading Route...
</p>
</div>
<p style="font-size: 90%;" class="center">
Try dragging the map while the complex route is being calculated (you will only be able to do that with Workers!)
</p>
</div><script src="src/webworkers/points.js" defer type="text/javascript">
</script> <script src="src/webworkers/annealing.js" defer type="text/javascript">
</script> <script defer type="text/javascript">
(function() {
var markersArray = [];
var map = null;
var useThreads = false;
document.querySelector('#w-wrapper').addEventListener('click', function(event) {
if (!map) {
map = new google.maps.Map(document.querySelector('#wmap'), {
zoom: 3,
center: new google.maps.LatLng(13, 13),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
map.getDiv().style.border = '1px solid #ccc';
drawPoints();
}
if (event.target.id == 'find-route-y') {
useThreads = true;
document.querySelector('#w-loading').style.visibility = 'visible';
test();
} else if (event.target.id == 'find-route-n'){
useThreads = false;
document.querySelector('#w-loading').style.visibility = 'visible';
// this setTimout is so that we see the 'loading' label
setTimeout(function() { test(); }, 10);
}
}, false);
function drawPath(path) {
var firstPoint = true;
var l = p1.length;
var scaleFactor = 5;
for (var i = 0; i < l - 1; ++i) {
var points = [
new google.maps.LatLng(p1[i].x / scaleFactor,
p1[i].y / scaleFactor),
new google.maps.LatLng(p1[i + 1].x / scaleFactor,
p1[i + 1].y / scaleFactor)
];
var polyline = new google.maps.Polyline(
{path: points, strokeColor: '#ff0000', strokeWeight: 1});
markersArray.push(polyline);
polyline.setMap(map);
}
}
function drawPoints() {
var blueIcon = new google.maps.MarkerImage(
'src/webworkers/point.png',
new google.maps.Size(3, 3), // size
new google.maps.Point(0, 0), // origin
new google.maps.Point(0, 0)); // anchor
for (var i = 0; i < p1.length; ++i) {
// Render in Gmap instead of canvas
var point = new google.maps.LatLng(p1[i].x / 5, p1[i].y / 5);
var marker = new google.maps.Marker({
position: point, icon: blueIcon, map: map});
markersArray.push(marker);
}
}
function deleteOverlays() {
if (markersArray) {
for (var i in markersArray) {
markersArray[i].setMap(null);
}
markersArray = [];
}
}
function test() {
var name = "Test 1";
var self = this;
deleteOverlays();
drawPoints();
setTimeout(function() {
var opts = {
points: p1,
t0: 1,
g: 0.99,
stepsPerT: 10
};
var callback = {
name: name,
newMin: function(p) {
},
draw: function(p) {
document.querySelector('#w-loading').style.visibility = 'hidden';
drawPath(p);
}
};
var a;
if (useThreads) {
var worker = new Worker('src/webworkers/Worker.js')
worker.onmessage = function(event) {
var returnedData = JSON.parse(event.data);
var msg = returnedData[0];
var p = returnedData[1];
callback[msg](p);
};
worker.onerror = function(event) {
console.log(event);
};
worker.postMessage(JSON.stringify({
opts: opts,
width: 200,
height: 200
}));
} else {
var annealing = new Annealing();
var callback2 = {
onNewMin: function(p) {
// postMessage('newmin')
},
onDone: function(p) {
document.querySelector('#w-loading').style.visibility = 'hidden';
drawPath(p);
}
};
annealing.init(opts, opts.width, opts.height, callback2);
annealing.go();
}
}, 10);
}
})();
</script>
</section>
</div>
<div class="slide realtime-communication" id="web-sockets">
<header>
<span class="js">JS</span>
<h1>
WebSocket
</h1>
</header>
<section>
<pre>
var socket = new <b>WebSocket</b>('ws://html5rocks.websocket.org/echo');
socket.<b>onopen</b> = function(event) {
socket.<b>send</b>('Hello, WebSocket');
};
socket.<b>onmessage</b> = function(event) { alert(event.data); }
socket.<b>onclose</b> = function(event) { alert('closed'); }
</pre>
<p id="websockets-message">
Full-duplex, bi-directional communication over the Web: Both the server and client can send data at any time, or even at the same time. Only the data itself is sent, without the overhead of HTTP headers, dramatically reducing bandwidth.
</p>
<div id="ws-left">
Use the echo demo below to test a WebSocket connection from your browser. Both the message you send and the response you receive travel over the same WebSocket connection.
<div id="ws-config-location">
<h4>
Location:
</h4><input type="text" id="wsUri" disabled><br>
<input type="checkbox" id="wsSecureCb" onclick="wsToggleTls();" disabled> <label id="wsSecureCbLabel" for="wsSecureCb">Use secure WebSocket (TLS/SSL)</label><br>
<button id="wsConnectBut" disabled>Connect</button> <button id="wsDisconnectBut" disabled>Disconnect</button>
</div>
<div id="ws-config-message">
<h4>
Message:
</h4><input type="text" id="wsMessage" value="Hello, WebSocket" disabled> <button id="wsSendBut" disabled>Send</button>
</div>
</div>
<div id="ws-right">
<div id="ws-log">
<strong>Output:</strong>
<div id="wsConsoleLog"></div><button id="wsClearLogBut">Clear log</button>
</div>
</div>
<div id="ws-powered">
Demo powered by <a href="http://kaazing.com" target="_blank"><img id="wsKaazingLogo" src="src/websocket/kaazing-logo_99x16.png" width="99" height="16" alt="Powered by Kaazing"></a>
</div>
</section><script src="src/websocket/websocket.js" defer type="text/javascript">
</script>
</div>
<div class="slide realtime-communication" id="notifications-api">
<header>
<span class="js">JS</span>
<h1>
Notifications
</h1>
</header>
<section>
<pre>
if (window.<b>webkitNotifications</b>.<b>checkPermission</b>() == 0) {
// you can pass any url as a parameter
window.<b>webkitNotifications</b>.<b>createNotification</b>(tweet.picture, tweet.title,
tweet.text).<b>show</b>();
} else {
window.<b>webkitNotifications</b>.<b>requestPermission</b>();
}
</pre>
<div id="notifications-message">
<p>
<button id="request-permission" href="#">Set notification permissions for this page</button>
</p>
<p>
Note: Use this button if you also want to <em>reset</em> the permissions
</p><br>
<p>
Enter your twitter user name to show your last tweet as a notification
</p><input type="text" id="username" placeholder="username"> <button id="show-tweets">Show tweet notifications</button>
</div><script defer type="text/javascript">
document.getElementById('request-permission').addEventListener('click', function() {
window.webkitNotifications.requestPermission();
}, false);
document.getElementById('show-tweets').addEventListener('click', function() {
readTweets();
}, false);
function readTweets() {
var username = document.getElementById('username').value;
if (username == 'username') {
alert('Enter a username first');
return;
}
var script = document.createElement("script");
script.src = 'http://twitter.com/statuses/user_timeline/'+ username+'.json?count=1&callback=fetchTweets';
document.body.appendChild(script);
}
function fetchTweets(data) {
var tweet;
var i = data.length;
while (i--) {
tweet = data[i];
if (window.webkitNotifications.checkPermission() == 0) {
// note the show()
window.webkitNotifications.createNotification(tweet.user.profile_image_url, tweet.user.name, tweet.text).show();
} else {
// Note that we can't call requestPermission from here as we are in the callback function and not triggered just on user action
alert('You have to click on "Set notification permissions for this page" first to be able to receive notifications.');
return;
}
}
}
</script>
</section>
</div>
<div class="slide transitionSlide" id="hardware-access-title">
<section class="middle">
<h2>
File / Hardware Access
</h2>
<p>
Deeper integration with the Operating System
</p><img src="http://www.html5rocks.com/static/images/identity/classes_64/HTML5_Device_Access_64.png" title="HTML5 Device Access" alt="HTML5 Device Access">
</section>
</div>
<div class="slide device-access" id="native-drag-and-drop">
<header>
<span class="js">JS</span>
<h1>
Native Drag & Drop
</h1>
</header>
<section id="dnd-section">
<pre>
document.addEventListener(<em>'dragstart'</em>, function(event) {
event.<b>dataTransfer.setData</b>('text', 'Customized text');
event.<b>dataTransfer.effectAllowed</b> = 'copy';
}, false);
</pre>
<ol id="drag-zone">
<li>
<img src="src/dwd1.png" draggable="" class="copy">
</li>
<li>
<span class="draggable-text" draggable="">Select text and drag (original text will be dropped)</span>
</li>
<li>
<span draggable="" class="overwrite">Select text and drag (dragged text data will be altered from original)</span>
</li>
</ol>
<div id="drop-data">
Source Data
</div>
<div id="drop-zone">
Drop Area
</div><script defer type="text/javascript">
(function() {
var dragZone = document.querySelector('#drag-zone');
var dropZone = document.querySelector('#drop-zone');
dragZone.addEventListener('dragstart', function(event) {
if (event.target.className) { // img case
event.dataTransfer.effectAllowed = event.target.className;
event.target.style.border = "4px solid #cc3300";
}
else { // text case
if (event.target.parentNode.className == 'overwrite') {
event.dataTransfer.setData("text", "<strong>Overwritten Content</strong>");
}
event.target.parentNode.style.border = "4px solid #cc3300";
}
return true;
}, true);
dragZone.addEventListener('dragend', function(event) {
if (event.target.className) { // img case
event.target.style.border = "4px solid #888";
}
else { // text case
event.target.parentNode.style.border = "4px solid #888";
}
return true;
}, true);
dropZone.addEventListener('dragenter', function(event) {
if (event.preventDefault) event.preventDefault();
event.dataTransfer.dropEffect = 'copy';
this.className = 'hovering';
return false;
}, false);
dropZone.addEventListener('dragover', function(event) {
if (event.preventDefault) event.preventDefault(); // allows us to drop
event.dataTransfer.dropEffect = 'copy';
return false;
}, false);
dropZone.addEventListener('dragleave', function(event) {
if (event.preventDefault) event.preventDefault(); // allows us to drop
this.className = '';
return false;
}, false);
dropZone.addEventListener('drop', function(event) {
if (event.preventDefault) event.preventDefault();
var imgPassed = null;
var dropdata = document.querySelector('#drop-data');
var types = event.dataTransfer.types;
document.querySelector('#drop-data').textContent = '';
this.innerHTML = '';
for (var i = 0; i < types.length; i++) {
if (types[i] == 'Files') {
var files = event.dataTransfer.files;
for (var j = 0; j < files.length; j++) {
dropdata.textContent += 'File Name: '+files[j].fileName;
dropdata.textContent += 'File Size: '+files[j].fileSize;
}
}
else {
if (typeof event.dataTransfer.getData(types[i]) !== 'undefined') {
dropdata.innerHTML += '<p><em class="datatypes">'+types[i]+'</em>: <br />'+event.dataTransfer.getData(types[i]).replace(/</g, '<') + '</p>';
}
}
if (types[i] == 'text/uri-list') {
imgPassed = event.dataTransfer.getData('text/uri-list');
}
}
if (imgPassed) {
var cEl = document.createElement('canvas');
cEl.width = 200;
cEl.height = 100;
var ctx = cEl.getContext('2d');
var img_buffer = document.createElement('img');
img_buffer.src = imgPassed;
img_buffer.style.display = 'none';
document.body.appendChild(img_buffer); // this line only needed in safari
img_buffer.onload = function() { ctx.drawImage(img_buffer,0,0,100,100); }
this.appendChild(cEl);
} else {
if (event.dataTransfer.getData('text')) {
this.innerHTML = event.dataTransfer.getData('text');
}
else if (event.dataTransfer.getData('text/plain')) {
this.innerHTML = event.dataTransfer.getData('text/plain');
}
}
return false;
}, false);
})();
</script>
</section>
</div>
<div class="slide device-access" id="desktop-drag-in">
<header>
<span class="js">JS</span>
<h1>
Desktop Drag-In (File API)
</h1>
</header>
<section>
<h3>
Drag files in from the desktop:
</h3>
<pre>
document.querySelector('#dropzone').addEventListener('drop', function(e) {
var reader = new <b>FileReader</b>();
reader.onload = function(evt) {
document.querySelector('img').src = evt.target.<b>result</b>;
};
reader.<b>readAsDataURL</b>(e.<b>dataTransfer.files[0]</b>);
}, false);
</pre>
<div class="example">
<div id="dropzone" class="vbox boxcenter center">
Drop in images from your desktop
</div>
</div>
<div id="dnd-thumbnails" class="center"></div><script src="src/dnd/dnd-lib.js" defer type="text/javascript">
</script> <script defer type="text/javascript">
window.addEventListener('load', function(e) {
var dndc = new DNDFileController('dropzone', 'dnd-thumbnails');
}, false);
</script>
</section>
</div>
<div class="slide device-access" id="desktop-drag-out">
<header>
<span class="js">JS</span>
<h1>
Desktop Drag-Out
</h1>
</header>
<section id="dnd-section2">
<h3>
Drag files out onto the desktop:
</h3>
<pre>
<a href="src/star.mp3" draggable="true" class="dragout"
data-downloadurl="<b>MIMETYPE:FILENAME:ABSOLUTE_URI_TO_FILE</b>">download</a>
</pre>
<pre>
var files = document.querySelectorAll('.dragout');
for (var i = 0, file; file = files[i]; ++i) {
file.addEventListener('dragstart', function(e) {
e.dataTransfer.setData('DownloadURL', this.dataset.downloadurl);
}, false);