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