diff --git a/themes/intotheeast/js/post/post-form.js b/themes/intotheeast/js/post/post-form.js index 6cdc037..44065a3 100644 --- a/themes/intotheeast/js/post/post-form.js +++ b/themes/intotheeast/js/post/post-form.js @@ -92,4 +92,4 @@ Please report this to https://github.com/markedjs/marked.`,o){var s="

An error ----- `]},Id={link:"URL for the link:",image:"URL of the image:"},zd={locale:"en-US",format:{hour:"2-digit",minute:"2-digit"}},Od={bold:"**",code:"```",italic:"*"},Hd={sbInit:"Attach files by drag and dropping or pasting from clipboard.",sbOnDragEnter:"Drop image to upload it.",sbOnDrop:"Uploading image #images_names#...",sbProgress:"Uploading #file_name#: #progress#%",sbOnUploaded:"Uploaded #image_name#",sizeUnits:" B, KB, MB"},Rd={noFileGiven:"You must select a file.",typeNotAllowed:"This image type is not allowed.",fileTooLarge:`Image #image_name# is too big (#image_size#). -Maximum file size is #image_max_size#.`,importError:"Something went wrong when uploading the image #image_name#."};function J(o){o=o||{},o.parent=this;var f=!0;if(o.autoDownloadFontAwesome===!1&&(f=!1),o.autoDownloadFontAwesome!==!0)for(var c=document.styleSheets,l=0;l-1&&(f=!1);if(f){var s=document.createElement("link");s.rel="stylesheet",s.href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css",document.getElementsByTagName("head")[0].appendChild(s)}if(o.element)this.element=o.element;else if(o.element===null){console.log("EasyMDE: Error. No element was found.");return}if(o.toolbar===void 0){o.toolbar=[];for(var g in pr)Object.prototype.hasOwnProperty.call(pr,g)&&(g.indexOf("separator-")!=-1&&o.toolbar.push("|"),(pr[g].default===!0||o.showIcons&&o.showIcons.constructor===Array&&o.showIcons.indexOf(g)!=-1)&&o.toolbar.push(g))}if(Object.prototype.hasOwnProperty.call(o,"previewClass")||(o.previewClass="editor-preview"),Object.prototype.hasOwnProperty.call(o,"status")||(o.status=["autosave","lines","words","cursor"],o.uploadImage&&o.status.unshift("upload-image")),o.previewRender||(o.previewRender=function(p){return this.parent.markdown(p)}),o.parsingConfig=Pt({highlightFormatting:!0},o.parsingConfig||{}),o.insertTexts=Pt({},Nd,o.insertTexts||{}),o.promptTexts=Pt({},Id,o.promptTexts||{}),o.blockStyles=Pt({},Od,o.blockStyles||{}),o.autosave!=null&&(o.autosave.timeFormat=Pt({},zd,o.autosave.timeFormat||{})),o.iconClassMap=Pt({},ke,o.iconClassMap||{}),o.shortcuts=Pt({},Sd,o.shortcuts||{}),o.maxHeight=o.maxHeight||void 0,o.direction=o.direction||"ltr",typeof o.maxHeight<"u"?o.minHeight=o.maxHeight:o.minHeight=o.minHeight||"300px",o.errorCallback=o.errorCallback||function(p){alert(p)},o.uploadImage=o.uploadImage||!1,o.imageMaxSize=o.imageMaxSize||2097152,o.imageAccept=o.imageAccept||"image/png, image/jpeg, image/gif, image/avif",o.imageTexts=Pt({},Hd,o.imageTexts||{}),o.errorMessages=Pt({},Rd,o.errorMessages||{}),o.imagePathAbsolute=o.imagePathAbsolute||!1,o.imageCSRFName=o.imageCSRFName||"csrfmiddlewaretoken",o.imageCSRFHeader=o.imageCSRFHeader||!1,o.imageInputName=o.imageInputName||"image",o.autosave!=null&&o.autosave.unique_id!=null&&o.autosave.unique_id!=""&&(o.autosave.uniqueId=o.autosave.unique_id),o.overlayMode&&o.overlayMode.combine===void 0&&(o.overlayMode.combine=!0),this.options=o,this.render(),o.initialValue&&(!this.options.autosave||this.options.autosave.foundSavedValue!==!0)&&this.value(o.initialValue),o.uploadImage){var d=this;this.codemirror.on("dragenter",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbOnDragEnter),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragend",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbInit),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragleave",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbInit),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragover",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbOnDragEnter),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("drop",function(p,y){y.stopPropagation(),y.preventDefault(),o.imageUploadFunction?d.uploadImagesUsingCustomFunction(o.imageUploadFunction,y.dataTransfer.files):d.uploadImages(y.dataTransfer.files)}),this.codemirror.on("paste",function(p,y){o.imageUploadFunction?d.uploadImagesUsingCustomFunction(o.imageUploadFunction,y.clipboardData.files):d.uploadImages(y.clipboardData.files)})}}J.prototype.uploadImages=function(o,f,c){if(o.length!==0){for(var l=[],s=0;s=2){var R=I[1];if(f.imagesPreviewHandler){var H=f.imagesPreviewHandler(I[1]);typeof H=="string"&&(R=H)}if(window.EMDEimagesCache[R])T(B,window.EMDEimagesCache[R]);else{window.EMDEimagesCache[R]={};var _=document.createElement("img");_.onload=function(){window.EMDEimagesCache[R]={naturalWidth:_.naturalWidth,naturalHeight:_.naturalHeight,url:R},T(B,window.EMDEimagesCache[R])},_.src=R}}}})}this.codemirror.on("update",function(){z()}),this.gui.sideBySide=this.createSideBySide(),this._rendered=this.element,(f.autofocus===!0||o.autofocus)&&this.codemirror.focus();var N=this.codemirror;setTimeout(function(){N.refresh()}.bind(N),0)};J.prototype.cleanup=function(){document.removeEventListener("keydown",this.documentOnKeyDown)};function Fu(){if(typeof localStorage=="object")try{localStorage.setItem("smde_localStorage",1),localStorage.removeItem("smde_localStorage")}catch{return!1}else return!1;return!0}J.prototype.autosave=function(){if(Fu()){var o=this;if(this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("EasyMDE: You must set a uniqueId to use the autosave feature");return}this.options.autosave.binded!==!0&&(o.element.form!=null&&o.element.form!=null&&o.element.form.addEventListener("submit",function(){clearTimeout(o.autosaveTimeoutId),o.autosaveTimeoutId=void 0,localStorage.removeItem("smde_"+o.options.autosave.uniqueId)}),this.options.autosave.binded=!0),this.options.autosave.loaded!==!0&&(typeof localStorage.getItem("smde_"+this.options.autosave.uniqueId)=="string"&&localStorage.getItem("smde_"+this.options.autosave.uniqueId)!=""&&(this.codemirror.setValue(localStorage.getItem("smde_"+this.options.autosave.uniqueId)),this.options.autosave.foundSavedValue=!0),this.options.autosave.loaded=!0);var f=o.value();f!==""?localStorage.setItem("smde_"+this.options.autosave.uniqueId,f):localStorage.removeItem("smde_"+this.options.autosave.uniqueId);var c=document.getElementById("autosaved");if(c!=null&&c!=null&&c!=""){var l=new Date,s=new Intl.DateTimeFormat([this.options.autosave.timeFormat.locale,"en-US"],this.options.autosave.timeFormat.format).format(l),g=this.options.autosave.text==null?"Autosaved: ":this.options.autosave.text;c.innerHTML=g+s}}else console.log("EasyMDE: localStorage not available, cannot autosave")};J.prototype.clearAutosavedValue=function(){if(Fu()){if(this.options.autosave==null||this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("EasyMDE: You must set a uniqueId to clear the autosave value");return}localStorage.removeItem("smde_"+this.options.autosave.uniqueId)}else console.log("EasyMDE: localStorage not available, cannot autosave")};J.prototype.openBrowseFileWindow=function(o,f){var c=this,l=this.gui.toolbar.getElementsByClassName("imageInput")[0];l.click();function s(g){c.options.imageUploadFunction?c.uploadImagesUsingCustomFunction(c.options.imageUploadFunction,g.target.files):c.uploadImages(g.target.files,o,f),l.removeEventListener("change",s)}l.addEventListener("change",s)};J.prototype.uploadImage=function(o,f,c){var l=this;f=f||function(w){Cu(l,w)};function s(y){l.updateStatusBar("upload-image",y),setTimeout(function(){l.updateStatusBar("upload-image",l.options.imageTexts.sbInit)},1e4),c&&typeof c=="function"&&c(y),l.options.errorCallback(y)}function g(y){var w=l.options.imageTexts.sizeUnits.split(",");return y.replace("#image_name#",o.name).replace("#image_size#",gn(o.size,w)).replace("#image_max_size#",gn(l.options.imageMaxSize,w))}if(o.size>this.options.imageMaxSize){s(g(this.options.errorMessages.fileTooLarge));return}var d=new FormData;d.append("image",o),l.options.imageCSRFToken&&!l.options.imageCSRFHeader&&d.append(l.options.imageCSRFName,l.options.imageCSRFToken);var p=new XMLHttpRequest;p.upload.onprogress=function(y){if(y.lengthComputable){var w=""+Math.round(y.loaded*100/y.total);l.updateStatusBar("upload-image",l.options.imageTexts.sbProgress.replace("#file_name#",o.name).replace("#progress#",w))}},p.open("POST",this.options.imageUploadEndpoint),l.options.imageCSRFToken&&l.options.imageCSRFHeader&&p.setRequestHeader(l.options.imageCSRFName,l.options.imageCSRFToken),p.onload=function(){try{var y=JSON.parse(this.responseText)}catch{console.error("EasyMDE: The server did not return a valid json."),s(g(l.options.errorMessages.importError));return}this.status===200&&y&&!y.error&&y.data&&y.data.filePath?f((l.options.imagePathAbsolute?"":window.location.origin+"/")+y.data.filePath):y.error&&y.error in l.options.errorMessages?s(g(l.options.errorMessages[y.error])):y.error?s(g(y.error)):(console.error("EasyMDE: Received an unexpected response after uploading the image."+this.status+" ("+this.statusText+")"),s(g(l.options.errorMessages.importError)))},p.onerror=function(y){console.error("EasyMDE: An unexpected error occurred when trying to upload the image."+y.target.status+" ("+y.target.statusText+")"),s(l.options.errorMessages.importError)},p.send(d)};J.prototype.uploadImageUsingCustomFunction=function(o,f){var c=this;function l(d){Cu(c,d)}function s(d){var p=g(d);c.updateStatusBar("upload-image",p),setTimeout(function(){c.updateStatusBar("upload-image",c.options.imageTexts.sbInit)},1e4),c.options.errorCallback(p)}function g(d){var p=c.options.imageTexts.sizeUnits.split(",");return d.replace("#image_name#",f.name).replace("#image_size#",gn(f.size,p)).replace("#image_max_size#",gn(c.options.imageMaxSize,p))}o.apply(this,[f,l,s])};J.prototype.setPreviewMaxHeight=function(){var o=this.codemirror,f=o.getWrapperElement(),c=f.nextSibling,l=parseInt(window.getComputedStyle(f).paddingTop),s=parseInt(window.getComputedStyle(f).borderTopWidth),g=parseInt(this.options.maxHeight),d=g+l*2+s*2,p=d.toString()+"px";c.style.height=p};J.prototype.createSideBySide=function(){var o=this.codemirror,f=o.getWrapperElement(),c=f.nextSibling;if(!c||!c.classList.contains("editor-preview-side")){if(c=document.createElement("div"),c.className="editor-preview-side",this.options.previewClass)if(Array.isArray(this.options.previewClass))for(var l=0;l0||S>0&&F0?"Converting "+f+" photo"+(f>1?"s":"")+"\u2026":"Uploading "+S+" photo"+(S>1?"s":"")+"\u2026",c.details.open=!0):S>0?(c.summary.textContent="\u2713 "+S+" photo"+(S>1?"s":"")+" ready \u2014 tap to review",c.details.open=!1):(c.summary.textContent="Photos (1\u20136)",c.details.open=!0)}}function d(){g(),setTimeout(g,150),setTimeout(g,500)}function p(){var D=o.querySelector('button[type="submit"], input[type="submit"]');if(D&&(D.disabled=f>0),f>0)s("Converting "+f+" photo"+(f>1?"s":"")+"\u2026");else{var S=Lu();S&&/Converting/.test(S.textContent)&&s("")}g()}o.addEventListener("submit",function(D){f>0&&(D.preventDefault(),s("Hang on \u2014 a photo is still converting.","err"))},!0);function y(D){return function(S){var F=S&&S.file;return F?Wd(F).then(function(T){return T?(f++,p(),import("./heic-to-CN7JBE7H.js").then(function(z){var N=z.heicTo||z.default&&z.default.heicTo;return N({blob:F,type:"image/jpeg",quality:.85})}).then(function(z){var N=new File([z],qd(F.name),{type:"image/jpeg"});D.addFile(N)}).catch(function(){s("A photo couldn\u2019t be converted and was skipped \u2014 the others are fine.","err")}).then(function(){f--,p()}),!1):!0}):!0}}var w=0;(function D(){var S=window.GravFilePond&&window.GravFilePond.getInstances?window.GravFilePond.getInstances():[];if(!S.length){w++<120&&setTimeout(D,50);return}S.forEach(function(F){F&&!F._heicHooked&&(F._heicHooked=!0,F.setOptions({beforeAddFile:y(F),allowReorder:!0,itemInsertLocation:"after"}),l=F,["addfile","processfile","processfiles","removefile","error"].forEach(function(T){try{F.on(T,d)}catch{}}),g())})})()}function vt(o){return document.querySelector('[name="data['+o+']"]')}function Gd(){var o=Array.prototype.slice.call(document.querySelectorAll(".advanced-field"));if(o.length){var f=[];if(o.forEach(function(g){var d=g.closest(".form-field");d&&f.indexOf(d)===-1&&f.push(d)}),!!f.length){var c=document.createElement("details");c.className="more-options";var l=document.createElement("summary");l.className="more-options__summary",l.textContent="More options",c.appendChild(l),f[0].parentNode.insertBefore(c,f[0]),f.forEach(function(g){c.appendChild(g)});var s=f.some(function(g){var d=g.querySelector('input[type="text"]');if(d&&d.value.trim())return!0;var p=g.querySelector('input[type="radio"]:checked');return!!(p&&p.value&&p.value!=="0")});s&&(c.open=!0)}}}var Kd={0:"Sunny",1:"Partly cloudy",2:"Partly cloudy",3:"Cloudy",45:"Foggy",48:"Foggy",51:"Drizzle",53:"Drizzle",55:"Drizzle",56:"Drizzle",57:"Drizzle",61:"Rain",63:"Rain",65:"Rain",66:"Rain",67:"Rain",80:"Rain",81:"Rain",82:"Rain",71:"Snow",73:"Snow",75:"Snow",77:"Snow",85:"Snow",86:"Snow",95:"Thunderstorm",96:"Thunderstorm",99:"Thunderstorm"};function _t(o,f,c){o&&(o.className="form-status"+(c?" form-status--"+c:""),o.textContent=f||"")}function Xd(){var o=document.getElementById("get-location"),f=document.getElementById("get-weather");if(!o&&!f)return;var c=document.getElementById("location-status"),l=document.getElementById("weather-status");function s(){var p=vt("lat"),y=vt("lng"),w=p?p.value.trim():"",D=y?y.value.trim():"";return w&&D?{lat:w,lng:D}:null}function g(){if(f){var p=!!s();f.disabled=!p,f.title=p?"":"Get location first"}}g();function d(p,y){var w=vt("location_city"),D=vt("location_country");if(!((!w||w.value.trim())&&(!D||D.value.trim()))){var S="https://api.bigdatacloud.net/data/reverse-geocode-client?latitude="+encodeURIComponent(p)+"&longitude="+encodeURIComponent(y)+"&localityLanguage=en";fetch(S).then(function(F){return F.json()}).then(function(F){var T=(F.city||F.locality||"").trim(),z=(F.countryName||"").trim();w&&!w.value.trim()&&T&&(w.value=T),D&&!D.value.trim()&&z&&(D.value=z);var N=[T,z].filter(Boolean).join(", ");N&&_t(c,"\u2713 Location captured \xB7 "+N,"ok")}).catch(function(){})}}o&&o.addEventListener("click",function(){if(!navigator.geolocation){_t(c,"Geolocation is not supported on this device.","err");return}o.classList.add("is-loading"),o.disabled=!0,_t(c,"Getting location\u2026"),navigator.geolocation.getCurrentPosition(function(p){var y=p.coords.latitude.toFixed(6),w=p.coords.longitude.toFixed(6),D=vt("lat"),S=vt("lng");D&&(D.value=y),S&&(S.value=w),o.classList.remove("is-loading"),o.disabled=!1,_t(c,"\u2713 Location captured \xB7 "+y+", "+w,"ok"),g(),d(y,w)},function(p){o.classList.remove("is-loading"),o.disabled=!1,_t(c,"\u2717 "+(p&&p.message?p.message:"Could not get location")+" \u2014 enter coordinates manually if needed.","err")},{enableHighAccuracy:!0,timeout:15e3})}),f&&f.addEventListener("click",function(){var p=s();if(!p){_t(l,"Get location first, then fetch weather.","err");return}f.classList.add("is-loading"),f.disabled=!0,_t(l,"Fetching weather\u2026");var y="https://api.open-meteo.com/v1/forecast?latitude="+p.lat+"&longitude="+p.lng+"¤t=temperature_2m,weather_code&temperature_unit=celsius";fetch(y).then(function(w){return w.json()}).then(function(w){var D=Math.round(w.current.temperature_2m),S=Kd[w.current.weather_code]||"Cloudy",F=vt("weather_temp_c"),T=vt("weather_desc");F&&(F.value=D),T&&(T.value=S),f.classList.remove("is-loading"),g(),_t(l,"\u2713 Weather set \xB7 "+S+" \xB7 "+D+"\xB0C (edit above if needed)","ok")}).catch(function(){f.classList.remove("is-loading"),g(),_t(l,"\u2717 Could not fetch weather \u2014 set it manually above.","err")})})}function Yd(){var o=new Date;return o.setSeconds(0,0),o.setMinutes(o.getMinutes()-o.getTimezoneOffset()),o.toISOString().slice(0,16)}function Zd(){var o={title:"Title",date:"Date & time",content:"Content"},f=document.querySelector('form[name="new-entry"]');if(!f)return;var c=vt("date");c&&!String(c.value).trim()&&(c.value=Yd());function l(){f.querySelectorAll(".field-error").forEach(function(d){d.remove()}),f.querySelectorAll(".field-invalid").forEach(function(d){d.classList.remove("field-invalid")})}function s(d,p){d.classList.add("field-invalid");var y=document.createElement("span");y.className="field-error",y.textContent=p,d.parentNode.insertBefore(y,d.nextSibling)}function g(d){var p=f.querySelector(".photos-collapse"),y,w;if(p?(p.open=!0,w=p.querySelector(".photos-collapse__summary"),y=p):(y=document.querySelector(".filepond-root, .form-input-file"),w=y),!w)return y||null;var D=document.createElement("span");return D.className="field-error",D.textContent=d,w.insertAdjacentElement("afterend",D),y||w}f.addEventListener("submit",function(d){l();var p=null;!ha&&document.querySelectorAll(".filepond--item").length<1&&(p=g("Add at least one photo.")),Object.keys(o).forEach(function(y){var w=vt(y);w&&!String(w.value).trim()&&(s(w,o[y]+" is required."),p||(p=w))}),p&&(d.preventDefault(),typeof p.focus=="function"&&p.focus(),p.scrollIntoView({behavior:"smooth",block:"center"}))})}var fa="intotheeast:new-entry-draft";function Qd(o){return Array.prototype.slice.call(o.querySelectorAll('[name^="data["]')).filter(function(f){if(f.type==="file")return!1;var c=f.name;return c.indexOf("data[_json")!==0&&c.indexOf("data[photos")!==0})}function Jd(){var o=document.querySelector(".filepond-root, .form-input-file");if(!(!o||!o.parentNode)&&!o.parentNode.querySelector(".photo-reauth-hint")){var f=document.createElement("p");f.className="photo-reauth-hint is-shown",f.textContent="Your text was restored \u2014 photos need re-selecting (they can\u2019t be saved in a draft).",o.parentNode.insertBefore(f,o.nextSibling)}}function $d(){var o=document.querySelector('form[name="new-entry"]');if(!o||ha)return;if(document.querySelector(".notices.success")){try{localStorage.removeItem(fa)}catch{}return}function f(){var g={};Qd(o).forEach(function(d){d.type==="radio"?d.checked&&(g[d.name]=d.value):g[d.name]=d.value});try{localStorage.setItem(fa,JSON.stringify(g))}catch{}}var c=null;try{c=localStorage.getItem(fa)}catch{c=null}if(c){var l=null;try{l=JSON.parse(c)}catch{l=null}if(l){var s=!1;Object.keys(l).forEach(function(g){var d=l[g];if(d!=null&&String(d).trim()&&(s=!0),g!=="data[content]"){var p=o.querySelectorAll('input[type="radio"][name="'+g+'"]');if(p.length){p.forEach(function(w){w.checked=w.value===d});return}var y=o.querySelector('[name="'+g+'"]');y&&y.type!=="file"&&(y.value=d)}}),window.postFormEditor&&l["data[content]"]!=null&&window.postFormEditor.value(l["data[content]"]),s&&Jd()}}o.addEventListener("input",f),o.addEventListener("change",f),window.postFormEditor&&window.postFormEditor.codemirror.on("change",f)}function Vd(){var o=document.querySelector(".post-form-wrap"),f=document.querySelector(".post-form-wrap .notices.success, .post-form-wrap .notices.green");if(!(!o||!f)){var c=document.createElement("div");c.className="post-success";var l=document.createElement("p");l.className="post-success__title",l.textContent="\u2713 Saved to your journal.",c.appendChild(l);var s=document.createElement("div");s.className="post-success__actions";var g=o.getAttribute("data-trip-url");if(g){var d=document.createElement("a");d.className="post-success__view",d.href=g,d.textContent="View your journal \u2192",s.appendChild(d)}var p=document.createElement("a");p.className="post-success__again",p.href=window.location.pathname,p.textContent="Post another",s.appendChild(p),c.appendChild(s),f.parentNode.insertBefore(c,f.nextSibling),["form",".form-action-row","#location-status","#weather-status"].forEach(function(y){var w=o.querySelector(y);w&&(w.style.display="none")}),f.scrollIntoView({behavior:"smooth",block:"start"})}}var ha=!1;function Tu(o){return new URLSearchParams(window.location.search).get(o)}function Wt(o,f){var c=vt(o);c&&(c.value=f==null?"":String(f))}function ca(o,f){var c=f?"1":"0",l=document.querySelectorAll('[name="data['+o+']"]');Array.prototype.forEach.call(l,function(s){s.checked=String(s.value)===c})}function eh(o){var f=o==null?"":String(o);if(window.postFormEditor&&typeof window.postFormEditor.value=="function")window.postFormEditor.value(f);else{var c=vt("content");c&&(c.value=f)}}function Mu(o,f){var c=o.querySelectorAll("input, textarea, select, button");Array.prototype.forEach.call(c,function(l){l.type==="file"||l.name&&l.name.indexOf("data[photos")===0||(l.disabled=f)}),window.postFormEditor&&window.postFormEditor.codemirror&&window.postFormEditor.codemirror.setOption("readOnly",f?"nocursor":!1)}function da(o,f){o&&(o.tagName==="INPUT"?o.value=f:o.textContent=f)}function th(o,f){var c=o.querySelector(".post-edit-error");if(c){c.textContent=f;return}var l=document.createElement("div");l.className="post-edit-error",l.setAttribute("role","alert"),l.textContent=f;var s=o.querySelector("h1");s?s.insertAdjacentElement("afterend",l):o.insertBefore(l,o.firstChild)}function Nu(o,f){f=f||0;var c=window.GravFilePond&&window.GravFilePond.getInstances?window.GravFilePond.getInstances():[];if(c.length&&c[0]){o(c[0]);return}f<120&&setTimeout(function(){Nu(o,f+1)},50)}function rh(o){fetch("/api/v1/pages"+o+"/media",{credentials:"include",headers:{Accept:"application/json"}}).then(function(f){return f.ok?f.json():{data:[]}}).then(function(f){var c=f&&f.data||[],l=c.filter(function(s){return s&&typeof s.filename=="string"&&/\.(jpe?g|png|gif|webp|heic|heif)$/i.test(s.filename)}).sort(function(s,g){return s.filenameg.filename?1:0});Nu(function(s){try{s.setOptions({allowBrowse:!1,allowDrop:!1,allowReorder:!0})}catch{}l.forEach(function(g){try{var d=s.addFile(o+"/"+g.filename,{type:"local"});d&&typeof d.catch=="function"&&d.catch(function(){})}catch{}})})}).catch(function(){})}function ih(){var o=document.querySelector('form[name="new-entry"]'),f=document.querySelector(".post-form-wrap");if(!(!o||!f)){var c=Tu("edit");if(c){ha=!0;var l=f.querySelector("h1");l&&(l.textContent="Edit entry");var s=o.querySelector('button[type="submit"], input[type="submit"]'),g=s?s.tagName==="INPUT"?s.value:s.textContent:"Save changes";Mu(o,!0),da(s,"Loading entry\u2026");var d=Tu("return")||f.getAttribute("data-trip-url")||"";o.setAttribute("action","/post?edit="+encodeURIComponent(c)+(d?"&return="+encodeURIComponent(d):"")),fetch("/api/v1/pages"+c,{credentials:"include",headers:{Accept:"application/json"}}).then(function(p){if(!p.ok)throw new Error("HTTP "+p.status);return p.json()}).then(function(p){var y=p&&p.data||{},w=y.header||{};Wt("title",w.title!=null?w.title:y.title),Wt("date",w.date?String(w.date).replace(" ","T"):""),eh(y.content),Wt("lat",w.lat),Wt("lng",w.lng),Wt("location_city",w.location_city),Wt("location_country",w.location_country),Wt("weather_desc",w.weather_desc),Wt("weather_temp_c",w.weather_temp_c),Wt("transport_mode",w.transport_mode),ca("featured",w.featured),ca("force_connect",w.force_connect),ca("published",w.published!==void 0?w.published:y.published);var D=vt("edit_path");D&&(D.value=c+"/entry.md"),Mu(o,!1),da(s,"Save changes");var S=o.querySelector(".more-options");S&&(S.open=!0),rh(c)}).catch(function(){th(f,"Sorry \u2014 this entry could not be loaded for editing. Go back to the journal and try again."),da(s,g)})}}}function Bu(){window.postFormEditor=Pd(),Vd(),ih(),$d(),jd(),Gd(),Xd(),Zd()}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Bu):Bu(); +Maximum file size is #image_max_size#.`,importError:"Something went wrong when uploading the image #image_name#."};function J(o){o=o||{},o.parent=this;var f=!0;if(o.autoDownloadFontAwesome===!1&&(f=!1),o.autoDownloadFontAwesome!==!0)for(var c=document.styleSheets,l=0;l-1&&(f=!1);if(f){var s=document.createElement("link");s.rel="stylesheet",s.href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css",document.getElementsByTagName("head")[0].appendChild(s)}if(o.element)this.element=o.element;else if(o.element===null){console.log("EasyMDE: Error. No element was found.");return}if(o.toolbar===void 0){o.toolbar=[];for(var g in pr)Object.prototype.hasOwnProperty.call(pr,g)&&(g.indexOf("separator-")!=-1&&o.toolbar.push("|"),(pr[g].default===!0||o.showIcons&&o.showIcons.constructor===Array&&o.showIcons.indexOf(g)!=-1)&&o.toolbar.push(g))}if(Object.prototype.hasOwnProperty.call(o,"previewClass")||(o.previewClass="editor-preview"),Object.prototype.hasOwnProperty.call(o,"status")||(o.status=["autosave","lines","words","cursor"],o.uploadImage&&o.status.unshift("upload-image")),o.previewRender||(o.previewRender=function(p){return this.parent.markdown(p)}),o.parsingConfig=Pt({highlightFormatting:!0},o.parsingConfig||{}),o.insertTexts=Pt({},Nd,o.insertTexts||{}),o.promptTexts=Pt({},Id,o.promptTexts||{}),o.blockStyles=Pt({},Od,o.blockStyles||{}),o.autosave!=null&&(o.autosave.timeFormat=Pt({},zd,o.autosave.timeFormat||{})),o.iconClassMap=Pt({},ke,o.iconClassMap||{}),o.shortcuts=Pt({},Sd,o.shortcuts||{}),o.maxHeight=o.maxHeight||void 0,o.direction=o.direction||"ltr",typeof o.maxHeight<"u"?o.minHeight=o.maxHeight:o.minHeight=o.minHeight||"300px",o.errorCallback=o.errorCallback||function(p){alert(p)},o.uploadImage=o.uploadImage||!1,o.imageMaxSize=o.imageMaxSize||2097152,o.imageAccept=o.imageAccept||"image/png, image/jpeg, image/gif, image/avif",o.imageTexts=Pt({},Hd,o.imageTexts||{}),o.errorMessages=Pt({},Rd,o.errorMessages||{}),o.imagePathAbsolute=o.imagePathAbsolute||!1,o.imageCSRFName=o.imageCSRFName||"csrfmiddlewaretoken",o.imageCSRFHeader=o.imageCSRFHeader||!1,o.imageInputName=o.imageInputName||"image",o.autosave!=null&&o.autosave.unique_id!=null&&o.autosave.unique_id!=""&&(o.autosave.uniqueId=o.autosave.unique_id),o.overlayMode&&o.overlayMode.combine===void 0&&(o.overlayMode.combine=!0),this.options=o,this.render(),o.initialValue&&(!this.options.autosave||this.options.autosave.foundSavedValue!==!0)&&this.value(o.initialValue),o.uploadImage){var d=this;this.codemirror.on("dragenter",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbOnDragEnter),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragend",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbInit),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragleave",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbInit),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("dragover",function(p,y){d.updateStatusBar("upload-image",d.options.imageTexts.sbOnDragEnter),y.stopPropagation(),y.preventDefault()}),this.codemirror.on("drop",function(p,y){y.stopPropagation(),y.preventDefault(),o.imageUploadFunction?d.uploadImagesUsingCustomFunction(o.imageUploadFunction,y.dataTransfer.files):d.uploadImages(y.dataTransfer.files)}),this.codemirror.on("paste",function(p,y){o.imageUploadFunction?d.uploadImagesUsingCustomFunction(o.imageUploadFunction,y.clipboardData.files):d.uploadImages(y.clipboardData.files)})}}J.prototype.uploadImages=function(o,f,c){if(o.length!==0){for(var l=[],s=0;s=2){var R=I[1];if(f.imagesPreviewHandler){var H=f.imagesPreviewHandler(I[1]);typeof H=="string"&&(R=H)}if(window.EMDEimagesCache[R])T(B,window.EMDEimagesCache[R]);else{window.EMDEimagesCache[R]={};var _=document.createElement("img");_.onload=function(){window.EMDEimagesCache[R]={naturalWidth:_.naturalWidth,naturalHeight:_.naturalHeight,url:R},T(B,window.EMDEimagesCache[R])},_.src=R}}}})}this.codemirror.on("update",function(){z()}),this.gui.sideBySide=this.createSideBySide(),this._rendered=this.element,(f.autofocus===!0||o.autofocus)&&this.codemirror.focus();var N=this.codemirror;setTimeout(function(){N.refresh()}.bind(N),0)};J.prototype.cleanup=function(){document.removeEventListener("keydown",this.documentOnKeyDown)};function Fu(){if(typeof localStorage=="object")try{localStorage.setItem("smde_localStorage",1),localStorage.removeItem("smde_localStorage")}catch{return!1}else return!1;return!0}J.prototype.autosave=function(){if(Fu()){var o=this;if(this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("EasyMDE: You must set a uniqueId to use the autosave feature");return}this.options.autosave.binded!==!0&&(o.element.form!=null&&o.element.form!=null&&o.element.form.addEventListener("submit",function(){clearTimeout(o.autosaveTimeoutId),o.autosaveTimeoutId=void 0,localStorage.removeItem("smde_"+o.options.autosave.uniqueId)}),this.options.autosave.binded=!0),this.options.autosave.loaded!==!0&&(typeof localStorage.getItem("smde_"+this.options.autosave.uniqueId)=="string"&&localStorage.getItem("smde_"+this.options.autosave.uniqueId)!=""&&(this.codemirror.setValue(localStorage.getItem("smde_"+this.options.autosave.uniqueId)),this.options.autosave.foundSavedValue=!0),this.options.autosave.loaded=!0);var f=o.value();f!==""?localStorage.setItem("smde_"+this.options.autosave.uniqueId,f):localStorage.removeItem("smde_"+this.options.autosave.uniqueId);var c=document.getElementById("autosaved");if(c!=null&&c!=null&&c!=""){var l=new Date,s=new Intl.DateTimeFormat([this.options.autosave.timeFormat.locale,"en-US"],this.options.autosave.timeFormat.format).format(l),g=this.options.autosave.text==null?"Autosaved: ":this.options.autosave.text;c.innerHTML=g+s}}else console.log("EasyMDE: localStorage not available, cannot autosave")};J.prototype.clearAutosavedValue=function(){if(Fu()){if(this.options.autosave==null||this.options.autosave.uniqueId==null||this.options.autosave.uniqueId==""){console.log("EasyMDE: You must set a uniqueId to clear the autosave value");return}localStorage.removeItem("smde_"+this.options.autosave.uniqueId)}else console.log("EasyMDE: localStorage not available, cannot autosave")};J.prototype.openBrowseFileWindow=function(o,f){var c=this,l=this.gui.toolbar.getElementsByClassName("imageInput")[0];l.click();function s(g){c.options.imageUploadFunction?c.uploadImagesUsingCustomFunction(c.options.imageUploadFunction,g.target.files):c.uploadImages(g.target.files,o,f),l.removeEventListener("change",s)}l.addEventListener("change",s)};J.prototype.uploadImage=function(o,f,c){var l=this;f=f||function(w){Cu(l,w)};function s(y){l.updateStatusBar("upload-image",y),setTimeout(function(){l.updateStatusBar("upload-image",l.options.imageTexts.sbInit)},1e4),c&&typeof c=="function"&&c(y),l.options.errorCallback(y)}function g(y){var w=l.options.imageTexts.sizeUnits.split(",");return y.replace("#image_name#",o.name).replace("#image_size#",gn(o.size,w)).replace("#image_max_size#",gn(l.options.imageMaxSize,w))}if(o.size>this.options.imageMaxSize){s(g(this.options.errorMessages.fileTooLarge));return}var d=new FormData;d.append("image",o),l.options.imageCSRFToken&&!l.options.imageCSRFHeader&&d.append(l.options.imageCSRFName,l.options.imageCSRFToken);var p=new XMLHttpRequest;p.upload.onprogress=function(y){if(y.lengthComputable){var w=""+Math.round(y.loaded*100/y.total);l.updateStatusBar("upload-image",l.options.imageTexts.sbProgress.replace("#file_name#",o.name).replace("#progress#",w))}},p.open("POST",this.options.imageUploadEndpoint),l.options.imageCSRFToken&&l.options.imageCSRFHeader&&p.setRequestHeader(l.options.imageCSRFName,l.options.imageCSRFToken),p.onload=function(){try{var y=JSON.parse(this.responseText)}catch{console.error("EasyMDE: The server did not return a valid json."),s(g(l.options.errorMessages.importError));return}this.status===200&&y&&!y.error&&y.data&&y.data.filePath?f((l.options.imagePathAbsolute?"":window.location.origin+"/")+y.data.filePath):y.error&&y.error in l.options.errorMessages?s(g(l.options.errorMessages[y.error])):y.error?s(g(y.error)):(console.error("EasyMDE: Received an unexpected response after uploading the image."+this.status+" ("+this.statusText+")"),s(g(l.options.errorMessages.importError)))},p.onerror=function(y){console.error("EasyMDE: An unexpected error occurred when trying to upload the image."+y.target.status+" ("+y.target.statusText+")"),s(l.options.errorMessages.importError)},p.send(d)};J.prototype.uploadImageUsingCustomFunction=function(o,f){var c=this;function l(d){Cu(c,d)}function s(d){var p=g(d);c.updateStatusBar("upload-image",p),setTimeout(function(){c.updateStatusBar("upload-image",c.options.imageTexts.sbInit)},1e4),c.options.errorCallback(p)}function g(d){var p=c.options.imageTexts.sizeUnits.split(",");return d.replace("#image_name#",f.name).replace("#image_size#",gn(f.size,p)).replace("#image_max_size#",gn(c.options.imageMaxSize,p))}o.apply(this,[f,l,s])};J.prototype.setPreviewMaxHeight=function(){var o=this.codemirror,f=o.getWrapperElement(),c=f.nextSibling,l=parseInt(window.getComputedStyle(f).paddingTop),s=parseInt(window.getComputedStyle(f).borderTopWidth),g=parseInt(this.options.maxHeight),d=g+l*2+s*2,p=d.toString()+"px";c.style.height=p};J.prototype.createSideBySide=function(){var o=this.codemirror,f=o.getWrapperElement(),c=f.nextSibling;if(!c||!c.classList.contains("editor-preview-side")){if(c=document.createElement("div"),c.className="editor-preview-side",this.options.previewClass)if(Array.isArray(this.options.previewClass))for(var l=0;l0||S>0&&F0?"Converting "+f+" photo"+(f>1?"s":"")+"\u2026":"Uploading "+S+" photo"+(S>1?"s":"")+"\u2026",c.details.open=!0):S>0?(c.summary.textContent="\u2713 "+S+" photo"+(S>1?"s":"")+" ready \u2014 tap to review",c.details.open=!1):(c.summary.textContent="Photos (1\u20136)",c.details.open=!0)}}function d(){g(),setTimeout(g,150),setTimeout(g,500)}function p(){var D=o.querySelector('button[type="submit"], input[type="submit"]');if(D&&(D.disabled=f>0),f>0)s("Converting "+f+" photo"+(f>1?"s":"")+"\u2026");else{var S=Lu();S&&/Converting/.test(S.textContent)&&s("")}g()}o.addEventListener("submit",function(D){f>0&&(D.preventDefault(),s("Hang on \u2014 a photo is still converting.","err"))},!0);function y(D){return function(S){var F=S&&S.file;return F?Wd(F).then(function(T){return T?(f++,p(),import("./heic-to-CN7JBE7H.js").then(function(z){var N=z.heicTo||z.default&&z.default.heicTo;return N({blob:F,type:"image/jpeg",quality:.85})}).then(function(z){var N=new File([z],qd(F.name),{type:"image/jpeg"});D.addFile(N)}).catch(function(){s("A photo couldn\u2019t be converted and was skipped \u2014 the others are fine.","err")}).then(function(){f--,p()}),!1):!0}):!0}}var w=0;(function D(){var S=window.GravFilePond&&window.GravFilePond.getInstances?window.GravFilePond.getInstances():[];if(!S.length){w++<120&&setTimeout(D,50);return}S.forEach(function(F){F&&!F._heicHooked&&(F._heicHooked=!0,F.setOptions({beforeAddFile:y(F),allowReorder:!0,itemInsertLocation:"after"}),l=F,["addfile","processfile","processfiles","removefile","error"].forEach(function(T){try{F.on(T,d)}catch{}}),g())})})()}function vt(o){return document.querySelector('[name="data['+o+']"]')}function Gd(){var o=Array.prototype.slice.call(document.querySelectorAll(".advanced-field"));if(o.length){var f=[];if(o.forEach(function(g){var d=g.closest(".form-field");d&&f.indexOf(d)===-1&&f.push(d)}),!!f.length){var c=document.createElement("details");c.className="more-options";var l=document.createElement("summary");l.className="more-options__summary",l.textContent="More options",c.appendChild(l),f[0].parentNode.insertBefore(c,f[0]),f.forEach(function(g){c.appendChild(g)});var s=f.some(function(g){var d=g.querySelector('input[type="text"]');if(d&&d.value.trim())return!0;var p=g.querySelector('input[type="radio"]:checked');return!!(p&&p.value&&p.value!=="0")});s&&(c.open=!0)}}}var Kd={0:"Sunny",1:"Partly cloudy",2:"Partly cloudy",3:"Cloudy",45:"Foggy",48:"Foggy",51:"Drizzle",53:"Drizzle",55:"Drizzle",56:"Drizzle",57:"Drizzle",61:"Rain",63:"Rain",65:"Rain",66:"Rain",67:"Rain",80:"Rain",81:"Rain",82:"Rain",71:"Snow",73:"Snow",75:"Snow",77:"Snow",85:"Snow",86:"Snow",95:"Thunderstorm",96:"Thunderstorm",99:"Thunderstorm"};function _t(o,f,c){o&&(o.className="form-status"+(c?" form-status--"+c:""),o.textContent=f||"")}function Xd(){var o=document.getElementById("get-location"),f=document.getElementById("get-weather");if(!o&&!f)return;var c=document.getElementById("location-status"),l=document.getElementById("weather-status");function s(){var p=vt("lat"),y=vt("lng"),w=p?p.value.trim():"",D=y?y.value.trim():"";return w&&D?{lat:w,lng:D}:null}function g(){if(f){var p=!!s();f.disabled=!p,f.title=p?"":"Get location first"}}g();function d(p,y){var w=vt("location_city"),D=vt("location_country");if(!((!w||w.value.trim())&&(!D||D.value.trim()))){var S="https://api.bigdatacloud.net/data/reverse-geocode-client?latitude="+encodeURIComponent(p)+"&longitude="+encodeURIComponent(y)+"&localityLanguage=en";fetch(S).then(function(F){return F.json()}).then(function(F){var T=(F.city||F.locality||"").trim(),z=(F.countryName||"").trim();w&&!w.value.trim()&&T&&(w.value=T),D&&!D.value.trim()&&z&&(D.value=z);var N=[T,z].filter(Boolean).join(", ");N&&_t(c,"\u2713 Location captured \xB7 "+N,"ok")}).catch(function(){})}}o&&o.addEventListener("click",function(){if(!navigator.geolocation){_t(c,"Geolocation is not supported on this device.","err");return}o.classList.add("is-loading"),o.disabled=!0,_t(c,"Getting location\u2026"),navigator.geolocation.getCurrentPosition(function(p){var y=p.coords.latitude.toFixed(6),w=p.coords.longitude.toFixed(6),D=vt("lat"),S=vt("lng");D&&(D.value=y),S&&(S.value=w),o.classList.remove("is-loading"),o.disabled=!1,_t(c,"\u2713 Location captured \xB7 "+y+", "+w,"ok"),g(),d(y,w)},function(p){o.classList.remove("is-loading"),o.disabled=!1,_t(c,"\u2717 "+(p&&p.message?p.message:"Could not get location")+" \u2014 enter coordinates manually if needed.","err")},{enableHighAccuracy:!0,timeout:15e3})}),f&&f.addEventListener("click",function(){var p=s();if(!p){_t(l,"Get location first, then fetch weather.","err");return}f.classList.add("is-loading"),f.disabled=!0,_t(l,"Fetching weather\u2026");var y="https://api.open-meteo.com/v1/forecast?latitude="+p.lat+"&longitude="+p.lng+"¤t=temperature_2m,weather_code&temperature_unit=celsius";fetch(y).then(function(w){return w.json()}).then(function(w){var D=Math.round(w.current.temperature_2m),S=Kd[w.current.weather_code]||"Cloudy",F=vt("weather_temp_c"),T=vt("weather_desc");F&&(F.value=D),T&&(T.value=S),f.classList.remove("is-loading"),g(),_t(l,"\u2713 Weather set \xB7 "+S+" \xB7 "+D+"\xB0C (edit above if needed)","ok")}).catch(function(){f.classList.remove("is-loading"),g(),_t(l,"\u2717 Could not fetch weather \u2014 set it manually above.","err")})})}function Yd(){var o=new Date;return o.setSeconds(0,0),o.setMinutes(o.getMinutes()-o.getTimezoneOffset()),o.toISOString().slice(0,16)}function Zd(){var o={title:"Title",date:"Date & time",content:"Content"},f=document.querySelector('form[name="new-entry"]');if(!f)return;var c=vt("date");c&&!String(c.value).trim()&&(c.value=Yd());function l(){f.querySelectorAll(".field-error").forEach(function(d){d.remove()}),f.querySelectorAll(".field-invalid").forEach(function(d){d.classList.remove("field-invalid")})}function s(d,p){d.classList.add("field-invalid");var y=document.createElement("span");y.className="field-error",y.textContent=p,d.parentNode.insertBefore(y,d.nextSibling)}function g(d){var p=f.querySelector(".photos-collapse"),y,w;if(p?(p.open=!0,w=p.querySelector(".photos-collapse__summary"),y=p):(y=document.querySelector(".filepond-root, .form-input-file"),w=y),!w)return y||null;var D=document.createElement("span");return D.className="field-error",D.textContent=d,w.insertAdjacentElement("afterend",D),y||w}f.addEventListener("submit",function(d){l();var p=null;!ha&&document.querySelectorAll(".filepond--item").length<1&&(p=g("Add at least one photo.")),Object.keys(o).forEach(function(y){var w=vt(y);w&&!String(w.value).trim()&&(s(w,o[y]+" is required."),p||(p=w))}),p&&(d.preventDefault(),typeof p.focus=="function"&&p.focus(),p.scrollIntoView({behavior:"smooth",block:"center"}))})}var fa="intotheeast:new-entry-draft";function Qd(o){return Array.prototype.slice.call(o.querySelectorAll('[name^="data["]')).filter(function(f){if(f.type==="file")return!1;var c=f.name;return c.indexOf("data[_json")!==0&&c.indexOf("data[photos")!==0})}function Jd(){var o=document.querySelector(".filepond-root, .form-input-file");if(!(!o||!o.parentNode)&&!o.parentNode.querySelector(".photo-reauth-hint")){var f=document.createElement("p");f.className="photo-reauth-hint is-shown",f.textContent="Your text was restored \u2014 photos need re-selecting (they can\u2019t be saved in a draft).",o.parentNode.insertBefore(f,o.nextSibling)}}function $d(){var o=document.querySelector('form[name="new-entry"]');if(!o||ha)return;if(document.querySelector(".notices.success")){try{localStorage.removeItem(fa)}catch{}return}function f(){var g={};Qd(o).forEach(function(d){d.type==="radio"?d.checked&&(g[d.name]=d.value):g[d.name]=d.value});try{localStorage.setItem(fa,JSON.stringify(g))}catch{}}var c=null;try{c=localStorage.getItem(fa)}catch{c=null}if(c){var l=null;try{l=JSON.parse(c)}catch{l=null}if(l){var s=!1;Object.keys(l).forEach(function(g){var d=l[g];if(d!=null&&String(d).trim()&&(s=!0),g!=="data[content]"){var p=o.querySelectorAll('input[type="radio"][name="'+g+'"]');if(p.length){p.forEach(function(w){w.checked=w.value===d});return}var y=o.querySelector('[name="'+g+'"]');y&&y.type!=="file"&&(y.value=d)}}),window.postFormEditor&&l["data[content]"]!=null&&window.postFormEditor.value(l["data[content]"]),s&&Jd()}}o.addEventListener("input",f),o.addEventListener("change",f),window.postFormEditor&&window.postFormEditor.codemirror.on("change",f)}function Vd(){var o=document.querySelector(".post-form-wrap"),f=document.querySelector(".post-form-wrap .notices.success, .post-form-wrap .notices.green");if(!(!o||!f)){var c=document.createElement("div");c.className="post-success";var l=document.createElement("p");l.className="post-success__title",l.textContent="\u2713 Saved to your journal.",c.appendChild(l);var s=document.createElement("div");s.className="post-success__actions";var g=o.getAttribute("data-trip-url");if(g){var d=document.createElement("a");d.className="post-success__view",d.href=g,d.textContent="View your journal \u2192",s.appendChild(d)}var p=document.createElement("a");p.className="post-success__again",p.href=window.location.pathname,p.textContent="Post another",s.appendChild(p),c.appendChild(s),f.parentNode.insertBefore(c,f.nextSibling),["form",".form-action-row","#location-status","#weather-status"].forEach(function(y){var w=o.querySelector(y);w&&(w.style.display="none")}),f.scrollIntoView({behavior:"smooth",block:"start"})}}var ha=!1;function Tu(o){return new URLSearchParams(window.location.search).get(o)}function Wt(o,f){var c=vt(o);c&&(c.value=f==null?"":String(f))}function ca(o,f){var c=f?"1":"0",l=document.querySelectorAll('[name="data['+o+']"]');Array.prototype.forEach.call(l,function(s){s.checked=String(s.value)===c})}function eh(o){var f=o==null?"":String(o);if(window.postFormEditor&&typeof window.postFormEditor.value=="function")window.postFormEditor.value(f);else{var c=vt("content");c&&(c.value=f)}}function Mu(o,f){var c=o.querySelectorAll("input, textarea, select, button");Array.prototype.forEach.call(c,function(l){l.type==="file"||l.name&&l.name.indexOf("data[photos")===0||(l.disabled=f)}),window.postFormEditor&&window.postFormEditor.codemirror&&window.postFormEditor.codemirror.setOption("readOnly",f?"nocursor":!1)}function da(o,f){o&&(o.tagName==="INPUT"?o.value=f:o.textContent=f)}function th(o,f){var c=o.querySelector(".post-edit-error");if(c){c.textContent=f;return}var l=document.createElement("div");l.className="post-edit-error",l.setAttribute("role","alert"),l.textContent=f;var s=o.querySelector("h1");s?s.insertAdjacentElement("afterend",l):o.insertBefore(l,o.firstChild)}function Nu(o,f){f=f||0;var c=window.GravFilePond&&window.GravFilePond.getInstances?window.GravFilePond.getInstances():[];if(c.length&&c[0]){o(c[0]);return}f<120&&setTimeout(function(){Nu(o,f+1)},50)}function rh(o){fetch("/api/v1/pages"+o+"/media",{credentials:"include",headers:{Accept:"application/json"}}).then(function(f){return f.ok?f.json():{data:[]}}).then(function(f){var c=f&&f.data||[],l=c.filter(function(s){return s&&typeof s.filename=="string"&&/\.(jpe?g|png|gif|webp|heic|heif)$/i.test(s.filename)}).sort(function(s,g){return s.filenameg.filename?1:0});Nu(function(s){try{s.setOptions({allowBrowse:!0,allowDrop:!0,allowReorder:!0})}catch{}l.forEach(function(g){try{var d=s.addFile(o+"/"+g.filename,{type:"local"});d&&typeof d.catch=="function"&&d.catch(function(){})}catch{}})})}).catch(function(){})}function ih(){var o=document.querySelector('form[name="new-entry"]'),f=document.querySelector(".post-form-wrap");if(!(!o||!f)){var c=Tu("edit");if(c){ha=!0;var l=f.querySelector("h1");l&&(l.textContent="Edit entry");var s=o.querySelector('button[type="submit"], input[type="submit"]'),g=s?s.tagName==="INPUT"?s.value:s.textContent:"Save changes";Mu(o,!0),da(s,"Loading entry\u2026");var d=Tu("return")||f.getAttribute("data-trip-url")||"";o.setAttribute("action","/post?edit="+encodeURIComponent(c)+(d?"&return="+encodeURIComponent(d):"")),fetch("/api/v1/pages"+c,{credentials:"include",headers:{Accept:"application/json"}}).then(function(p){if(!p.ok)throw new Error("HTTP "+p.status);return p.json()}).then(function(p){var y=p&&p.data||{},w=y.header||{};Wt("title",w.title!=null?w.title:y.title),Wt("date",w.date?String(w.date).replace(" ","T"):""),eh(y.content),Wt("lat",w.lat),Wt("lng",w.lng),Wt("location_city",w.location_city),Wt("location_country",w.location_country),Wt("weather_desc",w.weather_desc),Wt("weather_temp_c",w.weather_temp_c),Wt("transport_mode",w.transport_mode),ca("featured",w.featured),ca("force_connect",w.force_connect),ca("published",w.published!==void 0?w.published:y.published);var D=vt("edit_path");D&&(D.value=c+"/entry.md"),Mu(o,!1),da(s,"Save changes");var S=o.querySelector(".more-options");S&&(S.open=!0),rh(c)}).catch(function(){th(f,"Sorry \u2014 this entry could not be loaded for editing. Go back to the journal and try again."),da(s,g)})}}}function Bu(){window.postFormEditor=Pd(),Vd(),ih(),$d(),jd(),Gd(),Xd(),Zd()}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",Bu):Bu(); diff --git a/themes/intotheeast/js/src/post-form.js b/themes/intotheeast/js/src/post-form.js index 38a5ebc..caa0db7 100644 --- a/themes/intotheeast/js/src/post-form.js +++ b/themes/intotheeast/js/src/post-form.js @@ -778,19 +778,17 @@ function editWaitForPond(cb, tries) { if (tries < 120) setTimeout(function () { editWaitForPond(cb, tries + 1); }, 50); } -// U7: load the entry's current photos into FilePond as LOCAL items. Local files -// already live on the server, so FilePond shows them for reorder/removal but does -// NOT re-upload them on save. Their filenames sort to folder order (first = cover) -// and ride the `photo_order` manifest on submit; cache-on-save reconciles the -// folder to match (U8). A broken media URL is skipped, never aborting the rest. +// U7/R9: load the entry's current photos into FilePond as LOCAL items (already on +// the server — shown for reorder/removal, never re-uploaded). Adding new photos on +// edit is enabled (allowBrowse/allowDrop): on submit, existing filenames + any new +// uploads ride the `photo_order` manifest and cache-on-save reconciles the folder +// (delete dropped, renumber survivors photo-1..N, first = cover). A broken media +// URL is skipped, never aborting the rest. // -// Adding NEW photos on edit (R9) is intentionally suppressed here (allowBrowse / -// allowDrop off) — a new upload on the edit save goes through add-page-by-form's -// edit-mode file merge, which fatals on Grav 2.0 (`(array)$page->header()` yields -// mangled protected-property keys, so `$original_frontmatter['photos']` is never -// set → array_merge(null,…) TypeError). That's a stock, GPM-managed plugin we -// must not fork, so add-photo-on-edit is deferred to the form-to-page/image-upload -// rework. Remove + reorder (which never upload) work and are what M2 ships. +// Add-on-edit depends on a local patch to add-page-by-form (stock GPM plugin's +// edit-mode file merge fatals on Grav 2.0's Header object — see the patch note in +// add-page-by-form.php). That patch is git-ignored, so it must be re-applied on a +// fresh plugin install until upstream is forked. function editLoadPhotos(route) { fetch('/api/v1/pages' + route + '/media', { credentials: 'include', headers: { Accept: 'application/json' } }) .then(function (r) { return r.ok ? r.json() : { data: [] }; }) @@ -802,8 +800,7 @@ function editLoadPhotos(route) { return a.filename < b.filename ? -1 : (a.filename > b.filename ? 1 : 0); }); editWaitForPond(function (pond) { - // Keep remove + reorder; drop the add affordance (see note above). - try { pond.setOptions({ allowBrowse: false, allowDrop: false, allowReorder: true }); } catch (e) { /* older API */ } + try { pond.setOptions({ allowBrowse: true, allowDrop: true, allowReorder: true }); } catch (e) { /* older API */ } images.forEach(function (m) { try { var p = pond.addFile(route + '/' + m.filename, { type: 'local' });