Sha256: ccdbac7fcaf1d7e45dc2e3b3fea545dc13a5ab19292b8268339b14ef6a4243ba
Contents?: true
Size: 1.6 KB
Versions: 2
Compression:
Stored size: 1.6 KB
Contents
/** * @namespace WORKAREA.quantityControl */ WORKAREA.registerModule('quantityControl', (function () { 'use strict'; var handleQtyEvent = function (event) { var $button = $(event.currentTarget), eventData = $button.data('quantityControl'), $qtyInput = $button.closest('form').find('.quantity-control__input'), currentQty = parseInt($qtyInput.val()), changeDirection = eventData.direction, autoSubmit = eventData.autosubmit || false; event.preventDefault(); updateQty($qtyInput, calculateQty(currentQty, changeDirection)); if(autoSubmit) { _.delay(submitForm, WORKAREA.config.oneTheme.quantityConrol.autoSubmitDelay, $qtyInput); } }, calculateQty = function(currentQty, changeDirection) { if (changeDirection === 'inc') { return currentQty + 1; } else { return currentQty > 0 ? currentQty - 1 : currentQty; } }, updateQty = function ($qtyInput, newQty) { $qtyInput.val(newQty); }, submitForm = function($qtyInput) { var $form = $qtyInput.closest('form'); if($form.valid()) { $form.submit(); } }, /** * @method * @name init * @memberof WORKAREA.quantityControl */ init = function ($scope) { $('[data-quantity-control]', $scope).on('click', handleQtyEvent); }; return { init: init }; }()));
Version data entries
2 entries across 2 versions & 1 rubygems