Preparation Code Preparation HTML (this will be inserted in the <body>
of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script src ="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" > </script >
<script >
(function ($ ) {
var topics = {};
$.publish1 = function (topic, args ) {
if (topics[topic]) {
var currentTopic = topics[topic];
for (var i = 0 , j = currentTopic.length ; i < j; i++) {
currentTopic[i].apply ($, args || []);
}
}
};
$.subscribe1 = function (topic, callback ) {
if (!topics[topic]) {
topics[topic] = [];
}
topics[topic].push (callback);
return {
"topic" : topic,
"callback" : callback
};
};
$.unsubscribe1 = function (handle ) {
var topic = handle.topic ;
if (topics[topic]) {
var currentTopic = topics[topic];
for (var i = 0 , j = currentTopic.length ; i < j; i++) {
if (currentTopic[i] === handle.callback ) {
currentTopic.splice (i, 1 );
}
}
}
};
})(jQuery);
(function (jQuery ) {
var o = jQuery ({});
jQuery.each ({
"subscribe2" : "bind" ,
"unsubscribe2" : "unbind" ,
"publish2" : "trigger"
}, function (fn, api ) {
jQuery[fn] = function ( ) {
o[api].apply (o, arguments );
};
});
})(jQuery);
</script >
Setup JS
Teardown JS