bgneal@45
|
1 /**
|
bgneal@183
|
2 * editor_plugin_src.js
|
bgneal@45
|
3 *
|
bgneal@183
|
4 * Copyright 2009, Moxiecode Systems AB
|
bgneal@183
|
5 * Released under LGPL License.
|
bgneal@183
|
6 *
|
bgneal@183
|
7 * License: http://tinymce.moxiecode.com/license
|
bgneal@183
|
8 * Contributing: http://tinymce.moxiecode.com/contributing
|
bgneal@45
|
9 */
|
bgneal@45
|
10
|
bgneal@45
|
11 (function() {
|
bgneal@45
|
12 tinymce.create('tinymce.plugins.Save', {
|
bgneal@45
|
13 init : function(ed, url) {
|
bgneal@45
|
14 var t = this;
|
bgneal@45
|
15
|
bgneal@45
|
16 t.editor = ed;
|
bgneal@45
|
17
|
bgneal@45
|
18 // Register commands
|
bgneal@45
|
19 ed.addCommand('mceSave', t._save, t);
|
bgneal@45
|
20 ed.addCommand('mceCancel', t._cancel, t);
|
bgneal@45
|
21
|
bgneal@45
|
22 // Register buttons
|
bgneal@45
|
23 ed.addButton('save', {title : 'save.save_desc', cmd : 'mceSave'});
|
bgneal@45
|
24 ed.addButton('cancel', {title : 'save.cancel_desc', cmd : 'mceCancel'});
|
bgneal@45
|
25
|
bgneal@45
|
26 ed.onNodeChange.add(t._nodeChange, t);
|
bgneal@45
|
27 ed.addShortcut('ctrl+s', ed.getLang('save.save_desc'), 'mceSave');
|
bgneal@45
|
28 },
|
bgneal@45
|
29
|
bgneal@45
|
30 getInfo : function() {
|
bgneal@45
|
31 return {
|
bgneal@45
|
32 longname : 'Save',
|
bgneal@45
|
33 author : 'Moxiecode Systems AB',
|
bgneal@45
|
34 authorurl : 'http://tinymce.moxiecode.com',
|
bgneal@45
|
35 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/save',
|
bgneal@45
|
36 version : tinymce.majorVersion + "." + tinymce.minorVersion
|
bgneal@45
|
37 };
|
bgneal@45
|
38 },
|
bgneal@45
|
39
|
bgneal@45
|
40 // Private methods
|
bgneal@45
|
41
|
bgneal@45
|
42 _nodeChange : function(ed, cm, n) {
|
bgneal@45
|
43 var ed = this.editor;
|
bgneal@45
|
44
|
bgneal@45
|
45 if (ed.getParam('save_enablewhendirty')) {
|
bgneal@45
|
46 cm.setDisabled('save', !ed.isDirty());
|
bgneal@45
|
47 cm.setDisabled('cancel', !ed.isDirty());
|
bgneal@45
|
48 }
|
bgneal@45
|
49 },
|
bgneal@45
|
50
|
bgneal@45
|
51 // Private methods
|
bgneal@45
|
52
|
bgneal@45
|
53 _save : function() {
|
bgneal@45
|
54 var ed = this.editor, formObj, os, i, elementId;
|
bgneal@45
|
55
|
bgneal@45
|
56 formObj = tinymce.DOM.get(ed.id).form || tinymce.DOM.getParent(ed.id, 'form');
|
bgneal@45
|
57
|
bgneal@45
|
58 if (ed.getParam("save_enablewhendirty") && !ed.isDirty())
|
bgneal@45
|
59 return;
|
bgneal@45
|
60
|
bgneal@45
|
61 tinyMCE.triggerSave();
|
bgneal@45
|
62
|
bgneal@45
|
63 // Use callback instead
|
bgneal@45
|
64 if (os = ed.getParam("save_onsavecallback")) {
|
bgneal@45
|
65 if (ed.execCallback('save_onsavecallback', ed)) {
|
bgneal@45
|
66 ed.startContent = tinymce.trim(ed.getContent({format : 'raw'}));
|
bgneal@45
|
67 ed.nodeChanged();
|
bgneal@45
|
68 }
|
bgneal@45
|
69
|
bgneal@45
|
70 return;
|
bgneal@45
|
71 }
|
bgneal@45
|
72
|
bgneal@45
|
73 if (formObj) {
|
bgneal@45
|
74 ed.isNotDirty = true;
|
bgneal@45
|
75
|
bgneal@45
|
76 if (formObj.onsubmit == null || formObj.onsubmit() != false)
|
bgneal@45
|
77 formObj.submit();
|
bgneal@45
|
78
|
bgneal@45
|
79 ed.nodeChanged();
|
bgneal@45
|
80 } else
|
bgneal@45
|
81 ed.windowManager.alert("Error: No form element found.");
|
bgneal@45
|
82 },
|
bgneal@45
|
83
|
bgneal@45
|
84 _cancel : function() {
|
bgneal@45
|
85 var ed = this.editor, os, h = tinymce.trim(ed.startContent);
|
bgneal@45
|
86
|
bgneal@45
|
87 // Use callback instead
|
bgneal@45
|
88 if (os = ed.getParam("save_oncancelcallback")) {
|
bgneal@45
|
89 ed.execCallback('save_oncancelcallback', ed);
|
bgneal@45
|
90 return;
|
bgneal@45
|
91 }
|
bgneal@45
|
92
|
bgneal@45
|
93 ed.setContent(h);
|
bgneal@45
|
94 ed.undoManager.clear();
|
bgneal@45
|
95 ed.nodeChanged();
|
bgneal@45
|
96 }
|
bgneal@45
|
97 });
|
bgneal@45
|
98
|
bgneal@45
|
99 // Register plugin
|
bgneal@45
|
100 tinymce.PluginManager.add('save', tinymce.plugins.Save);
|
bgneal@45
|
101 })(); |