Created
July 7, 2012 23:33
-
-
Save isa/3068581 to your computer and use it in GitHub Desktop.
jQuery Even PubSub Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en" class="no-js"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Some title</title> | |
<link rel="stylesheet" href="stylesheets/main.css" type="text/css" /> | |
<script type="text/javascript" charset="utf-8" src="javascripts/modernizr-2.5.3.min.js"></script> | |
<script type="text/javascript" charset="utf-8" src="javascripts/jquery-1.7.2.min.js"></script> | |
<script type="text/javascript" charset="utf-8" src="javascripts/main.js"></script> | |
<script type="text/javascript" charset="utf-8"> | |
(function($) { | |
var o = $({}); | |
$.each({ | |
trigger: 'publish', | |
on: 'subscribe', | |
off: 'unsubscribe' | |
}, function (key, value) { | |
jQuery[value] = function() { | |
o[key].apply(o, arguments); | |
}; | |
}); | |
})(jQuery); | |
$.subscribe('mp/something-happened', function(e, results) { | |
console.log('event received'); | |
}); | |
console.log('publishing the event'); | |
$.publish('mp/something-happened', 'published'); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment