From 3d9eb96db1ed9a44870d616b27972160679df255 Mon Sep 17 00:00:00 2001 From: Ivan Virabyan Date: Tue, 29 Dec 2015 13:45:27 +0300 Subject: [PATCH] Fixed broken methods for contenteditable #49 --- jquery.mentions.coffee | 11 ++++++++++- jquery.mentions.js | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/jquery.mentions.coffee b/jquery.mentions.coffee index 1d33274..aa17d50 100644 --- a/jquery.mentions.coffee +++ b/jquery.mentions.coffee @@ -458,12 +458,21 @@ class MentionsContenteditable extends MentionsBase getValue: -> value = @input.clone() + markupMention = @_markupMention $(@selector, value).replaceWith -> uid = $(this).data 'mention' name = $(this).text() - return @_markupMention({name: name, uid: uid}) + return markupMention({name: name, uid: uid}) value.html().replace(@marker, '') + getMentions: -> + mentions = [] + $(@selector, @input).each -> + mentions.push + uid: $(this).data 'mention' + name: $(this).text() + return mentions + clear: -> @input.html('') @_update() diff --git a/jquery.mentions.js b/jquery.mentions.js index 254222c..57f0b35 100644 --- a/jquery.mentions.js +++ b/jquery.mentions.js @@ -612,13 +612,14 @@ }; MentionsContenteditable.prototype.getValue = function() { - var value; + var markupMention, value; value = this.input.clone(); + markupMention = this._markupMention; $(this.selector, value).replaceWith(function() { var name, uid; uid = $(this).data('mention'); name = $(this).text(); - return this._markupMention({ + return markupMention({ name: name, uid: uid }); @@ -626,6 +627,18 @@ return value.html().replace(this.marker, ''); }; + MentionsContenteditable.prototype.getMentions = function() { + var mentions; + mentions = []; + $(this.selector, this.input).each(function() { + return mentions.push({ + uid: $(this).data('mention'), + name: $(this).text() + }); + }); + return mentions; + }; + MentionsContenteditable.prototype.clear = function() { this.input.html(''); return this._update();