ember.js - Subscribe to DOM events within Ember app -


i've got ember cli based blog. resize <img> inside posts upon clicking them using function inside application-controller.

i rely on on('init') , ember.run.later , feels dirty.

how can improve subscription code below?

import ember 'ember';  export default ember.arraycontroller.extend({   imagescaling: function() {     ember.run.later((function() {        //subscribe actual event       ember.$(".post-content img").on("click", function(){         // resize here       })     }), 3000)   }.on('init') }); 

if you're inserting of images inside ember templates, can use action helper:

<img {{action 'scaleimages' on='click'}} src='' /> 

i realize that's not case though. way i've dealt dom interactions in past override application view set , tear down event handler there. can avoid ember.run.later call modifying jquery event listener. here's how it:

// app/views/application.js export default ember.view.extend({     setupimagescaling: function() {         $('body').on('click.image-scaling', 'img', function() {             // resize here         });     }.on('didinsertelement'),      teardownimagescaling: function() {         $('body').off('click.image-sacling');     }.on('willdestroyelement') }); 

in opinion, above 'most ember' way of handling kind of situation.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -