Projet

Général

Profil

Paste
Télécharger (2,28 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / panels / js / panels-base.js @ fc3d89c3

1
/**
2
 * @file
3
 * Implement basic methods required by all of panels.
4
 */
5

    
6
(function ($) {
7
  Drupal.Panels = Drupal.Panels || {};
8

    
9
  Drupal.Panels.changed = function(item) {
10
    if (!item.is('.changed')) {
11
      item.addClass('changed');
12
      item.find('div.grabber span.text').append(' <span class="star">*</span> ');
13
    }
14
  };
15

    
16
  Drupal.Panels.AddContentModalQuickFilter = function() {
17
    var input_field = $('.panels-add-content-modal input[name=quickfilter]');
18
    input_field.data.panelsAddContentModalQuickFilter = {
19
      keyupTimeout: false,
20
      filter: function(e) {
21
        if (this.val().length) {
22
          var search_expression = this.val().toLowerCase();
23
          $('.panels-add-content-modal .panels-section-columns .content-type-button').each(function(i, elem) {
24
            if ($(elem).text().toLowerCase().search(search_expression) > -1) {
25
              $(elem).show();
26
            }
27
            else {
28
              $(elem).hide();
29
            }
30
          });
31
        }
32
        else {
33
          $('.panels-add-content-modal .panels-section-columns .content-type-button').show();
34
        }
35
      }
36
    }
37
    // Use timeout to reduce the iteration over the DOM tree.
38
    input_field.bind('keyup.AddContentModalQuickFilter', jQuery.proxy(function(e){
39
      var filter = $(this).data.panelsAddContentModalQuickFilter;
40
      if (filter.keyupTimeout) {
41
        window.clearTimeout(filter.timeout);
42
        filter.keyupTimeout = false;
43
      }
44
      // If there's only one item left and enter is hit select it right away.
45
      if (e.keyCode == 13 && $('.panels-add-content-modal .panels-section-columns .content-type-button:visible').length == 1) {
46
        $('.panels-add-content-modal .panels-section-columns .content-type-button:visible a').trigger('click');
47
      }
48
      else {
49
        filter.keyupTimeout = window.setTimeout(jQuery.proxy(filter.filter, this), 200);
50
      }
51
    }, input_field));
52
    input_field.focus();
53
  };
54

    
55
  Drupal.Panels.restripeTable = function(table) {
56
    // :even and :odd are reversed because jquery counts from 0 and
57
    // we count from 1, so we're out of sync.
58
    $('tbody tr:not(:hidden)', $(table))
59
      .removeClass('even')
60
      .removeClass('odd')
61
      .filter(':even')
62
        .addClass('odd')
63
      .end()
64
      .filter(':odd')
65
        .addClass('even');
66
  };
67
})(jQuery);