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

Field background: support showing image thumbnail instead of URL #1421

Merged

Conversation

lexuanbao161096
Copy link
Contributor

No description provided.

Copy link
Member

@rilwis rilwis left a 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 ạ.

Copy link
Member

@rilwis rilwis left a 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é.

inc/fields/file-input.php Outdated Show resolved Hide resolved
inc/fields/file-input.php Show resolved Hide resolved
js/file-input.js Show resolved Hide resolved
Copy link
Member

@rilwis rilwis left a 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é.

@@ -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' ];
Copy link
Member

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ả :(.

</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' : '',
Copy link
Member

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' );
}
Copy link
Member

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?

Copy link
Member

@rilwis rilwis left a 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ứ!

@rilwis rilwis merged commit ad11cfd into master Dec 24, 2021
@rilwis rilwis deleted the feature/background-field-show-selected-image-in-backend branch December 24, 2021 08:13
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

Successfully merging this pull request may close these issues.

None yet

2 participants