Commit 2f823c9c authored by Ariel Barreiro's avatar Ariel Barreiro
Browse files

Allow other modules to act on the created card element

parent 7760e35f
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -59,6 +59,9 @@
            // Create an instance of the card Element
            var card = elements.create('card', options);

            // Allow other modules to act on the created card element
            $(element).trigger('drupalStripe.elementCreated', ['card', card, elements]);

            // Add an instance of the card Element into the `card-element` <div>
            card.mount('#' + element.id + '-card-element');

+35 −0
Original line number Diff line number Diff line
/**
 * @file
 * Provides stripe attachment logic.
 */

(function ($, window, Drupal, drupalSettings, Stripe) {

  'use strict';

  /**
   * Attaches the stripe behavior
   *
   * @type {Drupal~behavior}
   *
   * @prop {Drupal~behaviorAttach} attach
   */
  Drupal.behaviors.stripeExamples = {
    attach: function (context, settings) {

      $('.form-item-stripe').on('drupalStripe.elementCreate', function(event, type, options) {
        console.log('Stripe ' + type + ' create options:', options);
      });

      $('.form-item-stripe').on('drupalStripe.elementCreated', function(event, type, element, elements) {
        // Do something on card.
        console.log('Stripe elements instance: ', elements);
        console.log('Stripe ' + type + ' element intance:', element);
        element.on('ready', function(e) {
          // Add an event handler
        });
      });
    }
  };

})(jQuery, window, Drupal, drupalSettings, Stripe);
+3 −0
Original line number Diff line number Diff line
stripe_examples:
  js:
    js/stripe_examples.js: {}

  css:
    theme:
      css/stripe_examples.css: {}