2

How can write the event to switch from portrait to landscape?And how can make this switch in browser debug?This is the view where the event landscape must be captured.Maybe in the object events?Or can you suggest me?

          var HomeView = Backbone.View.extend({

 template: Handlebars.compile(template),

 events: {
  "click .log_out":"log_out",
  "click .prove":"prove"
  },

  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;
    },

    log_out:function(){
        console.log("logout");
        Parse.User.logOut();
     //   new AppView;//ERRORE UNDEFINED NOT A FUNCTION
     window.location='index.html'  ;//METTERE UNA NEW APPVIEW MA DA ERRORE!!!
    },

    prove:function(){
     var lista=new Usercollection();
     lista.fetch();
     console.log(lista.length);

    }


 });

 return HomeView;

  });
Stefano Maglione
  • 3,946
  • 11
  • 49
  • 96

2 Answers2

0

I guess you must have specified the el for a view object.
All the events that you specify in the event hash are delegated to el of that view object.
So you can write like this to listen to a orientationchange event.

events: {
  'orientationchange' : 'onOrientationChange'
}

onOrientationChange: function() {
   if(window.orientation == 90 || window.orientation == -90) {
     //you are in landscape zone
     //do whatever you want to do
   }
}
bitsbuffer
  • 555
  • 1
  • 6
  • 17
  • Thankyou so much,and how can i try the landscape in the console of chrome? – Stefano Maglione May 11 '13 at 20:41
  • resizing your browser window will trigger orientation changes in chrome. see my answer in: http://stackoverflow.com/questions/14236245/is-it-possible-to-emulate-orientation-in-a-browser/16182499#16182499 – Cory Danielson May 12 '13 at 00:40
  • will the orientation change event be triggered from the `el` though? isn't it a window event? – Cory Danielson May 12 '13 at 00:41
  • 1
    I've tried with the example above by Shubhmay but don't trigger the change – Stefano Maglione May 12 '13 at 13:23
  • @Stefano Maglione, can you give more details about your code.I've a code where this is working.The `orientationchange` event is propagating to the `el` of my `view` – bitsbuffer May 13 '13 at 06:08
  • @CoryDanielson `orientationchane` events propagates to the `el` of `view`,please go to this link to confirm https://dl.dropboxusercontent.com/u/32577704/event.jpg – bitsbuffer May 13 '13 at 10:10
-1

Do you have a view element that handles the portrait? Can you show us this code in order to help you?

royB
  • 12,779
  • 15
  • 58
  • 80