diff options
Diffstat (limited to 'third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app')
20 files changed, 339 insertions, 0 deletions
diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/app.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/app.js new file mode 100644 index 0000000000..f260c4c706 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/app.js @@ -0,0 +1,18 @@ +import Ember from 'ember'; +import Resolver from './resolver'; +import loadInitializers from 'ember-load-initializers'; +import config from './config/environment'; + +let App; + +Ember.MODEL_FACTORY_INJECTIONS = true; + +App = Ember.Application.extend({ + modulePrefix: config.modulePrefix, + podModulePrefix: config.podModulePrefix, + Resolver +}); + +loadInitializers(App, config.modulePrefix); + +export default App; diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-item.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-item.js new file mode 100644 index 0000000000..0de7fbf116 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-item.js @@ -0,0 +1,49 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + repo: Ember.inject.service(), + tagName: 'li', + editing: false, + classNameBindings: ['todo.completed', 'editing'], + + actions: { + startEditing() { + this.get('onStartEdit')(); + this.set('editing', true); + Ember.run.scheduleOnce('afterRender', this, 'focusInput'); + }, + + doneEditing(todoTitle) { + if (!this.get('editing')) { return; } + if (Ember.isBlank(todoTitle)) { + this.send('removeTodo'); + } else { + this.set('todo.title', todoTitle.trim()); + this.set('editing', false); + this.get('onEndEdit')(); + } + }, + + handleKeydown(e) { + if (e.keyCode === 13) { + e.target.blur(); + } else if (e.keyCode === 27) { + this.set('editing', false); + } + }, + + toggleCompleted(e) { + let todo = this.get('todo'); + Ember.set(todo, 'completed', e.target.checked); + this.get('repo').persist(); + }, + + removeTodo() { + this.get('repo').delete(this.get('todo')); + } + }, + + focusInput() { + this.element.querySelector('input.edit').focus(); + } +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-list.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-list.js new file mode 100644 index 0000000000..cd8183cfac --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/components/todo-list.js @@ -0,0 +1,28 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + repo: Ember.inject.service(), + tagName: 'section', + elementId: 'main', + classNames: ['main'], + canToggle: true, + allCompleted: Ember.computed('todos.@each.completed', function () { + return this.get('todos').isEvery('completed'); + }), + + actions: { + enableToggle() { + this.set('canToggle', true); + }, + + disableToggle() { + this.set('canToggle', false); + }, + + toggleAll() { + let allCompleted = this.get('allCompleted'); + this.get('todos').forEach(todo => Ember.set(todo, 'completed', !allCompleted)); + this.get('repo').persist(); + } + } +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/active.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/active.js new file mode 100644 index 0000000000..df03d40790 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/active.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + todos: Ember.computed.filterBy('model', 'completed', false) +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/application.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/application.js new file mode 100644 index 0000000000..c814e5fa73 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/application.js @@ -0,0 +1,20 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + repo: Ember.inject.service(), + remaining: Ember.computed.filterBy('model', 'completed', false), + completed: Ember.computed.filterBy('model', 'completed'), + actions: { + createTodo(e) { + if (e.keyCode === 13 && !Ember.isBlank(e.target.value)) { + this.get('repo').add({ title: e.target.value.trim(), completed: false }); + e.target.value = ''; + } + }, + + clearCompleted() { + this.get('model').removeObjects(this.get('completed')); + this.get('repo').persist(); + } + } +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/completed.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/completed.js new file mode 100644 index 0000000000..634d00afef --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/controllers/completed.js @@ -0,0 +1,5 @@ +import Ember from 'ember'; + +export default Ember.Controller.extend({ + todos: Ember.computed.filterBy('model', 'completed', true) +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/gt.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/gt.js new file mode 100644 index 0000000000..f370695a2f --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/gt.js @@ -0,0 +1,7 @@ +import Ember from 'ember'; + +export function gt([n1, n2]/*, hash*/) { + return n1 > n2; +} + +export default Ember.Helper.helper(gt); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/pluralize.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/pluralize.js new file mode 100644 index 0000000000..b1f1a2acc8 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/helpers/pluralize.js @@ -0,0 +1,8 @@ +import Ember from 'ember'; +import { pluralize } from 'ember-inflector'; + +export function pluralizeHelper([singular, count]/*, hash*/) { + return count === 1 ? singular : pluralize(singular); +} + +export default Ember.Helper.helper(pluralizeHelper); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/index.html b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/index.html new file mode 100644 index 0000000000..2e4af0bb47 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/index.html @@ -0,0 +1,19 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <title>Ember.js TodoMVC example</title> + <meta name="description" content=""> + <meta name="viewport" content="width=device-width, initial-scale=1"> + {{content-for "head"}} + <link rel="stylesheet" href="{{rootURL}}assets/vendor.css"> + {{content-for "head-footer"}} + </head> + <body> + {{content-for "body"}} + <script src="{{rootURL}}assets/vendor.js"></script> + <script src="{{rootURL}}assets/todomvc.js"></script> + {{content-for "body-footer"}} + </body> +</html> diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/resolver.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/resolver.js new file mode 100644 index 0000000000..2fb563d6c0 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/resolver.js @@ -0,0 +1,3 @@ +import Resolver from 'ember-resolver'; + +export default Resolver; diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/router.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/router.js new file mode 100644 index 0000000000..c0b3bfc496 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/router.js @@ -0,0 +1,14 @@ +import Ember from 'ember'; +import config from './config/environment'; + +const Router = Ember.Router.extend({ + location: config.locationType, + rootURL: config.rootURL +}); + +Router.map(function () { + this.route('active'); + this.route('completed'); +}); + +export default Router; diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/routes/application.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/routes/application.js new file mode 100644 index 0000000000..296a375ba2 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/routes/application.js @@ -0,0 +1,8 @@ +import Ember from 'ember'; + +export default Ember.Route.extend({ + repo: Ember.inject.service(), + model() { + return this.get('repo').findAll(); + } +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/memory.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/memory.js new file mode 100644 index 0000000000..74c5cdf19f --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/memory.js @@ -0,0 +1,78 @@ +(function(root) { + var localStorageMemory = {}; + var cache = {}; + + /** + * number of stored items. + */ + localStorageMemory.length = 0; + + /** + * returns item for passed key, or null + * + * @para {String} key + * name of item to be returned + * @returns {String|null} + */ + localStorageMemory.getItem = function(key) { + return cache[key] || null; + }; + + /** + * sets item for key to passed value, as String + * + * @para {String} key + * name of item to be set + * @para {String} value + * value, will always be turned into a String + * @returns {undefined} + */ + localStorageMemory.setItem = function(key, value) { + if (typeof value === 'undefined') { + localStorageMemory.removeItem(key); + } else { + if (!(cache.hasOwnProperty(key))) { + localStorageMemory.length++; + } + + cache[key] = '' + value; + } + }; + + /** + * removes item for passed key + * + * @para {String} key + * name of item to be removed + * @returns {undefined} + */ + localStorageMemory.removeItem = function(key) { + if (cache.hasOwnProperty(key)) { + delete cache[key]; + localStorageMemory.length--; + } + }; + + /** + * returns name of key at passed index + * + * @para {Number} index + * Position for key to be returned (starts at 0) + * @returns {String|null} + */ + localStorageMemory.key = function(index) { + return Object.keys(cache)[index] || null; + }; + + /** + * removes all stored items and sets length to 0 + * + * @returns {undefined} + */ + localStorageMemory.clear = function() { + cache = {}; + localStorageMemory.length = 0; + }; + + root.localStorageMemory = localStorageMemory; +})(window); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/repo.js b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/repo.js new file mode 100644 index 0000000000..cffa3858fd --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/services/repo.js @@ -0,0 +1,27 @@ +import Ember from 'ember'; +import localStorageMemory from './memory'; + +export default Ember.Service.extend({ + lastId: 0, + data: null, + findAll() { + return this.get('data') || + this.set('data', JSON.parse(window.localStorageMemory.getItem('todos') || '[]')); + }, + + add(attrs) { + let todo = Object.assign({ id: this.incrementProperty('lastId') }, attrs); + this.get('data').pushObject(todo); + this.persist(); + return todo; + }, + + delete(todo) { + this.get('data').removeObject(todo); + this.persist(); + }, + + persist() { + window.localStorageMemory.setItem('todos', JSON.stringify(this.get('data'))); + } +}); diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/active.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/active.hbs new file mode 100644 index 0000000000..de244f487d --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/active.hbs @@ -0,0 +1 @@ +{{todo-list todos=todos}}
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/application.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/application.hbs new file mode 100644 index 0000000000..70bf1196a9 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/application.hbs @@ -0,0 +1,29 @@ +<section id="todoapp" class="todoapp"> + <header id="header" class="header"> + <h1>todos</h1> + <input type="text" id="new-todo" class="new-todo" onkeydown={{action 'createTodo'}} placeholder="What needs to be done?" autofocus> + </header> + {{outlet}} + {{#if (gt model.length 0)}} + <footer id="footer" class="footer"> + <span id="todo-count" class="todo-count"><strong>{{remaining.length}}</strong> {{pluralize 'item' remaining.length}} left</span> + <ul id="filters" class="filters"> + <li>{{#link-to "index" activeClass="selected"}}All{{/link-to}}</li> + <li>{{#link-to "active" activeClass="selected"}}Active{{/link-to}}</li> + <li>{{#link-to "completed" activeClass="selected"}}Completed{{/link-to}}</li> + </ul> + {{#if completed.length}} + <button id="clear-completed" class="clear-completed" onclick={{action 'clearCompleted'}}>Clear completed</button> + {{/if}} + </footer> + {{/if}} +</section> +<footer id="info" class="info"> + <p>Double-click to edit a todo</p> + <p> + Created by + <a href="http://github.com/cibernox">Miguel Camba</a>, + <a href="http://github.com/addyosmani">Addy Osmani</a> + </p> + <p>Part of <a href="http://todomvc.com">TodoMVC</a></p> +</footer>
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/completed.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/completed.hbs new file mode 100644 index 0000000000..de244f487d --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/completed.hbs @@ -0,0 +1 @@ +{{todo-list todos=todos}}
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-item.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-item.hbs new file mode 100644 index 0000000000..c06975e865 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-item.hbs @@ -0,0 +1,6 @@ +<div class="view"> + <input type="checkbox" class="toggle" checked={{todo.completed}} onchange={{action 'toggleCompleted'}}> + <label ondblclick={{action 'startEditing'}}>{{todo.title}}</label> + <button onclick={{action 'removeTodo'}} class="destroy"></button> +</div> +<input type="text" class="edit" value={{todo.title}} onblur={{action 'doneEditing' value='target.value'}} onkeydown={{action 'handleKeydown'}} autofocus>
\ No newline at end of file diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-list.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-list.hbs new file mode 100644 index 0000000000..4e3c2b29f1 --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/components/todo-list.hbs @@ -0,0 +1,10 @@ +{{#if todos.length}} + {{#if canToggle}} + <input type="checkbox" id="toggle-all" class="toggle-all" checked={{allCompleted}} onchange={{action 'toggleAll'}}> + {{/if}} + <ul id="todo-list" class="todo-list"> + {{#each todos as |todo|}} + {{todo-item todo=todo onStartEdit=(action 'disableToggle') onEndEdit=(action 'enableToggle')}} + {{/each}} + </ul> +{{/if}} diff --git a/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/index.hbs b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/index.hbs new file mode 100644 index 0000000000..7d5565c36a --- /dev/null +++ b/third_party/webkit/PerformanceTests/Speedometer/resources/todomvc/architecture-examples/emberjs/app/templates/index.hbs @@ -0,0 +1,3 @@ +{{#if model.length}} + {{todo-list todos=model}} +{{/if}} |