Permalink
Browse files

added feature detection

  • Loading branch information...
impressivewebs committed Dec 2, 2011
1 parent 750e529 commit c697b8879023b99c85eac7c6dd1d91cf77cb4872
Showing with 34 additions and 29 deletions.
  1. +34 −29 js/script.js
View
@@ -1,39 +1,44 @@
$(function(){
- // run the code on each ordered list with a 'reversed' attribute.
- var myLists = $('ol[reversed]'),
- currCount = null,
- currChildren = null;
+
+ if (!('reversed' in document.createElement('ol'))) {
- myLists.each(function() {
-
- // check the existence of the start attribute
- if ($(this).attr('start')) {
-
- // if it exists, convert it to an integer; also ensures even decimal values work
- currCount = parseInt($(this).attr('start'), 10);
+ // run the code on each ordered list with a 'reversed' attribute.
+ var myLists = $('ol[reversed]'),
+ currCount = null,
+ currChildren = null;
+
+ myLists.each(function() {
+
+ // check the existence of the start attribute
+ if ($(this).attr('start')) {
+
+ // if it exists, convert it to an integer; also ensures even decimal values work
+ currCount = parseInt($(this).attr('start'), 10);
+
+ // If it wasn't a number, it will return 'NaN'; if so, use the number of list items instead
+ if (isNaN(currCount)) {
+ currCount = $(this).children().size();
+ }
- // If it wasn't a number, it will return 'NaN'; if so, use the number of list items instead
- if (isNaN(currCount)) {
+ // do this if the start attribute is not present
+ // the first number is derived from the number of list items
+ } else {
currCount = $(this).children().size();
}
-
- // do this if the start attribute is not present
- // the first number is derived from the number of list items
- } else {
- currCount = $(this).children().size();
- }
-
- // grab all the child list items
- currChildren = $(this).children();
-
- // go through each list item, adding the 'value' attribute plus currCount number
- // then subract one from currCount so we're ready for the next one
- currChildren.each(function() {
+
+ // grab all the child list items
+ currChildren = $(this).children();
+
+ // go through each list item, adding the 'value' attribute plus currCount number
+ // then subract one from currCount so we're ready for the next one
+ currChildren.each(function() {
- $(this).attr('value', currCount);
- currCount = currCount - 1;
+ $(this).attr('value', currCount);
+ currCount = currCount - 1;
+ });
+
});
- });
+ }
});

0 comments on commit c697b88

Please sign in to comment.