Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.32 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Is there a way to listen to Html Element Style changes - Backbone.JS
  2. <li id="imovel" style="<%=  display %>">
  3.         <div class="thumbnail">                      
  4.           <a href="#">
  5.             <img src="http://placehold.it/90x60"></img>
  6.             <%= textvar %>
  7.           </a>
  8.         </div>                                    
  9.     </li>
  10.        
  11. var imovelView = Backbone.View.extend({
  12.  
  13.     el: $('#imovel')
  14.  
  15.     ,template:  _.template( $("#listing_template").html())
  16.  
  17.     ,events: {
  18.         "change:display #imovel" : "activate"
  19.     }
  20.  
  21.     ,initialize: function(){
  22.         this.on('change:display', this.toggle, this);
  23.         this.collection.bind('add', this.render, this);
  24.     }
  25.  
  26.     ,activate: function(item){
  27.         alert("change display");
  28.     }
  29.  
  30.     ,render: function(item){
  31.         var showPerPage = $('#show_per_page').val();
  32.         var totalEntries = this.collection.length;
  33.  
  34.         var pageMax = Math.ceil( showPerPage/totalEntries );
  35.         var displayValue = "display: none;";
  36.  
  37.         if(totalEntries <= showPerPage){
  38.             displayValue = "display: block;";
  39.         }
  40.  
  41.         var variables = { textvar: item.get("Lat"), display: displayValue };        
  42.         var template = this.template( variables );
  43.  
  44.         $('#max_page').val(pageMax);
  45.         $('#content').append( template );
  46.         resizeViewport();
  47.     }
  48.  
  49. });