-
-
Save digilord/4e34fd576c53c5493f7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<title>chat</title> | |
</head> | |
<body> | |
{{> entryfield}} | |
{{> messages}} | |
</body> | |
<template name="entryfield"> | |
<input type="text" id="name" placeholder="Name" /><input type="text" id="message" placeholder="Your Message"/> | |
</template> | |
<template name="messages"> | |
<p> | |
{{#each messages}} | |
<strong>{{name}}</strong>- {{message}} | |
{{/each}} | |
</p> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Messages = new Meteor.Collection('messages'); | |
if (Meteor.isClient) { | |
Template.messages.messages = function (){ | |
return Messages.find({}, { sort: { time: -1 }}); | |
}; | |
Template.entryfield.events = { | |
"keydown #message": function(event, template) { | |
if(event.which == 13) { | |
//submit the form | |
var nameEle = template.find('#name'); | |
var messageEle = template.find('#message'); | |
if(name.value != '' && message.value != '') { | |
Messages.insert({ | |
name: name.value, | |
message: message.value, | |
time: Date.Now() | |
}); | |
name.value =''; | |
message.value=''; | |
} | |
} | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment