Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

use select field for ratings if IE11 #81

Merged
merged 3 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion assets/css/adventure.css

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

47 changes: 39 additions & 8 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,53 @@ function amp_travel_enqueue_styles() {
}
add_action( 'wp_enqueue_scripts', 'amp_travel_enqueue_styles' );


/**
* Add rating field to comments.
* Add star rating field to comments.
*/
function amp_travel_comment_rating_field() {
function amp_travel_comment_star_rating_field() {
?>
<p class="comment-form-rating">
<label><?php esc_html_e( 'Your rating', 'travel' ); ?></label>
<fieldset class="rating">
<?php for ( $i = 5; $i >= 1; $i -- ) : ?>
<input name="rating" type="radio" id="rating<?php echo esc_attr( $i ); ?>" value="<?php echo esc_attr( $i ); ?>" />
<label for="rating<?php echo esc_attr( $i ); ?>">☆</label>
<?php endfor; ?>
</fieldset>
<fieldset class="rating">
<?php for ( $i = 5; $i >= 1; $i -- ) : ?>
<input name="rating" type="radio" id="rating<?php echo esc_attr( $i ); ?>" value="<?php echo esc_attr( $i ); ?>" />
<label for="rating<?php echo esc_attr( $i ); ?>">☆</label>
<?php endfor; ?>
</fieldset>
</p>
<?php
}

/**
* Add select rating field to comments.
*/
function amp_travel_comment_select_rating_field() {
echo '<p class="comment-form-rating-select"><label for="rating">' . esc_html( 'Your rating' ) . '</label>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be:

esc_html__( 'Your rating', 'travel' )

<select required="required" class="select-arr rounded" name="rating" id="rating" [disabled]="commentform_post_' . esc_attr( get_the_ID() ) . '.submitting" on=\'change:AMP.setState( { commentform_post_' . esc_attr( get_the_ID() ) . ': { values: { "rating": event.value } } } )\'>
<option value="">--</option>';

for ( $i = 5; $i >= 1; $i-- ) {
/* translators: %d: Rating */
echo '<option value="' . esc_attr( $i ) . '">' . sprintf( esc_html( _n( '%d star', '%d stars', $i, 'travel' ) ), esc_html( number_format_i18n( $i ) ) ) . '</option>';
}
echo '</select>
</p>';
}

/**
* Add star or select rating field to comments.
*/
function amp_travel_comment_rating_field() {
global $is_IE;
if ( true === $is_IE ) {
// add the legacy select field type.
amp_travel_comment_select_rating_field();
} else {
// add the star rating field type.
amp_travel_comment_star_rating_field();
}
}
add_action( 'comment_form_logged_in_after', 'amp_travel_comment_rating_field' );
add_action( 'comment_form_after_fields', 'amp_travel_comment_rating_field' );

Expand Down