- Display a dialog when user approves an image
- Changing A Mockup URL Slug
- Extend Backbone Models, Views, Collections
- Adding Custom Scripts and Styles
- ph_website_publish_thread
- New Comment Threads
- Add additional notification emails
- Welcome message for new users on mockup projects
- Change the subscribed user email based on a role
- Display a dialog when the user submits a comment
- Auto-Close Mockup Comment After New Comment
- Changing the mockup download
- Add Settings To Extensions Page
- Listening for Javscript Events
- Change default mockup project options
- Overriding and Changing Templates
- How to Install SureFeedback & Addons
- How to Update SureFeedback
- Should I Install SureFeedback on My Main Site or a Dedicated Installation?
- Caching and SureFeedback
- Dashboard Shortcode
- Adding A Project Shortcode To Your Site 3.1.x and lower
- Project Shortcode
- Hosting
- Cloudways Compatibility
Listening for Javscript Events
SureFeedback doesn’t necessarily broadcast javascript events on a global level, but the awesome part about Backbone.js is you can listen for DOM or model events by extending views and models.
Model Events
Model events can be listened to using the backbone’s listenTo method. For example, when a model attribute changes, we can listen for the change and run our own functions on the event. Here’s an example of extending a model and running our own function on the event.
Websites:
ph.api.views.CommentBubble = ph.api.views.CommentBubble.extend({
initialize: function () {
// we're extending the original method
this.constructor.__super__.initialize.apply(this, arguments);
// output model to console
console.log(this.model);
// listen to models comments
this.listenTo(this.model.get('comments'), 'add', this.prefixDoSomething);
},
prefixDoSomething: function(updatedModel){
// log changed comments
console.log(this.model.get('comments'));
}
});
Mockups:
Huddle.CommentView = Huddle.CommentView.extend({
initialize: function () {
// we're extending the original method
this.constructor.__super__.initialize.apply(this, arguments);
// output model to console
console.log(this.model);
// listen to models comments
this.listenTo(this.model.items, 'add', this.prefixDoSomething);
},
prefixDoSomething: function(updatedModel){
// log changed comments
console.log(this.model.items);
}
});
View Events
View events can be listened to by extending backbone’s events hash. For example, when a something is clicked on a particular view or subview, we can extend the events hash to run our own functions on the event.
It’s recommended that you use Backbone events hash instead of javascript or jquery events. This is because they are pre-scoped and will automatically remove themselves when the view is removed, ensuring no memory leaks and other performance issues!
Here’s an example of extending the events hash and running our own function on the event.
Websites
ph.api.views.Comment = ph.api.views.Comment.extend({
// Add new events
events: function () {
// we're extending the original events here with our own
return _.extend({}, this.constructor.__super__.events, {
'hover .ph-annotation-dot': 'prefixDoSomething'
});
},
// add our own method
prefixDoSomething: function () {
console.log('hovered!');
}
});
Mockups
Huddle.ImageView = Huddle.ImageView.extend({
// Add new events
events: function () {
// we're extending the original events here with our own
return _.extend({}, this.constructor.__super__.events, {
'hover img.ph-project-image': 'prefixDoSomething'
});
},
// add our own method
prefixDoSomething: function () {
console.log('hovered!');
}
});
We don't respond to the article feedback, we use it to improve our support content.