Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. (function () {
  2.  
  3. var ElementPrototype = Object.create(HTMLElement.prototype);
  4.  
  5. // Lifecycle methods
  6.  
  7. ElementPrototype.createdCallback = function () {
  8.  
  9. };
  10.  
  11. ElementPrototype.attachedCallback = function () {
  12.  
  13. };
  14.  
  15. ElementPrototype.detachedCallback = function () {
  16.  
  17. };
  18.  
  19. ElementPrototype.attributeChangedCallback = function (attr, oldVal, newVal) {
  20. if (attr in attrs) {
  21. attrs[attr].call(this, oldVal, newVal);
  22. }
  23. };
  24.  
  25. // Custom methods
  26.  
  27. ElementPrototype.foo = function () {
  28.  
  29. };
  30.  
  31. // Attribute handlers
  32.  
  33. var attrs = {
  34. 'attr': function (oldVal, newVal) {
  35.  
  36. }
  37. };
  38.  
  39. // Property handlers
  40.  
  41. Object.defineProperties(ElementPrototype, {
  42. 'prop': {
  43. get : function () {
  44.  
  45. },
  46. set : function (newVal) {
  47.  
  48. }
  49. }
  50. });
  51.  
  52. // Register the element
  53.  
  54. window.CustomElement = document.registerElement('custom-element', {
  55. prototype: ElementPrototype
  56. });
  57.  
  58. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement