Mercurial > hg > rr-repo
comparison sites/all/modules/wysiwyg/editors/js/fckeditor-2.6.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 (function($) { | |
2 | |
3 /** | |
4 * Attach this editor to a target element. | |
5 */ | |
6 Drupal.wysiwyg.editor.attach.fckeditor = function(context, params, settings) { | |
7 var FCKinstance = new FCKeditor(params.field, settings.Width, settings.Height, settings.ToolbarSet); | |
8 // Apply editor instance settings. | |
9 FCKinstance.BasePath = settings.EditorPath; | |
10 FCKinstance.Config.wysiwygFormat = params.format; | |
11 FCKinstance.Config.CustomConfigurationsPath = settings.CustomConfigurationsPath; | |
12 | |
13 // Load Drupal plugins and apply format specific settings. | |
14 // @see fckeditor.config.js | |
15 // @see Drupal.wysiwyg.editor.instance.fckeditor.init() | |
16 | |
17 // Attach editor. | |
18 FCKinstance.ReplaceTextarea(); | |
19 }; | |
20 | |
21 /** | |
22 * Detach a single or all editors. | |
23 */ | |
24 Drupal.wysiwyg.editor.detach.fckeditor = function (context, params, trigger) { | |
25 var instances = []; | |
26 if (typeof params != 'undefined' && typeof FCKeditorAPI != 'undefined') { | |
27 var instance = FCKeditorAPI.GetInstance(params.field); | |
28 if (instance) { | |
29 instances[params.field] = instance; | |
30 } | |
31 } | |
32 else { | |
33 instances = FCKeditorAPI.__Instances; | |
34 } | |
35 | |
36 for (var instanceName in instances) { | |
37 var instance = instances[instanceName]; | |
38 instance.UpdateLinkedField(); | |
39 if (trigger == 'serialize') { | |
40 // The editor is not being removed from the DOM, so updating the linked | |
41 // field is the only action necessary. | |
42 continue; | |
43 } | |
44 // Since we already detach the editor and update the textarea, the submit | |
45 // event handler needs to be removed to prevent data loss (in IE). | |
46 // FCKeditor uses 2 nested iFrames; instance.EditingArea.Window is the | |
47 // deepest. Its parent is the iFrame containing the editor. | |
48 var instanceScope = instance.EditingArea.Window.parent; | |
49 instanceScope.FCKTools.RemoveEventListener(instance.GetParentForm(), 'submit', instance.UpdateLinkedField); | |
50 // Run cleanups before forcing an unload of the iFrames or IE crashes. | |
51 // This also deletes the instance from the FCKeditorAPI.__Instances array. | |
52 instanceScope.FCKTools.RemoveEventListener(instanceScope, 'unload', instanceScope.FCKeditorAPI_Cleanup); | |
53 instanceScope.FCKTools.RemoveEventListener(instanceScope, 'beforeunload', instanceScope.FCKeditorAPI_ConfirmCleanup); | |
54 if (jQuery.isFunction(instanceScope.FCKIECleanup_Cleanup)) { | |
55 instanceScope.FCKIECleanup_Cleanup(); | |
56 } | |
57 instanceScope.FCKeditorAPI_ConfirmCleanup(); | |
58 instanceScope.FCKeditorAPI_Cleanup(); | |
59 // Remove the editor elements. | |
60 $('#' + instanceName + '___Config').remove(); | |
61 $('#' + instanceName + '___Frame').remove(); | |
62 $('#' + instanceName).show(); | |
63 } | |
64 }; | |
65 | |
66 Drupal.wysiwyg.editor.instance.fckeditor = { | |
67 init: function(instance) { | |
68 // Track which editor instance is active. | |
69 instance.FCK.Events.AttachEvent('OnFocus', function(editorInstance) { | |
70 Drupal.wysiwyg.activeId = editorInstance.Name; | |
71 }); | |
72 | |
73 // Create a custom data processor to wrap the default one and allow Drupal | |
74 // plugins modify the editor contents. | |
75 var wysiwygDataProcessor = function() {}; | |
76 wysiwygDataProcessor.prototype = new instance.FCKDataProcessor(); | |
77 // Attach: Convert text into HTML. | |
78 wysiwygDataProcessor.prototype.ConvertToHtml = function(data) { | |
79 // Called from SetData() with stripped comments/scripts, revert those | |
80 // manipulations and attach Drupal plugins. | |
81 var data = instance.FCKConfig.ProtectedSource.Revert(data); | |
82 if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { | |
83 for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { | |
84 if (typeof Drupal.wysiwyg.plugins[plugin].attach == 'function') { | |
85 data = Drupal.wysiwyg.plugins[plugin].attach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name); | |
86 data = Drupal.wysiwyg.editor.instance.fckeditor.prepareContent(data); | |
87 } | |
88 } | |
89 } | |
90 // Re-protect the source and use the original data processor to convert it | |
91 // into XHTML. | |
92 data = instance.FCKConfig.ProtectedSource.Protect(data); | |
93 return instance.FCKDataProcessor.prototype.ConvertToHtml.call(this, data); | |
94 }; | |
95 // Detach: Convert HTML into text. | |
96 wysiwygDataProcessor.prototype.ConvertToDataFormat = function(rootNode, excludeRoot, ignoreIfEmptyParagraph, format) { | |
97 // Called from GetData(), convert the content's DOM into a XHTML string | |
98 // using the original data processor and detach Drupal plugins. | |
99 var data = instance.FCKDataProcessor.prototype.ConvertToDataFormat.call(this, rootNode, excludeRoot, ignoreIfEmptyParagraph, format); | |
100 if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat] && Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { | |
101 for (var plugin in Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal) { | |
102 if (typeof Drupal.wysiwyg.plugins[plugin].detach == 'function') { | |
103 data = Drupal.wysiwyg.plugins[plugin].detach(data, Drupal.settings.wysiwyg.plugins.drupal[plugin], instance.FCK.Name); | |
104 } | |
105 } | |
106 } | |
107 return data; | |
108 }; | |
109 instance.FCK.DataProcessor = new wysiwygDataProcessor(); | |
110 }, | |
111 | |
112 addPlugin: function(plugin, settings, pluginSettings, instance) { | |
113 if (typeof Drupal.wysiwyg.plugins[plugin] != 'object') { | |
114 return; | |
115 } | |
116 | |
117 if (Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css) { | |
118 instance.FCKConfig.EditorAreaCSS += ',' + Drupal.settings.wysiwyg.plugins[instance.wysiwygFormat].drupal[plugin].css; | |
119 } | |
120 | |
121 // @see fckcommands.js, fck_othercommands.js, fckpastewordcommand.js | |
122 instance.FCKCommands.RegisterCommand(plugin, { | |
123 // Invoke the plugin's button. | |
124 Execute: function () { | |
125 if (typeof Drupal.wysiwyg.plugins[plugin].invoke == 'function') { | |
126 var data = { format: 'html', node: instance.FCKSelection.GetParentElement() }; | |
127 // @todo This is NOT the same as data.node. | |
128 data.content = data.node.innerHTML; | |
129 Drupal.wysiwyg.plugins[plugin].invoke(data, pluginSettings, instance.FCK.Name); | |
130 } | |
131 }, | |
132 | |
133 // isNode: Return whether the plugin button should be enabled for the | |
134 // current selection. | |
135 // @see FCKUnlinkCommand.prototype.GetState() | |
136 GetState: function () { | |
137 // Always disabled if not in WYSIWYG mode. | |
138 if (instance.FCK.EditMode != FCK_EDITMODE_WYSIWYG) { | |
139 return FCK_TRISTATE_DISABLED; | |
140 } | |
141 var state = instance.FCK.GetNamedCommandState(this.Name); | |
142 // FCKeditor sets the wrong state in WebKit browsers. | |
143 if (!$.support.queryCommandEnabled && state == FCK_TRISTATE_DISABLED) { | |
144 state = FCK_TRISTATE_OFF; | |
145 } | |
146 if (state == FCK_TRISTATE_OFF && instance.FCK.EditMode == FCK_EDITMODE_WYSIWYG) { | |
147 if (typeof Drupal.wysiwyg.plugins[plugin].isNode == 'function') { | |
148 var node = instance.FCKSelection.GetSelectedElement(); | |
149 state = Drupal.wysiwyg.plugins[plugin].isNode(node) ? FCK_TRISTATE_ON : FCK_TRISTATE_OFF; | |
150 } | |
151 } | |
152 return state; | |
153 }, | |
154 | |
155 /** | |
156 * Return information about the plugin as a name/value array. | |
157 */ | |
158 Name: plugin | |
159 }); | |
160 | |
161 // Register the plugin button. | |
162 // Arguments: commandName, label, tooltip, style, sourceView, contextSensitive, icon. | |
163 instance.FCKToolbarItems.RegisterItem(plugin, new instance.FCKToolbarButton(plugin, settings.iconTitle, settings.iconTitle, null, false, true, settings.icon)); | |
164 }, | |
165 | |
166 openDialog: function(dialog, params) { | |
167 // @todo Implement open dialog. | |
168 }, | |
169 | |
170 closeDialog: function(dialog) { | |
171 // @todo Implement close dialog. | |
172 }, | |
173 | |
174 prepareContent: function(content) { | |
175 // @todo Not needed for FCKeditor? | |
176 return content; | |
177 }, | |
178 | |
179 insert: function(content) { | |
180 var instance = FCKeditorAPI.GetInstance(this.field); | |
181 // @see FCK.InsertHtml(), FCK.InsertElement() | |
182 instance.InsertHtml(content); | |
183 }, | |
184 | |
185 getContent: function () { | |
186 var instance = FCKeditorAPI.GetInstance(this.field); | |
187 return instance.GetData(); | |
188 }, | |
189 | |
190 setContent: function (content) { | |
191 var instance = FCKeditorAPI.GetInstance(this.field); | |
192 instance.SetHTML(content); | |
193 } | |
194 }; | |
195 | |
196 })(jQuery); |