| OLD | NEW | 
|---|
| (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); | 
| OLD | NEW | 
|---|