!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)})});