PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/save/editor_plugin_src.js

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