tripal_panes.admin.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * Override the field UI's default behavior
  3. * @param $
  4. */
  5. (function($) {
  6. Drupal.behaviors.tripalPane = {
  7. attach: function (context, settings) {
  8. Drupal.behaviors.fieldUIDisplayOverview = {};
  9. rearrangeRegion ();
  10. }
  11. };
  12. function rearrangeRegion () {
  13. // For each field, make sure the selected value matches the region where it resides
  14. $('#field-display-overview tr.tabledrag-leaf').each(function () {
  15. // ID
  16. var id = $(this).attr('id');
  17. // Get the region
  18. var region = getRegion (this).attr('class');
  19. var regex = /region-title region-(.+)-title/;
  20. var match = regex.exec(region);
  21. var region_id = match[1].replace('-', '_');
  22. var select = $(this).find('div.form-item-fields-' + id + '-region select');
  23. $(select).children().each(function() {
  24. if ($(this).val() == region_id) {
  25. $(this).attr('selected', 'true');
  26. } else {
  27. $(this).attr('selected', null);
  28. }
  29. });
  30. });
  31. }
  32. function getRegion (field) {
  33. var previous = $(field).prev();
  34. var region = null;
  35. if ($(previous).hasClass('region-title')) {
  36. region = previous;
  37. } else {
  38. region = getRegion (previous);
  39. }
  40. return region;
  41. }
  42. })(jQuery);