I'm studying angularjs, and I want to write a custom "editable" directive, which can make a normal html element "editable":
When user clicks it, it will show a text input or textarea to let user edit the content, and there is also a "update" and "cancel" button besides. User can click the "update" button or press "Ctrl+enter" to submit the modified content, or click "cancel" or press "escape" to cancel the modification.
The "editable" signature looks like:
<div editable
e-trigger="click|dblclick" /* use click or dblclick to trigger the action */
e-update-url="http://xxx/xxx" /* when submitting, the data will PUT to this url */
e-singleline="true|false" /* if ture, use text input, otherwise textarea */
ng-model="name"> /* the corresponding model name */
{{name}}
</div>
I've create a live demo here: http://jsfiddle.net/Freewind/KRduz/, you can just update it.