Skip to content

Commit 144a0d0

Browse files
committed
added title and description to jquery patterns
1 parent 80ddc10 commit 144a0d0

12 files changed

+43
-9
lines changed

jquery-patterns/append.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<html lang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<meta charset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: append
10+
Description: use string concatenate and set innerHTML
11+
*/
12+
913
// antipattern
1014
// appending inside
1115
$.each(reallyLongArray, function(count, item) {

jquery-patterns/cache-selector.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: selector cache
10+
Description: using selector cache to avoid requery
11+
*/
12+
913
// antipattern
1014
$('.list-item').click(function () {
1115
$('.photo').hide();

jquery-patterns/context-and-find.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: context and find
10+
Description: better to choose `find` over `context`
11+
*/
12+
913
// antipattern
1014
var arms = $('div.robotarm', '#container');
1115
// preferred

jquery-patterns/data.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: data
10+
Description: pattern and antipattern of using data
11+
*/
12+
913
// antipattern
1014
$(elem).data(key,value);
1115

jquery-patterns/decending-from-id.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</head>
77
<body>
88
<script>
9-
/*
10-
better to descend from an id
9+
/* Title: Decending from id
10+
Description: be more specific, better to descend from an id
1111
*/
1212

1313
// antipattern

jquery-patterns/detach.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
</head>
77
<body>
88
<script>
9-
/*
10-
take element off the DOM while manipulating them
9+
/* Title: detach
10+
Description: take element off the DOM while manipulating them
1111
*/
12+
1213
var table = $('#some-table');
1314
var parent = table.parent();
1415

jquery-patterns/event-delegation.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: event delegation
10+
Description: event delegation pattern and antipattern
11+
*/
12+
913
// antipattern
1014
$('a.trigger', $('#container')[0]).live('click', handlerFn)
1115

1216
// preferred
1317
$('#container').on('click', 'a.trigger', handlerFn)
18+
1419
// reference
1520
// http://paulirish.com/2009/perf/
1621
</script>

jquery-patterns/left-and-right.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</head>
77
<body>
88
<script>
9-
/*
10-
specific on the right, light on the left
9+
/* Title: Left and Right
10+
Description: specific on the right, light on the left
1111
*/
1212

1313
// antipattern

jquery-patterns/requery.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: requery
10+
Description: avoid requery by using jQuery chaining
11+
*/
12+
913
// antipattern
1014
// create and append your element
1115
$(document.body).append("<div class='baaron' />");

jquery-patterns/specific-when-needed.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
</head>
77
<body>
88
<script>
9-
/*
10-
no need to be over-specific
9+
/* Title: Be Specific when Needed
10+
Description: no need to be over-specific
1111
*/
1212

1313
// antipattern

0 commit comments

Comments
 (0)