-
Notifications
You must be signed in to change notification settings - Fork 3
/
bb-tb.js
68 lines (42 loc) · 1.63 KB
/
bb-tb.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
66
67
68
(function() {
"use strict";
var MyView = Backbone.View.extend({
el: '#container',
events: {
'click button:first': 'handleClick',
'fastclick button:last': 'handleFastClick'
},
initialize: function() {
this.$output = this.$('#output');
this.addFastButtons();
},
handleClick: function() {
this.$output.prepend('<p>handleClick()</p>');
},
handleFastClick: function() {
this.$output.prepend('<p>handleFastClick()</p>');
},
addFastButtons: function() {
var EVENT_NAME = 'fastclick';
var events = (_.isFunction(this.events) ? this.events() : this.events) || {};
var that = this;
function byEventName(key) {
return key.substr(0, EVENT_NAME.length + 1) === EVENT_NAME + ' ' || key === EVENT_NAME;
}
function toJustSelectors(key) {
return key.substr(EVENT_NAME.length + 1);
}
function toMatchingElements(selector) {
return selector === "" ? [that.el] : that.$(selector).toArray();
}
function registerTrigger(element) {
new MBP.fastButton(element, function() {
$(element).trigger(EVENT_NAME);
});
}
_.chain(events).keys().filter(byEventName).map(toJustSelectors).map(toMatchingElements).flatten().each(registerTrigger);
}
});
MBP.hadTouchEvent = true; // work around some Android 2.3.x workarounds for the demo...
new MyView();
})();