Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                <select class="country-select" id="country">
  <option value="AU">Australia</option>
  <option value="NZ">New Zealand</option>
</select>
<input type="search" class="form-input" id="addrs_1" placeholder="Search address here..."></input>
<div id="map"></div>
              
            
!

CSS

              
                html, body {
  margin: 0;
  font-family: 'Open Sans', Arial, Helvetica, sans-serif;
  font-size: 15px;
  color: #6d6d6d;
}

#map {
	position: absolute;
	width: 100%;
  margin-top: 10px;
	height: calc(100% - 55px);
}

#addrs_1 {
  margin-left: 10px;
  margin-top: 10px;
  width: 500px;
  height: 35px;
  font-size: 16px;
  padding-left: 6px;
  box-sizing: border-box;
}

input[type=search] {
  -webkit-appearance: textfield;
  box-sizing: content-box;
}

select {
  background-color: white;
  border: thin solid #CCCCCC;
  display: inline-block;
  color: #757575;
  border-radius: 0;
  font: inherit;
  font-size: 16px;
  height: 35px;
  padding: 0.4em 4.5em 0.5em 6px;

  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  -webkit-appearance: none;
  -moz-appearance: none;
}

select.country-select {
  background-image:
    linear-gradient(45deg, transparent 50%, #757575 50%),
    linear-gradient(135deg, #757575 50%, transparent 50%),
    linear-gradient(to right, #CCCCCC, #CCCCCC);
  background-position:
    calc(100% - 20px) calc(1em),
    calc(100% - 15px) calc(1em),
    calc(100% - 2.5em) 0.4em;
  background-size:
    5px 5px,
    5px 5px,
    1px 1.5em;
  background-repeat: no-repeat;
  margin-left: 10px;
}
              
            
!

JS

              
                (function(d){
  var addressField = d.getElementById('addrs_1'),
      countrySelect = d.getElementById('country'),
      AFAPIkeys = {
        AU: 'ADDRESSFINDER_DEMO_KEY',
        NZ: 'ADDRESSFINDER_DEMO_KEY'
      },
      widgets = {
        AU: null,
        NZ: null
      },
      map = null,
      infoWindow = null,
      marker = null;

  
  // ADDRESS FINDER WIDGET INTEGRATION
  
  function initAF(){
    widgets['AU'] = new AddressFinder.Widget(
      addressField,
      AFAPIkeys['AU'],
      'AU'
    );
    scrollToLocationOnMap(widgets['AU'], 'AU')
    
    widgets['NZ'] = new AddressFinder.Widget(
      addressField,
      AFAPIkeys['NZ'],
      'NZ'
    );
    scrollToLocationOnMap(widgets['NZ'], 'NZ')

    setWidgetState(); // Set the initial state for the form
    countrySelect.addEventListener('change', setWidgetState);
  }
  
  function disableWidgets() {
    widgets['AU'].disable();
    widgets['NZ'].disable();
  }
  
  function setWidgetState(){
    disableWidgets(); // disable both widgets first
    
    var countryCode = countrySelect.options[countrySelect.selectedIndex].getAttribute('value'); 
    if (countryCode) {
      // selectively enable the right widget
      widgets[countryCode].enable();
    }
  }

  
  // GOOGLE MAPS INTEGRATION
  
  function initMap() {
    var myLatLng = getGoogleLatLng(-29.7014833, 144.1768874),
    mapOptions = {
      zoom: 5,
      center: myLatLng,
    }
    map = new google.maps.Map(document.getElementById('map'), mapOptions);
  }
  
  function scrollToLocationOnMap(widget, countryCode) {
    widget.on('result:select', function(fullAddress, metaData) {
      if (marker) {marker.setMap(null);} // Remove multiple markers
      
      // latitude is present in AU widget but is named 'y' in NZ widget
      var googleLatLng = metaData.latitude ? getGoogleLatLng(metaData.latitude, metaData.longitude) : getGoogleLatLng(metaData.y, metaData.x)
      // full_address is present in AU widget but full address in NZ widget is available at 'a'
      var address = metaData.full_address ? metaData.full_address : metaData.a
      
      infoWindow = new google.maps.InfoWindow({
        content: address,
        maxWidth: 300
      })
      
      map.setCenter(googleLatLng);
      map.setZoom(16);
      marker = new google.maps.Marker({
        position: googleLatLng,
        map: map
      });
      
      // Make it open by default
      infoWindow.open(map, marker);
      addEventListeners()
    });
  }
  
  function addEventListeners() {
    // Allows you to reopen the window if you click on the marker again
    google.maps.event.addListener(marker, 'click', function() {
      infoWindow.open( map, marker );
    });
  }
  
  function getGoogleLatLng(lat, lng) {
    return new google.maps.LatLng(lat, lng)
  }
  
  
  // SETUP FUNCTIONS
  
  function initialise() {
    initMap()
    initAF()
  }
  
  function addAF() {
    var script = document.createElement('script');
    script.src = 'https://api.addressfinder.io/assets/v3/widget.js';
    script.async = true;
    script.onload = initialise;
    document.body.appendChild(script);
  }
  
  function addGMaps(){
    var script = document.createElement('script');
    script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp';
    script.async = true;
    script.onload = addAF;
    document.body.appendChild(script);
  }
  
  addGMaps()

})(document);
              
            
!
999px

Console