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

              
                <body ng-app="app" ng-controller="ChatCtrl" class='chat'>

    <div id="thread">
        <div class="thread-list">

            <p>Channels you want to publish in:</p>
            </br>
     
     
       <div class="switch">
        #GENERAL: 
    <label>
      <input type="checkbox" ng-model="publishGeneral">
      <span class="lever"></span>
    </label>
  </div>
     
     <br />
        <div class="switch">
        #RANDOM: 
    <label>
      <input type="checkbox" ng-model="publishRandom">
      <span class="lever"></span>
    </label>
  </div>

        </div>
        <footer class="teal message-form">
            <form ng-submit="sendMessage()" class="container">
                <div class="row">
                    <div class="input-field col s9">
                        <i class="prefix mdi-communication-chat"></i>
                        <input ng-model="messageContent" type="text" placeholder="Type your message">
                        <span class="chip left">
             <img src="{{avatarUrl(uuid)}}">
            User #{{uuid}}
           </span>
                    </div>
                    <div class="input-field col s2">
                        <button type="submit" class="waves-effect waves-light btn-floating btn-large">
             <i class="mdi-content-send"></i>
           </button>
                    </div>
                </div>
            </form>
        </footer>
    </div>

    <div id="thread">
        <ul class="collection message-list">
            <li class="collection-item avatar" ng-repeat="message in threadGeneral.slice().reverse()">
                <img ng-src="{{avatarUrl(message.sender_uuid)}}" alt="{{message.sender_uuid}}" class="circle">
                <span class="title">User #{{ message.sender_uuid }}</span>
                <p><i class="prefix mdi-action-alarm"></i><span class="message-date">{{ message.date | date:"MM/dd/yyyy 'at' h:mma"}}</span></br> {{ message.content }}</p>
            </li>
        </ul>
<span class='thread-title teal lighten-2'>#GENERAL</span>
    </div>

    <div id="thread">
        <ul class="collection message-list">
            <li class="collection-item avatar" ng-repeat="message in threadRandom.slice().reverse()">
                <img ng-src="{{avatarUrl(message.sender_uuid)}}" alt="{{message.sender_uuid}}" class="circle">
                <span class="title">User #{{ message.sender_uuid }}</span>
                <p><i class="prefix mdi-action-alarm"></i><span class="message-date">{{ message.date | date:"MM/dd/yyyy 'at' h:mma"}}</span></br> {{ message.content }}</p>
            </li>
        </ul>
      <span class='thread-title teal lighten-2'>#RANDOM</span>
    </div>


</body>
              
            
!

CSS

              
                body{
  background-color: #FAFFFD;
}

.chat {
  display: flex;
  flex-direction: row;
  height: 100vh;
  background-color: white;
}

#thread {
  display: flex;
  flex-direction: column;
  flex: 10 0 8em; 
 border-right: solid black 1px;
}


.thread-list {
 
  flex: 1; 
  padding: 50px;
  margin-top:0;
  margin-bottom:0;
  border: none;
}


.message-list {
  flex: 1; 
  overflow: auto;
  margin-top:0;
  margin-bottom:0;
  border: none;
}


.message-form {
  flex:1;
  max-height:120px;
  color: white;
}


.message-date {
  color: #585858;
}


footer .input-field input,
button {
 border-color: #FFFFFF;
}

.chip {
 font-style: italic;
}

.thread-title{
 text-align: center;
 color: white;
}
              
            
!

JS

              
                angular
    .module('app', ['pubnub.angular.service'])

.controller('ChatCtrl', ['$scope', 'Pubnub', '$pubnubChannel', function($scope, Pubnub, $pubnubChannel) {

    $scope.uuid = _.random(1000000).toString();
    Pubnub.init({
        publish_key: 'pub-c-a1cd7ac1-585e-478e-925b-65d17ce62f7d',
        subscribe_key: 'sub-c-204f063e-c559-11e5-b764-02ee2ddab7fe',
        ssl: true,
        uuid: $scope.uuid
    });

    $scope.threadGeneral = $pubnubChannel("general", {
        autoload: 20
    })
    

    $scope.threadRandom = $pubnubChannel('random', {
        autoload: 20
    })

    $scope.messageContent = '';
    $scope.publishGeneral = true;
    $scope.publishRandom = false;

    $scope.avatarUrl = function(uuid) {
        return '//robohash.org/' + uuid + '?set=set2&bgset=bg2&size=70x70';
    };

    // Send the messages over PubNub Network
    $scope.sendMessage = function() {
        // Don't send an empty message 
        if ($scope.messageContent == '')
            return;
        var message = {
            content: $scope.messageContent,
            sender_uuid: $scope.uuid,
            date: new Date()
        }

        if ($scope.publishGeneral)
            $scope.threadGeneral.$publish(message);

        if ($scope.publishRandom)
            $scope.threadRandom.$publish(message);
        // Reset the messageContent input
        $scope.messageContent = '';
    }
}]);
              
            
!
999px

Console