-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
616 lines (523 loc) · 18.3 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Front-End Styleguide</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/prettify.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
<script src="js/prettify.js"></script>
<link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700' rel='stylesheet' type='text/css'>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body onload="prettyPrint()">
<div id="nav-bg"></div>
<div id="nav">
<ul>
<li class="nav-block">
<a href="#global-start">Global Style Rules</a>
<ul class="level2">
<li><a href="#spaces">Spaces vs. Tabs</a></li>
</ul>
</li>
<li class="nav-block">
<a href="#html-start">HTML Style Rules</a>
<ul class="level2">
<li><a href="#formatting">General formatting</a></li>
<li><a href="#caps">Capitalization</a></li>
<li><a href="#whitespace">Trailing whitespace</a></li>
<li><a href="#entities">Entity references</a></li>
</ul>
</li>
<li class="nav-block">
<a href="#css-start">CSS Formatting Rules</a>
<ul class="level2">
<li><a href="#indentation">Block content indentation</a></li>
<li><a href="#commenting">Commenting</a></li>
<li><a href="#order">Declaration order</a></li>
<li><a href="#prefixes">Vendor Prefix Order</a></li>
<li><a href="#name-stops">Property name stops</a></li>
<li><a href="#declaration-stops">Declaration stops</a></li>
<li><a href="#type-selectors">Type selectors</a></li>
<li><a href="#separation">Selector separation</a></li>
<li><a href="#rule-separation">Rule separation</a></li>
<li><a href="#naming">Naming Conventions</a></li>
<li><a href="#hexadecimal">Hexadecimal notation</a></li>
</ul>
</li>
<li class="nav-block">
<a href="#js-start">JavaScript Rules</a>
<ul class="level2">
<li><a href="#semicolons">Semicolons</a></li>
<li><a href="#strict-equals">Always use Strict Equals</a></li>
<li><a href="#js-naming">Naming Conventions</a></li>
</ul>
</li>
</ul>
</div>
<div id="content-wrap">
<div id="content">
<h1>Front-End Developer Styleguide</h1>
<p>This document defines formatting and style rules for HTML, CSS, and JavaScript. It aims at improving code quality and consistency throughout all of our projects. All code in any code-base should look like a single person wrote it, no matter how many people contributed. In order to achieve this, the following coding standards must be followed by all developers here at <strong>melt</strong>media.</p>
<a name="global-start"></a>
<h2>Global Style Rules</h2>
<div class="section first">
<a name="spaces"></a>
<h3>Spaces vs. Tabs</h3>
<p>Always indent by two spaces, never mix tabs with spaces.</p>
<div class="note">
<ul>
<li>For easier diffs</li>
<li>Legacy code uses spaces</li>
<li>Consistency throughout all projects</li>
</ul>
</div>
</div>
<a name="html-start"></a>
<h2>HTML Style Rules</h2>
<div class="section first">
<a name="formatting"></a>
<h3>General formatting</h3>
<p>Use a new line for every block, list, or table element, and indent every such child element. Also, all tags have to be closed.</p>
<div class="note">
<p>Code readability and consistency</p>
</div>
<pre class="prettyprint">
<code>
<blockquote>
<p><em>Space</em>, the final frontier.</p>
</blockquote>
<ul>
<li>Moe</li>
<li>Larry</li>
<li>Curly</li>
</ul>
<table>
<thead>
<tr>
<th scope="col">Income</th>
<th scope="col">Taxes</th>
</tr>
</thead>
<tbody>
<tr>
<td>$ 5.00</td>
<td>$ 4.50</td>
</tr>
</tbody>
</table>
</code></pre>
</div>
<div class="section">
<a name="caps"></a>
<h3>Capitalization</h3>
<p>All Element names, attributes, attribute values, selectors, properties, and property values (with the exception of strings) should be lowercase.</p>
<div class="note">
<p>Consistency throughout all projects</p>
</div>
<pre class="wrong two-line">
<code>
<!-- BAD -->
<A HREF="/">Home</A>
</code>
</pre>
<pre class="correct two-line">
<code>
<!-- GOOD -->
<a href="/">Home</a>
</code></pre>
</div>
<div class="section">
<a name="whitespace"></a>
<h3>Trailing whitespace</h3>
<p>Remove all trailing white spaces inside of html tags. Also, always leave a blank line at the end of your file.</p>
<p><em>Tip: configure your editor to "show invisibles". This will allow you to eliminate end of line whitespace, eliminate unintended blank line whitespace, and avoid polluting commits. Below are links to view instructions for various text editors:</em></p>
<h4>Resources</h4>
<ul>
<li>Sublime Text 2: <a class="arrow" href="#">http://www.tbd.com</a></li>
<li>Textmate: <a class="arrow" href="#">http://www.tbd.com</a></li>
<li>Coda 2: <a class="arrow" href="#">http://www.tbd.com</a></li>
</ul>
<div class="note note-small">
<p>Trailing white spaces can complicate diffs</p>
<span class="icon"></span>
</div>
<pre class="wrong two-line">
<code>
<!-- BAD -->
<p>What? </p>
</code>
</pre>
<pre class="correct two-line">
<code>
<!-- GOOD -->
<p>Yes please.</p>
</code></pre>
</div>
<div class="section">
<a name="entities"></a>
<h3>Entity references</h3>
<p>For all special characters use their numeric character reference.</p>
<h4>Resources</h4>
<ul>
<li><a class="arrow" href="http://www.html-entities.org" target="_blank">html-entities.org</a></li>
<li><a class="arrow" href="https://github.com/johntrimble/bentity" target="_blank">Bentity Tool</a></li>
</ul>
<div class="note">
<ul>
<li>Consistent rendering across all browsers</li>
<li>Consistency throughout all projects</li>
</ul>
</div>
</div>
<a name="css-start"></a>
<h2>CSS Formatting Rules</h2>
<div class="section">
<a name="indentation"></a>
<h3>Block content indentation</h3>
<p>Indent all block content to reflect hierarchy and improve understanding.</p>
<div class="note">
<p>Easier to read and helps reflect hierarchy</p>
</div>
<pre class="correct">
<code>
@media (max-width: 960px) {
.wrapper {
color: #999;
width: 100%;
}
}
</code></pre>
</div>
<div class="section">
<a name="commenting"></a>
<h3>Commenting</h3>
<p>Be sure to comment your CSS. Use section separators to help organize the document. The goal is to make our code as self documented as possible.</p>
<div class="note">
<ul>
<li>Code organization</li>
<li>Maintainability</li>
<li>Consistency throughout projects</li>
</ul>
</div>
<pre class="correct">
<code>
/* --- [ GLOBAL HEADER ] --- */
#header {
margin: 0 auto;
width: 980px;
}
/*
This is a comment describing what the css
below is doing and why it's that way.
*/
.subnav {
float: left;
position: relative;
}
</code></pre>
</div>
<div class="section">
<a name="order"></a>
<h3>Declaration order</h3>
<p>Put declarations in alphabetical order. Ignore vendor-specific prefixes for sorting purposes.</p>
<div class="note">
<p>Helps with consistency, also easy to remember and maintain</p>
</div>
<pre class="correct">
<code>
#page-container {
background: #ccc;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #e3e3e3;
color: #202020;
margin: 0 auto;
text-align: left;
z-index: 1;
}
</code></pre>
</div>
<div class="section">
<a name="prefixes"></a>
<h3>Vendor Prefix Order</h3>
<p>Vendor prefixes should always come before the actual property. The last property should be the actual property because it will be based entirely on the spec, it will match other browsers implementations, and will be the only supported version as time goes on as vendor prefixes are removed.</p>
<h4>Resources</h4>
<ul>
<li><a class="arrow" href="http://css-tricks.com/ordering-css3-properties/" target="_blank">Ordering CSS3 Properties</a></li>
</ul>
<div class="note">
<ul>
<li>Consistency amongst projects</li>
<li>Future proof your CSS</li>
</ul>
</div>
<pre class="correct">
<code>
.modal {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
border: 1px solid #e3e3e3;
}
</code></pre>
</div>
<div class="section">
<a name="name-stops"></a>
<h3>Property name stops</h3>
<p>Always add a space after the colon</p>
<div class="note">
<p>Makes code easier to read</p>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
.title {
font-weight:bold;
}
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
.title {
font-weight: bold;
}
</code></pre>
</div>
<div class="section">
<a name="declaration-stops"></a>
<h3>Declaration stops</h3>
<p>End every declaration with a semicolon</p>
<div class="note">
<p>Consistency throughout all projects</p>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
.test {
display: block;
height: 100px
}
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
.test {
display: block;
height: 100px;
}
</code></pre>
</div>
<div class="section">
<a name="type-selectors"></a>
<h3>Type selectors</h3>
<p>Unless necessary (for example with helper classes), do not use element names in conjunction with IDs or classes. Avoiding unnecessary ancestor selectors is useful for performance reasons as well as makes your CSS more scalable.</p>
<h4>Resources</h4>
<ul>
<li>Selector Performance: <a class="arrow" href="http://www.stevesouders.com/blog/2009/06/18/simplifying-css-selectors/" target="_blank">Simplifying CSS Selectors</a></li>
<li>Object Oriented CSS: <a class="arrow" href="http://coding.smashingmagazine.com/2011/12/12/an-introduction-to-object-oriented-css-oocss/" target="_blank">Introduction to Object Oriented CSS</a></li>
</ul>
<div class="note">
<p>Makes styles to reliant on structure</p>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
ul#example { ... }
div.error { ... }
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
#example { ... }
.error { ... }
</code></pre>
</div>
<div class="section">
<a name="separation"></a>
<h3>Selector and declaration separation</h3>
<p>Always separate selectors and declarations by new lines.</p>
<div class="note">
<ul>
<li>Code Readability</li>
<li>Can cause compiling issues for some preprocessors</li>
</ul>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
a:hover, a:focus, a:visted {
color: #c60;
text-decoration: underline;
}
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
a:hover,
a:focus,
a:visted {
color: #c60;
text-decoration: underline;
}
</code></pre>
</div>
<div class="section">
<a name="rule-separation"></a>
<h3>Rule separation</h3>
<p>Always separate rules by new lines. Makes code easier to read.</p>
<div class="note">
<p>Makes code easier to read and maintain</p>
</div>
<pre class="correct">
<code>
body {
background: #fff;
}
#container {
color: #4a4a4a;
width: 70%;
}
</code></pre>
</div>
<div class="section">
<a name="naming"></a>
<h3>Naming Conventions</h3>
<p>Separate words in IDs and class names by a hyphen and all names should be lowercase.</p>
<div class="note">
<p>For code consistency across all projects</p>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
.content_wrap {}
#pageWrap {}
#Footer
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
.content-wrap {}
#page-wrap {}
#footer {}
</code></pre>
</div>
<div class="section">
<a name="hexadecimal"></a>
<h3>Hexadecimal notation</h3>
<p>Always use lowercase hex values, e.g., #aaa. Also, use 3 character hexadecimal notation where possible.</p>
<div class="note">
<ul>
<li>Consistency amongst projects</li>
<li>Hex colors can help optimize style sheets to their smallest size</li>
</ul>
</div>
<pre class="wrong">
<code>
<!-- BAD -->
#header {
background: white;
color: #cccccc;
}
</code></pre>
<pre class="correct">
<code>
<!-- GOOD -->
#header {
background: #fff;
color: #ccc;
}
</code></pre>
</div>
<a name="js-start"></a>
<h2>JavaScript Rules</h2>
<div class="section">
<a name="semicolons"></a>
<h3>Semicolons</h3>
<p>End all statements with a semicolon.</p>
<div class="note">
<ul>
<li>Consistency amongst projects</li>
<li>Minifying JavaScript without semicolons is risky and may produce unpredictable results</li>
</ul>
</div>
<pre class="wrong">
<code>
<!-- No semicolons -->
var $form = $("register-form")
$form.submit(onFormSubmit)
</code></pre>
<pre class="correct">
<code>
<!-- Recommended -->
var $form = $("register-form");
$form.submit(onFormSubmit);
</code></pre>
</div>
<div class="section">
<a name="strict-equals"></a>
<h3>Always use Strict Equals</h3>
<p>End all statements with a semicolon.</p>
<div class="note">
<ul>
<li>Avoid type coercion which can cause unpredictable results</li>
<li>This helps to maintain data type integrity throughout your code</li>
<li>In general, it's just safer</li>
</ul>
</div>
<pre class="wrong">
<code>
<!-- Type converting equals -->
function checkZero(value) {
return value==0;
}
checkZero("0");
</code></pre>
<pre class="correct">
<code>
<!-- Strict equals -->
function checkZero(value) {
return value===0;
}
checkZero("0");
</code></pre>
</div>
<div class="section">
<a name="js-naming"></a>
<h3>Naming Conventions</h3>
<p>The variable name of a jQuery object, always start with a dollar sign ("$")</p>
<div class="note">
<p>Identifies the variable to be a jQuery object. It's good to make this separation as jQuery objects come with a different set of properties.</p>
</div>
<pre class="wrong">
<code>
<!-- Not starting with $ -->
var slides = $(".slide");
slides.each(function(i, slide) {
slide.css("left", i*100);
});
</code></pre>
<pre class="correct">
<code>
<!-- Starting with $ -->
var $slides = $(".slide");
$slides.each(function(i, $slide) {
$slide.css("left", i*100);
});
</code></pre>
</div>
</div> <!-- /end #content -->
<a href="#top" id="top-btn">Back to top</a>
</div> <!-- /end #content-wrap -->
<!-- javascript
================================================== -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>