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