Ticket #4512: 4512.diff
| File 4512.diff, 75.1 KB (added by , 19 years ago) |
|---|
-
wp-includes/js/scriptaculous/builder.js
1 // script.aculo.us builder.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us builder.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // … … 89 89 var attrs = []; 90 90 for(attribute in attributes) 91 91 attrs.push((attribute in this.ATTR_MAP ? this.ATTR_MAP[attribute] : attribute) + 92 '="' + attributes[attribute].toString().escapeHTML() + '"');92 '="' + attributes[attribute].toString().escapeHTML().gsub(/"/,'"') + '"'); 93 93 return attrs.join(" "); 94 94 }, 95 95 _children: function(element, children) { -
wp-includes/js/scriptaculous/controls.js
1 // script.aculo.us controls.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us controls.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan) -
wp-includes/js/scriptaculous/dragdrop.js
1 // script.aculo.us dragdrop.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us dragdrop.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz) … … 638 638 scrollSensitivity: 20, 639 639 scrollSpeed: 15, 640 640 format: this.SERIALIZE_RULE, 641 642 // these take arrays of elements or ids and can be 643 // used for better initialization performance 644 elements: false, 645 handles: false, 646 641 647 onChange: Prototype.emptyFunction, 642 648 onUpdate: Prototype.emptyFunction 643 649 }, arguments[1] || {}); … … 702 708 options.droppables.push(element); 703 709 } 704 710 705 (this.findElements(element, options) || []).each( function(e) { 706 // handles are per-draggable 707 var handle = options.handle ? 708 $(e).down('.'+options.handle,0) : e; 711 (options.elements || this.findElements(element, options) || []).each( function(e,i) { 712 var handle = options.handles ? $(options.handles[i]) : 713 (options.handle ? $(e).getElementsByClassName(options.handle)[0] : e); 709 714 options.draggables.push( 710 715 new Draggable(e, Object.extend(options_for_draggable, { handle: handle }))); 711 716 Droppables.add(e, options_for_droppable); -
wp-includes/js/scriptaculous/effects.js
1 // script.aculo.us effects.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us effects.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // Contributors: -
wp-includes/js/scriptaculous/MIT-LICENSE
1 Copyright (c) 2005 , 2006Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)1 Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 2 3 3 Permission is hereby granted, free of charge, to any person obtaining 4 4 a copy of this software and associated documentation files (the -
wp-includes/js/scriptaculous/prototype.js
1 /* Prototype JavaScript framework, version 1.5. 01 /* Prototype JavaScript framework, version 1.5.1.1 2 2 * (c) 2005-2007 Sam Stephenson 3 3 * 4 4 * Prototype is freely distributable under the terms of an MIT-style license. 5 * For details, see the Prototype web site: http:// prototype.conio.net/5 * For details, see the Prototype web site: http://www.prototypejs.org/ 6 6 * 7 7 /*--------------------------------------------------------------------------*/ 8 8 9 9 var Prototype = { 10 Version: '1.5.0', 10 Version: '1.5.1.1', 11 12 Browser: { 13 IE: !!(window.attachEvent && !window.opera), 14 Opera: !!window.opera, 15 WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1, 16 Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1 17 }, 18 11 19 BrowserFeatures: { 12 XPath: !!document.evaluate 20 XPath: !!document.evaluate, 21 ElementExtensions: !!window.HTMLElement, 22 SpecificElementExtensions: 23 (document.createElement('div').__proto__ !== 24 document.createElement('form').__proto__) 13 25 }, 14 26 15 ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 16 emptyFunction: function() {}, 27 ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>', 28 JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, 29 30 emptyFunction: function() { }, 17 31 K: function(x) { return x } 18 32 } 19 33 … … 46 60 } 47 61 }, 48 62 63 toJSON: function(object) { 64 var type = typeof object; 65 switch(type) { 66 case 'undefined': 67 case 'function': 68 case 'unknown': return; 69 case 'boolean': return object.toString(); 70 } 71 if (object === null) return 'null'; 72 if (object.toJSON) return object.toJSON(); 73 if (object.ownerDocument === document) return; 74 var results = []; 75 for (var property in object) { 76 var value = Object.toJSON(object[property]); 77 if (value !== undefined) 78 results.push(property.toJSON() + ': ' + value); 79 } 80 return '{' + results.join(', ') + '}'; 81 }, 82 49 83 keys: function(object) { 50 84 var keys = []; 51 85 for (var property in object) … … 75 109 Function.prototype.bindAsEventListener = function(object) { 76 110 var __method = this, args = $A(arguments), object = args.shift(); 77 111 return function(event) { 78 return __method.apply(object, [ ( event || window.event)].concat(args).concat($A(arguments)));112 return __method.apply(object, [event || window.event].concat(args)); 79 113 } 80 114 } 81 115 82 116 Object.extend(Number.prototype, { 83 117 toColorPart: function() { 84 var digits = this.toString(16); 85 if (this < 16) return '0' + digits; 86 return digits; 118 return this.toPaddedString(2, 16); 87 119 }, 88 120 89 121 succ: function() { … … 93 125 times: function(iterator) { 94 126 $R(0, this, true).each(iterator); 95 127 return this; 128 }, 129 130 toPaddedString: function(length, radix) { 131 var string = this.toString(radix || 10); 132 return '0'.times(length - string.length) + string; 133 }, 134 135 toJSON: function() { 136 return isFinite(this) ? this.toString() : 'null'; 96 137 } 97 138 }); 98 139 140 Date.prototype.toJSON = function() { 141 return '"' + this.getFullYear() + '-' + 142 (this.getMonth() + 1).toPaddedString(2) + '-' + 143 this.getDate().toPaddedString(2) + 'T' + 144 this.getHours().toPaddedString(2) + ':' + 145 this.getMinutes().toPaddedString(2) + ':' + 146 this.getSeconds().toPaddedString(2) + '"'; 147 }; 148 99 149 var Try = { 100 150 these: function() { 101 151 var returnValue; … … 145 195 } 146 196 } 147 197 } 148 String.interpret = function(value){ 149 return value == null ? '' : String(value); 150 } 198 Object.extend(String, { 199 interpret: function(value) { 200 return value == null ? '' : String(value); 201 }, 202 specialChar: { 203 '\b': '\\b', 204 '\t': '\\t', 205 '\n': '\\n', 206 '\f': '\\f', 207 '\r': '\\r', 208 '\\': '\\\\' 209 } 210 }); 151 211 152 212 Object.extend(String.prototype, { 153 213 gsub: function(pattern, replacement) { … … 213 273 }, 214 274 215 275 escapeHTML: function() { 216 var div = document.createElement('div'); 217 var text = document.createTextNode(this); 218 div.appendChild(text); 219 return div.innerHTML; 276 var self = arguments.callee; 277 self.text.data = this; 278 return self.div.innerHTML; 220 279 }, 221 280 222 281 unescapeHTML: function() { 223 282 var div = document.createElement('div'); 224 283 div.innerHTML = this.stripTags(); 225 284 return div.childNodes[0] ? (div.childNodes.length > 1 ? 226 $A(div.childNodes).inject('', function(memo,node){ return memo+node.nodeValue }) :285 $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : 227 286 div.childNodes[0].nodeValue) : ''; 228 287 }, 229 288 … … 233 292 234 293 return match[1].split(separator || '&').inject({}, function(hash, pair) { 235 294 if ((pair = pair.split('='))[0]) { 236 var name = decodeURIComponent(pair[0]); 237 var value = pair[1] ? decodeURIComponent(pair[1]) : undefined; 295 var key = decodeURIComponent(pair.shift()); 296 var value = pair.length > 1 ? pair.join('=') : pair[0]; 297 if (value != undefined) value = decodeURIComponent(value); 238 298 239 if (hash[name] !== undefined) { 240 if (hash[name].constructor != Array) 241 hash[name] = [hash[name]]; 242 if (value) hash[name].push(value); 299 if (key in hash) { 300 if (hash[key].constructor != Array) hash[key] = [hash[key]]; 301 hash[key].push(value); 243 302 } 244 else hash[ name] = value;303 else hash[key] = value; 245 304 } 246 305 return hash; 247 306 }); … … 256 315 String.fromCharCode(this.charCodeAt(this.length - 1) + 1); 257 316 }, 258 317 318 times: function(count) { 319 var result = ''; 320 for (var i = 0; i < count; i++) result += this; 321 return result; 322 }, 323 259 324 camelize: function() { 260 325 var parts = this.split('-'), len = parts.length; 261 326 if (len == 1) return parts[0]; … … 270 335 return camelized; 271 336 }, 272 337 273 capitalize: function() {338 capitalize: function() { 274 339 return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); 275 340 }, 276 341 … … 283 348 }, 284 349 285 350 inspect: function(useDoubleQuotes) { 286 var escapedString = this.replace(/\\/g, '\\\\'); 287 if (useDoubleQuotes) 288 return '"' + escapedString.replace(/"/g, '\\"') + '"'; 289 else 290 return "'" + escapedString.replace(/'/g, '\\\'') + "'"; 351 var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) { 352 var character = String.specialChar[match[0]]; 353 return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16); 354 }); 355 if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"'; 356 return "'" + escapedString.replace(/'/g, '\\\'') + "'"; 357 }, 358 359 toJSON: function() { 360 return this.inspect(true); 361 }, 362 363 unfilterJSON: function(filter) { 364 return this.sub(filter || Prototype.JSONFilter, '#{1}'); 365 }, 366 367 isJSON: function() { 368 var str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, ''); 369 return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str); 370 }, 371 372 evalJSON: function(sanitize) { 373 var json = this.unfilterJSON(); 374 try { 375 if (!sanitize || json.isJSON()) return eval('(' + json + ')'); 376 } catch (e) { } 377 throw new SyntaxError('Badly formed JSON string: ' + this.inspect()); 378 }, 379 380 include: function(pattern) { 381 return this.indexOf(pattern) > -1; 382 }, 383 384 startsWith: function(pattern) { 385 return this.indexOf(pattern) === 0; 386 }, 387 388 endsWith: function(pattern) { 389 var d = this.length - pattern.length; 390 return d >= 0 && this.lastIndexOf(pattern) === d; 391 }, 392 393 empty: function() { 394 return this == ''; 395 }, 396 397 blank: function() { 398 return /^\s*$/.test(this); 291 399 } 292 400 }); 293 401 402 if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { 403 escapeHTML: function() { 404 return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); 405 }, 406 unescapeHTML: function() { 407 return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); 408 } 409 }); 410 294 411 String.prototype.gsub.prepareReplacement = function(replacement) { 295 412 if (typeof replacement == 'function') return replacement; 296 413 var template = new Template(replacement); … … 299 416 300 417 String.prototype.parseQuery = String.prototype.toQueryParams; 301 418 419 Object.extend(String.prototype.escapeHTML, { 420 div: document.createElement('div'), 421 text: document.createTextNode('') 422 }); 423 424 with (String.prototype.escapeHTML) div.appendChild(text); 425 302 426 var Template = Class.create(); 303 427 Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/; 304 428 Template.prototype = { … … 316 440 } 317 441 } 318 442 319 var $break = new Object(); 320 var $continue = new Object(); 443 var $break = {}, $continue = new Error('"throw $continue" is deprecated, use "return" instead'); 321 444 322 445 var Enumerable = { 323 446 each: function(iterator) { 324 447 var index = 0; 325 448 try { 326 449 this._each(function(value) { 327 try { 328 iterator(value, index++); 329 } catch (e) { 330 if (e != $continue) throw e; 331 } 450 iterator(value, index++); 332 451 }); 333 452 } catch (e) { 334 453 if (e != $break) throw e; … … 530 649 } 531 650 } 532 651 652 if (Prototype.Browser.WebKit) { 653 $A = Array.from = function(iterable) { 654 if (!iterable) return []; 655 if (!(typeof iterable == 'function' && iterable == '[object NodeList]') && 656 iterable.toArray) { 657 return iterable.toArray(); 658 } else { 659 var results = []; 660 for (var i = 0, length = iterable.length; i < length; i++) 661 results.push(iterable[i]); 662 return results; 663 } 664 } 665 } 666 533 667 Object.extend(Array.prototype, Enumerable); 534 668 535 669 if (!Array.prototype._reverse) … … 588 722 return this.length > 1 ? this : this[0]; 589 723 }, 590 724 591 uniq: function() { 592 return this.inject([], function(array, value) { 593 return array.include(value) ? array : array.concat([value]); 725 uniq: function(sorted) { 726 return this.inject([], function(array, value, index) { 727 if (0 == index || (sorted ? array.last() != value : !array.include(value))) 728 array.push(value); 729 return array; 594 730 }); 595 731 }, 596 732 … … 604 740 605 741 inspect: function() { 606 742 return '[' + this.map(Object.inspect).join(', ') + ']'; 743 }, 744 745 toJSON: function() { 746 var results = []; 747 this.each(function(object) { 748 var value = Object.toJSON(object); 749 if (value !== undefined) results.push(value); 750 }); 751 return '[' + results.join(', ') + ']'; 607 752 } 608 753 }); 609 754 610 755 Array.prototype.toArray = Array.prototype.clone; 611 756 612 function $w(string) {757 function $w(string) { 613 758 string = string.strip(); 614 759 return string ? string.split(/\s+/) : []; 615 760 } 616 761 617 if (window.opera){618 Array.prototype.concat = function() {762 if (Prototype.Browser.Opera){ 763 Array.prototype.concat = function() { 619 764 var array = []; 620 for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);621 for (var i = 0, length = arguments.length; i < length; i++) {622 if (arguments[i].constructor == Array) {623 for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)765 for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); 766 for (var i = 0, length = arguments.length; i < length; i++) { 767 if (arguments[i].constructor == Array) { 768 for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) 624 769 array.push(arguments[i][j]); 625 770 } else { 626 771 array.push(arguments[i]); … … 629 774 return array; 630 775 } 631 776 } 632 var Hash = function(obj) { 633 Object.extend(this, obj || {}); 777 var Hash = function(object) { 778 if (object instanceof Hash) this.merge(object); 779 else Object.extend(this, object || {}); 634 780 }; 635 781 636 782 Object.extend(Hash, { 637 783 toQueryString: function(obj) { 638 784 var parts = []; 785 parts.add = arguments.callee.addPair; 639 786 640 this.prototype._each.call(obj, function(pair) {787 this.prototype._each.call(obj, function(pair) { 641 788 if (!pair.key) return; 789 var value = pair.value; 642 790 643 if (pair.value && pair.value.constructor == Array) { 644 var values = pair.value.compact(); 645 if (values.length < 2) pair.value = values.reduce(); 646 else { 647 key = encodeURIComponent(pair.key); 648 values.each(function(value) { 649 value = value != undefined ? encodeURIComponent(value) : ''; 650 parts.push(key + '=' + encodeURIComponent(value)); 651 }); 652 return; 653 } 791 if (value && typeof value == 'object') { 792 if (value.constructor == Array) value.each(function(value) { 793 parts.add(pair.key, value); 794 }); 795 return; 654 796 } 655 if (pair.value == undefined) pair[1] = ''; 656 parts.push(pair.map(encodeURIComponent).join('=')); 657 }); 797 parts.add(pair.key, value); 798 }); 658 799 659 800 return parts.join('&'); 801 }, 802 803 toJSON: function(object) { 804 var results = []; 805 this.prototype._each.call(object, function(pair) { 806 var value = Object.toJSON(pair.value); 807 if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value); 808 }); 809 return '{' + results.join(', ') + '}'; 660 810 } 661 811 }); 662 812 813 Hash.toQueryString.addPair = function(key, value, prefix) { 814 key = encodeURIComponent(key); 815 if (value === undefined) this.push(key); 816 else this.push(key + '=' + (value == null ? '' : encodeURIComponent(value))); 817 } 818 663 819 Object.extend(Hash.prototype, Enumerable); 664 820 Object.extend(Hash.prototype, { 665 821 _each: function(iterator) { … … 713 869 return '#<Hash:{' + this.map(function(pair) { 714 870 return pair.map(Object.inspect).join(': '); 715 871 }).join(', ') + '}>'; 872 }, 873 874 toJSON: function() { 875 return Hash.toJSON(this); 716 876 } 717 877 }); 718 878 719 879 function $H(object) { 720 if (object && object.constructor ==Hash) return object;880 if (object instanceof Hash) return object; 721 881 return new Hash(object); 722 882 }; 883 884 // Safari iterates over shadowed properties 885 if (function() { 886 var i = 0, Test = function(value) { this.key = value }; 887 Test.prototype.key = 'foo'; 888 for (var property in new Test('bar')) i++; 889 return i > 1; 890 }()) Hash.prototype._each = function(iterator) { 891 var cache = []; 892 for (var key in this) { 893 var value = this[key]; 894 if ((value && value == Hash.prototype[key]) || cache.include(key)) continue; 895 cache.push(key); 896 var pair = [key, value]; 897 pair.key = key; 898 pair.value = value; 899 iterator(pair); 900 } 901 }; 723 902 ObjectRange = Class.create(); 724 903 Object.extend(ObjectRange.prototype, Enumerable); 725 904 Object.extend(ObjectRange.prototype, { … … 834 1013 request: function(url) { 835 1014 this.url = url; 836 1015 this.method = this.options.method; 837 var params = this.options.parameters;1016 var params = Object.clone(this.options.parameters); 838 1017 839 1018 if (!['get', 'post'].include(this.method)) { 840 1019 // simulate other verbs over post … … 842 1021 this.method = 'post'; 843 1022 } 844 1023 845 params = Hash.toQueryString(params); 846 if (params && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) params += '&_=' 1024 this.parameters = params; 847 1025 848 // when GET, append parameters to URL 849 if (this.method == 'get' && params) 850 this.url += (this.url.indexOf('?') > -1 ? '&' : '?') + params; 1026 if (params = Hash.toQueryString(params)) { 1027 // when GET, append parameters to URL 1028 if (this.method == 'get') 1029 this.url += (this.url.include('?') ? '&' : '?') + params; 1030 else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent)) 1031 params += '&_='; 1032 } 851 1033 852 1034 try { 1035 if (this.options.onCreate) this.options.onCreate(this.transport); 853 1036 Ajax.Responders.dispatch('onCreate', this, this.transport); 854 1037 855 1038 this.transport.open(this.method.toUpperCase(), this.url, … … 861 1044 this.transport.onreadystatechange = this.onStateChange.bind(this); 862 1045 this.setRequestHeaders(); 863 1046 864 var body = this.method == 'post' ? (this.options.postBody || params) : null; 1047 this.body = this.method == 'post' ? (this.options.postBody || params) : null; 1048 this.transport.send(this.body); 865 1049 866 this.transport.send(body);867 868 1050 /* Force Firefox to handle ready state 4 for synchronous requests */ 869 1051 if (!this.options.asynchronous && this.transport.overrideMimeType) 870 1052 this.onStateChange(); … … 935 1117 this.dispatchException(e); 936 1118 } 937 1119 938 if ((this.getHeader('Content-type') || 'text/javascript').strip(). 1120 var contentType = this.getHeader('Content-type'); 1121 if (contentType && contentType.strip(). 939 1122 match(/^(text|application)\/(x-)?(java|ecma)script(;.*)?$/i)) 940 1123 this.evalResponse(); 941 1124 } … … 962 1145 evalJSON: function() { 963 1146 try { 964 1147 var json = this.getHeader('X-JSON'); 965 return json ? eval('(' + json + ')') : null;1148 return json ? json.evalJSON() : null; 966 1149 } catch (e) { return null } 967 1150 }, 968 1151 969 1152 evalResponse: function() { 970 1153 try { 971 return eval( this.transport.responseText);1154 return eval((this.transport.responseText || '').unfilterJSON()); 972 1155 } catch (e) { 973 1156 this.dispatchException(e); 974 1157 } … … 1083 1266 results.push(query.snapshotItem(i)); 1084 1267 return results; 1085 1268 }; 1086 }1087 1269 1088 document.getElementsByClassName = function(className, parentElement) { 1089 if (Prototype.BrowserFeatures.XPath) { 1270 document.getElementsByClassName = function(className, parentElement) { 1090 1271 var q = ".//*[contains(concat(' ', @class, ' '), ' " + className + " ')]"; 1091 1272 return document._getElementsByXPath(q, parentElement); 1092 } else {1093 var children = ($(parentElement) || document.body).getElementsByTagName('*');1094 var elements = [], child;1095 for (var i = 0, length = children.length; i < length; i++) {1096 child = children[i];1097 if (Element.hasClassName(child, className))1098 elements.push(Element.extend(child));1099 }1100 return elements;1101 1273 } 1274 1275 } else document.getElementsByClassName = function(className, parentElement) { 1276 var children = ($(parentElement) || document.body).getElementsByTagName('*'); 1277 var elements = [], child, pattern = new RegExp("(^|\\s)" + className + "(\\s|$)"); 1278 for (var i = 0, length = children.length; i < length; i++) { 1279 child = children[i]; 1280 var elementClassName = child.className; 1281 if (elementClassName.length == 0) continue; 1282 if (elementClassName == className || elementClassName.match(pattern)) 1283 elements.push(Element.extend(child)); 1284 } 1285 return elements; 1102 1286 }; 1103 1287 1104 1288 /*--------------------------------------------------------------------------*/ 1105 1289 1106 if (!window.Element) 1107 var Element = new Object(); 1290 if (!window.Element) var Element = {}; 1108 1291 1109 1292 Element.extend = function(element) { 1110 if (!element || _nativeExtensions || element.nodeType == 3) return element; 1293 var F = Prototype.BrowserFeatures; 1294 if (!element || !element.tagName || element.nodeType == 3 || 1295 element._extended || F.SpecificElementExtensions || element == window) 1296 return element; 1111 1297 1112 if (!element._extended && element.tagName && element != window) {1113 var methods = Object.clone(Element.Methods), cache = Element.extend.cache;1298 var methods = {}, tagName = element.tagName, cache = Element.extend.cache, 1299 T = Element.Methods.ByTag; 1114 1300 1115 if (element.tagName == 'FORM') 1116 Object.extend(methods, Form.Methods); 1117 if (['INPUT', 'TEXTAREA', 'SELECT'].include(element.tagName)) 1118 Object.extend(methods, Form.Element.Methods); 1119 1301 // extend methods for all tags (Safari doesn't need this) 1302 if (!F.ElementExtensions) { 1303 Object.extend(methods, Element.Methods), 1120 1304 Object.extend(methods, Element.Methods.Simulated); 1305 } 1121 1306 1122 for (var property in methods) { 1123 var value = methods[property]; 1124 if (typeof value == 'function' && !(property in element)) 1125 element[property] = cache.findOrStore(value); 1126 } 1307 // extend methods for specific tags 1308 if (T[tagName]) Object.extend(methods, T[tagName]); 1309 1310 for (var property in methods) { 1311 var value = methods[property]; 1312 if (typeof value == 'function' && !(property in element)) 1313 element[property] = cache.findOrStore(value); 1127 1314 } 1128 1315 1129 element._extended = true;1316 element._extended = Prototype.emptyFunction; 1130 1317 return element; 1131 1318 }; 1132 1319 … … 1212 1399 }, 1213 1400 1214 1401 descendants: function(element) { 1215 return $A($(element).getElementsByTagName('*')) ;1402 return $A($(element).getElementsByTagName('*')).each(Element.extend); 1216 1403 }, 1217 1404 1405 firstDescendant: function(element) { 1406 element = $(element).firstChild; 1407 while (element && element.nodeType != 1) element = element.nextSibling; 1408 return $(element); 1409 }, 1410 1218 1411 immediateDescendants: function(element) { 1219 1412 if (!(element = $(element).firstChild)) return []; 1220 1413 while (element && element.nodeType != 1) element = element.nextSibling; … … 1242 1435 }, 1243 1436 1244 1437 up: function(element, expression, index) { 1245 return Selector.findElement($(element).ancestors(), expression, index); 1438 element = $(element); 1439 if (arguments.length == 1) return $(element.parentNode); 1440 var ancestors = element.ancestors(); 1441 return expression ? Selector.findElement(ancestors, expression, index) : 1442 ancestors[index || 0]; 1246 1443 }, 1247 1444 1248 1445 down: function(element, expression, index) { 1249 return Selector.findElement($(element).descendants(), expression, index); 1446 element = $(element); 1447 if (arguments.length == 1) return element.firstDescendant(); 1448 var descendants = element.descendants(); 1449 return expression ? Selector.findElement(descendants, expression, index) : 1450 descendants[index || 0]; 1250 1451 }, 1251 1452 1252 1453 previous: function(element, expression, index) { 1253 return Selector.findElement($(element).previousSiblings(), expression, index); 1454 element = $(element); 1455 if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element)); 1456 var previousSiblings = element.previousSiblings(); 1457 return expression ? Selector.findElement(previousSiblings, expression, index) : 1458 previousSiblings[index || 0]; 1254 1459 }, 1255 1460 1256 1461 next: function(element, expression, index) { 1257 return Selector.findElement($(element).nextSiblings(), expression, index); 1462 element = $(element); 1463 if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element)); 1464 var nextSiblings = element.nextSiblings(); 1465 return expression ? Selector.findElement(nextSiblings, expression, index) : 1466 nextSiblings[index || 0]; 1258 1467 }, 1259 1468 1260 1469 getElementsBySelector: function() { … … 1268 1477 1269 1478 readAttribute: function(element, name) { 1270 1479 element = $(element); 1271 if (document.all && !window.opera) { 1480 if (Prototype.Browser.IE) { 1481 if (!element.attributes) return null; 1272 1482 var t = Element._attributeTranslations; 1273 1483 if (t.values[name]) return t.values[name](element, name); 1274 1484 if (t.names[name]) name = t.names[name]; 1275 1485 var attribute = element.attributes[name]; 1276 if(attribute) return attribute.nodeValue;1486 return attribute ? attribute.nodeValue : null; 1277 1487 } 1278 1488 return element.getAttribute(name); 1279 1489 }, … … 1342 1552 }, 1343 1553 1344 1554 empty: function(element) { 1345 return $(element).innerHTML. match(/^\s*$/);1555 return $(element).innerHTML.blank(); 1346 1556 }, 1347 1557 1348 1558 descendantOf: function(element, ancestor) { … … 1361 1571 1362 1572 getStyle: function(element, style) { 1363 1573 element = $(element); 1364 if (['float','cssFloat'].include(style)) 1365 style = (typeof element.style.styleFloat != 'undefined' ? 'styleFloat' : 'cssFloat'); 1366 style = style.camelize(); 1574 style = style == 'float' ? 'cssFloat' : style.camelize(); 1367 1575 var value = element.style[style]; 1368 1576 if (!value) { 1369 if (document.defaultView && document.defaultView.getComputedStyle) { 1370 var css = document.defaultView.getComputedStyle(element, null); 1371 value = css ? css[style] : null; 1372 } else if (element.currentStyle) { 1373 value = element.currentStyle[style]; 1374 } 1577 var css = document.defaultView.getComputedStyle(element, null); 1578 value = css ? css[style] : null; 1375 1579 } 1580 if (style == 'opacity') return value ? parseFloat(value) : 1.0; 1581 return value == 'auto' ? null : value; 1582 }, 1376 1583 1377 if((value == 'auto') && ['width','height'].include(style) && (element.getStyle('display') != 'none')) 1378 value = element['offset'+style.capitalize()] + 'px'; 1584 getOpacity: function(element) { 1585 return $(element).getStyle('opacity'); 1586 }, 1379 1587 1380 if (window.opera && ['left', 'top', 'right', 'bottom'].include(style)) 1381 if (Element.getStyle(element, 'position') == 'static') value = 'auto'; 1382 if(style == 'opacity') { 1383 if(value) return parseFloat(value); 1384 if(value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) 1385 if(value[1]) return parseFloat(value[1]) / 100; 1386 return 1.0; 1387 } 1388 return value == 'auto' ? null : value; 1588 setStyle: function(element, styles, camelized) { 1589 element = $(element); 1590 var elementStyle = element.style; 1591 1592 for (var property in styles) 1593 if (property == 'opacity') element.setOpacity(styles[property]) 1594 else 1595 elementStyle[(property == 'float' || property == 'cssFloat') ? 1596 (elementStyle.styleFloat === undefined ? 'cssFloat' : 'styleFloat') : 1597 (camelized ? property : property.camelize())] = styles[property]; 1598 1599 return element; 1389 1600 }, 1390 1601 1391 set Style: function(element, style) {1602 setOpacity: function(element, value) { 1392 1603 element = $(element); 1393 for (var name in style) { 1394 var value = style[name]; 1395 if(name == 'opacity') { 1396 if (value == 1) { 1397 value = (/Gecko/.test(navigator.userAgent) && 1398 !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 0.999999 : 1.0; 1399 if(/MSIE/.test(navigator.userAgent) && !window.opera) 1400 element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); 1401 } else if(value == '') { 1402 if(/MSIE/.test(navigator.userAgent) && !window.opera) 1403 element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,''); 1404 } else { 1405 if(value < 0.00001) value = 0; 1406 if(/MSIE/.test(navigator.userAgent) && !window.opera) 1407 element.style.filter = element.getStyle('filter').replace(/alpha\([^\)]*\)/gi,'') + 1408 'alpha(opacity='+value*100+')'; 1409 } 1410 } else if(['float','cssFloat'].include(name)) name = (typeof element.style.styleFloat != 'undefined') ? 'styleFloat' : 'cssFloat'; 1411 element.style[name.camelize()] = value; 1412 } 1604 element.style.opacity = (value == 1 || value === '') ? '' : 1605 (value < 0.00001) ? 0 : value; 1413 1606 return element; 1414 1607 }, 1415 1608 … … 1483 1676 } 1484 1677 }; 1485 1678 1486 Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf}); 1679 Object.extend(Element.Methods, { 1680 childOf: Element.Methods.descendantOf, 1681 childElements: Element.Methods.immediateDescendants 1682 }); 1487 1683 1488 Element._attributeTranslations = {}; 1684 if (Prototype.Browser.Opera) { 1685 Element.Methods._getStyle = Element.Methods.getStyle; 1686 Element.Methods.getStyle = function(element, style) { 1687 switch(style) { 1688 case 'left': 1689 case 'top': 1690 case 'right': 1691 case 'bottom': 1692 if (Element._getStyle(element, 'position') == 'static') return null; 1693 default: return Element._getStyle(element, style); 1694 } 1695 }; 1696 } 1697 else if (Prototype.Browser.IE) { 1698 Element.Methods.getStyle = function(element, style) { 1699 element = $(element); 1700 style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize(); 1701 var value = element.style[style]; 1702 if (!value && element.currentStyle) value = element.currentStyle[style]; 1489 1703 1490 Element._attributeTranslations.names = { 1491 colspan: "colSpan", 1492 rowspan: "rowSpan", 1493 valign: "vAlign", 1494 datetime: "dateTime", 1495 accesskey: "accessKey", 1496 tabindex: "tabIndex", 1497 enctype: "encType", 1498 maxlength: "maxLength", 1499 readonly: "readOnly", 1500 longdesc: "longDesc" 1501 }; 1704 if (style == 'opacity') { 1705 if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/)) 1706 if (value[1]) return parseFloat(value[1]) / 100; 1707 return 1.0; 1708 } 1502 1709 1503 Element._attributeTranslations.values = { 1504 _getAttr: function(element, attribute) { 1505 return element.getAttribute(attribute, 2); 1506 }, 1710 if (value == 'auto') { 1711 if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none')) 1712 return element['offset'+style.capitalize()] + 'px'; 1713 return null; 1714 } 1715 return value; 1716 }; 1507 1717 1508 _flag: function(element, attribute) { 1509 return $(element).hasAttribute(attribute) ? attribute : null; 1510 }, 1718 Element.Methods.setOpacity = function(element, value) { 1719 element = $(element); 1720 var filter = element.getStyle('filter'), style = element.style; 1721 if (value == 1 || value === '') { 1722 style.filter = filter.replace(/alpha\([^\)]*\)/gi,''); 1723 return element; 1724 } else if (value < 0.00001) value = 0; 1725 style.filter = filter.replace(/alpha\([^\)]*\)/gi, '') + 1726 'alpha(opacity=' + (value * 100) + ')'; 1727 return element; 1728 }; 1511 1729 1512 style: function(element) { 1513 return element.style.cssText.toLowerCase(); 1514 }, 1515 1516 title: function(element) { 1517 var node = element.getAttributeNode('title'); 1518 return node.specified ? node.nodeValue : null; 1519 } 1520 }; 1521 1522 Object.extend(Element._attributeTranslations.values, { 1523 href: Element._attributeTranslations.values._getAttr, 1524 src: Element._attributeTranslations.values._getAttr, 1525 disabled: Element._attributeTranslations.values._flag, 1526 checked: Element._attributeTranslations.values._flag, 1527 readonly: Element._attributeTranslations.values._flag, 1528 multiple: Element._attributeTranslations.values._flag 1529 }); 1530 1531 Element.Methods.Simulated = { 1532 hasAttribute: function(element, attribute) { 1533 var t = Element._attributeTranslations; 1534 attribute = t.names[attribute] || attribute; 1535 return $(element).getAttributeNode(attribute).specified; 1536 } 1537 }; 1538 1539 // IE is missing .innerHTML support for TABLE-related elements 1540 if (document.all && !window.opera){ 1730 // IE is missing .innerHTML support for TABLE-related elements 1541 1731 Element.Methods.update = function(element, html) { 1542 1732 element = $(element); 1543 1733 html = typeof html == 'undefined' ? '' : html.toString(); … … 1558 1748 div.innerHTML = '<table><tbody><tr><td>' + html.stripScripts() + '</td></tr></tbody></table>'; 1559 1749 depth = 4; 1560 1750 } 1561 $A(element.childNodes).each(function(node){ 1562 element.removeChild(node) 1563 }); 1564 depth.times(function(){ div = div.firstChild }); 1565 1566 $A(div.childNodes).each( 1567 function(node){ element.appendChild(node) }); 1751 $A(element.childNodes).each(function(node) { element.removeChild(node) }); 1752 depth.times(function() { div = div.firstChild }); 1753 $A(div.childNodes).each(function(node) { element.appendChild(node) }); 1568 1754 } else { 1569 1755 element.innerHTML = html.stripScripts(); 1570 1756 } 1571 setTimeout(function() { html.evalScripts()}, 10);1757 setTimeout(function() { html.evalScripts() }, 10); 1572 1758 return element; 1573 1759 } 1760 } 1761 else if (Prototype.Browser.Gecko) { 1762 Element.Methods.setOpacity = function(element, value) { 1763 element = $(element); 1764 element.style.opacity = (value == 1) ? 0.999999 : 1765 (value === '') ? '' : (value < 0.00001) ? 0 : value; 1766 return element; 1767 }; 1768 } 1769 1770 Element._attributeTranslations = { 1771 names: { 1772 colspan: "colSpan", 1773 rowspan: "rowSpan", 1774 valign: "vAlign", 1775 datetime: "dateTime", 1776 accesskey: "accessKey", 1777 tabindex: "tabIndex", 1778 enctype: "encType", 1779 maxlength: "maxLength", 1780 readonly: "readOnly", 1781 longdesc: "longDesc" 1782 }, 1783 values: { 1784 _getAttr: function(element, attribute) { 1785 return element.getAttribute(attribute, 2); 1786 }, 1787 _flag: function(element, attribute) { 1788 return $(element).hasAttribute(attribute) ? attribute : null; 1789 }, 1790 style: function(element) { 1791 return element.style.cssText.toLowerCase(); 1792 }, 1793 title: function(element) { 1794 var node = element.getAttributeNode('title'); 1795 return node.specified ? node.nodeValue : null; 1796 } 1797 } 1574 1798 }; 1575 1799 1800 (function() { 1801 Object.extend(this, { 1802 href: this._getAttr, 1803 src: this._getAttr, 1804 type: this._getAttr, 1805 disabled: this._flag, 1806 checked: this._flag, 1807 readonly: this._flag, 1808 multiple: this._flag 1809 }); 1810 }).call(Element._attributeTranslations.values); 1811 1812 Element.Methods.Simulated = { 1813 hasAttribute: function(element, attribute) { 1814 var t = Element._attributeTranslations, node; 1815 attribute = t.names[attribute] || attribute; 1816 node = $(element).getAttributeNode(attribute); 1817 return node && node.specified; 1818 } 1819 }; 1820 1821 Element.Methods.ByTag = {}; 1822 1576 1823 Object.extend(Element, Element.Methods); 1577 1824 1578 var _nativeExtensions = false; 1825 if (!Prototype.BrowserFeatures.ElementExtensions && 1826 document.createElement('div').__proto__) { 1827 window.HTMLElement = {}; 1828 window.HTMLElement.prototype = document.createElement('div').__proto__; 1829 Prototype.BrowserFeatures.ElementExtensions = true; 1830 } 1579 1831 1580 if(/Konqueror|Safari|KHTML/.test(navigator.userAgent)) 1581 ['', 'Form', 'Input', 'TextArea', 'Select'].each(function(tag) { 1582 var className = 'HTML' + tag + 'Element'; 1583 if(window[className]) return; 1584 var klass = window[className] = {}; 1585 klass.prototype = document.createElement(tag ? tag.toLowerCase() : 'div').__proto__; 1586 }); 1832 Element.hasAttribute = function(element, attribute) { 1833 if (element.hasAttribute) return element.hasAttribute(attribute); 1834 return Element.Methods.Simulated.hasAttribute(element, attribute); 1835 }; 1587 1836 1588 1837 Element.addMethods = function(methods) { 1589 Object.extend(Element.Methods, methods || {});1838 var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag; 1590 1839 1840 if (!methods) { 1841 Object.extend(Form, Form.Methods); 1842 Object.extend(Form.Element, Form.Element.Methods); 1843 Object.extend(Element.Methods.ByTag, { 1844 "FORM": Object.clone(Form.Methods), 1845 "INPUT": Object.clone(Form.Element.Methods), 1846 "SELECT": Object.clone(Form.Element.Methods), 1847 "TEXTAREA": Object.clone(Form.Element.Methods) 1848 }); 1849 } 1850 1851 if (arguments.length == 2) { 1852 var tagName = methods; 1853 methods = arguments[1]; 1854 } 1855 1856 if (!tagName) Object.extend(Element.Methods, methods || {}); 1857 else { 1858 if (tagName.constructor == Array) tagName.each(extend); 1859 else extend(tagName); 1860 } 1861 1862 function extend(tagName) { 1863 tagName = tagName.toUpperCase(); 1864 if (!Element.Methods.ByTag[tagName]) 1865 Element.Methods.ByTag[tagName] = {}; 1866 Object.extend(Element.Methods.ByTag[tagName], methods); 1867 } 1868 1591 1869 function copy(methods, destination, onlyIfAbsent) { 1592 1870 onlyIfAbsent = onlyIfAbsent || false; 1593 1871 var cache = Element.extend.cache; … … 1598 1876 } 1599 1877 } 1600 1878 1601 if (typeof HTMLElement != 'undefined') { 1879 function findDOMClass(tagName) { 1880 var klass; 1881 var trans = { 1882 "OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph", 1883 "FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList", 1884 "DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading", 1885 "H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote", 1886 "INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION": 1887 "TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD": 1888 "TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR": 1889 "TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET": 1890 "FrameSet", "IFRAME": "IFrame" 1891 }; 1892 if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element'; 1893 if (window[klass]) return window[klass]; 1894 klass = 'HTML' + tagName + 'Element'; 1895 if (window[klass]) return window[klass]; 1896 klass = 'HTML' + tagName.capitalize() + 'Element'; 1897 if (window[klass]) return window[klass]; 1898 1899 window[klass] = {}; 1900 window[klass].prototype = document.createElement(tagName).__proto__; 1901 return window[klass]; 1902 } 1903 1904 if (F.ElementExtensions) { 1602 1905 copy(Element.Methods, HTMLElement.prototype); 1603 1906 copy(Element.Methods.Simulated, HTMLElement.prototype, true); 1604 copy(Form.Methods, HTMLFormElement.prototype);1605 [HTMLInputElement, HTMLTextAreaElement, HTMLSelectElement].each(function(klass) {1606 copy(Form.Element.Methods, klass.prototype);1607 });1608 _nativeExtensions = true;1609 1907 } 1610 }1611 1908 1612 var Toggle = new Object(); 1613 Toggle.display = Element.toggle; 1909 if (F.SpecificElementExtensions) { 1910 for (var tag in Element.Methods.ByTag) { 1911 var klass = findDOMClass(tag); 1912 if (typeof klass == "undefined") continue; 1913 copy(T[tag], klass.prototype); 1914 } 1915 } 1614 1916 1917 Object.extend(Element, Element.Methods); 1918 delete Element.ByTag; 1919 }; 1920 1921 var Toggle = { display: Element.toggle }; 1922 1615 1923 /*--------------------------------------------------------------------------*/ 1616 1924 1617 1925 Abstract.Insertion = function(adjacency) { … … 1741 2049 }; 1742 2050 1743 2051 Object.extend(Element.ClassNames.prototype, Enumerable); 2052 /* Portions of the Selector class are derived from Jack Slocum’s DomQuery, 2053 * part of YUI-Ext version 0.40, distributed under the terms of an MIT-style 2054 * license. Please see http://www.yui-ext.com/ for more information. */ 2055 1744 2056 var Selector = Class.create(); 2057 1745 2058 Selector.prototype = { 1746 2059 initialize: function(expression) { 1747 this.params = {classNames: []}; 1748 this.expression = expression.toString().strip(); 1749 this.parseExpression(); 2060 this.expression = expression.strip(); 1750 2061 this.compileMatcher(); 1751 2062 }, 1752 2063 1753 parseExpression: function() { 1754 function abort(message) { throw 'Parse error in selector: ' + message; } 2064 compileMatcher: function() { 2065 // Selectors with namespaced attributes can't use the XPath version 2066 if (Prototype.BrowserFeatures.XPath && !(/\[[\w-]*?:/).test(this.expression)) 2067 return this.compileXPathMatcher(); 1755 2068 1756 if (this.expression == '') abort('empty expression'); 2069 var e = this.expression, ps = Selector.patterns, h = Selector.handlers, 2070 c = Selector.criteria, le, p, m; 1757 2071 1758 var params = this.params, expr = this.expression, match, modifier, clause, rest; 1759 while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) { 1760 params.attributes = params.attributes || []; 1761 params.attributes.push({name: match[2], operator: match[3], value: match[4] || match[5] || ''}); 1762 expr = match[1]; 2072 if (Selector._cache[e]) { 2073 this.matcher = Selector._cache[e]; return; 1763 2074 } 2075 this.matcher = ["this.matcher = function(root) {", 2076 "var r = root, h = Selector.handlers, c = false, n;"]; 1764 2077 1765 if (expr == '*') return this.params.wildcard = true;1766 1767 while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)) {1768 modifier = match[1], clause = match[2], rest = match[3];1769 switch (modifier) {1770 case '#': params.id = clause; break;1771 case '.': params.classNames.push(clause); break;1772 case '':1773 case undefined: params.tagName = clause.toUpperCase();break;1774 default: abort(expr.inspect());2078 while (e && le != e && (/\S/).test(e)) { 2079 le = e; 2080 for (var i in ps) { 2081 p = ps[i]; 2082 if (m = e.match(p)) { 2083 this.matcher.push(typeof c[i] == 'function' ? c[i](m) : 2084 new Template(c[i]).evaluate(m)); 2085 e = e.replace(m[0], ''); 2086 break; 2087 } 1775 2088 } 1776 expr = rest;1777 2089 } 1778 2090 1779 if (expr.length > 0) abort(expr.inspect()); 2091 this.matcher.push("return h.unique(n);\n}"); 2092 eval(this.matcher.join('\n')); 2093 Selector._cache[this.expression] = this.matcher; 1780 2094 }, 1781 2095 1782 buildMatchExpression: function() { 1783 var params = this.params, conditions = [], clause; 2096 compileXPathMatcher: function() { 2097 var e = this.expression, ps = Selector.patterns, 2098 x = Selector.xpath, le, m; 1784 2099 1785 if (params.wildcard) 1786 conditions.push('true'); 1787 if (clause = params.id) 1788 conditions.push('element.readAttribute("id") == ' + clause.inspect()); 1789 if (clause = params.tagName) 1790 conditions.push('element.tagName.toUpperCase() == ' + clause.inspect()); 1791 if ((clause = params.classNames).length > 0) 1792 for (var i = 0, length = clause.length; i < length; i++) 1793 conditions.push('element.hasClassName(' + clause[i].inspect() + ')'); 1794 if (clause = params.attributes) { 1795 clause.each(function(attribute) { 1796 var value = 'element.readAttribute(' + attribute.name.inspect() + ')'; 1797 var splitValueBy = function(delimiter) { 1798 return value + ' && ' + value + '.split(' + delimiter.inspect() + ')'; 2100 if (Selector._cache[e]) { 2101 this.xpath = Selector._cache[e]; return; 2102 } 2103 2104 this.matcher = ['.//*']; 2105 while (e && le != e && (/\S/).test(e)) { 2106 le = e; 2107 for (var i in ps) { 2108 if (m = e.match(ps[i])) { 2109 this.matcher.push(typeof x[i] == 'function' ? x[i](m) : 2110 new Template(x[i]).evaluate(m)); 2111 e = e.replace(m[0], ''); 2112 break; 1799 2113 } 2114 } 2115 } 1800 2116 1801 switch (attribute.operator) { 1802 case '=': conditions.push(value + ' == ' + attribute.value.inspect()); break; 1803 case '~=': conditions.push(splitValueBy(' ') + '.include(' + attribute.value.inspect() + ')'); break; 1804 case '|=': conditions.push( 1805 splitValueBy('-') + '.first().toUpperCase() == ' + attribute.value.toUpperCase().inspect() 1806 ); break; 1807 case '!=': conditions.push(value + ' != ' + attribute.value.inspect()); break; 1808 case '': 1809 case undefined: conditions.push('element.hasAttribute(' + attribute.name.inspect() + ')'); break; 1810 default: throw 'Unknown operator ' + attribute.operator + ' in selector'; 2117 this.xpath = this.matcher.join(''); 2118 Selector._cache[this.expression] = this.xpath; 2119 }, 2120 2121 findElements: function(root) { 2122 root = root || document; 2123 if (this.xpath) return document._getElementsByXPath(this.xpath, root); 2124 return this.matcher(root); 2125 }, 2126 2127 match: function(element) { 2128 return this.findElements(document).include(element); 2129 }, 2130 2131 toString: function() { 2132 return this.expression; 2133 }, 2134 2135 inspect: function() { 2136 return "#<Selector:" + this.expression.inspect() + ">"; 2137 } 2138 }; 2139 2140 Object.extend(Selector, { 2141 _cache: {}, 2142 2143 xpath: { 2144 descendant: "//*", 2145 child: "/*", 2146 adjacent: "/following-sibling::*[1]", 2147 laterSibling: '/following-sibling::*', 2148 tagName: function(m) { 2149 if (m[1] == '*') return ''; 2150 return "[local-name()='" + m[1].toLowerCase() + 2151 "' or local-name()='" + m[1].toUpperCase() + "']"; 2152 }, 2153 className: "[contains(concat(' ', @class, ' '), ' #{1} ')]", 2154 id: "[@id='#{1}']", 2155 attrPresence: "[@#{1}]", 2156 attr: function(m) { 2157 m[3] = m[5] || m[6]; 2158 return new Template(Selector.xpath.operators[m[2]]).evaluate(m); 2159 }, 2160 pseudo: function(m) { 2161 var h = Selector.xpath.pseudos[m[1]]; 2162 if (!h) return ''; 2163 if (typeof h === 'function') return h(m); 2164 return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m); 2165 }, 2166 operators: { 2167 '=': "[@#{1}='#{3}']", 2168 '!=': "[@#{1}!='#{3}']", 2169 '^=': "[starts-with(@#{1}, '#{3}')]", 2170 '$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']", 2171 '*=': "[contains(@#{1}, '#{3}')]", 2172 '~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]", 2173 '|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]" 2174 }, 2175 pseudos: { 2176 'first-child': '[not(preceding-sibling::*)]', 2177 'last-child': '[not(following-sibling::*)]', 2178 'only-child': '[not(preceding-sibling::* or following-sibling::*)]', 2179 'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]", 2180 'checked': "[@checked]", 2181 'disabled': "[@disabled]", 2182 'enabled': "[not(@disabled)]", 2183 'not': function(m) { 2184 var e = m[6], p = Selector.patterns, 2185 x = Selector.xpath, le, m, v; 2186 2187 var exclusion = []; 2188 while (e && le != e && (/\S/).test(e)) { 2189 le = e; 2190 for (var i in p) { 2191 if (m = e.match(p[i])) { 2192 v = typeof x[i] == 'function' ? x[i](m) : new Template(x[i]).evaluate(m); 2193 exclusion.push("(" + v.substring(1, v.length - 1) + ")"); 2194 e = e.replace(m[0], ''); 2195 break; 2196 } 2197 } 1811 2198 } 1812 }); 2199 return "[not(" + exclusion.join(" and ") + ")]"; 2200 }, 2201 'nth-child': function(m) { 2202 return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m); 2203 }, 2204 'nth-last-child': function(m) { 2205 return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m); 2206 }, 2207 'nth-of-type': function(m) { 2208 return Selector.xpath.pseudos.nth("position() ", m); 2209 }, 2210 'nth-last-of-type': function(m) { 2211 return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m); 2212 }, 2213 'first-of-type': function(m) { 2214 m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m); 2215 }, 2216 'last-of-type': function(m) { 2217 m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m); 2218 }, 2219 'only-of-type': function(m) { 2220 var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m); 2221 }, 2222 nth: function(fragment, m) { 2223 var mm, formula = m[6], predicate; 2224 if (formula == 'even') formula = '2n+0'; 2225 if (formula == 'odd') formula = '2n+1'; 2226 if (mm = formula.match(/^(\d+)$/)) // digit only 2227 return '[' + fragment + "= " + mm[1] + ']'; 2228 if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b 2229 if (mm[1] == "-") mm[1] = -1; 2230 var a = mm[1] ? Number(mm[1]) : 1; 2231 var b = mm[2] ? Number(mm[2]) : 0; 2232 predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " + 2233 "((#{fragment} - #{b}) div #{a} >= 0)]"; 2234 return new Template(predicate).evaluate({ 2235 fragment: fragment, a: a, b: b }); 2236 } 2237 } 1813 2238 } 2239 }, 1814 2240 1815 return conditions.join(' && '); 2241 criteria: { 2242 tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;', 2243 className: 'n = h.className(n, r, "#{1}", c); c = false;', 2244 id: 'n = h.id(n, r, "#{1}", c); c = false;', 2245 attrPresence: 'n = h.attrPresence(n, r, "#{1}"); c = false;', 2246 attr: function(m) { 2247 m[3] = (m[5] || m[6]); 2248 return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}"); c = false;').evaluate(m); 2249 }, 2250 pseudo: function(m) { 2251 if (m[6]) m[6] = m[6].replace(/"/g, '\\"'); 2252 return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m); 2253 }, 2254 descendant: 'c = "descendant";', 2255 child: 'c = "child";', 2256 adjacent: 'c = "adjacent";', 2257 laterSibling: 'c = "laterSibling";' 1816 2258 }, 1817 2259 1818 compileMatcher: function() { 1819 this.match = new Function('element', 'if (!element.tagName) return false; \ 1820 element = $(element); \ 1821 return ' + this.buildMatchExpression()); 2260 patterns: { 2261 // combinators must be listed first 2262 // (and descendant needs to be last combinator) 2263 laterSibling: /^\s*~\s*/, 2264 child: /^\s*>\s*/, 2265 adjacent: /^\s*\+\s*/, 2266 descendant: /^\s/, 2267 2268 // selectors follow 2269 tagName: /^\s*(\*|[\w\-]+)(\b|$)?/, 2270 id: /^#([\w\-\*]+)(\b|$)/, 2271 className: /^\.([\w\-\*]+)(\b|$)/, 2272 pseudo: /^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|\s|(?=:))/, 2273 attrPresence: /^\[([\w]+)\]/, 2274 attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\]]*?)\4|([^'"][^\]]*?)))?\]/ 1822 2275 }, 1823 2276 1824 findElements: function(scope) { 1825 var element; 2277 handlers: { 2278 // UTILITY FUNCTIONS 2279 // joins two collections 2280 concat: function(a, b) { 2281 for (var i = 0, node; node = b[i]; i++) 2282 a.push(node); 2283 return a; 2284 }, 1826 2285 1827 if (element = $(this.params.id)) 1828 if (this.match(element)) 1829 if (!scope || Element.childOf(element, scope)) 1830 return [element]; 2286 // marks an array of nodes for counting 2287 mark: function(nodes) { 2288 for (var i = 0, node; node = nodes[i]; i++) 2289 node._counted = true; 2290 return nodes; 2291 }, 1831 2292 1832 scope = (scope || document).getElementsByTagName(this.params.tagName || '*'); 2293 unmark: function(nodes) { 2294 for (var i = 0, node; node = nodes[i]; i++) 2295 node._counted = undefined; 2296 return nodes; 2297 }, 1833 2298 1834 var results = []; 1835 for (var i = 0, length = scope.length; i < length; i++) 1836 if (this.match(element = scope[i])) 1837 results.push(Element.extend(element)); 2299 // mark each child node with its position (for nth calls) 2300 // "ofType" flag indicates whether we're indexing for nth-of-type 2301 // rather than nth-child 2302 index: function(parentNode, reverse, ofType) { 2303 parentNode._counted = true; 2304 if (reverse) { 2305 for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) { 2306 node = nodes[i]; 2307 if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; 2308 } 2309 } else { 2310 for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++) 2311 if (node.nodeType == 1 && (!ofType || node._counted)) node.nodeIndex = j++; 2312 } 2313 }, 1838 2314 1839 return results; 2315 // filters out duplicates and extends all nodes 2316 unique: function(nodes) { 2317 if (nodes.length == 0) return nodes; 2318 var results = [], n; 2319 for (var i = 0, l = nodes.length; i < l; i++) 2320 if (!(n = nodes[i])._counted) { 2321 n._counted = true; 2322 results.push(Element.extend(n)); 2323 } 2324 return Selector.handlers.unmark(results); 2325 }, 2326 2327 // COMBINATOR FUNCTIONS 2328 descendant: function(nodes) { 2329 var h = Selector.handlers; 2330 for (var i = 0, results = [], node; node = nodes[i]; i++) 2331 h.concat(results, node.getElementsByTagName('*')); 2332 return results; 2333 }, 2334 2335 child: function(nodes) { 2336 var h = Selector.handlers; 2337 for (var i = 0, results = [], node; node = nodes[i]; i++) { 2338 for (var j = 0, children = [], child; child = node.childNodes[j]; j++) 2339 if (child.nodeType == 1 && child.tagName != '!') results.push(child); 2340 } 2341 return results; 2342 }, 2343 2344 adjacent: function(nodes) { 2345 for (var i = 0, results = [], node; node = nodes[i]; i++) { 2346 var next = this.nextElementSibling(node); 2347 if (next) results.push(next); 2348 } 2349 return results; 2350 }, 2351 2352 laterSibling: function(nodes) { 2353 var h = Selector.handlers; 2354 for (var i = 0, results = [], node; node = nodes[i]; i++) 2355 h.concat(results, Element.nextSiblings(node)); 2356 return results; 2357 }, 2358 2359 nextElementSibling: function(node) { 2360 while (node = node.nextSibling) 2361 if (node.nodeType == 1) return node; 2362 return null; 2363 }, 2364 2365 previousElementSibling: function(node) { 2366 while (node = node.previousSibling) 2367 if (node.nodeType == 1) return node; 2368 return null; 2369 }, 2370 2371 // TOKEN FUNCTIONS 2372 tagName: function(nodes, root, tagName, combinator) { 2373 tagName = tagName.toUpperCase(); 2374 var results = [], h = Selector.handlers; 2375 if (nodes) { 2376 if (combinator) { 2377 // fastlane for ordinary descendant combinators 2378 if (combinator == "descendant") { 2379 for (var i = 0, node; node = nodes[i]; i++) 2380 h.concat(results, node.getElementsByTagName(tagName)); 2381 return results; 2382 } else nodes = this[combinator](nodes); 2383 if (tagName == "*") return nodes; 2384 } 2385 for (var i = 0, node; node = nodes[i]; i++) 2386 if (node.tagName.toUpperCase() == tagName) results.push(node); 2387 return results; 2388 } else return root.getElementsByTagName(tagName); 2389 }, 2390 2391 id: function(nodes, root, id, combinator) { 2392 var targetNode = $(id), h = Selector.handlers; 2393 if (!nodes && root == document) return targetNode ? [targetNode] : []; 2394 if (nodes) { 2395 if (combinator) { 2396 if (combinator == 'child') { 2397 for (var i = 0, node; node = nodes[i]; i++) 2398 if (targetNode.parentNode == node) return [targetNode]; 2399 } else if (combinator == 'descendant') { 2400 for (var i = 0, node; node = nodes[i]; i++) 2401 if (Element.descendantOf(targetNode, node)) return [targetNode]; 2402 } else if (combinator == 'adjacent') { 2403 for (var i = 0, node; node = nodes[i]; i++) 2404 if (Selector.handlers.previousElementSibling(targetNode) == node) 2405 return [targetNode]; 2406 } else nodes = h[combinator](nodes); 2407 } 2408 for (var i = 0, node; node = nodes[i]; i++) 2409 if (node == targetNode) return [targetNode]; 2410 return []; 2411 } 2412 return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : []; 2413 }, 2414 2415 className: function(nodes, root, className, combinator) { 2416 if (nodes && combinator) nodes = this[combinator](nodes); 2417 return Selector.handlers.byClassName(nodes, root, className); 2418 }, 2419 2420 byClassName: function(nodes, root, className) { 2421 if (!nodes) nodes = Selector.handlers.descendant([root]); 2422 var needle = ' ' + className + ' '; 2423 for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) { 2424 nodeClassName = node.className; 2425 if (nodeClassName.length == 0) continue; 2426 if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle)) 2427 results.push(node); 2428 } 2429 return results; 2430 }, 2431 2432 attrPresence: function(nodes, root, attr) { 2433 var results = []; 2434 for (var i = 0, node; node = nodes[i]; i++) 2435 if (Element.hasAttribute(node, attr)) results.push(node); 2436 return results; 2437 }, 2438 2439 attr: function(nodes, root, attr, value, operator) { 2440 if (!nodes) nodes = root.getElementsByTagName("*"); 2441 var handler = Selector.operators[operator], results = []; 2442 for (var i = 0, node; node = nodes[i]; i++) { 2443 var nodeValue = Element.readAttribute(node, attr); 2444 if (nodeValue === null) continue; 2445 if (handler(nodeValue, value)) results.push(node); 2446 } 2447 return results; 2448 }, 2449 2450 pseudo: function(nodes, name, value, root, combinator) { 2451 if (nodes && combinator) nodes = this[combinator](nodes); 2452 if (!nodes) nodes = root.getElementsByTagName("*"); 2453 return Selector.pseudos[name](nodes, value, root); 2454 } 1840 2455 }, 1841 2456 1842 toString: function() { 1843 return this.expression; 1844 } 1845 } 2457 pseudos: { 2458 'first-child': function(nodes, value, root) { 2459 for (var i = 0, results = [], node; node = nodes[i]; i++) { 2460 if (Selector.handlers.previousElementSibling(node)) continue; 2461 results.push(node); 2462 } 2463 return results; 2464 }, 2465 'last-child': function(nodes, value, root) { 2466 for (var i = 0, results = [], node; node = nodes[i]; i++) { 2467 if (Selector.handlers.nextElementSibling(node)) continue; 2468 results.push(node); 2469 } 2470 return results; 2471 }, 2472 'only-child': function(nodes, value, root) { 2473 var h = Selector.handlers; 2474 for (var i = 0, results = [], node; node = nodes[i]; i++) 2475 if (!h.previousElementSibling(node) && !h.nextElementSibling(node)) 2476 results.push(node); 2477 return results; 2478 }, 2479 'nth-child': function(nodes, formula, root) { 2480 return Selector.pseudos.nth(nodes, formula, root); 2481 }, 2482 'nth-last-child': function(nodes, formula, root) { 2483 return Selector.pseudos.nth(nodes, formula, root, true); 2484 }, 2485 'nth-of-type': function(nodes, formula, root) { 2486 return Selector.pseudos.nth(nodes, formula, root, false, true); 2487 }, 2488 'nth-last-of-type': function(nodes, formula, root) { 2489 return Selector.pseudos.nth(nodes, formula, root, true, true); 2490 }, 2491 'first-of-type': function(nodes, formula, root) { 2492 return Selector.pseudos.nth(nodes, "1", root, false, true); 2493 }, 2494 'last-of-type': function(nodes, formula, root) { 2495 return Selector.pseudos.nth(nodes, "1", root, true, true); 2496 }, 2497 'only-of-type': function(nodes, formula, root) { 2498 var p = Selector.pseudos; 2499 return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root); 2500 }, 1846 2501 1847 Object.extend(Selector, { 2502 // handles the an+b logic 2503 getIndices: function(a, b, total) { 2504 if (a == 0) return b > 0 ? [b] : []; 2505 return $R(1, total).inject([], function(memo, i) { 2506 if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i); 2507 return memo; 2508 }); 2509 }, 2510 2511 // handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type 2512 nth: function(nodes, formula, root, reverse, ofType) { 2513 if (nodes.length == 0) return []; 2514 if (formula == 'even') formula = '2n+0'; 2515 if (formula == 'odd') formula = '2n+1'; 2516 var h = Selector.handlers, results = [], indexed = [], m; 2517 h.mark(nodes); 2518 for (var i = 0, node; node = nodes[i]; i++) { 2519 if (!node.parentNode._counted) { 2520 h.index(node.parentNode, reverse, ofType); 2521 indexed.push(node.parentNode); 2522 } 2523 } 2524 if (formula.match(/^\d+$/)) { // just a number 2525 formula = Number(formula); 2526 for (var i = 0, node; node = nodes[i]; i++) 2527 if (node.nodeIndex == formula) results.push(node); 2528 } else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b 2529 if (m[1] == "-") m[1] = -1; 2530 var a = m[1] ? Number(m[1]) : 1; 2531 var b = m[2] ? Number(m[2]) : 0; 2532 var indices = Selector.pseudos.getIndices(a, b, nodes.length); 2533 for (var i = 0, node, l = indices.length; node = nodes[i]; i++) { 2534 for (var j = 0; j < l; j++) 2535 if (node.nodeIndex == indices[j]) results.push(node); 2536 } 2537 } 2538 h.unmark(nodes); 2539 h.unmark(indexed); 2540 return results; 2541 }, 2542 2543 'empty': function(nodes, value, root) { 2544 for (var i = 0, results = [], node; node = nodes[i]; i++) { 2545 // IE treats comments as element nodes 2546 if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue; 2547 results.push(node); 2548 } 2549 return results; 2550 }, 2551 2552 'not': function(nodes, selector, root) { 2553 var h = Selector.handlers, selectorType, m; 2554 var exclusions = new Selector(selector).findElements(root); 2555 h.mark(exclusions); 2556 for (var i = 0, results = [], node; node = nodes[i]; i++) 2557 if (!node._counted) results.push(node); 2558 h.unmark(exclusions); 2559 return results; 2560 }, 2561 2562 'enabled': function(nodes, value, root) { 2563 for (var i = 0, results = [], node; node = nodes[i]; i++) 2564 if (!node.disabled) results.push(node); 2565 return results; 2566 }, 2567 2568 'disabled': function(nodes, value, root) { 2569 for (var i = 0, results = [], node; node = nodes[i]; i++) 2570 if (node.disabled) results.push(node); 2571 return results; 2572 }, 2573 2574 'checked': function(nodes, value, root) { 2575 for (var i = 0, results = [], node; node = nodes[i]; i++) 2576 if (node.checked) results.push(node); 2577 return results; 2578 } 2579 }, 2580 2581 operators: { 2582 '=': function(nv, v) { return nv == v; }, 2583 '!=': function(nv, v) { return nv != v; }, 2584 '^=': function(nv, v) { return nv.startsWith(v); }, 2585 '$=': function(nv, v) { return nv.endsWith(v); }, 2586 '*=': function(nv, v) { return nv.include(v); }, 2587 '~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); }, 2588 '|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); } 2589 }, 2590 1848 2591 matchElements: function(elements, expression) { 1849 var selector = new Selector(expression); 1850 return elements.select(selector.match.bind(selector)).map(Element.extend); 2592 var matches = new Selector(expression).findElements(), h = Selector.handlers; 2593 h.mark(matches); 2594 for (var i = 0, results = [], element; element = elements[i]; i++) 2595 if (element._counted) results.push(element); 2596 h.unmark(matches); 2597 return results; 1851 2598 }, 1852 2599 1853 2600 findElement: function(elements, expression, index) { 1854 if (typeof expression == 'number') index = expression, expression = false; 2601 if (typeof expression == 'number') { 2602 index = expression; expression = false; 2603 } 1855 2604 return Selector.matchElements(elements, expression || '*')[index || 0]; 1856 2605 }, 1857 2606 1858 2607 findChildElements: function(element, expressions) { 1859 return expressions.map(function(expression) { 1860 return expression.match(/[^\s"]+(?:"[^"]*"[^\s"]+)*/g).inject([null], function(results, expr) { 1861 var selector = new Selector(expr); 1862 return results.inject([], function(elements, result) { 1863 return elements.concat(selector.findElements(result || element)); 1864 }); 1865 }); 1866 }).flatten(); 2608 var exprs = expressions.join(','), expressions = []; 2609 exprs.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) { 2610 expressions.push(m[1].strip()); 2611 }); 2612 var results = [], h = Selector.handlers; 2613 for (var i = 0, l = expressions.length, selector; i < l; i++) { 2614 selector = new Selector(expressions[i].strip()); 2615 h.concat(results, selector.findElements(element)); 2616 } 2617 return (l > 1) ? h.unique(results) : results; 1867 2618 } 1868 2619 }); 1869 2620 … … 1880 2631 var data = elements.inject({}, function(result, element) { 1881 2632 if (!element.disabled && element.name) { 1882 2633 var key = element.name, value = $(element).getValue(); 1883 if (value != undefined) {1884 if (result[key]) {2634 if (value != null) { 2635 if (key in result) { 1885 2636 if (result[key].constructor != Array) result[key] = [result[key]]; 1886 2637 result[key].push(value); 1887 2638 } … … 1928 2679 1929 2680 disable: function(form) { 1930 2681 form = $(form); 1931 form.getElements().each(function(element) { 1932 element.blur(); 1933 element.disabled = 'true'; 1934 }); 2682 Form.getElements(form).invoke('disable'); 1935 2683 return form; 1936 2684 }, 1937 2685 1938 2686 enable: function(form) { 1939 2687 form = $(form); 1940 form.getElements().each(function(element) { 1941 element.disabled = ''; 1942 }); 2688 Form.getElements(form).invoke('enable'); 1943 2689 return form; 1944 2690 }, 1945 2691 … … 1954 2700 form = $(form); 1955 2701 form.findFirstElement().activate(); 1956 2702 return form; 2703 }, 2704 2705 request: function(form, options) { 2706 form = $(form), options = Object.clone(options || {}); 2707 2708 var params = options.parameters; 2709 options.parameters = form.serialize(true); 2710 2711 if (params) { 2712 if (typeof params == 'string') params = params.toQueryParams(); 2713 Object.extend(options.parameters, params); 2714 } 2715 2716 if (form.hasAttribute('method') && !options.method) 2717 options.method = form.method; 2718 2719 return new Ajax.Request(form.readAttribute('action'), options); 1957 2720 } 1958 2721 } 1959 2722 1960 Object.extend(Form, Form.Methods);1961 1962 2723 /*--------------------------------------------------------------------------*/ 1963 2724 1964 2725 Form.Element = { … … 2004 2765 2005 2766 activate: function(element) { 2006 2767 element = $(element); 2007 element.focus(); 2008 if (element.select && ( element.tagName.toLowerCase() != 'input' || 2009 !['button', 'reset', 'submit'].include(element.type) ) ) 2010 element.select(); 2768 try { 2769 element.focus(); 2770 if (element.select && (element.tagName.toLowerCase() != 'input' || 2771 !['button', 'reset', 'submit'].include(element.type))) 2772 element.select(); 2773 } catch (e) {} 2011 2774 return element; 2012 2775 }, 2013 2776 2014 2777 disable: function(element) { 2015 2778 element = $(element); 2779 element.blur(); 2016 2780 element.disabled = true; 2017 2781 return element; 2018 2782 }, 2019 2783 2020 2784 enable: function(element) { 2021 2785 element = $(element); 2022 element.blur();2023 2786 element.disabled = false; 2024 2787 return element; 2025 2788 } 2026 2789 } 2027 2790 2028 Object.extend(Form.Element, Form.Element.Methods); 2791 /*--------------------------------------------------------------------------*/ 2792 2029 2793 var Field = Form.Element; 2030 var $F = Form.Element. getValue;2794 var $F = Form.Element.Methods.getValue; 2031 2795 2032 2796 /*--------------------------------------------------------------------------*/ 2033 2797 … … 2194 2958 KEY_PAGEDOWN: 34, 2195 2959 2196 2960 element: function(event) { 2197 return event.target || event.srcElement;2961 return $(event.target || event.srcElement); 2198 2962 }, 2199 2963 2200 2964 isLeftClick: function(event) { … … 2259 3023 useCapture = useCapture || false; 2260 3024 2261 3025 if (name == 'keypress' && 2262 (navigator.appVersion.match(/Konqueror|Safari|KHTML/) 2263 || element.attachEvent)) 3026 (Prototype.Browser.WebKit || element.attachEvent)) 2264 3027 name = 'keydown'; 2265 3028 2266 3029 Event._observeAndCache(element, name, observer, useCapture); … … 2271 3034 useCapture = useCapture || false; 2272 3035 2273 3036 if (name == 'keypress' && 2274 (navigator.appVersion.match(/Konqueror|Safari|KHTML/) 2275 || element.detachEvent)) 3037 (Prototype.Browser.WebKit || element.attachEvent)) 2276 3038 name = 'keydown'; 2277 3039 2278 3040 if (element.removeEventListener) { … … 2286 3048 }); 2287 3049 2288 3050 /* prevent memory leaks in IE */ 2289 if ( navigator.appVersion.match(/\bMSIE\b/))3051 if (Prototype.Browser.IE) 2290 3052 Event.observe(window, 'unload', Event.unloadCache, false); 2291 3053 var Position = { 2292 3054 // set to true if needed, warning: firefox performance problems … … 2400 3162 valueL += element.offsetLeft || 0; 2401 3163 2402 3164 // Safari fix 2403 if (element.offsetParent ==document.body)3165 if (element.offsetParent == document.body) 2404 3166 if (Element.getStyle(element,'position')=='absolute') break; 2405 3167 2406 3168 } while (element = element.offsetParent); … … 2496 3258 // Safari returns margins on body which is incorrect if the child is absolutely 2497 3259 // positioned. For performance reasons, redefine Position.cumulativeOffset for 2498 3260 // KHTML/WebKit only. 2499 if ( /Konqueror|Safari|KHTML/.test(navigator.userAgent)) {3261 if (Prototype.Browser.WebKit) { 2500 3262 Position.cumulativeOffset = function(element) { 2501 3263 var valueT = 0, valueL = 0; 2502 3264 do { -
wp-includes/js/scriptaculous/scriptaculous.js
1 // script.aculo.us scriptaculous.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us scriptaculous.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // … … 24 24 // For details, see the script.aculo.us web site: http://script.aculo.us/ 25 25 26 26 var Scriptaculous = { 27 Version: '1.7.1_beta 2',27 Version: '1.7.1_beta3', 28 28 require: function(libraryName) { 29 29 // inserting via DOM fails in Safari 2.0, so brute force approach 30 30 document.write('<script type="text/javascript" src="'+libraryName+'"></script>'); -
wp-includes/js/scriptaculous/slider.js
1 // script.aculo.us slider.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us slider.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Marty Haught, Thomas Fuchs 4 4 // -
wp-includes/js/scriptaculous/sound.js
1 // script.aculo.us sound.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us sound.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // -
wp-includes/js/scriptaculous/unittest.js
1 // script.aculo.us unittest.js v1.7.1_beta 2, Sat Apr 28 15:20:12 CEST20071 // script.aculo.us unittest.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 2 3 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 4 4 // (c) 2005-2007 Jon Tirsen (http://www.tirsen.com) -
wp-includes/js/scriptaculous/wp-scriptaculous.js
1 // Copyright (c) 2005 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 1 // script.aculo.us scriptaculous.js v1.7.1_beta3, Fri May 25 17:19:41 +0200 2007 2 3 // Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us) 2 4 // 3 5 // Permission is hereby granted, free of charge, to any person obtaining 4 6 // a copy of this software and associated documentation files (the … … 10 12 // 11 13 // The above copyright notice and this permission notice shall be 12 14 // included in all copies or substantial portions of the Software. 15 // 16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 // 24 // For details, see the script.aculo.us web site: http://script.aculo.us/ 13 25 14 26 var Scriptaculous = { 15 Version: '1.7. 0',27 Version: '1.7.1_beta3', 16 28 require: function(libraryName) { 17 29 // inserting via DOM fails in Safari 2.0, so brute force approach 18 30 document.write('<script type="text/javascript" src="'+libraryName+'"></script>'); 19 31 }, 32 REQUIRED_PROTOTYPE: '1.5.1', 20 33 load: function() { 34 function convertVersionString(versionString){ 35 var r = versionString.split('.'); 36 return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]); 37 } 38 21 39 if((typeof Prototype=='undefined') || 22 40 (typeof Element == 'undefined') || 23 41 (typeof Element.Methods=='undefined') || 24 parseFloat(Prototype.Version.split(".")[0] + "." + 25 Prototype.Version.split(".")[1]) < 1.5) 26 throw("script.aculo.us requires the Prototype JavaScript framework >= 1.5.0"); 42 (convertVersionString(Prototype.Version) < 43 convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE))) 44 throw("script.aculo.us requires the Prototype JavaScript framework >= " + 45 Scriptaculous.REQUIRED_PROTOTYPE); 27 46 28 47 $A(document.getElementsByTagName("script")).findAll( function(s) { 29 48 return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/)) 30 49 }).each( function(s) { 31 50 var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,''); 32 51 var includes = s.src.match(/\?.*load=([a-z,]*)/); 33 if ( includes ) 34 includes[1].split(',').each( 52 (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each( 35 53 function(include) { Scriptaculous.require(path+include+'.js') }); 36 54 }); 37 55 } 38 56 } 39 57 40 Scriptaculous.load(); 58 Scriptaculous.load(); 59 No newline at end of file
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)