All Downloads are FREE. Search and download functionalities are using the official Maven repository.

template.js.plugins.jquery.subscribe.min.js Maven / Gradle / Ivy

There is a newer version: 5.0.4
Show newest version
/*
 * jquery.subscribe.1.2.3
 * 
 * Implementation of publish/subcription framework for jQuery
 * Requires use of jQuery. Tested with jQuery 1.3 and above
 *
 *
 * Copyright (c) 2008 Eric Chijioke (obinna a-t g mail dot c o m)
 * Copyright (c) 2011 Johannes Geppert http://www.jgeppert.com
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 */
(function(d){var c,e,b,a;if(!window._subscribe_topics){c={};e={}}b=function(f){return f.parentWindow||f.defaultView};d.fn.extend({createTopic:function(f){if(f&&!c[f]){c[f]={};c[f].objects={};c[f].objects.__noId__=[]}return this},destroyTopic:function(f){if(f&&c[f]){d.each(c[f].objects,function(h,g){if(d.isArray(g)){d.each(g,function(i,k){if(!d.isFunction(k)){k.unbind(f)}})}else{g.unbind(f)}})}delete c[f];return this},subscribe:function(g,i,l,f){if(this[0]&&g&&i){this.createTopic(g);if(this.attr("id")){c[g].objects[this.attr("id")]=this}else{var m=c[g].objects.__noId__;if(this[0].nodeType===9){jQuery.each(m,function(n,o){if(!d.isFunction(o)&&o[0].nodeType===9&&b(this[0]).frameElement===b(o[0]).frameElement){return this}})}var j=false;for(a=0;a0){this.unbind(g)}}if(d.isFunction(i)){this.bind(g,l,i)}else{if(typeof(i)==="string"&&d.isFunction(e[i])){this.bind(g,l,e[i])}}}}return this},unsubscribe:function(g){if(g){if(c[g]){if(this.attr("id")){var f=c[g].objects[this.attr("id")];if(f){delete c[g].objects[this.attr("id")]}}else{var h=c[g].objects.__noId__;for(a=0;a0){jQuery.each(k,function(m,n){if(!d.isFunction(n)){n.trigger(i,j)}})}}else{k.trigger(i,j)}})}return this},publishOnEvent:function(g,f,h){if(g&&f){this.createTopic(f);this.bind(g,h,function(i){d(this).publish(f,i.data,i)})}return this}});d.extend({subscribe:function(f,g,h){return d(document).subscribe(f,g,h)},unsubscribe:function(f,g,h){return d(document).unsubscribe(f,g,h)},subscribeHandler:function(f,g){if(f&&g&&d.isFunction(g)){e[f]=g}return d(document)},publish:function(f,g){return d(document).publish(f,g)},createTopic:function(f){return d(document).createTopic(f)},destroyTopic:function(f){return d(document).destroyTopic(f)}})})(jQuery);




© 2015 - 2024 Weber Informatics LLC | Privacy Policy