Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <body id="app">
  <div class="show-picture">
    <div class="flex">
      <div class="image popup"></div>
    </div>
  </div>
  <div class="wrapper">


    <h1>Gallery</h1>
    <form v-on:submit='search'>
      <input type="text" id="search-phrase" placeholder="Input text" v-model='searchPhrase'>
      <button type="submit" id="search">Search</button>
      <div class="clearfix"></div>
    </form>

    <div class="wrapper__titles" v-if="searchResults">
      <h2 class="res-title">Results</h2>
      <h2 class="fav-title">Favorites</h2>
      <div class="clearfix"></div>
    </div>


    <div class="results">
      <!-- Pictures got from vk -->
      <div class="results__all">
        <!-- Template for pictures got from vk -->
        <result-item v-if="searchResults" v-for='searchResult in searchResults' v-bind:search-result='searchResult'></result-item>
      </div>

      <!-- Favorite pictures -->
      <div class="results__favorite">
        <!-- Template for pictures maved to favorites -->
        <favorite-item v-for="favorite in favorites" v-bind:favorite='favorite'></favorite-item>
      </div>
      <div class="clearfix"></div>
    </div>
  </div>
  
  
  <!-- template for result-item -->
  <template id="result-template">
    <div class="results__all__item">
      <a href v-on:click.stop.prevent='show(searchResult)'><img v-bind:src='searchResult.src_big'></a>
      <a href class='add' v-on:click.stop.prevent='add(searchResult)' v-if='!searchResult.added'>Add to favorites</a>
      <a href class='remove' v-on:click.stop.prevent='remove(searchResult)' v-if='searchResult.added'>Added</a>
    </div>
  </template>
  
  <!-- template for favorite-item -->
  <template id="favorite-template">
    <div class="results__fav__item">
      <a href v-on:click.stop.prevent='show(favorite)'><img v-bind:src='favorite.src_big'></a>
      <a href class='remove' v-on:click.stop.prevent='remove(favorite)'>Remove from favorites</a>
    </div>
  </template>
  
</body>

              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
  font-family: Verdana, sans-serif;
  text-decoration: none;
  color: #212121;
}

.wrapper {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1%;
  box-sizing: border-box;
}


/* Head with input field */

.wrapper h1 {
  margin: 1% 0;
  font-size: 3rem;
}

.wrapper input {
  display: inline-block;
  float: left;
  width: 74%;
  height: 50px;
  margin: 0 0 2% 0;
  padding: 10px;
  box-sizing: border-box;
  border-radius: 5px;
  border: 1px solid #b0b0b0;
  outline: none;
  font-size: 1.2rem;
  transition: all 300ms ease-out;
}

.wrapper input:hover,
.wrapper input:focus {
  border: 1px solid #FF5722;
}

form > button {
  display: inline-block;
  float: right;
  width: 24%;
  height: 50px;
  margin: 0 0 2% 0;
  border: 1px solid #FF5722;
  border-radius: 5px;
  box-sizing: border-box;
  font-size: 1.2rem;
  text-align: center;
  line-height: 50px;
  color: #FF5722;
  background-color: #FFFFFF;
  font-weight: bold;
  transition: all 300ms ease-out;
}

form > button:hover {
  background-color: #FF5722;
  color: #FFFFFF;
}

.clearfix {
  content: '';
  clear: both;
  line-height: 0px;
}



/* Results block */

.results {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.results h2 {
  display: block;
  width: 100%;
}

.res-title {
  float: left;
  width: 74%;
  margin-bottom: 0.5rem;
}

.results__all {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 74%;
  box-sizing: border-box;
}

.results__all__item {
  display: inline-block;
  width: 30%;
  margin: 0 0 0.8rem 0;
}

.results__all__item:nth-of-type(3n) {}

.results__all__item img {
  width: 100%;
  height: auto;
}

.results__all__item a {
  display: block;
  width: 100%;
  box-sizing: border-box;
  font-size: 0.7rem;
  text-align: center;
  line-height: 20px;
  transition: all 300ms ease-out;
}

.results__all__item a.add {
  border: 1px solid #FF5722;
  color: #FF5722;
}

.results__all__item a.remove {
  border: 1px solid #4CAF50;
  color: #4CAF50;
}

.fav-title {
  float: right;
  width: 24%;
  margin-bottom: 0.5rem;
}

.results__favorite {
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  flex-wrap: wrap;
  width: 24%;
}

.results__fav__item {
  display: inline-block;
  width: 100%;
  margin: 0 0 0.8rem 0;
}

.results__fav__item img {
  width: 100%;
  height: auto;
}

.results__fav__item a.remove {
  display: block;
  width: 100%;
  border: 1px solid #FF5722;
  box-sizing: border-box;
  font-size: 0.7rem;
  text-align: center;
  line-height: 20px;
  color: #FF5722;
  transition: all 300ms ease-out;
}

.results__all__item a.add:hover,
.results__fav__item a.remove:hover {
  background-color: #FF5722;
  color: #FFFFFF;
}

.results__all__item a.remove:hover {
  background-color: #4CAF50;
  color: #FFFFFF;
}


/* Showing picture */
.show-picture {
  position: fixed;
  display: none;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);
}

.flex {
  display: flex;
  width: 100%;
  height: 100%;
  flex-direction: row;
  justify-content: center;
  align-items: center;
}

.image {
  width: 90%;
  height: 90%;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
}



@media screen and (max-width: 600px) {
  .wrapper h1 {
    font-size: 2rem;
  }

  .res-title,
  .fav-title {
    font-size: 1rem;
  }
}

@media screen and (max-width: 400px) {
  .wrapper h1 {
    font-size: 1.5rem;
  }

  .res-title,
  .fav-title {
    font-size: 0.8rem;
  }
}

@media screen and (max-width: 370px) {
  form > button {
    font-size: 1rem;
  }
}

              
            
!

JS

              
                'use strict';
$(document).ready(function () {
  
  
  Vue.component('result-item', {
    props: [
      'searchResult',
    ],
    template: '#result-template',
    methods: {
      show: function (obj) {
        var src;
        if (obj.src_xxxbig !== undefined) src = obj.src_xxxbig;
        else if (obj.src_xxbig !== undefined) src = obj.src_xxbig;
        else if (obj.src_xbig !== undefined) src = obj.src_xbig;
        else src = obj.src_big;
        /* Setting background image and showing our popup */
        $('.image').css('background-image', 'url(' + src + ')');
        $('.show-picture').css('display', 'block');
      },
      add: function (searchResult) {
        var index = vueView.searchResults.indexOf(searchResult);
        /* Checking if stuff is already in favorites or not */
        if (vueView.favorites.indexOf(searchResult) === -1) {
          /* Pushing stuff to favorites if not */
          vueView.favorites.push(searchResult);
          /* Changing field value to hide button "Add to favorites" and show "Added" */
          vueView.searchResults[index].added = true;
        };
      },
      remove: function (searchResult) {
        var index = vueView.searchResults.indexOf(searchResult);
        if (vueView.favorites.indexOf(searchResult) !== -1) {
          /* Removing stuff from favorites */
          vueView.favorites.splice((vueView.favorites.indexOf(searchResult)), 1);
          /* Changing field value to hide button "Added" and show "Add to favorites" */
          vueView.searchResults[index].added = false;
        };
      },
    },
  });
  
  
  Vue.component('favorite-item', {
    props: [
      'favorite',
    ],
    template: '#favorite-template',
    methods: {
      show: function (obj) {
        var src;
        if (obj.src_xxxbig !== undefined) src = obj.src_xxxbig;
        else if (obj.src_xxbig !== undefined) src = obj.src_xxbig;
        else if (obj.src_xbig !== undefined) src = obj.src_xbig;
        else src = obj.src_big;
        /* Setting background image and showing our popup */
        $('.image').css('background-image', 'url(' + src + ')');
        $('.show-picture').css('display', 'block');
      },
      remove: function (favorite) {
        var index = vueView.searchResults.indexOf(favorite);
        if (vueView.favorites.indexOf(favorite) !== -1) {
          /* Removing stuff from favorites */
          vueView.favorites.splice((vueView.favorites.indexOf(favorite)), 1);
          /* Changing field value to hide button "Added" and show "Add to favorites" */
          vueView.searchResults[index].added = false;
        };
      },
    },
  });
     
  
  var vueView = new Vue({
    el: '#app',
    data: {
      searchPhrase: '',
      searchResults: null,
      favorites: [],
    },
    methods: {
      search: function (e) {
        e.preventDefault();
        var _this = this;
        var searchUrl = 'https://api.vk.com/method/photos.search?q=' + this.searchPhrase + '&count=100&callback=JSON_CALLBACK';
        $.ajax({
          url: searchUrl,
          dataType: 'jsonp',
          success: function (content) {
            var searchResults = content.response;
            var arr = [];

            /* Iterate through results and pushing objects to result array */
            for (var i = 1; i < searchResults.length; i++) {
              arr.push(searchResults[i]);
              /* Adding flag for hiding button "Added" */
              arr[i - 1].added = false;
            };
            console.log('Done, bleat!');
            _this.$set('searchResults', arr);
            _this.$set('favorites', []);
          },

          error: function () {
            console.log('Error, sukaaa!');
          },
        });
      },
    },
  });

  
  /* Closing our popup by clicking somewhere */
  $('.flex').click(function () {
    $('.show-picture').css('display', 'none');
  });

  /* Closing our popup by pressing ESC button */
  $(window).keydown(function (event) {
    if (event.keyCode == 27	&& $('.show-picture').css('display') === 'block') {
      $('.show-picture').css('display', 'none');
    };
  });

});

              
            
!
999px

Console