diff --git a/ext/update_helper/prototype_update_helper.html b/ext/update_helper/prototype_update_helper.html index b2d355d..b5aa69f 100644 --- a/ext/update_helper/prototype_update_helper.html +++ b/ext/update_helper/prototype_update_helper.html @@ -280,6 +280,38 @@ this.assertNotNotified(); }, + testSelectorInstanceMethods: function() { + var selector = new Selector('div'); + this.assertWarnNotified('The Selector class has been deprecated. Please use the new Prototype.Selector API instead.'); + + selector.findElements(document); + this.assertWarnNotified('Selector#findElements has been deprecated. Please use the new Prototype.Selector API instead.'); + + selector.match(document.documentElement); + this.assertWarnNotified('Selector#match has been deprecated. Please use the new Prototype.Selector API instead.'); + + selector.toString(); + this.assertWarnNotified('Selector#toString has been deprecated. Please use the new Prototype.Selector API instead.'); + + selector.inspect(); + this.assertWarnNotified('Selector#inspect has been deprecated. Please use the new Prototype.Selector API instead.'); + }, + + testSelectorMatchElements: function() { + Selector.matchElements([], 'div'); + this.assertWarnNotified('Selector.matchElements has been deprecated. Please use the new Prototype.Selector API instead.'); + }, + + testSelectorFindElement: function() { + Selector.findElement([], 'div'); + this.assertWarnNotified('Selector.findElement has been deprecated. Please use the new Prototype.Selector API instead.'); + }, + + testSelectorFindChildElements: function() { + Selector.findChildElements(document, 'div'); + this.assertWarnNotified('Selector.findChildElements has been deprecated. Please use the new Prototype.Selector API instead.'); + }, + testLogDeprecationOption: function() { prototypeUpdateHelper.logLevel = UpdateHelper.Warn; var h = $H({ foo: 2 }); diff --git a/ext/update_helper/prototype_update_helper.js b/ext/update_helper/prototype_update_helper.js index e5107ca..353deee 100644 --- a/ext/update_helper/prototype_update_helper.js +++ b/ext/update_helper/prototype_update_helper.js @@ -275,6 +275,62 @@ var prototypeUpdateHelper = new UpdateHelper([ message: 'The class API has been fully revised and now allows for mixins and inheritance.\n' + 'You can find more about it here: http://prototypejs.org/learn/class-inheritance', condition: function() { return !arguments.length } + }, + + { + methodName: 'initialize', + namespace: Selector.prototype, + message: 'The Selector class has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'findElements', + namespace: Selector.prototype, + message: 'Selector#findElements has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'match', + namespace: Selector.prototype, + message: 'Selector#match has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'toString', + namespace: Selector.prototype, + message: 'Selector#toString has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'inspect', + namespace: Selector.prototype, + message: 'Selector#inspect has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'matchElements', + namespace: Selector, + message: 'Selector.matchElements has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'findElement', + namespace: Selector, + message: 'Selector.findElement has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' + }, + + { + methodName: 'findChildElements', + namespace: Selector, + message: 'Selector.findChildElements has been deprecated. Please use the new Prototype.Selector API instead.', + type: 'warn' } ]); diff --git a/src/deprecated.js b/src/deprecated.js index c5ea33e..c008d66 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -184,3 +184,95 @@ Element.ClassNames.prototype = { Object.extend(Element.ClassNames.prototype, Enumerable); /*--------------------------------------------------------------------------*/ + +/** deprecated, section: DOM + * class Selector + * + * A class that queries the document for elements that match a given CSS + * selector. +**/ +(function() { + window.Selector = Class.create({ + /** deprecated + * new Selector(expression) + * - expression (String): A CSS selector. + * + * Creates a `Selector` with the given CSS selector. + **/ + initialize: function(expression) { + this.expression = expression.strip(); + }, + + /** deprecated + * Selector#findElements(root) -> [Element...] + * - root (Element | document): A "scope" to search within. All results will + * be descendants of this node. + * + * Searches the document for elements that match the instance's CSS + * selector. + **/ + findElements: function(rootElement) { + return Prototype.Selector.select(this.expression, rootElement); + }, + + /** deprecated + * Selector#match(element) -> Boolean + * + * Tests whether a `element` matches the instance's CSS selector. + **/ + match: function(element) { + return Prototype.Selector.match(element, this.expression); + }, + + toString: function() { + return this.expression; + }, + + inspect: function() { + return "#"; + } + }); + + Object.extend(Selector, { + /** deprecated + * Selector.matchElements(elements, expression) -> [Element...] + * + * Filters the given collection of elements with `expression`. + * + * The only nodes returned will be those that match the given CSS selector. + **/ + matchElements: Prototype.Selector.filter, + + /** deprecated + * Selector.findElement(elements, expression[, index = 0]) -> Element + * Selector.findElement(elements[, index = 0]) -> Element + * + * Returns the `index`th element in the collection that matches + * `expression`. + * + * Returns the `index`th element overall if `expression` is not given. + **/ + findElement: function(elements, expression, index) { + index = index || 0; + var matchIndex = 0, element; + // Match each element individually, since Sizzle.matches does not preserve order + for (var i = 0, length = elements.length; i < length; i++) { + element = elements[i]; + if (Prototype.Selector.match(element, expression) && index === matchIndex++) { + return Element.extend(element); + } + } + }, + + /** deprecated + * Selector.findChildElements(element, expressions) -> [Element...] + * + * Searches beneath `element` for any elements that match the selector + * (or selectors) specified in `expressions`. + **/ + findChildElements: function(element, expressions) { + var selector = expressions.toArray().join(', '); + return Prototype.Selector.select(selector, element || document); + } + }); +})(); diff --git a/src/dom/selector.js b/src/dom/selector.js index d079f66..e0e5d40 100644 --- a/src/dom/selector.js +++ b/src/dom/selector.js @@ -1,96 +1,4 @@ -/** deprecated, section: DOM - * class Selector - * - * A class that queries the document for elements that match a given CSS - * selector. -**/ -(function() { - window.Selector = Class.create({ - /** deprecated - * new Selector(expression) - * - expression (String): A CSS selector. - * - * Creates a `Selector` with the given CSS selector. - **/ - initialize: function(expression) { - this.expression = expression.strip(); - }, - - /** deprecated - * Selector#findElements(root) -> [Element...] - * - root (Element || document): A "scope" to search within. All results will - * be descendants of this node. - * - * Searches the document for elements that match the instance's CSS - * selector. - **/ - findElements: function(rootElement) { - return Prototype.Selector.select(this.expression, rootElement); - }, - - /** deprecated - * Selector#match(element) -> Boolean - * - * Tests whether a `element` matches the instance's CSS selector. - **/ - match: function(element) { - return Prototype.Selector.match(element, this.expression); - }, - - toString: function() { - return this.expression; - }, - - inspect: function() { - return "#"; - } - }); - - Object.extend(Selector, { - /** deprecated - * Selector.matchElements(elements, expression) -> [Element...] - * - * Filters the given collection of elements with `expression`. - * - * The only nodes returned will be those that match the given CSS selector. - **/ - matchElements: Prototype.Selector.filter, - - /** deprecated - * Selector.findElement(elements, expression[, index = 0]) -> Element - * Selector.findElement(elements[, index = 0]) -> Element - * - * Returns the `index`th element in the collection that matches - * `expression`. - * - * Returns the `index`th element overall if `expression` is not given. - **/ - findElement: function(elements, expression, index) { - index = index || 0; - var matchIndex = 0, element; - // Match each element individually, since Sizzle.matches does not preserve order - for (var i = 0, length = elements.length; i < length; i++) { - element = elements[i]; - if (Prototype.Selector.match(element, expression) && index === matchIndex++) { - return Element.extend(element); - } - } - }, - - /** deprecated - * Selector.findChildElements(element, expressions) -> [Element...] - * - * Searches beneath `element` for any elements that match the selector - * (or selectors) specified in `expressions`. - **/ - findChildElements: function(element, expressions) { - var selector = expressions.toArray().join(', '); - return Prototype.Selector.select(selector, element || document); - } - }); -})(); - -/** related to: Selector +/** related to: Prototype.Selector * $$(expression...) -> [Element...] * * Returns all elements in the document that match the provided CSS selectors.