1/** 2 * @file 3 * JavaScript behaviors for terms of service. 4 */ 5 6(function ($, Drupal, once) { 7 8 'use strict'; 9 10 // @see http://api.jqueryui.com/dialog/ 11 Drupal.webform = Drupal.webform || {}; 12 Drupal.webform.termsOfServiceModal = Drupal.webform.termsOfServiceModal || {}; 13 Drupal.webform.termsOfServiceModal.options = Drupal.webform.termsOfServiceModal.options || {}; 14 15 /** 16 * Initialize terms of service element. 17 * 18 * @type {Drupal~behavior} 19 */ 20 Drupal.behaviors.webformTermsOfService = { 21 attach: function (context) { 22 $(once('webform-terms-of-service', '.js-form-type-webform-terms-of-service', context)).each(function () { 23 var $element = $(this); 24 var $a = $element.find('label a'); 25 var $details = $element.find('.webform-terms-of-service-details'); 26 27 var type = $element.attr('data-webform-terms-of-service-type'); 28 29 // Initialize the modal. 30 if (type === 'modal') { 31 // Move details title to attribute. 32 var $title = $element.find('.webform-terms-of-service-details--title'); 33 if ($title.length) { 34 $details.attr('title', $title.text()); 35 $title.remove(); 36 } 37 38 var options = $.extend({ 39 modal: true, 40 autoOpen: false, 41 minWidth: 600, 42 maxWidth: 800 43 }, Drupal.webform.termsOfServiceModal.options); 44 $details.dialog(options); 45 } 46 47 // Add aria-* attributes. 48 if (type !== 'modal') { 49 $a.attr({ 50 'aria-expanded': false, 51 'aria-controls': $details.attr('id') 52 }); 53 } 54 55 // Set event handlers. 56 $a.on('click', openDetails) 57 .on('keydown', function (event) { 58 // Space or Return. 59 if (event.which === 32 || event.which === 13) { 60 openDetails(event); 61 } 62 }); 63 64 function openDetails(event) { 65 if (type === 'modal') { 66 $details.dialog('open'); 67 } 68 else { 69 var expanded = ($a.attr('aria-expanded') === 'true'); 70 71 // Toggle `aria-expanded` attributes on link. 72 $a.attr('aria-expanded', !expanded); 73 74 // Toggle details. 75 $details[expanded ? 'slideUp' : 'slideDown'](); 76 } 77 event.preventDefault(); 78 } 79 }); 80 } 81 }; 82 83})(jQuery, Drupal, once);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.