Révision 5721e759
Ajouté par Assos Assos il y a presque 10 ans
drupal7/sites/all/modules/token_insert/token_insert_wysiwyg/plugins/token_insert_wysiwyg/token_insert_wysiwyg.js | ||
---|---|---|
1 |
// $Id |
|
2 |
(function ($) { |
|
3 |
function hideShowFieldset(buttonid, action) { |
|
4 |
var $fieldset = $('#' + buttonid).closest('fieldset'); |
|
5 |
$fieldset[action](); |
|
6 |
} |
|
1 |
/*jshint strict:true, browser:true, curly:true, eqeqeq:true, expr:true, forin:true, latedef:true, newcap:true, noarg:true, trailing: true, undef:true, unused:true */ |
|
2 |
/*global Drupal:true, jQuery: true*/ |
|
3 |
(function ($, Drupal) { |
|
4 |
"use strict"; |
|
5 |
function hideShowFieldset(buttonid, action) { |
|
6 |
var $fieldset = $('#' + buttonid).closest('fieldset'); |
|
7 |
$fieldset[action](); |
|
8 |
} |
|
7 | 9 |
|
8 |
/** |
|
9 |
* Wysiwyg plugin button implementation for token_insert plugin. |
|
10 |
*/ |
|
11 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg = { |
|
12 |
/** |
|
13 |
* Return whether the passed node belongs to this plugin. |
|
14 |
* |
|
15 |
* @param node |
|
16 |
* The currently focused DOM element in the editor content. |
|
17 |
*/ |
|
18 |
isNode: function(node) { |
|
19 |
return ($(node).is('img.token_insert_wysiwyg-token_insert_wysiwyg')); |
|
20 |
}, |
|
10 |
var dialogs = {}; |
|
21 | 11 |
|
22 | 12 |
/** |
23 |
* Execute the button. |
|
24 |
* |
|
25 |
* @param data |
|
26 |
* An object containing data about the current selection: |
|
27 |
* - format: 'html' when the passed data is HTML content, 'text' when the |
|
28 |
* passed data is plain-text content. |
|
29 |
* - node: When 'format' is 'html', the focused DOM element in the editor. |
|
30 |
* - content: The textual representation of the focused/selected editor |
|
31 |
* content. |
|
32 |
* @param settings |
|
33 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
34 |
* @param instanceId |
|
35 |
* The ID of the current editor instance. |
|
13 |
* Wysiwyg plugin button implementation for token_insert plugin. |
|
36 | 14 |
*/ |
37 |
invoke: function(data, settings, instanceId) { |
|
38 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg.insert_form(data, settings, instanceId); |
|
39 |
}, |
|
40 |
|
|
41 |
|
|
42 |
insert_form: function (data, settings, instanceId) { |
|
43 |
form_id = Drupal.settings.token_insert_wysiwyg.current_form; |
|
15 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg = { |
|
16 |
/** |
|
17 |
* Return whether the passed node belongs to this plugin. |
|
18 |
* |
|
19 |
* @param node |
|
20 |
* The currently focused DOM element in the editor content. |
|
21 |
*/ |
|
22 |
isNode: function(node) { |
|
23 |
return ($(node).is('img.token_insert_wysiwyg-token_insert_wysiwyg')); |
|
24 |
}, |
|
44 | 25 |
|
45 |
// Location, where to fetch the dialog. |
|
46 |
var aurl = Drupal.settings.basePath + 'index.php?q=token_insert_wysiwyg/insert/' + form_id; |
|
47 |
dialogdiv = jQuery('<div id="token-insert-dialog"></div>'); |
|
48 |
dialogdiv.load(aurl + " #token-insert-wysiwyg-form", function(){ |
|
49 |
var dialogClose = function () { |
|
50 |
try { |
|
51 |
dialogdiv.dialog('destroy').remove(); |
|
52 |
} catch (e) {}; |
|
53 |
}; |
|
54 |
btns = {}; |
|
55 |
btns[Drupal.t('Insert token')] = function () { |
|
26 |
/** |
|
27 |
* Execute the button. |
|
28 |
* |
|
29 |
* @param data |
|
30 |
* An object containing data about the current selection: |
|
31 |
* - format: 'html' when the passed data is HTML content, 'text' when the |
|
32 |
* passed data is plain-text content. |
|
33 |
* - node: When 'format' is 'html', the focused DOM element in the editor. |
|
34 |
* - content: The textual representation of the focused/selected editor |
|
35 |
* content. |
|
36 |
* @param settings |
|
37 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
38 |
* @param instanceId |
|
39 |
* The ID of the current editor instance. |
|
40 |
*/ |
|
41 |
invoke: function(data, settings, instanceId) { |
|
42 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg.insert_form(data, settings, instanceId); |
|
43 |
}, |
|
56 | 44 |
|
57 |
var token = dialogdiv.contents().find('#edit-insert option:selected').val(); |
|
58 |
var editor_id = instanceId; |
|
59 | 45 |
|
60 |
token = '[' + token + ']'; |
|
61 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg.insertIntoEditor(token, editor_id); |
|
62 |
jQuery(this).dialog("close"); |
|
46 |
insert_form: function (data, settings, instanceId) { |
|
47 |
if (!dialogs[instanceId]) { |
|
48 |
var id = 'token-insert-dialog-' + instanceId; |
|
49 |
var $dialogdiv = $('<div id="' + id + '"></div>').appendTo('body'); |
|
50 |
var ajax_settings = { |
|
51 |
url: Drupal.settings.basePath + 'token_insert_wysiwyg/insert/' + instanceId, |
|
52 |
event: 'dialog.token-insert-wysiwyg', |
|
53 |
method: 'html' |
|
54 |
}; |
|
55 |
new Drupal.ajax(id, $dialogdiv[0], ajax_settings); |
|
56 |
$dialogdiv.trigger(ajax_settings.event); |
|
57 |
} |
|
58 |
else { |
|
59 |
dialogs[instanceId].dialog("open"); |
|
60 |
} |
|
61 |
}, |
|
63 | 62 |
|
64 |
}; |
|
63 |
insertIntoEditor: function (token, editor_id) { |
|
64 |
Drupal.wysiwyg.instances[editor_id].insert(token); |
|
65 |
}, |
|
65 | 66 |
|
66 |
btns[Drupal.t('Cancel')] = function () { |
|
67 |
jQuery(this).dialog("close"); |
|
68 |
}; |
|
67 |
/** |
|
68 |
* Prepare all plain-text contents of this plugin with HTML representations. |
|
69 |
* |
|
70 |
* Optional; only required for "inline macro tag-processing" plugins. |
|
71 |
* |
|
72 |
* @param content |
|
73 |
* The plain-text contents of a textarea. |
|
74 |
* @param settings |
|
75 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
76 |
* @param instanceId |
|
77 |
* The ID of the current editor instance. |
|
78 |
*/ |
|
79 |
attach: function(content, settings) { |
|
80 |
content = content.replace(/<!--token_insert_wysiwyg-->/g, this._getPlaceholder(settings)); |
|
81 |
// hide the token_insert_text fieldset when wysiwyg is enabled, |
|
82 |
// token_insert_test won't work then, users should use the |
|
83 |
// wysiwyg plugin instead. |
|
84 |
if (typeof Drupal.settings.token_insert !== 'undefined') { |
|
85 |
for (var index in Drupal.settings.token_insert.buttons) { |
|
86 |
if (Drupal.settings.token_insert.buttons.hasOwnProperty(index)) { |
|
87 |
hideShowFieldset(index, 'hide'); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
return content; |
|
92 |
}, |
|
69 | 93 |
|
70 |
dialogdiv.dialog({ |
|
71 |
modal: true, |
|
72 |
autoOpen: false, |
|
73 |
closeOnEscape: true, |
|
74 |
resizable: false, |
|
75 |
draggable: false, |
|
76 |
autoresize: true, |
|
77 |
namespace: 'jquery_ui_dialog_default_ns', |
|
78 |
dialogClass: 'jquery_ui_dialog-dialog', |
|
79 |
title: Drupal.t('Insert token'), |
|
80 |
buttons: btns, |
|
81 |
width: 700, |
|
82 |
close: dialogClose |
|
83 |
}); |
|
84 |
dialogdiv.dialog("open"); |
|
85 |
}); |
|
86 |
}, |
|
87 |
|
|
88 |
insertIntoEditor: function (token, editor_id) { |
|
89 |
Drupal.wysiwyg.instances[editor_id].insert(token); |
|
90 |
}, |
|
94 |
/** |
|
95 |
* Process all HTML placeholders of this plugin with plain-text contents. |
|
96 |
* |
|
97 |
* Optional; only required for "inline macro tag-processing" plugins. |
|
98 |
* |
|
99 |
* @param content |
|
100 |
* The HTML content string of the editor. |
|
101 |
* @param settings |
|
102 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
103 |
* @param instanceId |
|
104 |
* The ID of the current editor instance. |
|
105 |
*/ |
|
106 |
detach: function(content) { |
|
107 |
var $content = $('<div>' + content + '</div>'); |
|
108 |
// show the token_insert_text fieldset when wysiwyg is disabled |
|
109 |
if (typeof Drupal.settings.token_insert !== 'undefined') { |
|
110 |
for (var index in Drupal.settings.token_insert.buttons) { |
|
111 |
if (Drupal.settings.token_insert.buttons.hasOwnProperty(index)) { |
|
112 |
hideShowFieldset(index, 'show'); |
|
113 |
} |
|
114 |
} |
|
115 |
} |
|
116 |
return $content.html(); |
|
117 |
}, |
|
91 | 118 |
|
92 |
/** |
|
93 |
* Prepare all plain-text contents of this plugin with HTML representations. |
|
94 |
* |
|
95 |
* Optional; only required for "inline macro tag-processing" plugins. |
|
96 |
* |
|
97 |
* @param content |
|
98 |
* The plain-text contents of a textarea. |
|
99 |
* @param settings |
|
100 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
101 |
* @param instanceId |
|
102 |
* The ID of the current editor instance. |
|
103 |
*/ |
|
104 |
attach: function(content, settings, instanceId) { |
|
105 |
content = content.replace(/<!--token_insert_wysiwyg-->/g, this._getPlaceholder(settings)); |
|
106 |
// hide the token_insert_text fieldset when wysiwyg is enabled, |
|
107 |
// token_insert_test won't work then, users should use the |
|
108 |
// wysiwyg plugin instead. |
|
109 |
if (typeof Drupal.settings.token_insert !== 'undefined') { |
|
110 |
$.each(Drupal.settings.token_insert.buttons, function(index, fieldid) { |
|
111 |
hideShowFieldset(index, 'hide'); |
|
112 |
}); |
|
119 |
/** |
|
120 |
* Helper function to return a HTML placeholder. |
|
121 |
* |
|
122 |
* The 'drupal-content' CSS class is required for HTML elements in the editor |
|
123 |
* content that shall not trigger any editor's native buttons (such as the |
|
124 |
* image button for this example placeholder markup). |
|
125 |
*/ |
|
126 |
_getPlaceholder: function (settings) { |
|
127 |
return '<img src="' + settings.path + '/images/spacer.gif" alt="<--token_insert_wysiwyg->" title="<--token_insert_wysiwyg-->" class="token_insert_wysiwyg-token_insert_wysiwyg drupal-content" />'; |
|
113 | 128 |
} |
114 |
return content; |
|
115 |
}, |
|
129 |
}; |
|
116 | 130 |
|
117 |
/** |
|
118 |
* Process all HTML placeholders of this plugin with plain-text contents. |
|
119 |
* |
|
120 |
* Optional; only required for "inline macro tag-processing" plugins. |
|
121 |
* |
|
122 |
* @param content |
|
123 |
* The HTML content string of the editor. |
|
124 |
* @param settings |
|
125 |
* The plugin settings, as provided in the plugin's PHP include file. |
|
126 |
* @param instanceId |
|
127 |
* The ID of the current editor instance. |
|
128 |
*/ |
|
129 |
detach: function(content, settings, instanceId) { |
|
130 |
var $content = $('<div>' + content + '</div>'); |
|
131 |
// show the token_insert_text fieldset when wysiwyg is disabled |
|
132 |
if (typeof Drupal.settings.token_insert !== 'undefined') { |
|
133 |
$.each(Drupal.settings.token_insert.buttons, function(index, fieldid) { |
|
134 |
hideShowFieldset(index, 'show'); |
|
135 |
}); |
|
136 |
} |
|
137 |
$.each($('img.token_insert_wysiwyg-token_insert_wysiwyg', $content), function (i, elem) { |
|
138 |
//... |
|
131 |
Drupal.ajax.prototype.commands.tokenInsertTable = function (ajax, response, status) { |
|
132 |
var $dialogdiv = $(response.selector); |
|
133 |
var instanceId = response.instance_id; |
|
134 |
$dialogdiv.find('.token-insert-table .token-key').once('token-insert-table', function() { |
|
135 |
var newThis = $('<a href="javascript:void(0);" title="' + Drupal.t('Insert this token into your form') + '">' + $(this).html() + '</a>').click(function(e){ |
|
136 |
e.preventDefault(); |
|
137 |
var token = $(this).text(); |
|
138 |
Drupal.wysiwyg.plugins.token_insert_wysiwyg.insertIntoEditor(token, instanceId); |
|
139 | 139 |
}); |
140 |
return $content.html(); |
|
141 |
}, |
|
140 |
$(this).html(newThis); |
|
141 |
}); |
|
142 |
var btns = {}; |
|
142 | 143 |
|
143 |
/** |
|
144 |
* Helper function to return a HTML placeholder. |
|
145 |
* |
|
146 |
* The 'drupal-content' CSS class is required for HTML elements in the editor |
|
147 |
* content that shall not trigger any editor's native buttons (such as the |
|
148 |
* image button for this example placeholder markup). |
|
149 |
*/ |
|
150 |
_getPlaceholder: function (settings) { |
|
151 |
return '<img src="' + settings.path + '/images/spacer.gif" alt="<--token_insert_wysiwyg->" title="<--token_insert_wysiwyg-->" class="token_insert_wysiwyg-token_insert_wysiwyg drupal-content" />'; |
|
152 |
} |
|
153 |
}; |
|
154 |
})(jQuery); |
|
144 |
btns[Drupal.t('Cancel')] = function () { |
|
145 |
$dialogdiv.dialog('close'); |
|
146 |
}; |
|
147 |
|
|
148 |
$dialogdiv.dialog({ |
|
149 |
modal: false, |
|
150 |
autoOpen: false, |
|
151 |
closeOnEscape: true, |
|
152 |
resizable: false, |
|
153 |
draggable: true, |
|
154 |
autoresize: true, |
|
155 |
namespace: 'jquery_ui_dialog_default_ns', |
|
156 |
dialogClass: 'jquery_ui_dialog-dialog', |
|
157 |
title: Drupal.t('Insert token'), |
|
158 |
buttons: btns, |
|
159 |
width: 700 |
|
160 |
}); |
|
161 |
$dialogdiv.css({maxHeight: 350}); |
|
162 |
dialogs[instanceId] = $dialogdiv; |
|
163 |
$dialogdiv.dialog("open"); |
|
164 |
}; |
|
165 |
})(jQuery, Drupal); |
Formats disponibles : Unified diff
Weekly update of contrib modules