Skip to content

Commit

Permalink
Prevent script error If keyword isn't exists and example code code cl…
Browse files Browse the repository at this point in the history
…eaning.
  • Loading branch information
Alan Hong committed Oct 2, 2015
1 parent 77bdd09 commit d76341e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 43 deletions.
18 changes: 9 additions & 9 deletions dist/summernote.js
Expand Up @@ -6,7 +6,7 @@
* Copyright 2013-2015 Alan Hong. and other contributors
* summernote may be freely distributed under the MIT license./
*
* Date: 2015-10-02T07:51Z
* Date: 2015-10-02T08:24Z
*/
(function (factory) {
/* global define */
Expand Down Expand Up @@ -5813,10 +5813,10 @@

this.events = {
'summernote.keyup': function (we, e) {
self.update(e);
self.handleKeyup(e);
},
'summernote.keydown' : function (we, e) {
self.updateKeydown(e);
self.handleKeydown(e);
}
};

Expand Down Expand Up @@ -5929,9 +5929,9 @@
});
};

this.updateKeydown = function (e) {
this.handleKeydown = function (e) {
if (!this.$popover.is(':visible')) {
return true;
return;
}

if (e.keyCode === key.code.ENTER) {
Expand Down Expand Up @@ -5969,16 +5969,17 @@
return $group;
};

this.update = function (e) {
this.handleKeyup = function (e) {
if (list.contains([key.code.ENTER, key.code.UP, key.code.DOWN], e.keyCode)) {
if (e.keyCode === key.code.ENTER) {
if (this.$popover.is(':visible')) {
return false;
}
}
} else {
if (hints.length) {
var wordRange = summernote.invoke('editor.createRange').getWordRange();
var wordRange = summernote.invoke('editor.createRange').getWordRange();
var keyword = wordRange.toString();
if (hints.length && keyword) {
this.$content.empty().data('count', 0);

var bnd = func.rect2bnd(list.last(wordRange.getClientRects()));
Expand All @@ -5990,7 +5991,6 @@

this.lastWordRange = wordRange;

var keyword = wordRange.toString();
hints.forEach(function (hint, idx) {
if (hint.match.test(keyword)) {
self.createGroup(idx, keyword).appendTo(self.$content);
Expand Down
2 changes: 1 addition & 1 deletion dist/summernote.min.js

Large diffs are not rendered by default.

51 changes: 26 additions & 25 deletions examples/hint-emoji.html
Expand Up @@ -29,35 +29,36 @@
<script type="text/javascript">
$(document).ready(function () {
var self = this;
var emoji, emojiLink;

// load github's emoji list
$.getJSON('https://api.github.com/emojis', function (data) {
emoji = Object.keys(data);
emojiLink = data;
});
$.ajax({
url: 'https://api.github.com/emojis'
}).then(function (data) {
var emojis = Object.keys(data);
var emojiUrls = data;

$('.summernote').summernote({
height: 300,
hint : [{
search: function (keyword, callback) {
callback($.grep(emoji, function (item) {
return item.indexOf(keyword) === 0;
}));
},
match: /\B:([\-+\w]+)$/,
template: function (item) {
var content = emojiLink[item];
return '<img src="' + content + '" width="20" /> :' + item + ':';
},
content: function (item) {
var url = emojiLink[item];
if (url) {
return $('<img />').attr('src', url).css({width: 20})[0];
$('.summernote').summernote({
height: 300,
hint: [{
search: function (keyword, callback) {
callback($.grep(emojis, function (item) {
return item.indexOf(keyword) === 0;
}));
},
match: /\B:([\-+\w]+)$/,
template: function (item) {
var content = emojiUrls[item];
return '<img src="' + content + '" width="20" /> :' + item + ':';
},
content: function (item) {
var url = emojiUrls[item];
if (url) {
return $('<img />').attr('src', url).css('width', 20)[0];
}
return '';
}
return '';
}
}]
}]
});
});
});
</script>
Expand Down
16 changes: 8 additions & 8 deletions src/js/bs3/module/HintPopover.js
Expand Up @@ -15,10 +15,10 @@ define([

this.events = {
'summernote.keyup': function (we, e) {
self.update(e);
self.handleKeyup(e);
},
'summernote.keydown' : function (we, e) {
self.updateKeydown(e);
self.handleKeydown(e);
}
};

Expand Down Expand Up @@ -131,9 +131,9 @@ define([
});
};

this.updateKeydown = function (e) {
this.handleKeydown = function (e) {
if (!this.$popover.is(':visible')) {
return true;
return;
}

if (e.keyCode === key.code.ENTER) {
Expand Down Expand Up @@ -171,16 +171,17 @@ define([
return $group;
};

this.update = function (e) {
this.handleKeyup = function (e) {
if (list.contains([key.code.ENTER, key.code.UP, key.code.DOWN], e.keyCode)) {
if (e.keyCode === key.code.ENTER) {
if (this.$popover.is(':visible')) {
return false;
}
}
} else {
if (hints.length) {
var wordRange = summernote.invoke('editor.createRange').getWordRange();
var wordRange = summernote.invoke('editor.createRange').getWordRange();
var keyword = wordRange.toString();
if (hints.length && keyword) {
this.$content.empty().data('count', 0);

var bnd = func.rect2bnd(list.last(wordRange.getClientRects()));
Expand All @@ -192,7 +193,6 @@ define([

this.lastWordRange = wordRange;

var keyword = wordRange.toString();
hints.forEach(function (hint, idx) {
if (hint.match.test(keyword)) {
self.createGroup(idx, keyword).appendTo(self.$content);
Expand Down

0 comments on commit d76341e

Please sign in to comment.