Sha256: 6231324bf8c9ea0605241af501fbaf4a492fafbbaabddb4eec1ae0d60d676b49

Contents?: true

Size: 1.75 KB

Versions: 28

Compression:

Stored size: 1.75 KB

Contents

_.each(["View"], function(name) {
  // Cache Backbone constructor.
  var ctor = Backbone[name];
  // Cache original fetch.
  var delegateEvents = ctor.prototype.delegateEvents;

  var delegateEventSplitter = /^(\S+)\s*(.*)$/;

  // Override the fetch method to emit a fetch event.
  ctor.prototype.delegateEvents = function(events) {
      if (!(events || (events = _.result(this, 'events')))) return;
      this.undelegateEvents();
      for (var key in events) {
        var method = events[key];
        if (!_.isFunction(method)) method = this[events[key]];
        if (!method) throw new Error('Method "' + events[key] + '" does not exist');
        var match = key.match(delegateEventSplitter);
        var eventName = match[1], selector = match[2];
        method = _.bind(method, this);
        originalEvent = eventName;
        eventName = '.delegateEvents' + this.cid;
        if ((originalEvent == "click") && (selector !== '')) {
          if (window.TOUCH_SUPPORT) {
            this.$el.on( "touchstart" + eventName, selector, function(event) { $(this).addClass('active'); } );
            this.$el.on( "touchend" + eventName, selector, function(event) { $(this).removeClass('active'); } );
            this.$el.on( "touchcancel" + eventName, selector, function(event) { $(this).removeClass('active'); } );
          }
          else {
            this.$el.on( "mousedown" + eventName, selector, function(event) { $(this).addClass('active'); } );
            this.$el.on( "mouseup" + eventName, selector, function(event) { $(this).removeClass('active'); } );
          }
        }
        if (selector === '') {
          this.$el.on(originalEvent + eventName, method);
        } else {
          this.$el.on(originalEvent + eventName, selector, method);
        }
      }
  };
});

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
iugu-ux-1.0.25 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.24 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.23 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.22 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.21 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.20 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.19 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.18 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.17 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.16 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.15 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.14 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.13 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.12 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.11 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.10 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.9 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.8 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.7 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js
iugu-ux-1.0.6 vendor/assets/javascripts/vendor/backbone.advanced-delegate.js