field_group.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. (function ($) {
  2. 'use strict';
  3. /**
  4. * Drupal FieldGroup object.
  5. */
  6. Drupal.FieldGroup = Drupal.FieldGroup || {};
  7. Drupal.FieldGroup.Effects = Drupal.FieldGroup.Effects || {};
  8. Drupal.FieldGroup.groupWithfocus = null;
  9. Drupal.FieldGroup.setGroupWithfocus = function (element) {
  10. element.css({display: 'block'});
  11. Drupal.FieldGroup.groupWithfocus = element;
  12. };
  13. /**
  14. * Behaviors.
  15. */
  16. Drupal.behaviors.fieldGroup = {
  17. attach: function (context, settings) {
  18. settings.field_group = settings.field_group || drupalSettings.field_group;
  19. if (typeof settings.field_group === 'undefined') {
  20. return;
  21. }
  22. // Execute all of them.
  23. $.each(Drupal.FieldGroup.Effects, function (func) {
  24. // We check for a wrapper function in Drupal.field_group as
  25. // alternative for dynamic string function calls.
  26. var type = func.toLowerCase().replace('process', '');
  27. if (typeof settings.field_group[type] !== 'undefined' && $.isFunction(this.execute)) {
  28. this.execute(context, settings, settings.field_group[type]);
  29. }
  30. });
  31. // Add a new ID to each fieldset.
  32. $('.group-wrapper fieldset').each(function () {
  33. // Tats bad, but we have to keep the actual id to prevent layouts to break.
  34. var fieldgroupID = 'field_group-' + $(this).attr('id') + ' ' + $(this).attr('id');
  35. $(this).attr('id', fieldgroupID);
  36. });
  37. // Set the hash in url to remember last userselection.
  38. $('.group-wrapper ul li').each(function () {
  39. var fieldGroupNavigationListIndex = $(this).index();
  40. $(this).children('a').click(function () {
  41. var fieldset = $('.group-wrapper fieldset').get(fieldGroupNavigationListIndex);
  42. // Grab the first id, holding the wanted hashurl.
  43. var hashUrl = $(fieldset).attr('id').replace(/^field_group-/, '').split(' ')[0];
  44. window.location.hash = hashUrl;
  45. });
  46. });
  47. }
  48. };
  49. })(jQuery);