0

With the event above in backbone I can't detect the orientation. It doesn't work.Are there any alternative to that?By bind an event or something else?Or something is wrong in my code?

var HomeView = Backbone.View.extend({
    template: Handlebars.compile(template),
    events: {
        "click .log_out": "log_out",
        "click .prove": "prove",
        "orientationchange": "onOrientationChange"
    },

    initialize: function () {
        console.log("inhomeview");
        this.render();
    },

    render: function () {
        //var context = JSON.parse(JSON.stringify(this.model));//eliminare
        var context = this.model;
        var html = this.template(context);
        console.log(html);

        $('#pagina').empty();
        $('#pagina').append(this.$el.html(html));

        return this;
    },

    onOrientationChange: function () {
        if (window.orientation === 90 || window.orientation === -90) {
            alert('you are in landscape');
        }
    }
});
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55
Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96

1 Answers1

2

It would work only in case if you set view el to window.

Or you can manually subscribe to the orientationchange event:

initialize : function() {
    $(window).on('orientationchange', this.onOrientationChange);
}
Vitalii Petrychuk
  • 14,035
  • 8
  • 51
  • 55