Skip to content

Commit

Permalink
added title and description to jquery patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
chuanxshi committed Jan 15, 2012
1 parent 80ddc10 commit 144a0d0
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 9 deletions.
6 changes: 5 additions & 1 deletion jquery-patterns/append.html
@@ -1,11 +1,15 @@
<!doctype html>
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: append
Description: use string concatenate and set innerHTML
*/

// antipattern
// appending inside
$.each(reallyLongArray, function(count, item) {
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/cache-selector.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: selector cache
Description: using selector cache to avoid requery
*/

// antipattern
$('.list-item').click(function () {
$('.photo').hide();
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/context-and-find.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: context and find
Description: better to choose `find` over `context`
*/

// antipattern
var arms = $('div.robotarm', '#container');
// preferred
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/data.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: data
Description: pattern and antipattern of using data
*/

// antipattern
$(elem).data(key,value);

Expand Down
4 changes: 2 additions & 2 deletions jquery-patterns/decending-from-id.html
Expand Up @@ -6,8 +6,8 @@
</head>
<body>
<script>
/*
better to descend from an id
/* Title: Decending from id
Description: be more specific, better to descend from an id
*/

// antipattern
Expand Down
5 changes: 3 additions & 2 deletions jquery-patterns/detach.html
Expand Up @@ -6,9 +6,10 @@
</head>
<body>
<script>
/*
take element off the DOM while manipulating them
/* Title: detach
Description: take element off the DOM while manipulating them
*/

var table = $('#some-table');
var parent = table.parent();

Expand Down
5 changes: 5 additions & 0 deletions jquery-patterns/event-delegation.html
Expand Up @@ -6,11 +6,16 @@
</head>
<body>
<script>
/* Title: event delegation
Description: event delegation pattern and antipattern
*/

// antipattern
$('a.trigger', $('#container')[0]).live('click', handlerFn)

// preferred
$('#container').on('click', 'a.trigger', handlerFn)

// reference
// http://paulirish.com/2009/perf/
</script>
Expand Down
4 changes: 2 additions & 2 deletions jquery-patterns/left-and-right.html
Expand Up @@ -6,8 +6,8 @@
</head>
<body>
<script>
/*
specific on the right, light on the left
/* Title: Left and Right
Description: specific on the right, light on the left
*/

// antipattern
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/requery.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: requery
Description: avoid requery by using jQuery chaining
*/

// antipattern
// create and append your element
$(document.body).append("<div class='baaron' />");
Expand Down
4 changes: 2 additions & 2 deletions jquery-patterns/specific-when-needed.html
Expand Up @@ -6,8 +6,8 @@
</head>
<body>
<script>
/*
no need to be over-specific
/* Title: Be Specific when Needed
Description: no need to be over-specific
*/

// antipattern
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/universal-selector.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: Universal Selector
Description: better use of universal selector
*/

// antipattern
$('.buttons > *')
// preferred
Expand Down
4 changes: 4 additions & 0 deletions jquery-patterns/window-scroll-event.html
Expand Up @@ -6,6 +6,10 @@
</head>
<body>
<script>
/* Title: window scroll event
Description: avoid attaching handlers to the window scroll event
*/

// antipattern
$(window).scroll(function() {
$('.foo').something();
Expand Down

0 comments on commit 144a0d0

Please sign in to comment.