Properly namespace things.

master
Nick Sergeant 2012-02-24 20:45:00 -05:00
parent 06e2654b22
commit da494d7f1b
3 changed files with 24 additions and 29 deletions

View File

@ -8,14 +8,14 @@ var snipt = {
return modules[name]; return modules[name];
} }
return modules[name] = { Views: {} }; return modules[name] = {};
}; };
}() }()
}; };
jQuery(function($) { jQuery(function($) {
var SiteView = snipt.module('site').Views.SiteView; var SiteView = snipt.module('site').SiteView;
window.site = new SiteView(); window.site = new SiteView();
}); });

View File

@ -3,12 +3,14 @@
var Snipt = snipt.module('snipt'); var Snipt = snipt.module('snipt');
SiteView = Backbone.View.extend({ Site.SiteView = Backbone.View.extend({
el: 'body', el: 'body',
initialize: function(opts) { initialize: function(opts) {
this.$el = $(this.el); this.$el = $(this.el);
this.$html = $('html');
this.$html_body = this.$el.add(this.$html);
this.$search_form = $('form.search', this.$el); this.$search_form = $('form.search', this.$el);
this.$search_query = $('input#search-query', this.$el); this.$search_query = $('input#search-query', this.$el);
this.$snipts = $('section#snipts article.snipt', this.$el); this.$snipts = $('section#snipts article.snipt', this.$el);
@ -18,8 +20,8 @@
this.inFieldLabels(); this.inFieldLabels();
if (this.$snipts.length) { if (this.$snipts.length) {
SniptListView = Snipt.Views.SniptListView; var SniptListView = Snipt.SniptListView;
SniptList = new SniptListView({ 'snipts': this.$snipts }); this.snipt_list = new SniptListView({ 'snipts': this.$snipts });
$('body').click(function() { $('body').click(function() {
if (window.$selected && !$('div.modal-body:visible', window.site.$modals).length) { if (window.$selected && !$('div.modal-body:visible', window.site.$modals).length) {
@ -88,8 +90,5 @@
}); });
} }
}); });
Site.Views = {
'SiteView': SiteView
};
})(snipt.module('site')); })(snipt.module('site'));

View File

@ -1,9 +1,9 @@
(function(Snipt) { (function(Snipt) {
SniptModel = Backbone.Model.extend({ Snipt.SniptModel = Backbone.Model.extend({
}); });
SniptView = Backbone.View.extend({ Snipt.SniptView = Backbone.View.extend({
tagName: 'article', tagName: 'article',
@ -66,7 +66,7 @@
snipt: this.model.toJSON() snipt: this.model.toJSON()
}); });
$('section#main').hide(); $('section#main').hide();
$('body').addClass('detail'); window.site.$el.addClass('detail');
$('section#main-edit').html(editPane).show(); $('section#main-edit').html(editPane).show();
window.scrollTo(0, 0); window.scrollTo(0, 0);
} }
@ -159,20 +159,20 @@
} }
$('script#disqus').remove(); $('script#disqus').remove();
$('body').append('<script id="disqus" type="text/javascript">' + $('script#disqus-template').text() + '</script>'); window.site.$el.append('<script id="disqus" type="text/javascript">' + $('script#disqus-template').text() + '</script>');
return this; return this;
}, },
select: function(fromClick) { select: function(fromClick) {
$('article.selected', SniptList.$el).removeClass('selected'); $('article.selected', window.site.snipt_list.$el).removeClass('selected');
this.$el.addClass('selected'); this.$el.addClass('selected');
if (fromClick !== true) { if (fromClick !== true) {
if (SniptList.$snipts.index(this.$el) === 0) { if (window.site.$snipts.index(this.$el) === 0) {
window.scrollTo(0, 0); window.scrollTo(0, 0);
} else { } else {
$('html, body').animate({ window.site.$html_body.animate({
scrollTop: this.$el.offset().top - 50 scrollTop: this.$el.offset().top - 50
}, 0); }, 0);
} }
@ -185,13 +185,12 @@
e.stopPropagation(); e.stopPropagation();
} }
}); });
SniptListView = Backbone.View.extend({ Snipt.SniptListView = Backbone.View.extend({
el: 'section#snipts', el: 'section#snipts',
initialize: function(opts) { initialize: function(opts) {
this.$snipts = opts.snipts; opts.snipts.each(this.addExistingSnipt);
this.$snipts.each(this.addExistingSnipt);
this.$el = $(this.el); this.$el = $(this.el);
this.keyboardShortcuts(); this.keyboardShortcuts();
@ -251,9 +250,9 @@
} }
}; };
var view = new SniptView({ var view = new Snipt.SniptView({
el: this, el: this,
model: new SniptModel(data) model: new Snipt.SniptModel(data)
}); });
}, },
keyboardShortcuts: function() { keyboardShortcuts: function() {
@ -263,14 +262,14 @@
$document.bind('keydown', 'j', function() { $document.bind('keydown', 'j', function() {
if (!$selected) { if (!$selected) {
SniptList.$snipts.eq(0).trigger('selectSnipt'); window.site.$snipts.eq(0).trigger('selectSnipt');
} else { } else {
$selected.trigger('next'); $selected.trigger('next');
} }
}); });
$document.bind('keydown', 'k', function() { $document.bind('keydown', 'k', function() {
if (!$selected) { if (!$selected) {
SniptList.$snipts.eq(0).trigger('selectSnipt'); window.site.$snipts.eq(0).trigger('selectSnipt');
} else { } else {
$selected.trigger('prev'); $selected.trigger('prev');
} }
@ -290,15 +289,15 @@
}); });
$document.bind('keydown', 'esc', function() { $document.bind('keydown', 'esc', function() {
if ($('section#main-edit:visible').length) { if ($('section#main-edit:visible').length) {
if (!$('html').hasClass('detail')) { if (!window.site.$html.hasClass('detail')) {
$('body').removeClass('detail'); window.site.$el.removeClass('detail');
} }
$('section#main-edit').hide(); $('section#main-edit').hide();
$('section#main').show(); $('section#main').show();
if (SniptList.$snipts.index($selected) === 0) { if (window.site.$snipts.index($selected) === 0) {
window.scrollTo(0, 0); window.scrollTo(0, 0);
} else { } else {
$('html, body').animate({ window.site.$html_body.animate({
scrollTop: $selected.offset().top - 50 scrollTop: $selected.offset().top - 50
}, 0); }, 0);
} }
@ -361,8 +360,5 @@
}); });
} }
}); });
Snipt.Views = {
'SniptListView': SniptListView
};
})(snipt.module('snipt')); })(snipt.module('snipt'));