_comment.php
2 years ago
_db.php
2 years ago
_hidden.php
2 years ago
_label.php
2 years ago
_row.php
2 years ago
attachment.php
2 years ago
checkbox.php
2 years ago
cleditor.php
2 years ago
codemirror.php
2 years ago
color.php
2 years ago
currency.php
2 years ago
date.php
2 years ago
datetime.php
2 years ago
email.php
2 years ago
link.php
2 years ago
number.php
2 years ago
oembed.php
2 years ago
password.php
2 years ago
phone.php
2 years ago
radio.php
2 years ago
select.php
2 years ago
slider.php
2 years ago
slug.php
2 years ago
text.php
2 years ago
textarea.php
2 years ago
time.php
2 years ago
tinymce.php
2 years ago
website.php
2 years ago
currency.php
87 lines
| 1 | <?php |
| 2 | // Don't load directly. |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | die( '-1' ); |
| 5 | } |
| 6 | |
| 7 | $field_number = PodsForm::field_loader( 'currency' ); |
| 8 | |
| 9 | $value = $field_number->format( $value, $name, $options, $pod, $id ); |
| 10 | |
| 11 | $attributes = array(); |
| 12 | $attributes['type'] = 'text'; |
| 13 | $attributes['value'] = $value; |
| 14 | $attributes['tabindex'] = 2; |
| 15 | $attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
| 16 | |
| 17 | global $wp_locale; |
| 18 | |
| 19 | if ( '9999.99' == pods_var( 'currency_format', $options ) ) { |
| 20 | $thousands = ''; |
| 21 | $dot = '.'; |
| 22 | } elseif ( '9999,99' == pods_var( 'currency_format', $options ) ) { |
| 23 | $thousands = ''; |
| 24 | $dot = ','; |
| 25 | } elseif ( '9.999,99' == pods_var( 'currency_format', $options ) ) { |
| 26 | $thousands = '.'; |
| 27 | $dot = ','; |
| 28 | } else { |
| 29 | $thousands = $wp_locale->number_format['thousands_sep']; |
| 30 | $dot = $wp_locale->number_format['decimal_point']; |
| 31 | } |
| 32 | |
| 33 | $currency = 'usd'; |
| 34 | |
| 35 | $currency_format_sign = pods_v( 'currency_format_sign', $options, $currency ); |
| 36 | |
| 37 | $currencies = PodsField_Currency::data_currencies(); |
| 38 | |
| 39 | if ( isset( $currencies[ $currency_format_sign ] ) ) { |
| 40 | $currency = $currency_format_sign; |
| 41 | } |
| 42 | |
| 43 | $currency_sign = $currencies[ $currency ]['sign']; |
| 44 | ?> |
| 45 | <div class="pods-currency-container"> |
| 46 | <code class="pods-currency-sign pods-hidden"><?php echo $currency_sign; ?></code> |
| 47 | <input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>/> |
| 48 | </div> |
| 49 | <script> |
| 50 | jQuery( function ( $ ) { |
| 51 | var input = $( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ), |
| 52 | currency_sign = input.siblings( 'code.pods-currency-sign' ); |
| 53 | |
| 54 | input.on( 'blur', function () { |
| 55 | if ( !/^[0-9\<?php |
| 56 | echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) ); |
| 57 | ?>]$/.test( $( this ).val() ) ) { |
| 58 | var newval = $( this ) |
| 59 | .val() |
| 60 | .replace( /[^0-9-\<?php |
| 61 | echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) ); |
| 62 | ?>]/g, '' ); |
| 63 | $( this ).val( newval ); |
| 64 | } |
| 65 | } ); |
| 66 | |
| 67 | if ( currency_sign.length ) { |
| 68 | currency_sign.removeClass( 'pods-hidden' ); |
| 69 | |
| 70 | function resize_currency_sign() { |
| 71 | if ( currency_sign.width() < 1 ) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | input.css( 'padding-left', currency_sign.width() + 12 ); |
| 76 | currency_sign.css( 'line-height', parseInt( input.innerHeight(), 10 ) + 'px' ); |
| 77 | } |
| 78 | |
| 79 | // Cover most events we need. |
| 80 | $(window).on( 'resize load visibilitychange postbox-toggled postbox-columnchange postboxes-columnchange', resize_currency_sign ); |
| 81 | |
| 82 | // Gutenberg show/hide panels do not trigger any known events, this is one final hackaround for that. |
| 83 | input.on( 'hover focus', resize_currency_sign ); |
| 84 | } |
| 85 | } ); |
| 86 | </script> |
| 87 |