Sha256: e5898d294015a969bd9b326976c392e87b6fe46427c16c3050f548f7b720b24e

Contents?: true

Size: 902 Bytes

Versions: 6

Compression:

Stored size: 902 Bytes

Contents

//= require jquery.maskMoney.min

$(function() {
  var getUnmaskedMoneyCents,
      updateSiblingHiddenFieldValueOf,
      syncUnmaskedValueWithHiddenField,
      $applyMaskMoneyTo,
      setupMaskMoney,
      EVENTS_TO_SYNC = 'change keyup paste';

  getUnmaskedMoneyCents = function($el) {
    return $el.maskMoney('unmasked')[0] * 100;
  };

  updateSiblingHiddenFieldValueOf = function($el, getNewValue) {
    $el.siblings('[type="hidden"]').val(
      getNewValue($el)
    );
  };

  syncUnmaskedValueWithHiddenField = function() {
    updateSiblingHiddenFieldValueOf($(this), getUnmaskedMoneyCents);
  };

  $applyMaskMoneyTo = function(el) {
    return $(el).maskMoney().trigger('mask');
  };

  setupMaskMoney = function() {
    $applyMaskMoneyTo(this)
      .on(
        EVENTS_TO_SYNC,
        syncUnmaskedValueWithHiddenField
      );
  };

  $('[data-maskmoney]').each(setupMaskMoney);
});

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
administrate-field-money-0.3.0 app/assets/javascripts/administrate-field-money/application.js
administrate-field-money-0.2.1 app/assets/javascripts/administrate-field-money/application.js
administrate-field-money-0.2.0 app/assets/javascripts/administrate-field-money/application.js
administrate-field-money-0.1.2 app/assets/javascripts/administrate-field-money/application.js
administrate-field-money-0.1.1 app/assets/javascripts/administrate-field-money/application.js
administrate-field-money-0.1.0 app/assets/javascripts/administrate-field-money/application.js