How to use delegate - 10 common examples

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 ForbesLindesay-Unmaintained / transformers / test / fixtures / component / build / build.js View on Github external
List.prototype.off = function(event, selector, fn, capture){
  if ('string' == typeof selector) {
    for (var i = 0; i < this.els.length; ++i) {
      // TODO: add selector support back
      delegate.unbind(this.els[i], event, fn._delegate, capture);
    }
    return this;
  }

  capture = fn;
  fn = selector;

  for (var i = 0; i < this.els.length; ++i) {
    events.unbind(this.els[i], event, fn, capture);
  }
  return this;
};
github swup / swup / src / index.js View on Github external
enable() {
		// check for Promise support
		if (typeof Promise === 'undefined') {
			console.warn('Promise is not supported');
			return;
		}

		// add event listeners
		this.delegatedListeners.click = delegate(
			document,
			this.options.linkSelector,
			'click',
			this.linkClickHandler.bind(this)
		);
		window.addEventListener('popstate', this.popStateHandler.bind(this));

		// initial save to cache
		let page = getDataFromHtml(document.documentElement.outerHTML, this.options.containers);
		page.url = page.responseURL = getCurrentUrl();
		if (this.options.cache) {
			this.cache.cacheUrl(page);
		}

		// mark swup blocks in html
		markSwupElements(document.documentElement, this.options.containers);
github sindresorhus / refined-github / source / features / add-confirmation-to-comment-cancellation.js View on Github external
export default function () {
	delegate('.js-hide-inline-comment-form', 'click', event => {
		// Do not prompt if textarea is empty
		const textarea = event.target.closest('.js-inline-comment-form').querySelector('.js-comment-field');
		if (textarea.value === '') {
			return;
		}

		if (window.confirm('Are you sure you want to discard your unsaved changes?') === false) { // eslint-disable-line no-alert
			event.stopPropagation();
			event.stopImmediatePropagation();
		}
	});
}
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 component / dom / dom.js View on Github external
return this.forEach(function (el) {
      // TODO: add selector support back
      delegate.unbind(el, event, fn._delegate, capture);
    });
  }
github component / dom / lib / events.js View on Github external
return this.forEach(function (el) {
      // TODO: add selector support back
      delegate.unbind(el, event, fn._delegate, capture);
    });
  }

delegate

Lightweight event delegation

MIT
Latest version published 6 years ago

Package Health Score

70 / 100
Full package analysis

Popular delegate functions