system.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. (function ($) {
  2. /**
  3. * Show/hide the 'Email site administrator when updates are available' checkbox
  4. * on the install page.
  5. */
  6. Drupal.hideEmailAdministratorCheckbox = function () {
  7. // Make sure the secondary box is shown / hidden as necessary on page load.
  8. if ($('#edit-update-status-module-1').is(':checked')) {
  9. $('.form-item-update-status-module-2').show();
  10. }
  11. else {
  12. $('.form-item-update-status-module-2').hide();
  13. }
  14. // Toggle the display as necessary when the checkbox is clicked.
  15. $('#edit-update-status-module-1').change( function () {
  16. $('.form-item-update-status-module-2').toggle();
  17. });
  18. };
  19. /**
  20. * Internal function to check using Ajax if clean URLs can be enabled on the
  21. * settings page.
  22. *
  23. * This function is not used to verify whether or not clean URLs
  24. * are currently enabled.
  25. */
  26. Drupal.behaviors.cleanURLsSettingsCheck = {
  27. attach: function (context, settings) {
  28. // This behavior attaches by ID, so is only valid once on a page.
  29. // Also skip if we are on an install page, as Drupal.cleanURLsInstallCheck will handle
  30. // the processing.
  31. if (!($('#edit-clean-url').length) || $('#edit-clean-url.install').once('clean-url').length) {
  32. return;
  33. }
  34. var url = settings.basePath + 'admin/config/search/clean-urls/check';
  35. $.ajax({
  36. url: location.protocol + '//' + location.host + url,
  37. dataType: 'json',
  38. success: function () {
  39. // Check was successful. Redirect using a "clean URL". This will force the form that allows enabling clean URLs.
  40. location = settings.basePath +"admin/config/search/clean-urls";
  41. }
  42. });
  43. }
  44. };
  45. /**
  46. * Internal function to check using Ajax if clean URLs can be enabled on the
  47. * install page.
  48. *
  49. * This function is not used to verify whether or not clean URLs
  50. * are currently enabled.
  51. */
  52. Drupal.cleanURLsInstallCheck = function () {
  53. var url = location.protocol + '//' + location.host + Drupal.settings.basePath + 'admin/config/search/clean-urls/check';
  54. // Submit a synchronous request to avoid database errors associated with
  55. // concurrent requests during install.
  56. $.ajax({
  57. async: false,
  58. url: url,
  59. dataType: 'json',
  60. success: function () {
  61. // Check was successful.
  62. $('#edit-clean-url').attr('value', 1);
  63. }
  64. });
  65. };
  66. /**
  67. * When a field is filled out, apply its value to other fields that will likely
  68. * use the same value. In the installer this is used to populate the
  69. * administrator e-mail address with the same value as the site e-mail address.
  70. */
  71. Drupal.behaviors.copyFieldValue = {
  72. attach: function (context, settings) {
  73. for (var sourceId in settings.copyFieldValue) {
  74. $('#' + sourceId, context).once('copy-field-values').bind('blur', function () {
  75. // Get the list of target fields.
  76. var targetIds = settings.copyFieldValue[sourceId];
  77. // Add the behavior to update target fields on blur of the primary field.
  78. for (var delta in targetIds) {
  79. var targetField = $('#' + targetIds[delta]);
  80. if (targetField.val() == '') {
  81. targetField.val(this.value);
  82. }
  83. }
  84. });
  85. }
  86. }
  87. };
  88. /**
  89. * Show/hide custom format sections on the regional settings page.
  90. */
  91. Drupal.behaviors.dateTime = {
  92. attach: function (context, settings) {
  93. for (var fieldName in settings.dateTime) {
  94. if (settings.dateTime.hasOwnProperty(fieldName)) {
  95. (function (fieldSettings, fieldName) {
  96. var source = '#edit-' + fieldName;
  97. var suffix = source + '-suffix';
  98. // Attach keyup handler to custom format inputs.
  99. $('input' + source, context).once('date-time').keyup(function () {
  100. var input = $(this);
  101. var url = fieldSettings.lookup + (/\?/.test(fieldSettings.lookup) ? '&format=' : '?format=') + encodeURIComponent(input.val());
  102. $.getJSON(url, function (data) {
  103. $(suffix).empty().append(' ' + fieldSettings.text + ': <em>' + data + '</em>');
  104. });
  105. });
  106. })(settings.dateTime[fieldName], fieldName);
  107. }
  108. }
  109. }
  110. };
  111. /**
  112. * Show/hide settings for page caching depending on whether page caching is
  113. * enabled or not.
  114. */
  115. Drupal.behaviors.pageCache = {
  116. attach: function (context, settings) {
  117. $('#edit-cache-0', context).change(function () {
  118. $('#page-compression-wrapper').hide();
  119. $('#cache-error').hide();
  120. });
  121. $('#edit-cache-1', context).change(function () {
  122. $('#page-compression-wrapper').show();
  123. $('#cache-error').hide();
  124. });
  125. $('#edit-cache-2', context).change(function () {
  126. $('#page-compression-wrapper').show();
  127. $('#cache-error').show();
  128. });
  129. }
  130. };
  131. })(jQuery);