diff --git a/mention.js b/mention.js index 7c390ed..de3a8b7 100644 --- a/mention.js +++ b/mention.js @@ -35,18 +35,18 @@ }, _matcher = function(itemProps) { var i; - + if(settings.emptyQuery){ - var q = (this.query.toLowerCase()), - caratPos = this.$element[0].selectionStart, - lastChar = q.slice(caratPos-1,caratPos); - if(lastChar==settings.delimiter){ - return true; - } + var q = (this.query.toLowerCase()), + caratPos = this.$element[0].selectionStart, + lastChar = q.slice(caratPos-1,caratPos); + if(lastChar==settings.delimiter){ + return true; + } } - + for (i in settings.queryBy) { - if (itemProps[settings.queryBy[i]]) { + if (itemProps[settings.queryBy[i]] && settings.queryBy.hasOwnProperty(i)) { var item = itemProps[settings.queryBy[i]].toLowerCase(), usernames = (this.query.toLowerCase()).match(new RegExp(settings.delimiter + '\\w+', "g")), j; @@ -68,17 +68,17 @@ var data = this.query, caratPos = this.$element[0].selectionStart, i; - + for (i = caratPos; i >= 0; i--) { if (data[i] == settings.delimiter) { break; } } var replace = data.substring(i, caratPos), - textBefore = data.substring(0, i), - textAfter = data.substring(caratPos), - data = textBefore + settings.delimiter + item + textAfter; - + textBefore = data.substring(0, i), + textAfter = data.substring(caratPos), + data = textBefore + settings.delimiter + item + textAfter; + this.tempQuery = data; return data; @@ -111,9 +111,13 @@ } } for (i in priorities) { - var j; - for (j in priorities[i]) { - finals.push(priorities[i][j]); + if(priorities.hasOwnProperty(i)) { + var j; + for (j in priorities[i]) { + if(priorities[i].hasOwnProperty(j)) { + finals.push(priorities[i][j]); + } + } } } return finals;