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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <div class="container">
  <div class="row">
    <div class="col-12 selectorgroup">Generating filters...</div>
    <div class="col-12 intro">
      <p>Hellow! This page originally has nothing below this.</p>
    </div>
    <div class="col-12 row" id="insertpoint">Loading...</div>
  </div>
</div>
              
            
!

CSS

              
                img { width: 100%; height: auto; }
.item, .intro, .selectorgroup {
  margin: 15px 0;
}
              
            
!

JS

              
                var data = [
  {
    img: "http://www.fillmurray.com/g/400/200",
    title: "Title all this",
    url: "https://google.com",
    group: "Freshman + Sophmore",
    cta: "learn more",
    desc:
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. In eu leo enim. That i can change"
  },
  {
    img: "http://www.fillmurray.com/g/402/201",
    title: "Title 2",
    url: "https://bing.com",
    group: "Sophmore + Senior",
    cta: "watch now",
    desc:
      "Donec eget feugiat erat. Fusce ante nisi, consequat a accumsan ut, elementum sit amet ipsum."
  },
  {
    img: "http://www.fillmurray.com/g/404/202",
    title: "Title 3",
    url: "https://google.com",
    group: "Junior",
    cta: "click here",
    desc:
      "Aenean vitae turpis eget nunc interdum feugiat quis a justo. Integer ut vulputate turpis."
  },
  {
    img: "http://www.fillmurray.com/g/406/203",
    title: "Title 4",
    url: "https://yahoo.com",
    group: "Senior + Freshman",
    cta: "yay",
    desc:
      "Quisque vitae vehicula nisl. Proin pulvinar interdum egestas. Sed at neque tristique, maximus lectus quis, egestas massa."
  },
  {
    img: "http://www.fillmurray.com/g/408/204",
    title: "Title 5",
    url: "http://youtube.com",
    group: "Freshman",
    cta: "omg no",
    desc:
      "Curabitur commodo accumsan nulla vitae vehicula. Praesent aliquet maximus purus."
  },
  {
    img: "http://www.fillmurray.com/g/410/205",
    title: "Title 6",
    url: "http://youtube.com",
    group: "Freshman",
    cta: "this is jess",
    desc:
      "This is more text. Curabitur commodo accumsan nulla vitae vehicula. Praesent aliquet maximus purus."
  },
  {
    img: "http://www.fillmurray.com/g/412/206",
    title: "new Title 7",
    url: "http://youtube.com",
    group: "Sophmore",
    cta: "this is test",
    desc:
      "This is more text. Curabitur commodo accumsan nulla vitae vehicula. Praesent aliquet maximus purus."
  }
];
console.log(data.length);

// clear out the loading text
$("#insertpoint").html("");
for (i = 0; i < data.length; i++) {
  // seperated to allow if statements
  var groupFilter = data[i].group
    .toLowerCase()
    .replace(/\W/g, " ")
    .replace(/\s+/g, " ");
  groupFilter = groupFilter.split(" ");
  console.log("a");
  for (y = 0; y < groupFilter.length; y++) {
      groupFilter[y] = "filter-"+groupFilter[y];
  }
  groupFilter = groupFilter.toString().replace(/,/g, " ");;
  var $item = $(
    "<div class='col-xs-12 col-sm-6 col-md-4 item " + groupFilter + "'></div>"
  );
  $item.append("<img src='" + data[i].img + "'>");
  $item.append("<h6>" + data[i].group + "</h6>");
  $item.append("<h2>" + data[i].title + "</h2>");
  $item.append("<p>" + data[i].desc + "</p>");
  $item.append("<a href='" + data[i].url + "'>" + data[i].cta + "</a>");
  $("#insertpoint").append($item);
}

// filter generator below

function sortonedeep(a, b) {
  if (a[1] < b[1]) return -1;
  if (a[1] > b[1]) return 1;
  return 0;
}

function filterMaker(filterDisplay, filterSet, filterHeader, showReset) {
  filterDisplay = $(filterDisplay);
  filterHeader = $(filterHeader);
  var filterTerms = [];

  // get filterHeader terms, split them into seperate words, add to filterTerms for button creation
  filterHeader.each(function() {
    var ix = $(this)
      .html()
      .replace(/\W/g, " ")
      .replace(/\s+/g, " ");
    ix = ix.split(" ");
    for (i = 0; i < ix.length; i++) {
      filterTerms["filter-" + ix[i].toLowerCase()] = ix[i];
    }
  });

  //convert object to seperate arrays, sort
  filterTerms = Object.keys(filterTerms).map(function(key) {
    return [key, filterTerms[key]];
  });
  filterTerms = filterTerms.sort(sortonedeep);

  //clear out filterDisplay
  filterDisplay.html("");
  //add to array for generation
  if (showReset) {
    filterTerms.push(["filter-reset", "Reset"]);
  }
  //create buttons
  for (i = 0; i < filterTerms.length; i++) {
    filterDisplay.append(
      "<button class='" +
        filterTerms[i][0] +
        " btn-filter btn btn-primary'>" +
        filterTerms[i][1] +
        "</button> "
    );
  }
  //create event listeners for each button
  filterDisplay.find(".btn-filter").click(function() {
    //on click, hide all
    $(filterSet).hide();
    //create loop that determines if the clicked button matches, then trigger a show for all.
    for (i = 0; i < filterTerms.length; i++) {
      if ($(this).hasClass(filterTerms[i][0])) {
        var x = filterSet + "." + filterTerms[i][0];
        $(x).show();
        break;
        // if matches reset, show all
      } else if ($(this).hasClass("filter-reset")) {
        $(filterSet).show();
        break;
      }
    }
  });
}

// call to generate
filterMaker(".selectorgroup", ".item", ".item h6", true);

              
            
!
999px

Console