diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..c947305 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/README.md b/README.md index 38108ec..9d6a10d 100644 --- a/README.md +++ b/README.md @@ -35,5 +35,5 @@ There are 4 returnable values for this field which include: ## Todo - - [ ] Variants and subsets need to prefill with saved values. + - [x] Variants and subsets need to prefill with saved values. - [ ] Upgrade Google CSS API from v1 to v2. diff --git a/acf-google-fonts.php b/acf-google-fonts.php index 98bcbf7..d7ad88c 100644 --- a/acf-google-fonts.php +++ b/acf-google-fonts.php @@ -3,7 +3,7 @@ /** * Plugin Name: Advanced Custom Fields: Google Fonts * Description: A field for Advanced Custom Fields (ACF) allowing users to select fonts from the Google Fonts suite. - * Version: 1.0.0 + * Version: 1.0.1 * Plugin URI: https://github.com/skapecollective/acf-google-fonts/ * Author: Skape Collective * Author URI: https://skape.co/ @@ -23,7 +23,7 @@ // Register global constants AcfGoogleFonts\Wrappers\Constants::set( 'FILE', __FILE__ ); AcfGoogleFonts\Wrappers\Constants::set( 'DEBUG', defined( 'WP_DEBUG' ) && WP_DEBUG ); -AcfGoogleFonts\Wrappers\Constants::set( 'VERSION', '1.0.0' ); +AcfGoogleFonts\Wrappers\Constants::set( 'VERSION', '1.0.1' ); AcfGoogleFonts\Wrappers\Constants::set( 'PATH', plugin_dir_path( __FILE__ ) ); AcfGoogleFonts\Wrappers\Constants::set( 'URL', plugin_dir_url( __FILE__ ) ); AcfGoogleFonts\Wrappers\Constants::set( 'BASENAME', plugin_basename( __FILE__ ) ); diff --git a/assets/js/field.js b/assets/js/field.js index 2b83810..70e9759 100644 --- a/assets/js/field.js +++ b/assets/js/field.js @@ -8,6 +8,7 @@ const $container = $field.find( '.acf-google_fonts' ); const $select = $container.find( '.acf-google_fonts-choice select' ); const $preview = $container.find( '.acf-google_fonts-preview' ); + const data = JSON.parse( $container.find( '.acf-google_fonts-js_data' ).text() ); // Initiate select2 $select.select2(); @@ -15,11 +16,6 @@ const checkboxTypes = [ 'variants', 'subsets' ]; var request = null; - const name = $select.data( 'js-name' ); - const key = $select.data( 'js-key' ); - const action = $select.data( 'js-action' ); - const token = $select.data( 'js-token' ); - const handleError = ( response ) => console.log( response ); const handleSuccess = ( response ) => { @@ -72,19 +68,21 @@ class: 'acf-google_fonts-list' } ).appendTo( $type ); + let currentValue = 'values' in data && type in data.values ? data.values[ type ] : null; + for ( var value in response.data[ type ] ) { const label = response.data[ type ][ value ]; - const id = `_${key}_${type}_${value}`; + const id = `_${data.id}_${type}_${value}`; const $li = $( '
  • ' ).appendTo( $ul ); $( '', { type: 'checkbox', - name: `${name}[${type}][]`, + name: `${data.name}[${type}][]`, value: value, id: id - } ).appendTo( $li ); + } ).appendTo( $li ).prop( 'checked', Array.isArray( currentValue ) ? currentValue.includes( value ) : false ); $( '
  • ").appendTo(o);a("",{type:"checkbox",name:"".concat(j,"[").concat(m,"][]"),value:p,id:r}).appendTo(s),a("
    ",{contenteditable:!0,text:k||b._e("google_fonts","preview_text"),style:"font-family: ".concat(c.data.family,";")}).appendTo(d),a("",{href:c.data.infoUrl,target:"_blank",text:b._e("google_fonts","preview_link")}).appendTo(f)}for(var l=0;l",{class:"acf-google_fonts-list"}).appendTo(n),p="values"in h&&m in h.values?h.values[m]:null;for(var q in c.data[m]){var r=c.data[m][q],s="_".concat(h.id,"_").concat(m,"_").concat(q),t=a("
  • ").appendTo(o);a("",{type:"checkbox",name:"".concat(h.name,"[").concat(m,"][]"),value:q,id:s}).appendTo(t).prop("checked",!!Array.isArray(p)&&p.includes(q)),a("