diff options
Diffstat (limited to 'interface/js')
-rw-r--r-- | interface/js/app/config.js | 4 | ||||
-rw-r--r-- | interface/js/lib/codejar-linenumbers.min.js | 6 | ||||
-rw-r--r-- | interface/js/lib/codejar.min.js | 4 | ||||
-rw-r--r-- | interface/js/lib/linenumbers.min.js | 5 | ||||
-rw-r--r-- | interface/js/main.js | 2 |
5 files changed, 12 insertions, 9 deletions
diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 8d979f1f2..b3f4e5661 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -181,7 +181,6 @@ define(["jquery", "codejar", "linenumbers", "prism"], mode = (new Blob([data[0].data]).size > 5120) ? "basic" : $("input[name=editorMode]:checked").val(); $("<" + editor[mode].elt + ' id="editor" class="' + editor[mode].class + '" data-id="' + item.map + '">' + - rspamd.escapeHTML(data[0].data) + "</" + editor[mode].elt + ">").appendTo("#modalBody"); if (editor[mode].codejar) { @@ -189,6 +188,9 @@ define(["jquery", "codejar", "linenumbers", "prism"], document.querySelector("#editor"), withLineNumbers((el) => Prism.highlightElement(el)) ); + jar.updateCode(data[0].data); + } else { + document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data); } var icon = "fa-edit"; diff --git a/interface/js/lib/codejar-linenumbers.min.js b/interface/js/lib/codejar-linenumbers.min.js new file mode 100644 index 000000000..e3ca168ce --- /dev/null +++ b/interface/js/lib/codejar-linenumbers.min.js @@ -0,0 +1,6 @@ +/*! + * codejar-linenumbers v1.0.0 (https://github.com/julianpoemp/codejar-linenumbers) + * Copyright (c) 2023, Julian Poemp, MIT + */ +function withLineNumbers(r,e={}){const d={class:"codejar-linenumbers",wrapClass:"codejar-wrap",width:"35px",backgroundColor:"rgba(128, 128, 128, 0.15)",color:"",...e};let l;return function(e){r(e),l||(l=init(e,d),e.addEventListener("scroll",()=>l.style.top=`-${e.scrollTop}px`));var t=(e.textContent||"").replace(/\n\n$/g,"\n").split("\n").length;let o="";for(let e=0;e<t;e++)o+=e+1+` +`;l.innerText=o}}function init(e,t){var o=getComputedStyle(e),r=document.createElement("div"),d=(r.className=t.wrapClass,r.style.position="relative",document.createElement("div")),l=(d.className="codejar-linenumbers-inner-wrap",d.style.background=o.background,d.style.marginTop=o.borderTopWidth,d.style.marginBottom=o.borderBottomWidth,d.style.marginLeft=o.borderLeftWidth,d.style.borderTopLeftRadius=o.borderTopLeftRadius,d.style.borderBottomLeftRadius=o.borderBottomLeftRadius,document.createElement("div")),d=(l.className=t.class,d.appendChild(l),r.appendChild(d),l.style.width=t.width,l.style.overflow="hidden",l.style.backgroundColor=t.backgroundColor,l.style.fontFamily=o.fontFamily,l.style.fontSize=o.fontSize,l.style.lineHeight=o.lineHeight,l.style.paddingTop=`calc(${o.paddingTop})`,l.style.paddingLeft=o.paddingLeft,l.style.borderTopLeftRadius=o.borderTopLeftRadius,l.style.borderBottomLeftRadius=o.borderBottomLeftRadius,document.createElement("div"));return d.setAttribute("class","codejar-linenumber"),d.style.color=t.color||o.color,d.style.setProperty("mix-blend-mode","unset"),l.appendChild(d),e.style.paddingLeft=`calc(${t.width} + ${l.style.paddingLeft} + 5px)`,e.style.whiteSpace="pre",e.parentNode.insertBefore(r,e),r.appendChild(e),d}
\ No newline at end of file diff --git a/interface/js/lib/codejar.min.js b/interface/js/lib/codejar.min.js index d2b860deb..6326ea3fe 100644 --- a/interface/js/lib/codejar.min.js +++ b/interface/js/lib/codejar.min.js @@ -1,5 +1,5 @@ /*! - * CodeJar 3.7.0 (https://github.com/antonmedv/codejar) + * CodeJar 4.2.0 (https://github.com/antonmedv/codejar) * Copyright (c) 2020, Anton Medvedev, MIT */ -const globalWindow=window;function CodeJar(u,n,e={}){const f=Object.assign({tab:"\t",indentOn:/[({\[]$/,moveToNewLine:/^[)}\]]/,spellcheck:!1,catchTab:!0,preserveIdent:!0,addClosing:!0,history:!0,window:globalWindow},e),o=f.window,p=o.document;let r=[],h=[],g=-1,i=!1,s,y,v=(u.setAttribute("contenteditable","plaintext-only"),u.setAttribute("spellcheck",f.spellcheck?"true":"false"),u.style.outline="none",u.style.overflowWrap="break-word",u.style.overflowY="auto",!(u.style.whiteSpace="pre-wrap"));n(u),(v="plaintext-only"!==u.contentEditable?!0:v)&&u.setAttribute("contenteditable","true");const t=d(()=>{var e=T();n(u,e),b(e)},30);let C=!1;const N=e=>!O(e)&&!M(e)&&"Meta"!==e.key&&"Control"!==e.key&&"Alt"!==e.key&&!e.key.startsWith("Arrow"),a=d(e=>{N(e)&&(w(),C=!1)},300);e=(e,t)=>{r.push([e,t]),u.addEventListener(e,t)};function T(){var e=H();const t={start:0,end:0,dir:void 0};let{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:i}=e;if(n&&o)return n===u&&o===u?(t.start=0<r&&u.textContent?u.textContent.length:0,t.end=0<i&&u.textContent?u.textContent.length:0,t.dir=i>=r?"->":"<-"):(n.nodeType===Node.ELEMENT_NODE&&(e=p.createTextNode(""),n.insertBefore(e,n.childNodes[r]),n=e,r=0),o.nodeType===Node.ELEMENT_NODE&&(e=p.createTextNode(""),o.insertBefore(e,o.childNodes[i]),o=e,i=0),l(u,e=>{if(e===n&&e===o)return t.start+=r,t.end+=i,t.dir=r<=i?"->":"<-","stop";if(e===n){if(t.start+=r,t.dir)return"stop";t.dir="->"}else if(e===o){if(t.end+=i,t.dir)return"stop";t.dir="<-"}e.nodeType===Node.TEXT_NODE&&("->"!=t.dir&&(t.start+=e.nodeValue.length),"<-"!=t.dir)&&(t.end+=e.nodeValue.length)}),u.normalize()),t;throw"error1"}function b(n){var e,t,r=H();let o,i=0,s,a=0,d=(n.dir||(n.dir="->"),n.start<0&&(n.start=0),n.end<0&&(n.end=0),"<-"==n.dir&&({start:e,end:t}=n,n.start=t,n.end=e),0);l(u,e=>{var t;if(e.nodeType===Node.TEXT_NODE)return t=(e.nodeValue||"").length,d+t>n.start&&(o||(o=e,i=n.start-d),d+t>n.end)?(s=e,a=n.end-d,"stop"):void(d+=t)}),o||(o=u,i=u.childNodes.length),s||(s=u,a=u.childNodes.length),"<-"==n.dir&&([o,i,s,a]=[s,a,o,i]),r.setBaseAndExtent(o,i,s,a)}function E(){var e=H().getRangeAt(0),t=p.createRange();return t.selectNodeContents(u),t.setEnd(e.startContainer,e.startOffset),t.toString()}function m(){var e=H().getRangeAt(0),t=p.createRange();return t.selectNodeContents(u),t.setStart(e.endContainer,e.endOffset),t.toString()}function k(e){v&&"Enter"===e.key&&(_(e),e.stopPropagation(),""==m()?(S("\n "),(e=T()).start=--e.end,b(e)):S("\n"))}function w(){var e,t,n;i&&(e=u.innerHTML,t=T(),(n=h[g])&&n.html===e&&n.pos.start===t.start&&n.pos.end===t.end||(g++,h[g]={html:e,pos:t},h.splice(g+1),300<g&&(g=300,h.splice(0,1))))}function l(e,t){var n=[];e.firstChild&&n.push(e.firstChild);let r=n.pop();for(;r&&"stop"!==t(r);)r.nextSibling&&n.push(r.nextSibling),r.firstChild&&n.push(r.firstChild),r=n.pop()}function x(e){return e.metaKey||e.ctrlKey}function O(e){return x(e)&&!e.shiftKey&&"Z"===L(e)}function M(e){return x(e)&&e.shiftKey&&"Z"===L(e)}function L(e){e=e.key||e.keyCode||e.which;if(e)return("string"==typeof e?e:String.fromCharCode(e)).toUpperCase()}function S(e){e=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),p.execCommand("insertHTML",!1,e)}function d(t,n){let r=0;return(...e)=>{clearTimeout(r),r=o.setTimeout(()=>t(...e),n)}}function A(e){let t=e.length-1;for(;0<=t&&"\n"!==e[t];)t--;let n=++t;for(;n<e.length&&/[ \t]/.test(e[n]);)n++;return[e.substring(t,n)||"",t,n]}function D(){return u.textContent||""}function _(e){e.preventDefault()}function H(){var e;return((null==(e=u.parentNode)?void 0:e.nodeType)==Node.DOCUMENT_FRAGMENT_NODE?u.parentNode:o).getSelection()}return e("keydown",e=>{if(!e.defaultPrevented){if(y=D(),f.preserveIdent){var t=e;if("Enter"===t.key){var n=E(),r=m(),[o]=A(n);let e=o;f.indentOn.test(n)&&(e+=f.tab),0<e.length?(_(t),t.stopPropagation(),S("\n"+e)):k(t),e!==o&&f.moveToNewLine.test(r)&&(n=T(),S("\n"+o),b(n))}}else k(e);if(f.catchTab){t=e;"Tab"===t.key&&(_(t),t.shiftKey?([t,r]=A(E()),0<t.length&&(o=T(),t=Math.min(f.tab.length,t.length),b({start:r,end:r+t}),p.execCommand("delete"),o.start-=t,o.end-=t,b(o))):S(f.tab))}if(f.addClosing){var i,n=e,s=`([{'"`,a=`)]}'"`,d=m(),l="\\"===(l=E()).substr(l.length-1),d=d.substr(0,1);a.includes(n.key)&&!l&&d===n.key?(i=T(),_(n),i.start=++i.end,b(i)):s.includes(n.key)&&!l&&(`"'`.includes(n.key)||[""," ","\n"].includes(d))&&(_(n),i=T(),l=i.start==i.end?"":H().toString(),S(n.key+l+a[s.indexOf(n.key)]),i.start++,i.end++,b(i))}var c;f.history&&(O(d=e)&&(_(d),g--,(c=h[g])&&(u.innerHTML=c.html,b(c.pos)),g<0)&&(g=0),M(d)&&(_(d),g++,(c=h[g])&&(u.innerHTML=c.html,b(c.pos)),g>=h.length)&&g--,N(e))&&!C&&(w(),C=!0),v&&(!x(l=e)||"C"!==L(l))&&b(T())}}),e("keyup",e=>{e.defaultPrevented||e.isComposing||(y!==D()&&t(),a(e),s&&s(D()))}),e("focus",e=>{i=!0}),e("blur",e=>{i=!1}),e("paste",e=>{var t;w(),_(e=e),e=(e.originalEvent||e).clipboardData.getData("text/plain").replace(/\r/g,""),t=T(),S(e),n(u),b({start:Math.min(t.start,t.end)+e.length,end:Math.min(t.start,t.end)+e.length,dir:"<-"}),w(),s&&s(D())}),{updateOptions(e){Object.assign(f,e)},updateCode(e){u.textContent=e,n(u)},onUpdate(e){s=e},toString:D,save:T,restore:b,recordHistory:w,destroy(){for(var[e,t]of r)u.removeEventListener(e,t)}}}
\ No newline at end of file +const globalWindow=window;function CodeJar(l,n,e={}){const c={tab:"\t",indentOn:/[({\[]$/,moveToNewLine:/^[)}\]]/,spellcheck:!1,catchTab:!0,preserveIdent:!0,addClosing:!0,history:!0,window:globalWindow,...e},o=c.window,f=o.document,r=[],u=[];let p=-1,a=!1,i=()=>{},h;l.setAttribute("contenteditable","plaintext-only"),l.setAttribute("spellcheck",c.spellcheck?"true":"false"),l.style.outline="none",l.style.overflowWrap="break-word",l.style.overflowY="auto",l.style.whiteSpace="pre-wrap";const d=(e,t)=>{n(e,t)};let g=!1;(g="plaintext-only"!==l.contentEditable?!0:g)&&l.setAttribute("contenteditable","true");const t=S(()=>{var e=v();d(l,e),T(e)},30);let y=!1;const N=e=>!O(e)&&!M(e)&&"Meta"!==e.key&&"Control"!==e.key&&"Alt"!==e.key&&!e.key.startsWith("Arrow"),s=S(e=>{N(e)&&(x(),y=!1)},300);e=(e,t)=>{r.push([e,t]),l.addEventListener(e,t)};function v(){var e=H();const t={start:0,end:0,dir:void 0};let{anchorNode:n,anchorOffset:r,focusNode:o,focusOffset:a}=e;if(n&&o)return n===l&&o===l?(t.start=0<r&&l.textContent?l.textContent.length:0,t.end=0<a&&l.textContent?l.textContent.length:0,t.dir=a>=r?"->":"<-"):(n.nodeType===Node.ELEMENT_NODE&&(e=f.createTextNode(""),n.insertBefore(e,n.childNodes[r]),n=e,r=0),o.nodeType===Node.ELEMENT_NODE&&(e=f.createTextNode(""),o.insertBefore(e,o.childNodes[a]),o=e,a=0),w(l,e=>{if(e===n&&e===o)return t.start+=r,t.end+=a,t.dir=r<=a?"->":"<-","stop";if(e===n){if(t.start+=r,t.dir)return"stop";t.dir="->"}else if(e===o){if(t.end+=a,t.dir)return"stop";t.dir="<-"}e.nodeType===Node.TEXT_NODE&&("->"!=t.dir&&(t.start+=e.nodeValue.length),"<-"!=t.dir)&&(t.end+=e.nodeValue.length)}),l.normalize()),t;throw"error1"}function T(n){var e=H();let r,o=0,a,i=0,d=(n.dir||(n.dir="->"),n.start<0&&(n.start=0),n.end<0&&(n.end=0),"<-"==n.dir&&({start:t,end:s}=n,n.start=s,n.end=t),0);w(l,e=>{var t;if(e.nodeType===Node.TEXT_NODE)return t=(e.nodeValue||"").length,d+t>n.start&&(r||(r=e,o=n.start-d),d+t>n.end)?(a=e,i=n.end-d,"stop"):void(d+=t)}),r||(r=l,o=l.childNodes.length),a||(a=l,i=l.childNodes.length),"<-"==n.dir&&([r,o,a,i]=[a,i,r,o]);var t,s=C(r),s=(s&&(t=f.createTextNode(""),s.parentNode?.insertBefore(t,s),r=t,o=0),C(a));s&&(t=f.createTextNode(""),s.parentNode?.insertBefore(t,s),a=t,i=0),e.setBaseAndExtent(r,o,a,i),l.normalize()}function C(e){for(;e&&e!==l;){if(e.nodeType===Node.ELEMENT_NODE){var t=e;if("false"==t.getAttribute("contenteditable"))return t}e=e.parentNode}}function E(){var e=H().getRangeAt(0),t=f.createRange();return t.selectNodeContents(l),t.setEnd(e.startContainer,e.startOffset),t.toString()}function m(){var e=H().getRangeAt(0),t=f.createRange();return t.selectNodeContents(l),t.setStart(e.endContainer,e.endOffset),t.toString()}function b(e){g&&"Enter"===e.key&&(B(e),e.stopPropagation(),""==m()?(L("\n "),(e=v()).start=--e.end,T(e)):L("\n"))}function x(){var e,t,n;a&&(e=l.innerHTML,t=v(),(n=u[p])&&n.html===e&&n.pos.start===t.start&&n.pos.end===t.end||(p++,u[p]={html:e,pos:t},u.splice(p+1),300<p&&(p=300,u.splice(0,1))))}function w(e,t){var n=[];e.firstChild&&n.push(e.firstChild);let r=n.pop();for(;r&&"stop"!==t(r);)r.nextSibling&&n.push(r.nextSibling),r.firstChild&&n.push(r.firstChild),r=n.pop()}function k(e){return e.metaKey||e.ctrlKey}function O(e){return k(e)&&!e.shiftKey&&"Z"===D(e)}function M(e){return k(e)&&e.shiftKey&&"Z"===D(e)}function D(e){e=e.key||e.keyCode||e.which;if(e)return("string"==typeof e?e:String.fromCharCode(e)).toUpperCase()}function L(e){e=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),f.execCommand("insertHTML",!1,e)}function S(t,n){let r=0;return(...e)=>{clearTimeout(r),r=o.setTimeout(()=>t(...e),n)}}function A(e){let t=e.length-1;for(;0<=t&&"\n"!==e[t];)t--;let n=++t;for(;n<e.length&&/[ \t]/.test(e[n]);)n++;return[e.substring(t,n)||"",t,n]}function _(){return l.textContent||""}function B(e){e.preventDefault()}function H(){return(l.parentNode?.nodeType==Node.DOCUMENT_FRAGMENT_NODE?l.parentNode:o).getSelection()}return e("keydown",e=>{if(!e.defaultPrevented){if(h=_(),c.preserveIdent){var t=e;if("Enter"===t.key){var n=E(),r=m(),[o]=A(n);let e=o;c.indentOn.test(n)&&(e+=c.tab),0<e.length?(B(t),t.stopPropagation(),L("\n"+e)):b(t),e!==o&&c.moveToNewLine.test(r)&&(n=v(),L("\n"+o),T(n))}}else b(e);if(c.catchTab){t=e;"Tab"===t.key&&(B(t),t.shiftKey?([t,r]=A(E()),0<t.length&&(o=v(),t=Math.min(c.tab.length,t.length),T({start:r,end:r+t}),f.execCommand("delete"),o.start-=t,o.end-=t,T(o))):L(c.tab))}if(c.addClosing){var a,n=e,i=`([{'"`;i.includes(n.key)&&(B(n),a=v(),d=a.start==a.end?"":H().toString(),L(n.key+d+`)]}'"`[i.indexOf(n.key)]),a.start++,a.end++,T(a))}var d,s;c.history&&(O(d=e)&&(B(d),p--,(s=u[p])&&(l.innerHTML=s.html,T(s.pos)),p<0)&&(p=0),M(d)&&(B(d),p++,(s=u[p])&&(l.innerHTML=s.html,T(s.pos)),p>=u.length)&&p--,N(e))&&!y&&(x(),y=!0),g&&(!k(i=e)||"C"!==D(i))&&T(v())}}),e("keyup",e=>{e.defaultPrevented||e.isComposing||(h!==_()&&t(),s(e),i(_()))}),e("focus",e=>{a=!0}),e("blur",e=>{a=!1}),e("paste",e=>{var t;x(),(e=e).defaultPrevented||(B(e),e=(e.originalEvent??e).clipboardData.getData("text/plain").replace(/\r\n?/g,"\n"),t=v(),L(e),d(l),T({start:Math.min(t.start,t.end)+e.length,end:Math.min(t.start,t.end)+e.length,dir:"<-"})),x(),i(_())}),e("cut",e=>{var t,n;x(),e=e,t=v(),n=H(),(e.originalEvent??e).clipboardData.setData("text/plain",n.toString()),f.execCommand("delete"),d(l),T({start:Math.min(t.start,t.end),end:Math.min(t.start,t.end),dir:"<-"}),B(e),x(),i(_())}),{updateOptions(e){Object.assign(c,e)},updateCode(e){l.textContent=e,d(l),i(e)},onUpdate(e){i=e},toString:_,save:v,restore:T,recordHistory:x,destroy(){for(var[e,t]of r)l.removeEventListener(e,t)}}}
\ No newline at end of file diff --git a/interface/js/lib/linenumbers.min.js b/interface/js/lib/linenumbers.min.js deleted file mode 100644 index 0dd83d0d0..000000000 --- a/interface/js/lib/linenumbers.min.js +++ /dev/null @@ -1,5 +0,0 @@ -/*! - * CodeJar 3.2.2 helper: lineNumbers (https://github.com/antonmedv/codejar) - * Copyright (c) 2020, Anton Medvedev, MIT - */ -function withLineNumbers(e,t={}){const o=Object.assign({class:"codejar-linenumbers",wrapClass:"codejar-wrap",width:"35px",backgroundColor:"rgba(128, 128, 128, 0.15)",color:""},t);let l;return function(t){e(t),l||(l=init(t,o),t.addEventListener("scroll",()=>l.style.top=`-${t.scrollTop}px`));const n=(t.textContent||"").replace(/\n+$/,"\n").split("\n").length+1;let s="";for(let e=1;e<n;e++)s+=`${e}\n`;l.innerText=s}}function init(e,t){const o=getComputedStyle(e),l=document.createElement("div");l.className=t.wrapClass,l.style.position="relative";const n=document.createElement("div");n.className=t.class,l.appendChild(n),n.style.position="absolute",n.style.top="0px",n.style.left="0px",n.style.bottom="0px",n.style.width=t.width,n.style.overflow="hidden",n.style.backgroundColor=t.backgroundColor,n.style.color=t.color||o.color,n.style.setProperty("mix-blend-mode","difference"),n.style.fontFamily=o.fontFamily,n.style.fontSize=o.fontSize,n.style.lineHeight=o.lineHeight,n.style.paddingTop=o.paddingTop,n.style.paddingLeft=o.paddingLeft,n.style.borderTopLeftRadius=o.borderTopLeftRadius,n.style.borderBottomLeftRadius=o.borderBottomLeftRadius;const s=document.createElement("div");return s.style.position="relative",s.style.top="0px",n.appendChild(s),e.style.paddingLeft=`calc(${t.width} + ${n.style.paddingLeft})`,e.style.whiteSpace="pre",e.parentNode.insertBefore(l,e),l.appendChild(e),s}
\ No newline at end of file diff --git a/interface/js/main.js b/interface/js/main.js index d0e904f37..4182bb2bc 100644 --- a/interface/js/main.js +++ b/interface/js/main.js @@ -14,7 +14,7 @@ requirejs.config({ fontawesome: "fontawesome.min", fontawesome_solid: "solid.min", footable: "footable.min", - linenumbers: "linenumbers.min", + linenumbers: "codejar-linenumbers.min", nprogress: "nprogress.min", prism: "prism", stickytabs: "jquery.stickytabs.min" |