1
|
|
2
|
(function ($) {
|
3
|
|
4
|
Drupal.behaviors.tokenTree = {
|
5
|
attach: function (context, settings) {
|
6
|
$('table.token-tree', context).once('token-tree', function () {
|
7
|
$(this).treeTable();
|
8
|
});
|
9
|
}
|
10
|
};
|
11
|
|
12
|
Drupal.behaviors.tokenDialog = {
|
13
|
attach: function (context, settings) {
|
14
|
$('a.token-dialog', context).once('token-dialog').click(function() {
|
15
|
var url = $(this).attr('href');
|
16
|
var dialog = $('<div style="display: none" class="loading">' + Drupal.t('Loading token browser...') + '</div>').appendTo('body');
|
17
|
|
18
|
|
19
|
var data = {};
|
20
|
data['ajax_page_state[theme]'] = Drupal.settings.ajaxPageState.theme;
|
21
|
data['ajax_page_state[theme_token]'] = Drupal.settings.ajaxPageState.theme_token;
|
22
|
|
23
|
dialog.dialog({
|
24
|
title: $(this).attr('title') || Drupal.t('Available tokens'),
|
25
|
width: 700,
|
26
|
close: function(event, ui) {
|
27
|
dialog.remove();
|
28
|
}
|
29
|
});
|
30
|
|
31
|
dialog.load(
|
32
|
url,
|
33
|
data,
|
34
|
function (responseText, textStatus, XMLHttpRequest) {
|
35
|
dialog.removeClass('loading');
|
36
|
}
|
37
|
);
|
38
|
|
39
|
return false;
|
40
|
});
|
41
|
}
|
42
|
}
|
43
|
|
44
|
Drupal.behaviors.tokenInsert = {
|
45
|
attach: function (context, settings) {
|
46
|
|
47
|
$('textarea, input[type="text"]', context).focus(function() {
|
48
|
Drupal.settings.tokenFocusedField = this;
|
49
|
});
|
50
|
|
51
|
$('.token-click-insert .token-key', context).once('token-click-insert', function() {
|
52
|
var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function(){
|
53
|
if (typeof Drupal.settings.tokenFocusedField == 'undefined') {
|
54
|
alert(Drupal.t('First click a text field to insert your tokens into.'));
|
55
|
}
|
56
|
else {
|
57
|
var myField = Drupal.settings.tokenFocusedField;
|
58
|
var myValue = $(this).text();
|
59
|
|
60
|
|
61
|
if (document.selection) {
|
62
|
myField.focus();
|
63
|
sel = document.selection.createRange();
|
64
|
sel.text = myValue;
|
65
|
}
|
66
|
|
67
|
|
68
|
else if (myField.selectionStart || myField.selectionStart == '0') {
|
69
|
var startPos = myField.selectionStart;
|
70
|
var endPos = myField.selectionEnd;
|
71
|
myField.value = myField.value.substring(0, startPos)
|
72
|
+ myValue
|
73
|
+ myField.value.substring(endPos, myField.value.length);
|
74
|
} else {
|
75
|
myField.value += myValue;
|
76
|
}
|
77
|
|
78
|
$('html,body').animate({scrollTop: $(myField).offset().top}, 500);
|
79
|
}
|
80
|
return false;
|
81
|
});
|
82
|
$(this).html(newThis);
|
83
|
});
|
84
|
}
|
85
|
};
|
86
|
|
87
|
})(jQuery);
|