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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="//cdn.pubnub.com/pubnub.min.js"></script>

<div class="container-fluid">
  <div class="row">
    <div class="col-md-12">
      <nav class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
          <div class="navbar-header">
            <a class="navbar-brand">MemeWarz!</a>
          </div>
          <div class="navbar-form navbar-left">
            <button type="submit" class="btn btn-default" id="find-match">Find Match</button>
          </div>
          <ul class="nav navbar-nav navbar-right">
            <li>
              <a href="#">
                You are <strong id="whoami"></strong> 
              </a>
            </li>
          </ul>
        </div>
      </nav>
    </div>
  </div>
  <div class="row">
    <div class="col-md-6">
      <div class="panel panel-default">
        <div class="panel-heading">Online Users</div>
        <div class="list-group" id="online-users"></div>
      </div>
    </div>
    <div class="col-md-6">
      <div class="panel panel-default">
        <div class="panel-heading">Live Chat</div>
        <ul class="list-group" id="chat-output"></ul>
        <div class="panel-body">
          <form id="chat">
            <div class="input-group">
              <input type="text" class="form-control" id="chat-input" />
              <span class="input-group-btn">
                <button type="submit" class="btn btn-default">Send Message</button>
              </span>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
              
            
!

CSS

              
                body {
  padding: 10px;
}
#chat-output {
  height: 200px;
  overflow-y: scroll;
}
              
            
!

JS

              
                // generate a random username
var randomName = function() {
  
  var animals = ['pigeon', 'seagull', 'bat', 'owl', 'sparrows', 'robin', 'bluebird', 'cardinal', 'hawk', 'fish', 'shrimp', 'frog', 'whale', 'shark', 'eel', 'seal', 'lobster', 'octopus', 'mole', 'shrew', 'rabbit', 'chipmunk', 'armadillo', 'dog', 'cat', 'lynx', 'mouse', 'lion', 'moose', 'horse', 'deer', 'raccoon', 'zebra', 'goat', 'cow', 'pig', 'tiger', 'wolf', 'pony', 'antelope', 'buffalo', 'camel', 'donkey', 'elk', 'fox', 'monkey', 'gazelle', 'impala', 'jaguar', 'leopard', 'lemur', 'yak', 'elephant', 'giraffe', 'hippopotamus', 'rhinoceros', 'grizzlybear']

  var colors = ['silver', 'gray', 'black', 'red', 'maroon', 'olive', 'lime', 'green', 'teal', 'blue', 'navy', 'fuchsia', 'purple'];

  return colors[Math.floor(Math.random() * colors.length)] + '_' + animals[Math.floor(Math.random() * animals.length)];
  
}

var me = randomName();
$('#whoami').text(me);

var $input = $('#chat-input');
var $output = $('#chat-output');

var pubnub = PUBNUB.init({
  publish_key: 'demo',
  subscribe_key: 'demo',
  uuid: me
});

var channel = 'memewarz-lobby-demo-5';

$('#chat').submit(function() {
    
  pubnub.publish({
    channel: channel,
    message: {
      text: $input.val(),
      uuid: me
    }
  });
  
  $input.val('');
  
  return false;
  
});

$('#find-match').click(function(){

  pubnub.here_now({
    channel: channel,
    callback: function(data) {
     
      var users = data.uuids;

      for(var i = users.length - 1; i >= 0; i--) {
        if(users[i] === me) {
          users.splice(i, 1);
        }
      }
            
      var random_user = users[Math.floor(Math.random() * users.length)];
      
      alert('Opponent Found: ' + random_user);

    }
  });
  
});

pubnub.subscribe({
  channel: channel,
  message: function(data) {
    
    var $line = $('<li class="list-group-item"><strong>' + data.uuid + ':</strong> </span>');
    var $message = $('<span class="text" />').text(data.text).html();
    
    $line.append($message);
    $output.append($line);
    
    $output.scrollTop($output[0].scrollHeight);

  }, 
  presence: function(data) {

    // get notified when people join
    if(data.action == "join") {

      var $new_user = $('<li id="' + data.uuid + '" class="list-group-item">' + data.uuid + '</li>')

      $('#online-users').append($new_user);

    }

    // and when they leave
    if(data.action == "leave"  || data.action == "timeout") {
      $('#' + data.uuid).remove();
    }

  }
});

              
            
!
999px

Console