Skip to content

Instantly share code, notes, and snippets.

@thruflo
Created June 29, 2010 14:59
Show Gist options
  • Select an option

  • Save thruflo/457319 to your computer and use it in GitHub Desktop.

Select an option

Save thruflo/457319 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js">
</script>
<script type="text/javascript">
(function ($) {
jQuery.fn.foo = function (name) {
return this.each(
function (i) {
function init () {
console.log('init');
console.log(this);
$(this).click(handle);
}
function handle (event) {
event.stopPropagation();
console.log('handle');
console.log(this);
doit();
}
function doit () {
console.log('doit');
console.log(this);
}
if (!$(this).data('foo')) {
$(this).data('foo', true);
// register public methods
$.extend(
this, {
'doit': doit
}
);
// initialise
init();
}
}
);
};
$(document).ready(
function () {
$('#foo').foo();
$('#bar').click(
function () {
var foo = $('#foo').get(0);
foo.doit();
}
);
}
);
}
)(jQuery);
</script>
</head>
<body>
<a id="foo" href="#foo">
foo
</a>
<br />
<a id="bar" href="#bar">
bar
</a>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment