X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=web%2Fquery%2Fvendor%2Fcouchapp%2F_attachments%2Fjquery.couch.app.util.js;fp=web%2Fquery%2Fvendor%2Fcouchapp%2F_attachments%2Fjquery.couch.app.util.js;h=b71aa54dba9826c6af13215e7629b117f1e0e170;hb=85070b3d456667f238051af1a2f1f2a0c12300ab;hp=0000000000000000000000000000000000000000;hpb=607f0e13927eb18075c375fa9ba5527da4fcbb44;p=myops.git
diff --git a/web/query/vendor/couchapp/_attachments/jquery.couch.app.util.js b/web/query/vendor/couchapp/_attachments/jquery.couch.app.util.js
new file mode 100644
index 0000000..b71aa54
--- /dev/null
+++ b/web/query/vendor/couchapp/_attachments/jquery.couch.app.util.js
@@ -0,0 +1,90 @@
+$.log = function(m) {
+ if (window && window.console && window.console.log) {
+ window.console.log(arguments.length == 1 ? m : arguments);
+ }
+};
+
+// http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery/1186309#1186309
+$.fn.serializeObject = function() {
+ var o = {};
+ var a = this.serializeArray();
+ $.each(a, function() {
+ if (o[this.name]) {
+ if (!o[this.name].push) {
+ o[this.name] = [o[this.name]];
+ }
+ o[this.name].push(this.value || '');
+ } else {
+ o[this.name] = this.value || '';
+ }
+ });
+ return o;
+};
+
+// todo remove this crap
+function escapeHTML(st) {
+ return(
+ st && st.replace(/&/g,'&').
+ replace(/>/g,'>').
+ replace(/'+a+'';
+ }).replace(/\@([\w\-]+)/g,function(user,name) {
+ return ''+user+'';
+ }).replace(/\#([\w\-\.]+)/g,function(word,tag) {
+ return ''+word+'';
+ });
+};
+
+$.fn.prettyDate = function() {
+ $(this).each(function() {
+ var string, title = $(this).attr("title");
+ if (title) {
+ string = $.prettyDate(title);
+ } else {
+ string = $.prettyDate($(this).text());
+ }
+ $(this).text(string);
+ });
+};
+
+$.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";
+};
+
+$.argsToArray = function(args) {
+ if (!args.callee) return args;
+ var array = [];
+ for (var i=0; i < args.length; i++) {
+ array.push(args[i]);
+ };
+ return array;
+}