forked from niklasvh/feedback.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfeedback.min.js
1 lines (1 loc) · 13.4 KB
/
feedback.min.js
1
!function(e,t,a){function n(e){return s.gettext(e)}var i={label:"Send Feedback",header:"Send Feedback",nextLabel:"Continue",reviewLabel:"Review",sendLabel:"Send",closeLabel:"Close",messageSuccess:"Your feedback was sent succesfully.",messageError:"There was an error sending your feedback to the server.",formDescription:"Please describe the issue you are experiencing",highlightDescription:"Highlight or blackout important information",highlight:"Highlight",blackout:"Blackout",issue:"Issue"},s=Object.create({"default":i,lang:"default",gettext:function(e){return this[this.lang]&&this[this.lang][e]?this[this.lang][e]:this["default"][e]?this["default"][e]:e}});if(s.es_MX={label:"Env?e sus comentarios",header:"Env?e sus comentarios",nextLabel:"Continuar",reviewLabel:"Revise",sendLabel:"Enviar",closeLabel:"Cerrar",messageSuccess:"Su reacci?n ha sido enviado con ?xito.",messageError:"Se ha producido un error al enviar sus comentarios en el servidor."},s.es_MX={label:"Enviar coment?rios",header:"Enviar coment?rios",nextLabel:"Continuar",reviewLabel:"Revisar",sendLabel:"Enviar",closeLabel:"Fechar",messageSuccess:"Seu coment?rio foi enviado com sucesso.",messageError:"Houve um erro ao enviar seu coment?rio ao servidor."},s.ru_RU={label:"Сообщить об ошибке",header:"Сообщить об ошибке",nextLabel:"Далее",reviewLabel:"Далее",sendLabel:"Отправить",closeLabel:"Закрыть",messageSuccess:"Ваше сообщение успешно отправлено.",messageError:"Произошла ошибка при отправке сообщения на сервер.",formDescription:"Пожалуйста, опишите проблему с которой вы столкнулись",highlightDescription:"Выделите или спрячьте важную информацию",highlight:"Выделить",blackout:"Спрятать",issue:"Ваше сообщение"},e.Feedback===a){var o,l=function(t){e.console.log(t)},r=function(e){for(var t=0,n=e.length;n>t;t++){var i=Array.prototype.pop.call(e);i!==a&&null!==i.parentNode&&i.parentNode.removeChild(i)}},c=function(){var e=t.createElement("div"),a=3;for(e.className="feedback-loader";a--;)e.appendChild(t.createElement("span"));return e},d=function(e){return e.getBoundingClientRect()},h=function(e){for(var t;null!==(t=e.firstChild)?e.removeChild(t):!1;);},p=function(e,a){var n=t.createElement(e);return n.appendChild(t.createTextNode(a)),n},g=function(t,n){if(t.onload!==a)return n;if(t.onreadystatechange!==a){var i=function(){"loaded"!==t.readyState&&"complete"!==t.readyState?e.setTimeout(i,250):n()};e.setTimeout(i,250)}else l("ERROR: We can't track when script is loaded")},u=function(){var e;return e=navigator.languages!=a?navigator.languages[0]:navigator.language,e?e.replace("-","_"):void 0},m="data-html2canvas-ignore",f=t.createElement("div");e.Feedback=function(i){i=i||{},i.url=i.url||"/",i.adapter=i.adapter||new e.Feedback.XHR(i.url),i.lang=i.lang||"auto","auto"===i.lang&&(i.lang=u()),s.lang=i.lang,i.pages===a&&(i.pages=[new e.Feedback.Form,new e.Feedback.Screenshot(i),new e.Feedback.Review]);var l,d,g,b=t.createElement("div"),v={open:function(){var a=i.pages.length;for(g=0;a>g;g++)i.pages[g]instanceof e.Feedback.Review||i.pages[g].render();var s=p("a","×"),r=t.createElement("div"),c=t.createElement("div");d=t.createElement("div"),t.body.appendChild(b),s.className="feedback-close",s.onclick=v.close,s.href="#",l.disabled=!0,r.appendChild(s),r.appendChild(p("h3",n("header"))),r.className="feedback-header",f.className="feedback-body",h(f),g=0,f.appendChild(i.pages[g++].dom),o=p("button",n("nextLabel")),o.className="feedback-btn",o.onclick=function(){g>0&&i.pages[g-1].end(d)===!1||(h(f),g===a?v.send(i.adapter):(i.pages[g].start(d,r,c,o),i.pages[g]instanceof e.Feedback.Review&&i.pages[g].render(i.pages),f.appendChild(i.pages[g++].dom),g===a&&(o.firstChild.nodeValue=n("sendLabel")),i.pages[g]instanceof e.Feedback.Review&&(o.firstChild.nodeValue=n("reviewLabel"))))},c.className="feedback-footer",c.appendChild(o),d.className="feedback-modal",d.setAttribute(m,!0),d.appendChild(r),d.appendChild(f),d.appendChild(c),t.body.appendChild(d)},close:function(){l.disabled=!1,r([d,b]),g>0&&i.pages[g-1].end(d);for(var e=0,t=i.pages.length;t>e;e++)i.pages[e].close();return!1},send:function(s){if(!(s instanceof e.Feedback.Send))throw new Error("Adapter is not an instance of Feedback.Send");for(var l,r=0,d=i.pages.length,p=[],g=0;d>r;r++)(l=i.pages[r].data())!==!1&&(p[g++]=l);o.disabled=!0,h(f),f.appendChild(c()),s.send(p,function(s){h(f),o.disabled=!1,o.firstChild.nodeValue=n("closeLabel"),o.onclick=function(){return v.close(),!1},f.appendChild(s===!0?t.createTextNode(n("messageSuccess")):t.createTextNode(n("messageError")));for(var l=i.pages.length,r=0;l>r;r++)i.pages[r]instanceof e.Feedback.Review||(i.pages[r]._data=a)})}};return b.className="feedback-glass",b.style.pointerEvents="none",b.setAttribute(m,!0),i=i||{},l=p("button",n("label")),l.className="feedback-btn feedback-bottom-right",l.setAttribute(m,!0),l.onclick=v.open,null!==i.appendTo&&(i.appendTo!==a?i.appendTo:t.body).appendChild(l),v},e.Feedback.Page=function(){},e.Feedback.Page.prototype={render:function(e){this.dom=e},start:function(){},close:function(){},data:function(){return!1},review:function(){return null},end:function(){return!0}},e.Feedback.Send=function(){},e.Feedback.Send.prototype={send:function(){}},e.Feedback.Form=function(e){this.elements=e||[{type:"textarea",name:"issue",label:n("formDescription"),required:!1}],this.dom=t.createElement("div")},e.Feedback.Form.prototype=new e.Feedback.Page,e.Feedback.Form.prototype.render=function(){var e,a=0,n=this.elements.length;for(h(this.dom);n>a;a++)switch(e=this.elements[a],e.type){case"textarea":this.dom.appendChild(p("label",e.label+":"+(e.required===!0?" *":""))),this.dom.appendChild(e.element=t.createElement("textarea"))}return this},e.Feedback.Form.prototype.end=function(){for(var e,t=0,a=this.elements.length;a>t;t++){if(e=this.elements[t],e.required===!0&&0===e.element.value.length)return e.element.className="feedback-error",!1;e.element.className=""}return!0},e.Feedback.Form.prototype.data=function(){if(this._data!==a)return this._data;for(var t,n=0,i=this.elements.length,s={};i>n;n++)t=this.elements[n],s[t.name]=t.element.value;return s.url=e.location.href,this._data=s},e.Feedback.Form.prototype.review=function(e){for(var a,n=0,i=this.elements.length;i>n;n++)a=this.elements[n],a.element.value.length>0&&(e.appendChild(p("label",a.label+":")),e.appendChild(t.createTextNode(a.element.value)),e.appendChild(t.createElement("hr")));return e},e.Feedback.Review=function(){this.dom=t.createElement("div"),this.dom.className="feedback-review"},e.Feedback.Review.prototype=new e.Feedback.Page,e.Feedback.Review.prototype.render=function(e){var t=0,a=e.length;for(h(this.dom);a>t;t++)e[t].review(this.dom);return this},e.Feedback.Screenshot=function(e){this.options=e||{},this.options.blackoutClass=this.options.blackoutClass||"feedback-blackedout",this.options.highlightClass=this.options.highlightClass||"feedback-highlighted",this.h2cDone=!1},e.Feedback.Screenshot.prototype=new e.Feedback.Page,e.Feedback.Screenshot.prototype.end=function(e){e.className=e.className.replace(/feedback\-animate\-toside/,""),t.body.removeEventListener("mousemove",this.mouseMoveEvent,!1),t.body.removeEventListener("click",this.mouseClickEvent,!1),r([this.h2cCanvas]),this.h2cDone=!1},e.Feedback.Screenshot.prototype.close=function(){r([this.blackoutBox,this.highlightContainer,this.highlightBox,this.highlightClose]),r(t.getElementsByClassName(this.options.blackoutClass)),r(t.getElementsByClassName(this.options.highlightClass))},e.Feedback.Screenshot.prototype.start=function(i,s,o,l){if(this.h2cDone){h(this.dom),l.disabled=!1;var r=this,g="feedback-highlight-element",u="data-exclude",m=!0;this.mouseMoveEvent=function(t){if(t.target!==v&&(-1!==t.target.className.indexOf(r.options.blackoutClass)||-1!==t.target.className.indexOf(r.options.highlightClass))){var n=parseInt(t.target.style.left,10)+parseInt(t.target.style.width,10);n=Math.max(n,10),n=Math.min(n,e.innerWidth-15);var o=parseInt(t.target.style.top,10);return o=Math.max(o,10),k.style.left=n+"px",k.style.top=o+"px",b=t.target,F(),void(v=a)}return"BODY"===t.target.nodeName||t.target===k||t.target===i||t.target===l||t.target.parentNode===i||t.target.parentNode===s?(F(),void(v=t.target)):(S(),void(t.target!==v&&(v=t.target,e.clearTimeout(f),f=e.setTimeout(function(){var t,a=d(v);m===!1?t=C:(t=y,t.width=a.width,t.height=a.height,x.drawImage(r.h2cCanvas,e.pageXOffset+a.left,e.pageYOffset+a.top,a.width,a.height,0,0,a.width,a.height)),t.setAttribute(u,!1),t.style.left=e.pageXOffset+a.left+"px",t.style.top=e.pageYOffset+a.top+"px",t.style.width=a.width+"px",t.style.height=a.height+"px"},100))))},this.mouseClickEvent=function(e){if(e.preventDefault(),m===!1){if("false"===C.getAttribute(u)){var n=t.createElement("div");n.className=r.options.blackoutClass,n.style.left=C.style.left,n.style.top=C.style.top,n.style.width=C.style.width,n.style.height=C.style.height,t.body.appendChild(n),v=a}}else"false"===y.getAttribute(u)&&(y.className+=" "+r.options.highlightClass,y.className=y.className.replace(/feedback\-highlight\-element/g,""),r.highlightBox=y=t.createElement("canvas"),x=y.getContext("2d"),y.className+=" "+g,t.body.appendChild(y),F(),v=a)},this.highlightClose=p("div","×"),this.blackoutBox=t.createElement("div"),this.highlightBox=t.createElement("canvas"),this.highlightContainer=t.createElement("div");var f,b,v,k=this.highlightClose,y=this.highlightBox,C=this.blackoutBox,w=this.highlightContainer,x=y.getContext("2d"),E=function(e){e.preventDefault(),-1===L.className.indexOf("active")?(L.className+=" active",R.className=R.className.replace(/active/g,"")):(R.className+=" active",L.className=L.className.replace(/active/g,"")),m=!m},F=function(){N(C),N(y),e.clearTimeout(f)},N=function(e){e.style.left="-5px",e.style.top="-5px",e.style.width="0px",e.style.height="0px",e.setAttribute(u,!0)},S=function(){k.style.left="-50px",k.style.top="-50px"},L=p("a",n("blackout")),R=p("a",n("highlight"));i.className+=" feedback-animate-toside",k.id="feedback-highlight-close",k.addEventListener("click",function(){b.parentNode.removeChild(b),S()},!1),t.body.appendChild(k),this.h2cCanvas.className="feedback-canvas",t.body.appendChild(this.h2cCanvas);var T=[R,L];this.dom.appendChild(p("p",n("highlightDescription")));for(var B=0;2>B;B++)T[B].className="feedback-btn feedback-btn-small "+(0===B?"active":"feedback-btn-inverse"),T[B].href="#",T[B].onclick=E,this.dom.appendChild(T[B]),this.dom.appendChild(t.createTextNode(" "));w.id="feedback-highlight-container",w.style.width=this.h2cCanvas.width+"px",w.style.height=this.h2cCanvas.height+"px",this.highlightBox.className+=" "+g,this.blackoutBox.id="feedback-blackout-element",t.body.appendChild(this.highlightBox),w.appendChild(this.blackoutBox),t.body.appendChild(w),t.body.addEventListener("mousemove",this.mouseMoveEvent,!1),t.body.addEventListener("click",this.mouseClickEvent,!1)}else{var D=arguments,r=this;l.disabled!==!0&&this.dom.appendChild(c()),l.disabled=!0,e.setTimeout(function(){r.start.apply(r,D)},500)}},e.Feedback.Screenshot.prototype.render=function(){this.dom=t.createElement("div");var n,i=this,s=this.options,o=function(){try{s.onrendered=s.onrendered||function(e){i.h2cCanvas=e,i.h2cDone=!0},e.html2canvas([t.body],s)}catch(a){i.h2cDone=!0,l("Error in html2canvas: "+a.message)}};if(e.html2canvas===a&&n===a){n=t.createElement("script"),n.src=s.h2cPath||"libs/html2canvas.js",n.onerror=function(){l("Failed to load html2canvas library, check that the path is correctly defined")},n.onload=g(n,function(){return e.html2canvas===a?void l("Loaded html2canvas, but library not found"):(e.html2canvas.logging=e.Feedback.debug,void o())});var r=t.getElementsByTagName("script")[0];r.parentNode.insertBefore(n,r)}else o();return this},e.Feedback.Screenshot.prototype.data=function(){if(this._data!==a)return this._data;if(this.h2cCanvas!==a){var e,n,i=this.h2cCanvas.getContext("2d"),s=5;i.fillStyle="#000",Array.prototype.slice.call(t.getElementsByClassName("feedback-blackedout"),0).forEach(function(e){var t=d(e);i.fillRect(t.left,t.top,t.width,t.height)});var o=Array.prototype.slice.call(t.getElementsByClassName("feedback-highlighted"),0);o.length>0&&(e=t.createElement("canvas"),n=e.getContext("2d"),e.width=this.h2cCanvas.width,e.height=this.h2cCanvas.height,n.drawImage(this.h2cCanvas,0,0),i.fillStyle="#777",i.globalAlpha=.5,i.fillRect(0,0,this.h2cCanvas.width,this.h2cCanvas.height),i.beginPath(),o.forEach(function(e){var t=parseInt(e.style.left,10),a=parseInt(e.style.top,10),n=parseInt(e.style.width,10),o=parseInt(e.style.height,10);i.moveTo(t+s,a),i.lineTo(t+n-s,a),i.quadraticCurveTo(t+n,a,t+n,a+s),i.lineTo(t+n,a+o-s),i.quadraticCurveTo(t+n,a+o,t+n-s,a+o),i.lineTo(t+s,a+o),i.quadraticCurveTo(t,a+o,t,a+o-s),i.lineTo(t,a+s),i.quadraticCurveTo(t,a,t+s,a)}),i.closePath(),i.clip(),i.globalAlpha=1,i.drawImage(e,0,0));try{return this._data=this.h2cCanvas.toDataURL()}catch(l){}}},e.Feedback.Screenshot.prototype.review=function(e){var t=this.data();if(t!==a){var n=new Image;n.src=t,n.style.width="300px",e.appendChild(n)}},e.Feedback.XHR=function(e){this.xhr=new XMLHttpRequest,this.url=e},e.Feedback.XHR.prototype=new e.Feedback.Send,e.Feedback.XHR.prototype.send=function(t,a){var n=this.xhr;n.onreadystatechange=function(){4==n.readyState&&a(200===n.status)},n.open("POST",this.url,!0),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.send("data="+encodeURIComponent(e.JSON.stringify(t)))}}}(window,document);