1 /** |
1 /** |
2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $ |
2 * $Id: editor_plugin_src.js 372 2007-11-11 18:38:50Z spocke $ |
3 * |
3 * |
4 * @author Moxiecode |
4 * @author Moxiecode |
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. |
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved. |
6 */ |
6 */ |
7 |
7 |
8 /* Import plugin specific language pack */ |
8 (function() { |
9 tinyMCE.importPluginLanguagePack('save'); |
9 tinymce.create('tinymce.plugins.Save', { |
|
10 init : function(ed, url) { |
|
11 var t = this; |
10 |
12 |
11 var TinyMCE_SavePlugin = { |
13 t.editor = ed; |
12 getInfo : function() { |
|
13 return { |
|
14 longname : 'Save', |
|
15 author : 'Moxiecode Systems AB', |
|
16 authorurl : 'http://tinymce.moxiecode.com', |
|
17 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save', |
|
18 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion |
|
19 }; |
|
20 }, |
|
21 |
14 |
22 initInstance : function(inst) { |
15 // Register commands |
23 inst.addShortcut('ctrl', 's', 'lang_save_desc', 'mceSave'); |
16 ed.addCommand('mceSave', t._save, t); |
24 }, |
17 ed.addCommand('mceCancel', t._cancel, t); |
25 |
18 |
26 /** |
19 // Register buttons |
27 * Returns the HTML contents of the save control. |
20 ed.addButton('save', {title : 'save.save_desc', cmd : 'mceSave'}); |
28 */ |
21 ed.addButton('cancel', {title : 'save.cancel_desc', cmd : 'mceCancel'}); |
29 getControlHTML : function(cn) { |
|
30 switch (cn) { |
|
31 case "save": |
|
32 return tinyMCE.getButtonHTML(cn, 'lang_save_desc', '{$pluginurl}/images/save.gif', 'mceSave'); |
|
33 } |
|
34 |
22 |
35 return ""; |
23 ed.onNodeChange.add(t._nodeChange, t); |
36 }, |
24 ed.addShortcut('ctrl+s', ed.getLang('save.save_desc'), 'mceSave'); |
|
25 }, |
37 |
26 |
38 /** |
27 getInfo : function() { |
39 * Executes the save command. |
28 return { |
40 */ |
29 longname : 'Save', |
41 execCommand : function(editor_id, element, command, user_interface, value) { |
30 author : 'Moxiecode Systems AB', |
42 // Handle commands |
31 authorurl : 'http://tinymce.moxiecode.com', |
43 switch (command) { |
32 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save', |
44 case "mceSave": |
33 version : tinymce.majorVersion + "." + tinymce.minorVersion |
45 if (tinyMCE.getParam("fullscreen_is_enabled")) |
34 }; |
46 return true; |
35 }, |
47 |
36 |
48 var inst = tinyMCE.selectedInstance; |
37 // Private methods |
49 var formObj = inst.formElement.form; |
|
50 |
38 |
51 if (tinyMCE.getParam("save_enablewhendirty") && !inst.isDirty()) |
39 _nodeChange : function(ed, cm, n) { |
52 return true; |
40 var ed = this.editor; |
53 |
41 |
54 if (formObj) { |
42 if (ed.getParam('save_enablewhendirty')) { |
55 tinyMCE.triggerSave(); |
43 cm.setDisabled('save', !ed.isDirty()); |
|
44 cm.setDisabled('cancel', !ed.isDirty()); |
|
45 } |
|
46 }, |
56 |
47 |
57 // Use callback instead |
48 // Private methods |
58 var os; |
|
59 if ((os = tinyMCE.getParam("save_onsavecallback"))) { |
|
60 if (eval(os + '(inst);')) { |
|
61 inst.startContent = tinyMCE.trim(inst.getBody().innerHTML); |
|
62 /*inst.undoLevels = new Array(); |
|
63 inst.undoIndex = 0; |
|
64 inst.typingUndoIndex = -1; |
|
65 inst.undoRedo = true; |
|
66 inst.undoLevels[inst.undoLevels.length] = inst.startContent;*/ |
|
67 tinyMCE.triggerNodeChange(false, true); |
|
68 } |
|
69 |
49 |
70 return true; |
50 _save : function() { |
|
51 var ed = this.editor, formObj, os, i, elementId; |
|
52 |
|
53 if (ed.getParam("fullscreen_is_enabled")) |
|
54 return true; |
|
55 |
|
56 formObj = tinymce.DOM.get(ed.id).form; |
|
57 |
|
58 if (ed.getParam("save_enablewhendirty") && !ed.isDirty()) |
|
59 return true; |
|
60 |
|
61 if (formObj) { |
|
62 tinyMCE.triggerSave(); |
|
63 |
|
64 // Use callback instead |
|
65 if (os = ed.getParam("save_onsavecallback")) { |
|
66 if (ed.execCallback('save_onsavecallback', ed)) { |
|
67 ed.startContent = tinymce.trim(ed.getContent({format : 'raw'})); |
|
68 ed.nodeChanged(); |
71 } |
69 } |
72 |
70 |
73 // Disable all UI form elements that TinyMCE created |
71 return; |
74 for (var i=0; i<formObj.elements.length; i++) { |
72 } |
75 var elementId = formObj.elements[i].name ? formObj.elements[i].name : formObj.elements[i].id; |
|
76 |
73 |
77 if (elementId.indexOf('mce_editor_') == 0) |
74 ed.isNotDirty = true; |
78 formObj.elements[i].disabled = true; |
|
79 } |
|
80 |
75 |
81 tinyMCE.isNotDirty = true; |
76 if (formObj.onsubmit == null || formObj.onsubmit() != false) |
|
77 tinymce.DOM.get(ed.id).form.submit(); |
82 |
78 |
83 if (formObj.onsubmit == null || formObj.onsubmit() != false) |
79 ed.nodeChanged(); |
84 inst.formElement.form.submit(); |
80 } else |
85 } else |
81 ed.windowManager.alert("Error: No form element found."); |
86 alert("Error: No form element found."); |
|
87 |
82 |
88 return true; |
83 return true; |
89 } |
84 }, |
90 // Pass to next handler in chain |
|
91 return false; |
|
92 }, |
|
93 |
85 |
94 handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) { |
86 _cancel : function() { |
95 if (tinyMCE.getParam("fullscreen_is_enabled")) { |
87 var ed = this.editor, os, h = tinymce.trim(ed.startContent); |
96 tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled'); |
|
97 return true; |
|
98 } |
|
99 |
88 |
100 if (tinyMCE.getParam("save_enablewhendirty")) { |
89 // Use callback instead |
101 var inst = tinyMCE.getInstanceById(editor_id); |
90 if (os = ed.getParam("save_oncancelcallback")) { |
102 |
91 ed.execCallback('save_oncancelcallback', ed); |
103 if (inst.isDirty()) { |
92 return; |
104 tinyMCE.switchClass(editor_id + '_save', 'mceButtonNormal'); |
|
105 return true; |
|
106 } |
93 } |
107 |
94 |
108 tinyMCE.switchClass(editor_id + '_save', 'mceButtonDisabled'); |
95 ed.setContent(h); |
|
96 ed.undoManager.clear(); |
|
97 ed.nodeChanged(); |
109 } |
98 } |
|
99 }); |
110 |
100 |
111 return true; |
101 // Register plugin |
112 } |
102 tinymce.PluginManager.add('save', tinymce.plugins.Save); |
113 }; |
103 })(); |
114 |
|
115 tinyMCE.addPlugin("save", TinyMCE_SavePlugin); |
|