6 Drupal.behaviors.tokenTree = {
7 attach: function (context, settings) {
8 $('table.token-tree', context).once('token-tree').each(function () {
9 $(this).treetable({ expandable: true });
14 Drupal.behaviors.tokenInsert = {
15 attach: function (context, settings) {
16 // Keep track of which textfield was last selected/focused.
17 $('textarea, input[type="text"]', context).focus(function () {
18 drupalSettings.tokenFocusedField = this;
21 $('.token-click-insert .token-key', context).once('token-click-insert').each(function () {
22 var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function () {
23 if (typeof drupalSettings.tokenFocusedField == 'undefined') {
24 alert(Drupal.t('First click a text field to insert your tokens into.'));
27 var myField = drupalSettings.tokenFocusedField;
28 var myValue = $(this).text();
31 if (document.selection) {
33 var sel = document.selection.createRange();
37 // MOZILLA/NETSCAPE support.
38 else if (myField.selectionStart || myField.selectionStart === '0') {
39 var startPos = myField.selectionStart;
40 var endPos = myField.selectionEnd;
41 myField.value = myField.value.substring(0, startPos)
43 + myField.value.substring(endPos, myField.value.length);
46 myField.value += myValue;
49 $('html,body').animate({scrollTop: $(myField).offset().top}, 500);
53 $(this).html(newThis);
58 })(jQuery, drupalSettings);