Skip to content

Commit

Permalink
wymeditor: Adds attribution to image dialog
Browse files Browse the repository at this point in the history
Fixes #119
  • Loading branch information
laurensmartina committed Oct 6, 2020
1 parent c98967a commit 55cfe02
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions system/wymeditor/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ WYMeditor.STRINGS.en = {
Title: 'Title',
Relationship: 'Relationship',
Alternative_Text: 'Alternative text',
Attribution: 'Attribution',
Attribution_placeholder: 'license: author (date)',
Caption: 'Caption',
Summary: 'Summary',
Number_Of_Rows: 'Number of rows',
Expand Down
4 changes: 3 additions & 1 deletion system/wymeditor/lang/nl.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ WYMeditor.STRINGS.nl = {
Title: 'Titel',
Relationship: 'Relatie',
Alternative_Text: 'Alternatieve tekst',
Attribution: 'Bijdrage',
Attribution_placeholder: 'licentie: auteur (datum)',
Caption: 'Bijschrift',
Summary: 'Summary',
Number_Of_Rows: 'Aantal rijen',
Expand All @@ -53,4 +55,4 @@ WYMeditor.STRINGS.nl = {
File: 'File',

Preset: 'Preset',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
WYMeditor.editor.prototype.image_upload = function() {
var wym = this;
var uploadUrl = wym._options.dialogImageUploadUrl;

wym._options.attributionImgAttribute = 'data-attribution';
wym._options.attributionSelector = '.wym_attribution';

// Check the options
if (uploadUrl == undefined) {
WYMeditor.console.warn(
Expand All @@ -29,7 +33,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.
Expand All @@ -47,12 +54,37 @@ 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();
}

// Put together the whole dialog script
wym._options.dialogImageHtml = String() +
'<body class="wym_dialog wym_dialog_image">' +
Expand Down Expand Up @@ -95,6 +127,10 @@ WYMeditor.editor.prototype.image_upload = function() {
'<label>{Title}</label>' +
'<input type="text" class="wym_title" value="" size="40" />' +
'</div>' +
'<div class="row">' +
'<label>{Attribution}</label>' +
'<input type="text" class="wym_attribution" value="" size="40" placeholder="{Attribution_placeholder}" />' +
'</div>' +
'<div class="row row-indent">' +
'<input class="wym_submit" type="submit" ' + 'value="{Submit}" />' +
'<input class="wym_cancel" type="button" ' + 'value="{Cancel}" />' +
Expand Down

0 comments on commit 55cfe02

Please sign in to comment.