Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #5263 (closed enhancement: invalid)

Opened 3 years ago

Last modified 3 years ago

[PATCH] TinyMCE integration

Reported by: patrys@pld-linux.org Assigned to: Rails
Priority: normal Milestone:
Component: script.aculo.us Version:
Severity: normal Keywords:
Cc:

Description

Here is a new widget that integrates TinyMCE for the purpose of editing:

Ajax.InPlaceRichEditor = Class.create();
Object.extend(Ajax.InPlaceRichEditor.prototype, Ajax.InPlaceEditor.prototype);
Object.extend(Ajax.InPlaceRichEditor.prototype,
{
	enterEditMode: function(evt)
	{
		if (this.saving) return;
		if (this.editing) return;

		this.editing = true;
		this.onEnterEditMode();

		if (this.options.externalControl)
		{
			Element.hide(this.options.externalControl);
		}

		Element.hide(this.element);
		this.createForm();
		this.element.parentNode.insertBefore(this.form, this.element);
		Field.scrollFreeActivate(this.editField);

		if (this.options.textarea)
		{
			tinyMCE.addMCEControl(this.editField, 'value');
		}

		// stop the event to avoid a page refresh in Safari
		if (evt)
		{
			Event.stop(evt);
		}
		return false;
	},
	onclickCancel: function()
	{
		if (this.options.textarea)
		{
			tinyMCE.removeMCEControl('value');
		}

		this.onComplete();
		this.leaveEditMode();
		return false;
	},
	onSubmit: function()
	{
		// onLoading resets these so we need to save them away for the Ajax call
		var form = this.form;

		if (this.options.textarea)
		{
			var tinyVal = tinyMCE.getContent('value');

			if (tinyVal)
				this.editField.value = tinyVal;

			tinyMCE.removeMCEControl('value');
		}

		var value = this.editField.value;

		// do this first, sometimes the ajax call returns before we get a chance to switch on Saving...
		// which means this will actually switch on Saving... *after* we've left edit mode causing Saving...
		// to be displayed indefinitely
		this.onLoading();

		if (this.options.evalScripts)
		{
			new Ajax.Request(
				this.url, Object.extend(
				{
					parameters: this.options.callback(form, value),
					onComplete: this.onComplete.bind(this),
					onFailure: this.onFailure.bind(this),
					asynchronous:true, 
					evalScripts:true
				}, this.options.ajaxOptions));
		}
		else
		{
			new Ajax.Updater(
				{
					success: this.element,
					// don't update on failure (this could be an option)
					failure: null
				}, 
				this.url, Object.extend(
				{
					parameters: this.options.callback(form, value),
					onComplete: this.onComplete.bind(this),
					onFailure: this.onFailure.bind(this)
				}, this.options.ajaxOptions));
		}
		// stop the event to avoid a page refresh in Safari
		if (arguments.length > 1)
		{
			Event.stop(arguments[0]);
		}
		return false;
	}
});

Attachments

tGedit.zip (62.4 kB) - added by anonymous on 08/23/06 17:35:49.

Change History

06/02/06 12:29:51 changed by patrys@pld-linux.org

  • owner changed from David to Rails.
  • component changed from ActiveRecord to script.aculo.us.

Sorry for posting wrong component, my firefox just cleared the form

06/02/06 17:36:24 changed by david

  • status changed from new to closed.
  • resolution set to invalid.

This looks great, but could you turn it into a plugin instead of a patch to scriptaculous? We've stopped accepting new widgets into the core and will actually be moving stuff out, like the auto-complete, into plugins.

08/23/06 17:35:49 changed by anonymous

  • attachment tGedit.zip added.