octocatstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource
via CSS Lint

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource
via JS Hint

Code Indentation

     

Save Automatically?

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

Want a Run Button?

If active, the preview will update automatically when you change code.

HTML

            
              <!-- 

Note that this example has been updated for v1.0.0 of conditioner.js

The element:{seen} test has been replaced with element:{was visible}.

-->
<h1>Binding and Loading a Map Module</h1>

<p>Scroll down to the Map, it's only a couple of pixels away.</p>

<a href="http://maps.google.com/?ll=51.741,3.822"
   data-module="ui/Map"
   data-conditions="media:{(min-width:30em)} and element:{was visible}">A Beach on Google Maps</a>

<p>It will only be visible if the current view is wider than 30em's, which is approximately 480 pixels.</p>
            
          
!

CSS

            
              html,body {
  margin:0;
  padding:0;
}

html {
  text-align:center;
  color:#222;
  background:#dedede;
}

body {
  padding:4em 1em 2.5em;
  font-family:'American Typewriter', 'Courier New', Courier, Monaco, mono; 
  background:#f2f2f2;
  box-shadow:inset 0 0 5em #ccc;
}

h1 {
  font-size:1.25em;
  margin-right:1em;
  margin-left:1em;
}

h1+p {  
  margin-bottom:30em;
}

a[data-initialized]+p {
  display:none;
}

a {
  display:block;
}

img {
  border:2px solid #fff;
  max-width:100%;
  box-shadow:0 .125em .25em #aaa;
}

            
          
!

JS

            
              // define google maps module
define('ui/Map',function(){

    'use strict';

    // Map Class
    var exports = function(element,options) {

        // set element reference
        this._element = element;
      
        // remember options
        this._options = options;

        // backup content
        this._inner = this._element.innerHTML;

        // remember if loading
        this._loading = false;

        // load map
        this._load(this._element.getAttribute('href'));
    };

    // default options
    exports.options = {
        zoom:10
    };
  
    // get position success
    exports.prototype._load = function(url) {

        // url is a required param but will fail silently if not supplied
        if (!url) {return;}

        // now loading map
        this._loading = true;

        // set to loading
        this._element.innerHTML = 'Loading map';

        // setup lat lng
        var qs = url.match(/[\d]*\.?[\d]+/g),
            
        // setup position object
        position = {
            coords:{
                latitude:parseFloat(qs[0]),
                longitude:parseFloat(qs[1])
            },
            zoom:parseInt(qs[2],10) || this._options.zoom
        };

        // clear
        var self = this,
        style = '&style=feature:water|hue:0x00a1ff|saturation:-24&style=feature:road|element:labels|visibility:off&style=feature:administrative|element:labels|visibility:off&style=feature:landscape.natural|element:geometry.fill|saturation:-44|lightness:37|hue:0xf6ff00&style=feature:administrative.province|visibility:off&style=feature:poi|visibility:off&style=feature:transit|visibility:off&style=feature:water|element:labels|visibility:off',
        map = document.createElement('img');
        map.setAttribute('alt','');
        map.className = 'map';
        map.onload = function() {

            // if not loading don't append
            if (!self._loading) {
                return;
            }

            // append map image
            self._element.innerHTML = '';
            self._element.appendChild(map);
        };
        map.src = 'http://maps.googleapis.com/maps/api/staticmap?center=' + position.coords.latitude + ',' + position.coords.longitude + '&zoom=' + position.zoom + '&size=' + 500 + 'x' + 150 + '&maptype=roadmap&sensor=false' + style + '&key=AIzaSyCcvAEOb99l4In3NkK8KyFimgF7i0LQFCA';
      
        // key will only be valid from my codepen account, so please remove or replace when forking.

    };

    // Unload Map module
    exports.prototype.unload = function() {

        // not loading anymore
        this._loading = false;

        // restore content
        this._element.innerHTML = this._inner;

    };

    return exports;

});

// load conditioner
require(['conditioner'],function(conditioner) {
  
  conditioner.init();
  
});

            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console