diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-06-04 23:10:31 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-06-05 21:23:49 +0200 |
commit | d088234d67f3aa422796d922e08a07949dc53d83 (patch) | |
tree | a964821b6b725dd26becbb3e91acf8d7dd5e0014 /public_html/data/js/lexer-input.js | |
parent | 048410164d2a17bbb588e43351e44eeb81610960 (diff) |
Move public files to ./public_html
./data/local is not moved because it contains likely untracked files
and moving it would throw an error when updating.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'public_html/data/js/lexer-input.js')
-rw-r--r-- | public_html/data/js/lexer-input.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/public_html/data/js/lexer-input.js b/public_html/data/js/lexer-input.js new file mode 100644 index 000000000..02dda36dd --- /dev/null +++ b/public_html/data/js/lexer-input.js @@ -0,0 +1,48 @@ +(function () { +'use strict'; +define(['util', 'underscore', 'jquery', 'jquery-ui'], function (Util, _, $) { + var PrivateFunctions = { + switchLexer: function (lexer, baseUrl) { + var url = baseUrl + '/' + Util.fixedEncodeURIComponent(lexer); + window.location = url; + }, + lexerSelected: function (event, ui) { + event.preventDefault(); + var baseUrl = $(event.target).data('base-url'); + this.switchLexer(ui.item.value, baseUrl); + }, + setupAutocomplete: function () { + var lexerSource = []; + for (var key in appConfig.lexers) { + lexerSource.push({ label: appConfig.lexers[key], value: key }); + } + + $('.lexer-form input').autocomplete({ + source: lexerSource, + select: _.bind(PrivateFunctions.lexerSelected, PrivateFunctions) + }); + }, + setupEvents: function () { + $('.lexer-form').on('submit', _.bind(function (event) { + event.preventDefault(); + var input = $(event.target).find('input'); + var lexer = input.val(); + var baseUrl = input.data('base-url'); + this.switchLexer(lexer, baseUrl); + }, this)); + + $('.lexer-toggle').on('click', _.bind(function(event) { + Util.focusDropdownInput(event.target); + }, Util)); + } + }; + var LexerInput = { + initialize: function () { + PrivateFunctions.setupAutocomplete(); + PrivateFunctions.setupEvents(); + } + }; + + return LexerInput; +}); +})(); |