2012-01-25 07:13:08 -08:00
|
|
|
|
2011-11-06 08:12:05 -08:00
|
|
|
(function(Site) {
|
|
|
|
|
|
|
|
var Snipt = snipt.module('snipt');
|
|
|
|
|
|
|
|
SiteView = Backbone.View.extend({
|
|
|
|
el: 'body',
|
|
|
|
|
|
|
|
initialize: function(opts) {
|
|
|
|
|
2012-01-24 15:48:42 -08:00
|
|
|
this.$el = $(this.el);
|
2012-02-14 08:39:45 -08:00
|
|
|
this.$search_form = $('form.search', this.$el);
|
2012-01-24 15:48:42 -08:00
|
|
|
this.$search_query = $('input#search-query', this.$el);
|
|
|
|
this.$snipts = $('section#snipts article.snipt', this.$el);
|
2012-01-25 16:39:38 -08:00
|
|
|
this.$copyModals = $('div.copy-modal', this.$snipts);
|
2011-11-06 08:12:05 -08:00
|
|
|
|
|
|
|
this.keyboardShortcuts();
|
|
|
|
this.inFieldLabels();
|
|
|
|
|
2012-01-15 11:51:33 -08:00
|
|
|
if (this.$snipts.length) {
|
2011-11-06 08:12:05 -08:00
|
|
|
SniptListView = Snipt.Views.SniptListView;
|
2012-01-15 11:51:33 -08:00
|
|
|
SniptList = new SniptListView({ 'snipts': this.$snipts });
|
2012-01-24 15:48:42 -08:00
|
|
|
|
|
|
|
$('body').click(function() {
|
|
|
|
if (window.$selected) {
|
|
|
|
window.$selected.trigger('deselect');
|
|
|
|
}
|
|
|
|
});
|
2011-11-06 08:12:05 -08:00
|
|
|
}
|
|
|
|
|
2012-02-14 08:39:45 -08:00
|
|
|
$search_query = this.$search_query;
|
|
|
|
$search_query.focus(function() {
|
2012-01-15 17:08:19 -08:00
|
|
|
if (window.$selected) {
|
|
|
|
$selected.trigger('deselect');
|
|
|
|
}
|
|
|
|
});
|
2012-02-14 08:39:45 -08:00
|
|
|
this.$search_form.submit(function() {
|
|
|
|
window.location = 'https://www.google.com/search?q=' + $search_query.val() + ' site:snipt.net%20';
|
|
|
|
return false;
|
|
|
|
});
|
2012-01-15 17:08:19 -08:00
|
|
|
|
2012-01-25 17:26:53 -08:00
|
|
|
$('div.modal a.close').click(function() {
|
|
|
|
$(this).parent().parent().modal('hide');
|
|
|
|
return false;
|
|
|
|
});
|
2011-11-06 08:12:05 -08:00
|
|
|
},
|
2012-01-24 16:08:24 -08:00
|
|
|
events: {
|
|
|
|
'showKeyboardShortcuts': 'showKeyboardShortcuts'
|
|
|
|
},
|
|
|
|
|
2011-11-06 08:12:05 -08:00
|
|
|
keyboardShortcuts: function() {
|
2012-01-24 16:08:24 -08:00
|
|
|
var $el = this.$el;
|
2011-11-06 08:12:05 -08:00
|
|
|
|
2012-01-15 11:51:33 -08:00
|
|
|
$search_query = this.$search_query;
|
2012-01-15 20:05:54 -08:00
|
|
|
$document = $(document);
|
2012-01-15 11:51:33 -08:00
|
|
|
|
2012-01-15 20:05:54 -08:00
|
|
|
$document.bind('keydown', '/', function(e) {
|
2011-11-06 08:12:05 -08:00
|
|
|
e.preventDefault();
|
|
|
|
$search_query.focus();
|
|
|
|
});
|
2012-02-12 21:42:25 -08:00
|
|
|
$document.bind('keydown', 'h', function(e) {
|
2012-01-24 16:08:24 -08:00
|
|
|
$el.trigger('showKeyboardShortcuts');
|
|
|
|
});
|
2012-02-14 21:49:55 -08:00
|
|
|
$document.bind('keydown', 'Shift+h', function(e) {
|
|
|
|
window.location = '/';
|
|
|
|
});
|
|
|
|
$document.bind('keydown', 't', function(e) {
|
|
|
|
window.open('', '_blank');
|
|
|
|
});
|
|
|
|
$document.bind('keydown', 'r', function(e) {
|
|
|
|
location.reload(true);
|
|
|
|
});
|
|
|
|
$document.bind('keydown', 'Ctrl+h', function(e) {
|
|
|
|
history.go(-1);
|
|
|
|
});
|
|
|
|
$document.bind('keydown', 'Ctrl+l', function(e) {
|
|
|
|
history.go(1);
|
|
|
|
});
|
2011-11-06 08:12:05 -08:00
|
|
|
$('input').bind('keydown', 'esc', function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.blur();
|
|
|
|
});
|
|
|
|
},
|
2012-01-24 16:08:24 -08:00
|
|
|
showKeyboardShortcuts: function() {
|
2012-01-25 06:49:36 -08:00
|
|
|
$('#keyboard-shortcuts').modal('toggle');
|
2012-01-24 16:08:24 -08:00
|
|
|
},
|
2011-11-06 08:12:05 -08:00
|
|
|
inFieldLabels: function () {
|
2012-01-24 15:48:42 -08:00
|
|
|
$('div.infield label', this.$el).inFieldLabels({
|
2012-01-15 17:08:19 -08:00
|
|
|
fadeDuration: 200
|
|
|
|
});
|
2011-11-06 08:12:05 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Site.Views = {
|
|
|
|
'SiteView': SiteView
|
|
|
|
};
|
|
|
|
|
|
|
|
})(snipt.module('site'));
|