Permalink
Browse files

Slow progress. Added in a page limit, working around the issue that '…

…limit' and 'skip' queries currently break Meteor's observers. Also worked on backbone routing, but server-side routing isn't in place, and backbone routes seem to break template renders. Good times.
  • Loading branch information...
1 parent 28bfcf4 commit e21b0f54d1e1e2b18090fad3191b96981ac0d96a @bmelton committed Apr 16, 2012
Showing with 268 additions and 5 deletions.
  1. +3 −0 .meteor/packages
  2. +146 −0 client/eve.js
  3. +64 −0 client/orbvt.js
  4. +9 −0 client/utils.js
  5. +14 −5 orbvt.html
  6. +32 −0 server/orbvt.js
View
@@ -3,4 +3,7 @@
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
+jquery
+underscore
+backbone
autopublish
View
@@ -0,0 +1,146 @@
+/**
+ * Eve.js <evejs.com> - Version: 0.2 (April 15, 2012)
+ *
+ * A JavaScript meta-framework for scoped event delegation.
+ *
+ * Copyright (c) 2012 Michelle Steigerwalt, http://evejs.com/
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+var Eve = {
+
+ __registry: {},
+
+ __scopes: {},
+
+ __attachments: {},
+
+ __debugging: [],
+
+ __debugAll: false,
+
+ dbug: function(name, message) {
+ var debug = this.__debugAll;
+ if (!this.__debugAll) {
+ debug = false;
+ for (var i = 0; i<this.__debugging.length; i++) {
+ if (this.__debugging[i]==name) debug = true;
+ }
+ }
+ if (!debug) { return; }
+ while (name.length<10) { name=name+' '; }
+ name = name.substring(0, 10)+" - ";
+ console.info(name, message);
+ },
+
+ debug: function(moduleName) {
+ if (moduleName) {
+ this.__debugging.push(moduleName);
+ } else {
+ this.__debugAll = true;
+ }
+ },
+
+ register: function(name, obj) {
+ this.dbug(name, "registered");
+ if (this.__registry[name]) {
+ throw new Error("Module already exists: "+name);
+ }
+ obj.prototype.del = this.delegateScoped;
+ this.__registry[name] = obj;
+ return this;
+ },
+
+ scope: function(ns, fun) {
+ if (this.__scopes[ns]) {
+ console.warn("Duplicate namespace: "+ns);
+ }
+ this.__scopes[ns] = fun.apply({
+ name: ns,
+ namespace: ns,
+ listen: this.delegateScoped,
+ attach: this.attachFromScope
+ }, [ns]);
+ },
+
+ attach: function(moduleName, namespace) {
+ this.dbug(moduleName, "attached to "+namespace);
+ //We're delegating off the window, so there's no need to reattach for
+ //multiple instances of a single given module.
+ if (this.__attachments[moduleName+namespace]) {
+ return false;
+ }
+ if (!this.__registry[moduleName]) {
+ console.warn("Module not found: "+moduleName);
+ return false;
+ }
+ var mod = this.__registry[moduleName].apply({
+ namespace:namespace,
+ listen:this.delegateScoped,
+ name:moduleName
+ }, [namespace]);
+ this.__attachments[moduleName+namespace] = mod;
+ return true;
+ },
+
+ //This method is bound to the namespaced closure.
+ delegateScoped: function(selector, event, handler) {
+ //There's a special hell for putting optional parameters at the
+ //beginning. A special and awesome hell.
+ if (!handler) {
+ handler = event;
+ event = selector;
+ selector = '';
+ }
+ var name = this.name,
+ sel = (this.namespace+' '+selector).trim(),
+ fun = function() {
+ Eve.dbug(name, sel);
+ //Simple pass-through of scope and arguments.
+ handler.apply(this, arguments);
+ };
+ //JavaScript framework development is so much easier when you let some
+ //other framework do most of the work.
+ if (window.jQuery) {
+ $(window).delegate(sel, event, fun);
+ } else if (window.MooTools) {
+ //I really hate the MooTools event delegation syntax.
+ $(window).addEvent(event+':relay('+sel+')', fun);
+ } else if (window.YUI) {
+ YUI().use('node', function(Y) {
+ Y.one(document.body).delegate(event, fun, sel);
+ });
+ } else if (window.Prototype) {
+ $(document.body).on(event, sel, fun);
+ } else if (window.dojo) {
+ require(["dojo/on"], function(on){
+ on(document, sel+':'+event, fun);
+ });
+ } else {
+ console.error("Eve doesn't support your JavaScript framework.");
+ }
+ },
+
+ //This method is bound to the namespaced closure.
+ attachFromScope: function(moduleName, ns) {
+ Eve.attach(moduleName, this.namespace+' '+(ns||''));
+ }
+
+};
View
@@ -0,0 +1,64 @@
+Posts = new Meteor.Collection("Posts");
+Properties = new Meteor.Collection("Properties");
+nPosts = new Meteor.Collection("nPosts");
+
+if (Meteor.is_client) {
+ Template.stamp.stamp = function() {
+ return today();
+ };
+
+ Template.stamp.events = {
+ 'click #new_post': function(event) {
+ Meteor.call("test");
+ }
+ }
+
+ Template.orbvt.posts = function() {
+ posts = Posts.find({}, {sort: {timestamp: 1}}).fetch();
+ return posts.slice(0,10);
+ // return Posts.find({}, {sort: {timestamp: -1}});
+ };
+
+ Template.properties.properties = function() {
+ return Properties.find();
+ };
+
+ Template.orbvt.events = {
+ 'click h1': function(event) {
+ event.preventDefault();
+ },
+ 'click .destroy': function (event) {
+ Posts.remove(event.currentTarget.id);
+ if(Posts.find().count() == 0) {
+ var post = {title: 'Test post', author: 'bmelton', content: "Hello", date: 'April 11', timestamp: new Date()};
+ Posts.insert(post);
+ }
+ }
+ }
+}
+
+Meteor.startup(function () {
+ Backbone.history.start({pushState: true});
+});
+
+var self = this;
+var Router = Backbone.Router.extend({
+ routes: {
+ "": "main",
+ "new": "new"
+ },
+ main: function() {
+ console.log("Yo yo");
+ },
+ new: function() {
+ console.log("New");
+ }
+});
+
+Router = new Router;
+
+Eve.scope("#test", function() {
+ this.listen("li.nav", "click", function() {
+ console.log("HOLLA");
+ });
+});
View
@@ -0,0 +1,9 @@
+months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
+
+var today = function() {
+ var d = new Date();
+ month = months[d.getMonth()];
+ day = d.getDate();
+ year = d.getFullYear();
+ return month + " " + day + ", " + year ;
+}
View
@@ -18,13 +18,18 @@
{{>orbvt}}
</div>
</div>
+ <div style="display: none; background: white;" id="newpost">
+ <input type="text" name="title" id="id_title" value="title"><br />
+ <textarea name="content" id="id_content"></textarea><br />
+ <input type="submit" name="submit" id="submit" value="Submit" />
+ </div>
</body>
+
<template name="orbvt">
<div>
- {{#each posts}}
- {{>post}}
- <a href="#" id="{{_id}}" class="destroy">Delete</a>
- {{/each}}
+ {{#each posts}}
+ {{>post}}
+ {{/each}}
</div>
</template>
@@ -40,13 +45,17 @@
<template name="stamp">
{{stamp}}
- <div style="float: right; margin-right: 40px;"><a id="new_post" href="#">New Post</a></div>
+ <div style="float: right; margin-right: 40px;">
+ <a id="new_screen" href="/new">Screen</a> &nbsp;&nbsp;&nbsp;&nbsp;&middot; &nbsp;&nbsp;&nbsp;&nbsp;
+ <a id="new_post" href="#">New Post</a>
+ </div>
</template>
<template name="post">
<section id="{{_id}}">
<div class="post contain">
<h1><a href="{{_id}}">{{title}}</a></h1>
{{content}}<br />
+ <a href="#" id="{{_id}}" class="destroy">Delete</a>
</div>
</section>
</template>
View
@@ -0,0 +1,32 @@
+Posts = new Meteor.Collection("Posts");
+Properties = new Meteor.Collection("Properties");
+
+Meteor.methods({
+ test: function() {
+ Posts.insert({title: "INSERTED", author: "bmelton", date: "April 12", content: "Inserted from method."});
+ }
+});
+
+var jankystring = "abcdabcdblmblm";
+
+Meteor.startup(function () {
+ if(Posts.find().count() === 0) {
+ var default_message = "Hello world.";
+ var post = {
+ title: 'Test post',
+ author: 'bmelton',
+ content: default_message,
+ date: 'April 11',
+ timestamp: new Date()
+ };
+ }
+
+ if(Properties.find().count() == 0) {
+ Properties.insert({name: "@bmelton", type: "link", href : "http://twitter.com/bmelton/"});
+ Properties.insert({name: "github.com/bmelton", type: "link", href : "http://github.com/bmelton/"});
+ Properties.insert({name: "sympodial.com", type: "link", href : "http://sympodial.com/"});
+ }
+ // Meteor.default_server.method_handlers['/Posts/insert'] = function () {};
+ // Meteor.default_server.method_handlers['/Posts/remove'] = function () {};
+ // Meteor.default_server.method_handlers['/Posts/update'] = function () {};
+});

0 comments on commit e21b0f5

Please sign in to comment.