Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// $Id$
/**
* Wysiwyg plugin button implementation for Awesome plugin.
*/
Drupal.wysiwyg.plugins.awesome = {
/**
* Return whether the passed node belongs to this plugin.
*
* @param node
* The currently focused DOM element in the editor content.
*/
isNode: function(node) {
return ($(node).is('img.mymodule-awesome'));
},
/**
* Execute the button.
*
* @param data
* An object containing data about the current selection:
* - format: 'html' when the passed data is HTML content, 'text' when the
* passed data is plain-text content.
* - node: When 'format' is 'html', the focused DOM element in the editor.
* - content: The textual representation of the focused/selected editor
* content.
* @param settings
* The plugin settings, as provided in the plugin's PHP include file.
* @param instanceId
* The ID of the current editor instance.
*/
invoke: function(data, settings, instanceId) {
// Generate HTML markup.
if (data.format == 'html') {
// Prevent duplicating a teaser break.
if ($(data.node).is('img.mymodule-awesome')) {
return;
}
var content = this._getPlaceholder(settings);
}
// Generate plain text.
else {
var content = '<!--break-->';
}
// Insert new content into the editor.
if (typeof content != 'undefined') {
Drupal.wysiwyg.instances[instanceId].insert(content);
}
},
/**
* Prepare all plain-text contents of this plugin with HTML representations.
*
* Optional; only required for "inline macro tag-processing" plugins.
*
* @param content
* The plain-text contents of a textarea.
* @param settings
* The plugin settings, as provided in the plugin's PHP include file.
* @param instanceId
* The ID of the current editor instance.
*/
attach: function(content, settings, instanceId) {
content = content.replace(/<!--break-->/g, this._getPlaceholder(settings));
return content;
},
/**
* Process all HTML placeholders of this plugin with plain-text contents.
*
* Optional; only required for "inline macro tag-processing" plugins.
*
* @param content
* The HTML content string of the editor.
* @param settings
* The plugin settings, as provided in the plugin's PHP include file.
* @param instanceId
* The ID of the current editor instance.
*/
detach: function(content, settings, instanceId) {
var $content = $('<div>' + content + '</div>');
$.each($('img.mymodule-awesome', $content), function (i, elem) {
//...
});
return $content.html();
},
/**
* Helper function to return a HTML placeholder.
*
* The 'drupal-content' CSS class is required for HTML elements in the editor
* content that shall not trigger any editor's native buttons (such as the
* image button for this example placeholder markup).
*/
_getPlaceholder: function (settings) {
return '<img src="' + settings.path + '/images/spacer.gif" alt="<--break->" title="<--break-->" class="wysiwyg-break drupal-content" />';
}
};