From 7d206a8c86e5e0cc6f71ac15cf07117f90a2bba6 Mon Sep 17 00:00:00 2001 From: Laurens Martina Date: Mon, 5 Oct 2020 21:44:55 +0200 Subject: [PATCH] wymeditor: Adds attribution to image dialog Fixes #119 --- system/wymeditor/lang/en.js | 2 + system/wymeditor/lang/nl.js | 4 +- .../jquery.wymeditor.image_upload.js | 37 ++++++++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/system/wymeditor/lang/en.js b/system/wymeditor/lang/en.js index 8d514c2b..a136bd3d 100644 --- a/system/wymeditor/lang/en.js +++ b/system/wymeditor/lang/en.js @@ -28,6 +28,8 @@ WYMeditor.STRINGS.en = { Title: 'Title', Relationship: 'Relationship', Alternative_Text: 'Alternative text', + Attribution: 'Attribution', + Attribution_placeholder: 'cc: author (date)', Caption: 'Caption', Summary: 'Summary', Number_Of_Rows: 'Number of rows', diff --git a/system/wymeditor/lang/nl.js b/system/wymeditor/lang/nl.js index 834fea38..f9d8c239 100644 --- a/system/wymeditor/lang/nl.js +++ b/system/wymeditor/lang/nl.js @@ -28,6 +28,8 @@ WYMeditor.STRINGS.nl = { Title: 'Titel', Relationship: 'Relatie', Alternative_Text: 'Alternatieve tekst', + Attribution: 'Bijdrage', + Attribution_placeholder: 'cc: auteur (datum)', Caption: 'Bijschrift', Summary: 'Summary', Number_Of_Rows: 'Aantal rijen', @@ -53,4 +55,4 @@ WYMeditor.STRINGS.nl = { File: 'File', Preset: 'Preset', -}; \ No newline at end of file +}; diff --git a/system/wymeditor/plugins/image_upload/jquery.wymeditor.image_upload.js b/system/wymeditor/plugins/image_upload/jquery.wymeditor.image_upload.js index fdcc2fb5..fae710df 100644 --- a/system/wymeditor/plugins/image_upload/jquery.wymeditor.image_upload.js +++ b/system/wymeditor/plugins/image_upload/jquery.wymeditor.image_upload.js @@ -29,7 +29,10 @@ WYMeditor.editor.prototype.image_upload = function() { orig.call(this, wDialog); var wym = this, doc = wDialog.document, - options = wym._options; + options = wym._options, + selectedImage = wym.getSelectedImage(); + + jQuery(options.attributionSelector, doc).val(jQuery(selectedImage).attr(options.attributionImgAttribute)); var oldSubmitLabel = jQuery("form#image_upload_form .submit", doc).val(); // WYMEditor automatically locks onto any form here, so remove the binding. @@ -47,12 +50,40 @@ WYMeditor.editor.prototype.image_upload = function() { } else { jQuery(options.srcSelector, doc).val(response.thumbUrl); jQuery(options.altSelector, doc).val(response.original_filename); + jQuery(options.attributionSelector, doc).val(response.attribution); } jQuery("form#image_upload_form .submit", doc).val(oldSubmitLabel); } }) }; + d.submitHandler = function (wDialog) { + var wym = this, + options = wym._options, + imgAttrs, + selectedImage = wym.getSelectedImage(); + + imgAttrs = { + src: jQuery(options.srcSelector, wDialog.document).val(), + title: jQuery(options.titleSelector, wDialog.document).val(), + alt: jQuery(options.altSelector, wDialog.document).val(), + }; + imgAttrs[options.attributionImgAttribute] = jQuery(options.attributionSelector, wDialog.document).val(); + + wym.focusOnDocument(); + + if (selectedImage) { + wym._updateImageAttrs(selectedImage, imgAttrs); + wym.registerModification(); + } else { + wym.insertImage(imgAttrs); + } + wDialog.close(); + } + + wym._options.attributionImgAttribute = 'data-attribution'; + wym._options.attributionSelector = '.wym_attribution'; + // Put together the whole dialog script wym._options.dialogImageHtml = String() + '' + @@ -95,6 +126,10 @@ WYMeditor.editor.prototype.image_upload = function() { '' + '' + '' + + '
' + + '' + + '' + + '
' + '
' + '' + '' +