Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update vendor

  • Loading branch information...
commit 97fa538b9c755ebe0d2085aeea3ee5ea96db15d6 1 parent dc8c25a
@jchris jchris authored
View
50 vendor/couchapp/_attachments/jquery.couch.app.js
@@ -37,67 +37,71 @@
function docForm() { alert("docForm has been moved to vendor/couchapp/lib/docForm.js, use app.require to load") };
- function resolveModule(names, parent, current) {
+ function resolveModule(path, names, parents, current) {
+ parents = parents || [];
if (names.length === 0) {
if (typeof current != "string") {
throw ["error","invalid_require_path",
'Must require a JavaScript string, not: '+(typeof current)];
}
- return [current, parent];
+ return [current, parents];
}
var n = names.shift();
if (n == '..') {
- if (!(parent && parent.parent)) {
- throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)];
+ parents.pop();
+ var pp = parents.pop();
+ if (!pp) {
+ throw ["error", "invalid_require_path", path];
}
- return resolveModule(names, parent.parent.parent, parent.parent);
+ return resolveModule(path, names, parents, pp);
} else if (n == '.') {
- if (!parent) {
- throw ["error", "invalid_require_path", 'Object has no parent '+JSON.stringify(current)];
+ var p = parents.pop();
+ if (!p) {
+ throw ["error", "invalid_require_path", path];
}
- return resolveModule(names, parent.parent, parent);
+ return resolveModule(path, names, parents, p);
+ } else {
+ parents = [];
}
if (!current[n]) {
- throw ["error", "invalid_require_path", 'Object has no property "'+n+'". '+JSON.stringify(current)];
+ throw ["error", "invalid_require_path", path];
}
- var p = current;
- current = current[n];
- current.parent = p;
- return resolveModule(names, p, current);
+ parents.push(current);
+ return resolveModule(path, names, parents, current[n]);
}
function makeRequire(ddoc) {
var moduleCache = [];
- function getCachedModule(name, parent) {
+ function getCachedModule(name, parents) {
var key, i, len = moduleCache.length;
for (i=0;i<len;++i) {
key = moduleCache[i].key;
- if (key[0] === name && key[1] === parent) {
+ if (key[0] === name && key[1] === parents) {
return moduleCache[i].module;
}
}
return null;
}
- function setCachedModule(name, parent, module) {
- moduleCache.push({ key: [name, parent], module: module });
+ function setCachedModule(name, parents, module) {
+ moduleCache.push({ key: [name, parents], module: module });
}
- var require = function (name, parent) {
- var cachedModule = getCachedModule(name, parent);
+ var require = function (name, parents) {
+ var cachedModule = getCachedModule(name, parents);
if (cachedModule !== null) {
return cachedModule;
}
var exports = {};
- var resolved = resolveModule(name.split('/'), parent, ddoc);
+ var resolved = resolveModule(name, name.split('/'), parents, ddoc);
var source = resolved[0];
- parent = resolved[1];
+ parents = resolved[1];
var s = "var func = function (exports, require) { " + source + " };";
try {
eval(s);
- func.apply(ddoc, [exports, function(name) {return require(name, parent, source)}]);
+ func.apply(ddoc, [exports, function(name) {return require(name, parents)}]);
} catch(e) {
throw ["error","compilation_error","Module require('"+name+"') raised error "+e.toSource()];
}
- setCachedModule(name, parent, exports);
+ setCachedModule(name, parents, exports);
return exports;
}
return require;
View
13 vendor/couchapp/_attachments/jquery.couch.app.util.js
@@ -48,7 +48,13 @@ $.linkify = function(body) {
$.fn.prettyDate = function() {
$(this).each(function() {
- $(this).text($.prettyDate($(this).text()));
+ var string, title = $(this).attr("title");
+ if (title) {
+ string = $.prettyDate(title);
+ } else {
+ string = $.prettyDate($(this).text());
+ }
+ $(this).text(string);
});
};
@@ -69,8 +75,9 @@ $.prettyDate = function(time){
day_diff == 1 && "yesterday" ||
day_diff < 21 && day_diff + " days ago" ||
day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
- day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
- Math.ceil( day_diff / 365 ) + " years ago";
+ time;
+ // day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
+ // Math.ceil( day_diff / 365 ) + " years ago";
};
$.argsToArray = function(args) {
View
74 vendor/couchapp/_attachments/jquery.evently.js
@@ -22,7 +22,7 @@ function $$(node) {
}
};
$.forIn = forIn;
- function funViaString(fun) {
+ function funViaString(fun, hint) {
if (fun && fun.match && fun.match(/^function/)) {
eval("var f = "+fun);
if (typeof f == "function") {
@@ -31,7 +31,8 @@ function $$(node) {
return f.apply(this, arguments);
} catch(e) {
// IF YOU SEE AN ERROR HERE IT HAPPENED WHEN WE TRIED TO RUN YOUR FUNCTION
- $.log({"message": "Error in evently function.", "error": e, "src" : fun});
+ $.log({"message": "Error in evently function.", "error": e,
+ "src" : fun, "hint":hint});
throw(e);
}
};
@@ -42,7 +43,7 @@ function $$(node) {
function runIfFun(me, fun, args) {
// if the field is a function, call it, bound to the widget
- var f = funViaString(fun);
+ var f = funViaString(fun, me);
if (typeof f == "function") {
return f.apply(me, args);
} else {
@@ -75,43 +76,71 @@ function $$(node) {
function extractEvents(name, ddoc) {
// extract events from ddoc.evently and ddoc.vendor.*.evently
- var events = [true, {}];
- $.forIn(ddoc.vendor, function(k, v) {
+ var events = [true, {}]
+ , vendor = ddoc.vendor || {}
+ , evently = ddoc.evently || {}
+ ;
+ $.forIn(vendor, function(k, v) {
if (v.evently && v.evently[name]) {
events.push(v.evently[name]);
}
});
- if (ddoc.evently[name]) {events.push(ddoc.evently[name]);}
+ if (evently[name]) {events.push(evently[name]);}
return $.extend.apply(null, events);
}
+ function extractPartials(ddoc) {
+ var partials = [true, {}]
+ , vendor = ddoc.vendor || {}
+ , evently = ddoc.evently || {}
+ ;
+ $.forIn(vendor, function(k, v) {
+ if (v.evently && v.evently._partials) {
+ partials.push(v.evently._partials);
+ }
+ });
+ if (evently._partials) {partials.push(evently._partials);}
+ return $.extend.apply(null, partials);
+ };
+
+ function applyCommon(events) {
+ if (events._common) {
+ $.forIn(events, function(k, v) {
+ events[k] = $.extend(true, {}, events._common, v);
+ });
+ delete events._common;
+ return events;
+ } else {
+ return events;
+ }
+ }
+
$.fn.evently = function(events, app, args) {
var elem = $(this);
// store the app on the element for later use
if (app) {
- $$(elem).app = app;
+ $$(elem).app = app;
}
if (typeof events == "string") {
events = extractEvents(events, app.ddoc);
}
-
+ events = applyCommon(events);
$$(elem).evently = events;
+ if (app && app.ddoc) {
+ $$(elem).partials = extractPartials(app.ddoc);
+ }
// setup the handlers onto elem
forIn(events, function(name, h) {
eventlyHandler(elem, name, h, args);
});
if (events._init) {
- // $.log("ev _init", elem);
elem.trigger("_init", args);
}
if (app && events._changes) {
$("body").bind("evently-changes-"+app.db.name, function() {
- // we want to unbind this function when the element is deleted.
- // maybe jquery 1.4.2 has this covered?
- // $.log('changes', elem);
elem.trigger("_changes");
});
followChanges(app);
@@ -122,10 +151,15 @@ function $$(node) {
// eventlyHandler applies the user's handler (h) to the
// elem, bound to trigger based on name.
function eventlyHandler(elem, name, h, args) {
+ if ($.evently.log) {
+ elem.bind(name, function() {
+ $.log(elem, name);
+ });
+ }
if (h.path) {
elem.pathbinder(name, h.path);
}
- var f = funViaString(h);
+ var f = funViaString(h, name);
if (typeof f == "function") {
elem.bind(name, {args:args}, f);
} else if (typeof f == "string") {
@@ -141,7 +175,7 @@ function $$(node) {
} else {
// an object is using the evently / mustache template system
if (h.fun) {
- elem.bind(name, {args:args}, funViaString(h.fun));
+ throw("e.fun has been removed, please rename to e.before")
}
// templates, selectors, etc are intepreted
// when our named event is triggered.
@@ -166,7 +200,7 @@ function $$(node) {
// if there's a query object we run the query,
// and then call the data function with the response.
if (h.before && (!qrun || !arun)) {
- funViaString(h.before).apply(me, args);
+ funViaString(h.before, me).apply(me, args);
}
if (h.async && !arun) {
runAsync(me, h, args)
@@ -200,22 +234,22 @@ function $$(node) {
}
if (h.after) {
runIfFun(me, h.after, args);
- // funViaString(h.after).apply(me, args);
}
}
};
// todo this should return the new element
function mustachioed(me, h, args) {
+ var partials = $$(me).partials;
return $($.mustache(
runIfFun(me, h.mustache, args),
runIfFun(me, h.data, args),
- runIfFun(me, h.partials, args)));
+ runIfFun(me, $.extend(true, partials, h.partials), args)));
};
function runAsync(me, h, args) {
// the callback is the first argument
- funViaString(h.async).apply(me, [function() {
+ funViaString(h.async, me).apply(me, [function() {
renderElement(me, h,
$.argsToArray(arguments).concat($.argsToArray(args)), false, true);
}].concat($.argsToArray(args)));
@@ -233,7 +267,9 @@ function $$(node) {
var q = {};
forIn(qu, function(k, v) {
- q[k] = v;
+ if (["type", "view"].indexOf(k) == -1) {
+ q[k] = v;
+ }
});
if (qType == "newRows") {
View
2  vendor/couchapp/evently/account/loginForm/mustache.html
@@ -1,5 +1,5 @@
<form>
- <label for="name">Name</label> <input type="text" name="name" value="">
+ <label for="name">Name</label> <input type="text" name="name" value="" autocapitalize="off" autocorrect="off">
<label for="password">Password</label> <input type="password" name="password" value="">
<input type="submit" value="Login">
<a href="#signup">or Signup</a>
View
2  vendor/couchapp/evently/account/signupForm/mustache.html
@@ -1,5 +1,5 @@
<form>
- <label for="name">Name</label> <input type="text" name="name" value="">
+ <label for="name">Name</label> <input type="text" name="name" value="" autocapitalize="off" autocorrect="off">
<label for="password">Password</label> <input type="password" name="password" value="">
<input type="submit" value="Signup">
<a href="#login">or Login</a>
View
15 vendor/couchapp/lib/docform.js
@@ -26,15 +26,22 @@ function docForm(formSelector, opts) {
function formToDeepJSON(form, fields, doc) {
form = $(form);
fields.forEach(function(field) {
- var element = form.find("[name="+field+"]");
+ var element = form.find("[name="+field+"]"),
+ parts = field.split('-'),
+ frontObj = doc, frontName = parts.shift();
+
if (element.attr('type') === 'checkbox') {
var val = element.attr('checked');
} else {
var val = element.val();
- if (!val) return;
+ if (!val) {
+ if (frontObj[field]) {
+ delete frontObj[field];
+ }
+ return;
+ }
}
- var parts = field.split('-');
- var frontObj = doc, frontName = parts.shift();
+
while (parts.length > 0) {
frontObj[frontName] = frontObj[frontName] || {};
frontObj = frontObj[frontName];
View
4 vendor/couchapp/lib/linkup.js
@@ -11,8 +11,8 @@ exports.encode = function(body, person_prefix, tag_prefix) {
return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
return '<a target="_blank" href="'+a+'">'+a+'</a>';
}).replace(/\@([\w\-]+)/g,function(user,name) {
- return '<a href="'+person_prefix+encodeURIComponent(name.toLowerCase())+'">'+user+'</a>';
+ return '<a href="'+person_prefix+encodeURIComponent(name)+'">'+user+'</a>';
}).replace(/\#([\w\-\.]+)/g,function(word,tag) {
- return '<a href="'+tag_prefix+encodeURIComponent(tag.toLowerCase())+'">'+word+'</a>';
+ return '<a href="'+tag_prefix+encodeURIComponent(tag)+'">'+word+'</a>';
});
};
View
21 vendor/couchapp/lib/utils.js
@@ -0,0 +1,21 @@
+exports.prettyDate = function(time){
+
+ var date = new Date(time.replace(/-/g,"/").replace("T", " ").replace("Z", " +0000").replace(/(\d*\:\d*:\d*)\.\d*/g,"$1")),
+ diff = (((new Date()).getTime() - date.getTime()) / 1000),
+ day_diff = Math.floor(diff / 86400);
+
+ if (isNaN(day_diff)) return time;
+
+ return day_diff < 1 && (
+ diff < 60 && "just now" ||
+ diff < 120 && "1 minute ago" ||
+ diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
+ diff < 7200 && "1 hour ago" ||
+ diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
+ day_diff == 1 && "yesterday" ||
+ day_diff < 21 && day_diff + " days ago" ||
+ day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
+ time;
+ // day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
+ // Math.ceil( day_diff / 365 ) + " years ago";
+};
Please sign in to comment.
Something went wrong with that request. Please try again.