draggableviews_list.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * @file
  3. * Adds draggable functionality to the html list display of the view.
  4. */
  5. (function ($) {
  6. Drupal.behaviors.draggableViews = {
  7. attach: function (context, settings) {
  8. $('.views-form .' + Drupal.settings.draggableviews_row_class + ':not(.draggableviews-processed)', context)
  9. // Add class for theming.
  10. .addClass('draggableviews-processed')
  11. // Add sortable effect.
  12. .sortable({
  13. update: function(event, ui) {
  14. $( ".draggableviews-weight" ).each(function (i, Val) {
  15. $(this).val(i);
  16. });
  17. if (!$(this).hasClass('draggableviews-changed')) {
  18. // If view is not ajaxified.
  19. if (!Drupal.settings.draggableviews_ajax) {
  20. $('<div class="draggableviews-changed-warning messages warning">' + Drupal.t('Changes made in this list will not be saved until the form is submitted.') + '</div>')
  21. .insertBefore($(this).parents('form div.item-list')).hide().fadeIn('slow');
  22. $(this).addClass('draggableviews-changed');
  23. }
  24. else {
  25. // If view ajaxified.
  26. $('<div class="draggableviews-changed-notice messages warning">' + Drupal.t('Order of the list has been changed.') + '</div>')
  27. .insertBefore($(this).parents('form div.item-list')).hide().fadeIn('slow').delay(3000).fadeOut('slow');
  28. $(this).addClass('draggableviews-changed');
  29. }
  30. }
  31. // If Ajax enabled, we should submit the form.
  32. if (Drupal.settings.draggableviews_ajax) {
  33. $(this).parent().parent().find('#edit-submit').trigger('mousedown');
  34. }
  35. },
  36. containment: 'parent',
  37. cursor: 'move'
  38. });
  39. if (Drupal.settings.draggableviews_ajax) {
  40. $('.views-form .' + Drupal.settings.draggableviews_row_class).parent().parent().find('#edit-submit').hide();
  41. }
  42. }
  43. }
  44. })(jQuery);