1(function() { 2 3 /** 4 * class Button 5 */ 6 var Button = function(button) { 7 this.construct(button); 8 } 9 10 /** 11 * Methods which belong to the button object 12 */ 13 Button.prototype = { 14 /** 15 * Button.construct(button) < Button 16 * - button (Object): DOM reference to a button 17 */ 18 construct: function(button) { 19 var newButton = document.createElement('iframe'); 20 21 var url = "http://api.tweetmeme.com/button.js?url=" + escape(button.href); 22 23 // get all the addiontial options 24 url += '&' + button.rel.toLowerCase(); 25 26 // tracking data 27 if (document && document.referrer) { 28 var ref = document.referrer; 29 if (ref) { 30 url += '&o=' + escape(ref); 31 } 32 } 33 34 newButton.src = url; 35 newButton.frameBorder = "0"; 36 newButton.scrolling = "no"; 37 38 // get the style info 39 var params = new Array(); 40 var qp = button.rel.split('&'); 41 for (var i = 0; i < qp.length; i++) { 42 var kv = qp[i].split('='); 43 if (kv.length > 1) { 44 params[kv[0]] = kv[1]; 45 } 46 } 47 48 if (params['style']) { 49 switch(params['style']) { 50 case 'compact': { 51 var h = 20; 52 var w = 90; 53 break; 54 } 55 default: { 56 var h = 61; 57 var w = 50; 58 break; 59 } 60 } 61 62 newButton.height = h; 63 newButton.width = w; 64 } else { 65 newButton.height = 61; 66 newButton.width = 50; 67 } 68 69 button.parentNode.insertBefore(newButton, button); 70 var parent = button.parentNode; 71 parent.removeChild(button); 72 73 this.button = newButton; 74 } 75 } 76 77 /** 78 * class Selector 79 * 80 * Provides a means to select DOM objects from expressions 81 */ 82 var Selector = { 83 /** 84 * Selector.findChildElements -> Array 85 * - element (Object): Element to search for children from 86 * - expression (String): Expression to search for 87 * 88 * <h2>Example</h2> 89 * 90 * The types of selectors supported in the expression are #(id), .(classes) and tag names 91 * 92 * Selector.findChildElements(div, '#hello') 93 * -> Objects with id hello which are children of div 94 */ 95 findChildElements: function(element, expression) { 96 // set up the results array 97 var results = new Array(); 98 99 if (typeof expression != 'string') { 100 return false; 101 } 102 103 // pull the identifier from the expression (either # or .) 104 var identifier = expression.substring(0, 1); 105 var match = expression.substring(1); 106 // fetch all the child nodes (tested on FF3.6/Opera10.5/Chrome4.1.249.1045 107 this.search(element.childNodes, function(node) { 108 switch(identifier) { 109 case '#': 110 node.id = match ? results.push(node) : false; 111 break; 112 case '.': 113 var classes = node.className; 114 if (classes) { 115 classes = classes.split(' '); 116 for (j in classes) { 117 if (classes[j] == match) { 118 results.push(node); 119 } 120 } 121 } 122 break; 123 default: 124 node.tagName == expression.toUpperCase() ? results.push(node) : false 125 break; 126 } 127 }); 128 return results; 129 }, 130 131 /** 132 * Selector.search 133 * - nodes (Array): Array of DOM elements 134 * - match (Object): function to run on each node 135 * 136 * <h2>Example</h2> 137 * 138 * Selector.search(children, function(node) { 139 * node.innerHTML = 'yo'; 140 * }); 141 */ 142 search: function(nodes, match) { 143 for (var i = 0; i < nodes.length; i++) { 144 if (nodes[i].childNodes.length > 0) { 145 this.search(nodes[i].childNodes, match); 146 } 147 match(nodes[i]); 148 } 149 } 150 } 151 152 // grab all the buttons 153 var buttons = Selector.findChildElements(document.body, '.tm_button'); 154 155 // create the button objects 156 var buttonObjs = new Array(); 157 if (buttons.length > 0) { 158 for (var i = 0; i < buttons.length; i++) { 159 var obj = new Button(buttons[i]); 160 buttonObjs[obj.url] = obj; 161 } 162 } 163})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.