Projet

Général

Profil

Révision caf16a48

Ajouté par Assos Assos il y a presque 9 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/themes/bootstrap/js/misc/autocomplete.js
4 4
 * Attaches the autocomplete behavior to all required fields.
5 5
 */
6 6
Drupal.behaviors.autocomplete = {
7
  attach: function (context, settings) {
7
  attach: function (context) {
8
    var $context = $(context);
8 9
    var acdb = [];
9
    $('input.autocomplete', context).once('autocomplete', function () {
10
    $context.find('input.autocomplete').once('autocomplete', function () {
10 11
      var uri = this.value;
11 12
      if (!acdb[uri]) {
12 13
        acdb[uri] = new Drupal.ACDB(uri);
13 14
      }
14
      var $input = $('#' + this.id.substr(0, this.id.length - 13))
15
      var $input = $context.find('#' + this.id.substr(0, this.id.length - 13))
15 16
        .attr('autocomplete', 'OFF')
16 17
        .attr('aria-autocomplete', 'list');
17
      $($input[0].form).submit(Drupal.autocompleteSubmit);
18
      $input
19
        .after($('<span class="element-invisible" aria-live="assertive"></span>')
18
      $context.find($input[0].form).submit(Drupal.autocompleteSubmit);
19
      $input.parents('.form-item')
20
        .attr('role', 'application')
21
        .append($('<span class="element-invisible" aria-live="assertive"></span>')
20 22
          .attr('id', $input.attr('id') + '-autocomplete-aria-live')
21
        );
22
      $input.parent().parent().attr('role', 'application');
23
      new Drupal.jsAC($input, acdb[uri]);
23
      );
24
      new Drupal.jsAC($input, acdb[uri], $context);
24 25
    });
25 26
  }
26 27
};
27 28

  
29
/**
30
 * Prevents the form from submitting if the suggestions popup is open
31
 * and closes the suggestions popup when doing so.
32
 */
33
Drupal.autocompleteSubmit = function () {
34
  return $('.form-autocomplete > .dropdown').each(function () {
35
    this.owner.hidePopup();
36
  }).length == 0;
37
};
38

  
28 39
/**
29 40
 * Highlights a suggestion.
30 41
 */
......
105 116
};
106 117

  
107 118
Drupal.jsAC.prototype.setStatus = function (status) {
108
  var $throbber = $('.glyphicon-refresh', $('#' + this.input.id).parent());
109

  
119
  var $throbber = $(this.input).parent().find('.glyphicon-refresh, .autocomplete-throbber').first();
120
  var throbbingClass = $throbber.is('.autocomplete-throbber') ? 'throbbing' : 'glyphicon-spin';
110 121
  switch (status) {
111 122
    case 'begin':
112
      $throbber.addClass('glyphicon-spin');
123
      $throbber.addClass(throbbingClass);
113 124
      $(this.ariaLive).html(Drupal.t('Searching for matches...'));
114 125
      break;
115 126
    case 'cancel':
116 127
    case 'error':
117 128
    case 'found':
118
      $throbber.removeClass('glyphicon-spin');
129
      $throbber.removeClass(throbbingClass);
119 130
      break;
120 131
  }
121 132
};
122 133

  
134
// Save the previous autocomplete prototype.
135
var oldPrototype = Drupal.jsAC.prototype;
136

  
137
/**
138
 * Override the autocomplete constructor.
139
 */
140
Drupal.jsAC = function ($input, db, $context) {
141
  var ac = this;
142
  this.$context = $context;
143
  this.input = $input[0];
144
  this.ariaLive = $context.find('#' + this.input.id + '-autocomplete-aria-live');
145
  this.db = db;
146
  $input
147
    .keydown(function (event) { return ac.onkeydown(this, event); })
148
    .keyup(function (event) { ac.onkeyup(this, event); })
149
    .blur(function () { ac.hidePopup(); ac.db.cancel(); });
150
};
151

  
152
// Restore the previous prototype.
153
Drupal.jsAC.prototype = oldPrototype;
154

  
123 155
})(jQuery);

Formats disponibles : Unified diff