Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default insert behavior #21

Merged
merged 3 commits into from
Aug 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,22 @@ var behavior = (function() {
cursor.update();
},

insert: function(element, direction) {
insert: function(element, direction, cursor) {
log('Default insert ' + direction + ' behavior');
var parent = element.parentNode;
var newElement = element.cloneNode(false);
if(newElement.id) newElement.id += '-js-editable-clone';

switch(direction) {
case 'before':
parent.insertBefore(newElement, element);
break;
case 'after':
parent.insertBefore(newElement, element.nextSibling);
break;
}

newElement.focus();
},

split: function(element, before, after, cursor) {
Expand Down
5 changes: 3 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ var config = {
* @event insert
* @param {HTMLElement} element The element triggering the event.
* @param {String} direction The insert direction: "before" or "after".
* @param {Cursor} cursor The actual cursor object.
*/
insert: function(element, direction) {
behavior.insert(element, direction);
insert: function(element, direction, cursor) {
behavior.insert(element, direction, cursor);
},


Expand Down
4 changes: 2 additions & 2 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ var dispatcher = (function() {
var cursor = selectionWatcher.getCursor();

if (cursor.isAtTheEnd()) {
notifier('insert', this, 'after');
notifier('insert', this, 'after', cursor);
} else if(cursor.isAtTheBeginning()) {
notifier('insert', this, 'before');
notifier('insert', this, 'before', cursor);
} else {
notifier('split', this, cursor.before(), cursor.after(), cursor);
}
Expand Down
2 changes: 1 addition & 1 deletion test/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
var tooltip = $('<div class="selection-tip" style="display:none;">How may I help?</div>')
$(document.body).append(tooltip);

$("article>div>p").editable();
$("article>div>p, article>div li").editable();
Editable.focus(function(el) {
console.log('Focus event handler was triggered on', el);

Expand Down