0.2.1 • Published 11 years ago
editize v0.2.1
editize
This browser module provides a function that makes a DOM element editable via the contentEditable attribute and adds some event handlers and styles.
editize(listItemElement)
.editingStateClass('editing-list-item')
.onStartEdit(changePageBackgroundColor)
.onEndEdit(restorePageBackgroundColor);Specification
If editize is called on a DOM element el, a document doc, and window win, editize will return an editized object.
- When
elis clicked, it will get thecontentEditableattribute. - When
elis clicked,focuswill be called on it, which should show the cursor. - When
elis clicked, the text in it will be highlighted by changingwin's selection. When a specified key is hit or a
blurevent is triggered,contentEditablewill be removed.doc' andwinare optional. If they are not passed toeditize, it will use the globaldocumentandwindow`.The
editizedobject will have theeditingStateClass,onStartEdit, andonEndEditmethods.- Calling
editingStateClasswith a string will cause the start of editing to add that class toel. - Calling
onStartEditwith a function will set the "start edit" event handler to that function. When the user starts to edit the element, that function will be called.- Editing starts as soon as the user clicks on
el.
- Editing starts as soon as the user clicks on
- Calling
onEndEditwith a function will set the "end edit" event handler to that function. When the finishes editing the element, that function will be called. - Calling
addQuitKeywith a keyCode will set- Editing ends when the user hits an ending key or a blur event occurs.
- Calling
Installation
npm install editizeUsage
Include <script src="editize.js"> in your html file. Then, in your JavaScript file:
- Obtain the DOM element you want to be editized.
- Call `editize` on it.
- Set any properties you want on the editized object returned by `editize`.Tests
Run tests with make test.
License
MIT.