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