Permalink
Browse files

Merge pull request #2 from scottux/cleaner

Streamlining
  • Loading branch information...
2 parents ef980e7 + 22a8f08 commit c41c56bcc63fadf2aadaa9797d26dfce96d25be3 @AVGP committed May 5, 2012
Showing with 136 additions and 429 deletions.
  1. +2 −0 .gitignore
  2. +2 −0 .meteor/packages
  3. +1 −2 README
  4. +2 −2 client/index.html → chat.html
  5. +70 −0 chat.js
  6. +59 −0 chat.less
  7. +0 −54 client/client.js
  8. +0 −35 client/css/main.css
  9. +0 −265 client/css/screen.css
  10. +0 −36 public/ie.css
  11. +0 −29 public/print.css
  12. +0 −6 server/server.js
View
@@ -0,0 +1,2 @@
+
+.DS_Store
View
@@ -4,3 +4,5 @@
# but you can also edit it by hand.
autopublish
+less
+jquery
View
@@ -2,6 +2,5 @@ meteor.js Chat example
This is a very simple example of a chat application done with meteor.js.
-The client-side consists of a few css-files (3 from blueprint-css and one actual application CSS file.) plus the index.html with the necessary template declarations and the client.js for the interactive parts.
- The server-side is just the bare server startup code in server/server.js
+Cleaned up to only require necessary elements.
@@ -38,7 +38,7 @@
<template name="roomItem">
<li class="roomItem">
- {{name}} <a href="javascript:void(0);" class="enter">[Enter]</a>
+ {{name}} <button class="enter">Enter</button> <button class="delete">Delete</button>
</li>
</template>
@@ -47,7 +47,7 @@
<h2>Room &quot;{{roomName}}&quot;</h2>
<ul id="messages">
{{#each messages}}
- <li><span class="author">{{author}}:</span> {{text}}</li>
+ <li><span class="author{{authorClass}}">{{author}} [{{timestamp}}]:</span> {{text}}</li>
{{/each}}
</ul>
<form action="javascript:void(0)">
View
@@ -0,0 +1,70 @@
+var Rooms = new Meteor.Collection("rooms");
+var Messages = new Meteor.Collection("messages");
+
+if (Meteor.is_client) {
+ Template.rooms.events = {
+ "click #addRoom": function (){
+ var roomName = window.prompt("Name the room", "My room") || "Anonymous Room";
+ if(roomName) {
+ Rooms.insert({"name": roomName});
+ }
+ }
+ };
+
+ Template.main.currentRoom = function (){
+ return Session.get("room") || false;
+ };
+
+ Template.rooms.availableRooms = function (){
+ return Rooms.find({});
+ };
+
+ Template.roomItem.events = {
+ "click .enter": function (){
+ var name;
+ if(Session.get("name") === undefined) {
+ name = window.prompt("Your name", "Guest") || "Jerky";
+ Session.set("name", name);
+ }
+ Session.set("room", this._id);
+ },
+ "click .delete": function (){
+ Rooms.remove({_id:this._id});
+ }
+ };
+
+ Template.room.roomName = function (){
+ var room = Rooms.findOne({_id: Session.get("room")});
+ return room && room.name ;
+ };
+
+ Template.room.messages = function (){
+ return Messages.find({room: Session.get("room")});
+ };
+
+ Template.messageItem.authorClass = function (){
+ return Session.equals("name", this.author) ? ' mine' : '';
+ };
+
+ Template.room.events = {
+ "click #leave": function (){
+ if(!window.confirm("Leave this room?", "Do you really want to leave?")) { return; }
+ Session.set("room", undefined);
+ },
+ "submit": function (){
+ var $msg = $("#msg");
+ if ($msg.val()){
+ Messages.insert({
+ "room": Session.get("room"),
+ "author": Session.get("name"),
+ "text": $msg.val(),
+ "timestamp": (new Date()).toUTCString()
+ });
+ }
+ $msg.val("");
+ $msg.focus();
+ Meteor.flush()
+ $("#messages").scrollTop(99999);
+ }
+ };
+}
View
@@ -0,0 +1,59 @@
+/* LESS variables */
+@gray : #999;
+@blue : #4f82b1;
+
+/* http://meyerweb.com/eric/tools/css/reset/
+ v2.0 | 20110126
+ License: none (public domain)
+*/
+html, body, div, span, applet, object, iframe,
+h1, h2, h3, h4, h5, h6, p, blockquote, pre,
+a, abbr, acronym, address, big, cite, code,
+del, dfn, em, img, ins, kbd, q, s, samp,
+small, strike, strong, sub, sup, tt, var,
+b, u, i, center,
+dl, dt, dd, ol, ul, li,
+fieldset, form, label, legend,
+table, caption, tbody, tfoot, thead, tr, th, td,
+article, aside, canvas, details, embed,
+figure, figcaption, footer, header, hgroup,
+menu, nav, output, ruby, section, summary,
+time, mark, audio, video {
+ margin: 0;
+ padding: 0;
+ border: 0;
+ font-size: 100%;
+ font: inherit;
+ vertical-align: baseline;
+}
+/* HTML5 display-role reset for older browsers */
+article, aside, details, figcaption, figure,
+footer, header, hgroup, menu, nav, section {
+ display: block;
+}
+body {
+ line-height: 1;
+}
+ol, ul {
+ list-style: none;
+}
+blockquote, q {
+ quotes: none;
+}
+blockquote:before, blockquote:after,
+q:before, q:after {
+ content: '';
+ content: none;
+}
+table {
+ border-collapse: collapse;
+ border-spacing: 0;
+}
+
+body { padding:20px 50px; }
+h2 { color:#FFF; font-weight:700; line-height:2; font-size:113%; }
+.roomScreen, .roomList { background: @blue; padding: 10px; border:1px solid @gray; }
+.roomScreen > form, .roomList > p { background:#eee; padding:5px; border:1px solid @gray; border-top:0px; }
+.roomList > ul {background:#FFF;}
+#messages { background:#fff; padding: 10px; border:1px solid @gray; height: 350px; overflow:auto; }
+#messages .mine { color:green; }
View
@@ -1,54 +0,0 @@
-var Rooms = new Meteor.Collection("rooms");
-var Messages = new Meteor.Collection("messages");
-
-Template.rooms.events = {
- "click #addRoom": function () {
- var roomName = window.prompt("Name for the new name", "My room");
- if(roomName != "") {
- Rooms.insert({"name": roomName});
- }
- }
-};
-
-Template.main.currentRoom = function() {
- return Session.get("room") || false;
-}
-
-Template.rooms.availableRooms = function () {
- return Rooms.find({});
-};
-
-Template.roomItem.events = {
- "click a.enter": function () {
- if(Session.get("name") === undefined) {
- var name = window.prompt("Your name", "Anonymous Coward");
- if(name === "") name = "Jerky";
- Session.set("name", name);
- }
- Session.set("room", this._id);
- }
-};
-
-Template.room.roomName = function() {
- var room = Rooms.findOne({_id: Session.get("room")});
- return room && room.name ;
-};
-
-Template.room.messages = function() {
- return Messages.find({room: Session.get("room")});
-};
-
-Template.room.events = {
- "click #leave": function() {
- if(!window.confirm("Leave this room", "Do you really want to leave?")) return;
- Session.set("room", undefined);
- },
- "submit": function() {
- Messages.insert({
- "room": Session.get("room"),
- "author": Session.get("name"),
- "text": $("#msg").val()
- });
- $("#msg").val("");
- }
-};
View
@@ -1,35 +0,0 @@
-html, body {
- height: 100%;
- position: relative;
-}
-
-body {
- font-size: 14px;
- background: #ccc;
-}
-
-#wrapper {
- position: relative;
- top: 2.5%;
- width: 900px;
- height: 95%;
- margin: 0px auto;
- background: #fff;
- box-shadow: #888 10px 0px 15px;
- padding: 3px;
-}
-
-.roomScreen ul#messages {
- position: relative;
- border: 1px inset #ccc;
- width: 850px;
- height: 500px;
- margin: 0px auto;
- list-style: none;
- overflow: scroll;
-}
-
-.author {
- font-weight: bold;
- text-decoration: underline;
-}
Oops, something went wrong. Retry.

0 comments on commit c41c56b

Please sign in to comment.