forked from aheckmann/jquery.hook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
47 lines (36 loc) · 1.28 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>Test jquery.hook</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script src="jquery.hook.js"></script>
<script>
$(function(){
$.hook('addClass hide');
$("#clickme").bind('onbeforeaddClass', function (e) {
alert('onbeforeaddClass fired :' + ('onbeforeaddClass' === e.type));
})
.bind('onaddClass', function (e) {
alert('onaddClass fired :' + ('onaddClass'=== e.type));
return false;
})
.bind('onafteraddClass', function (e) {
alert('onafteraddClass fired : ' + ('onafteraddClass' === e.type)); //+ '\n' + $(this).is('.newclass'));
});
$("#clickme").addClass('newclass'); // 3 alerts
$.unhook('addClass');
$("#clickme").addClass('diffClass'); // no alerts but class is still added
alert( "the button has class 'diffClass' : " + $("#clickme").is('.diffClass') ); // alerts true
$("#clickme").bind('onafterhide', function () {
alert("The button is now hidden.");
}).bind('click', function () {
$(this).hide(); // alerts "The button is now hidden."
});
});
</script>
</head>
<body>
<button id="clickme" name="clickme" type="button">click me</button>
</body>
</html>