diff --git a/CHANGELOG b/CHANGELOG
index 34b6e12..e6000d0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel]
+
* Make Element#writeAttribute handle frameborder attribute in IE. Closes #11068. [staaky, Tobie Langel]
* Minor clean-up of selector.js. Closes #10844. [RQuadling]
diff --git a/Rakefile b/Rakefile
index c100190..5584402 100644
--- a/Rakefile
+++ b/Rakefile
@@ -7,7 +7,7 @@ PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
PROTOTYPE_VERSION = '1.6.0.2'
-task :default => [:dist, :package, :clean_package_source]
+task :default => [:dist, :dist_helper, :package, :clean_package_source]
desc "Builds the distribution"
task :dist do
@@ -21,6 +21,18 @@ task :dist do
end
end
+desc "Builds the updating helper"
+task :dist_helper do
+ $:.unshift File.join(PROTOTYPE_ROOT, 'lib')
+ require 'protodoc'
+
+ Dir.chdir(File.join(PROTOTYPE_ROOT, 'ext', 'update_helper')) do
+ File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype_update_helper.js'), 'w+') do |dist|
+ dist << Protodoc::Preprocessor.new('prototype_update_helper.js')
+ end
+ end
+end
+
Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
package.need_tar_gz = true
package.package_dir = PROTOTYPE_PKG_DIR
diff --git a/ext/deprecation/deprecation_test.html b/ext/update_helper/prototype_update_helper.html
similarity index 53%
rename from ext/deprecation/deprecation_test.html
rename to ext/update_helper/prototype_update_helper.html
index 470573a..0649b07 100644
--- a/ext/deprecation/deprecation_test.html
+++ b/ext/update_helper/prototype_update_helper.html
@@ -5,7 +5,7 @@
Prototype Unit test file
-
+
@@ -29,8 +29,8 @@
message: [],
type: []
};
- DeprecationNotifier.notify = DeprecationNotifier.notify.wrap(function(proceed, message, type) {
- if (!proceed(message, type)) return; // DeprecationNotifier.notify return false if the message is not logged.
+ prototypeUpdateHelper.notify = prototypeUpdateHelper.notify.wrap(function(proceed, message, type) {
+ if (!proceed(message, type)) return; // UpdateHelper#notify return false if the message is not logged.
log.message.push(message);
log.type.push(type);
});
@@ -40,29 +40,29 @@
}
Test.Unit.Testcase.addMethods({
- assertDeprecationNotified: function(expected) {
+ assertInfoNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
- this.assertEqual(expected, actualMessage, 'assertDeprecationNotified');
- this.assertEqual('deprecation', actualType, 'assertDeprecationNotified');
+ this.assertEqual(expected, actualMessage, 'assertInfoNotified');
+ this.assertEqual('info', actualType, 'assertInfoNotified');
log.message.push(null);
log.type.push(null);
},
- assertRemovalNotified: function(expected) {
+ assertErrorNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
- this.assertEqual(expected, actualMessage, 'assertRemovalNotified');
- this.assertEqual('removal', actualType, 'assertRemovalNotified');
+ this.assertEqual(expected, actualMessage, 'assertErrorNotified');
+ this.assertEqual('error', actualType, 'assertErrorNotified');
log.message.push(null);
log.type.push(null);
},
- assertModificationNotified: function(expected) {
+ assertWarnNotified: function(expected) {
var actualMessage = log.message.beforeLast() || log.message.last();
var actualType = log.type.beforeLast() || log.type.last();
- this.assertEqual(expected, actualMessage, 'assertModificationNotified');
- this.assertEqual('modification', actualType, 'assertModificationNotified');
+ this.assertEqual(expected, actualMessage, 'assertWarnNotified');
+ this.assertEqual('warn', actualType, 'assertWarnNotified');
log.message.push(null);
log.type.push(null);
},
@@ -77,15 +77,15 @@
new Test.Unit.Runner({
testGetStack: function(){ with(this) {
- assertMatch(/deprecation_test\.html:\d+\n$/, DeprecationNotifier.getStack());
+ assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());
}},
testDisplay: function(){ with(this) {
Toggle.display('foo');
- assertDeprecationNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
+ assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
Element.show('foo', 'bar', 'bla');
- assertRemovalNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
+ assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.');
$('foo', 'bar', 'bla').each(Element.hide);
@@ -95,11 +95,11 @@
assertNotNotified();
Element.hide('foo', 'bar', 'bla');
- assertRemovalNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
+ assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.');
Element.toggle('foo', 'bar', 'bla');
- assertRemovalNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
+ assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.');
}},
@@ -108,41 +108,41 @@
assertNotNotified();
Element.setStyle('foo', { 'font-size': '18px' });
- assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
+ assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
Element.setStyle('foo', 'font-size: 18px;');
assertNotNotified();
$('foo').setStyle({ 'font-size': '18px' });
- assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
+ assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
}},
testClassNames: function(){ with(this) {
new Element.ClassNames('foo');
- assertDeprecationNotified('Element.ClassNames has been deprecated.')
+ assertInfoNotified('Element.ClassNames has been deprecated.')
$('foo').classNames();
- assertDeprecationNotified('Element#classNames has been deprecated.\n' +
+ assertInfoNotified('Element#classNames has been deprecated.\n' +
'If you need to access CSS class names as an array, try: $w(element.classname).')
Element.getElementsByClassName('foo', 'className');
- assertDeprecationNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
+ assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
document.getElementsByClassName('className');
- assertDeprecationNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
+ assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
}},
testDomSelectors: function(){ with(this) {
Element.childOf('foo', 'bar');
- assertDeprecationNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
+ assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
$('foo').immediateDescendants();
- assertDeprecationNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
+ assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
$('foo').getElementsBySelector('a');
- assertDeprecationNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
+ assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
$('foo').select('a');
assertNotNotified();
@@ -150,109 +150,109 @@
testField: function(){ with(this) {
Field.clear('foo', 'bar', 'bla');
- assertRemovalNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
+ assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.');
Field.present('foo', 'bar', 'bla');
- assertRemovalNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
+ assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.');
}},
testInsertion: function(){ with(this) {
Insertion.Before('foo', 'text');
- assertDeprecationNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
+ assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
Insertion.Top('foo', 'text');
- assertDeprecationNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
+ assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
Insertion.Bottom('foo', 'text');
- assertDeprecationNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
+ assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
Insertion.After('foo', 'text');
- assertDeprecationNotified('Insertion.After has been deprecated, please use Element#insert instead.');
+ assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');
}},
testPosition: function(){ with(this) {
Position.prepare('foo');
- assertDeprecationNotified('Position.prepare has been deprecated.');
+ assertInfoNotified('Position.prepare has been deprecated.');
Position.within('foo');
- assertDeprecationNotified('Position.within has been deprecated.');
+ assertInfoNotified('Position.within has been deprecated.');
Position.withinIncludingScrolloffsets('foo');
- assertDeprecationNotified('Position.withinIncludingScrolloffsets has been deprecated.');
+ assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');
Position.overlap('foo');
- assertDeprecationNotified('Position.overlap has been deprecated.');
+ assertInfoNotified('Position.overlap has been deprecated.');
Position.cumulativeOffset('foo');
- assertDeprecationNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
+ assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
Position.positionedOffset('foo');
- assertDeprecationNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
+ assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
Position.absolutize('foo');
- assertDeprecationNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
+ assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
Position.relativize('foo');
- assertDeprecationNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
+ assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
Position.realOffset('foo');
- assertDeprecationNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
+ assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
Position.offsetParent('foo');
- assertDeprecationNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
+ assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
Position.page('foo');
- assertDeprecationNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
+ assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
Position.clone('foo', 'bar');
- assertDeprecationNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
+ assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
}},
testEvent: function(){ with(this) {
Event.unloadCache();
- assertRemovalNotified('Event.unloadCache has been deprecated.')
+ assertErrorNotified('Event.unloadCache has been deprecated.')
}},
testHash: function(){ with(this) {
Hash.toQueryString({});
- assertDeprecationNotified('Hash.toQueryString has been deprecated.\n' +
+ assertInfoNotified('Hash.toQueryString has been deprecated.\n' +
'Use the instance method Hash#toQueryString or Object.toQueryString instead.');
Hash.toJSON({});
- assertRemovalNotified('Hash.toJSON has been removed.\n' +
+ assertErrorNotified('Hash.toJSON has been removed.\n' +
'Use the instance method Hash#toJSON or Object.toJSON instead.');
var h = $H({ foo: 2 });
h.remove('foo');
- assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
+ assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
'Please note that Hash#unset only accepts one argument.');
h.merge('foo');
- assertModificationNotified('Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
+ assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
h['foo'];
- assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
+ assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
'Please use Hash#get(\'foo\') instead.')
h.foo = 3;
- assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
+ assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'foo\', 3) instead.')
h.bar = 'bar';
h.toJSON();
- assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
+ assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'bar\', \'bar\') instead.')
h.bar;
- assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
+ assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
'Please use Hash#get(\'bar\') instead.')
h.baz = 'baz';
h.bar;
- assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
+ assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
'Please use Hash#set(\'baz\', \'baz\') instead.')
h.set('toJSON', 'arg'); // make sure hash methods are not overwritten
@@ -261,26 +261,26 @@
testClass: function(){ with(this) {
Class.create();
- assertDeprecationNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
+ assertInfoNotified('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');
Class.create({});
assertNotNotified();
}},
testLogDeprecationOption: function(){ with(this) {
- DeprecationNotifier.logDeprecation = false;
+ prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
var h = $H({ foo: 2 });
h.merge({ foo: 3 });
- assertModificationNotified('Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
+ assertWarnNotified('Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' + 'If you need a destructive merge, use Hash#update instead.');
h.remove('foo');
- assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
+ assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
'Please note that Hash#unset only accepts one argument.');
document.getElementsByClassName('className');
assertNotNotified();
- DeprecationNotifier.logDeprecation = true;
+ prototypeUpdateHelper.logLevel = UpdateHelper.Info;
}}
});
diff --git a/ext/deprecation/deprecation.js b/ext/update_helper/prototype_update_helper.js
similarity index 78%
rename from ext/deprecation/deprecation.js
rename to ext/update_helper/prototype_update_helper.js
index 2db80e1..c3ce2f2 100644
--- a/ext/deprecation/deprecation.js
+++ b/ext/update_helper/prototype_update_helper.js
@@ -1,73 +1,26 @@
-/* Prototype Deprecation Notifier for Prototype 1.6.0.2
- * (c) 2008 Tobie Langel
+<%= include "update_helper.js" %>
+
+/* UpdateHelper for Prototype <%= PROTOTYPE_VERSION %> (c) 2008 Tobie Langel
+ *
+ * UpdateHelper for Prototype is freely distributable under the same
+ * terms as Prototype (MIT-style license).
+ * For details, see the Prototype web site: http://www.prototypejs.org/
+ *
+ * Include this file right below prototype.js. All messages
+ * will be logged to the console.
+ *
+ * Note: You can tune the level of warning by redefining
+ * prototypeUpdateHelper.logLevel with one of the appropriate constansts
+ * (UpdateHelper.Info, UpdateHelper.Warn or UpdateHelper.Error), e.g.:
+ *
+ * prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
*
- * Prototype Deprecation Notifier is freely distributable under the same
- * terms as Prototype (MIT-style license).
- * For details, see the Prototype web site: http://www.prototypejs.org/
- *
- * Include this file right below prototype.js. All warning messages
- * will be logged to the console.
- *
- * Note: You can turn off deprecation messages (and log only removal and
- * modification messages) by specifying:
- * DeprecationNotifier.logDeprecation = false;
+ * This, for example, will prevent deprecation messages from being logged.
*
* THIS SCRIPT WORKS IN FIREFOX ONLY
*--------------------------------------------------------------------------*/
-var DeprecationNotifier = {
- logDeprecation: true,
- MessageTemplate: new Template('Prototype #{type} Warning: #{message}\n#{stack}'),
- Regexp: new RegExp("@" + window.location.protocol + ".*?\\d+\\n", "g"),
-
- init: function(deprecatedMethods) {
- if (!Prototype.Browser.Gecko) return;
- deprecatedMethods.each(function(d) {
- var condition = d.condition,
- type = d.type || 'deprecation',
- message = d.message,
- namespace = d.namespace,
- method = d.methodName;
-
- namespace[method] = (namespace[method] || function() {}).wrap(function(proceed) {
- var args = $A(arguments).splice(1);
- if (!condition || condition.apply(this, args))
- DeprecationNotifier.notify(message, type);
- return proceed.apply(proceed, args);
- });
- });
- Element.addMethods();
- },
-
- notify: function(message, type) {
- if (type == 'deprecation' && !DeprecationNotifier.logDeprecation)
- return false;
- this.log(this.MessageTemplate.evaluate({
- message: message,
- stack: this.getStack(),
- type: type.capitalize()
- }), type);
- return true;
- },
-
- getStack: function() {
- try {
- throw new Error("stack");
- } catch(e) {
- return e.stack.match(this.Regexp).reject(function(path) {
- return /(prototype|unittest|deprecation)\.js/.test(path);
- }).join("\n");
- }
- },
-
- log: function(message, type) {
- if (type !== 'deprecation') {
- console.error(message);
- } else console.warn(message);
- }
-};
-
-DeprecationNotifier.init([
+var prototypeUpdateHelper = new UpdateHelper([
{
methodName: 'display',
namespace: Toggle,
@@ -79,7 +32,7 @@ DeprecationNotifier.init([
namespace: Element.Methods,
message: 'Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.',
- type: 'removal',
+ type: 'error',
condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
},
@@ -88,7 +41,7 @@ DeprecationNotifier.init([
namespace: Element.Methods,
message: 'Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.',
- type: 'removal',
+ type: 'error',
condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
},
@@ -97,7 +50,7 @@ DeprecationNotifier.init([
namespace: Element.Methods,
message: 'Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.',
- type: 'removal',
+ type: 'error',
condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
},
@@ -106,7 +59,7 @@ DeprecationNotifier.init([
namespace: Form.Element.Methods,
message: 'Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.',
- type: 'removal',
+ type: 'error',
condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
},
@@ -115,7 +68,7 @@ DeprecationNotifier.init([
namespace: Form.Element.Methods,
message: 'Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.',
- type: 'removal',
+ type: 'error',
condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
},
@@ -239,7 +192,7 @@ DeprecationNotifier.init([
namespace: Element.Methods,
message: 'Use of uncamelized style-property names is no longer supported.\n' +
'Use either camelized style-property names or a regular CSS string instead (see online documentation).',
- type: 'removal',
+ type: 'error',
condition: function(element, style) {
return !Object.isString(style) && Object.keys(style).join('').include('-');
}
@@ -281,7 +234,7 @@ DeprecationNotifier.init([
namespace: Hash,
message: 'Hash.toJSON has been removed.\n' +
'Use the instance method Hash#toJSON or Object.toJSON instead.',
- type: 'removal'
+ type: 'error'
},
{
@@ -289,22 +242,22 @@ DeprecationNotifier.init([
namespace: Hash.prototype,
message: 'Hash#remove is no longer supported, use Hash#unset instead.\n' +
'Please note that Hash#unset only accepts one argument.',
- type: 'removal'
+ type: 'error'
},
{
methodName: 'merge',
namespace: Hash.prototype,
- message: 'Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' +
+ message: 'Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' +
'If you need a destructive merge, use Hash#update instead.',
- type: 'modification'
+ type: 'warn'
},
{
methodName: 'unloadCache',
namespace: Event,
message: 'Event.unloadCache has been deprecated.',
- type: 'removal'
+ type: 'error'
},
{
@@ -312,17 +265,13 @@ DeprecationNotifier.init([
namespace: Class,
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;
- }
+ condition: function() { return !arguments.length }
}
]);
// Special casing for Hash.
(function() {
- if (!Prototype.Browser.Gecko) return;
-
var __properties = Object.keys(Hash.prototype).concat(['_object', '__properties']);
var messages = {
@@ -337,7 +286,7 @@ DeprecationNotifier.init([
property: property,
value: Object.inspect(value)
});
- DeprecationNotifier.notify(message, 'removal');
+ prototypeUpdateHelper.notify(message, 'error');
}
function defineSetters(obj, prop) {
diff --git a/ext/update_helper/update_helper.js b/ext/update_helper/update_helper.js
new file mode 100644
index 0000000..81a0ad0
--- /dev/null
+++ b/ext/update_helper/update_helper.js
@@ -0,0 +1,75 @@
+/* Update Helper (c) 2008 Tobie Langel
+ *
+ * Requires Prototype >= 1.6.0
+ *
+ * Update Helper is distributable under the same terms as Prototype
+ * (MIT-style license). For details, see the Prototype web site:
+ * http://www.prototypejs.org/
+ *
+ *--------------------------------------------------------------------------*/
+
+var UpdateHelper = Class.create({
+ logLevel: 0,
+ MessageTemplate: new Template('Update Helper: #{message}\n#{stack}'),
+ Regexp: new RegExp("@" + window.location.protocol + ".*?\\d+\\n", "g"),
+
+ initialize: function(deprecatedMethods) {
+ var notify = function(message, type) {
+ this.notify(message, type);
+ }.bind(this); // Late binding to simplify testing.
+
+ deprecatedMethods.each(function(d) {
+ var condition = d.condition,
+ type = d.type || 'info',
+ message = d.message,
+ namespace = d.namespace,
+ method = d.methodName;
+
+ namespace[method] = (namespace[method] || function() {}).wrap(function(proceed) {
+ var args = $A(arguments).splice(1);
+ if (!condition || condition.apply(this, args)) notify(message, type);
+ return proceed.apply(proceed, args);
+ });
+ });
+ Element.addMethods();
+ },
+
+ notify: function(message, type) {
+ switch(type) {
+ case 'info':
+ if (this.logLevel > UpdateHelper.Info) return false;
+ case 'warn':
+ if (this.logLevel > UpdateHelper.Warn) return false;
+ default:
+ if (this.logLevel > UpdateHelper.Error) return false;
+ }
+ this.log(this.MessageTemplate.evaluate({
+ message: message,
+ stack: this.getStack()
+ }), type);
+ return true;
+ },
+
+ getStack: function() {
+ try {
+ throw new Error("stack");
+ } catch(e) {
+ return (e.stack || '').match(this.Regexp).reject(function(path) {
+ return /(prototype|unittest|update_helper)\.js/.test(path);
+ }).join("\n");
+ }
+ },
+
+ log: function(message, type) {
+ if (type == 'error') console.error(message);
+ else if (type == 'warn') console.warn(message);
+ else console.log(message);
+ }
+});
+
+Object.extend(UpdateHelper, {
+ Info: 0,
+ Warn: 1,
+ Error: 2
+});
+