2 if (window && window.console && window.console.log) {
3 window.console.log(arguments.length == 1 ? m : arguments);
7 // http://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery/1186309#1186309
8 $.fn.serializeObject = function() {
10 var a = this.serializeArray();
11 $.each(a, function() {
13 if (!o[this.name].push) {
14 o[this.name] = [o[this.name]];
16 o[this.name].push(this.value || '');
18 o[this.name] = this.value || '';
24 // todo remove this crap
25 function escapeHTML(st) {
27 st && st.replace(/&/g,'&').
30 replace(/"/g,'"')
34 function safeHTML(st, len) {
35 return st ? escapeHTML(st.substring(0,len)) : '';
38 // todo this should take a replacement template
39 $.linkify = function(body) {
40 return body.replace(/((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi,function(a) {
41 return '<a target="_blank" href="'+a+'">'+a+'</a>';
42 }).replace(/\@([\w\-]+)/g,function(user,name) {
43 return '<a href="#/mentions/'+encodeURIComponent(name.toLowerCase())+'">'+user+'</a>';
44 }).replace(/\#([\w\-\.]+)/g,function(word,tag) {
45 return '<a href="#/tags/'+encodeURIComponent(tag.toLowerCase())+'">'+word+'</a>';
49 $.fn.prettyDate = function() {
50 $(this).each(function() {
51 var string, title = $(this).attr("title");
53 string = $.prettyDate(title);
55 string = $.prettyDate($(this).text());
61 $.prettyDate = function(time){
63 var date = new Date(time.replace(/-/g,"/").replace("T", " ").replace("Z", " +0000").replace(/(\d*\:\d*:\d*)\.\d*/g,"$1")),
64 diff = (((new Date()).getTime() - date.getTime()) / 1000),
65 day_diff = Math.floor(diff / 86400);
67 if (isNaN(day_diff)) return time;
69 return day_diff < 1 && (
70 diff < 60 && "just now" ||
71 diff < 120 && "1 minute ago" ||
72 diff < 3600 && Math.floor( diff / 60 ) + " minutes ago" ||
73 diff < 7200 && "1 hour ago" ||
74 diff < 86400 && Math.floor( diff / 3600 ) + " hours ago") ||
75 day_diff == 1 && "yesterday" ||
76 day_diff < 21 && day_diff + " days ago" ||
77 day_diff < 45 && Math.ceil( day_diff / 7 ) + " weeks ago" ||
79 // day_diff < 730 && Math.ceil( day_diff / 31 ) + " months ago" ||
80 // Math.ceil( day_diff / 365 ) + " years ago";
83 $.argsToArray = function(args) {
84 if (!args.callee) return args;
86 for (var i=0; i < args.length; i++) {