~daker/loco-team-portal/fix.656761

« back to all changes in this revision

Viewing changes to loco_directory/media/js/twidenash.js

  • Committer: Chris Johnston
  • Date: 2010-09-28 17:35:23 UTC
  • mfrom: (301.1.1 loco-directory)
  • Revision ID: chrisjohnston@ubuntu.com-20100928173523-wog48dkv0eakp618
Bugfix for bug #620869 thanks to mhall119 and daker, and updated translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                var img = document.createElement("img");
77
77
                img.src = twidenash.items[i].img;
78
78
                img.width = 48;
 
79
                var relative_to = (arguments.length > 1) ? arguments[1] : new Date();
 
80
                var delta = parseInt((relative_to.getTime() - twidenash.items[i].dt) / 1000);
 
81
                var pluralize = function (singular, n) {
 
82
                    return '' + n + ' ' + singular + (n == 1 ? '' : 's');
 
83
                };
 
84
                if(delta < 60) {
 
85
                     date_msg = 'less than a minute ago ';
 
86
                } else if(delta < (45*60)) {
 
87
                    date_msg = 'about ' + pluralize("minute", parseInt(delta / 60)) + ' ago ';
 
88
                } else if(delta < (24*60*60)) {
 
89
                    date_msg = 'about ' + pluralize("hour", parseInt(delta / 3600)) + ' ago ';
 
90
                } else {
 
91
                    date_msg = 'about ' + pluralize("day", parseInt(delta / 86400)) + ' ago ';
 
92
                }
79
93
                var span = document.createElement("span");
80
94
                span.className = 'comment';
81
95
                var nick = document.createElement("span");
82
96
                nick.className = 'nick';
83
 
                nick.appendChild(document.createTextNode(twidenash.items[i].user + 
84
 
                    ": "));
 
97
                nick.appendChild(document.createTextNode(twidenash.items[i].user));
 
98
                var time = document.createElement("span");
 
99
                time.className = 'time';
 
100
                time.appendChild(document.createTextNode(" ( "+ date_msg +" ) "));
 
101
                
85
102
                var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi;
86
103
                span.innerHTML = twidenash.items[i].text.replace(exp,"<a href='$1' target='_blank'>$1</a>");
87
104
                li.appendChild(img);
88
105
                li.appendChild(nick);
 
106
                li.appendChild(time);
89
107
                li.appendChild(span);
90
108
                ul.appendChild(li);
91
109
                twidenash.printed++;