From b8e23e37dd2342d156b36480662e6fe31b12d0ad Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Mon, 27 Mar 2006 05:47:17 +0000 Subject: Update to Prototype 1.5.0_pre1 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4063 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/html/javascripts/prototype.js | 36 +++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'railties/html/javascripts/prototype.js') diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js index 5c939795c8..2d4ba34c18 100644 --- a/railties/html/javascripts/prototype.js +++ b/railties/html/javascripts/prototype.js @@ -1,4 +1,4 @@ -/* Prototype JavaScript framework, version 1.5.0_pre0 +/* Prototype JavaScript framework, version 1.5.0_pre1 * (c) 2005 Sam Stephenson * * Prototype is freely distributable under the terms of an MIT-style license. @@ -7,7 +7,7 @@ /*--------------------------------------------------------------------------*/ var Prototype = { - Version: '1.5.0_pre0', + Version: '1.5.0_pre1', ScriptFragment: '(?:)((\n|\r|.)*?)(?:<\/script>)', emptyFunction: function() {}, @@ -1251,9 +1251,16 @@ Selector.prototype = { function abort(message) { throw 'Parse error in selector: ' + message; } if (this.expression == '') abort('empty expression'); - if (this.expression == '*') return this.params.wildcard = true; var params = this.params, expr = this.expression, match, modifier, clause, rest; + while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) { + params.attributes = params.attributes || []; + params.attributes.push({name: match[2], operator: match[3], value: match[4] || match[5] || ''}); + expr = match[1]; + } + + if (expr == '*') return this.params.wildcard = true; + while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+)(.*)/i)) { modifier = match[1], clause = match[2], rest = match[3]; switch (modifier) { @@ -1273,8 +1280,7 @@ Selector.prototype = { var params = this.params, conditions = [], clause; if (params.wildcard) - return 'true'; - + conditions.push('true'); if (clause = params.id) conditions.push('element.id == ' + clause.inspect()); if (clause = params.tagName) @@ -1282,6 +1288,26 @@ Selector.prototype = { if ((clause = params.classNames).length > 0) for (var i = 0; i < clause.length; i++) conditions.push('Element.hasClassName(element, ' + clause[i].inspect() + ')'); + if (clause = params.attributes) { + clause.each(function(attribute) { + var value = 'element.getAttribute(' + attribute.name.inspect() + ')'; + var splitValueBy = function(delimiter) { + return value + ' && ' + value + '.split(' + delimiter.inspect() + ')'; + } + + switch (attribute.operator) { + case '=': conditions.push(value + ' == ' + attribute.value.inspect()); break; + case '~=': conditions.push(splitValueBy(' ') + '.include(' + attribute.value.inspect() + ')'); break; + case '|=': conditions.push( + splitValueBy('-') + '.first().toUpperCase() == ' + attribute.value.toUpperCase().inspect() + ); break; + case '!=': conditions.push(value + ' != ' + attribute.value.inspect()); break; + case '': + case undefined: conditions.push(value + ' != null'); break; + default: throw 'Unknown operator ' + attribute.operator + ' in selector'; + } + }); + } return conditions.join(' && '); }, -- cgit v1.2.3