Sha256: 1bf2a8a4bfc08735feaab51fa3530a16729e2b9f3923b0ef1aa8649bcae792bd
Contents?: true
Size: 1.76 KB
Versions: 4
Compression:
Stored size: 1.76 KB
Contents
class Editor constructor: (@form, @titleFormField, @titleEditableItem, @bodyFormField, @bodyEditableItem) -> 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'}) @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
4 entries across 4 versions & 1 rubygems