summaryrefslogtreecommitdiffstats
path: root/data/js/tabwidth-input.js
blob: 9cc37516d09c4c8a28bd2a4316fa67c45cc8f3fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(function () {
'use strict';
define(['jquery', 'underscore', 'util'], function ($, _, Util) {
	var PrivateFunctions = {
		setupEvents: function () {
			$('.tabwidth-toggle').on('click', _.bind(function (event) {
				Util.focusDropdownInput(event.target);
			}, Util));

			$('form.tabwidth-form input').on('click', function (event) {
				// Suppress blur event on dropdown toggle
				event.stopImmediatePropagation();
			});

			$('form.tabwidth-form').on('submit', function (event) {
				var value = $(event.target).find('input').val();
				Util.setTabwidth(value);
				$(event.target).parents('.open').removeClass('open');
				event.preventDefault();
			});

			$('form.tabwidth-form input').on('change', function (event) {
				var value = $(event.target).val();
				Util.setTabwidth(value);
				event.preventDefault();
			});
		}
	};
	var TabwidthInput = {
		initialize: function () {
			PrivateFunctions.setupEvents();
		}
	};

	return TabwidthInput;
});
})();