-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhtml_button.js
65 lines (57 loc) · 1.7 KB
/
html_button.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
Plugin Name: HTML Button
Plugin URI: https://github.com/empika/ImpactJS-Plugins
Description: Bind HTML buttons to ordinary mouse clicks (mouseup, mousedown, click)
Version: 0.2
Revision Date: 20-05-2012
Requires: ImpactJS
Author: Edward Parris
Author URI: http://www.nixonmcinnes.co.uk/people/edward/
Changelog
---------
0.2: Namespace the plugin.
0.1: Initial release.
*/
ig.module(
'plugins.empika.html_button'
)
.requires(
'impact.input'
)
.defines(function() {
ig.Input.inject({
// Overwrite bindTouch so we can bind click if touch is not available
bindTouch: function( selector, action_down, action_up, click ) {
var action_down = typeof(action_down) != 'undefined' ? action_down : false;
var action_up = typeof(action_up) != 'undefined' ? action_up : false;
var click = typeof(click) != 'undefined' ? click : false;
var element = ig.$( selector );
var that = this;
if('ontouchstart' in element && 'ontouchend' in element){
element.addEventListener('touchstart', function(ev) {
that.touchStart( ev, action_down );
}, false);
element.addEventListener('touchend', function(ev) {
that.touchEnd( ev, action_down );
}, false);
}
else{
if( action_down ){
element.addEventListener('mousedown', function(ev) {
that.touchStart( ev, action_down );
}, false);
}
if( action_up ){
element.addEventListener('mouseup', function(ev) {
that.touchStart( ev, action_up );
}, false);
}
if( click ){
element.addEventListener('click', function(ev) {
that.touchStart( ev, click );
}, false);
}
}
}
});
});