62 lines
1.6 KiB
JavaScript
62 lines
1.6 KiB
JavaScript
/**
|
|
* @file
|
|
* Javascript behaviors for admin pages.
|
|
*/
|
|
|
|
(function ($, Drupal) {
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Filter webform autocomplete handler.
|
|
*
|
|
* @type {Drupal~behavior}
|
|
*/
|
|
Drupal.behaviors.webformFilterAutocomplete = {
|
|
attach: function (context) {
|
|
$('.webform-filter-form input.form-autocomplete', context).once('webform-autocomplete')
|
|
.each(function () {
|
|
// If input value is an autocomplete match, reset the input to its
|
|
// default value.
|
|
if (/\(([^)]+)\)$/.test(this.value)) {
|
|
this.value = this.defaultValue;
|
|
}
|
|
|
|
// From: http://stackoverflow.com/questions/5366068/jquery-ui-autocomplete-submit-onclick-result
|
|
$(this).bind('autocompleteselect', function (event, ui) {
|
|
if (ui.item) {
|
|
$(this).val(ui.item.value);
|
|
this.form.submit();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Allow table rows to be hyperlinked.
|
|
*
|
|
* @type {Drupal~behavior}
|
|
*/
|
|
Drupal.behaviors.webformTableRowHref = {
|
|
attach: function (context) {
|
|
// Only attach the click event handler to the entire table and determine
|
|
// which row triggers the event.
|
|
$('.webform-results__table', context).once('webform-results-table').click(function (event) {
|
|
if (event.target.tagName == 'A' || event.target.tagName == 'BUTTON') {
|
|
return true;
|
|
}
|
|
|
|
var $tr = $(event.target).parents('tr[data-webform-href]');
|
|
if (!$tr.length) {
|
|
return true;
|
|
}
|
|
|
|
window.location = $tr.attr('data-webform-href');
|
|
return false;
|
|
});
|
|
}
|
|
};
|
|
|
|
})(jQuery, Drupal);
|