Sha256: 827a9983fca65707432d1847637e74e6746fc15cb3cc56bad3e549b5803c7122

Contents?: true

Size: 1.81 KB

Versions: 54

Compression:

Stored size: 1.81 KB

Contents

/**
 * Count quantity wrapper.
 *
 * @author Htmlstream
 * @version 1.0
 *
 */
;(function ($) {
  'use strict';

  $.HSCore.components.HSCountQty = {
    /**
     *
     *
     * @var Object _baseConfig
     */
    _baseConfig: {},

    /**
     *
     *
     * @var jQuery pageCollection
     */
    pageCollection: $(),

    /**
     * Initialization of Count quantity wrapper.
     *
     * @param String selector (optional)
     * @param Object config (optional)
     *
     * @return jQuery pageCollection - collection of initialized items.
     */

    init: function (selector, config) {

      this.collection = selector && $(selector).length ? $(selector) : $();
      if (!$(selector).length) return;

      this.config = config && $.isPlainObject(config) ?
          $.extend({}, this._baseConfig, config) : this._baseConfig;

      this.config.itemSelector = selector;

      this.initCountQty();

      return this.pageCollection;

    },

    initCountQty: function () {
      //Variables
      var $self = this,
          collection = $self.pageCollection;

      //Actions
      this.collection.each(function (i, el) {
        //Variables
        var $this = $(el),
            $plus = $this.find('.js-plus'),
            $minus = $this.find('.js-minus'),
            $result = $this.find('.js-result'),
            resultVal = parseInt($result.val());

        $plus.on('click', function (e) {
          e.preventDefault();

          resultVal += 1;

          $result.val(resultVal);
        });

        $minus.on('click', function (e) {
          e.preventDefault();

          if (resultVal >= 1) {
            resultVal -= 1;

            $result.val(resultVal);
          } else {
            return false;
          }
        });

        //Actions
        collection = collection.add($this);
      });
    }

  };

})(jQuery);

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
jekyll-theme-glueckkanja-1.2.29 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.28 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.27 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.26 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.25 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.24 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.23 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.22 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.21 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.20 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.19 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.18 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.17 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.16 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.15 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.14 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.13 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.12 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.11 assets/js/components/hs.count-qty.js
jekyll-theme-glueckkanja-1.2.10 assets/js/components/hs.count-qty.js