Sha256: 22fa63ccfdb69434fd837c7bb2f473a85f3127531d91fe65590c6e75a25eba59

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

class Editor
	constructor: (@form, @titleFormField, @titleEditableItem,
	              @bodyFormField, @bodyEditableItem, @toolbarButtons) ->
		if (@form.length == 1) and (@titleFormField.length == 1) and
		   (@titleEditableItem.length == 1) and (@bodyFormField.length == 1) and
		   (@bodyEditableItem.length == 1)
			imageUploadPath = @bodyEditableItem.data("image-upload-path")
			imageDeletePath = @bodyEditableItem.data("image-delete-path")

			if (imageUploadPath.length > 0) and (imageDeletePath.length > 0)
				@bodyEditor = new MediumEditor(@bodyEditableItem, {
					buttonLabels: 'fontawesome',
					buttons: @toolbarButtons
				})

				@titleEditor = new MediumEditor(@titleEditableItem)

				@bodyEditableItem.mediumInsert({
					editor: @bodyEditor,
					addons: {
						images: {
							imagesUploadScript: imageUploadPath,
							imagesDeleteScript: imageDeletePath,
							deleteFile: (file, that) =>
								$.post that.options.imagesDeleteScript, {file: file}, (data, status, jqxhr) =>
									if data.id
										@form.append('<input type="hidden" name="post[images_attributes][' + data.id + '][id]" value="' + data.id + '" />')
										@form.append('<input type="hidden" name="post[images_attributes][' + data.id + '][_destroy]" value="true" />')
								, "json"
						}
					}
				})

				@cleanBindings()
				@addBindings()
			else
				console.error("Missing image upload and/or image delete paths for body editor!")
		else
			console.error("Invalid length for editable items or form fields!")

	addBindings: ->
		@form.on "submit", @updateFormFields

	cleanBindings: ->
		@form.off "submit"

	updateFormFields: (event) =>
		@titleFormField.val(@titleEditor.serialize()["element-0"].value)
		@bodyFormField.val(@bodyEditor.serialize()["element-0"].value)

# Make available to other scripts
@Editor = Editor

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
proclaim-0.5.6 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.5.5 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.5.3 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.5.2 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.5.1 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.5.0 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.4.0 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.3.1 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.3.0 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.2.4 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.2.2 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.2.1 app/assets/javascripts/proclaim/editor.js.coffee
proclaim-0.2.0 app/assets/javascripts/proclaim/editor.js.coffee