This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/modules/contrib/webform/js/webform.element.counter.js
2017-03-16 15:29:07 +00:00

39 lines
1,016 B
JavaScript

/**
* @file
* Javascript behaviors for jQuery Word and Counter Counter integration.
*/
(function ($, Drupal) {
'use strict';
/**
* Initialize text field and textarea word and character counter.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformCounter = {
attach: function (context) {
$(context).find('.js-webform-counter').once('webform-counter').each(function () {
var options = {
goal: $(this).attr('data-counter-limit'),
msg: $(this).attr('data-counter-message')
};
// Only word type can be defined, otherwise the counter defaults to
// character counting.
if ($(this).attr('data-counter-type') == 'word') {
options.type = 'word';
}
// Set the target to a div that is appended to end of the input's parent container.
options.target = $('<div></div>');
$(this).parent().append(options.target);
$(this).counter(options);
})
}
};
})(jQuery, Drupal);