diff --git a/js/appcommon.js b/js/appcommon.js index 321439a..81229d3 100644 --- a/js/appcommon.js +++ b/js/appcommon.js @@ -90,60 +90,64 @@ $.ready(function () { e.preventDefault() }) - do { - let msgAt, box - // populate the form errors box from GET arg ?err=... - // (a way to pass errors back from server via redirect) - msgAt = window.location.search.indexOf('err=') - if (msgAt !== -1 && qs('.Box.errors')) { - let errs = decodeURIComponent(window.location.search.substr(msgAt + 4)).split(',') - let humanReadableErrors = [] - errs.forEach(function (er) { - let lbls = qsa('label[for="' + er + '"]') - if (lbls) { - for (let i = 0; i < lbls.length; i++) { - let lbl = lbls[i] - lbl.classList.add('error') - if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')) + try { + do { + let msgAt, box + // populate the form errors box from GET arg ?err=... + // (a way to pass errors back from server via redirect) + msgAt = window.location.search.indexOf('err=') + if (msgAt !== -1 && qs('.Box.errors')) { + let errs = decodeURIComponent(window.location.search.substr(msgAt + 4)).split(',') + let humanReadableErrors = [] + errs.forEach(function (er) { + let lbls = qsa('label[for="' + er + '"]') + if (lbls) { + for (let i = 0; i < lbls.length; i++) { + let lbl = lbls[i] + lbl.classList.add('error') + if (i === 0) humanReadableErrors.push(lbl.childNodes[0].textContent.trim().replace(/: ?$/, '')) + } + } else { + humanReadableErrors.push(er) } - } else { - humanReadableErrors.push(er) - } - }) - - qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ') - qs('.Box.errors').classList.remove('hidden') - break - } + }) + + qs('.Box.errors .list').innerHTML = humanReadableErrors.join(', ') + qs('.Box.errors').classList.remove('hidden') + break + } - let fademsgbox = function (box, time) { - box.classList.remove('hidden') - setTimeout(() => { - box.classList.add('hiding') + let fademsgbox = function (box, time) { + box.classList.remove('hidden') setTimeout(() => { - box.classList.add('hidden') - }, 1000) - }, time) - } + box.classList.add('hiding') + setTimeout(() => { + box.classList.add('hidden') + }, 1000) + }, time) + } - msgAt = window.location.search.indexOf('errmsg=') - box = qs('.Box.errmessage') - if (msgAt !== -1 && box) { - let msg = decodeURIComponent(window.location.search.substr(msgAt + 7)) - box.innerHTML = msg - fademsgbox(box, 3000) - break - } + msgAt = window.location.search.indexOf('errmsg=') + box = qs('.Box.errmessage') + if (msgAt !== -1 && box) { + let msg = decodeURIComponent(window.location.search.substr(msgAt + 7)) + box.innerHTML = msg + fademsgbox(box, 3000) + break + } - msgAt = window.location.search.indexOf('msg=') - box = qs('.Box.message') - if (msgAt !== -1 && box) { - let msg = decodeURIComponent(window.location.search.substr(msgAt + 4)) - box.innerHTML = msg - fademsgbox(box, 2000) - break - } - } while (0) + msgAt = window.location.search.indexOf('msg=') + box = qs('.Box.message') + if (msgAt !== -1 && box) { + let msg = decodeURIComponent(window.location.search.substr(msgAt + 4)) + box.innerHTML = msg + fademsgbox(box, 2000) + break + } + } while (0) + } catch (e) { + console.error(e) + } modal.init() notify.init()