Carlos Salazar Carlos Salazar - 1 year ago 113
Javascript Question

Ember Action on mobile device orientation change

I've been tasked with taking an ember website and making it responsive to mobile. one of the problems is that they use a component to draw a graph (d3). the graph is not re-rendered when there is a change on the parent container. Not really much of a problem on a desktop display, but on mobile the drawn graph is drastically different between portrait and landscape.

I'm wondering if there is a way to attach an ember observer on a window device orientation change, either hrough jquery or regular javascript?

Answer Source

Not completely sure if Ember has window event handling thus far, but utilizing resize via jQuery might do the trick:

resizeHandler: function() {
    //execute re-render

init: function() {
    $(window).on('resize', this.get('resizeHandler'));

willDestroy: function() {
    $(window).unbind('resize', this.get('resizeHandler'));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download