Sha256: fb884ba96b80cfc920553bbb47b3d2e334d27b4f936abe932b78f1dffdd199cd

Contents?: true

Size: 1.58 KB

Versions: 20

Compression:

Stored size: 1.58 KB

Contents

window.ClassToggler = (function() {
  var defaults;

  defaults = {
    containerClass: null,
    $target: null,
    activeClass: "active",
    inactiveClass: null,
    toggleOn: "click"
  };

  function ClassToggler(options) {
    this.options = Utils.setOptions(options, defaults);
    if (this.options.$target) {
      this.addEventListeners();
    } else {
      console.trace("ClassToggle", this.options);
    }
  }

  ClassToggler.prototype.addEventListeners = function() {
    return this.options.$target.on(this.options.toggleOn, (function(_this) {
      return function(e) {
        var $togglableElement = _this.options.containerClass ? $(e.target).closest(_this.options.containerClass) : $(e.delegateTarget);
        if (_this.isActive($togglableElement)) {
          return _this.hide($togglableElement, e);
        } else {
          return _this.show($togglableElement, e);
        }
      };
    })(this));
  };

  ClassToggler.prototype.isActive = function($togglableElement) {
    return $togglableElement.hasClass(this.options.activeClass);
  };

  ClassToggler.prototype.show = function($togglableElement, e) {
    var base;
    if (typeof (base = this.options).onShow === "function") {
      base.onShow($togglableElement, e);
    }

    return $togglableElement.addClass(this.options.activeClass);
  };

  ClassToggler.prototype.hide = function($togglableElement, e) {
    var base;
    if (typeof (base = this.options).onHide === "function") {
      base.onHide($togglableElement, e);
    }

    return $togglableElement.removeClass(this.options.activeClass);
  };

  return ClassToggler;

})();

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ustyle-1.16.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.15.3 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.14.11 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.14.10 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.14.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.12.6 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.12.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.12.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.11.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.10.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.8.7 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.8.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.8.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.7.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.6.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.5.8 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.4.1 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.4.0 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.3.12 vendor/assets/javascripts/ustyle/classtoggler.js
ustyle-1.3.6 vendor/assets/javascripts/ustyle/classtoggler.js