Last active
          August 29, 2015 14:22 
        
      - 
      
- 
        Save jubstuff/17f8250b491fa2e7122e to your computer and use it in GitHub Desktop. 
    Simple Toggle widget with jQuery or Backbone
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var toggleFacet = { | |
| init: function (options, elem) { | |
| this.options = $.extend({}, this.options, options); | |
| this.$elem = $(elem); | |
| this.eventify(); | |
| }, | |
| options: { | |
| toggleClass: 'facet-collapsed' | |
| }, | |
| eventify: function () { | |
| var that = this; | |
| this.$elem.on('click', function (e) { | |
| if(e.target !== this) { | |
| return; | |
| } | |
| e.preventDefault(); | |
| $(this).toggleClass(that.options.toggleClass); | |
| }); | |
| } | |
| }; | |
| (function ($) { | |
| $.fn.extend({ | |
| toggleFacet: function (options) { | |
| return this.each(function () { | |
| var myToggleFacet = Object.create(toggleFacet); | |
| myToggleFacet.init(options, this); | |
| $(this).data('toggleFacet', myToggleFacet); | |
| }); | |
| } | |
| }); | |
| })(jQuery); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | var ToggleFacet = Backbone.View.extend({ | |
| el: '#caratteristiche', | |
| events: { | |
| 'click': 'toggleFacet' | |
| }, | |
| toggleFacet: function(event) { | |
| event.preventDefault(); | |
| this.$el.toggleClass('facet-collapsed'); | |
| } | |
| }); | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | $('#caratteristiche, #caratteristiche1, #caratteristiche2').on('click', 'a', function(event){ | |
| if(event.target !== this) { | |
| return; | |
| } | |
| event.preventDefault(); | |
| $(this).parent().toggleClass('facet-collapsed'); | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment