Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

removed jQuery dependancy

  • Loading branch information...
commit 1f99c5785cbb616e6bdc48d04174f2a536d9946d 1 parent 129ae8e
Remy Sharp authored

Showing 1 changed file with 40 additions and 41 deletions. Show diff stats Hide diff stats

  1. 81  js/script.js
81  js/script.js
... ...
@@ -1,44 +1,43 @@
1  
-$(function(){
2  
-	
3  
-	if (!('reversed' in document.createElement('ol'))) {
  1
+if (!('reversed' in document.createElement('ol'))) (function () {
4 2
 
5  
-		// run the code on each ordered list with a 'reversed' attribute.
6  
-		var myLists = $('ol[reversed]'),
7  
-			currCount = null,
8  
-			currChildren = null;
  3
+  // run the code on each ordered list with a 'reversed' attribute.
  4
+  var lists = document.getElementsByTagName('ol'),
  5
+      length = lists.length,
  6
+      i,
  7
+      j,
  8
+      childrenLength = 0,
  9
+      child = null
  10
+      currCount = null,
  11
+      currChildren = null;
9 12
 
10  
-		myLists.each(function() {
  13
+  for (i = 0; i < length; i++) {
  14
+    child = lists[i];
11 15
 
12  
-			// check the existence of the start attribute
13  
-			if ($(this).attr('start')) {
14  
-				
15  
-				// if it exists, convert it to an integer; also ensures even decimal values work
16  
-				currCount = parseInt($(this).attr('start'), 10);
17  
-				
18  
-				// If it wasn't a number, it will return 'NaN'; if so, use the number of list items instead
19  
-				if (isNaN(currCount)) {
20  
-					currCount = $(this).children().length;
21  
-				}
22  
-			
23  
-			// do this if the start attribute is not present
24  
-			// the first number is derived from the number of list items
25  
-			} else {
26  
-				currCount = $(this).children().length;
27  
-			}
28  
-			
29  
-			// grab all the child list items
30  
-			currChildren = $(this).children();
31  
-			
32  
-			// go through each list item, adding the 'value' attribute plus currCount number
33  
-			// then subract one from currCount so we're ready for the next one
34  
-			currChildren.each(function() {
35  
-
36  
-			   $(this).attr('value', currCount);
37  
-			   currCount = currCount - 1;
38  
-
39  
-			});
40  
-			
41  
-		});
42  
-		
43  
-	}
44  
-});
  16
+    if (child.getAttribute('reversed') !== null) {
  17
+      currChildren = child.getElementsByTagName('li');
  18
+      childrenLength = currChildren.length;
  19
+      // check the existence of the start attribute
  20
+      if (child.getAttribute('start') !== null) {
  21
+        // if it exists, convert it to an integer; also ensures even decimal values work
  22
+        currCount = +child.start;
  23
+        
  24
+        // If it wasn't a number, it will return 'NaN'; if so, use the number of list items instead
  25
+        if (isNaN(currCount)) {
  26
+          currCount = currChildren.length;
  27
+        }
  28
+      
  29
+      // do this if the start attribute is not present
  30
+      // the first number is derived from the number of list items
  31
+      } else {
  32
+        currCount = currChildren.length;
  33
+      }
  34
+      
  35
+      // go through each list item, adding the 'value' attribute plus currCount number
  36
+      // then subract one from currCount so we're ready for the next one
  37
+      for (j = 0; j < childrenLength; j++) {
  38
+        currChildren[j].setAttribute('value', currCount);
  39
+        currCount -= 1;
  40
+      }
  41
+    }    
  42
+  }
  43
+})();

0 notes on commit 1f99c57

Please sign in to comment.
Something went wrong with that request. Please try again.