Created
May 6, 2014 19:46
-
-
Save secretrobotron/846d28209f9e9bc83e7f to your computer and use it in GitHub Desktop.
test custom element for thimble (ultra portable!)
This file contains hidden or 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
<script> | |
(function () { | |
// super secret special shim for loading Polymer elements in weird situations | |
if (!window.Polymer) { | |
var base = location.protocol === 'https:' ? 'https://appmaker-integration.herokuapp.com' : 'http://localhost:1999/'; | |
var waiting = []; | |
window.Polymer = function(){waiting.push(arguments)}; | |
["/vendor/polymer/polymer.html", "/ceci/ceci-element.html", "/ceci/ceci-definition.html"].forEach(function(src) { | |
var l = document.createElement('link'); | |
l.rel="import"; | |
l.href = base + src; | |
document.head.appendChild(l); | |
}); | |
var s = document.createElement('script'); | |
s.src = base + '/vendor/platform/platform.js'; | |
s.onload = function () { | |
setTimeout(function () { | |
waiting.forEach(function (w) { | |
window.Polymer.apply(document, w); | |
}); | |
}, 500); | |
}; | |
document.head.appendChild(s); | |
} | |
})(); | |
</script> | |
<polymer-element name="ceci-mood" extends="ceci-element" attributes="mood"> | |
<ceci-definition> | |
{ | |
"name": "Mood", | |
"description": "Shows mood.", | |
"broadcasts": { | |
"comment": { | |
"label": "Comment", | |
"description": "Comments about the mood." | |
} | |
}, | |
"listeners": { | |
"reset": { | |
"description": "Reset", | |
"label": "Reset" | |
} | |
}, | |
"attributes": { | |
"mood": { | |
"description": "Current mood", | |
"label": "Mood", | |
"editable": "select", | |
"options": ["normal","happy","sad"] | |
} | |
} | |
} | |
</ceci-definition> | |
<template> | |
<style></style> | |
<div>{{face}}</div> | |
<shadow></shadow> | |
</template> | |
<script> | |
var faceMap = { | |
normal: ':|', | |
happy: ':)', | |
sad: ':(' | |
}; | |
Polymer("ceci-mood", { | |
mood: 'normal', | |
face: ':|', | |
ready: function() { | |
this.super(); | |
console.log('FACE BOOT'); | |
}, | |
moodChanged: function (oldMood, newMood) { | |
this.face = faceMap[newMood] || faceMap.normal; | |
}, | |
reset: function() { | |
this.mood = 'normal'; | |
} | |
}); | |
</script> | |
</polymer-element> | |
<ceci-mood></ceci-mood> | |
<button onclick="document.querySelector('ceci-mood').reset()">Normal</button> | |
<button onclick="document.querySelector('ceci-mood').mood='happy';">Happy</button> | |
<button onclick="document.querySelector('ceci-mood').mood='sad';">Sad</button> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment