danielebarchiesi@0: (function($) { danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Attach this editor to a target element. danielebarchiesi@0: */ danielebarchiesi@0: Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) { danielebarchiesi@0: var FCKinstance = new FCKeditor(params.field, settings.Width, settings.Height, settings.ToolbarSet); danielebarchiesi@0: // Apply editor instance settings. danielebarchiesi@0: FCKinstance.BasePath = settings.EditorPath; danielebarchiesi@0: FCKinstance.Config.wysiwygFormat = params.format; danielebarchiesi@0: FCKinstance.Config.CustomConfigurationsPath = settings.CustomConfigurationsPath; danielebarchiesi@0: danielebarchiesi@0: // Load Drupal plugins and apply format specific settings. danielebarchiesi@0: // @see fckeditor.config.js danielebarchiesi@0: // @see Drupal.wysiwyg.editor.instance.fckeditor.init() danielebarchiesi@0: danielebarchiesi@0: // Attach editor. danielebarchiesi@0: FCKinstance.ReplaceTextarea(); danielebarchiesi@0: }; danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Detach a single or all editors. danielebarchiesi@0: */ danielebarchiesi@0: Drupal.wysiwyg.editor.detach.fckeditor = function (context, params, trigger) { danielebarchiesi@0: var instances = []; danielebarchiesi@0: if (typeof params != 'undefined' && typeof FCKeditorAPI != 'undefined') { danielebarchiesi@0: var instance = FCKeditorAPI.GetInstance(params.field); danielebarchiesi@0: if (instance) { danielebarchiesi@0: instances[params.field] = instance; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: instances = FCKeditorAPI.__Instances; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: for (var instanceName in instances) { danielebarchiesi@0: var instance = instances[instanceName]; danielebarchiesi@0: instance.UpdateLinkedField(); danielebarchiesi@0: if (trigger == 'serialize') { danielebarchiesi@0: // The editor is not being removed from the DOM, so updating the linked danielebarchiesi@0: // field is the only action necessary. danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Since we already detach the editor and update the textarea, the submit danielebarchiesi@0: // event handler needs to be removed to prevent data loss (in IE). danielebarchiesi@0: // FCKeditor uses 2 nested iFrames; instance.EditingArea.Window is the danielebarchiesi@0: // deepest. Its parent is the iFrame containing the editor. danielebarchiesi@0: var instanceScope = instance.EditingArea.Window.parent; danielebarchiesi@0: instanceScope.FCKTools.RemoveEventListener(instance.GetParentForm(), 'submit', instance.UpdateLinkedField); danielebarchiesi@0: // Run cleanups before forcing an unload of the iFrames or IE crashes. danielebarchiesi@0: // This also deletes the instance from the FCKeditorAPI.__Instances array. danielebarchiesi@0: instanceScope.FCKTools.RemoveEventListener(instanceScope, 'unload', instanceScope.FCKeditorAPI_Cleanup); danielebarchiesi@0: instanceScope.FCKTools.RemoveEventListener(instanceScope, 'beforeunload', instanceScope.FCKeditorAPI_ConfirmCleanup); danielebarchiesi@0: if (jQuery.isFunction(instanceScope.FCKIECleanup_Cleanup)) { danielebarchiesi@0: instanceScope.FCKIECleanup_Cleanup(); danielebarchiesi@0: } danielebarchiesi@0: instanceScope.FCKeditorAPI_ConfirmCleanup(); danielebarchiesi@0: instanceScope.FCKeditorAPI_Cleanup(); danielebarchiesi@0: // Remove the editor elements. danielebarchiesi@0: $('#' + instanceName + '___Config').remove(); danielebarchiesi@0: $('#' + instanceName + '___Frame').remove(); danielebarchiesi@0: $('#' + instanceName).show(); danielebarchiesi@0: } danielebarchiesi@0: }; danielebarchiesi@0: danielebarchiesi@0: Drupal.wysiwyg.editor.instance.fckeditor = { danielebarchiesi@0: init: function(instance) { danielebarchiesi@0: // Track which editor instance is active. danielebarchiesi@0: instance.FCK.Events.AttachEvent('OnFocus', function(editorInstance) { danielebarchiesi@0: Drupal.wysiwyg.activeId = editorInstance.Name; danielebarchiesi@0: }); danielebarchiesi@0: danielebarchiesi@0: // Create a custom data processor to wrap the default one and allow Drupal danielebarchiesi@0: // plugins modify the editor contents. danielebarchiesi@0: var wysiwygDataProcessor = function() {}; danielebarchiesi@0: wysiwygDataProcessor.prototype = new instance.FCKDataProcessor(); danielebarchiesi@0: // Attach: Convert text into HTML. danielebarchiesi@0: wysiwygDataProcessor.prototype.ConvertToHtml = function(data) { danielebarchiesi@0: // Called from SetData() with stripped comments/scripts, revert those danielebarchiesi@0: // manipulations and attach Drupal plugins. danielebarchiesi@0: var data = instance.FCKConfig.ProtectedSource.Revert(data); danielebarchiesi@0: if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { danielebarchiesi@0: for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { danielebarchiesi@0: if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') { danielebarchiesi@0: data = Drupal.wysiwyg.plugins[plugin].attach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name); danielebarchiesi@0: data = Drupal.wysiwyg.editor.instance.fckeditor.prepareContent(data); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: // Re-protect the source and use the original data processor to convert it danielebarchiesi@0: // into XHTML. danielebarchiesi@0: data = instance.FCKConfig.ProtectedSource.Protect(data); danielebarchiesi@0: return instance.FCKDataProcessor.prototype.ConvertToHtml.call(this, data); danielebarchiesi@0: }; danielebarchiesi@0: // Detach: Convert HTML into text. danielebarchiesi@0: wysiwygDataProcessor.prototype.ConvertToDataFormat = function(rootNode, excludeRoot, ignoreIfEmptyParagraph, format) { danielebarchiesi@0: // Called from GetData(), convert the content's DOM into a XHTML string danielebarchiesi@0: // using the original data processor and detach Drupal plugins. danielebarchiesi@0: var data = instance.FCKDataProcessor.prototype.ConvertToDataFormat.call(this, rootNode, excludeRoot, ignoreIfEmptyParagraph, format); danielebarchiesi@0: if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { danielebarchiesi@0: for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { danielebarchiesi@0: if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') { danielebarchiesi@0: data = Drupal.wysiwyg.plugins[plugin].detach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return data; danielebarchiesi@0: }; danielebarchiesi@0: instance.FCK.DataProcessor = new wysiwygDataProcessor(); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: addPlugin: function(plugin, settings, pluginSettings, instance) { danielebarchiesi@0: if (typeof Drupal.wysiwyg.plugins[plugin] != 'object') { danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css) { danielebarchiesi@0: instance.FCKConfig.EditorAreaCSS += ',' + Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // @see fckcommands.js, fck_othercommands.js, fckpastewordcommand.js danielebarchiesi@0: instance.FCKCommands.RegisterCommand(plugin, { danielebarchiesi@0: // Invoke the plugin's button. danielebarchiesi@0: Execute: function () { danielebarchiesi@0: if (typeof Drupal.wysiwyg.plugins[plugin].invoke == 'function') { danielebarchiesi@0: var data = { format: 'html', node: instance.FCKSelection.GetParentElement() }; danielebarchiesi@0: // @todo This is NOT the same as data.node. danielebarchiesi@0: data.content = data.node.innerHTML; danielebarchiesi@0: Drupal.wysiwyg.plugins[plugin].invoke(data, pluginSettings, instance.FCK.Name); danielebarchiesi@0: } danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: // isNode: Return whether the plugin button should be enabled for the danielebarchiesi@0: // current selection. danielebarchiesi@0: // @see FCKUnlinkCommand.prototype.GetState() danielebarchiesi@0: GetState: function () { danielebarchiesi@0: // Always disabled if not in WYSIWYG mode. danielebarchiesi@0: if (instance.FCK.EditMode != FCK_EDITMODE_WYSIWYG) { danielebarchiesi@0: return FCK_TRISTATE_DISABLED; danielebarchiesi@0: } danielebarchiesi@0: var state = instance.FCK.GetNamedCommandState(this.Name); danielebarchiesi@0: // FCKeditor sets the wrong state in WebKit browsers. danielebarchiesi@0: if (!$.support.queryCommandEnabled && state == FCK_TRISTATE_DISABLED) { danielebarchiesi@0: state = FCK_TRISTATE_OFF; danielebarchiesi@0: } danielebarchiesi@0: if (state == FCK_TRISTATE_OFF && instance.FCK.EditMode == FCK_EDITMODE_WYSIWYG) { danielebarchiesi@0: if (typeof Drupal.wysiwyg.plugins[plugin].isNode == 'function') { danielebarchiesi@0: var node = instance.FCKSelection.GetSelectedElement(); danielebarchiesi@0: state = Drupal.wysiwyg.plugins[plugin].isNode(node) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return state; danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return information about the plugin as a name/value array. danielebarchiesi@0: */ danielebarchiesi@0: Name: plugin danielebarchiesi@0: }); danielebarchiesi@0: danielebarchiesi@0: // Register the plugin button. danielebarchiesi@0: // Arguments: commandName, label, tooltip, style, sourceView, contextSensitive, icon. danielebarchiesi@0: instance.FCKToolbarItems.RegisterItem(plugin, new instance.FCKToolbarButton(plugin, settings.iconTitle, settings.iconTitle, null, false, true, settings.icon)); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: openDialog: function(dialog, params) { danielebarchiesi@0: // @todo Implement open dialog. danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: closeDialog: function(dialog) { danielebarchiesi@0: // @todo Implement close dialog. danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: prepareContent: function(content) { danielebarchiesi@0: // @todo Not needed for FCKeditor? danielebarchiesi@0: return content; danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: insert: function(content) { danielebarchiesi@0: var instance = FCKeditorAPI.GetInstance(this.field); danielebarchiesi@0: // @see FCK.InsertHtml(), FCK.InsertElement() danielebarchiesi@0: instance.InsertHtml(content); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: getContent: function () { danielebarchiesi@0: var instance = FCKeditorAPI.GetInstance(this.field); danielebarchiesi@0: return instance.GetData(); danielebarchiesi@0: }, danielebarchiesi@0: danielebarchiesi@0: setContent: function (content) { danielebarchiesi@0: var instance = FCKeditorAPI.GetInstance(this.field); danielebarchiesi@0: instance.SetHTML(content); danielebarchiesi@0: } danielebarchiesi@0: }; danielebarchiesi@0: danielebarchiesi@0: })(jQuery);