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

              
                <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