Owen Leonard
08900d5653
system preferences This patch adds CodeMirror plugins for linting JS, CSS, HTML, and YAML. When invalid data is entered in a linted CodeMirror editor an icon is displayed in the editor's "gutter." Hovering over the icon displays the error message. This patch renames the minified CodeMirror JS file to match convention but the version is unchanged. To test, apply the patch and go to Administration -> System preferences. Test preferences of each type and confirm that each type of CodeMirror editor shows an error indicator if you entry invalid data. Valid data should trigger no error indicator. - HTML: e.g. OpacMainUserBlock, opacheader. Enter invalid HTML, for example "<h1>Hello <h2>World</h2>." Example valid HTML: "<h1>Hello world</h1>" - JavaScript: e.g. OpacUserJS, IntranetUserJS. Example bad JS, "alert("Success!');" Example valid JS: "alert("Success!");" - CSS: e.g. IntranetUserCSS, SCOUserCSS. Example bad CSS, "p { color blue }" Example valid CSS, "p { color: blue; }" - YAML: e.g. OpacHiddenItems. Example bad YAML: "one: two, three: four" Example valid YAML: "one: two three: four" Also test that other CodeMirror instances still work correctly without linting: The advanced MARC editor, SQL reports editing. Signed-off-by: David Nind <david@davidnind.com> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
1 line
No EOL
4.1 KiB
JavaScript
1 line
No EOL
4.1 KiB
JavaScript
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],t):t(CodeMirror)}(function(s){"use strict";var p="CodeMirror-lint-markers";function a(t){t.parentNode&&t.parentNode.removeChild(t)}function c(t,e,n){var o=function(t,e){var n=document.createElement("div");function o(t){if(!n.parentNode)return s.off(document,"mousemove",o);n.style.top=Math.max(0,t.clientY-n.offsetHeight-5)+"px",n.style.left=t.clientX+5+"px"}return n.className="CodeMirror-lint-tooltip",n.appendChild(e.cloneNode(!0)),document.body.appendChild(n),s.on(document,"mousemove",o),o(t),null!=n.style.opacity&&(n.style.opacity=1),n}(t,e);function r(){s.off(n,"mouseout",r),o&&(function(t){t.parentNode&&(null==t.style.opacity&&a(t),t.style.opacity=0,setTimeout(function(){a(t)},600))}(o),o=null)}var i=setInterval(function(){if(o)for(var t=n;;t=t.parentNode){if(t&&11==t.nodeType&&(t=t.host),t==document.body)return;if(!t){r();break}}if(!o)return clearInterval(i)},400);s.on(n,"mouseout",r)}function u(e,t,n){this.marked=[],this.options=t,this.timeout=null,this.hasGutter=n,this.onMouseOver=function(t){!function(t,e){var n=e.target||e.srcElement;if(!/\bCodeMirror-lint-mark-/.test(n.className))return;for(var o=n.getBoundingClientRect(),r=(o.left+o.right)/2,i=(o.top+o.bottom)/2,a=t.findMarksAt(t.coordsChar({left:r,top:i},"client")),s=[],u=0;u<a.length;++u){var l=a[u].__annotation;l&&s.push(l)}s.length&&function(t,e){for(var n=e.target||e.srcElement,o=document.createDocumentFragment(),r=0;r<t.length;r++){var i=t[r];o.appendChild(g(i))}c(e,o,n)}(s,e)}(e,t)},this.waitingFor=0}function h(t){var e=t.state.lint;e.hasGutter&&t.clearGutter(p);for(var n=0;n<e.marked.length;++n)e.marked[n].clear();e.marked.length=0}function v(e,t,n,o){var r=document.createElement("div"),i=r;return r.className="CodeMirror-lint-marker-"+t,n&&((i=r.appendChild(document.createElement("div"))).className="CodeMirror-lint-marker-multiple"),0!=o&&s.on(i,"mouseover",function(t){c(t,e,i)}),r}function g(t){var e=t.severity;e=e||"error";var n=document.createElement("div");return n.className="CodeMirror-lint-message-"+e,void 0!==t.messageHTML?n.innerHTML=t.messageHTML:n.appendChild(document.createTextNode(t.message)),n}function l(e){var t=e.state.lint.options,n=t.options||t,o=t.getAnnotations||e.getHelper(s.Pos(0,0),"lint");if(o)if(t.async||o.async)!function(n,t,e){var o=n.state.lint,r=++o.waitingFor;function i(){r=-1,n.off("change",i)}n.on("change",i),t(n.getValue(),function(t,e){n.off("change",i),o.waitingFor==r&&(e&&t instanceof s&&(t=e),n.operation(function(){f(n,t)}))},e,n)}(e,o,n);else{var r=o(e.getValue(),n,e);if(!r)return;r.then?r.then(function(t){e.operation(function(){f(e,t)})}):e.operation(function(){f(e,r)})}}function f(t,e){h(t);for(var n,o,r=t.state.lint,i=r.options,a=function(t){for(var e=[],n=0;n<t.length;++n){var o=t[n],r=o.from.line;(e[r]||(e[r]=[])).push(o)}return e}(e),s=0;s<a.length;++s){var u=a[s];if(u){for(var l=null,c=r.hasGutter&&document.createDocumentFragment(),f=0;f<u.length;++f){var m=u[f],d=m.severity;o=d=d||"error",l="error"==(n=l)?n:o,i.formatAnnotation&&(m=i.formatAnnotation(m)),r.hasGutter&&c.appendChild(g(m)),m.to&&r.marked.push(t.markText(m.from,m.to,{className:"CodeMirror-lint-mark-"+d,__annotation:m}))}r.hasGutter&&t.setGutterMarker(s,p,v(c,l,1<u.length,r.options.tooltips))}}i.onUpdateLinting&&i.onUpdateLinting(e,a,t)}function m(t){var e=t.state.lint;e&&(clearTimeout(e.timeout),e.timeout=setTimeout(function(){l(t)},e.options.delay||500))}s.defineOption("lint",!1,function(t,e,n){if(n&&n!=s.Init&&(h(t),!1!==t.state.lint.options.lintOnChange&&t.off("change",m),s.off(t.getWrapperElement(),"mouseover",t.state.lint.onMouseOver),clearTimeout(t.state.lint.timeout),delete t.state.lint),e){for(var o=t.getOption("gutters"),r=!1,i=0;i<o.length;++i)o[i]==p&&(r=!0);var a=t.state.lint=new u(t,function(t,e){return e instanceof Function?{getAnnotations:e}:(e&&!0!==e||(e={}),e)}(0,e),r);!1!==a.options.lintOnChange&&t.on("change",m),0!=a.options.tooltips&&"gutter"!=a.options.tooltips&&s.on(t.getWrapperElement(),"mouseover",a.onMouseOver),l(t)}}),s.defineExtension("performLint",function(){this.state.lint&&l(this)})}); |