Skip to content

Instantly share code, notes, and snippets.

@darylldoyle
Created August 1, 2014 16:23
Show Gist options
  • Select an option

  • Save darylldoyle/16f2a56faf30ce050fa5 to your computer and use it in GitHub Desktop.

Select an option

Save darylldoyle/16f2a56faf30ce050fa5 to your computer and use it in GitHub Desktop.

Revisions

  1. darylldoyle created this gist Aug 1, 2014.
    28 changes: 28 additions & 0 deletions adminMaps.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    var googleMapsLoaded = false;
    var timeout;

    if(googleMapsLoaded === false) {
    timeout = setInterval("checkVariable()", 500);
    }

    function doGoogleMapsHook() {
    // set current zoom level
    var currentZoom = parseInt(jQuery('#acf-field-zoom_level').val());
    acf.fields.google_map.map.setZoom(currentZoom);
    // disable scrollwheel zooming
    acf.fields.google_map.map.setOptions({'scrollwheel': false});
    // update zoom level in field on change
    google.maps.event.addListener( acf.fields.google_map.map, 'zoom_changed', function( e ) {
    var zoom = acf.fields.google_map.map.zoom;
    // update input
    jQuery('#acf-field-zoom_level').val( zoom );
    });
    }

    function checkVariable() {
    if((typeof google !== 'undefined') && (acf.fields.google_map.map)){
    googleMapsLoaded = true;
    clearInterval(timeout);
    doGoogleMapsHook();
    }
    }
    8 changes: 8 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    <?php

    function jsAdminMaps($hook) {
    if( 'post.php' != $hook )
    return;
    wp_enqueue_script( 'jsAdminMapsCustom', get_template_directory_uri() . '/js/adminMaps.js', array('jquery'), '0.0.1', true );
    }
    add_action( 'admin_enqueue_scripts', 'jsAdminMaps' );