|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * JavaScript file for the UI Pattern settings module. |
| 4 | + */ |
| 5 | + |
| 6 | +(function ($, Drupal, drupalSettings, DrupalCoffee) { |
| 7 | + |
| 8 | + 'use strict'; |
| 9 | + |
| 10 | + /** |
| 11 | + * Attaches ui patterns settings module behaviors. |
| 12 | + * |
| 13 | + * Handles enable/disable bind input element. |
| 14 | + * |
| 15 | + * @type {Drupal~behavior} |
| 16 | + * |
| 17 | + * @prop {Drupal~behaviorAttach} attach |
| 18 | + * Attach ui patterns settings toggle functionality to the page. |
| 19 | + * |
| 20 | + * @todo get most of it out of the behavior in dedicated functions. |
| 21 | + */ |
| 22 | + Drupal.behaviors.ups_toggle_token = { |
| 23 | + attach: function () { |
| 24 | + var disableClass = 'ui-pattern-settings-disable'; |
| 25 | + |
| 26 | + $('.ui-pattern-settings-token-wrapper').once().each(function () { |
| 27 | + if ($(this).hasClass('ui-pattern-settings-token-has-value')) { |
| 28 | + $(this).prev().addClass(disableClass); |
| 29 | + } |
| 30 | + else { |
| 31 | + $(this).addClass(disableClass); |
| 32 | + } |
| 33 | + }); |
| 34 | + |
| 35 | + |
| 36 | + $('.js-ui-patterns-settings-token').once().each(function () { |
| 37 | + $(this).click(function () { |
| 38 | + var tokenWrapper = $(this).closest('.ui-pattern-settings-token-wrapper'); |
| 39 | + var tokenInput = tokenWrapper.find('input'); |
| 40 | + var inputWrapper = tokenWrapper.prev(); |
| 41 | + var initValue = tokenInput.val(); |
| 42 | + |
| 43 | + tokenWrapper.addClass(disableClass); |
| 44 | + tokenInput.attr('data-init-val', initValue); |
| 45 | + tokenInput.val(''); |
| 46 | + inputWrapper.removeClass(disableClass); |
| 47 | + }); |
| 48 | + }); |
| 49 | + |
| 50 | + $('.js-ui-patterns-settings-input').once().each(function () { |
| 51 | + $(this).click(function () { |
| 52 | + var inputWrapper = $(this).closest('.js-form-item'); |
| 53 | + var tokenWrapper = inputWrapper.next(); |
| 54 | + inputWrapper.addClass(disableClass); |
| 55 | + tokenWrapper.removeClass(disableClass); |
| 56 | + var tokenInput = tokenWrapper.find('input'); |
| 57 | + var restoreVal = tokenInput.attr('data-init-val'); |
| 58 | + if (restoreVal != '') { |
| 59 | + tokenInput.val(restoreVal); |
| 60 | + } |
| 61 | + }); |
| 62 | + }) |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | +})(jQuery, Drupal, drupalSettings); |
0 commit comments