Skip to content

Commit

Permalink
Added info metadata button for preview images. Fixed preview of images
Browse files Browse the repository at this point in the history
  • Loading branch information
w00fz committed Jun 22, 2017
1 parent 796c9d9 commit dbdd6e2
Show file tree
Hide file tree
Showing 21 changed files with 121 additions and 306 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
1. [](#new)
* New `Admin::getPageMedia()` static method that can be used in blueprints
* Added a new `mediapicker` form field which allows to select a media from any page [#1125](https://github.com/getgrav/grav-plugin-admin/pull/1125)
* Added info metadata button for images to view EXIF and other useful details about an image
1. [](#improved)
* Pass original image filename via the `AdminController::taskListedia()` task
* Various form styling improvements
Expand Down
1 change: 1 addition & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ protected function initializeAdmin()
'DROP_FILES_HERE_TO_UPLOAD',
'DELETE',
'INSERT',
'METADATA',
'VIEW',
'UNDO',
'REDO',
Expand Down
1 change: 1 addition & 0 deletions languages/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ PLUGIN_ADMIN:
CANNOT_ADD_FILES_PAGE_NOT_SAVED: "NOTE: Page must be saved before you can upload files to it."
DROP_FILES_HERE_TO_UPLOAD: "Drop your files here or <strong>click in this area</strong>"
INSERT: "Insert"
METADATA: "Metadata"
UNDO: "Undo"
REDO: "Redo"
HEADERS: "Headers"
Expand Down
1 change: 1 addition & 0 deletions themes/grav/app/forms/fields/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const DropzoneMediaConfig = {
<div class="dz-error-mark"><span>✘</span></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
<a class="dz-remove" title="${translations.PLUGIN_ADMIN.DELETE}" href="javascript:undefined;" data-dz-remove>${translations.PLUGIN_ADMIN.DELETE}</a>
<a class="dz-metadata" title="${translations.PLUGIN_ADMIN.METADATA}" href="#" target="_blank" data-dz-metadata>${translations.PLUGIN_ADMIN.METADATA}</a>
<a class="dz-view" title="${translations.PLUGIN_ADMIN.VIEW}" href="#" target="_blank" data-dz-view>${translations.PLUGIN_ADMIN.VIEW}</a>
</div>`.trim()
};
Expand Down
29 changes: 28 additions & 1 deletion themes/grav/app/pages/page/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const previewTemplate = `
<div class="dz-error-mark"><span>✘</span></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
<a class="dz-remove" title="${translations.PLUGIN_ADMIN.DELETE}" href="javascript:undefined;" data-dz-remove>${translations.PLUGIN_ADMIN.DELETE}</a>
<a class="dz-metadata" title="${translations.PLUGIN_ADMIN.METADATA}" href="#" target="_blank" data-dz-metadata>${translations.PLUGIN_ADMIN.METADATA}</a>
<a class="dz-view" title="${translations.PLUGIN_ADMIN.VIEW}" href="#" target="_blank" data-dz-view>${translations.PLUGIN_ADMIN.VIEW}</a>
<a class="dz-insert" title="${translations.PLUGIN_ADMIN.INSERT}" href="javascript:undefined;" data-dz-insert>${translations.PLUGIN_ADMIN.INSERT}</a>
</div>`.trim();
Expand Down Expand Up @@ -100,8 +101,34 @@ export default class PageMedia extends FilesField {
let file = target.parent('.dz-preview').find('.dz-filename');
let filename = encodeURI(file.text());
let URL = target.closest('[data-media-path]').data('media-path');
let original = this.dropzone.files.filter((file) => file.name === filename).shift().extras.original;

target.attr('href', `${URL}/${filename}`);
target.attr('href', `${URL}/${original}`);
});

this.container.delegate('[data-dz-metadata]', 'click', (e) => {
e.preventDefault();
const target = $(e.currentTarget);
const file = target.parent('.dz-preview').find('.dz-filename');
const filename = encodeURI(file.text());

let fileObj = this.dropzone.files.filter((file) => file.name === filename).shift() || {};
if (!fileObj.extras) { return false; }

fileObj = fileObj.extras;

const modal_element = $('body').find('[data-remodal-id="metadata"]');
const modal = $.remodal.lookup[modal_element.data('remodal')];

modal_element.find('h1 strong').html(filename);
modal_element.find('.meta-preview').html(`<img src="${fileObj.url}" />`);

const container = modal_element.find('.meta-content').html('<ul />').find('ul');
Object.keys(fileObj.metadata).forEach((meta) => {
container.append(`<li><strong>${meta}</strong>: ${fileObj.metadata[meta]}</li>`);
});

modal.open();
});

this.container.delegate('.dz-preview', 'dragstart', (e) => {
Expand Down
2 changes: 1 addition & 1 deletion themes/grav/css-compiled/fonts.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions themes/grav/css-compiled/fonts.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion themes/grav/css-compiled/nucleus.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit dbdd6e2

@axel-rank
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at the moment modal preview opens only if I click on the i metadata and not for the image.
should be modal for the image too.

Please sign in to comment.