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.