summaryrefslogtreecommitdiffstats
path: root/data/js/application.js
blob: a82c193c820aec72d5431be1af64ba8658a83e43 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function () {
'use strict';
define(
	[
		'require',
		'util',
		'lexer-input',
		'tabwidth-input',
		'vendor'
	],
	function (require, Util, LexerInput, TabwidthInput) {
		require(['script']);
		var App = {
			 // Gets called for every request (before page load)
			initialize: function () {
				this.setupLineHighlight();
			},

			/*
			 * Gets called for every request after page load
			 * config contains app config attributes passed from php
			 */
			onPageLoaded: function (config) {
				config = config || {};
				Util.highlightLineFromHash();
				Util.setTabwidthFromLocalStorage();
				TabwidthInput.initialize();
				LexerInput.initialize(config.lexers);
				this.configureTooltips();
				this.setupToggleSelectAllEvent();
				this.setupLineWrapToggle();
			},

			setupLineHighlight: function () {
				$(window).on('hashchange', Util.highlightLineFromHash);
			},
			
			configureTooltips: function () {
				$('[rel="tooltip"]').tooltip({
					placement: 'bottom',
					container: 'body',
				});
			},

			setupToggleSelectAllEvent: function () {
				$('#history-all').on('click', function(event) {
					// Suppress click event on table heading
					event.stopImmediatePropagation();
				});
				$('#history-all').on('change', function(event) {
					var checked = $(event.target).prop('checked');
					$('.delete-history').prop('checked', checked);
				});
			},

			setupLineWrapToggle: function () {
				var linesWrapped = localStorage.getItem('lines_wrapped') || 'true';
				Util.setLineWrap(linesWrapped === 'true');
				
				$('.linewrap-toggle').on('click', _.bind(Util.toggleLineWrap, Util));
			}
		};

		return App;
	}
);
})();