annotate media/js/tiny_mce/plugins/save/editor_plugin_src.js @ 45:a5b4c5ce0658

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