//10/21/22 by DW -- new versions of basic dialog routines function askDialog (prompt, defaultvalue, placeholder, askcallback, typeparam) { function closeDialog () { $(theDialog).modal ("hide"); $(theDialog).on ("hidden.bs.modal", function () { //code that runs when dialog has finished being hidden $(theDialogContainer).remove (); }); } function cancelDialog () { if (askcallback !== undefined) { askcallback ("", true); } closeDialog (); } function okDialog () { //ok button was clicked if (askcallback !== undefined) { var val = theInputElement.val (); askcallback (val, false); } closeDialog (); } function getCloseIcon () { var theIcon = $("×"); $(theIcon).click (cancelDialog); return (theIcon); } function getPrompt () { var promptText = ""; if (prompt !== undefined) { promptText = prompt; } var thePrompt = $("

" + promptText + "

"); return (thePrompt); } function getInputElement () { var valueatt = ""; if (defaultvalue !== undefined) { valueatt = "value=\"" + defaultvalue + "\""; } var placeholderAtt = ""; if (placeholder !== undefined) { placeholderAtt = "placeholder=\"" + placeholder + "\""; } var typeatt = "type=\"text\""; if (typeparam !== undefined) { typeatt = "type=\"" + typeparam + "\""; } var theElement = $(""); return (theElement); } function getCancelButton () { var theButton = $("Cancel"); $(theButton).click (cancelDialog); return (theButton); } function getOkButton () { var theButton = $("OK"); $(theButton).click (okDialog); return (theButton); } var theDialogContainer = $("
"); var theDialog = $("
"); var theHeader = $("
"); $(theHeader).append (getCloseIcon ()); $(theHeader).append (getPrompt ()); $(theDialog).append (theHeader); var theBody = $("
"); var theInputElement = getInputElement (); theBody.append (theInputElement); $(theDialog).append (theBody); var theFooter = $("
"); $(theFooter).append (getCancelButton ()); $(theFooter).append (getOkButton ()); $(theDialog).append (theFooter); $(theDialogContainer).append (theDialog); $("body").prepend (theDialogContainer); $(theDialog).modal ("show"); $(theDialog).on ("shown", function () { theInputElement.focus (); theInputElement.select (); }); $(theDialog).on ("keydown", function (ev) { if (ev.which == 13) { okDialog (); } }); } function alertDialog (prompt, callback) { var divAlertDialog = $("
"); var img = $(""); var divPrompt = $("
"); var divButton = $("OK"); divAlertDialog.append (img); divAlertDialog.append (divPrompt); divAlertDialog.append (divButton); $("body").prepend (divAlertDialog); $(divPrompt).html (prompt); $(divButton).click (function () { $(divAlertDialog).modal ("hide"); if (callback !== undefined) { callback (); } }); $(divAlertDialog).on ("changePrompt", function (event, thePrompt) { $(divPrompt).html (thePrompt); }); $(divAlertDialog).on ("changeButton", function (event, theButtonString) { $(divButton).html (theButtonString); }); $(divAlertDialog).modal ("show"); return (divAlertDialog); } function threeWayDialog (userOptions, callback) { //5/9/25 by DW var options = { prompt: "Stay here, in the editor, or view the published post on the web?", button0: "Web", //the default button1: "Edit", //the main option button2: undefined, //the weird option tooltip0: undefined, tooltip1: undefined, tooltip2: undefined, classForDialog: "divThreeWayDialog", whereToAppend: $("body") } mergeOptions (userOptions, options); const theDialog = $("
"); function closeDialog () { theDialog.modal ("hide"); theDialog.on ("hidden.bs.modal", function () { //code that runs when dialog has finished being hidden theDialog.remove (); }); } function getPrompt () { const divPrompt = $("
"); divPrompt.html (options.prompt); return (divPrompt); } function getIcon () { const theIcon = $(""); return (theIcon); } function appendButton (buttontext, tooltip, flPrimary=false, flLeft=false) { if (buttontext !== undefined) { const theButton = $("" + buttontext + ""); if (flPrimary) { theButton.addClass ("btn-primary"); } if (flLeft) { theButton.addClass ("btn-left"); } if (tooltip !== undefined) { theButton.attr ("title", tooltip); } theButton.click (function () { closeDialog (); callback (buttontext); }); theButtons.append (theButton); } } const theBody = $("
"); theBody.append (getIcon ()); theBody.append (getPrompt ()); const theButtons = $("
"); appendButton (options.button0, options.tooltip0, true); appendButton (options.button1, options.tooltip1); appendButton (options.button2, options.tooltip2, undefined, true); theBody.append (theButtons); theDialog.append (theBody); options.whereToAppend.append (theDialog); theDialog.modal ("show"); } function tableEditor (userOptions, callback) { //5/12/25 by DW const version = "0.5.0"; //5/11/25 by DW console.log ("tableEditor v" + version); var options = { theOriginalTable: new Object (), whereToAppend: undefined, prompt: "", columnHeaders: ["Name", "Value"], buttonText: ["OK", "Cancel", "+"], nameInputClass: undefined, //6/15/25 by DW dialogClosed: function (flCancel, theEditedTable) { } }; function copyUserOptions (userOptions) { if (userOptions !== undefined) { for (x in userOptions) { if (userOptions [x] !== undefined) { options [x] = userOptions [x]; } } } } copyUserOptions (userOptions); var theDialog, theTable; function getTableEditor () { const divTableEditor = $("
"); function closeDialog () { theDialog.modal ("hide"); theDialog.on ("hidden.bs.modal", function () { //code that runs when dialog has finished being hidden divTableEditor.empty (); }); } function cancelDialog () { options.dialogClosed (true, ""); closeDialog (); } function okDialog () { //ok button was clicked var theReturnedTable = new Object (); theTable.find ("tr").each (function () { //5/11/25 by DW var name = $(this).find ('td:eq(0) input').val (); var value = $(this).find ('td:eq(1) input').val (); if ((name !== undefined) && (value !== undefined)) { name = trimWhitespace (name); if (name.length > 0) { theReturnedTable [name] = value; } } }); closeDialog (); options.dialogClosed (false, theReturnedTable); } function getHeader () { function getCloseIcon () { var theIcon = $("×"); theIcon.click (cancelDialog); return (theIcon); } function getPrompt () { var thePrompt = $("
" + options.prompt + "
"); return (thePrompt); } const theHeader = $("
"); theHeader.append (getCloseIcon ()); theHeader.append (getPrompt ()); theDialog.append (theHeader); return (theHeader); } function addRow (name, value, flSetFocus=false) { const theRow = $(""); const theNameCell = $(""); const theInputForName = $(""); theInputForName.val (name); theNameCell.append (theInputForName); if (options.nameInputClass !== undefined) { //6/15/25 by DW theInputForName.addClass (options.nameInputClass); } theRow.append (theNameCell); const theValueCell = $(""); const theInputForValue = $(""); theInputForValue.val (value); theValueCell.append (theInputForValue); theRow.append (theValueCell); const theTrashCell = $(""); const theTrashIcon = $(""); theTrashIcon.click (function () { theRow.empty (); }); theTrashCell.append (theTrashIcon); theRow.append (theTrashCell); theTable.append (theRow); if (flSetFocus) { theInputForName.focus (); } } function getColumnHeaders () { //5/11/25 by DW var theHeaders = $(""); function getHeader (name) { const theHeader = $("" + name + ""); return (theHeader); } theHeaders.append (getHeader (options.columnHeaders [0])); theHeaders.append (getHeader (options.columnHeaders [1])); return (theHeaders); } function getTable () { theTable = $("
"); theTable.append (getColumnHeaders ()); for (var x in options.theOriginalTable) { addRow (x, options.theOriginalTable [x]); } return (theTable); } function getBody () { const theBody = $("
"); theBody.append (getTable ()); return (theBody); } function getCancelButton () { const buttonText = options.buttonText [1]; var theButton = $("" + buttonText + ""); theButton.click (cancelDialog); return (theButton); } function getOkButton () { const buttonText = options.buttonText [0]; var theButton = $("" + buttonText + ""); theButton.click (okDialog); return (theButton); } function getPlusButton () { const buttonText = options.buttonText [2]; var theButton = $("" + buttonText + ""); theButton.click (function () { console.log ("theButton.click"); addRow ("", "", true); }); return (theButton); } theDialog = $("
"); theDialog.append (getHeader ()); theDialog.append (getBody ()); const theFooter = $("
"); theFooter.append (getCancelButton ()); theFooter.append (getOkButton ()); theFooter.append (getPlusButton ()); theDialog.append (theFooter); divTableEditor.append (theDialog); return (divTableEditor); } options.whereToAppend.append (getTableEditor ()); theDialog.modal ("show"); }