diff --git a/static/editor.js b/static/editor.js new file mode 100644 index 0000000..1ae08cb --- /dev/null +++ b/static/editor.js @@ -0,0 +1,14 @@ +(function () { + let changed = false; + let textarea = document.querySelector('.edit-form__textarea'); + + let warnBeforeClosing = function (ev) { + ev.preventDefault(); + return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.'; + }; + + textarea.addEventListener('input', function () { + if (!changed) window.addEventListener('beforeunload', warnBeforeClosing); + changed = true; + }); +})(); diff --git a/views/mutators.qtpl b/views/mutators.qtpl index bd59829..c70906b 100644 --- a/views/mutators.qtpl +++ b/views/mutators.qtpl @@ -118,6 +118,7 @@ {% endfunc %} {% func editScripts() %} + {% for _, scriptPath := range cfg.EditScripts %} {% endfor %} diff --git a/views/mutators.qtpl.go b/views/mutators.qtpl.go index c7da710..ae39d0d 100644 --- a/views/mutators.qtpl.go +++ b/views/mutators.qtpl.go @@ -359,47 +359,48 @@ func PreviewHTML(rq *http.Request, hyphaName, textAreaFill, message, warning str func streameditScripts(qw422016 *qt422016.Writer) { //line views/mutators.qtpl:120 qw422016.N().S(` + `) -//line views/mutators.qtpl:121 +//line views/mutators.qtpl:122 for _, scriptPath := range cfg.EditScripts { -//line views/mutators.qtpl:121 +//line views/mutators.qtpl:122 qw422016.N().S(` `) -//line views/mutators.qtpl:123 +//line views/mutators.qtpl:124 } -//line views/mutators.qtpl:123 +//line views/mutators.qtpl:124 qw422016.N().S(` `) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 } -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 func writeeditScripts(qq422016 qtio422016.Writer) { -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 qw422016 := qt422016.AcquireWriter(qq422016) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 streameditScripts(qw422016) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 qt422016.ReleaseWriter(qw422016) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 } -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 func editScripts() string { -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 qb422016 := qt422016.AcquireByteBuffer() -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 writeeditScripts(qb422016) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 qs422016 := string(qb422016.B) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 qt422016.ReleaseByteBuffer(qb422016) -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 return qs422016 -//line views/mutators.qtpl:124 +//line views/mutators.qtpl:125 }