This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zeno Rocha
committed
Apr 26, 2014
1 parent
c34f7c6
commit 2180ace
Showing
1 changed file
with
20 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,25 @@ | ||
<!-- Import X-Tag --> | ||
<script src="../../x-tag-core/src/core.js"></script> | ||
|
||
<template> | ||
<p>Hello <strong></strong></p> | ||
</template> | ||
|
||
<script> | ||
(function(window, document, undefined) { | ||
// Refers to the "importer", which is index.html | ||
var thatDoc = document; | ||
|
||
// Refers to the "importee", which is src/my-element.html | ||
var thisDoc = document._currentScript.ownerDocument; | ||
|
||
// Gets content from <template> | ||
var template = thisDoc.querySelector('template').content; | ||
|
||
xtag.register('my-element', { | ||
lifecycle: { | ||
created: function() { | ||
// Caches <strong> DOM query | ||
this.strong = template.querySelector('strong'); | ||
|
||
// Creates the shadow root | ||
this.shadowRoot = this.createShadowRoot(); | ||
|
||
this.uiSetName(); | ||
}, | ||
attributeChanged: function() { | ||
this.uiSetName(); | ||
} | ||
}, | ||
accessors: { | ||
name: { | ||
attribute: {}, | ||
get: function(){ | ||
return this.getAttribute('name') || "World" | ||
}, | ||
set: function(value){ | ||
this.xtag.data.name = value; | ||
} | ||
} | ||
}, | ||
methods: { | ||
uiSetName: function() { | ||
// Sets name value into <strong> | ||
this.strong.textContent = this.name; | ||
|
||
// Removes shadow root content | ||
this.shadowRoot.innerHTML = ''; | ||
|
||
// Adds a template clone into shadow root | ||
var clone = thatDoc.importNode(template, true); | ||
this.shadowRoot.appendChild(clone); | ||
} | ||
} | ||
}); | ||
})(window, document); | ||
(function() { | ||
xtag.register('my-element', { | ||
lifecycle: { | ||
// Fires when an instance of the element is created | ||
created: function() {}, | ||
|
||
// Fires when an instance was inserted into the document | ||
inserted: function() {}, | ||
|
||
// Fires when an instance was removed from the document | ||
removed: function() {}, | ||
|
||
// Fires when an attribute was added, removed, or updated | ||
attributeChanged: function(attr, oldVal, newVal) {} | ||
}, | ||
events: {}, | ||
accessors: {}, | ||
methods: {} | ||
}); | ||
}()); | ||
</script> |