Skip to content
This repository
Browse code

prototype: Complete rewrite of the deprecation helper.

  • Loading branch information...
commit 87ce1533e45d8db092ce8a6096f19e2cb4e1157c 1 parent addfdef
Tobie Langel tobie authored
2  CHANGELOG
... ... @@ -1,3 +1,5 @@
  1 +* Complete rewrite of the deprecation helper, now renamed UpdateHelper and useable by third-party libs. [Tobie Langel]
  2 +
1 3 * Make Element#writeAttribute handle frameborder attribute in IE. Closes #11068. [staaky, Tobie Langel]
2 4
3 5 * Minor clean-up of selector.js. Closes #10844. [RQuadling]
14 Rakefile
@@ -7,7 +7,7 @@ PROTOTYPE_DIST_DIR = File.join(PROTOTYPE_ROOT, 'dist')
7 7 PROTOTYPE_PKG_DIR = File.join(PROTOTYPE_ROOT, 'pkg')
8 8 PROTOTYPE_VERSION = '1.6.0.2'
9 9
10   -task :default => [:dist, :package, :clean_package_source]
  10 +task :default => [:dist, :dist_helper, :package, :clean_package_source]
11 11
12 12 desc "Builds the distribution"
13 13 task :dist do
@@ -21,6 +21,18 @@ task :dist do
21 21 end
22 22 end
23 23
  24 +desc "Builds the updating helper"
  25 +task :dist_helper do
  26 + $:.unshift File.join(PROTOTYPE_ROOT, 'lib')
  27 + require 'protodoc'
  28 +
  29 + Dir.chdir(File.join(PROTOTYPE_ROOT, 'ext', 'update_helper')) do
  30 + File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype_update_helper.js'), 'w+') do |dist|
  31 + dist << Protodoc::Preprocessor.new('prototype_update_helper.js')
  32 + end
  33 + end
  34 +end
  35 +
24 36 Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package|
25 37 package.need_tar_gz = true
26 38 package.package_dir = PROTOTYPE_PKG_DIR
118 ext/deprecation/deprecation_test.html → ext/update_helper/prototype_update_helper.html
@@ -5,7 +5,7 @@
5 5 <title>Prototype Unit test file</title>
6 6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 7 <script src="../../dist/prototype.js" type="text/javascript"></script>
8   - <script src="deprecation.js" type="text/javascript"></script>
  8 + <script src="../../dist/prototype_update_helper.js" type="text/javascript"></script>
9 9 <script src="../../test/lib/unittest.js" type="text/javascript"></script>
10 10 <link rel="stylesheet" href="../../test/test.css" type="text/css" />
11 11 </head>
@@ -29,8 +29,8 @@
29 29 message: [],
30 30 type: []
31 31 };
32   - DeprecationNotifier.notify = DeprecationNotifier.notify.wrap(function(proceed, message, type) {
33   - if (!proceed(message, type)) return; // DeprecationNotifier.notify return false if the message is not logged.
  32 + prototypeUpdateHelper.notify = prototypeUpdateHelper.notify.wrap(function(proceed, message, type) {
  33 + if (!proceed(message, type)) return; // UpdateHelper#notify return false if the message is not logged.
34 34 log.message.push(message);
35 35 log.type.push(type);
36 36 });
@@ -40,29 +40,29 @@
40 40 }
41 41
42 42 Test.Unit.Testcase.addMethods({
43   - assertDeprecationNotified: function(expected) {
  43 + assertInfoNotified: function(expected) {
44 44 var actualMessage = log.message.beforeLast() || log.message.last();
45 45 var actualType = log.type.beforeLast() || log.type.last();
46   - this.assertEqual(expected, actualMessage, 'assertDeprecationNotified');
47   - this.assertEqual('deprecation', actualType, 'assertDeprecationNotified');
  46 + this.assertEqual(expected, actualMessage, 'assertInfoNotified');
  47 + this.assertEqual('info', actualType, 'assertInfoNotified');
48 48 log.message.push(null);
49 49 log.type.push(null);
50 50 },
51 51
52   - assertRemovalNotified: function(expected) {
  52 + assertErrorNotified: function(expected) {
53 53 var actualMessage = log.message.beforeLast() || log.message.last();
54 54 var actualType = log.type.beforeLast() || log.type.last();
55   - this.assertEqual(expected, actualMessage, 'assertRemovalNotified');
56   - this.assertEqual('removal', actualType, 'assertRemovalNotified');
  55 + this.assertEqual(expected, actualMessage, 'assertErrorNotified');
  56 + this.assertEqual('error', actualType, 'assertErrorNotified');
57 57 log.message.push(null);
58 58 log.type.push(null);
59 59 },
60 60
61   - assertModificationNotified: function(expected) {
  61 + assertWarnNotified: function(expected) {
62 62 var actualMessage = log.message.beforeLast() || log.message.last();
63 63 var actualType = log.type.beforeLast() || log.type.last();
64   - this.assertEqual(expected, actualMessage, 'assertModificationNotified');
65   - this.assertEqual('modification', actualType, 'assertModificationNotified');
  64 + this.assertEqual(expected, actualMessage, 'assertWarnNotified');
  65 + this.assertEqual('warn', actualType, 'assertWarnNotified');
66 66 log.message.push(null);
67 67 log.type.push(null);
68 68 },
@@ -77,15 +77,15 @@
77 77
78 78 new Test.Unit.Runner({
79 79 testGetStack: function(){ with(this) {
80   - assertMatch(/deprecation_test\.html:\d+\n$/, DeprecationNotifier.getStack());
  80 + assertMatch(/prototype_update_helper\.html:\d+\n$/, prototypeUpdateHelper.getStack());
81 81 }},
82 82
83 83 testDisplay: function(){ with(this) {
84 84 Toggle.display('foo');
85   - assertDeprecationNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
  85 + assertInfoNotified('Toggle.display has been deprecated, please use Element.toggle instead.');
86 86
87 87 Element.show('foo', 'bar', 'bla');
88   - assertRemovalNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
  88 + assertErrorNotified('Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
89 89 'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.');
90 90
91 91 $('foo', 'bar', 'bla').each(Element.hide);
@@ -95,11 +95,11 @@
95 95 assertNotNotified();
96 96
97 97 Element.hide('foo', 'bar', 'bla');
98   - assertRemovalNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
  98 + assertErrorNotified('Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
99 99 'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.');
100 100
101 101 Element.toggle('foo', 'bar', 'bla');
102   - assertRemovalNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
  102 + assertErrorNotified('Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
103 103 'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.');
104 104 }},
105 105
@@ -108,41 +108,41 @@
108 108 assertNotNotified();
109 109
110 110 Element.setStyle('foo', { 'font-size': '18px' });
111   - assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
  111 + assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
112 112 'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
113 113
114 114 Element.setStyle('foo', 'font-size: 18px;');
115 115 assertNotNotified();
116 116
117 117 $('foo').setStyle({ 'font-size': '18px' });
118   - assertRemovalNotified('Use of uncamelized style-property names is no longer supported.\n' +
  118 + assertErrorNotified('Use of uncamelized style-property names is no longer supported.\n' +
119 119 'Use either camelized style-property names or a regular CSS string instead (see online documentation).')
120 120 }},
121 121
122 122 testClassNames: function(){ with(this) {
123 123 new Element.ClassNames('foo');
124   - assertDeprecationNotified('Element.ClassNames has been deprecated.')
  124 + assertInfoNotified('Element.ClassNames has been deprecated.')
125 125
126 126 $('foo').classNames();
127   - assertDeprecationNotified('Element#classNames has been deprecated.\n' +
  127 + assertInfoNotified('Element#classNames has been deprecated.\n' +
128 128 'If you need to access CSS class names as an array, try: $w(element.classname).')
129 129
130 130 Element.getElementsByClassName('foo', 'className');
131   - assertDeprecationNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
  131 + assertInfoNotified('Element#getElementsByClassName has been deprecated, please use Element#select instead.')
132 132
133 133 document.getElementsByClassName('className');
134   - assertDeprecationNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
  134 + assertInfoNotified('document.getElementsByClassName has been deprecated, please use $$ instead.')
135 135 }},
136 136
137 137 testDomSelectors: function(){ with(this) {
138 138 Element.childOf('foo', 'bar');
139   - assertDeprecationNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
  139 + assertInfoNotified('Element#childOf has been deprecated, please use Element#descendantOf instead.');
140 140
141 141 $('foo').immediateDescendants();
142   - assertDeprecationNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
  142 + assertInfoNotified('Element#immediateDescendants has been deprecated, please use Element#childElements instead.');
143 143
144 144 $('foo').getElementsBySelector('a');
145   - assertDeprecationNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
  145 + assertInfoNotified('Element#getElementsBySelector has been deprecated, please use Element#select instead.');
146 146
147 147 $('foo').select('a');
148 148 assertNotNotified();
@@ -150,109 +150,109 @@
150 150
151 151 testField: function(){ with(this) {
152 152 Field.clear('foo', 'bar', 'bla');
153   - assertRemovalNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
  153 + assertErrorNotified('Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
154 154 'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.');
155 155
156 156 Field.present('foo', 'bar', 'bla');
157   - assertRemovalNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
  157 + assertErrorNotified('Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
158 158 'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.');
159 159 }},
160 160
161 161 testInsertion: function(){ with(this) {
162 162 Insertion.Before('foo', 'text');
163   - assertDeprecationNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
  163 + assertInfoNotified('Insertion.Before has been deprecated, please use Element#insert instead.');
164 164
165 165 Insertion.Top('foo', 'text');
166   - assertDeprecationNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
  166 + assertInfoNotified('Insertion.Top has been deprecated, please use Element#insert instead.');
167 167
168 168 Insertion.Bottom('foo', 'text');
169   - assertDeprecationNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
  169 + assertInfoNotified('Insertion.Bottom has been deprecated, please use Element#insert instead.');
170 170
171 171 Insertion.After('foo', 'text');
172   - assertDeprecationNotified('Insertion.After has been deprecated, please use Element#insert instead.');
  172 + assertInfoNotified('Insertion.After has been deprecated, please use Element#insert instead.');
173 173 }},
174 174
175 175 testPosition: function(){ with(this) {
176 176 Position.prepare('foo');
177   - assertDeprecationNotified('Position.prepare has been deprecated.');
  177 + assertInfoNotified('Position.prepare has been deprecated.');
178 178
179 179 Position.within('foo');
180   - assertDeprecationNotified('Position.within has been deprecated.');
  180 + assertInfoNotified('Position.within has been deprecated.');
181 181
182 182 Position.withinIncludingScrolloffsets('foo');
183   - assertDeprecationNotified('Position.withinIncludingScrolloffsets has been deprecated.');
  183 + assertInfoNotified('Position.withinIncludingScrolloffsets has been deprecated.');
184 184
185 185 Position.overlap('foo');
186   - assertDeprecationNotified('Position.overlap has been deprecated.');
  186 + assertInfoNotified('Position.overlap has been deprecated.');
187 187
188 188 Position.cumulativeOffset('foo');
189   - assertDeprecationNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
  189 + assertInfoNotified('Position.cumulativeOffset has been deprecated, please use Element#cumulativeOffset instead.');
190 190
191 191 Position.positionedOffset('foo');
192   - assertDeprecationNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
  192 + assertInfoNotified('Position.positionedOffset has been deprecated, please use Element#positionedOffset instead.');
193 193
194 194 Position.absolutize('foo');
195   - assertDeprecationNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
  195 + assertInfoNotified('Position.absolutize has been deprecated, please use Element#absolutize instead.');
196 196
197 197 Position.relativize('foo');
198   - assertDeprecationNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
  198 + assertInfoNotified('Position.relativize has been deprecated, please use Element#relativize instead.');
199 199
200 200 Position.realOffset('foo');
201   - assertDeprecationNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
  201 + assertInfoNotified('Position.realOffset has been deprecated, please use Element#cumulativeScrollOffset instead.');
202 202
203 203 Position.offsetParent('foo');
204   - assertDeprecationNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
  204 + assertInfoNotified('Position.offsetParent has been deprecated, please use Element#getOffsetParent instead.');
205 205
206 206 Position.page('foo');
207   - assertDeprecationNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
  207 + assertInfoNotified('Position.page has been deprecated, please use Element#viewportOffset instead.');
208 208
209 209 Position.clone('foo', 'bar');
210   - assertDeprecationNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
  210 + assertInfoNotified('Position.clone has been deprecated, please use Element#clonePosition instead.');
211 211 }},
212 212
213 213 testEvent: function(){ with(this) {
214 214 Event.unloadCache();
215   - assertRemovalNotified('Event.unloadCache has been deprecated.')
  215 + assertErrorNotified('Event.unloadCache has been deprecated.')
216 216 }},
217 217
218 218 testHash: function(){ with(this) {
219 219 Hash.toQueryString({});
220   - assertDeprecationNotified('Hash.toQueryString has been deprecated.\n' +
  220 + assertInfoNotified('Hash.toQueryString has been deprecated.\n' +
221 221 'Use the instance method Hash#toQueryString or Object.toQueryString instead.');
222 222
223 223 Hash.toJSON({});
224   - assertRemovalNotified('Hash.toJSON has been removed.\n' +
  224 + assertErrorNotified('Hash.toJSON has been removed.\n' +
225 225 'Use the instance method Hash#toJSON or Object.toJSON instead.');
226 226
227 227 var h = $H({ foo: 2 });
228 228
229 229 h.remove('foo');
230   - assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
  230 + assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
231 231 'Please note that Hash#unset only accepts one argument.');
232 232
233 233 h.merge('foo');
234   - 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.');
  234 + 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.');
235 235
236 236 h['foo'];
237   - assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
  237 + assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
238 238 'Please use Hash#get(\'foo\') instead.')
239 239
240 240 h.foo = 3;
241   - assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
  241 + assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
242 242 'Please use Hash#set(\'foo\', 3) instead.')
243 243
244 244 h.bar = 'bar';
245 245 h.toJSON();
246   - assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
  246 + assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
247 247 'Please use Hash#set(\'bar\', \'bar\') instead.')
248 248
249 249 h.bar;
250   - assertRemovalNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
  250 + assertErrorNotified('Directly accessing a property of an instance of Hash is no longer supported.\n' +
251 251 'Please use Hash#get(\'bar\') instead.')
252 252
253 253 h.baz = 'baz';
254 254 h.bar;
255   - assertRemovalNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
  255 + assertErrorNotified('Directly setting a property on an instance of Hash is no longer supported.\n' +
256 256 'Please use Hash#set(\'baz\', \'baz\') instead.')
257 257
258 258 h.set('toJSON', 'arg'); // make sure hash methods are not overwritten
@@ -261,26 +261,26 @@
261 261
262 262 testClass: function(){ with(this) {
263 263 Class.create();
264   - assertDeprecationNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
  264 + assertInfoNotified('The class API has been fully revised and now allows for mixins and inheritance.\n' +
265 265 'You can find more about it here: http://prototypejs.org/learn/class-inheritance');
266 266 Class.create({});
267 267 assertNotNotified();
268 268 }},
269 269
270 270 testLogDeprecationOption: function(){ with(this) {
271   - DeprecationNotifier.logDeprecation = false;
  271 + prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
272 272 var h = $H({ foo: 2 });
273 273
274 274 h.merge({ foo: 3 });
275   - 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.');
  275 + 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.');
276 276
277 277 h.remove('foo');
278   - assertRemovalNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
  278 + assertErrorNotified('Hash#remove is no longer supported, use Hash#unset instead.\n' +
279 279 'Please note that Hash#unset only accepts one argument.');
280 280
281 281 document.getElementsByClassName('className');
282 282 assertNotNotified();
283   - DeprecationNotifier.logDeprecation = true;
  283 + prototypeUpdateHelper.logLevel = UpdateHelper.Info;
284 284 }}
285 285 });
286 286
113 ext/deprecation/deprecation.js → ext/update_helper/prototype_update_helper.js
... ... @@ -1,73 +1,26 @@
1   -/* Prototype Deprecation Notifier for Prototype 1.6.0.2
2   - * (c) 2008 Tobie Langel
  1 +<%= include "update_helper.js" %>
  2 +
  3 +/* UpdateHelper for Prototype <%= PROTOTYPE_VERSION %> (c) 2008 Tobie Langel
  4 + *
  5 + * UpdateHelper for Prototype is freely distributable under the same
  6 + * terms as Prototype (MIT-style license).
  7 + * For details, see the Prototype web site: http://www.prototypejs.org/
  8 + *
  9 + * Include this file right below prototype.js. All messages
  10 + * will be logged to the console.
  11 + *
  12 + * Note: You can tune the level of warning by redefining
  13 + * prototypeUpdateHelper.logLevel with one of the appropriate constansts
  14 + * (UpdateHelper.Info, UpdateHelper.Warn or UpdateHelper.Error), e.g.:
  15 + *
  16 + * prototypeUpdateHelper.logLevel = UpdateHelper.Warn;
3 17 *
4   - * Prototype Deprecation Notifier is freely distributable under the same
5   - * terms as Prototype (MIT-style license).
6   - * For details, see the Prototype web site: http://www.prototypejs.org/
7   - *
8   - * Include this file right below prototype.js. All warning messages
9   - * will be logged to the console.
10   - *
11   - * Note: You can turn off deprecation messages (and log only removal and
12   - * modification messages) by specifying:
13   - * DeprecationNotifier.logDeprecation = false;
  18 + * This, for example, will prevent deprecation messages from being logged.
14 19 *
15 20 * THIS SCRIPT WORKS IN FIREFOX ONLY
16 21 *--------------------------------------------------------------------------*/
17 22
18   -var DeprecationNotifier = {
19   - logDeprecation: true,
20   - MessageTemplate: new Template('Prototype #{type} Warning: #{message}\n#{stack}'),
21   - Regexp: new RegExp("@" + window.location.protocol + ".*?\\d+\\n", "g"),
22   -
23   - init: function(deprecatedMethods) {
24   - if (!Prototype.Browser.Gecko) return;
25   - deprecatedMethods.each(function(d) {
26   - var condition = d.condition,
27   - type = d.type || 'deprecation',
28   - message = d.message,
29   - namespace = d.namespace,
30   - method = d.methodName;
31   -
32   - namespace[method] = (namespace[method] || function() {}).wrap(function(proceed) {
33   - var args = $A(arguments).splice(1);
34   - if (!condition || condition.apply(this, args))
35   - DeprecationNotifier.notify(message, type);
36   - return proceed.apply(proceed, args);
37   - });
38   - });
39   - Element.addMethods();
40   - },
41   -
42   - notify: function(message, type) {
43   - if (type == 'deprecation' && !DeprecationNotifier.logDeprecation)
44   - return false;
45   - this.log(this.MessageTemplate.evaluate({
46   - message: message,
47   - stack: this.getStack(),
48   - type: type.capitalize()
49   - }), type);
50   - return true;
51   - },
52   -
53   - getStack: function() {
54   - try {
55   - throw new Error("stack");
56   - } catch(e) {
57   - return e.stack.match(this.Regexp).reject(function(path) {
58   - return /(prototype|unittest|deprecation)\.js/.test(path);
59   - }).join("\n");
60   - }
61   - },
62   -
63   - log: function(message, type) {
64   - if (type !== 'deprecation') {
65   - console.error(message);
66   - } else console.warn(message);
67   - }
68   -};
69   -
70   -DeprecationNotifier.init([
  23 +var prototypeUpdateHelper = new UpdateHelper([
71 24 {
72 25 methodName: 'display',
73 26 namespace: Toggle,
@@ -79,7 +32,7 @@ DeprecationNotifier.init([
79 32 namespace: Element.Methods,
80 33 message: 'Passing an arbitrary number of elements to Element.show is no longer supported.\n' +
81 34 'Use [id_1, id_2, ...].each(Element.show) or $(id_1, id_2, ...).invoke("show") instead.',
82   - type: 'removal',
  35 + type: 'error',
83 36 condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
84 37 },
85 38
@@ -88,7 +41,7 @@ DeprecationNotifier.init([
88 41 namespace: Element.Methods,
89 42 message: 'Passing an arbitrary number of elements to Element.hide is no longer supported.\n' +
90 43 'Use [id_1, id_2, ...].each(Element.hide) or $(id_1, id_2, ...).invoke("hide") instead.',
91   - type: 'removal',
  44 + type: 'error',
92 45 condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
93 46 },
94 47
@@ -97,7 +50,7 @@ DeprecationNotifier.init([
97 50 namespace: Element.Methods,
98 51 message: 'Passing an arbitrary number of elements to Element.toggle is no longer supported.\n' +
99 52 'Use [id_1, id_2, ...].each(Element.toggle) or $(id_1, id_2, ...).invoke("toggle") instead.',
100   - type: 'removal',
  53 + type: 'error',
101 54 condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
102 55 },
103 56
@@ -106,7 +59,7 @@ DeprecationNotifier.init([
106 59 namespace: Form.Element.Methods,
107 60 message: 'Passing an arbitrary number of elements to Field.clear is no longer supported.\n' +
108 61 'Use [id_1, id_2, ...].each(Form.Element.clear) or $(id_1, id_2, ...).invoke("clear") instead.',
109   - type: 'removal',
  62 + type: 'error',
110 63 condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
111 64 },
112 65
@@ -115,7 +68,7 @@ DeprecationNotifier.init([
115 68 namespace: Form.Element.Methods,
116 69 message: 'Passing an arbitrary number of elements to Field.present is no longer supported.\n' +
117 70 'Use [id_1, id_2, ...].each(Form.Element.present) or $(id_1, id_2, ...).invoke("present") instead.',
118   - type: 'removal',
  71 + type: 'error',
119 72 condition: function() { return arguments.length > 1 && !Object.isNumber(arguments[1]) }
120 73 },
121 74
@@ -239,7 +192,7 @@ DeprecationNotifier.init([
239 192 namespace: Element.Methods,
240 193 message: 'Use of uncamelized style-property names is no longer supported.\n' +
241 194 'Use either camelized style-property names or a regular CSS string instead (see online documentation).',
242   - type: 'removal',
  195 + type: 'error',
243 196 condition: function(element, style) {
244 197 return !Object.isString(style) && Object.keys(style).join('').include('-');
245 198 }
@@ -281,7 +234,7 @@ DeprecationNotifier.init([
281 234 namespace: Hash,
282 235 message: 'Hash.toJSON has been removed.\n' +
283 236 'Use the instance method Hash#toJSON or Object.toJSON instead.',
284   - type: 'removal'
  237 + type: 'error'
285 238 },
286 239
287 240 {
@@ -289,22 +242,22 @@ DeprecationNotifier.init([
289 242 namespace: Hash.prototype,
290 243 message: 'Hash#remove is no longer supported, use Hash#unset instead.\n' +
291 244 'Please note that Hash#unset only accepts one argument.',
292   - type: 'removal'
  245 + type: 'error'
293 246 },
294 247
295 248 {
296 249 methodName: 'merge',
297 250 namespace: Hash.prototype,
298   - message: 'Hash#merge is no longer destructive: it operates on a clone of the Hash instance.\n' +
  251 + message: 'Hash#merge is no longer destructive and now operates on a clone of the Hash instance.\n' +
299 252 'If you need a destructive merge, use Hash#update instead.',
300   - type: 'modification'
  253 + type: 'warn'
301 254 },
302 255
303 256 {
304 257 methodName: 'unloadCache',
305 258 namespace: Event,
306 259 message: 'Event.unloadCache has been deprecated.',
307   - type: 'removal'
  260 + type: 'error'
308 261 },
309 262
310 263 {
@@ -312,17 +265,13 @@ DeprecationNotifier.init([
312 265 namespace: Class,
313 266 message: 'The class API has been fully revised and now allows for mixins and inheritance.\n' +
314 267 'You can find more about it here: http://prototypejs.org/learn/class-inheritance',
315   - condition: function() {
316   - return !arguments.length;
317   - }
  268 + condition: function() { return !arguments.length }
318 269 }
319 270 ]);
320 271
321 272 // Special casing for Hash.
322 273
323 274 (function() {
324   - if (!Prototype.Browser.Gecko) return;
325   -
326 275 var __properties = Object.keys(Hash.prototype).concat(['_object', '__properties']);
327 276
328 277 var messages = {
@@ -337,7 +286,7 @@ DeprecationNotifier.init([
337 286 property: property,
338 287 value: Object.inspect(value)
339 288 });
340   - DeprecationNotifier.notify(message, 'removal');
  289 + prototypeUpdateHelper.notify(message, 'error');
341 290 }
342 291
343 292 function defineSetters(obj, prop) {
75 ext/update_helper/update_helper.js
... ... @@ -0,0 +1,75 @@
  1 +/* Update Helper (c) 2008 Tobie Langel
  2 + *
  3 + * Requires Prototype >= 1.6.0
  4 + *
  5 + * Update Helper is distributable under the same terms as Prototype
  6 + * (MIT-style license). For details, see the Prototype web site:
  7 + * http://www.prototypejs.org/
  8 + *
  9 + *--------------------------------------------------------------------------*/
  10 +
  11 +var UpdateHelper = Class.create({
  12 + logLevel: 0,
  13 + MessageTemplate: new Template('Update Helper: #{message}\n#{stack}'),
  14 + Regexp: new RegExp("@" + window.location.protocol + ".*?\\d+\\n", "g"),
  15 +
  16 + initialize: function(deprecatedMethods) {
  17 + var notify = function(message, type) {
  18 + this.notify(message, type);
  19 + }.bind(this); // Late binding to simplify testing.
  20 +
  21 + deprecatedMethods.each(function(d) {
  22 + var condition = d.condition,
  23 + type = d.type || 'info',
  24 + message = d.message,
  25 + namespace = d.namespace,
  26 + method = d.methodName;
  27 +
  28 + namespace[method] = (namespace[method] || function() {}).wrap(function(proceed) {
  29 + var args = $A(arguments).splice(1);
  30 + if (!condition || condition.apply(this, args)) notify(message, type);
  31 + return proceed.apply(proceed, args);
  32 + });
  33 + });
  34 + Element.addMethods();
  35 + },
  36 +
  37 + notify: function(message, type) {
  38 + switch(type) {
  39 + case 'info':
  40 + if (this.logLevel > UpdateHelper.Info) return false;
  41 + case 'warn':
  42 + if (this.logLevel > UpdateHelper.Warn) return false;
  43 + default:
  44 + if (this.logLevel > UpdateHelper.Error) return false;
  45 + }
  46 + this.log(this.MessageTemplate.evaluate({
  47 + message: message,
  48 + stack: this.getStack()
  49 + }), type);
  50 + return true;
  51 + },
  52 +
  53 + getStack: function() {
  54 + try {
  55 + throw new Error("stack");
  56 + } catch(e) {
  57 + return (e.stack || '').match(this.Regexp).reject(function(path) {
  58 + return /(prototype|unittest|update_helper)\.js/.test(path);
  59 + }).join("\n");
  60 + }
  61 + },
  62 +
  63 + log: function(message, type) {
  64 + if (type == 'error') console.error(message);
  65 + else if (type == 'warn') console.warn(message);
  66 + else console.log(message);
  67 + }
  68 +});
  69 +
  70 +Object.extend(UpdateHelper, {
  71 + Info: 0,
  72 + Warn: 1,
  73 + Error: 2
  74 +});
  75 +

1 comment on commit 87ce153

cleverchao

nice job,and it is just a test for comment.

Please sign in to comment.
Something went wrong with that request. Please try again.