[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/token/ -> token.js (source)

   1  
   2  (function ($) {
   3  
   4  Drupal.behaviors.tokenTree = function() {
   5    $('table.token-tree').each(function() {
   6      $(this).treeTable();
   7    });
   8  };
   9  
  10  Drupal.behaviors.tokenInsert = function() {
  11    // Keep track of which textfield was last selected/focused.
  12    $('textarea, input[type="text"]').focus(function() {
  13      Drupal.settings.tokenFocusedField = this;
  14    });
  15  
  16    $('.token-click-insert .token-key').each(function() {
  17      var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function(){
  18        if (typeof Drupal.settings.tokenFocusedField == 'undefined') {
  19          alert(Drupal.t('First click a text field to insert your tokens into.'));
  20        }
  21        else {
  22          var myField = Drupal.settings.tokenFocusedField;
  23          var myValue = $(this).text();
  24  
  25          //IE support
  26          if (document.selection) {
  27            myField.focus();
  28            sel = document.selection.createRange();
  29            sel.text = myValue;
  30          }
  31  
  32          //MOZILLA/NETSCAPE support
  33          else if (myField.selectionStart || myField.selectionStart == '0') {
  34            var startPos = myField.selectionStart;
  35            var endPos = myField.selectionEnd;
  36            myField.value = myField.value.substring(0, startPos)
  37                          + myValue
  38                          + myField.value.substring(endPos, myField.value.length);
  39          } else {
  40            myField.value += myValue;
  41          }
  42  
  43          $('html,body').animate({scrollTop: $(myField).offset().top}, 500);
  44        }
  45        return false;
  46      });
  47      $(this).html(newThis);
  48    });
  49  };
  50  
  51  })(jQuery);


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7