move timeago and tooltip logic to the base View
This commit is contained in:
parent
d2807b5202
commit
fd6e3bae62
6 changed files with 30 additions and 33 deletions
|
|
@ -9,7 +9,11 @@ app.views.Base = Backbone.View.extend({
|
|||
},
|
||||
|
||||
render : function() {
|
||||
return this.renderTemplate().renderSubviews()
|
||||
this.renderTemplate()
|
||||
this.renderSubviews()
|
||||
this.renderPluginWidgets()
|
||||
|
||||
return this
|
||||
},
|
||||
|
||||
renderTemplate : function(){
|
||||
|
|
@ -17,7 +21,6 @@ app.views.Base = Backbone.View.extend({
|
|||
var presenter = _.isFunction(this.presenter) ? this.presenter() : this.presenter
|
||||
$(this.el).html(this.template(presenter));
|
||||
this.postRenderTemplate();
|
||||
return this;
|
||||
},
|
||||
|
||||
postRenderTemplate : $.noop, //hella callbax yo
|
||||
|
|
@ -31,7 +34,10 @@ app.views.Base = Backbone.View.extend({
|
|||
view.delegateEvents();
|
||||
}
|
||||
})
|
||||
|
||||
return this
|
||||
},
|
||||
|
||||
renderPluginWidgets : function() {
|
||||
this.$(this.tooltipSelector).twipsy();
|
||||
this.$("time").timeago();
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ app.views.CommentStream = app.views.Base.extend({
|
|||
postRenderTemplate : function() {
|
||||
this.$("label").inFieldLabels();
|
||||
this.model.comments.each(this.appendComment, this);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
createComment: function(evt) {
|
||||
|
|
|
|||
|
|
@ -19,11 +19,7 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
".post-content" : "postContentView"
|
||||
},
|
||||
|
||||
tooltips : [
|
||||
".delete",
|
||||
".block_user",
|
||||
".post_scope"
|
||||
],
|
||||
tooltipSelector : ".delete, .block_user, .post_scope",
|
||||
|
||||
initialize : function() {
|
||||
// set the guid
|
||||
|
|
@ -52,14 +48,6 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
return new postClass({ model : this.model });
|
||||
},
|
||||
|
||||
postRenderTemplate : function() {
|
||||
this.initializeTooltips();
|
||||
this.$("time").timeago();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
removeNsfwShield: function(evt){
|
||||
if(evt){ evt.preventDefault(); }
|
||||
|
||||
|
|
@ -108,14 +96,6 @@ app.views.Post = app.views.StreamObject.extend({
|
|||
this.$(".new_comment_form_wrapper").removeClass("hidden");
|
||||
this.$(".comment_box").focus();
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
initializeTooltips: function(){
|
||||
_.each(this.tooltips, function(selector, options){
|
||||
this.$(selector).twipsy(options);
|
||||
}, this);
|
||||
|
||||
return this;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
app.views.StreamObject = app.views.Base.extend({
|
||||
|
||||
initialize: function(options) {
|
||||
this.model.bind('remove', this.remove, this);
|
||||
this.model.bind('change', this.render, this);
|
||||
},
|
||||
|
||||
postRenderTemplate : function(){
|
||||
// time
|
||||
this.$("time").timeago();
|
||||
|
||||
// collapse long posts
|
||||
this.$(".collapsible").expander({
|
||||
slicePoint: 400,
|
||||
|
|
@ -16,7 +12,6 @@ app.views.StreamObject = app.views.Base.extend({
|
|||
expandText: Diaspora.I18n.t("show_more"),
|
||||
userCollapse: false
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
destroyModel: function(evt){
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
// temp hack to check if backbone is enabled for the page
|
||||
Diaspora.backboneEnabled = function(){
|
||||
return window.app.stream !== undefined;
|
||||
return window.app && window.app.stream !== undefined;
|
||||
}
|
||||
|
||||
window.Diaspora = Diaspora;
|
||||
|
|
|
|||
|
|
@ -71,5 +71,23 @@ describe("app.views.Base", function(){
|
|||
expect(this.view.$('.subview2').text().trim()).toBe("furreal this is the Second Subview")
|
||||
})
|
||||
})
|
||||
|
||||
context("calling out to third party plugins", function(){
|
||||
it("replaces .time with relative time ago in words", function(){
|
||||
spyOn($.fn, "timeago")
|
||||
this.view.render()
|
||||
expect($.fn.timeago).toHaveBeenCalled()
|
||||
expect($.fn.timeago.mostRecentCall.object.selector).toBe("time")
|
||||
})
|
||||
|
||||
|
||||
it("initializes tooltips declared with the view's tooltipSelector property", function(){
|
||||
this.view.tooltipSelector = ".christopher_columbus, .barrack_obama, .block_user"
|
||||
|
||||
spyOn($.fn, "twipsy")
|
||||
this.view.render()
|
||||
expect($.fn.twipsy.mostRecentCall.object.selector).toBe(".christopher_columbus, .barrack_obama, .block_user")
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue