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

78 lines
2.2 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) {
this.$el = $(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-01-15 17:08:19 -08:00
this.$search_query.focus(function() {
if (window.$selected) {
$selected.trigger('deselect');
}
});
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');
});
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'));