Skip to content

martinkr/jQuery.channel

Repository files navigation

jQuery.channel is a complete pub/sub implementation build on top of jQuery.Callbacks.

###Features

  • preserves the jQuery-chain! $('div').channel('subscribe' ... )
  • pass custom data while to the channel
  • manipulate the context "this" on the callback
  • use regular expressions as wildcards begining on the starting position within the string.
  • subscribe to multiple channels with just one call: $.channel('subscribe','CHANNEL/SUB*',myFunction)

Examples

Subscribe:

	jQuery.channel('subscribe','CHANNEL/FOO/BAR', myFunction );

Unsubscribe

	jQuery.channel('unsubscribe','CHANNEL/FOO/BAR', myFunction )

Publish

	jQuery.channel('publish','CHANNEL/FOO/BAR')

Advanced

Use Wildcards.

	jQuery.channel('subscribe','CHANNEL/FOO.*', myFunction );
	jQuery.channel('subscribe','CHANNEL/*.FOO/', myFunction );
	jQuery.channel('subscribe','CHANNEL/*.FOO.*/', myFunction );

Pass custom data to the channel.

	jQuery.channel('publish','CHANNEL/SUB/',{'key':'value'})

Change the context aka "this".

	jQuery.channel('publish','CHANNEL/SUB/',{},jQuery('#id'))

Preserve the jQuery-chain

	jQuery('#id').channel('subscribe','CHANNEL/FOO.*', myFunction ).html('subscribed!')

Requires

License

Dual licensed under the MIT and GPL licenses.

Copyright (c) 2011-2013 Martin Krause (jquery.public.mkrause.info)

About

jQuery.channel is a complete pub/sub implementation build on top of jQuery.Callbacks.

Resources

License

Stars

Watchers

Forks

Packages

No packages published