How to use the delegate.bind function in delegate

To help you get started, we’ve selected a few delegate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github knowthelist / fhem-tablet-ui / www / tablet / lib / powerange.js View on Github external
var e = parse(event);
  var el = this.el;
  var obj = this.obj;
  var name = e.name;
  var method = method || 'on' + name;
  var args = [].slice.call(arguments, 2);

  // callback
  function cb(){
    var a = [].slice.call(arguments).concat(args);
    obj[method].apply(obj, a);
  }

  // bind
  if (e.selector) {
    cb = delegate.bind(el, e.selector, name, cb);
  } else {
    events.bind(el, name, cb);
  }

  // subscription for unbinding
  this.sub(name, method, cb);

  return cb;
};
github auth0 / lock-passwordless / assets / remember.js View on Github external
this.excepts = [];
  this.ids = {};
  var self = this;

  // localstorage namespace
  this.namespace = options.namespace || 'remember:';

  // pull from storage
  this.pull();

  this.oninput = bind(this, this.input);
  this.onselect = bind(this, this.select);

  // bindings
  delegate.bind(document, inputs, 'input', this.oninput);
  delegate.bind(document, buttons, 'click', this.onselect);
}
github matthewmueller / tipp / dist / tipp.js View on Github external
var e = parse(event);
  var el = this.el;
  var obj = this.obj;
  var name = e.name;
  var method = method || 'on' + name;
  var args = [].slice.call(arguments, 2);

  // callback
  function cb(){
    var a = [].slice.call(arguments).concat(args);
    obj[method].apply(obj, a);
  }

  // bind
  if (e.selector) {
    cb = delegate.bind(el, e.selector, name, cb);
  } else {
    events.bind(el, name, cb);
  }

  // subscription for unbinding
  this.sub(name, method, cb);

  return cb;
};
github matthewmueller / remember / index.js View on Github external
options = options || {};
  this.excepts = [];
  this.ids = {};
  var self = this;

  // localstorage namespace
  this.namespace = options.namespace || 'remember:';

  // pull from storage
  this.pull();

  this.oninput = bind(this, this.input);
  this.onselect = bind(this, this.select);

  // bindings
  delegate.bind(document, inputs, 'input', this.oninput);
  delegate.bind(document, buttons, 'click', this.onselect);
}
github auth0 / lock-passwordless / assets / remember.js View on Github external
options = options || {};
  this.excepts = [];
  this.ids = {};
  var self = this;

  // localstorage namespace
  this.namespace = options.namespace || 'remember:';

  // pull from storage
  this.pull();

  this.oninput = bind(this, this.input);
  this.onselect = bind(this, this.select);

  // bindings
  delegate.bind(document, inputs, 'input', this.oninput);
  delegate.bind(document, buttons, 'click', this.onselect);
}
github zenorocha / delegate / test / index.html View on Github external
console.log(e.target);
        if (++n >= 3) {
          console.log('unbind');
          delegate.unbind(uls[0], 'click', fn, false);
        }
      }, false);

      var fn2 = delegate.bind(uls[1], 'li a', 'click', function(e){
        console.log(e.target);
        if (++n >= 8) {
          console.log('unbind');
          delegate.unbind(uls[1], 'click', fn2, false);
        }
      }, false);

      var fn3 = delegate.bind(uls[2], 'li', 'click', function(e){
        console.log(e.target);
        if (++n >= 8) {
          console.log('unbind');
          delegate.unbind(uls[2], 'click', fn2, false);
        }
      }, false);
github component / view / index.js View on Github external
View.prototype.bind = function(str, method){
  var parts = str.split(' ');
  var event = parts.shift();
  var selector = parts.join(' ');
  var meth = this[method];
  if (!meth) throw new TypeError('method "' + method + '" is not defined');
  var fn = delegate.bind(this.el, selector, event, meth.bind(this));
  this.bindings[str] = fn;
};
github component / dom / lib / events.js View on Github external
return this.forEach(function (el) {
      fn._delegate = delegate.bind(el, selector, event, fn, capture);
    });
  }
github garrows / browser-serialport / demo / browser-serialport.js View on Github external
List.prototype.on = function(event, selector, fn, capture){
  if ('string' == typeof selector) {
    for (var i = 0; i < this.els.length; ++i) {
      fn._delegate = delegate.bind(this.els[i], selector, event, fn, capture);
    }
    return this;
  }

  capture = fn;
  fn = selector;

  for (var i = 0; i < this.els.length; ++i) {
    events.bind(this.els[i], event, fn, capture);
  }

  return this;
};
github matthewmueller / events / events.js View on Github external
Events.prototype.bind = function(el, event, fn) {
  if('string' == typeof el) fn = event, event = el, el = this.el;

  this._events = this._events || {};

  var events = this._events,
      match = event.match(splitter),
      eventName = match[1],
      selector = match[2];

  fn = ('string' == typeof fn) ? this[fn] : fn;
  fn = fn.bind(this);

  if(selector === '') Event.bind(el, eventName, fn);
  else fn = Delegate.bind(el, selector, eventName, fn);

  if(!events[eventName]) events[eventName] = [];
  events[eventName].push(fn);

  return this;
};

delegate

Lightweight event delegation

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis

Popular delegate functions