- Timestamp:
- 2017-03-31T19:42:22+13:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/user_comments.js
r31547 r31558 5 5 // http://stackoverflow.com/questions/8714472/cant-pass-event-to-addeventlistener-closure-issue 6 6 // https://www.sitepoint.com/demystifying-javascript-closures-callbacks-iifes/ 7 // http://stackoverflow.com/questions/4869712/new-without-delete-on-same-variable-in-javascript 8 // http://stackoverflow.com/questions/7375120/why-is-arr-faster-than-arr-new-array 9 // http://stackoverflow.com/questions/874205/what-is-the-difference-between-an-array-and-an-object 10 // http://stackoverflow.com/questions/33514915/what-s-the-difference-between-and-while-declaring-a-javascript-array 11 // http://www.nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ 7 12 8 13 /*************** 9 14 * USER COMMENTS 10 15 ****************/ 16 17 gs.usercomments = {}; 18 11 19 // http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss 12 20 // Call as: alert(timestamp.printTime()); 13 function formatTime(timestamp) {21 gs.usercomments.formatTime = function(timestamp) { 14 22 var int_timestamp = parseInt(timestamp, 10); // don't forget the second param 15 23 var date = new Date(int_timestamp); … … 17 25 } 18 26 19 function loadUserComments() {27 gs.usercomments.loadUserComments = function() { 20 28 21 29 // don't bother loading comments if we're not on a document page (in which case there's no docid) … … 74 82 //var json_result_str = gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index"); 75 83 76 gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index", loadedUserComments, false); // false for asynchronous77 } 78 79 function loadedUserComments(data)84 gs.functions.getMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "index", gs.usercomments.loadedUserComments, false); // false for asynchronous 85 } 86 87 gs.usercomments.loadedUserComments = function(data) 80 88 { 81 89 // don't bother displaying comments if we're not on a document page … … 141 149 142 150 // for each usercomment, create a child div with the username, timestamp and comment 143 displayInUserCommentList(usercommentdiv, username, timestamp, comment);151 gs.usercomments.displayInUserCommentList(usercommentdiv, username, timestamp, comment); 144 152 145 153 i++; … … 155 163 156 164 157 function displayInUserCommentList(usercommentdiv, username, timestamp, comment) {165 gs.usercomments.displayInUserCommentList = function(usercommentdiv, username, timestamp, comment) { 158 166 159 167 //alert("Comment: " + username + " " + timestamp + " " + comment); … … 174 182 175 183 divgroup.appendChild(divtime); 176 txt=document.createTextNode( formatTime(timestamp)); // format timestamp for date/time display184 txt=document.createTextNode(gs.usercomments.formatTime(timestamp)); // format timestamp for date/time display 177 185 divtime.appendChild(txt); 178 186 … … 193 201 // Unused. Replaced in favour of call to escape() in setMetaArray function that calls urlPostSync 194 202 // http://stackoverflow.com/questions/6020714/escape-html-using-jquery 195 function safeHTML(str) {203 gs.usercomments.safeHTML = function(str) { 196 204 return str.replace("&", "&").replace("<", "<").replace(">", ">").replace('"',""").replace("'","'").replace("/", "/"); //"\\"" 197 } 198 199 200 function addUserComment(_username, _comment, _docid, doc) {205 } 206 207 208 gs.usercomments.addUserComment = function(_username, _comment, _docid, doc) { 201 209 202 210 // don't add empty strings for name/comment … … 287 295 288 296 //var result = gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index"); 289 gs.functions.setMetadataArray(gs.variables["c"], gs.variables["site"], docArray, "accumulate", "import|archives|index", function(ajaxResult) { return doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, false); // false for asynchronous, 297 gs.functions.setMetadataArray(gs.variables["c"], 298 gs.variables["site"], 299 docArray, "accumulate", 300 "import|archives|index", 301 function(ajaxResult) { return gs.usercomments.doneUpdatingMetatada(ajaxResult, _username, _timestamp, _comment); }, 302 false); // false for asynchronous, 290 303 // this is ok since we're disabling the comment submit button, so no further set-meta-array calls can be 291 304 // made until the ajax call returns and the callback is called which re-enables the submit button … … 296 309 } 297 310 298 function doneUpdatingMetatada(data, _username, _timestamp, _comment)311 gs.usercomments.doneUpdatingMetatada = function(data, _username, _timestamp, _comment) 299 312 { 300 313 … … 339 352 var usercommentdiv = document.getElementById("usercomments"); 340 353 if(usercommentdiv != undefined) { 341 displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment);354 gs.usercomments.displayInUserCommentList(usercommentdiv, _username, _timestamp, _comment); 342 355 } 343 356 } … … 348 361 } 349 362 350 function commentAreaSetup() {351 loadUserComments();363 gs.usercomments.commentAreaSetup = function() { 364 gs.usercomments.loadUserComments(); 352 365 353 366 //$("div#commentarea").html("<textarea required=\"required\" name=\"comment\" rows=\"10\" cols=\"64\" placeholder=\"Add your comment here...\"></textarea>"); … … 361 374 // This way we ensure we don't replace any other onLoad() functions, but append the loadUserComments() 362 375 // function to the existing set of eventhandlers called onDocReady 363 $(document).ready( commentAreaSetup);364 376 $(document).ready(gs.usercomments.commentAreaSetup); 377
Note:
See TracChangeset
for help on using the changeset viewer.