Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

removed jQuery dependancy

  • Loading branch information...
commit 1f99c5785cbb616e6bdc48d04174f2a536d9946d 1 parent 129ae8e
@remy remy authored
Showing with 40 additions and 41 deletions.
  1. +40 −41 js/script.js
View
81 js/script.js
@@ -1,44 +1,43 @@
-$(function(){
-
- if (!('reversed' in document.createElement('ol'))) {
+if (!('reversed' in document.createElement('ol'))) (function () {
- // run the code on each ordered list with a 'reversed' attribute.
- var myLists = $('ol[reversed]'),
- currCount = null,
- currChildren = null;
+ // run the code on each ordered list with a 'reversed' attribute.
+ var lists = document.getElementsByTagName('ol'),
+ length = lists.length,
+ i,
+ j,
+ childrenLength = 0,
+ child = null
+ currCount = null,
+ currChildren = null;
- myLists.each(function() {
+ for (i = 0; i < length; i++) {
+ child = lists[i];
- // 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().length;
- }
-
- // do this if the start attribute is not present
- // the first number is derived from the number of list items
- } else {
- currCount = $(this).children().length;
- }
-
- // 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;
-
- });
-
- });
-
- }
-});
+ if (child.getAttribute('reversed') !== null) {
+ currChildren = child.getElementsByTagName('li');
+ childrenLength = currChildren.length;
+ // check the existence of the start attribute
+ if (child.getAttribute('start') !== null) {
+ // if it exists, convert it to an integer; also ensures even decimal values work
+ currCount = +child.start;
+
+ // If it wasn't a number, it will return 'NaN'; if so, use the number of list items instead
+ if (isNaN(currCount)) {
+ currCount = currChildren.length;
+ }
+
+ // do this if the start attribute is not present
+ // the first number is derived from the number of list items
+ } else {
+ currCount = currChildren.length;
+ }
+
+ // 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
+ for (j = 0; j < childrenLength; j++) {
+ currChildren[j].setAttribute('value', currCount);
+ currCount -= 1;
+ }
+ }
+ }
+})();
Please sign in to comment.
Something went wrong with that request. Please try again.