Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had been trying for ages to generalize this kind of process, but in my case I was only concerned with the order of first event listener in the chain. </p> <p>If it's of any use, here is my jQuery plugin that binds an event listener that is always triggered before any others:</p> <p>** <em>UPDATED inline with jQuery changes (thanks Toskan)</em> **</p> <pre><code>(function($) { $.fn.bindFirst = function(/*String*/ eventType, /*[Object])*/ eventData, /*Function*/ handler) { var indexOfDot = eventType.indexOf("."); var eventNameSpace = indexOfDot &gt; 0 ? eventType.substring(indexOfDot) : ""; eventType = indexOfDot &gt; 0 ? eventType.substring(0, indexOfDot) : eventType; handler = handler == undefined ? eventData : handler; eventData = typeof eventData == "function" ? {} : eventData; return this.each(function() { var $this = $(this); var currentAttrListener = this["on" + eventType]; if (currentAttrListener) { $this.bind(eventType, function(e) { return currentAttrListener(e.originalEvent); }); this["on" + eventType] = null; } $this.bind(eventType + eventNameSpace, eventData, handler); var allEvents = $this.data("events") || $._data($this[0], "events"); var typeEvents = allEvents[eventType]; var newEvent = typeEvents.pop(); typeEvents.unshift(newEvent); }); }; })(jQuery); </code></pre> <p><strong>Things to note:</strong></p> <ul> <li>This hasn't been fully tested.</li> <li>It relies on the internals of the jQuery framework not changing (only tested with 1.5.2).</li> <li>It will not necessarily get triggered before event listeners that are bound in any way other than as an attribute of the source element or using jQuery bind() and other associated functions.</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload