snipt/snipt/media/js/src/modules/site.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

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-02-15 15:25:13 -08:00
_.templateSettings = {
interpolate : /\{\{(.+?)\}\}/g
};
this.$el = $(this.el);
2012-02-14 08:39:45 -08:00
this.$search_form = $('form.search', this.$el);
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();
if (this.$snipts.length) {
2011-11-06 08:12:05 -08:00
SniptListView = Snipt.Views.SniptListView;
SniptList = new SniptListView({ 'snipts': this.$snipts });
$('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
$search_query = this.$search_query;
$document = $(document);
$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 () {
$('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'));