Skip to content

Commit

Permalink
Fixes for currency formatting according to #150
Browse files Browse the repository at this point in the history
  • Loading branch information
devin committed Jun 3, 2015
1 parent 48ce882 commit ab3b710
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 58 deletions.
24 changes: 20 additions & 4 deletions assets/css/give-admin.css

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

2 changes: 1 addition & 1 deletion assets/css/give-admin.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/css/give-admin.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/frontend/give-checkout-global.min.js

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

33 changes: 28 additions & 5 deletions assets/scss/admin/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ Forms CPT
}

/* Table Rows */
div.cmb-type-levels-repeater-header {
border: none;
}

div.cmb-type-levels-repeater-header + div.cmb-repeat-group-wrap {
padding: 0 !important;
margin: 0 !important;
Expand All @@ -38,10 +34,12 @@ div.cmb-type-levels-repeater-header + div.cmb-repeat-group-wrap {

}

//Mulilevel Repeater Header
.cmb2-id--give-levels-header {
padding: 10px 12px 0 !important;
margin: 0 !important;
background: #F7F7F7;
border-bottom: none !important;

.table-container {
display: table;
Expand Down Expand Up @@ -97,10 +95,35 @@ div.cmb-type-levels-repeater-header + div.cmb-repeat-group-wrap {

}

//---------------------------------------------------
//Field One Offs
//---------------------------------------------------
.give-time-field {
width: 65px;
}

.give-money-field {
width: 75px;
margin-right: 0;
margin-left: 0;
}

.give-money-symbol {
border: 1px solid #e9e9e9;
background: #FCFCFC;
margin: 0;
font-size: 14px;
padding: 5px 8px;
}

.give-money-symbol-before {
border-right: 0;
}

.give-money-symbol-after {
border-left: 0;
}

p.give-level-id {
border-radius: 50%;
border: 1px solid #e9e9e9;
Expand All @@ -117,7 +140,7 @@ p.give-level-id {
}
.cmb-td {
padding-right: 10px;
box-sizing: border-box;
box-sizing: border-box;
}

}
Expand Down
52 changes: 28 additions & 24 deletions includes/admin/forms/metabox.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'name' => __( 'Set Donation', 'give' ),
'description' => __( 'This is the set donation amount for this form.', 'give' ),
'id' => $prefix . 'set_price',
'type' => 'text_money',
'type' => 'text_small',
'row_classes' => 'give-subfield',
'before_field' => give_currency_symbol(), // Replaces default '$'
'before_field' => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
'after_field' => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
'attributes' => array(
'placeholder' => give_format_amount( '0.00' ),
'value' => isset( $price ) ? esc_attr( give_format_amount( $price ) ) : '',
'class' => 'cmb-type-text-small give-money-field',
),
),
//Donation levels: Header
Expand Down Expand Up @@ -93,10 +95,12 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
array(
'name' => __( 'Amount', 'give' ),
'id' => $prefix . 'amount',
'type' => 'text_money',
'before_field' => give_currency_symbol(), // Replaces default '$'
'type' => 'text_small',
'before_field' => give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '',
'after_field' => give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '',
'attributes' => array(
'placeholder' => give_format_amount( '0.00' ),
'class' => 'cmb-type-text-small give-money-field',
),
'before' => 'give_format_admin_multilevel_amount',
),
Expand Down Expand Up @@ -169,19 +173,19 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'description' => __( 'This is the goal you want to achieve for this form.', 'give' ),
'id' => $prefix . 'set_goal',
'type' => 'text_money',
'row_classes' => 'give-subfield',
'row_classes' => 'give-subfield',
'before_field' => give_currency_symbol(), // Replaces default '$'
'attributes' => array(
'placeholder' => give_format_amount( '0.00' ),
'value' => isset( $goal ) ? esc_attr( give_format_amount( $goal ) ) : '',
),
),
array(
'name' => __( 'Goal Progress Bar Color', 'give' ),
'id' => $prefix . 'goal_color',
'type' => 'colorpicker',
'name' => __( 'Goal Progress Bar Color', 'give' ),
'id' => $prefix . 'goal_color',
'type' => 'colorpicker',
'row_classes' => 'give-subfield',
'default' => '#2bc253',
'default' => '#2bc253',
),
)
)
Expand Down Expand Up @@ -248,12 +252,12 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'default' => 'onpage',
),
array(
'id' => $prefix . 'reveal_label',
'name' => __( 'Reveal / Modal Open Text', 'give' ),
'desc' => __( 'The button label for completing the donation.', 'give' ),
'type' => 'text_small',
'id' => $prefix . 'reveal_label',
'name' => __( 'Reveal / Modal Open Text', 'give' ),
'desc' => __( 'The button label for completing the donation.', 'give' ),
'type' => 'text_small',
'row_classes' => 'give-subfield',
'attributes' => array(
'attributes' => array(
'placeholder' => __( 'Donate Now', 'give' ),
),
),
Expand Down Expand Up @@ -320,22 +324,22 @@ function give_single_forms_cmb2_metaboxes( array $meta_boxes ) {
'default' => 'none',
),
array(
'id' => $prefix . 'agree_label',
'name' => __( 'Agree to Terms Label', 'give' ),
'desc' => __( 'Label shown next to the agree to terms check box.', 'give' ),
'type' => 'text',
'id' => $prefix . 'agree_label',
'name' => __( 'Agree to Terms Label', 'give' ),
'desc' => __( 'Label shown next to the agree to terms check box.', 'give' ),
'type' => 'text',
'row_classes' => 'give-subfield',
'size' => 'regular',
'attributes' => array(
'size' => 'regular',
'attributes' => array(
'placeholder' => __( 'Agree to Terms?', 'give' ),
),
),
array(
'id' => $prefix . 'agree_text',
'id' => $prefix . 'agree_text',
'row_classes' => 'give-subfield',
'name' => __( 'Agreement Text', 'give' ),
'desc' => __( 'This is the actual text which the user will have to agree to.', 'give' ),
'type' => 'wysiwyg'
'name' => __( 'Agreement Text', 'give' ),
'desc' => __( 'This is the actual text which the user will have to agree to.', 'give' ),
'type' => 'wysiwyg'
),
)
)
Expand Down
10 changes: 2 additions & 8 deletions includes/formatting.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* @return string $amount Newly sanitized amount
*/
function give_sanitize_amount( $amount ) {
global $give_options;

$is_negative = false;
$thousands_sep = give_get_option( 'thousands_separator', ',' );
$decimal_sep = give_get_option( 'decimal_separator', '.' );
Expand Down Expand Up @@ -71,8 +69,6 @@ function give_sanitize_amount( $amount ) {
* @return string $amount Newly formatted amount or Price Not Available
*/
function give_format_amount( $amount, $decimals = true ) {
global $give_options;

$thousands_sep = give_get_option( 'thousands_separator', ',' );
$decimal_sep = give_get_option( 'decimal_separator', '.' );

Expand All @@ -98,7 +94,7 @@ function give_format_amount( $amount, $decimals = true ) {
$amount = 0;
}

$decimals = apply_filters( 'give_format_amount_decimals', $decimals ? 2 : 0, $amount );
$decimals = apply_filters( 'give_format_amount_decimals', $decimals ? 2 : 0, $amount );
$formatted = number_format( $amount, $decimals, $decimal_sep, $thousands_sep );

return apply_filters( 'give_format_amount', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep );
Expand Down Expand Up @@ -132,15 +128,13 @@ function give_format_admin_multilevel_amount( $field_args, $field ) {
* @return array $currency Currencies displayed correctly
*/
function give_currency_filter( $price = '', $currency = '' ) {
global $give_options;

if ( empty( $currency ) ) {

$currency = give_get_currency();

}

$position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
$position = give_get_option( 'currency_position', 'before' );

$negative = $price < 0;

Expand Down
8 changes: 2 additions & 6 deletions includes/forms/template.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ function give_output_donation_levels( $form_id = 0, $args = array() ) {
$currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
$symbol = isset( $give_options['currency'] ) ? give_currency_symbol( $give_options['currency'] ) : '$';
$currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
$default_amount = give_get_default_form_amount( $form_id );
$default_amount = give_format_amount(give_get_default_form_amount( $form_id ) );
$custom_amount_text = get_post_meta( $form_id, '_give_custom_amount_text', true );


do_action( 'give_before_donation_levels', $form_id );

//Set Price, No Custom Amount Allowed means hidden price field
Expand All @@ -243,11 +242,9 @@ function give_output_donation_levels( $form_id = 0, $args = array() ) {
<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount" value="<?php echo $default_amount; ?>" required>
<p class="set-price give-donation-amount form-row-wide">
<?php

if ( $currency_position == 'before' ) {
echo $currency_output;
}

?>
<span id="give-amount" class="give-text-input"><?php echo give_format_amount( $default_amount ); ?></span>
</p>
Expand All @@ -264,7 +261,7 @@ function give_output_donation_levels( $form_id = 0, $args = array() ) {
}
?>

<input class="give-text-input" id="give-amount" name="give-amount" type="text" placeholder="" value="<?php echo $default_amount; ?>" required autocomplete="off">
<input class="give-text-input" id="give-amount" name="give-amount" type="text" placeholder="" value="<?php echo $default_amount; ?>" required autocomplete="off">

<?php if ( $currency_position == 'after' ) {
echo $currency_output;
Expand All @@ -273,7 +270,6 @@ function give_output_donation_levels( $form_id = 0, $args = array() ) {
<p class="give-loading-text give-updating-price-loader" style="display: none;">
<span class="give-loading-animation"></span> <?php _e( 'Updating Price', 'Give' ); ?>
<span class="elipsis">.</span><span class="elipsis">.</span><span class="elipsis">.</span></p>

</div>
</div>
<?php }
Expand Down
Loading

0 comments on commit ab3b710

Please sign in to comment.