// Otherwise, parse toggle class
else {
input = this.$element.data('toggler');
-
// Allow for a . at the beginning of the string
- if (input[0] === '.') {
- this.className = input.slice(1);
- }
- else {
- this.className = input;
- }
+ this.className = input[0] === '.' ? input.slice(1) : input;
}
// Add ARIA attributes to triggers
var id = this.$element[0].id;
$('[data-open="'+id+'"], [data-close="'+id+'"], [data-toggle="'+id+'"]')
.attr('aria-controls', id);
-
// If the target is hidden, add aria-hidden
- if (this.$element.is(':hidden')) {
- this.$element.attr('aria-expanded', 'false');
- }
+ this.$element.attr('aria-expanded', this.$element.is(':hidden') ? false : true);
};
/**
* @private
*/
Toggler.prototype._events = function() {
- var _this = this;
-
- this.$element.on('toggle.zf.trigger', function() {
- _this.toggle();
- return false;
- });
+ this.$element.off('toggle.zf.trigger').on('toggle.zf.trigger', this.toggle.bind(this));
};
/**
* @fires Toggler#off
*/
Toggler.prototype.toggle = function() {
- if (!this.options.animate) {
- this._toggleClass();
- }
- else {
- this._toggleAnimate();
- }
+ this[ this.options.animate ? '_toggleAnimate' : '_toggleClass']();
};
Toggler.prototype._toggleClass = function() {
- var _this = this;
this.$element.toggleClass(this.className);
- if (this.$element.hasClass(this.className)) {
+ var isOn = this.$element.hasClass(this.className);
+ if (isOn) {
/**
* Fires if the target element has the class after a toggle.
* @event Toggler#on
this.$element.trigger('off.zf.toggler');
}
- _this._updateARIA();
+ this._updateARIA(isOn);
};
Toggler.prototype._toggleAnimate = function() {
if (this.$element.is(':hidden')) {
Foundation.Motion.animateIn(this.$element, this.animationIn, function() {
this.trigger('on.zf.toggler');
- _this._updateARIA();
+ _this._updateARIA(true);
});
}
else {
Foundation.Motion.animateOut(this.$element, this.animationOut, function() {
this.trigger('off.zf.toggler');
- _this._updateARIA();
+ _this._updateARIA(false);
});
}
};
- Toggler.prototype._updateARIA = function() {
- if (this.$element.is(':hidden')) {
- this.$element.attr('aria-expanded', 'false');
- }
- else {
- this.$element.attr('aria-expanded', 'true');
- }
+ Toggler.prototype._updateARIA = function(isOn) {
+ this.$element.attr('aria-expanded', isOn ? true : false);
};
/**