This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
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
c261eb2
commit abe4bee
Showing
2 changed files
with
61 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<!-- 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/hello-world.html | ||
var thisDoc = document._currentScript.ownerDocument; | ||
|
||
// Gets content from <template> | ||
var template = thisDoc.querySelector('template').content; | ||
|
||
xtag.register('hello-world', { | ||
lifecycle: { | ||
created: function() { | ||
// Caches <strong> DOM query | ||
this.strong = template.querySelector('strong'); | ||
|
||
// Creates the shadow root | ||
this.shadowRoot = this.createShadowRoot(); | ||
|
||
this.uiSetWho(); | ||
}, | ||
attributeChanged: function() { | ||
this.uiSetWho(); | ||
} | ||
}, | ||
accessors: { | ||
who: { | ||
attribute: {}, | ||
get: function(){ | ||
return this.getAttribute('who') || "World" | ||
}, | ||
set: function(value){ | ||
this.xtag.data.who = value; | ||
} | ||
} | ||
}, | ||
methods: { | ||
uiSetWho: function() { | ||
// Sets "who" value into <strong> | ||
this.strong.textContent = this.who; | ||
|
||
// 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); | ||
</script> |