/[drupal]/contributions/modules/wysiwyg/wysiwyg.api.js
ViewVC logotype

Contents of /contributions/modules/wysiwyg/wysiwyg.api.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Sun Aug 9 02:46:50 2009 UTC (3 months, 2 weeks ago) by sun
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--2, DRUPAL-6--3, DRUPAL-5--3, DRUPAL-5--2
File MIME type: text/javascript
#372826 by sun: Added Wysiwyg API developer documentation.
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="&lt;--break-&gt;" title="&lt;--break--&gt;" class="wysiwyg-break drupal-content" />';
97 }
98 };

  ViewVC Help
Powered by ViewVC 1.1.2