Changeset View
Changeset View
Standalone View
Standalone View
webroot/rsrc/js/core/behavior-toggle-class.js
Show All 10 Lines | |||||
* data. The `map` should be a map from element IDs to the classes that should | * data. The `map` should be a map from element IDs to the classes that should | ||||
* be toggled on them. | * be toggled on them. | ||||
* | * | ||||
* Optionally, you may provide a `state` key to set the default state of the | * Optionally, you may provide a `state` key to set the default state of the | ||||
* element. | * element. | ||||
*/ | */ | ||||
JX.behavior('toggle-class', function(config, statics) { | JX.behavior('toggle-class', function(config, statics) { | ||||
function install() { | function install() { | ||||
JX.Stratcom.listen( | JX.Stratcom.listen( | ||||
['touchstart', 'mousedown'], | 'click', | ||||
epriestley: (This comment is kind of pointless now, I'll just remove it.) | |||||
'jx-toggle-class', | 'jx-toggle-class', | ||||
function(e) { | function(e) { | ||||
e.kill(); | e.kill(); | ||||
var t = e.getNodeData('jx-toggle-class'); | var t = e.getNodeData('jx-toggle-class'); | ||||
t.state = !t.state; | t.state = !t.state; | ||||
for (var k in t.map) { | for (var k in t.map) { | ||||
JX.DOM.alterClass(JX.$(k), t.map[k], t.state); | JX.DOM.alterClass(JX.$(k), t.map[k], t.state); | ||||
} | } | ||||
}); | }); | ||||
// Swallow the regular click handler event so e.g. Quicksand | |||||
// click handler doesn't get a hold of it | |||||
JX.Stratcom.listen( | |||||
['click'], | |||||
'jx-toggle-class', | |||||
function(e) { | |||||
e.kill(); | |||||
}); | |||||
return true; | return true; | ||||
} | } | ||||
statics.install = statics.install || install(); | statics.install = statics.install || install(); | ||||
}); | }); |
(This comment is kind of pointless now, I'll just remove it.)