Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(704)

Side by Side Diff: pkg/element_created/lib/element_created.js

Issue 184033007: Prototype of Dart proxies for JS objects. Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: More tests. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/element_created/lib/element_created.dart ('k') | pkg/element_created/pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 (function (doc) {
2
3 var originalRegisterElement = document.registerElement;
4 if (!originalRegisterElement) {
5 throw new Error('document.registerElement is not present.');
6 }
7
8 function registerElement(name, options) {
9 var newOptions = Object.create(options);
10 for (var attr in options) {
11 if (options.hasOwnProperty(attr)) {
12 newOptions[attr] = options[attr];
13 }
14 }
15
16 var originalCreated = newOptions.prototype.createdCallback;
17
18 newOptions.prototype.createdCallback = function() {
19 originalCreated.call(this);
20
21 var key = getTagKey(this.tagName, this.getAttribute('is'));
22 var watchers = createdWatchers[key];
23 if (!watchers) {
24 return;
25 }
26 for (var i = 0, w; (w = watchers[i]); i++) {
27 invokeWatcher(this, w);
28 }
29 };
30
31 return originalRegisterElement.call(doc, name, newOptions);
32 }
33
34 function invokeWatcher(node, watcher) {
35 if (watcher.createdCallback) {
36 watcher.createdCallback.call(node);
37 }
38 }
39
40 // Unique key for the tagName & extends combo
41 function getTagKey(tagName, isTag) {
42 if (isTag) {
43 // '.' is a reserved character for XML names, so safe to use.
44 return tagName.toUpperCase() + '.' + isTag.toUpperCase();
45 }
46 return tagName.toUpperCase();
47 }
48
49 var createdWatchers = {};
50
51
52 function registerElementCreatedWatcher(name, options) {
53 if (!options) return;
54
55 var key = getTagKey(name, options.extends);
56 if (key in createdWatchers) {
57 createdWatchers[key].push(options);
58 } else {
59 createdWatchers[key] = [options];
60 }
61 }
62
63
64
65 doc.registerElementCreatedWatcher = registerElementCreatedWatcher;
66 doc.registerElement = registerElement;
67 })(document);
OLDNEW
« no previous file with comments | « pkg/element_created/lib/element_created.dart ('k') | pkg/element_created/pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698