Skip to content

Commit

Permalink
Added logic for selected field to be .tag-editor only
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin committed Sep 30, 2014
1 parent fd0340b commit 498435b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions jquery.tag-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@
// delete selected tags on backspace, delete, ctrl+x
function delete_selected_tags(e){
if (e.which == 8 || e.which == 46 || e.ctrlKey && e.which == 88) {
var sel = getSelection(), el = $(sel.getRangeAt(0).commonAncestorContainer);
if (el.hasClass('tag-editor')) {
var tags = [], splits = sel.toString().split(el.prev().data('options').dregex);
for (i=0; i<splits.length; i++){ var tag = $.trim(splits[i]); if (tag) tags.push(tag); }
$('.tag-editor-tag', el).each(function(){
if (~$.inArray($(this).html(), tags)) $(this).closest('li').find('.tag-editor-delete').click();
});
return false;
var sel = getSelection();
if(sel.anchorNode && sel.anchorNode.className==='tag-editor'){
var el = $(sel.getRangeAt(0).commonAncestorContainer);
if (el.hasClass('tag-editor')) {
var tags = [], splits = sel.toString().split(el.prev().data('options').dregex);
for (i=0; i<splits.length; i++){ var tag = $.trim(splits[i]); if (tag) tags.push(tag); }
$('.tag-editor-tag', el).each(function(){
if (~$.inArray($(this).html(), tags)) $(this).closest('li').find('.tag-editor-delete').click();
});
return false;
}
}
}
}
Expand Down

1 comment on commit 498435b

@SimonSteinberger
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Justin - great work. I'll include your patch also in the minified version.

Please sign in to comment.