Sha256: cdbec5b095431e9863793ce1115bf7bf63b217d1006d447ae00e8b28b27caf73

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

$(function() {
  var rootContainer = null;

  // donation kit configuration below

  if ((rootContainer = $('#edit-donation-kit')).length) {
    var nodeHtml = $('<div>').append($('.new-suggested-gift-container', rootContainer).clone()).html(),
        nodeIdx = parseInt(nodeHtml.match(/\[(\d+)\]/) ? RegExp.$1 : 0);

    $(document).on('click', '#edit-donation-kit .suggested-gift-remove', function() {
      if (confirm('Are you sure you want to remove this gift level?')) {
        $(this).parents('.suggested-gift-container').first().remove();
      }
    });

    $(document).on('click', '#edit-donation-kit .suggested-gift-add', function() {
      var lastNode = $('.new-suggested-gift-container').last(),
          amount = parseFloat($('input', lastNode).last().val()) || 0;

      console.log(lastNode, amount);

      if (amount) {
        nodeIdx += 1;

        setTimeout(function() {
          $('a', lastNode).html('Remove').removeClass('suggested-gift-add').addClass('suggested-gift-remove');
          var newHtml = nodeHtml.replace(/\[\d+]/g, '[' + nodeIdx + ']').replace(/_\d+_/g, '_' + nodeIdx + '_');
          lastNode.after(newHtml);
        }, 50);
      }
    })
  }
});

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
artfully_ose-1.2.0 app/assets/javascripts/custom/kits-config.js
artfully_ose-1.2.0.beta.1 app/assets/javascripts/custom/kits-config.js
artfully_ose-1.2.0.alpha.2 app/assets/javascripts/custom/kits-config.js
artfully_ose-1.2.0.alpha.1 app/assets/javascripts/custom/kits-config.js