Commit 8e1adcf4 authored by Rhsy's avatar Rhsy Committed by Sindre Sorhus

Close GH-169: inline makeEditable for PlastronJS.

parent 34674022
......@@ -54,13 +54,15 @@ todomvc.todocontrol.prototype.enterDocument = function() {
model.dispose();
}, 'destroy' );
var inputEl = this.getEls('.edit')[0];
// Dblclick to edit
this.on( goog.events.EventType.DBLCLICK, function( e ) {
this.makeEditable( true );
goog.dom.classes.add( this.getElement(), 'editing' );
inputEl.value = model.get('title');
inputEl.select();
}, 'view' );
// Save on edit
var inputEl = this.getEls('.edit')[0];
this.on( goog.events.EventType.KEYUP, function( e ) {
if ( e.keyCode === goog.events.KeyCodes.ENTER ) {
model.set( 'title', inputEl.value );
......@@ -71,20 +73,3 @@ todomvc.todocontrol.prototype.enterDocument = function() {
model.set( 'title', inputEl.value );
}, 'edit' );
};
/**
* make (un)editable
*
* @param {boolean} editable whether to make editable.
*/
todomvc.todocontrol.prototype.makeEditable = function( editable ) {
var inputEl = this.getEls('.edit')[0];
goog.dom.classes.enable( this.getElement(), 'editing', editable );
if ( editable ) {
inputEl.value = this.getModel().get('title');
inputEl.select();
}
};
\ No newline at end of file
......@@ -4,19 +4,19 @@
* @param model
*/
{template .todoItem}
<li {if $model['completed']}class="completed"{/if}>
<div class="view">
<input class="toggle" type="checkbox" {if $model['completed']}checked{/if}>
<label>{$model['title']}</label>
<button class="destroy"></button>
</div>
<input class="edit">
</li>
<li {if $model['completed']}class="completed"{/if}>
<div class="view">
<input class="toggle" type="checkbox" {if $model['completed']}checked{/if}>
<label>{$model['title']}</label>
<button class="destroy"></button>
</div>
<input class="edit">
</li>
{/template}
/**
* @param left
*/
{template .itemsLeft}
<strong>{$left}</strong> item{if $left != 1}s{/if} left
{/template}
\ No newline at end of file
<strong>{$left}</strong> item{if $left != 1}s{/if} left
{/template}
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