PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 3.3.4
Pods – Custom Content Types and Fields v3.3.4
trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / ui / fields / currency.php
pods / ui / fields Last commit date
_comment.php 2 years ago _db.php 2 years ago _hidden.php 2 years ago _label.php 1 year ago _row.php 2 years ago attachment.php 1 year ago checkbox.php 1 year ago cleditor.php 2 years ago codemirror.php 2 years ago color.php 2 years ago currency.php 1 year ago date.php 2 years ago datetime.php 2 years ago email.php 1 year ago link.php 1 year ago number.php 1 year ago oembed.php 1 year ago password.php 1 year ago phone.php 1 year ago radio.php 1 year ago select.php 1 year ago slider.php 1 year ago slug.php 2 years ago text.php 1 year ago textarea.php 1 year ago time.php 2 years ago tinymce.php 1 year 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_v( 'currency_format', $options ) ) {
20 $thousands = '';
21 $dot = '.';
22 } elseif ( '9999,99' === pods_v( 'currency_format', $options ) ) {
23 $thousands = '';
24 $dot = ',';
25 } elseif ( '9.999,99' === pods_v( '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