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
Field background: support showing image thumbnail instead of URL #1421
Field background: support showing image thumbnail instead of URL #1421
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ở task này e nên làm cho field file_input
, khi đó nó sẽ tự động dùng được cho cả field background luôn e ạ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A có comment nhé, e update nhé.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update tiếp e nhé.
inc/fields/file-input.php
Outdated
@@ -35,16 +35,23 @@ public static function admin_enqueue_scripts() { | |||
*/ | |||
public static function html( $meta, $field ) { | |||
$attributes = self::get_attributes( $field, $meta ); | |||
$file_ext = strtolower( end( explode( '.', $meta ) ) ); | |||
$expensions = [ 'jpeg', 'jpg', 'png', 'gif' ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sửa tên biến nhé, viết sai chính tả :(.
inc/fields/file-input.php
Outdated
</div>', | ||
self::render_attributes( $attributes ), | ||
esc_html__( 'Select', 'meta-box' ), | ||
$meta ? '' : 'hidden', | ||
esc_html__( 'Remove', 'meta-box' ) | ||
esc_html__( 'Remove', 'meta-box' ), | ||
( !in_array( $file_ext, $expensions ) || empty( $meta ) ) ? 'rwmb-file-input-hidden-image' : '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Chỗ điều kiện e nên sửa lại thành in_array( $file_ext, $extensions )
(tức là viết ngược lại). Viết dùng phủ định đọc ko xuôi. Khi viết ntn thì ko cần check empty( $meta )
nữa. Tên class e cũng để gọn thôi, rwmb-file-input-hidden
.
$el.closest( '.rwmb-file-input-inner' ).siblings( '.rwmb-file-input-image' ).removeClass( 'rwmb-file-input-hidden-image' ).html( '<img src="'+ url +'">' ) ; | ||
} else { | ||
$el.closest( '.rwmb-file-input-inner' ).siblings( '.rwmb-file-input-image' ).addClass( 'rwmb-file-input-hidden-image' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E viết ít chữ var
đi nhé, và chỗ select cái image ý, cho nó vào 1 biến cho ngắn gọn nhé. Và có cần phải thay hẳn html
của img
ko? Hay chỉ cần update src
cho nó là đc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sửa nốt đã chứ!
No description provided.