JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
<chat-app></chat-app>
chat-home {
display: block;
}
chat-home h1.page-header { margin-top: 0; }
import { Component, route, DefineMap, DefineList, realtimeRestModel } from "//unpkg.com/can@5/core.mjs";
const Message = DefineMap.extend("Message",{
id: "number",
name: "string",
body: "string",
created_at: "date"
});
Message.List = DefineList.extend("MessageList",{
"#": Message
});
Message.connection = realtimeRestModel({
url: {
resource: 'https://chat.donejs.com/api/messages',
contentType: 'application/x-www-form-urlencoded'
},
Map: Message,
List: Message.List
});
const socket = io('https://chat.donejs.com');
socket.on('messages created', function(message){
Message.connection.createInstance(message);
});
socket.on('messages updated', function(message){
Message.connection.updateInstance(message);
});
socket.on('messages removed', function(message){
Message.connection.destroyInstance(message);
});
Component.extend({
tag: "chat-messages",
view: `
<h1 class="page-header text-center">
Chat Messages
</h1>
<h5><a href="{{ routeUrl(page='home') }}">Home</a></h5>
{{# if(this.messagesPromise.isPending) }}
<div class="list-group-item list-group-item-info">
<h4 class="list-group-item-heading">Loading…</h4>
</div>
{{/ if }}
{{# if(this.messagesPromise.isRejected) }}
<div class="list-group-item list-group-item-danger">
<h4 class="list-group3-item-heading">Error</h4>
<p class="list-group-item-text">{{ this.messagesPromise.reason }}</p>
</div>
{{/ if }}
{{# if(this.messagesPromise.isResolved) }}
{{# for(message of this.messagesPromise.value) }}
<div class="list-group-item">
<h4 class="list-group3--item-heading">{{ message.name }}</h4>
<p class="list-group-item-text">{{ message.body }}</p>
</div>
{{ else }}
<div class="list-group-item">
<h4 class="list-group-item-heading">No messages</h4>
</div>
{{/ for }}
{{/ if }}
<form class="row" on:submit="this.send(scope.event)">
<div class="col-sm-3">
<input type="text" class="form-control" placeholder="Your name"
value:bind="this.name"/>
</div>
<div class="col-sm-6">
<input type="text" class="form-control" placeholder="Your message"
value:bind="this.body"/>
</div>
<div class="col-sm-3">
<input type="submit" class="btn btn-primary btn-block" value="Send"/>
</div>
</form>`,
ViewModel: {
// Properties
messagesPromise: {
default(){
return Message.getList({});
}
},
name: "string",
body: "string",
// Methods
send(event) {
event.preventDefault();
new Message({
name: this.name,
body: this.body
}).save().then(() => {
this.body = "";
});
}
}
});
Component.extend({
tag: "chat-app",
view: `
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
{{# eq(this.routeData.page, 'home') }}
<h1 class="page-header text-center" on:click="this.addExcitement()">
{{ this.message }}
</h1>
<a href="{{ routeUrl(page='chat') }}"
class="btn btn-primary btn-block btn-lg">
Start chat
</a>
{{ else }}
<chat-messages/>
{{/ eq }}
</div>
</div>
</div>`,
ViewModel: {
// Properties
message: {
type: "string",
default: "Chat Home"
},
routeData: {
default(){
route.register("{page}",{page: "home"});
route.start();
return route.data;
}
},
// Methods
addExcitement(){
this.message = this.message + "!";
}
}
});
Also see: Tab Triggers