summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/libs/autocomplete.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-06-20 16:27:28 +0200
committerqsm-odoo <qsm@odoo.com>2017-06-21 12:56:13 +0200
commit85d1e76ddbac9aeedfba4710443b74cbcc6586be (patch)
treece266dbcf69bb3aae986bc3cdc91536c03597ef6 /addons/web/static/src/js/libs/autocomplete.js
parent9fc7a04b4b4bc68535620fda7cfe2bafba6e0081 (diff)
[IMP] web, *: reorganize our libraries' extensions
* web_editor, web_tour, website_event_track Before this commit, one JS file was responsible for all the library extensions and fixes. There were two main problems with this system: - The file was only available in the backend (as some extensions are made on backend-only libraries). - Some other modules were doing library customizations. This commit creates one file per library to regroup their associated customization and adds them in the right asset. These are placed in the web module and every other module should avoid doing customizations. This allows to have libraries consistency accross all modules and between the backend and the frontend.
Diffstat (limited to 'addons/web/static/src/js/libs/autocomplete.js')
-rw-r--r--addons/web/static/src/js/libs/autocomplete.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/addons/web/static/src/js/libs/autocomplete.js b/addons/web/static/src/js/libs/autocomplete.js
new file mode 100644
index 00000000000..72f3ee8911b
--- /dev/null
+++ b/addons/web/static/src/js/libs/autocomplete.js
@@ -0,0 +1,38 @@
+odoo.define('web.autocomplete.extensions', function () {
+'use strict';
+
+/**
+ * The jquery autocomplete library extensions and fixes should be done here to
+ * avoid patching in place.
+ */
+
+// jquery autocomplete tweak to allow html and classnames
+var proto = $.ui.autocomplete.prototype;
+var initSource = proto._initSource;
+
+function filter( array, term ) {
+ var matcher = new RegExp( $.ui.autocomplete.escapeRegex(term), "i" );
+ return $.grep( array, function (value_) {
+ return matcher.test( $( "<div>" ).html( value_.label || value_.value || value_ ).text() );
+ });
+}
+
+$.extend(proto, {
+ _initSource: function () {
+ if ( this.options.html && $.isArray(this.options.source) ) {
+ this.source = function (request, response) {
+ response( filter( this.options.source, request.term ) );
+ };
+ } else {
+ initSource.call( this );
+ }
+ },
+ _renderItem: function (ul, item) {
+ return $( "<li></li>" )
+ .data( "item.autocomplete", item )
+ .append( $( "<a></a>" )[ this.options.html ? "html" : "text" ]( item.label ) )
+ .appendTo( ul )
+ .addClass(item.classname);
+ },
+});
+});