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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/element_created/lib/element_created.dart ('k') | pkg/element_created/pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/element_created/lib/element_created.js
diff --git a/pkg/element_created/lib/element_created.js b/pkg/element_created/lib/element_created.js
new file mode 100644
index 0000000000000000000000000000000000000000..243794501d9946bdf2fb2d4a541e1cd74f2bb89d
--- /dev/null
+++ b/pkg/element_created/lib/element_created.js
@@ -0,0 +1,67 @@
+(function (doc) {
+
+ var originalRegisterElement = document.registerElement;
+ if (!originalRegisterElement) {
+ throw new Error('document.registerElement is not present.');
+ }
+
+ function registerElement(name, options) {
+ var newOptions = Object.create(options);
+ for (var attr in options) {
+ if (options.hasOwnProperty(attr)) {
+ newOptions[attr] = options[attr];
+ }
+ }
+
+ var originalCreated = newOptions.prototype.createdCallback;
+
+ newOptions.prototype.createdCallback = function() {
+ originalCreated.call(this);
+
+ var key = getTagKey(this.tagName, this.getAttribute('is'));
+ var watchers = createdWatchers[key];
+ if (!watchers) {
+ return;
+ }
+ for (var i = 0, w; (w = watchers[i]); i++) {
+ invokeWatcher(this, w);
+ }
+ };
+
+ return originalRegisterElement.call(doc, name, newOptions);
+ }
+
+ function invokeWatcher(node, watcher) {
+ if (watcher.createdCallback) {
+ watcher.createdCallback.call(node);
+ }
+ }
+
+ // Unique key for the tagName & extends combo
+ function getTagKey(tagName, isTag) {
+ if (isTag) {
+ // '.' is a reserved character for XML names, so safe to use.
+ return tagName.toUpperCase() + '.' + isTag.toUpperCase();
+ }
+ return tagName.toUpperCase();
+ }
+
+ var createdWatchers = {};
+
+
+ function registerElementCreatedWatcher(name, options) {
+ if (!options) return;
+
+ var key = getTagKey(name, options.extends);
+ if (key in createdWatchers) {
+ createdWatchers[key].push(options);
+ } else {
+ createdWatchers[key] = [options];
+ }
+ }
+
+
+
+ doc.registerElementCreatedWatcher = registerElementCreatedWatcher;
+ doc.registerElement = registerElement;
+})(document);
« 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