Created
November 2, 2012 07:34
-
-
Save jlyu/3999291 to your computer and use it in GitHub Desktop.
Learning jQuery -9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.extend($.expr[':'], { | |
group: function(element, index, matches, set) { | |
var num = parseInt(matches[3], 10); | |
if (isNaN(num)){ | |
return false; | |
} | |
return index % num < num; | |
}, | |
containsExactly: function(element, index, matches, set) { | |
return $(element).text() === matches[3]; | |
}, | |
rewriteFilter: function(element, index, matches, set) { | |
} | |
}); | |
})(jQuery); | |
$(document).ready(function(){ | |
function stripe() { | |
var $news = $('#news'); | |
$news.find('tr.alt').removeClass('alt').end(); | |
$news.find('tr.alt-2').removeClass('alt-2').end(); | |
// (1) | |
$news.find('tbody').each(function() { | |
var $targetRow = $(this).children(':visible').has('td').filter(':group(3)'); | |
$targetRow.filter(function(index){ | |
return (index % 3)==1; | |
}).addClass('alt'); | |
$targetRow.filter(function(index){ | |
return (index % 3)==2; | |
}).addClass('alt-2'); | |
}); | |
} | |
stripe(); | |
$('#topics a').click(function(){ | |
var topic = $(this).text(); | |
var $tpc = $('#topics a:containsExactly("All")'); | |
$('#topics a.selected').removeClass('selected'); | |
$(this).addClass('selected'); | |
$('#news').find('tr').show(); | |
// (3) | |
if (topic != 'All') { | |
$('#news').find('tr:has(td)').not(function(){ | |
return $(this).children(':nth-child(4)').text() == topic; | |
}).hide(); | |
} | |
stripe(); | |
return false; | |
}); | |
/* | |
var $cell = $('#release').nextAll().andSelf(); | |
$cell.addClass('highlight'); | |
console.log($cell.context); | |
console.log($cell.selector); | |
console.log($cell.prevObject); | |
*/ | |
// (2) | |
$('td:containsExactly("jQuery 1.5 Released")').addClass('highlight'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment