Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media field URL and preview #239

Open
szepeviktor opened this issue Feb 19, 2016 · 5 comments
Open

Media field URL and preview #239

szepeviktor opened this issue Feb 19, 2016 · 5 comments

Comments

@szepeviktor
Copy link

Should I use field_{instantiated class name}_{section id}_{field ID} to put the media link into the input's value?

Is there a way to display preview for media field type?

@szepeviktor szepeviktor changed the title Media filed URL and preview Media field URL and preview Feb 19, 2016
@szepeviktor
Copy link
Author

Wait!
For image type:

The supported attributes are, 'title', 'alt', 'width', 'height', 'caption', 'id', 'align', and 'link'.

For media type only

The supported attributes are, 'id', 'caption', and 'description'.

Would it be possible to support all data that can be set in the "Insert Media" dialog?
'title', 'alt', 'width', 'height', 'caption', 'id', 'align', 'link'
and 'size' also, as it is available.

@michaeluno
Copy link
Owner

Is there a way to display preview for media field type?

There is no preview option for the media field type at the moment.

Would it be possible to support all data that can be set in the "Insert Media" dialog?

Not sure. I'll check.

@michaeluno
Copy link
Owner

When the media uploader dialog is closed, an attachment object is passed to the JavaScript method (

_oMediaUploader.state().get( 'selection' ).each( function( oAttachment, iIndex ) {
) and its attributes property holds the following members (the values are an example).

alt: "Alt value"
author: "1"
authorName: "admin"
caption: "This is a caption."
compat: Object
date: Fri Jan 29 2016 02:22:37 GMT+0900 (Tokyo Standard Time)
dateFormatted: "January 29, 2016"
description: "Descriptions!"
editLink: "http://.../wp-admin/post.php?post=2143&action=edit"
filename: "Penguins.jpg"
filesizeHumanReadable: "760 kB"
filesizeInBytes: 777835
height: 768
icon: "http://.../wp-includes/images/media/default.png"
id: 2143
link: "http://.../penguins/"
menuOrder: 0
meta: false
mime: "image/jpeg"
modified: Sat Feb 20 2016 10:16:24
name: "penguins"
nonces: Object
orientation: "landscape"
sizes: Object
status: "inherit"
subtype: "jpeg"
title: "Penguins"
type: "image"
uploadedTo: 0
url: "http://.../wp-content/uploads/2016/01/Penguins.jpg"
width: 1024

I don't see size and align in that property object so it is hard to set them to the input fields of the form created by the framework.

If you know a way to retrieve them, let me know.

@szepeviktor
Copy link
Author

Coudl it be sizes: Object?

@michaeluno
Copy link
Owner

The sizes property looks like this and no information for which one the user selected.

full: Object
    height: 768
    orientation: "landscape"
    url: "http://.../wp-content/uploads/2016/01/Penguins.jpg"
    width: 1024
    __proto__: Object
large: Object
    height: 469
    orientation: "landscape"
    url: "http://.../wp-content/uploads/2016/01/Penguins-1024x768.jpg"
    width: 625
    __proto__: Object
medium: Object
    height: 225
    orientation: "landscape"
    url: "http://.../wp-content/uploads/2016/01/Penguins-300x225.jpg"
    width: 300
    __proto__: Object
thumbnail: Object
    height: 150
    orientation: "landscape"
    url: "http://.../wp-content/uploads/2016/01/Penguins-150x150.jpg"
    width: 150

You can check the object by inserting console.log( oAttachment ); after the highlighted line posted in the previous reply. You'll find the attributes property.

I've roughly searched the web and could not find a proper way to retrieve all the selected options in the media uploader form including the ones you requested such as size and alignment. It's not impossible to code to retrieve those but if there is already an establish method to retrieve them, it should be used. Let me know if you know it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants