Skip to content

Commit

Permalink
Merge pull request yuku#272 from markgardner/master
Browse files Browse the repository at this point in the history
Adding support for match functions in select phase.
  • Loading branch information
Yuku TAKAHASHI committed Jul 8, 2016
2 parents 3eebf1d + ab20520 commit f54eb08
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/completer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@
return Object.prototype.toString.call(obj) === '[object String]';
};

var isFunction = function (obj) {
return Object.prototype.toString.call(obj) === '[object Function]';
};

var uniqueId = 0;

function Completer(element, option) {
Expand Down Expand Up @@ -238,7 +234,7 @@
var strategy = this.strategies[i];
var context = strategy.context(text);
if (context || context === '') {
var matchRegexp = isFunction(strategy.match) ? strategy.match(text) : strategy.match;
var matchRegexp = $.isFunction(strategy.match) ? strategy.match(text) : strategy.match;
if (isString(context)) { text = context; }
var match = text.match(matchRegexp);
if (match) { return [strategy, match[strategy.index], match]; }
Expand Down
4 changes: 3 additions & 1 deletion src/content_editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
var content = selection.toString();
var post = content.substring(range.startOffset);
var newSubstr = strategy.replace(value, e);
var regExp;
if (typeof newSubstr !== 'undefined') {
if ($.isArray(newSubstr)) {
post = newSubstr[1] + post;
newSubstr = newSubstr[0];
}
pre = pre.replace(strategy.match, newSubstr)
regExp = $.isFunction(strategy.match) ? strategy.match(pre) : strategy.match;
pre = pre.replace(regExp, newSubstr)
.replace(/ $/, "&nbsp"); // &nbsp necessary at least for CKeditor to not eat spaces
range.selectNodeContents(range.startContainer);
range.deleteContents();
Expand Down
4 changes: 3 additions & 1 deletion src/ie_textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
var pre = this.getTextFromHeadToCaret();
var post = this.el.value.substring(pre.length);
var newSubstr = strategy.replace(value, e);
var regExp;
if (typeof newSubstr !== 'undefined') {
if ($.isArray(newSubstr)) {
post = newSubstr[1] + post;
newSubstr = newSubstr[0];
}
pre = pre.replace(strategy.match, newSubstr);
regExp = $.isFunction(strategy.match) ? strategy.match(pre) : strategy.match;
pre = pre.replace(regExp, newSubstr);
this.$el.val(pre + post);
this.el.focus();
var range = this.el.createTextRange();
Expand Down
4 changes: 3 additions & 1 deletion src/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
var pre = this.getTextFromHeadToCaret();
var post = this.el.value.substring(this.el.selectionEnd);
var newSubstr = strategy.replace(value, e);
var regExp;
if (typeof newSubstr !== 'undefined') {
if ($.isArray(newSubstr)) {
post = newSubstr[1] + post;
newSubstr = newSubstr[0];
}
pre = pre.replace(strategy.match, newSubstr);
regExp = $.isFunction(strategy.match) ? strategy.match(pre) : strategy.match;
pre = pre.replace(regExp, newSubstr);
this.$el.val(pre + post);
this.el.selectionStart = this.el.selectionEnd = pre.length;
}
Expand Down

0 comments on commit f54eb08

Please sign in to comment.