danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Wysiwyg plugin button implementation for Awesome plugin. danielebarchiesi@0: */ danielebarchiesi@0: Drupal.wysiwyg.plugins.awesome = { danielebarchiesi@0: /** danielebarchiesi@0: * Return whether the passed node belongs to this plugin. danielebarchiesi@0: * danielebarchiesi@0: * @param node danielebarchiesi@0: * The currently focused DOM element in the editor content. danielebarchiesi@0: */ danielebarchiesi@0: isNode: function(node) { danielebarchiesi@0: return ($(node).is('img.mymodule-awesome')); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Execute the button. danielebarchiesi@0: * danielebarchiesi@0: * @param data danielebarchiesi@0: * An object containing data about the current selection: danielebarchiesi@0: * - format: 'html' when the passed data is HTML content, 'text' when the danielebarchiesi@0: * passed data is plain-text content. danielebarchiesi@0: * - node: When 'format' is 'html', the focused DOM element in the editor. danielebarchiesi@0: * - content: The textual representation of the focused/selected editor danielebarchiesi@0: * content. danielebarchiesi@0: * @param settings danielebarchiesi@0: * The plugin settings, as provided in the plugin's PHP include file. danielebarchiesi@0: * @param instanceId danielebarchiesi@0: * The ID of the current editor instance. danielebarchiesi@0: */ danielebarchiesi@0: invoke: function(data, settings, instanceId) { danielebarchiesi@0: // Generate HTML markup. danielebarchiesi@0: if (data.format == 'html') { danielebarchiesi@0: // Prevent duplicating a teaser break. danielebarchiesi@0: if ($(data.node).is('img.mymodule-awesome')) { danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: var content = this._getPlaceholder(settings); danielebarchiesi@0: } danielebarchiesi@0: // Generate plain text. danielebarchiesi@0: else { danielebarchiesi@0: var content = ''; danielebarchiesi@0: } danielebarchiesi@0: // Insert new content into the editor. danielebarchiesi@0: if (typeof content != 'undefined') { danielebarchiesi@0: Drupal.wysiwyg.instances[instanceId].insert(content); danielebarchiesi@0: } danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Prepare all plain-text contents of this plugin with HTML representations. danielebarchiesi@0: * danielebarchiesi@0: * Optional; only required for "inline macro tag-processing" plugins. danielebarchiesi@0: * danielebarchiesi@0: * @param content danielebarchiesi@0: * The plain-text contents of a textarea. danielebarchiesi@0: * @param settings danielebarchiesi@0: * The plugin settings, as provided in the plugin's PHP include file. danielebarchiesi@0: * @param instanceId danielebarchiesi@0: * The ID of the current editor instance. danielebarchiesi@0: */ danielebarchiesi@0: attach: function(content, settings, instanceId) { danielebarchiesi@0: content = content.replace(//g, this._getPlaceholder(settings)); danielebarchiesi@0: return content; danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Process all HTML placeholders of this plugin with plain-text contents. danielebarchiesi@0: * danielebarchiesi@0: * Optional; only required for "inline macro tag-processing" plugins. danielebarchiesi@0: * danielebarchiesi@0: * @param content danielebarchiesi@0: * The HTML content string of the editor. danielebarchiesi@0: * @param settings danielebarchiesi@0: * The plugin settings, as provided in the plugin's PHP include file. danielebarchiesi@0: * @param instanceId danielebarchiesi@0: * The ID of the current editor instance. danielebarchiesi@0: */ danielebarchiesi@0: detach: function(content, settings, instanceId) { danielebarchiesi@0: var $content = $('
' + content + '
'); danielebarchiesi@0: $.each($('img.mymodule-awesome', $content), function (i, elem) { danielebarchiesi@0: //... danielebarchiesi@0: }); danielebarchiesi@0: return $content.html(); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Helper function to return a HTML placeholder. danielebarchiesi@0: * danielebarchiesi@0: * The 'drupal-content' CSS class is required for HTML elements in the editor danielebarchiesi@0: * content that shall not trigger any editor's native buttons (such as the danielebarchiesi@0: * image button for this example placeholder markup). danielebarchiesi@0: */ danielebarchiesi@0: _getPlaceholder: function (settings) { danielebarchiesi@0: return '<--break->'; danielebarchiesi@0: } danielebarchiesi@0: };