Changeset 32852
- Timestamp:
- 2019-03-04T21:13:35+13:00 (5 years ago)
- Location:
- main/trunk/greenstone3/web/interfaces/default/js
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts.js
r32850 r32852 233 233 mapGPScontainer.css("display", "none"); 234 234 235 addFunctionalityToTable(mapGPScontainer); 235 addFunctionalityToTable(mapGPScontainer); // ********************************** 236 236 mapGPScontainer.metaNameField.css("display", "none"); 237 237 mapGPScontainer.addRowButton.css("display", "none"); … … 306 306 $("#editContentButton").html(gs.text.de.hide_editor); 307 307 //wait for 0.5 sec to let ckeditor up 308 309 // The following is now done in the CKEDTIOR.on('instanceReady') handler, which is added when docReady, see documentedit_scripts_util::$( document ).ready(...) 310 // Attempting CKEDTIOR.on('instanceReady') at the start of this method didn't work because it was probably too late in page load phase to add the event handler then 311 // (the instanceReady() event would have been triggered before this method finally got called). 312 /* 308 313 setTimeout(function () { 309 314 $(".sectionText").each(function () { … … 311 316 }); 312 317 }, 500); 318 */ 313 319 var editBar = $("#editBarLeft"); 314 320 … … 371 377 addEditMapGPSLink(titleDivs[i]); 372 378 } 373 379 380 // We need to keep track of editableElementsInitialisationProgress: the number of editable elements that need to be initialised/need to finish initialising 381 // As CKEditors will be added, meaning more editable elements, must increment our counter editableElementsInitialisationProgress 382 var $num_editable_textareas = $(".sectionText"); // consider searching for 'contenteditable="true"' as this is what CKEDITOR is looking for (we think!) 383 editableElementsInitialisationProgress += $num_editable_textareas.length; 384 374 385 _baseURL = gs.xsltParams.library_name; 375 386 onVisibleMetadataSetChange(); // make sure that the selected item in the list is active 387 388 // If the user is attempting to leave the page, check if there are unsaved changes 389 // and if so, display an "Are you sure you want to leave" message. 390 // https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page 391 // Newer versions of Firefox/Chrome don't display custom message (security feature): 392 // https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox 393 // and http://jsfiddle.net/XZAWS/ 394 // jquery bind() is deprecated: https://stackoverflow.com/questions/33654716/is-jquery-bind-deprecated 395 console.log("**** away to set up beforeunload handler!"); 396 $(window).on("beforeunload", function(event) { 397 398 if(gs.cgiParams.docEdit == "1") { // like document.xsl, which checks the same var upon onload 399 // shouldn't check for whether changes are saved unless on Doc Editing page (DocEdit=1) 400 // else the following pop up always ends up appearing when attempting 401 // to leave a doc view page in Doc Editing Mode (when not yet actually Doc Editing) 402 403 // Because we've done extra work now in maintaining "editableElementsInitialisationProgress", which is 404 // the number of editable elements that still need to finish initialising, we can now be confident that 405 // the call to changesToUpdate() below won't return the wrong answers if a page with docEdit turned on 406 // is asked to unload (e.g. by pressing Reload) before the page has finished loading. 407 var changes = changesToUpdate(); 408 409 console.log("#### CHANGES before page reload: ", changes); 410 411 if(changes.length > 0) { 412 console.log("The collection hasn't yet been saved after editing. Are you sure you want to leave?"); 413 return "The collection hasn't yet been saved after editing. Are you sure you want to leave?"; 414 } 415 } 416 }); 417 418 376 419 } 377 420 -
main/trunk/greenstone3/web/interfaces/default/js/documentedit_scripts_util.js
r32850 r32852 21 21 22 22 23 // If the user is attempting to leave the page, check if there are unsaved changes 24 // and if so, display an "Are you sure you want to leave" message. 25 // https://stackoverflow.com/questions/7080269/javascript-before-leaving-the-page 26 // Newer versions of Firefox/Chrome don't display custom message (security feature): 27 // https://stackoverflow.com/questions/22776544/why-is-jquery-onbeforeunload-not-working-in-chrome-and-firefox 28 // and http://jsfiddle.net/XZAWS/ 29 // jquery bind() is deprecated: https://stackoverflow.com/questions/33654716/is-jquery-bind-deprecated 30 $(window).on("beforeunload", function(event) { 31 32 if(gs.cgiParams.docEdit == "1") { // like document.xsl, which checks the same var upon onload 33 // shouldn't check for whether changes are saved unless on Doc Editing page (DocEdit=1) 34 // else the following pop up always ends up appearing when attempting 35 // to leave a doc view page in Doc Editing Mode (when not yet actually Doc Editing) 36 37 38 var changes = changesToUpdate(); 39 40 //console.log("#### CHANGES before page reload: ", changes); 41 42 if(changes.length > 0) { 43 console.log("The collection hasn't yet been saved after editing. Are you sure you want to leave?"); 44 return "The collection hasn't yet been saved after editing. Are you sure you want to leave?"; 45 } 46 } 47 48 }); 49 23 // We need to wait for all editable elements (metadataTable and sectionText) to be finished with initialising 24 // before we try to store their current states in the editableInitStates array 25 // To do this, we need to keep track of how many elements still require initialising. 26 var editableElementsInitialisationProgress = 0; 27 28 50 29 51 30 function encodeDelimiters(meta_value) { … … 305 284 { 306 285 var resultArray = new Array(); 307 getLastEditableStates(); 308 for (var j in editableLastStates) 309 { 310 if (isNodeChanged(editableLastStates[j])) 311 { 312 resultArray.push(editableLastStates[j].editableNode); 286 287 console.log("**** changesToUpdate::editableElementsInitialisationProgress = " + editableElementsInitialisationProgress); 288 289 // Only want to check for valid edited states if the editableInitStates has been fully set up: 290 // We don't bother if editableInitStates is not ready: 291 // if editableInitStates array has nothing in it (which means CKEditor is not ready) 292 // OR if some of the editable elements (metadataTable OR ckeditor editable values) still need to be initialised/initialising is only partway through 293 if ((editableInitStates.length > 0) && (editableElementsInitialisationProgress == 0)) { 294 getLastEditableStates(); 295 for (var j in editableLastStates) 296 { 297 if (isNodeChanged(editableLastStates[j])) 298 { 299 resultArray.push(editableLastStates[j].editableNode); 300 } 313 301 } 314 302 } … … 337 325 } 338 326 327 console.log("**** isNodeChanged() editableInitStates = ", editableInitStates); 339 328 return true; 340 329 … … 909 898 //This registering can cause a sizeable delay so we'll thread it (effectively) so the browser is not paused 910 899 cell.originalValue = cell.value; 911 setTimeout(function(){addEditableState(cell, editableInitStates)}, 0); 900 setTimeout(function(){ 901 addEditableState(cell, editableInitStates); 902 // finished initialising one more editable element, 903 // so decrement the counter keeping track of how many elements still need initialising 904 editableElementsInitialisationProgress--; 905 },0); 912 906 } 913 907 … … 958 952 function addFunctionalityToTable(table) 959 953 { 960 table.find("tr").each(function() 954 var $tr_array = table.find("tr"); 955 956 957 // We need to keep track of editableElementsInitialisationProgress: the number of editable elements that still need to be initialised/need to finish initialising 958 // Each table's rows means *that* many more editable elements still need initialising. 959 // So each time addFunctionalityToTable() is called on a table, we must increment our counter editableElementsInitialisationProgress 960 // with how many editable cells it has/how many rows it has. 961 editableElementsInitialisationProgress += $tr_array.length; 962 console.log("**** addFunctionalityToTable::editableElementsInitialisationProgress = " + editableElementsInitialisationProgress); 963 964 $tr_array.each(function() 961 965 { 962 966 var cells = $(this).find("td"); … … 1456 1460 } 1457 1461 */ 1462 1463 1464 $( document ).ready(function() { 1465 console.log( "**** Dom ready!" ); 1466 1467 // monitor whether ckeditor instances are all ready 1468 // See https://stackoverflow.com/questions/18461206/how-to-retrieve-the-ckeditor-status-ready 1469 // (and https://stackoverflow.com/questions/3447803/how-to-determine-if-ckeditor-is-loaded ) 1470 if(gs.cgiParams.docEdit == "1") { // CKEDITOR only exists in docEdit mode 1471 //CKEDITOR.on( 'loaded', function( evt ) { // not triggered 1472 //console.log("*** CKEDITOR loaded"); 1473 CKEDITOR.on( 'instanceReady', function( evt ) { 1474 console.log("*** CKEDITOR instanceReady", evt); 1475 addCKEEditableState(evt,editableInitStates); 1476 // finished initialising one more editable element, 1477 // so decrement the counter keeping track of how many elements still need initialising 1478 editableElementsInitialisationProgress--; 1479 } ); 1480 //} ); 1481 } 1482 1483 }); 1484 1485 1486
Note:
See TracChangeset
for help on using the changeset viewer.