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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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

            
              <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="panel panel-default">
  <div class="panel-heading">Lobby 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>
            
          
!

CSS

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

JS

            
              // use jQuery to find the DOM elements we care about
var $input = $('#chat-input'); // where the user inputs chat text
var $output = $('#chat-output'); // where output is sent

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

var channel = 'memewarz-lobby-demo';

// when the "send message" form is submitted
$('#chat').submit(function() {
    
  // publish input value to channel 
  pubnub.publish({
    channel: channel,
    message: $input.val()
  });
  
  // clear the input field
  $input.val('');
  
   // cancel event bubbling
  return false;
  
});


// when we receive messages
pubnub.subscribe({
  channel: channel, // our channel name
  message: function(text) { // this gets fired when a message comes in
    
    // create a new line for chat text
    var $line = $('<li class="list-group-item" />');
    
    // filter out html from messages
    var $message = $('<span class="text" />').text(text).html();
    
    // build the html elements
    $line.append($message);
    $output.append($line);
    
    // scroll the chat output to the bottom
    $output.scrollTop($output[0].scrollHeight);

  }
});
            
          
!
999px

Console