summaryrefslogtreecommitdiffstats
path: root/data/js/util.js
blob: 6c88edb2dede04212c05d3265eec3eacf552ec9f (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
38
39
40
41
42
43
44
45
46
47
48
49
50
(function () {
'use strict';
define(['jquery'], function () {
	var PrivateFunctions = {
		highlightLine: function (id) {
			this.clearLineHighlights();
			var line = $(id).parents('.table-row');
			line.addClass("highlight_line");
		},
		clearLineHighlights: function () {
			$('.highlight_line').removeClass('highlight_line');
		}
	};
	var Util = {
		fixedEncodeURIComponent: function (string) {
			var encodedString =  encodeURIComponent(string);
			encodedString = encodedString.replace(/[!'()]/g, escape);
			encodedString = encodedString.replace(/\*/g, "%2A");

			return encodedString;
		},
		highlightLineFromHash: function () {
			var hash = window.location.hash;
			if (hash.match(/^#n(?:-.+-)?\d+$/) === null) {
				PrivateFunctions.clearLineHighlights();
				return;
			}

			PrivateFunctions.highlightLine(hash);
		},
		focusDropdownInput: function (target) {
			setTimeout(function () {
				var dropDown = $(target).siblings('.dropdown-menu');
				dropDown.find('input').trigger('focus');
			}, 0);
		},
		setTabwidth: function (value) {
			value = value || 8;
			$('span.tabwidth-value').html(value);
			$('.tabwidth-form input').val(value);
			$('.highlight pre').css('tab-size', value);
			localStorage.setItem('tabwidth', value);
		},
		setTabwidthFromLocalStorage: function () {
			this.setTabwidth(localStorage.getItem('tabwidth'));
		}
	};
	return Util;
});
})();