Projet

Général

Profil

Paste
Télécharger (1,32 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / token_insert / token_insert_text / token_insert_text.js @ 5721e759

1
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */
2
/*global Drupal:true, jQuery: true*/
3
/**
4
 * Behavior to add "Insert" buttons.
5
 */
6
(function ($, Drupal) {
7
  "use strict";
8
  Drupal.behaviors.TokenInsertText = {
9
    attach: function(context) {
10
      function insert (e){
11
        var $self = $(this);
12
        e.preventDefault();
13
        var token = $self.text();
14
        var id = $self.closest('.token-insert-text-table').attr('id');
15
        $('#' + Drupal.settings.token_insert.tables[id]).insertAtCursor(token);
16
      }
17
      function bindInsert(id) {
18
        $(context).find("#" + key).find('.token-insert-table .token-key').once('token-insert-table', function() {
19
          var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(insert);
20
          $(this).html(newThis);
21
        });
22
      }
23

    
24
      // Add the click handler to the insert button.
25
      if (typeof(Drupal.settings.token_insert) !== 'undefined') {
26
        for (var key in Drupal.settings.token_insert.tables) {
27
          if (Drupal.settings.token_insert.tables.hasOwnProperty(key)) {
28
            bindInsert(key, context);
29
          }
30
        }
31
      }
32
    }
33
  };
34
})(jQuery, Drupal);