1
|
|
|
<?php |
2
|
|
|
$field_number = PodsForm::field_loader( 'currency' ); |
3
|
|
|
|
4
|
|
|
$value = $field_number->format( $value, $name, $options, $pod, $id ); |
|
|
|
|
5
|
|
|
|
6
|
|
|
$attributes = array(); |
7
|
|
|
$attributes['type'] = 'text'; |
8
|
|
|
$attributes['value'] = $value; |
9
|
|
|
$attributes['tabindex'] = 2; |
10
|
|
|
$attributes = PodsForm::merge_attributes( $attributes, $name, $form_field_type, $options ); |
11
|
|
|
|
12
|
|
|
global $wp_locale; |
|
|
|
|
13
|
|
|
|
14
|
|
|
if ( '9999.99' == pods_var( 'currency_format', $options ) ) { |
15
|
|
|
$thousands = ''; |
16
|
|
|
$dot = '.'; |
17
|
|
|
} elseif ( '9999,99' == pods_var( 'currency_format', $options ) ) { |
18
|
|
|
$thousands = ''; |
19
|
|
|
$dot = ','; |
20
|
|
|
} elseif ( '9.999,99' == pods_var( 'currency_format', $options ) ) { |
21
|
|
|
$thousands = '.'; |
22
|
|
|
$dot = ','; |
23
|
|
|
} else { |
24
|
|
|
$thousands = $wp_locale->number_format['thousands_sep']; |
25
|
|
|
$dot = $wp_locale->number_format['decimal_point']; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$currency = 'usd'; |
29
|
|
|
|
30
|
|
|
if ( isset( PodsField_Currency::$currencies[ pods_var( 'currency_format_sign', $options, - 1 ) ] ) ) { |
31
|
|
|
$currency = pods_var( 'currency_format_sign', $options ); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$currency_sign = PodsField_Currency::$currencies[ $currency ]['sign']; |
35
|
|
|
|
36
|
|
|
echo '<code class="currency-sign">' . $currency_sign . '</code>'; |
37
|
|
|
?> |
38
|
|
|
<input<?php PodsForm::attributes( $attributes, $name, $form_field_type, $options ); ?>/> |
39
|
|
|
<script> |
40
|
|
|
jQuery( function ( $ ) { |
41
|
|
|
var input = $( 'input#<?php echo esc_js( $attributes[ 'id' ] ); ?>' ), |
42
|
|
|
currency_sign = input.siblings( 'code.currency-sign' ); |
43
|
|
|
|
44
|
|
|
input.on( 'blur', function () { |
45
|
|
|
if ( !/^[0-9\<?php |
46
|
|
|
echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) ); |
47
|
|
|
?>]$/.test( $( this ).val() ) ) { |
48
|
|
|
var newval = $( this ) |
49
|
|
|
.val() |
50
|
|
|
.replace( /[^0-9-\\<?php echo esc_js( $currency_sign ); ?>\<?php |
51
|
|
|
echo esc_js( implode( '\\', array_filter( array( $dot, $thousands ) ) ) ); |
52
|
|
|
?>]/g, '' ); |
53
|
|
|
$( this ).val( newval ); |
54
|
|
|
} |
55
|
|
|
} ); |
56
|
|
|
|
57
|
|
|
if ( currency_sign.length ) { |
58
|
|
|
function resize_currency_sign() { |
59
|
|
|
input.css( 'padding-left', parseInt( input.css( 'padding-left' ), 10 ) + currency_sign.width() + 12 ); |
60
|
|
|
currency_sign.css( 'line-height', parseInt( input.innerHeight() ) + 'px' ); |
61
|
|
|
} |
62
|
|
|
$(window).resize( resize_currency_sign ); |
63
|
|
|
resize_currency_sign(); |
64
|
|
|
currency_sign.show(); |
65
|
|
|
} |
66
|
|
|
} ); |
67
|
|
|
</script> |
68
|
|
|
|
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.