jquery-fixclick

1.0.0 • Public • Published

jquery-fixclick

augmented clone/fork of AlloVince's fixclick plugin - his site is down so this is based on the v1.0 floating around...

Original / references to the original

References discussing the problem (mixing .click() and .dblclick())

Problem

When you bind both the single click and double click (dblclick) event on a DOM element, the click handler will fire once (or twice) before the dblclick handler is invoked.

Solution

With this plugin you can safely bind to both click and double click (dblclick) events and only have the appropriate one execute when the user clicks/double-clicks.

Note that the single-click event will be delayed by about 300 ms. This is unfortunately necessary to discern between both events.

Usage

Example usage:

$("#test").fixClick(function (e) {
  // do something here when click
  //
  // Note: this handler will be delayed! 
  // ($.fn.fixClick.clickDelay = 300 milliseconds by default)
  //
  // `e` event object is a clone of the original event and has
  // its `.simulated` field set to boolean `true`.
  ...
}, function (e) {
  // do something here when dblclick
  //
  // `e` is the usual event object you'ld expect for any jQuery
  // dblclick action. 
  ...
});

Enhanced example usage:

$("#test").fixClick(function (e) {
  // do something here when click
  //
  // Note: this handler will be delayed! 
  // ($.fn.fixClick.clickDelay = 300 milliseconds by default)
  //
  // `e` event object is a clone of the original event and has
  // its `.simulated` field set to boolean `true`.
  ...
}, function (e) {
  // do something here when dblclick
  //
  // `e` is the usual event object you'ld expect for any jQuery
  // dblclick action. 
  ...
}, function (e) {
  // this optional handler gets invoked *immediately* when
  // a click event arrives. Here you may perform some app-specific
  // setup/signaling.
  //
  // Warning/Note: this handler is, of course, invoked for each
  // click event, hence it will also be invoked for a dblclick.
  // When you wish jQuery-FixClick to *not* set up and fire a
  // delayed click handler (the first argument of this fixClick()
  // call), you can accomplish this by invoking
  // `e.stopImmediatePropagation()`.
  ...
  if (some_condition_where_you_dont_want_the_delayed_click_called) {
    e.stopImmediatePropagation();
  }
});

Readme

Keywords

Package Sidebar

Install

npm i jquery-fixclick

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • ganiserb