Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for contenteditable #17221

Open
wants to merge 4 commits into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.1.2 (2020-06-02)

## Fixes

* Gulp upgrade to 4.0.2
* Adding support for `contenteditable`

# 1.1.1 (2016-06-25)

## Fixes
Expand Down
21 changes: 16 additions & 5 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var _ = function (input, o) {
container: _.CONTAINER,
item: _.ITEM,
replace: _.REPLACE,
tabSelect: false
tabSelect: false,
html: false
}, o);

this.index = -1;
Expand Down Expand Up @@ -146,12 +147,13 @@ _.prototype = {
}
else { // Element or CSS selector
list = $(list);
var ref = this;

if (list && list.children) {
var items = [];
slice.apply(list.children).forEach(function (el) {
if (!el.disabled) {
var text = el.textContent.trim();
var text = ref.html ? el.innerHTML.trim() : el.textContent.trim();
var value = el.value || text;
var label = el.label || text;
if (value !== "") {
Expand Down Expand Up @@ -299,6 +301,7 @@ _.prototype = {
evaluate: function() {
var me = this;
var value = this.input.value;
if (typeof this.input.hasAttribute != 'undefined' && this.input.hasAttribute('contenteditable')) value = this.html ? this.input.innerHTML : this.input.innerText;

if (value.length >= this.minChars && this._list && this._list.length > 0) {
this.index = -1;
Expand Down Expand Up @@ -348,11 +351,11 @@ _.prototype = {
_.all = [];

_.FILTER_CONTAINS = function (text, input) {
return RegExp($.regExpEscape(input.trim()), "i").test(text);
return RegExp($.regExpEscape(input.trim()), "i").test(this.html ? text.replace(/(<([^>]+)>)/ig,"") : text);
};

_.FILTER_STARTSWITH = function (text, input) {
return RegExp("^" + $.regExpEscape(input.trim()), "i").test(text);
return RegExp("^" + $.regExpEscape(input.trim()), "i").test(this.html ? text.replace(/(<([^>]+)>)/ig,"") : text);
};

_.SORT_BYLENGTH = function (a, b) {
Expand Down Expand Up @@ -381,7 +384,15 @@ _.ITEM = function (text, input, item_id) {
};

_.REPLACE = function (text) {
this.input.value = text.value;
if (typeof this.input.hasAttribute != 'undefined' && this.input.hasAttribute('contenteditable')) {
if (this.html) {
this.input.innerHTML = text.value;
} else {
this.input.innerText = text.value;
}
} else {
this.input.value = text.value;
}
};

_.DATA = function (item/*, input*/) { return item; };
Expand Down
2 changes: 1 addition & 1 deletion awesomplete.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion awesomplete.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ gulp.task('concat', function() {

});

gulp.task('default', ['minify', 'concat']);
gulp.task('default', gulp.series('minify', 'concat'));
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"homepage": "https://leaverou.github.io/awesomplete/",
"devDependencies": {
"gulp": "^3.9.0",
"gulp": "^4.0.2",
"gulp-concat": "^2.6.0",
"gulp-header": "^1.7.1",
"gulp-rename": "^1.2.2",
Expand Down