From 034c8abfc065a21bf7eab26f67fc43f657c7311e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Sun, 29 Mar 2020 09:58:32 -0400 Subject: [PATCH] Added search bar functionality. --- bazarr/api.py | 32 +- bazarr/main.py | 28 -- static/css/jquery.typeahead.min.css | 1 + static/css/jquery.typeahead.scss | 620 ++++++++++++++++++++++++++++ static/js/jquery.typeahead.min.js | 10 + views/_main.html | 40 +- 6 files changed, 698 insertions(+), 33 deletions(-) create mode 100644 static/css/jquery.typeahead.min.css create mode 100644 static/css/jquery.typeahead.scss create mode 100644 static/js/jquery.typeahead.min.js diff --git a/bazarr/api.py b/bazarr/api.py index e8e9a22d7..fe469b99d 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -10,8 +10,7 @@ import time from operator import itemgetter import platform import io -from calendar import day_name -import importlib +import re from get_args import args from config import settings, base_url, save_settings @@ -35,7 +34,7 @@ from scheduler import Scheduler from subliminal_patch.core import SUBTITLE_EXTENSIONS -from flask import Flask, jsonify, request, Response, Blueprint +from flask import Flask, jsonify, request, Response, Blueprint, url_for from flask_restful import Resource, Api @@ -67,6 +66,31 @@ class Languages(Resource): return jsonify(result) +class Search(Resource): + def get(self): + query = request.args.get('query') + search_list = [] + + if query: + if settings.general.getboolean('use_sonarr'): + # Get matching series + series = database.execute("SELECT title, sonarrSeriesId, year FROM table_shows WHERE title LIKE ? " + "ORDER BY title ASC", ("%"+query+"%",)) + for serie in series: + search_list.append({'name': re.sub(r'\ \(\d{4}\)', '', serie['title']) + ' (' + serie['year'] + ')', + 'url': url_for('episodes', no=serie['sonarrSeriesId'])}) + + if settings.general.getboolean('use_radarr'): + # Get matching movies + movies = database.execute("SELECT title, radarrId, year FROM table_movies WHERE title LIKE ? ORDER BY " + "title ASC", ("%"+query+"%",)) + for movie in movies: + search_list.append({'name': re.sub(r'\ \(\d{4}\)', '', movie['title']) + ' (' + movie['year'] + ')', + 'url': url_for('movie', no=movie['radarrId'])}) + + return jsonify(search_list) + + class SaveSettings(Resource): def post(self): save_settings(request.form.items()) @@ -1144,6 +1168,8 @@ class SearchWantedMovies(Resource): api.add_resource(Badges, '/badges') api.add_resource(Languages, '/languages') +api.add_resource(Search, '/search_json') + api.add_resource(SaveSettings, '/savesettings') api.add_resource(SystemTasks, '/systemtasks') diff --git a/bazarr/main.py b/bazarr/main.py index ca239b99b..afc8d0b17 100644 --- a/bazarr/main.py +++ b/bazarr/main.py @@ -511,34 +511,6 @@ def serieseditor(): return render_template('serieseditor.html') -@app.route('/search_json/', methods=['GET']) -@login_required -def search_json(query): - - - query = '%' + query + '%' - search_list = [] - - if settings.general.getboolean('use_sonarr'): - # Get matching series - series = database.execute("SELECT title, sonarrSeriesId, year FROM table_shows WHERE title LIKE ? ORDER BY " - "title ASC", (query,)) - for serie in series: - search_list.append(dict([('name', re.sub(r'\ \(\d{4}\)', '', serie['title']) + ' (' + serie['year'] + ')'), - ('url', '/episodes/' + str(serie['sonarrSeriesId']))])) - - if settings.general.getboolean('use_radarr'): - # Get matching movies - movies = database.execute("SELECT title, radarrId, year FROM table_movies WHERE title LIKE ? ORDER BY " - "title ASC", (query,)) - for movie in movies: - search_list.append(dict([('name', re.sub(r'\ \(\d{4}\)', '', movie['title']) + ' (' + movie['year'] + ')'), - ('url', '/movie/' + str(movie['radarrId']))])) - - request.content_type = 'application/json' - return dict(items=search_list) - - @app.route('/episodes/') @login_required def episodes(no): diff --git a/static/css/jquery.typeahead.min.css b/static/css/jquery.typeahead.min.css new file mode 100644 index 000000000..6f563ae15 --- /dev/null +++ b/static/css/jquery.typeahead.min.css @@ -0,0 +1 @@ +.typeahead__container button,.typeahead__container input,.typeahead__container optgroup,.typeahead__container select,.typeahead__container textarea{font:inherit;margin:0}.typeahead__container optgroup{font-weight:700}.typeahead__container button,.typeahead__container input{overflow:visible}.typeahead__container button,.typeahead__container select{text-transform:none}.typeahead__container [type=reset],.typeahead__container [type=submit],.typeahead__container button,.typeahead__container html [type=button]{-webkit-appearance:button}.typeahead__container [type=button]::-moz-focus-inner,.typeahead__container [type=reset]::-moz-focus-inner,.typeahead__container [type=submit]::-moz-focus-inner,.typeahead__container button::-moz-focus-inner{border-style:none;padding:0}.typeahead__container [type=button]:-moz-focusring,.typeahead__container [type=reset]:-moz-focusring,.typeahead__container [type=submit]:-moz-focusring,.typeahead__container button:-moz-focusring{outline:1px dotted ButtonText}.typeahead__container fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}.typeahead__container legend{-webkit-box-sizing:border-box;box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}.typeahead__container textarea{overflow:auto}.typeahead__container [type=checkbox],.typeahead__container [type=radio]{-webkit-box-sizing:border-box;box-sizing:border-box;padding:0}.typeahead__container [type=number]::-webkit-inner-spin-button,.typeahead__container [type=number]::-webkit-outer-spin-button{height:auto}.typeahead__container ::-webkit-input-placeholder{color:inherit;opacity:.54}.typeahead__container ::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}.typeahead__container{position:relative;font:1rem Lato,"Helvetica Neue",Arial,Helvetica,sans-serif}.typeahead__container *{-webkit-box-sizing:border-box;box-sizing:border-box;outline:0}.typeahead__query{position:relative;z-index:2;width:100%}.typeahead__filter{position:relative}.typeahead__filter button{min-width:100%;white-space:nowrap}.typeahead__filter button:after{display:inline-block;margin-left:4px;width:0;height:0;vertical-align:-2px;content:"";border:4px solid;border-right-color:transparent;border-bottom-color:transparent;border-left-color:transparent}.typeahead__field{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;position:relative;width:100%}.typeahead__button button{border-top-right-radius:2px;border-bottom-right-radius:2px}.typeahead__field{color:#555}.typeahead__field .typeahead__hint,.typeahead__field [contenteditable],.typeahead__field input,.typeahead__field textarea{display:block;width:100%;line-height:1.25;min-height:calc(.5rem * 2 + 1.25rem + 2px);padding:.5rem .75rem;background:#fff;border:1px solid #ccc;border-radius:2px 0 0 2px;-webkit-appearance:none;-moz-appearance:none;appearance:none;-webkit-box-sizing:border-box;box-sizing:border-box}.typeahead__field .typeahead__hint:active,.typeahead__field .typeahead__hint:focus,.typeahead__field [contenteditable]:active,.typeahead__field [contenteditable]:focus,.typeahead__field input:active,.typeahead__field input:focus,.typeahead__field textarea:active,.typeahead__field textarea:focus{border-color:#66afe9}.typeahead__container.hint .typeahead__field [contenteditable],.typeahead__container.hint .typeahead__field input,.typeahead__container.hint .typeahead__field textarea{background:0 0}.typeahead__container.hint .typeahead__query>:last-child,.typeahead__hint{background:#fff}.typeahead__container button{display:inline-block;margin-bottom:0;text-align:center;-ms-touch-action:manipulation;touch-action:manipulation;cursor:pointer;background-color:#fff;border:1px solid #ccc;line-height:1.25;padding:.5rem .75rem;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#555}.typeahead__container button:focus,.typeahead__container button:hover{color:#3c3c3c;background-color:#f5f5f5;border-color:#b3b3b3}.typeahead__container button.active,.typeahead__container button:active{background-image:none}.typeahead__container button:active,.typeahead__container button:focus{border-color:#66afe9}.typeahead__container button.disabled,.typeahead__container button[disabled],.typeahead__container input.disabled,.typeahead__container input[disabled]{cursor:not-allowed;pointer-events:none;opacity:.65;-webkit-box-shadow:none;box-shadow:none;background-color:#fff;border-color:#ccc}.typeahead__container .typeahead__field .typeahead__hint,.typeahead__container .typeahead__field .typeahead__label-container,.typeahead__container .typeahead__field [contenteditable],.typeahead__container .typeahead__field input,.typeahead__container .typeahead__field textarea{padding-right:32px}.typeahead__button,.typeahead__filter{z-index:1}.typeahead__button button,.typeahead__filter button{margin-left:-1px;border-bottom-left-radius:0;border-top-left-radius:0}.typeahead__button:active,.typeahead__button:focus,.typeahead__button:hover,.typeahead__filter:active,.typeahead__filter:focus,.typeahead__filter:hover{z-index:1001}.typeahead__button:active button:active,.typeahead__button:active button:focus,.typeahead__button:focus button:active,.typeahead__button:focus button:focus,.typeahead__button:hover button:active,.typeahead__button:hover button:focus,.typeahead__filter:active button:active,.typeahead__filter:active button:focus,.typeahead__filter:focus button:active,.typeahead__filter:focus button:focus,.typeahead__filter:hover button:active,.typeahead__filter:hover button:focus{z-index:1001}.typeahead__filter+.typeahead__button button{margin-left:-2px}.typeahead__container.filter .typeahead__filter{z-index:1001}.typeahead__dropdown,.typeahead__list{position:absolute;left:0;z-index:1000;width:100%;min-width:160px;padding:5px 0;margin:2px 0 0;list-style:none;text-align:left;background-color:#fff;border:1px solid #ccc;border-radius:2px;background-clip:padding-box}.typeahead__result.detached .typeahead__list{position:relative;z-index:1041;top:initial;left:initial}.typeahead__dropdown{right:0;left:initial;z-index:1001}.typeahead__list>li{position:relative;border-top:solid 1px #ccc}.typeahead__list>li:first-child{border-top:none}.typeahead__dropdown .typeahead__dropdown-item[disabled]>a,.typeahead__list .typeahead__item[disabled]>a{cursor:not-allowed;color:#bababa;background-color:#fafafa}.typeahead__dropdown .typeahead__dropdown-item>a,.typeahead__list .typeahead__item>a{display:block;padding:.5rem .75rem;clear:both;color:#333;text-decoration:none}.typeahead__dropdown .typeahead__dropdown-item:not([disabled]).active>a,.typeahead__dropdown .typeahead__dropdown-item:not([disabled])>a:focus,.typeahead__dropdown .typeahead__dropdown-item:not([disabled])>a:hover,.typeahead__list .typeahead__item:not([disabled]).active>a,.typeahead__list .typeahead__item:not([disabled])>a:focus,.typeahead__list .typeahead__item:not([disabled])>a:hover{background-color:#f5f5f5;color:#3c3c3c}.typeahead__list.empty>li{padding:.5rem .75rem;color:#333}.typeahead__list>.typeahead__group{border-color:#bfdef6;font-weight:700}.typeahead__list>.typeahead__group:first-child{border-top:solid 1px #bfdef6}.typeahead__list>.typeahead__group.active>a,.typeahead__list>.typeahead__group>a,.typeahead__list>.typeahead__group>a:focus,.typeahead__list>.typeahead__group>a:hover{cursor:default;color:#17639f;background:#ecf5fc;display:block;padding:.5rem .75rem;clear:both;text-decoration:none}.typeahead__list>li.typeahead__group+li.typeahead__item{border-color:#bfdef6}.typeahead__container.backdrop+.typeahead__backdrop,.typeahead__container.filter .typeahead__dropdown,.typeahead__container.hint .typeahead__hint,.typeahead__container.result .typeahead__list{display:block!important}.typeahead__container .typeahead__dropdown,.typeahead__container .typeahead__hint,.typeahead__container .typeahead__list,.typeahead__container+.typeahead__backdrop{display:none!important}.typeahead__dropdown li:last-child{margin-top:5px;padding-top:5px;border-top:solid 1px #ccc}.typeahead__cancel-button{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;position:absolute;right:0;cursor:pointer;line-height:1.25;padding:.5rem .75rem;visibility:hidden}.typeahead__label .typeahead__cancel-button{visibility:visible;right:4px}.typeahead__container.cancel:not(.loading) .typeahead__cancel-button,.typeahead__label .typeahead__cancel-button{visibility:visible}.typeahead__container.cancel:not(.loading) .typeahead__cancel-button:hover,.typeahead__label .typeahead__cancel-button:hover{color:#d0021b}.typeahead__search-icon{padding:0 1.25rem;width:16px;height:16px;background:url(data:image/svg+xml;charset=utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTguMS4xLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDI1MC4zMTMgMjUwLjMxMyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMjUwLjMxMyAyNTAuMzEzOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCI+CjxnIGlkPSJTZWFyY2giPgoJPHBhdGggc3R5bGU9ImZpbGwtcnVsZTpldmVub2RkO2NsaXAtcnVsZTpldmVub2RkOyIgZD0iTTI0NC4xODYsMjE0LjYwNGwtNTQuMzc5LTU0LjM3OGMtMC4yODktMC4yODktMC42MjgtMC40OTEtMC45My0wLjc2ICAgYzEwLjctMTYuMjMxLDE2Ljk0NS0zNS42NiwxNi45NDUtNTYuNTU0QzIwNS44MjIsNDYuMDc1LDE1OS43NDcsMCwxMDIuOTExLDBTMCw0Ni4wNzUsMCwxMDIuOTExICAgYzAsNTYuODM1LDQ2LjA3NCwxMDIuOTExLDEwMi45MSwxMDIuOTExYzIwLjg5NSwwLDQwLjMyMy02LjI0NSw1Ni41NTQtMTYuOTQ1YzAuMjY5LDAuMzAxLDAuNDcsMC42NCwwLjc1OSwwLjkyOWw1NC4zOCw1NC4zOCAgIGM4LjE2OSw4LjE2OCwyMS40MTMsOC4xNjgsMjkuNTgzLDBDMjUyLjM1NCwyMzYuMDE3LDI1Mi4zNTQsMjIyLjc3MywyNDQuMTg2LDIxNC42MDR6IE0xMDIuOTExLDE3MC4xNDYgICBjLTM3LjEzNCwwLTY3LjIzNi0zMC4xMDItNjcuMjM2LTY3LjIzNWMwLTM3LjEzNCwzMC4xMDMtNjcuMjM2LDY3LjIzNi02Ny4yMzZjMzcuMTMyLDAsNjcuMjM1LDMwLjEwMyw2Ny4yMzUsNjcuMjM2ICAgQzE3MC4xNDYsMTQwLjA0NCwxNDAuMDQzLDE3MC4xNDYsMTAyLjkxMSwxNzAuMTQ2eiIgZmlsbD0iIzU1NTU1NSIvPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=) no-repeat scroll center center transparent}.typeahead__container.loading .typeahead__query:after,.typeahead__container.loading .typeahead__query:before{-webkit-transition:all 0s linear,opacity .2s ease;-o-transition:all 0s linear,opacity .2s ease;transition:all 0s linear,opacity .2s ease;position:absolute;z-index:3;content:"";top:50%;right:.55em;margin-top:-.675rem;width:1.35rem;height:1.35rem;-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:500rem;border-style:solid;border-width:.1em}.typeahead__container.loading .typeahead__query:before{border-color:rgba(0,0,0,.35)}.typeahead__container.loading .typeahead__query:after{-webkit-animation:button-spin .6s linear;animation:button-spin .6s linear;-webkit-animation-iteration-count:infinite;animation-iteration-count:infinite;border-color:#fff transparent transparent;-webkit-box-shadow:0 0 0 1px transparent;box-shadow:0 0 0 1px transparent}@-webkit-keyframes button-spin{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}@keyframes button-spin{from{-webkit-transform:rotate(0);transform:rotate(0)}to{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}.typeahead__label-container{list-style:none;position:absolute;padding-top:calc(1rem * .375);padding-left:6px;width:100%;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex}.typeahead__label{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;font-size:calc(1rem * .875);position:relative;background:#ecf5fc;border:solid 1px #c2e0ff;padding-left:4px;border-radius:2px;margin-right:4px;margin-bottom:calc(1rem * .375)}.typeahead__label>*{-webkit-align-self:center;-ms-flex-item-align:center;align-self:center}.typeahead__label .typeahead__cancel-button{line-height:normal;height:auto;position:static;padding-top:calc(1rem * .25 - 1px);padding-bottom:calc(1rem * .25 + 1px);padding-left:6px;padding-right:6px;margin-left:4px;font-size:calc(1rem * .875);border-left:solid 1px #c2e0ff}.typeahead__label .typeahead__cancel-button:hover{background-color:#d5e9f9} \ No newline at end of file diff --git a/static/css/jquery.typeahead.scss b/static/css/jquery.typeahead.scss new file mode 100644 index 000000000..477ab3b60 --- /dev/null +++ b/static/css/jquery.typeahead.scss @@ -0,0 +1,620 @@ +// FORM RESETS ----------------- https://github.com/necolas/normalize.css/ --------------------------------------------- + +.typeahead__container { + button, + input, + optgroup, + select, + textarea { + font: inherit; /* 1 */ + margin: 0; /* 2 */ + } + + /** + * Restore the font weight unset by the previous rule. + */ + + optgroup { + font-weight: bold; + } + + /** + * Show the overflow in IE. + * 1. Show the overflow in Edge. + */ + + button, + input { /* 1 */ + overflow: visible; + } + + /** + * Remove the inheritance of text transform in Edge, Firefox, and IE. + * 1. Remove the inheritance of text transform in Firefox. + */ + + button, + select { /* 1 */ + text-transform: none; + } + + /** + * 1. Prevent a WebKit bug where (2) destroys native `audio` and `video` + * controls in Android 4. + * 2. Correct the inability to style clickable types in iOS and Safari. + */ + + button, + html [type="button"], /* 1 */ + [type="reset"], + [type="submit"] { + -webkit-appearance: button; /* 2 */ + } + + /** + * Remove the inner border and padding in Firefox. + */ + + button::-moz-focus-inner, + [type="button"]::-moz-focus-inner, + [type="reset"]::-moz-focus-inner, + [type="submit"]::-moz-focus-inner { + border-style: none; + padding: 0; + } + + /** + * Restore the focus styles unset by the previous rule. + */ + + button:-moz-focusring, + [type="button"]:-moz-focusring, + [type="reset"]:-moz-focusring, + [type="submit"]:-moz-focusring { + outline: 1px dotted ButtonText; + } + + /** + * Change the border, margin, and padding in all browsers (opinionated). + */ + + fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; + } + + /** + * 1. Correct the text wrapping in Edge and IE. + * 2. Correct the color inheritance from `fieldset` elements in IE. + * 3. Remove the padding so developers are not caught out when they zero out + * `fieldset` elements in all browsers. + */ + + legend { + box-sizing: border-box; /* 1 */ + color: inherit; /* 2 */ + display: table; /* 1 */ + max-width: 100%; /* 1 */ + padding: 0; /* 3 */ + white-space: normal; /* 1 */ + } + + /** + * Remove the default vertical scrollbar in IE. + */ + + textarea { + overflow: auto; + } + + /** + * 1. Add the correct box sizing in IE 10-. + * 2. Remove the padding in IE 10-. + */ + + [type="checkbox"], + [type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ + } + + /** + * Correct the cursor style of increment and decrement buttons in Chrome. + */ + + [type="number"]::-webkit-inner-spin-button, + [type="number"]::-webkit-outer-spin-button { + height: auto; + } + + /** + * 1. Correct the odd appearance in Chrome and Safari. + * 2. Correct the outline style in Safari. + */ + + /** + * Correct the text style of placeholders in Chrome, Edge, and Safari. + */ + + ::-webkit-input-placeholder { + color: inherit; + opacity: 0.54; + } + + /** + * 1. Correct the inability to style clickable types in iOS and Safari. + * 2. Change font properties to `inherit` in Safari. + */ + + ::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ + } +} + +// VARIABLES ----------------------------------------------------------------------------------------------------------- + +$typeahead-font-size: 1rem !default; +$typeahead-line-height: 1.25 !default; +$typeahead-font-family: Lato, "Helvetica Neue", Arial, Helvetica, sans-serif !default; +$typeahead-primary-color: #66afe9 !default; +$typeahead-cancel-color: #d0021b !default; +$typeahead-radius: 2px !default; +$typeahead-shadow: false !default; // true / false +$typeahead-dropdown-spacing: 5px !default; +$typeahead-outline-color: $typeahead-primary-color !default; +$typeahead-loading-size: 1.35rem !default; + +$typeahead-padding-y: 0.5rem !default; +$typeahead-padding-x: 0.75rem !default; + +$typeahead-color: #555 !default; +$typeahead-border-color: #ccc !default; + +$typeahead-group-color: darken($typeahead-primary-color, 30%) !default; +$typeahead-group-background: lighten($typeahead-primary-color, 30%) !default; +$typeahead-group-border-color: lighten($typeahead-primary-color, 20%) !default; + +$typeahead-item-color: #333 !default; +$typeahead-item-background: #fff !default; +$typeahead-item-hover-background: #f5f5f5 !default; +$typeahead-item-disabled-color: #bababa !default; +$typeahead-item-disabled-background: #fafafa !default; + +$typeahead-label-color: #3a99fc !default; +$typeahead-label-font-size: calc(#{$typeahead-font-size} * 0.875) !default; +$typeahead-label-border-color: #c2e0ff !default; +$typeahead-label-background: lighten($typeahead-primary-color, 30%) !default; + +// TYPEAHEAD ----------------------------------------------------------------------------------------------------------- + +.typeahead__ { + &container { + position: relative; + font: $typeahead-font-size $typeahead-font-family; + } + + &container * { + box-sizing: border-box; + outline: 0; + } + + &query { + position: relative; + z-index: 2; + width: 100%; + } + + &filter { + position: relative; + button { + min-width: 100%; + white-space: nowrap; + &:after { + display: inline-block; + margin-left: 4px; + width: 0; + height: 0; + vertical-align: -2px; + content: ""; + border: 4px solid; + border-right-color: transparent; + border-bottom-color: transparent; + border-left-color: transparent; + } + } + } + + &field { + display: flex; + position: relative; + width: 100%; + } + + &button button { + border-top-right-radius: $typeahead-radius; + border-bottom-right-radius: $typeahead-radius; + } + + &field { + // #193 If applied to input, it overrides the placeholder color on IE10/11 + color: $typeahead-color; + input, + textarea, + [contenteditable], + .typeahead__hint { + display: block; + width: 100%; + line-height: $typeahead-line-height; + min-height: calc(#{$typeahead-padding-y} * 2 + 1.25rem + 2px); + padding: $typeahead-padding-y $typeahead-padding-x; + background: #fff; + border: 1px solid $typeahead-border-color; + border-radius: $typeahead-radius 0 0 $typeahead-radius; + appearance: none; + box-sizing: border-box; + @if ($typeahead-shadow) { + box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075); + } + + &:focus, + &:active { + border-color: $typeahead-outline-color; + } + + //border-color: #007eff; + //box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 0 3px rgba(0, 126, 255, 0.1); + } + } + + &container.hint .typeahead__field { + input, + textarea, + [contenteditable] { + background: transparent; + } + } + + &container.hint .typeahead__query > :last-child, + &hint { + background: #fff; + } + + &container button { + display: inline-block; + margin-bottom: 0; + text-align: center; + touch-action: manipulation; + cursor: pointer; + background-color: #fff; + border: 1px solid $typeahead-border-color; + line-height: $typeahead-line-height; + padding: $typeahead-padding-y $typeahead-padding-x; + user-select: none; + color: $typeahead-color; + @if ($typeahead-shadow) { + box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.05); + } + + &:hover, + &:focus { + color: darken($typeahead-color, 10%); + background-color: $typeahead-item-hover-background; + border-color: darken($typeahead-border-color, 10%); + } + + &:active, + &.active { + background-image: none; + @if ($typeahead-shadow) { + box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.125); + } + } + + &:focus, + &:active { + border-color: $typeahead-outline-color; + } + } + + &container { + input.disabled, + input[disabled], + button.disabled, + button[disabled] { + cursor: not-allowed; + pointer-events: none; + opacity: 0.65; + box-shadow: none; + background-color: #fff; + border-color: $typeahead-border-color; + } + + //&.multiselect, + //&.loading, + //&.cancel { + .typeahead__field { + input, + textarea, + [contenteditable], + .typeahead__hint, + .typeahead__label-container { + padding-right: 32px; + } + } + //} + } + + &filter, + &button { + z-index: 1; + button { + margin-left: -1px; + border-bottom-left-radius: 0; + border-top-left-radius: 0; + } + + &:hover, + &:active, + &:focus { + z-index: 1001; + button { + &:focus, + &:active { + z-index: 1001; + } + } + } + } + + &filter + &button { + button { + margin-left: -2px; + } + } + + &container.filter .typeahead__filter { + z-index: 1001; + } + + &list, + &dropdown { + position: absolute; + //top: 100%; + left: 0; + z-index: 1000; + width: 100%; + min-width: 160px; + padding: $typeahead-dropdown-spacing 0; + margin: 2px 0 0; + list-style: none; + text-align: left; + background-color: #fff; + border: 1px solid $typeahead-border-color; + border-radius: $typeahead-radius; + background-clip: padding-box; + @if ($typeahead-shadow) { + box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175); + } + } + + &result.detached .typeahead__list { + position: relative; + z-index: 1041; + top: initial; + left: initial; + } + + &dropdown { + right: 0; + left: initial; + z-index: 1001; + } + + &list > li { + position: relative; + border-top: solid 1px $typeahead-border-color; + &:first-child { + border-top: none; + } + } + + &list .typeahead__item, + &dropdown .typeahead__dropdown-item { + &[disabled] { + > a { + cursor: not-allowed; + color: $typeahead-item-disabled-color; + background-color: $typeahead-item-disabled-background; + } + } + + > a { + display: block; + padding: $typeahead-padding-y $typeahead-padding-x; + clear: both; + color: $typeahead-item-color; + text-decoration: none; + } + + &:not([disabled]) { + > a:hover, + > a:focus, + &.active > a { + background-color: $typeahead-item-hover-background; + color: darken($typeahead-color, 10%); + } + } + } + + &list.empty { + > li { + padding: $typeahead-padding-y $typeahead-padding-x; + color: $typeahead-item-color; + } + } + + &list > .typeahead__group { + border-color: $typeahead-group-border-color; + font-weight: bold; + + &:first-child { + @if ($typeahead-dropdown-spacing > 0) { + border-top: solid 1px $typeahead-group-border-color; + } + } + > a, + > a:hover, + > a:focus, + &.active > a { + cursor: default; + color: $typeahead-group-color; + background: $typeahead-group-background; + display: block; + padding: $typeahead-padding-y $typeahead-padding-x; + clear: both; + text-decoration: none; + } + } + + &list > { + li.typeahead__group + li.typeahead__item { + border-color: $typeahead-group-border-color; + } + } + + &container { + &.result .typeahead__list, + &.filter .typeahead__dropdown, + &.hint .typeahead__hint, + &.backdrop + .typeahead__backdrop { + display: block !important; + } + .typeahead__list, + .typeahead__dropdown, + .typeahead__hint, + + .typeahead__backdrop { + display: none !important; + } + } + + &dropdown li:last-child { + margin-top: $typeahead-dropdown-spacing; + padding-top: $typeahead-dropdown-spacing; + border-top: solid 1px $typeahead-border-color; + } + + &cancel-button { + user-select: none; + position: absolute; + right: 0; + cursor: pointer; + line-height: 1.25; + padding: $typeahead-padding-y $typeahead-padding-x; + visibility: hidden; + .typeahead__label & { + visibility: visible; + right: 4px; + } + } + + &container.cancel:not(.loading), + &label { + .typeahead__cancel-button { + visibility: visible; + &:hover { + color: $typeahead-cancel-color; + } + } + } + + &search-icon { + padding: 0 1.25rem; + width: 16px; + height: 16px; + // Reference: http://www.flaticon.com/free-icon/musica-searcher_70376 + background: url(data:image/svg+xml;charset=utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pgo8IS0tIEdlbmVyYXRvcjogQWRvYmUgSWxsdXN0cmF0b3IgMTguMS4xLCBTVkcgRXhwb3J0IFBsdWctSW4gLiBTVkcgVmVyc2lvbjogNi4wMCBCdWlsZCAwKSAgLS0+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiBpZD0iQ2FwYV8xIiB4PSIwcHgiIHk9IjBweCIgdmlld0JveD0iMCAwIDI1MC4zMTMgMjUwLjMxMyIgc3R5bGU9ImVuYWJsZS1iYWNrZ3JvdW5kOm5ldyAwIDAgMjUwLjMxMyAyNTAuMzEzOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSIgd2lkdGg9IjE2cHgiIGhlaWdodD0iMTZweCI+CjxnIGlkPSJTZWFyY2giPgoJPHBhdGggc3R5bGU9ImZpbGwtcnVsZTpldmVub2RkO2NsaXAtcnVsZTpldmVub2RkOyIgZD0iTTI0NC4xODYsMjE0LjYwNGwtNTQuMzc5LTU0LjM3OGMtMC4yODktMC4yODktMC42MjgtMC40OTEtMC45My0wLjc2ICAgYzEwLjctMTYuMjMxLDE2Ljk0NS0zNS42NiwxNi45NDUtNTYuNTU0QzIwNS44MjIsNDYuMDc1LDE1OS43NDcsMCwxMDIuOTExLDBTMCw0Ni4wNzUsMCwxMDIuOTExICAgYzAsNTYuODM1LDQ2LjA3NCwxMDIuOTExLDEwMi45MSwxMDIuOTExYzIwLjg5NSwwLDQwLjMyMy02LjI0NSw1Ni41NTQtMTYuOTQ1YzAuMjY5LDAuMzAxLDAuNDcsMC42NCwwLjc1OSwwLjkyOWw1NC4zOCw1NC4zOCAgIGM4LjE2OSw4LjE2OCwyMS40MTMsOC4xNjgsMjkuNTgzLDBDMjUyLjM1NCwyMzYuMDE3LDI1Mi4zNTQsMjIyLjc3MywyNDQuMTg2LDIxNC42MDR6IE0xMDIuOTExLDE3MC4xNDYgICBjLTM3LjEzNCwwLTY3LjIzNi0zMC4xMDItNjcuMjM2LTY3LjIzNWMwLTM3LjEzNCwzMC4xMDMtNjcuMjM2LDY3LjIzNi02Ny4yMzZjMzcuMTMyLDAsNjcuMjM1LDMwLjEwMyw2Ny4yMzUsNjcuMjM2ICAgQzE3MC4xNDYsMTQwLjA0NCwxNDAuMDQzLDE3MC4xNDYsMTAyLjkxMSwxNzAuMTQ2eiIgZmlsbD0iIzU1NTU1NSIvPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+CjxnPgo8L2c+Cjwvc3ZnPgo=) no-repeat scroll center center transparent; + } + + &container.loading .typeahead__query { + &:before, + &:after { + transition: all 0s linear, opacity 0.2s ease; + position: absolute; + z-index: 3; + content: ""; + top: 50%; + right: 0.55em; + margin-top: -($typeahead-loading-size / 2); + width: $typeahead-loading-size; + height: $typeahead-loading-size; + box-sizing: border-box; + border-radius: 500rem; + border-style: solid; + border-width: 0.1em; + } + + &:before { + border-color: rgba(0, 0, 0, 0.35); + } + + &:after { + animation: button-spin 0.6s linear; + animation-iteration-count: infinite; + border-color: #fff transparent transparent; + box-shadow: 0 0 0 1px transparent; + } + + @keyframes button-spin { + from { + transform: rotate(0deg); + } + to { + transform: rotate(360deg); + } + } + } + + &label-container { + list-style: none; + position: absolute; + padding-top: calc(#{$typeahead-font-size} * 0.375); + padding-left: 6px; + width: 100%; + flex-wrap: wrap; + display: flex; + } + + &label { + display: flex; + font-size: $typeahead-label-font-size; + position: relative; + background: $typeahead-label-background; + border: solid 1px $typeahead-label-border-color; + padding-left: 4px; + border-radius: $typeahead-radius; + margin-right: 4px; + margin-bottom: calc(#{$typeahead-font-size} * 0.375); + + > * { + align-self: center; + } + + .typeahead__cancel-button { + line-height: normal; + height: auto; + position: static; + padding-top: calc(#{$typeahead-font-size} * 0.25 - 1px); + padding-bottom: calc(#{$typeahead-font-size} * 0.25 + 1px); + padding-left: 6px; + padding-right: 6px; + margin-left: 4px; + font-size: $typeahead-label-font-size; + border-left: solid 1px $typeahead-label-border-color; + &:hover { + background-color: darken($typeahead-label-background, 5%); + } + } + } +} diff --git a/static/js/jquery.typeahead.min.js b/static/js/jquery.typeahead.min.js new file mode 100644 index 000000000..be0d97f49 --- /dev/null +++ b/static/js/jquery.typeahead.min.js @@ -0,0 +1,10 @@ +/*! + * jQuery Typeahead + * Copyright (C) 2019 RunningCoder.org + * Licensed under the MIT license + * + * @author Tom Bertrand + * @version 2.11.0 (2019-10-31) + * @link http://www.runningcoder.org/jquerytypeahead/ + */ +!function(e){var t;"function"==typeof define&&define.amd?define("jquery-typeahead",["jquery"],function(t){return e(t)}):"object"==typeof module&&module.exports?module.exports=(void 0===t&&(t="undefined"!=typeof window?require("jquery"):require("jquery")(void 0)),e(t)):e(jQuery)}(function(j){"use strict";function r(t,e){this.rawQuery=t.val()||"",this.query=t.val()||"",this.selector=t[0].selector,this.deferred=null,this.tmpSource={},this.source={},this.dynamicGroups=[],this.hasDynamicGroups=!1,this.generatedGroupCount=0,this.groupBy="group",this.groups=[],this.searchGroups=[],this.generateGroups=[],this.requestGroups=[],this.result=[],this.tmpResult={},this.groupTemplate="",this.resultHtml=null,this.resultCount=0,this.resultCountPerGroup={},this.options=e,this.node=t,this.namespace="."+this.helper.slugify.call(this,this.selector)+".typeahead",this.isContentEditable=void 0!==this.node.attr("contenteditable")&&"false"!==this.node.attr("contenteditable"),this.container=null,this.resultContainer=null,this.item=null,this.items=null,this.comparedItems=null,this.xhr={},this.hintIndex=null,this.filters={dropdown:{},dynamic:{}},this.dropdownFilter={static:[],dynamic:[]},this.dropdownFilterAll=null,this.isDropdownEvent=!1,this.requests={},this.backdrop={},this.hint={},this.label={},this.hasDragged=!1,this.focusOnly=!1,this.displayEmptyTemplate,this.__construct()}var i,s={input:null,minLength:2,maxLength:!(window.Typeahead={version:"2.11.0"}),maxItem:8,dynamic:!1,delay:300,order:null,offset:!1,hint:!1,accent:!1,highlight:!0,multiselect:null,group:!1,groupOrder:null,maxItemPerGroup:null,dropdownFilter:!1,dynamicFilter:null,backdrop:!1,backdropOnFocus:!1,cache:!1,ttl:36e5,compression:!1,searchOnFocus:!1,blurOnTab:!0,resultContainer:null,generateOnLoad:null,mustSelectItem:!1,href:null,display:["display"],template:null,templateValue:null,groupTemplate:null,correlativeTemplate:!1,emptyTemplate:!1,cancelButton:!0,loadingAnimation:!0,asyncResult:!1,filter:!0,matcher:null,source:null,callback:{onInit:null,onReady:null,onShowLayout:null,onHideLayout:null,onSearch:null,onResult:null,onLayoutBuiltBefore:null,onLayoutBuiltAfter:null,onNavigateBefore:null,onNavigateAfter:null,onEnter:null,onLeave:null,onClickBefore:null,onClickAfter:null,onDropdownFilter:null,onSendRequest:null,onReceiveRequest:null,onPopulateSource:null,onCacheSave:null,onSubmit:null,onCancel:null},selector:{container:"typeahead__container",result:"typeahead__result",list:"typeahead__list",group:"typeahead__group",item:"typeahead__item",empty:"typeahead__empty",display:"typeahead__display",query:"typeahead__query",filter:"typeahead__filter",filterButton:"typeahead__filter-button",dropdown:"typeahead__dropdown",dropdownItem:"typeahead__dropdown-item",labelContainer:"typeahead__label-container",label:"typeahead__label",button:"typeahead__button",backdrop:"typeahead__backdrop",hint:"typeahead__hint",cancelButton:"typeahead__cancel-button"},debug:!1},o={from:"ãàáäâẽèéëêìíïîõòóöôùúüûñç",to:"aaaaaeeeeeiiiiooooouuuunc"},n=~window.navigator.appVersion.indexOf("MSIE 9."),a=~window.navigator.appVersion.indexOf("MSIE 10"),l=!!~window.navigator.userAgent.indexOf("Trident")&&~window.navigator.userAgent.indexOf("rv:11");r.prototype={_validateCacheMethod:function(t){var e;if(!0===t)t="localStorage";else if("string"==typeof t&&!~["localStorage","sessionStorage"].indexOf(t))return!1;e=void 0!==window[t];try{window[t].setItem("typeahead","typeahead"),window[t].removeItem("typeahead")}catch(t){e=!1}return e&&t||!1},extendOptions:function(){if(this.options.cache=this._validateCacheMethod(this.options.cache),this.options.compression&&("object"==typeof LZString&&this.options.cache||(this.options.compression=!1)),this.options.maxLength&&!isNaN(this.options.maxLength)||(this.options.maxLength=1/0),void 0!==this.options.maxItem&&~[0,!1].indexOf(this.options.maxItem)&&(this.options.maxItem=1/0),this.options.maxItemPerGroup&&!/^\d+$/.test(this.options.maxItemPerGroup)&&(this.options.maxItemPerGroup=null),this.options.display&&!Array.isArray(this.options.display)&&(this.options.display=[this.options.display]),this.options.multiselect&&(this.items=[],this.comparedItems=[],"string"==typeof this.options.multiselect.matchOn&&(this.options.multiselect.matchOn=[this.options.multiselect.matchOn])),this.options.group&&(Array.isArray(this.options.group)||("string"==typeof this.options.group?this.options.group={key:this.options.group}:"boolean"==typeof this.options.group&&(this.options.group={key:"group"}),this.options.group.key=this.options.group.key||"group")),this.options.highlight&&!~["any",!0].indexOf(this.options.highlight)&&(this.options.highlight=!1),this.options.dropdownFilter&&this.options.dropdownFilter instanceof Object){Array.isArray(this.options.dropdownFilter)||(this.options.dropdownFilter=[this.options.dropdownFilter]);for(var t=0,e=this.options.dropdownFilter.length;te.maxLength&&(e.minLength=e.maxLength),this.options.source[t]=e,this.options.source[t].dynamic&&this.dynamicGroups.push(t),e.cache=void 0!==e.cache?this._validateCacheMethod(e.cache):this.options.cache,e.compression&&("object"==typeof LZString&&e.cache||(e.compression=!1))}return this.hasDynamicGroups=this.options.dynamic||!!this.dynamicGroups.length,!0},init:function(){this.helper.executeCallback.call(this,this.options.callback.onInit,[this.node]),this.container=this.node.closest("."+this.options.selector.container)},delegateEvents:function(){var i=this,t=["focus"+this.namespace,"input"+this.namespace,"propertychange"+this.namespace,"keydown"+this.namespace,"keyup"+this.namespace,"search"+this.namespace,"generate"+this.namespace];j("html").on("touchmove",function(){i.hasDragged=!0}).on("touchstart",function(){i.hasDragged=!1}),this.node.closest("form").on("submit",function(t){if(!i.options.mustSelectItem||!i.helper.isEmpty(i.item))return i.options.backdropOnFocus||i.hideLayout(),i.options.callback.onSubmit?i.helper.executeCallback.call(i,i.options.callback.onSubmit,[i.node,this,i.item||i.items,t]):void 0;t.preventDefault()}).on("reset",function(){setTimeout(function(){i.node.trigger("input"+i.namespace),i.hideLayout()})});var s=!1;if(this.node.attr("placeholder")&&(a||l)){var e=!0;this.node.on("focusin focusout",function(){e=!(this.value||!this.placeholder)}),this.node.on("input",function(t){e&&(t.stopImmediatePropagation(),e=!1)})}this.node.off(this.namespace).on(t.join(" "),function(t,e){switch(t.type){case"generate":i.generateSource(Object.keys(i.options.source));break;case"focus":if(i.focusOnly){i.focusOnly=!1;break}i.options.backdropOnFocus&&(i.buildBackdropLayout(),i.showLayout()),i.options.searchOnFocus&&!i.item&&(i.deferred=j.Deferred(),i.assignQuery(),i.generateSource());break;case"keydown":8===t.keyCode&&i.options.multiselect&&i.options.multiselect.cancelOnBackspace&&""===i.query&&i.items.length?i.cancelMultiselectItem(i.items.length-1,null,t):t.keyCode&&~[9,13,27,38,39,40].indexOf(t.keyCode)&&(s=!0,i.navigate(t));break;case"keyup":n&&i.node[0].value.replace(/^\s+/,"").toString().length=this.options.source[t].minLength&&this.query.length<=this.options.source[t].maxLength){if(this.filters.dropdown&&"group"===this.filters.dropdown.key&&this.filters.dropdown.value!==t)continue;if(this.searchGroups.push(t),!this.options.source[t].dynamic&&this.source[t])continue;this.generateGroups.push(t)}},generateSource:function(t){if(this.filterGenerateSource(),this.generatedGroupCount=0,Array.isArray(t)&&t.length)this.generateGroups=t;else if(!this.generateGroups.length)return void this.node.trigger("search"+this.namespace);if(this.requestGroups=[],this.options.loadingAnimation&&this.container.addClass("loading"),!this.helper.isEmpty(this.xhr)){for(var e in this.xhr)this.xhr.hasOwnProperty(e)&&this.xhr[e].abort();this.xhr={}}for(var i,s,o,n,r,a,l,h=this,c=(e=0,this.generateGroups.length);e(new Date).getTime()?(this.populateSource(a.data,i),l=!0):window[n].removeItem("TYPEAHEAD_"+this.selector+":"+i)}catch(t){}if(l)continue}!o.data||o.ajax?o.ajax&&(this.requests[i]||(this.requests[i]=this.generateRequestObject(i)),this.requestGroups.push(i)):"function"==typeof o.data?(s=o.data.call(this),Array.isArray(s)?h.populateSource(s,i):"function"==typeof s.promise&&function(e){j.when(s).then(function(t){t&&Array.isArray(t)&&h.populateSource(t,e)})}(i)):this.populateSource(j.extend(!0,[],o.data),i)}return this.requestGroups.length&&this.handleRequests(),this.options.asyncResult&&this.searchGroups.length!==this.generateGroups&&this.node.trigger("search"+this.namespace),!!this.generateGroups.length},generateRequestObject:function(s){var o=this,n=this.options.source[s],t={request:{url:n.ajax.url||null,dataType:"json",beforeSend:function(t,e){o.xhr[s]=t;var i=o.requests[s].callback.beforeSend||n.ajax.beforeSend;"function"==typeof i&&i.apply(null,arguments)}},callback:{beforeSend:null,done:null,fail:null,then:null,always:null},extra:{path:n.ajax.path||null,group:s},validForGroup:[s]};if("function"!=typeof n.ajax&&(n.ajax instanceof Object&&(t=this.extendXhrObject(t,n.ajax)),1/g," ").replace(/\s{2,}/," ").trim();for(l=0,h=i.length;l").html(g.replace(/\{\{([\w\-\.]+)(?:\|(\w+))?}}/g,function(t,e){return s.helper.namespace.call(s,e,i[l],"get","")}).trim()).text();o.display?~o.display.indexOf("compiled")||o.display.unshift("compiled"):~this.options.display.indexOf("compiled")||this.options.display.unshift("compiled")}else;}this.options.callback.onPopulateSource&&(i=this.helper.executeCallback.call(this,this.options.callback.onPopulateSource,[this.node,i,t,e])),this.tmpSource[t]=Array.isArray(i)&&i||[];var y=this.options.source[t].cache,v=this.options.source[t].compression,b=this.options.source[t].ttl||this.options.ttl;if(y&&!window[y].getItem("TYPEAHEAD_"+this.selector+":"+t)){this.options.callback.onCacheSave&&(i=this.helper.executeCallback.call(this,this.options.callback.onCacheSave,[this.node,i,t,e]));var k=JSON.stringify({data:i,ttl:(new Date).getTime()+b});v&&(k=LZString.compressToUTF16(k)),window[y].setItem("TYPEAHEAD_"+this.selector+":"+t,k)}this.incrementGeneratedGroup(t)},incrementGeneratedGroup:function(t){if(this.generatedGroupCount++,this.generatedGroupCount===this.generateGroups.length||this.options.asyncResult){this.xhr&&this.xhr[t]&&delete this.xhr[t];for(var e=0,i=this.generateGroups.length;e=this.query.length&&i.filter('[data-index="'+this.hintIndex+'"]').find("a:first")[0].click()}},getTemplateValue:function(i){if(i){var t=i.group&&this.options.source[i.group].templateValue||this.options.templateValue;if("function"==typeof t&&(t=t.call(this)),!t)return this.helper.namespace.call(this,i.matchedKey,i).toString();var s=this;return t.replace(/\{\{([\w\-.]+)}}/gi,function(t,e){return s.helper.namespace.call(s,e,i,"get","")})}},clearActiveItem:function(){this.resultContainer.find("."+this.options.selector.item).removeClass("active")},addActiveItem:function(t){t.addClass("active")},searchResult:function(){this.resetLayout(),!1!==this.helper.executeCallback.call(this,this.options.callback.onSearch,[this.node,this.query])&&(!this.searchGroups.length||this.options.multiselect&&this.options.multiselect.limit&&this.items.length>=this.options.multiselect.limit||this.searchResultData(),this.helper.executeCallback.call(this,this.options.callback.onResult,[this.node,this.query,this.result,this.resultCount,this.resultCountPerGroup]),this.isDropdownEvent&&(this.helper.executeCallback.call(this,this.options.callback.onDropdownFilter,[this.node,this.query,this.filters.dropdown,this.result]),this.isDropdownEvent=!1))},searchResultData:function(){var t,e,i,s,o,n,r,a,l,h,c,p=this.groupBy,u=null,d=this.query.toLowerCase(),f=this.options.maxItem,m=this.options.maxItemPerGroup,g=this.filters.dynamic&&!this.helper.isEmpty(this.filters.dynamic),y="function"==typeof this.options.matcher&&this.options.matcher;this.options.accent&&(d=this.helper.removeAccent.call(this,d));for(var v=0,b=this.searchGroups.length;v=f)||this.options.callback.onResult);k++)if((!g||this.dynamicFilter.validate.apply(this,[this.source[F][k]]))&&null!==(t=this.source[F][k])&&"boolean"!=typeof t&&(!this.options.multiselect||this.isMultiselectUniqueData(t))&&(!this.filters.dropdown||(t[this.filters.dropdown.key]||"").toLowerCase()===(this.filters.dropdown.value||"").toLowerCase())){if((u="group"===p?F:t[p]?t[p]:t.group)&&!this.tmpResult[u]&&(this.tmpResult[u]=[],this.resultCountPerGroup[u]=0),m&&"group"===p&&this.tmpResult[u].length>=m&&!this.options.callback.onResult)break;for(var x=0,C=(S=this.options.source[F].display||this.options.display).length;x=m)break;this.tmpResult[u].push(j.extend(!0,{matchedKey:S[x]},t)),this.resultItemCount++}break}if(!this.options.callback.onResult){if(this.resultItemCount>=f)break;if(m&&this.tmpResult[u].length>=m&&"group"===p)break}}if(this.options.order){var O,S=[];for(var F in this.tmpResult)if(this.tmpResult.hasOwnProperty(F)){for(v=0,b=this.tmpResult[F].length;v",{class:this.options.selector.result}),this.container.append(this.resultContainer)),!this.result.length&&this.generatedGroupCount===this.generateGroups.length)if(this.options.multiselect&&this.options.multiselect.limit&&this.items.length>=this.options.multiselect.limit)h=this.options.multiselect.limitTemplate?"function"==typeof this.options.multiselect.limitTemplate?this.options.multiselect.limitTemplate.call(this,this.query):this.options.multiselect.limitTemplate.replace(/\{\{query}}/gi,j("
").text(this.helper.cleanStringFromScript(this.query)).html()):"Can't select more than "+this.items.length+" items.";else{if(!this.options.emptyTemplate||""===this.query)return;h="function"==typeof this.options.emptyTemplate?this.options.emptyTemplate.call(this,this.query):this.options.emptyTemplate.replace(/\{\{query}}/gi,j("
").text(this.helper.cleanStringFromScript(this.query)).html())}this.displayEmptyTemplate=!!h;var o=this.query.toLowerCase();this.options.accent&&(o=this.helper.removeAccent.call(this,o));var c=this,t=this.groupTemplate||"
    ",p=!1;this.groupTemplate?t=j(t.replace(/<([^>]+)>\{\{(.+?)}}<\/[^>]+>/g,function(t,e,i,s,o){var n="",r="group"===i?c.groups:[i];if(!c.result.length)return!0===p?"":(p=!0,"<"+e+' class="'+c.options.selector.empty+'">'+h+"");for(var a=0,l=r.length;a
      ";return n})):(t=j(t),this.result.length||t.append(h instanceof j?h:'
    • '+h+"
    • ")),t.addClass(this.options.selector.list+(this.helper.isEmpty(this.result)?" empty":""));for(var e,i,n,s,r,a,l,u,d,f,m,g,y,v=this.groupTemplate&&this.result.length&&c.groups||[],b=0,k=this.result.length;b",{class:c.options.selector.group,html:j("",{href:"javascript:;",html:i||e,tabindex:-1}),"data-search-group":e}))),this.groupTemplate&&v.length&&~(m=v.indexOf(e||n.group))&&v.splice(m,1),r=j("
    • ",{class:c.options.selector.item+" "+c.options.selector.group+"-"+this.helper.slugify.call(this,e),disabled:!!n.disabled,"data-group":e,"data-index":b,html:j("",{href:s&&!n.disabled?(g=s,y=n,y.href=c.generateHref.call(c,g,y)):"javascript:;",html:function(){if(a=n.group&&c.options.source[n.group].template||c.options.template)"function"==typeof a&&(a=a.call(c,c.query,n)),l=a.replace(/\{\{([^\|}]+)(?:\|([^}]+))*}}/gi,function(t,e,i){var s=c.helper.cleanStringFromScript(String(c.helper.namespace.call(c,e,n,"get","")));return~(i=i&&i.split("|")||[]).indexOf("slugify")&&(s=c.helper.slugify.call(c,s)),~i.indexOf("raw")||!0===c.options.highlight&&o&&~d.indexOf(e)&&(s=c.helper.highlight.call(c,s,o.split(" "),c.options.accent)),s});else{for(var t=0,e=d.length;t'+c.helper.cleanStringFromScript(String(u.join(" ")))+""}(!0===c.options.highlight&&o&&!a||"any"===c.options.highlight)&&(l=c.helper.highlight.call(c,l,o.split(" "),c.options.accent)),j(this).append(l)}})}),function(t,i,e){e.on("click",function(t,e){i.disabled?t.preventDefault():(e&&"object"==typeof e&&(t.originalEvent=e),c.options.mustSelectItem&&c.helper.isEmpty(i)?t.preventDefault():(c.options.multiselect||(c.item=i),!1!==c.helper.executeCallback.call(c,c.options.callback.onClickBefore,[c.node,j(this),i,t])&&(t.originalEvent&&t.originalEvent.defaultPrevented||t.isDefaultPrevented()||(c.options.multiselect?(c.query=c.rawQuery="",c.addMultiselectItemLayout(i)):(c.focusOnly=!0,c.query=c.rawQuery=c.getTemplateValue.call(c,i),c.isContentEditable&&(c.node.text(c.query),c.helper.setCaretAtEnd(c.node[0]))),c.hideLayout(),c.node.val(c.query).focus(),c.options.cancelButton&&c.toggleCancelButtonVisibility(),c.helper.executeCallback.call(c,c.options.callback.onClickAfter,[c.node,j(this),i,t])))))}),e.on("mouseenter",function(t){i.disabled||(c.clearActiveItem(),c.addActiveItem(j(this))),c.helper.executeCallback.call(c,c.options.callback.onEnter,[c.node,j(this),i,t])}),e.on("mouseleave",function(t){i.disabled||c.clearActiveItem(),c.helper.executeCallback.call(c,c.options.callback.onLeave,[c.node,j(this),i,t])})}(0,n,r),(this.groupTemplate?t.find('[data-group-template="'+e+'"] ul'):t).append(r);if(this.result.length&&v.length)for(b=0,k=v.length;b",{class:this.options.selector.backdrop,css:this.backdrop.css}).insertAfter(this.container)),this.container.addClass("backdrop").css({"z-index":this.backdrop.css["z-index"]+1,position:"relative"}))},buildHintLayout:function(t){if(this.options.hint)if(this.node[0].scrollWidth>Math.ceil(this.node.innerWidth()))this.hint.container&&this.hint.container.val("");else{var e=this,i="",s=(t=t||this.result,this.query.toLowerCase());if(this.options.accent&&(s=this.helper.removeAccent.call(this,s)),this.hintIndex=null,this.searchGroups.length){if(this.hint.container||(this.hint.css=j.extend({"border-color":"transparent",position:"absolute",top:0,display:"inline","z-index":-1,float:"none",color:"silver","box-shadow":"none",cursor:"default","-webkit-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none"},this.options.hint),this.hint.container=j("<"+this.node[0].nodeName+"/>",{type:this.node.attr("type"),class:this.node.attr("class"),readonly:!0,unselectable:"on","aria-hidden":"true",tabindex:-1,click:function(){e.node.focus()}}).addClass(this.options.selector.hint).css(this.hint.css).insertAfter(this.node),this.node.parent().css({position:"relative"})),this.hint.container.css("color",this.hint.css.color),s)for(var o,n,r,a=0,l=t.length;a",{class:this.options.selector.filter,html:function(){j(this).append(j("