Changeset 27293 for main/trunk/greenstone2/macros/style.dm
- Timestamp:
- 2013-05-02T17:43:31+12:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/macros/style.dm
r27282 r27293 244 244 // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss 245 245 // Call as: alert(timestamp.printTime()); 246 String.prototype.printTime = function () \{247 var timestamp = parseInt(this, 10); // don't forget the second param248 var date = new Date( timestamp);246 function formatTime(timestamp) \{ 247 var int_timestamp = parseInt(timestamp, 10); // don't forget the second param 248 var date = new Date(int_timestamp); 249 249 return date.toLocaleDateString() + " " + date.toLocaleTimeString(); 250 250 \} … … 313 313 314 314 metapos++; 315 username = gsapi.getArchivesMetadata(doc_id, "username", metapos); 315 username = gsapi.getArchivesMetadata(doc_id, "username", metapos);//, "_cgiargun_", "_cgiargpw_"); 316 316 \} 317 317 318 318 // No need to sort by time, 319 // as the array is already stored sorted and hence retrieved in the right order by using metapos tcounter319 // as the array is already stored sorted and hence retrieved in the right order by using metapos counter 320 320 // If sorting the array of comment records, which would be by timestamp, see 321 321 // https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/sort … … 328 328 329 329 // create the output HTML for all comments in one go now 330 // (we do this here altogether to hopefully avoid reloading the page for each comment)330 // (we do this here for all values together to hopefully avoid reloading the page for each comment) 331 331 332 332 for(var i = 0; i < metapos; i++) \{ … … 339 339 340 340 // for each usercomment, create a child div with the username, timestamp and comment 341 342 var divgroup=document.createElement("div"); 343 var attr=document.createAttribute("class"); 344 attr.nodeValue="usercomment"; 345 divgroup.setAttributeNode(attr); 346 347 var divuser=document.createElement("div"); 348 var divtime=document.createElement("div"); 349 var divcomment=document.createElement("div"); 350 351 352 divgroup.appendChild(divuser); 353 var txt=document.createTextNode(username); 354 divuser.appendChild(txt); 355 356 divgroup.appendChild(divtime); 357 txt=document.createTextNode(timestamp.printTime()); // formate timestamp for date/time display 358 divtime.appendChild(txt); 359 360 divgroup.appendChild(divcomment); 361 txt=document.createTextNode(comment); 362 divcomment.appendChild(txt); 363 364 usercommentdiv.appendChild(divgroup); 341 displayInUserCommentList(usercommentdiv, username, timestamp, comment); 365 342 \} 366 343 … … 368 345 \} 369 346 347 function displayInUserCommentList(usercommentdiv, username, timestamp, comment) \{ 348 349 var divgroup=document.createElement("div"); 350 var attr=document.createAttribute("class"); 351 attr.nodeValue="usercomment"; 352 divgroup.setAttributeNode(attr); 353 354 var divuser=document.createElement("div"); 355 var divtime=document.createElement("div"); 356 var divcomment=document.createElement("div"); 357 358 359 divgroup.appendChild(divuser); 360 var txt=document.createTextNode(username); 361 divuser.appendChild(txt); 362 363 divgroup.appendChild(divtime); 364 txt=document.createTextNode(formatTime(timestamp)); // format timestamp for date/time display 365 divtime.appendChild(txt); 366 367 divgroup.appendChild(divcomment); 368 txt=document.createTextNode(comment); 369 divcomment.appendChild(txt); 370 371 usercommentdiv.appendChild(divgroup); 372 373 \} 370 374 371 375 // http://stackoverflow.com/questions/807878/javascript-that-executes-after-page-load
Note:
See TracChangeset
for help on using the changeset viewer.