JAVASCRIPT 18
Token.js Guest on 23rd September 2020 05:59:35 PM
  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);

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.