Initial revision with basic functionability
[bcms.git] / media / tinymce / plugins / save / editor_plugin_src.js
blobf95c65cd3bc00ab7aeacfb1e49c2cd4b703e73d1
1 /**\r
2  * $Id: editor_plugin_src.js 609 2008-02-18 16:19:27Z spocke $\r
3  *\r
4  * @author Moxiecode\r
5  * @copyright Copyright © 2004-2008, Moxiecode Systems AB, All rights reserved.\r
6  */\r
7 \r
8 (function() {\r
9         tinymce.create('tinymce.plugins.Save', {\r
10                 init : function(ed, url) {\r
11                         var t = this;\r
13                         t.editor = ed;\r
15                         // Register commands\r
16                         ed.addCommand('mceSave', t._save, t);\r
17                         ed.addCommand('mceCancel', t._cancel, t);\r
19                         // Register buttons\r
20                         ed.addButton('save', {title : 'save.save_desc', cmd : 'mceSave'});\r
21                         ed.addButton('cancel', {title : 'save.cancel_desc', cmd : 'mceCancel'});\r
23                         ed.onNodeChange.add(t._nodeChange, t);\r
24                         ed.addShortcut('ctrl+s', ed.getLang('save.save_desc'), 'mceSave');\r
25                 },\r
27                 getInfo : function() {\r
28                         return {\r
29                                 longname : 'Save',\r
30                                 author : 'Moxiecode Systems AB',\r
31                                 authorurl : 'http://tinymce.moxiecode.com',\r
32                                 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save',\r
33                                 version : tinymce.majorVersion + "." + tinymce.minorVersion\r
34                         };\r
35                 },\r
37                 // Private methods\r
39                 _nodeChange : function(ed, cm, n) {\r
40                         var ed = this.editor;\r
42                         if (ed.getParam('save_enablewhendirty')) {\r
43                                 cm.setDisabled('save', !ed.isDirty());\r
44                                 cm.setDisabled('cancel', !ed.isDirty());\r
45                         }\r
46                 },\r
48                 // Private methods\r
50                 _save : function() {\r
51                         var ed = this.editor, formObj, os, i, elementId;\r
53                         formObj = tinymce.DOM.get(ed.id).form || tinymce.DOM.getParent(ed.id, 'form');\r
55                         if (ed.getParam("save_enablewhendirty") && !ed.isDirty())\r
56                                 return true;\r
58                         tinyMCE.triggerSave();\r
60                         // Use callback instead\r
61                         if (os = ed.getParam("save_onsavecallback")) {\r
62                                 if (ed.execCallback('save_onsavecallback', ed)) {\r
63                                         ed.startContent = tinymce.trim(ed.getContent({format : 'raw'}));\r
64                                         ed.nodeChanged();\r
65                                 }\r
67                                 return;\r
68                         }\r
70                         if (formObj) {\r
71                                 ed.isNotDirty = true;\r
73                                 if (formObj.onsubmit == null || formObj.onsubmit() != false)\r
74                                         formObj.submit();\r
76                                 ed.nodeChanged();\r
77                         } else\r
78                                 ed.windowManager.alert("Error: No form element found.");\r
80                         return true;\r
81                 },\r
83                 _cancel : function() {\r
84                         var ed = this.editor, os, h = tinymce.trim(ed.startContent);\r
86                         // Use callback instead\r
87                         if (os = ed.getParam("save_oncancelcallback")) {\r
88                                 ed.execCallback('save_oncancelcallback', ed);\r
89                                 return;\r
90                         }\r
92                         ed.setContent(h);\r
93                         ed.undoManager.clear();\r
94                         ed.nodeChanged();\r
95                 }\r
96         });\r
98         // Register plugin\r
99         tinymce.PluginManager.add('save', tinymce.plugins.Save);\r
100 })();