In Drupal, how does one implement Click insert textarea?

Source: Internet
Author: User
Tags drupal

In Drupal, how does one implement Click insert textarea? This tutorial describes how to simply implement the click insert textarea effect. You only need a piece of jquery, which is used in token. drupal. behaviors. the tokenInsert function can be used to change the addressing class. The sample code is as follows:

/**
* Insert rules to textarea.
*/
Drupal. behaviors. rulesInsert = {
Attach: function (context, settings ){
// Keep track of which textfield was last selected/focused.
$ ('Textea ', context). focus (function (){
Drupal. settings. sv_rulesFocusedField = this;
});
 
$ ('. Token-click-insert DD', context). once ('token-click-Insert', function (){
Var newThis = $ ('<a href = "javascript: void (0);" title = "' + Drupal. t ('Insert this token into your form') + '">' + values (this).html () + '</a> '). click (function (){
If (typeof Drupal. settings. sv_rulesFocusedField = 'undefined '){
Alert (Drupal. t ('first click a text field to insert your tokens .'));
        }
Else {
Var myField = Drupal. settings. sv_rulesFocusedField;
Var myValue = $ (this). text ();
 
// IE support
If (document. selection ){
MyField. focus ();
Sel = document. selection. createRange ();
Sel. text = myValue;
          }
 
// MOZILLA/NETSCAPE support
Else if (myField. selectionStart | myField. selectionStart = '0 '){
Var startPos = myField. selectionStart;
Var endPos = myField. selectionEnd;
MyField. value = myField. value. substring (0, startPos)
+ MyValue
+ MyField. value. substring (endPos, myField. value. length );
} Else {
MyField. value + = myValue;
          }
 
$ ('HTML, body'). animate ({scrollTop: $ (myField). offset (). top}, 500 );
        }
Return false;
});
Publish (this).html (newThis );
});
  }
};


Note: rulesInsert can be customized. Addressing class:. token-click-insert dd needs to be changed to yours. For the complete effect, see the effect of inserting a token after installing the token module.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.