Properly namespace things.
parent
06e2654b22
commit
da494d7f1b
|
@ -8,14 +8,14 @@ var snipt = {
|
|||
return modules[name];
|
||||
}
|
||||
|
||||
return modules[name] = { Views: {} };
|
||||
return modules[name] = {};
|
||||
};
|
||||
}()
|
||||
};
|
||||
|
||||
jQuery(function($) {
|
||||
|
||||
var SiteView = snipt.module('site').Views.SiteView;
|
||||
var SiteView = snipt.module('site').SiteView;
|
||||
window.site = new SiteView();
|
||||
|
||||
});
|
||||
|
|
|
@ -3,12 +3,14 @@
|
|||
|
||||
var Snipt = snipt.module('snipt');
|
||||
|
||||
SiteView = Backbone.View.extend({
|
||||
Site.SiteView = Backbone.View.extend({
|
||||
el: 'body',
|
||||
|
||||
initialize: function(opts) {
|
||||
|
||||
this.$el = $(this.el);
|
||||
this.$html = $('html');
|
||||
this.$html_body = this.$el.add(this.$html);
|
||||
this.$search_form = $('form.search', this.$el);
|
||||
this.$search_query = $('input#search-query', this.$el);
|
||||
this.$snipts = $('section#snipts article.snipt', this.$el);
|
||||
|
@ -18,8 +20,8 @@
|
|||
this.inFieldLabels();
|
||||
|
||||
if (this.$snipts.length) {
|
||||
SniptListView = Snipt.Views.SniptListView;
|
||||
SniptList = new SniptListView({ 'snipts': this.$snipts });
|
||||
var SniptListView = Snipt.SniptListView;
|
||||
this.snipt_list = new SniptListView({ 'snipts': this.$snipts });
|
||||
|
||||
$('body').click(function() {
|
||||
if (window.$selected && !$('div.modal-body:visible', window.site.$modals).length) {
|
||||
|
@ -88,8 +90,5 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
Site.Views = {
|
||||
'SiteView': SiteView
|
||||
};
|
||||
|
||||
})(snipt.module('site'));
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
|
||||
(function(Snipt) {
|
||||
|
||||
SniptModel = Backbone.Model.extend({
|
||||
Snipt.SniptModel = Backbone.Model.extend({
|
||||
});
|
||||
SniptView = Backbone.View.extend({
|
||||
Snipt.SniptView = Backbone.View.extend({
|
||||
|
||||
tagName: 'article',
|
||||
|
||||
|
@ -66,7 +66,7 @@
|
|||
snipt: this.model.toJSON()
|
||||
});
|
||||
$('section#main').hide();
|
||||
$('body').addClass('detail');
|
||||
window.site.$el.addClass('detail');
|
||||
$('section#main-edit').html(editPane).show();
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
@ -159,20 +159,20 @@
|
|||
}
|
||||
|
||||
$('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;
|
||||
},
|
||||
select: function(fromClick) {
|
||||
|
||||
$('article.selected', SniptList.$el).removeClass('selected');
|
||||
$('article.selected', window.site.snipt_list.$el).removeClass('selected');
|
||||
this.$el.addClass('selected');
|
||||
|
||||
if (fromClick !== true) {
|
||||
if (SniptList.$snipts.index(this.$el) === 0) {
|
||||
if (window.site.$snipts.index(this.$el) === 0) {
|
||||
window.scrollTo(0, 0);
|
||||
} else {
|
||||
$('html, body').animate({
|
||||
window.site.$html_body.animate({
|
||||
scrollTop: this.$el.offset().top - 50
|
||||
}, 0);
|
||||
}
|
||||
|
@ -185,13 +185,12 @@
|
|||
e.stopPropagation();
|
||||
}
|
||||
});
|
||||
SniptListView = Backbone.View.extend({
|
||||
Snipt.SniptListView = Backbone.View.extend({
|
||||
el: 'section#snipts',
|
||||
|
||||
initialize: function(opts) {
|
||||
|
||||
this.$snipts = opts.snipts;
|
||||
this.$snipts.each(this.addExistingSnipt);
|
||||
opts.snipts.each(this.addExistingSnipt);
|
||||
this.$el = $(this.el);
|
||||
|
||||
this.keyboardShortcuts();
|
||||
|
@ -251,9 +250,9 @@
|
|||
}
|
||||
};
|
||||
|
||||
var view = new SniptView({
|
||||
var view = new Snipt.SniptView({
|
||||
el: this,
|
||||
model: new SniptModel(data)
|
||||
model: new Snipt.SniptModel(data)
|
||||
});
|
||||
},
|
||||
keyboardShortcuts: function() {
|
||||
|
@ -263,14 +262,14 @@
|
|||
|
||||
$document.bind('keydown', 'j', function() {
|
||||
if (!$selected) {
|
||||
SniptList.$snipts.eq(0).trigger('selectSnipt');
|
||||
window.site.$snipts.eq(0).trigger('selectSnipt');
|
||||
} else {
|
||||
$selected.trigger('next');
|
||||
}
|
||||
});
|
||||
$document.bind('keydown', 'k', function() {
|
||||
if (!$selected) {
|
||||
SniptList.$snipts.eq(0).trigger('selectSnipt');
|
||||
window.site.$snipts.eq(0).trigger('selectSnipt');
|
||||
} else {
|
||||
$selected.trigger('prev');
|
||||
}
|
||||
|
@ -290,15 +289,15 @@
|
|||
});
|
||||
$document.bind('keydown', 'esc', function() {
|
||||
if ($('section#main-edit:visible').length) {
|
||||
if (!$('html').hasClass('detail')) {
|
||||
$('body').removeClass('detail');
|
||||
if (!window.site.$html.hasClass('detail')) {
|
||||
window.site.$el.removeClass('detail');
|
||||
}
|
||||
$('section#main-edit').hide();
|
||||
$('section#main').show();
|
||||
if (SniptList.$snipts.index($selected) === 0) {
|
||||
if (window.site.$snipts.index($selected) === 0) {
|
||||
window.scrollTo(0, 0);
|
||||
} else {
|
||||
$('html, body').animate({
|
||||
window.site.$html_body.animate({
|
||||
scrollTop: $selected.offset().top - 50
|
||||
}, 0);
|
||||
}
|
||||
|
@ -361,8 +360,5 @@
|
|||
});
|
||||
}
|
||||
});
|
||||
Snipt.Views = {
|
||||
'SniptListView': SniptListView
|
||||
};
|
||||
|
||||
})(snipt.module('snipt'));
|
||||
|
|
Loading…
Reference in New Issue