From adfc120642d3a14b6f281c58460c974412a8432c Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 5 Oct 2014 13:25:40 +0200 Subject: [PATCH] Added autocompletion --- TODO | 3 +- public_html/css/tags.css | 23 ++ public_html/index.html | 3 + public_html/js/Controls/AutoCompleteInput.js | 223 ++++++++++++++++++ public_html/js/Controls/FileDropper.js | 10 +- public_html/js/Controls/TagInput.js | 43 ++-- .../js/Presenters/PostListPresenter.js | 7 +- public_html/js/Presenters/PostPresenter.js | 6 +- .../js/Presenters/PostUploadPresenter.js | 4 +- .../UserAccountSettingsPresenter.js | 2 +- public_html/js/Services/TagList.js | 27 +++ 11 files changed, 320 insertions(+), 31 deletions(-) create mode 100644 public_html/css/tags.css create mode 100644 public_html/js/Controls/AutoCompleteInput.js create mode 100644 public_html/js/Services/TagList.js diff --git a/TODO b/TODO index 4a642b97..03f12696 100644 --- a/TODO +++ b/TODO @@ -20,8 +20,9 @@ everything related to posts: (move post snapshot factory methods to PostService) everything related to tags: + - automatic tag removal + - tag refresh when editing post - tag listing - - tag autocompletion (difficult) - time of last tag usage - time of tag addition - mass tag diff --git a/public_html/css/tags.css b/public_html/css/tags.css new file mode 100644 index 00000000..9c522f91 --- /dev/null +++ b/public_html/css/tags.css @@ -0,0 +1,23 @@ +.autocomplete { + position: absolute; + display: none; + z-index: 10; +} +.autocomplete ul { + list-style-type: none; + padding: 0 0 !important; + margin: 0 !important; + border: 2px solid #5da; + background: white; + display: block !important; + text-align: left; +} + +.autocomplete li { + margin: 0; + padding: 0.1em 0.5em !important; +} + +.autocomplete li.active { + background: #5da; +} diff --git a/public_html/index.html b/public_html/index.html index dbef564a..1ca3f8e9 100644 --- a/public_html/index.html +++ b/public_html/index.html @@ -37,6 +37,7 @@ + @@ -86,9 +87,11 @@ + + diff --git a/public_html/js/Controls/AutoCompleteInput.js b/public_html/js/Controls/AutoCompleteInput.js new file mode 100644 index 00000000..26a027da --- /dev/null +++ b/public_html/js/Controls/AutoCompleteInput.js @@ -0,0 +1,223 @@ +var App = App || {}; +App.Controls = App.Controls || {}; + +App.Controls.AutoCompleteInput = function($input) { + var _ = App.DI.get('_'); + var jQuery = App.DI.get('jQuery'); + var tagList = App.DI.get('tagList'); + + var KEY_RETURN = 13; + var KEY_ESCAPE = 27; + var KEY_UP = 38; + var KEY_DOWN = 40; + + var options = { + caseSensitive: false, + source: null, + maxResults: 15, + minLengthToArbitrarySearch: 3, + onApply: null, + additionalFilter: null, + }; + var showTimeout = null; + var cachedSource = null; + var results = []; + var activeResult = -1; + + if ($input.length === 0) { + throw new Error('Input element was not found'); + } + if ($input.length > 1) { + throw new Error('Cannot add autocompletion to more than one element at once'); + } + if ($input.attr('data-autocomplete')) { + throw new Error('Autocompletion was already added for this element'); + } + $input.attr('data-autocomplete', true); + $input.attr('autocomplete', 'off'); + + var $div = jQuery('
'); + var $list = jQuery('