Skip to content

Instantly share code, notes, and snippets.

Forked from anonymous/jsbin.ketaqiwe.css
Created May 8, 2014 19:56
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralph/b734f0bba0154c66a891 to your computer and use it in GitHub Desktop.
Save ralph/b734f0bba0154c66a891 to your computer and use it in GitHub Desktop.
/* Put your CSS here */
html, body {
margin: 20px;
.color {
height: 200px;
width: 200px;
<!DOCTYPE html>
<meta name="description" content="Wrapping localStorage in Ember Demo" />
<meta charset="utf-8">
<title>Ember Starter Kit</title>
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>
<script src=""></script>
<script type="text/x-handlebars">
<h2>Wrapping localStorage in Ember Demo</h2>
<script type="text/x-handlebars" data-template-name="index">
<p>Pick your favorite color, then close this tab an come back:</p>
{{custom-color colors=model}}
<p>Also check <code>localStorage.color</code> in the Console.</p>
<script type="text/x-handlebars" data-template-name="components/custom-color">
{{#each item in colors}}
<li><a {{action setColor item}} href="#">{{item}}</a></li>
{{input name="color" value=color}}
<a href="#" {{action clear}}>clear</a>
App = Ember.Application.create(); {
// put your routes here
App.IndexRoute = Ember.Route.extend({
model: function() {
return ['red', 'yellow', 'green'];
App.LocalStorage = Ember.Object.extend({
unknownProperty: function(key) {
return localStorage[key];
setUnknownProperty: function(key, value) {
if(Ember.isNone(value)) {
delete localStorage[key];
} else {
localStorage[key] = value;
return value;
clear: function() {
for (var i=0, l=localStorage.length; i<l; i++){
App.CustomColorComponent = Ember.Component.extend({
color: Ember.computed.alias('storage.color'),
createLocalStorage: function() {
this.set('storage', App.LocalStorage.create());
actions: {
setColor: function(value) {
this.set('color', value);
clear: function() {
classNames: ['color'],
attributeBindings: ['style'],
style: function() {
var color = this.get('color');
return "background-color: " + color;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment