This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
/
site.js
115 lines (100 loc) Β· 3.76 KB
/
site.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
(function(Site) {
var Snipt = snipt.module('snipt');
Site.SiteView = Backbone.View.extend({
el: 'body',
initialize: function(opts) {
this.$body = $(this.el);
this.$html = $('html');
this.$html_body = this.$body.add(this.$html);
this.$search_form = $('form.search', this.$body);
this.$search_query = $('input#search-query', this.$body);
this.$snipts = $('section#snipts article.snipt', this.$body);
this.$modals = $('div.modal', this.$snipts);
this.$main_edit = $('section#main-edit');
this.$main = $('section#main');
this.keyboardShortcuts();
this.inFieldLabels();
if (this.$snipts.length) {
var SniptListView = Snipt.SniptListView;
this.snipt_list = new SniptListView({ 'snipts': this.$snipts });
this.$body.click(function() {
if (!window.ui_halted && !window.from_modal && window.$selected) {
window.$selected.trigger('deselect');
}
if (window.from_modal) {
window.from_modal = false;
}
});
}
$search_query = this.$search_query;
$search_query.focus(function() {
if (window.$selected) {
$selected.trigger('deselect');
}
});
this.$search_form.submit(function() {
window.location = 'https://www.google.com/search?q=' + $search_query.val() + ' site:snipt.net%20';
return false;
});
$('div.modal a.close').click(function() {
$(this).parent().parent().modal('hide');
window.ui_halted = false;
return false;
});
window.ui_halted = false;
},
events: {
'showKeyboardShortcuts': 'showKeyboardShortcuts'
},
keyboardShortcuts: function() {
var $body = this.$body;
$search_query = this.$search_query;
$document = $(document);
$document.bind('keydown', '/', function(e) {
if (!window.ui_halted) {
e.preventDefault();
$search_query.focus();
}
});
$document.bind('keydown', 'h', function(e) {
if (!window.ui_halted) {
$body.trigger('showKeyboardShortcuts');
}
});
$document.bind('keydown', 't', function(e) {
if (!window.ui_halted) {
window.open('', '_blank');
}
});
$document.bind('keydown', 'r', function(e) {
if (!window.ui_halted) {
location.reload(true);
}
});
$document.bind('keydown', 'Ctrl+h', function(e) {
if (!window.ui_halted) {
history.go(-1);
}
});
$document.bind('keydown', 'Ctrl+l', function(e) {
if (!window.ui_halted) {
history.go(1);
}
});
this.$search_query.bind('keydown', 'esc', function(e) {
if (!window.ui_halted) {
e.preventDefault();
this.blur();
}
});
},
showKeyboardShortcuts: function() {
$('#keyboard-shortcuts').modal('toggle');
},
inFieldLabels: function () {
$('div.infield label', this.$body).inFieldLabels({
fadeDuration: 200
});
}
});
})(snipt.module('site'));