Commit 300b76cd authored by Pascal Hartig's avatar Pascal Hartig

polymer: code style update

parent aad9dd5d
...@@ -4,14 +4,14 @@ ...@@ -4,14 +4,14 @@
var ENTER_KEY = 13; var ENTER_KEY = 13;
var ESC_KEY = 27; var ESC_KEY = 27;
Polymer('td-input', { Polymer('td-input', {
keypressAction: function(e, detail, sender) { keypressAction: function (e, detail, sender) {
// Listen for enter on keypress but esc on keyup, because // Listen for enter on keypress but esc on keyup, because
// IE doesn't fire keyup for enter. // IE doesn't fire keyup for enter.
if (e.keyCode === ENTER_KEY) { if (e.keyCode === ENTER_KEY) {
this.fire('td-input-commit'); this.fire('td-input-commit');
} }
}, },
keyupAction: function(e, detail, sender) { keyupAction: function (e, detail, sender) {
if (e.keyCode === ESC_KEY) { if (e.keyCode === ESC_KEY) {
this.fire('td-input-cancel'); this.fire('td-input-cancel');
} }
......
...@@ -124,8 +124,7 @@ label { ...@@ -124,8 +124,7 @@ label {
} }
.destroy:hover { .destroy:hover {
text-shadow: 0 0 1px #000, text-shadow: 0 0 1px #000, 0 0 10px rgba(199, 107, 107, 0.8);
0 0 10px rgba(199, 107, 107, 0.8);
-webkit-transform: scale(1.3); -webkit-transform: scale(1.3);
-moz-transform: scale(1.3); -moz-transform: scale(1.3);
-ms-transform: scale(1.3); -ms-transform: scale(1.3);
...@@ -148,11 +147,11 @@ label { ...@@ -148,11 +147,11 @@ label {
@media screen and (-webkit-min-device-pixel-ratio:0) { @media screen and (-webkit-min-device-pixel-ratio:0) {
.toggle { .toggle {
background: none; background: none;
/* /*
ShadowDOM Polyfill work around for webkit/blink bug ShadowDOM Polyfill work around for webkit/blink bug
https://code.google.com/p/chromium/issues/detail?id=251510 https://code.google.com/p/chromium/issues/detail?id=251510
*/ */
background-color: transparent; background-color: transparent;
} }
.toggle { .toggle {
......
...@@ -10,12 +10,12 @@ ...@@ -10,12 +10,12 @@
<input is="td-input" id="edit" class="edit" value="{{title}}" hidden?="{{!editing}}" on-td-input-commit="commitAction" on-td-input-cancel="cancelAction"> <input is="td-input" id="edit" class="edit" value="{{title}}" hidden?="{{!editing}}" on-td-input-commit="commitAction" on-td-input-cancel="cancelAction">
</template> </template>
<script> <script>
(function() { (function () {
var ENTER_KEY = 13; var ENTER_KEY = 13;
var ESC_KEY = 27; var ESC_KEY = 27;
Polymer('td-item', { Polymer('td-item', {
editing: false, editing: false,
editAction: function() { editAction: function () {
this.editing = true; this.editing = true;
// FIXME: Custom elements extended from <input> don't have // FIXME: Custom elements extended from <input> don't have
// <input> binding behavior. // <input> binding behavior.
...@@ -23,11 +23,11 @@ ...@@ -23,11 +23,11 @@
this.$.edit.value = this.title = this.item.title; this.$.edit.value = this.title = this.item.title;
// schedule focus for the end of microtask, when the input will be visible // schedule focus for the end of microtask, when the input will be visible
Platform.flush(); Platform.flush();
this.asyncMethod(function() { this.asyncMethod(function () {
this.$.edit.focus(); this.$.edit.focus();
}); });
}, },
commitAction: function() { commitAction: function () {
// FIXME: Custom elements extended from <input> don't have // FIXME: Custom elements extended from <input> don't have
// <input> binding behavior. // <input> binding behavior.
// https://github.com/Polymer/polymer/issues/186 // https://github.com/Polymer/polymer/issues/186
...@@ -38,7 +38,7 @@ ...@@ -38,7 +38,7 @@
if (this.item.title === '') { if (this.item.title === '') {
this.destroyAction(); this.destroyAction();
} }
this.fire('td-item-changed'); this.fire('td-item-changed');
} }
}, },
cancelAction: function() { cancelAction: function() {
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
completedCount: 0, completedCount: 0,
activeCount: 0, activeCount: 0,
allCompleted: false, allCompleted: false,
ready: function() { ready: function () {
this.asyncMethod(function() { this.asyncMethod(function () {
this.items = this.items || []; this.items = this.items || [];
}); });
}, },
filterChanged: function() { filterChanged: function () {
this.filterItems(); this.filterItems();
}, },
itemsChanged: function() { itemsChanged: function () {
this.completedCount = this.completedCount =
this.items.filter(this.filters.completed).length; this.items.filter(this.filters.completed).length;
this.activeCount = this.items.length - this.completedCount; this.activeCount = this.items.length - this.completedCount;
...@@ -24,15 +24,17 @@ ...@@ -24,15 +24,17 @@
this.storage.save(); this.storage.save();
} }
}, },
storageIdChanged: function() { storageIdChanged: function () {
this.storage = document.querySelector('#' + this.storageId); this.storage = document.querySelector('#' + this.storageId);
this.storage && (this.items = this.storage.value); if (this.storage) {
this.items = this.storage.value;
}
}, },
filterItems: function() { filterItems: function () {
var fn = this.filters[this.filter]; var fn = this.filters[this.filter];
this.filtered = fn ? this.items.filter(fn) : this.items; this.filtered = fn ? this.items.filter(fn) : this.items;
}, },
newItem: function(title) { newItem: function (title) {
title = String(title).trim(); title = String(title).trim();
if (title) { if (title) {
var item = { var item = {
...@@ -43,27 +45,27 @@ ...@@ -43,27 +45,27 @@
this.itemsChanged(); this.itemsChanged();
} }
}, },
destroyItem: function(item) { destroyItem: function (item) {
var i = this.items.indexOf(item); var i = this.items.indexOf(item);
if (i >= 0) { if (i >= 0) {
this.items.splice(i, 1); this.items.splice(i, 1);
} }
this.itemsChanged(); this.itemsChanged();
}, },
clearItems: function(){ clearItems: function () {
this.items = this.items.filter(this.filters.active); this.items = this.items.filter(this.filters.active);
}, },
setItemsCompleted: function(completed) { setItemsCompleted: function (completed) {
this.items.forEach(function(item) { this.items.forEach(function (item) {
item.completed = completed; item.completed = completed;
}); });
this.itemsChanged(); this.itemsChanged();
}, },
filters: { filters: {
active: function(item) { active: function (item) {
return !item.completed; return !item.completed;
}, },
completed: function(item) { completed: function (item) {
return item.completed; return item.completed;
} }
} }
......
/* base.css overrides */ /* base.css overrides */
@host { @host {
* { * {
display: block; display: block;
position: relative; position: relative;
} }
...@@ -17,7 +17,6 @@ button { ...@@ -17,7 +17,6 @@ button {
font-family: inherit; font-family: inherit;
color: inherit; color: inherit;
-webkit-appearance: none; -webkit-appearance: none;
/*-moz-appearance: none;*/
-ms-appearance: none; -ms-appearance: none;
-o-appearance: none; -o-appearance: none;
appearance: none; appearance: none;
...@@ -40,7 +39,6 @@ input:-ms-input-placeholder, #new-todo:-ms-input-placeholder { ...@@ -40,7 +39,6 @@ input:-ms-input-placeholder, #new-todo:-ms-input-placeholder {
#todoapp { #todoapp {
background: #fff; background: #fff;
background: rgba(255, 255, 255, 0.9); background: rgba(255, 255, 255, 0.9);
/*margin: 130px 0 40px 0;*/
margin: 0 0 40px 0; margin: 0 0 40px 0;
border: 1px solid #ccc; border: 1px solid #ccc;
position: relative; position: relative;
...@@ -247,11 +245,11 @@ label[for='toggle-all'] { ...@@ -247,11 +245,11 @@ label[for='toggle-all'] {
@media screen and (-webkit-min-device-pixel-ratio:0) { @media screen and (-webkit-min-device-pixel-ratio:0) {
#toggle-all { #toggle-all {
background: none; background: none;
/* /*
ShadowDOM Polyfill work around for webkit/blink bug ShadowDOM Polyfill work around for webkit/blink bug
https://code.google.com/p/chromium/issues/detail?id=251510 https://code.google.com/p/chromium/issues/detail?id=251510
*/ */
background-color: transparent; background-color: transparent;
} }
#toggle-all { #toggle-all {
......
...@@ -39,35 +39,39 @@ ...@@ -39,35 +39,39 @@
</template> </template>
<script> <script>
(function() { (function () {
var ENTER_KEY = 13; var ENTER_KEY = 13;
var ESC_KEY = 27; var ESC_KEY = 27;
Polymer('td-todos', { Polymer('td-todos', {
modelIdChanged: function() { modelIdChanged: function () {
this.model = document.querySelector('#' + this.modelId); this.model = document.querySelector('#' + this.modelId);
}, },
routeChanged: function() { routeChanged: function () {
this.model && (this.model.filter = this.route); if (this.model) {
this.model.filter = this.route;
}
}, },
addTodoAction: function() { addTodoAction: function () {
this.model.newItem(this.$['new-todo'].value); this.model.newItem(this.$['new-todo'].value);
// when polyfilling Object.observe, make sure we update immediately // when polyfilling Object.observe, make sure we update immediately
Platform.flush(); Platform.flush();
this.$['new-todo'].value = ''; this.$['new-todo'].value = '';
}, },
cancelAddTodoAction: function() { cancelAddTodoAction: function () {
this.$['new-todo'].value = ''; this.$['new-todo'].value = '';
}, },
itemChangedAction: function() { itemChangedAction: function () {
this.model && this.model.itemsChanged(); if (this.model) {
this.model.itemsChanged();
}
}, },
destroyItemAction: function(e, detail) { destroyItemAction: function (e, detail) {
this.model.destroyItem(detail); this.model.destroyItem(detail);
}, },
toggleAllCompletedAction: function(e, detail, sender) { toggleAllCompletedAction: function (e, detail, sender) {
this.model.setItemsCompleted(sender.checked); this.model.setItemsCompleted(sender.checked);
}, },
clearCompletedAction: function() { clearCompletedAction: function () {
this.model.clearItems(); this.model.clearItems();
} }
}); });
......
<!doctype html> <!doctype html>
<html lang="en"> <html lang="en" data-framework="polymer">
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
...@@ -10,12 +10,14 @@ ...@@ -10,12 +10,14 @@
<link rel="import" href="elements/td-todos.html"> <link rel="import" href="elements/td-todos.html">
</head> </head>
<body> <body>
<header> <section id="todoapp">
<h1>todos</h1> <header id="header">
</header> <h1>todos</h1>
<polymer-localstorage id="storage" name="todos-polymer"></polymer-localstorage> </header>
<td-model id="model" storageId="storage"></td-model> <polymer-localstorage id="storage" name="todos-polymer"></polymer-localstorage>
<td-todos modelId="model"></td-todos> <td-model id="model" storageId="storage"></td-model>
<td-todos modelId="model"></td-todos>
</section>
<footer id="info"> <footer id="info">
<p>Double-click to edit a todo</p> <p>Double-click to edit a todo</p>
<p>Created by <a href="http://www.polymer-project.org">The Polymer Authors</a></p> <p>Created by <a href="http://www.polymer-project.org">The Polymer Authors</a></p>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment