123

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

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 {
  box-sizing: border-box;
}

*, *:before, *:after {
  box-sizing: inherit;
}

body {
  font-family: sans-serif;
  margin: 0;
  background: #f2f3f5;
}

a {
  color:white;
  font-weight: 100;
  letter-spacing: 2px;
  text-decoration: none;
  background:rgba(0,0,0,0.2);
  padding:20px 5px;
  display: inline-block;
  width: 100%;
  text-align: center;
  transition:all 0.5s;
}

a:hover {
  background:rgba(0,0,0,0.3);
}

.wrapper {
  max-width: 1000px;
  margin:0 auto;
}
input {
  padding:10px;
  border:0;
  margin:0 5px;
}
section, footer {
  text-align: center;
  background:rgba(0,0,0,0.2);
  padding:20px;
  margin:20px 0;
  color:white;
  font-weight: 100;
}
/* Flex Container */
.flex-nav ul {
  border:1px solid black;
  list-style: none;
  margin: 0;
  padding: 0;
  display:flex;
}

/* Flex Item */
.flex-nav li {
  flex:3;
}

.flex-nav .social {
  flex:1;
}


@media all and (max-width:1000px) {
  
  .flex-nav ul {
    flex-wrap: wrap;
  }

  .flex-nav li {
    flex:1 1 50%;
  }

  .flex-nav .social {
    flex:1 1 25%;
  }

}


/* This is where the magic Happens */

@media all and (max-width:500px) {
  
  .flex-nav li {
    flex-basis:100%;
  }
  

  /* Turn on flexbox */
  .wrapper {
    display:flex;
    flex-direction:column;
  }

  /* Reorder items */
  .wrapper > * {
    order:999;
  }
  
  /* Nav */
  .flex-nav {
    order:1;
  }

  .toggleNav {
    display: block;
  }

  .flex-nav ul {
    display: none;
  }
    .flex-nav ul.open {
      display:flex;
    }
  
  /* Header */
  .top {
    order:2;
  }

  /* Details */
  .details {
    order:3;
  }

  /* Sign Up */
  .signup {
    order:4;
  }

}
            
          
!
            
              var App = {};

function pluck(property, object) {
    return object[property];
  }
  // better use R.map() from Ramda library
function mapWith(fn) {
    return function(list) {
      return Array.prototype.map.call(list, function(something) {
        return fn.call(this, something);
      });
    }
  }
  // better use R.compose() from Ramda library
function compose(f, g) {
  return function(x) {
    return f(g(x));
  };
}

// function getImgs(it) {
// 	return it.map(function(i) {
// 		return i.media['m'];
// 	});
// }

var getImgs = mapWith(compose(pluck.bind(this, 'm'), pluck.bind(this, 'media')));

App.model = function(term) {
  return m.request({
    method: 'GET',
    dataType: 'jsonp',
    callbackKey: "jsoncallback",
    url: 'https://api.flickr.com/services/feeds/photos_public.gne?tags=' + term + '&format=json',
    unwrapSuccess: function(resp) {
      return resp.items;
    },
    unwrapError: function(resp) {
      return resp.error;
    }
  })
};

App.controller = function() {
  var ctrl = this;
  ctrl.searchTerm = m.prop('');
  ctrl.data = App.model(ctrl.searchTerm() || m.route.param('filter'));
  ctrl.images = ctrl.data.then(getImgs)
  ctrl.update = function(e) {
    if (e.keyCode === 13) {
      console.log(e.keyCode);
      console.log(ctrl.searchTerm());
      m.route('/' + ctrl.searchTerm());
    }
  };

};
App.view = function(ctrl) {
  return m('.wrapper', [
    m('h1', 'Mostly adequate guide, Chapter 6'),
    m('a', {
      href: 'https://goo.gl/N47yqu',
      target: '_blank'
    }, 'Link to book'),
    m('div', [
      m('i.fa.fa-search'),
      m('input[placeholder="Input search term here"]', {
      value: ctrl.searchTerm(),
      oninput: m.withAttr('value', ctrl.searchTerm),
      onkeypress: ctrl.update
    })
    ]),
    m('h4', 'You are looking for: ' + ctrl.searchTerm()),
    ctrl.images().map(function(item) {
      return m('img', {
        src: item
      });
    })
  ]);
};

//m.mount(document.body, App);

m.route(document.body, '/', {
  '/': App,
  '/:filter': App
})
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console