Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

No commit message

  • Loading branch information...
commit 3707d4afb64dee96135a8a39f1ff3af6e8b5e3d8 1 parent 257d393
@aheckmann authored
Showing with 25 additions and 13 deletions.
  1. +25 −13 README.md
View
38 README.md
@@ -1,29 +1,41 @@
# jquery.hook
-> Provides the ability to hook into any `jQuery.fn[ method ]` with `onbeforeMETHOD`, `onMETHOD`, and `onafterMETHOD`s.
+> jQuery.hook provides the simple ability to hook into/around any `jQuery.fn[ method ]` with custom events. These events can be listened to just like any other jQuery events:
+ jQuery.hook('show');
+ jQuery(selector).bind('onbeforeshow', function () {
+ // this is fired before show() is fired
+ });
-Pass in a string or array of method names you want to hook into with `onbefore`, `on`, or `onafter` events. Example:
+Just pass in a string or array of method names you want to hook and when you call the method, three additional events are fired. Here is the new execution flow:
- jQuery.hook('show');
- jQuery(selector).bind('onbeforeshow', function (e) { alert(e.type); });
- jQuery(selector).show() -> alerts 'onbeforeshow'
+1) onbeforeMETHOD event fires
+2) onMETHOD event fires
+3) original METHOD fires
+4) onafterMETHOD event fires
+Example:
jQuery.hook('show hide');
jQuery(selector)
.bind('onbeforeshow', function (e) { alert(e.type);})
.bind('onshow', function (e) { alert(e.type);})
.bind('onaftershow', function (e) { alert(e.type);})
- .bind('onafterhide', function (e) { alert("The element is now hidden.");});
-
- jQuery(selector).show();
- -> alerts 'onbeforeshow' then alerts 'onshow', then alerts 'onaftershow'
-
- jQuery(selector).hide();
- -> after the element is hidden alerts 'The element is now hidden.'
+ .bind('onafterhide', function (e) {
+ alert("The element is hidden");
+ })
+ ;
+
+ jQuery(selector).show().hide();
+ -> alerts 'onbeforeshow',
+ then alerts 'onshow',
+ then alerts 'onaftershow',
+ and after hide fires alerts 'The element is hidden'
You can also unhook what you've hooked into by calling `jQuery.unhook()` passing in your string or array of method names to unhook.
- jQuery.unhook('show hide');
+Example:
+
+ jQuery.unhook('show hide');
+
Please sign in to comment.
Something went wrong with that request. Please try again.