panels-base.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @file
  3. * Implement basic methods required by all of panels.
  4. */
  5. (function ($) {
  6. Drupal.Panels = Drupal.Panels || {};
  7. Drupal.Panels.changed = function(item) {
  8. if (!item.is('.changed')) {
  9. item.addClass('changed');
  10. item.find('div.grabber span.text').append(' <span class="star">*</span> ');
  11. }
  12. };
  13. Drupal.Panels.AddContentModalQuickFilter = function() {
  14. var input_field = $('.panels-add-content-modal input[name=quickfilter]');
  15. input_field.data.panelsAddContentModalQuickFilter = {
  16. keyupTimeout: false,
  17. filter: function(e) {
  18. if (this.val().length) {
  19. var search_expression = this.val().toLowerCase();
  20. $('.panels-add-content-modal .panels-section-columns .content-type-button').each(function(i, elem) {
  21. if ($(elem).text().toLowerCase().search(search_expression) > -1) {
  22. $(elem).show();
  23. }
  24. else {
  25. $(elem).hide();
  26. }
  27. });
  28. }
  29. else {
  30. $('.panels-add-content-modal .panels-section-columns .content-type-button').show();
  31. }
  32. }
  33. }
  34. // Use timeout to reduce the iteration over the DOM tree.
  35. input_field.bind('keyup.AddContentModalQuickFilter', jQuery.proxy(function(e){
  36. var filter = $(this).data.panelsAddContentModalQuickFilter;
  37. if (filter.keyupTimeout) {
  38. window.clearTimeout(filter.timeout);
  39. filter.keyupTimeout = false;
  40. }
  41. // If there's only one item left and enter is hit select it right away.
  42. if (e.keyCode == 13 && $('.panels-add-content-modal .panels-section-columns .content-type-button:visible').length == 1) {
  43. $('.panels-add-content-modal .panels-section-columns .content-type-button:visible a').trigger('click');
  44. }
  45. else {
  46. filter.keyupTimeout = window.setTimeout(jQuery.proxy(filter.filter, this), 200);
  47. }
  48. }, input_field));
  49. input_field.focus();
  50. };
  51. Drupal.Panels.restripeTable = function(table) {
  52. // :even and :odd are reversed because jquery counts from 0 and
  53. // we count from 1, so we're out of sync.
  54. $('tbody tr:not(:hidden)', $(table))
  55. .removeClass('even')
  56. .removeClass('odd')
  57. .filter(':even')
  58. .addClass('odd')
  59. .end()
  60. .filter(':odd')
  61. .addClass('even');
  62. };
  63. })(jQuery);