Sunday, September 4, 2011

A Signal Slot Implementation for jQuery

What is Signal Slot?

Signals and slots is a language construct introduced in Qt, which makes it easy to implement the Observer pattern while avoiding boilerplate code. The concept is that controls (also known as widgets) can send signals containing event information (e.g. the text "toto" was selected, the scrollbar has been adjusted to value 37) which can be received by other controls using special functions known as slots. [wiki]

With this simple signal slot plugin for jQuery you can take this feature of Qt into your webapp.

This plugin was finished in 2008 and inspired by Qt and the another jQuery Plugin by AJ


Define your Signal

var SIGNAL = "A Signal";

var optionsForSignal = {
    evt: 'click',
    prefunc: function() {
         // conditions for emitting of this signal
    callback: function() {
        // callback after the signal emitted

$("#elementID").signal(SIGNAL, "Argument for Slot", optionsForSignal);
    ["Arg1", "#Arg2"], // If you have more than one arguments of Slot

Define your Slot

// add slot method 1
    function(arg1, args2, ...) {
      // what to do if this slot called
    false // a boolean to indicate if this slot should repeated

// add slot method 2
    function(arg1, arg2, ... ) {
      // example
      if ($(this).is(":hidden")) {
      } else {


Check out the example:

Latest Release


Signal Slot jQuery Plugin Licensed under the MIT

Enjoy. Let me know if you like. @yuanhao