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 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

              
                .bg.indigo

.container.white.z-depth-1
  .row
    .col.s12
      ul.tabs
        li.tab.col.s12.m4
          a(href="#start") Start
            i.material-icons home
        li.tab.col.s12.m4
          a(href="#location") Anfahrt
            i.material-icons map
        li.tab.col.s12.m4
          a(href="#doodle") Mitbringen
            i.material-icons.lower list
          
        
    .col.s12.tab-page#start
      h3 Einladung zu {{event}}
    .col.s12.tab-page#location
      h3 Anfahrt
      iframe(src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d391568.26869156724!2d116.11727567317983!3d39.93854659811947!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x35f05296e7142cb9%3A0xb9625620af0fa98a!2sPeking%2C+China!5e0!3m2!1sde!2sde!4v1477507016884" width="100%" height="450" frameborder="0" style="border:0" allowfullscreen)
    .col.s12.tab-page#doodle
      h3 Mitbringliste
      p.flow-text Es wird darum gebeten, eine sache aus der Liste mit zu bringen
      .doodle-list
        .doodle-header
          h4 Noch offen
          .open-doodles
            .doodle
              .doodle-name Salate
                .badge 14
            .doodle
              .doodle-name Appetizer
                .badge 4
          .add-doodle.row
            h5 Eintragen:
            .input-field.col.s6.m3
              select#catsel 
                option(value="" disabled="disabled" selected) Kategorie Wählen
    
            .input-field.col.s6.m3
              input#num(type="number" min="0" step="1" disabled)
              label(for="num") Portionen

            .input-field.col.s12.m6
               input#desc(type="text" disabled)
               label(for="desc") Beschreibung
            .col.s6.m4.l2
              .insert-doodle.btn-large.indigo.waves-effect.waves-light Eintragen
        .doodle-body
          h4 Bereits eingetragen
          .closed-doodles
            .doodle
              .doodle-name Orientalischer Salat
                span.doodle-category Salat
                .badge 12
              .doodle-subtitle von Max Mustermann
              
            
!

CSS

              
                .bg {
  position:fixed;
  top:0;
  left:0;
  right:0;
  height:380px;
  
  z-index:-1;
}

.container {
  position:relative;
  border-radius:3px;
  margin:64px auto;
  padding:16px 42px;
  min-height:~"calc(100vh - 128px)";
  
  font-size:1.2rem;
  line-height:1.8rem;
  text-align:justify;
}

p {
  margin-bottom:.75rem;
}

h1, h2, h3, h4 {
  font-weight:300;
}

pre {
  overflow-y:hidden;
  white-space:pre-wrap;
  tab-size:4;
  margin:8px 0;
}

// ul:not(.tabs), ul:not(.tabs) li {
//   list-style: decimal;
// }

// ul:not(.tabs) {
//   padding-left:4rem;
// }

.tabs .material-icons {
    display: inline-block;
    font-size: 1.5em;
    vertical-align:-4px;
}
.material-icons.lower {
    vertical-align: -7px;
}

.tab-page {
  min-height: 400px;
}

.dropdown-content .disabled * {
  color: #999 !important;
}

.badge {
  background-color: #3f51b5;
  padding: 2px 8px;
  color:#fff;
  
  float: right;
  border-radius: 4px;
  min-width: 40px;
  text-align:center;
}

.doodle {
  padding: 16px 8px;
  
  &:nth-child(odd) {
    background: rgba(0,0,0,0.05);
  }
  
  .doodle-name {
    font-size: 1.4rem;
  }
  
  .doodle-subtitle {
    opacity: .6;
  }
  
  .doodle-category {
    opacity: .6;
    margin-left: 16px;
    font-weight: 300;
  }
}

.add-doodle {
  padding: 24px 0 0 0;
  margin: 0 0 16px 0 !important;
}
              
            
!

JS

              
                let data = {
  cat: [
    {id: 1, name: "Kuchen", size: 41},
    {id: 2, name: "Salat", size: 400},
    {id: 4, name: "Appetizer", size: 9000}
  ],
  doodles: [
    {name: "salat...", sub: "Max mustermann", cat: 'Salat', badge: 12},
    {name: "KUCHENS", sub: "John Doe", cat: 'Kuchen', badge: 40},
    {name: "mist", sub: "No body", cat: 'Appetizer', badge: -2},
  ]
}

$.fn.setClass = (class_,state) => {
  state = state === undefined ? true : state;
  if (state) {
    this.addClass(class_);
  } else {
    this.removeClass(class_);
  }
  return this;
};

const GLOB = {};

function createDoodle({name, cat = "", sub, badge, classes = "", badgeclass = "", subclass = ""}) {
  let node = document.createElement("div");
  node.setAttribute('class', `doodle ${classes}`);
  
  cat = cat.length ? `(${cat})` : cat;
  
  node.innerHTML = `<div class="doodle-name">${name} <span class="doodle-category">${cat}</span><div class="badge ${badgeclass}">${badge}</div></div>`;
  
  if (sub) {
    let subNode = document.createElement("div")
    subNode.setAttribute('class', `${subclass} doodle-subtitle`);
    subNode.innerHTML = sub;
    node.appendChild(subNode);
  }
  
  
  return node
}

function addDoodle (doodle) {
  if (GLOB.done)
      GLOB.done.appendChild(doodle);
}

function addCat (cat, catObj) {
  if (GLOB.cat)
      GLOB.cat.appendChild(cat);
  if (GLOB.catsel) {
    let n = document.createElement("option");
    
    n.setAttribute("value", catObj.id);
    n.innerText = catObj.name;
    
    GLOB.catsel.appendChild(n);
  }
      
}

function error (msg) {
  Materialize.toast(msg, 6000, 'err');
}

$(() => {
  // code goes here
  
  GLOB.cat = document.querySelector('.open-doodles');
  GLOB.done = document.querySelector('.closed-doodles');
  GLOB.catsel = document.querySelector('#catsel');
  GLOB.in = {
    num: document.querySelector('input#num'),
    desc: document.querySelector('input#desc'),
    btn: document.querySelector('.insert-doodle'),
  }
  
  GLOB.cat.innerHTML = "";
  GLOB.done.innerHTML = "";
  
  GLOB.count = {}
  
  
  _.each(data.doodles, (doodle) => {
    if (GLOB.count[doodle.cat]) {
      GLOB.count[doodle.cat] += +doodle.badge;
    } else {
      GLOB.count[doodle.cat] = +doodle.badge;
    }
    
    addDoodle(createDoodle(doodle));
  })
  
  _.each(data.cat, (cat) => {
    let count = GLOB.count[cat.name] || 0;
    
    if (count >= +cat.size) {
      cat.full = true;
      return;
    } else {
      cat.badge = cat.size - count;
    }
    
    addCat(createDoodle(cat), cat);
  })
  
  
  $('select').material_select();
  $('select').on("change", function (e) {
    let val = this.value,
        cat = _.find(data.cat, (cat) => cat.id == val);
    
    if (!cat) return;
    
    GLOB.in.num.setAttribute("max", cat.badge);
    GLOB.in.num.value = "";
    GLOB.in.num.removeAttribute("disabled");
    GLOB.in.desc.removeAttribute("disabled");
  });
  
  $(GLOB.in.num).on("keydown input keyup", function(e){
    if (+this.value >= +this.max 
        && e.keyCode != 46 // delete
        && e.keyCode != 8 // backspace
       ) {
       e.preventDefault();
       this.value = this.max;
    }
  })
  
  GLOB.in.btn.addEventListener("click", (e) => {
    let cat = GLOB.catsel.value,
       _cat = _.find(data.cat, (c) => c.id == cat),
        num = GLOB.in.num.val,
        desc = GLOB.in.desc.value;
    
    console.log(cat, _cat, num, desc);
    
    if (!_cat) return error("Bitte wähle eine Kategorie")
      
    if (num === undefined || num <= 0 || num > cat.badge) return error("Anzahl ist nicht zulässig");
    
    if (desc === undefined || desc.length < 3 || desc.length > 300) return error("Beschreibung ungültig");
    
    $.ajax({
      url: "/add.php",
      data: {
        cat,
        num,
        desc
      },
      dataType: 'json',
      success(data) {
        console.log("data");
      },
      error(jqxhr, status, msg) {
        console.log(...arguments);
        error(status + ' - ' + msg);
      }
    })
  })
})
              
            
!
999px

Console