2 lines
6.8 KiB
JavaScript
2 lines
6.8 KiB
JavaScript
function disableScroll(){$("body").addClass("stop-scrolling")}function enableScroll(){$("body").removeClass("stop-scrolling")}function request(e,t,o,n,r=null){var s=new XMLHttpRequest;s.onreadystatechange=function(){var e;4==s.readyState&&200==s.status&&null!=r&&(e=JSON.parse(s.response),n={context:{baglist:[e.item.__id]}},r(n))},s.open("POST",o,!0),s.onload=function(){200<=s.status&&s.status<400?($(".ReportTypo-popup").find(".ReportTypo-main").removeClass("active").addClass("hidden"),$(".ReportTypo-popup").find(".ReportTypo-success").removeClass("hidden").addClass("active"),$(".ReportTypo-popup").addClass("active"),setTimeout(()=>{this.closeDialog(),$(".ReportTypo-popup").removeClass("active")},3e3)):(t.isError=!0,t.isSending=!1,this.refresh())}.bind(e),s.onerror=function(){t.isError=!0,t.isSending=!1,e.refresh()}.bind(e),s.send(JSON.stringify(n))}!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("TypoReporter",[],t):"object"==typeof exports?exports.TypoReporter=t():e.TypoReporter=t()}(this,function(){return o=[function(e,t,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.default=function(e,t,o){if("string"!=typeof e)throw new Error("tagName must be a string");var n=document.createElement(e);return t&&"object"===(void 0===t?"undefined":r(t))&&Object.keys(t).forEach(function(e){/on[A-Z][a-z]/.test(e)?n[e.toLowerCase()]=t[e]:n.setAttribute(e,t[e])}),"string"==typeof o?n.innerHTML=o:o instanceof Array&&o.forEach(function(e){n.appendChild(e)}),n},e.exports=t.default},function(e,t,o){"use strict";function n(e,t){if(e=e||{},!t)throw new Error('"rootNode" is not passed');if(!e.formId)throw new Error('"formId" option is not defined');if(e.snippetFieldName=e.snippetFieldName||"entry.13240190",e.urlFieldName=e.urlFieldName||"entry.238687347",e.commentFieldName=e.commentFieldName||"entry.1447231081",e.endpointUrl=e.endpointUrl||"https://cors-anywhere.herokuapp.com/https://docs.google.com/forms/d/e/"+e.formId+"/formResponse?embedded=true",e.offset=e.offset||50,e.translations=e.translations||this.translations,e.locale=e.locale||"en",!e.translations[e.locale])throw new Error("No translations defined for locale "+e.locale);this.i18n=e.translations[e.locale],this.props=e,this.node=t,this.state={},this.submit=this.submit.bind(this),this.handleCommentChange=this.handleCommentChange.bind(this),this.closeDialog=this.closeDialog.bind(this),document.addEventListener("keydown",function(e){e.ctrlKey&&13===e.which&&0!=window.getSelection().toString().length&&this.showDialog(),27===e.which&&this.closeDialog()}.bind(this)),this.refresh()}Object.defineProperty(t,"__esModule",{value:!0});var o=o(0),r=(o=o)&&o.__esModule?o:{default:o};n.prototype.translations={en:{header:"Report a mistake",messageLabel:"There is a mistake in the following text:",commentLabel:"Your comment",send:"Send",sending:"Sending",cancel:"Cancel",error:"Error! Something went wrong..."},ru:{header:"Сообщите об опечатке",messageLabel:"Текст, в котором допущена ошибка:",commentLabel:"Ваш комментарий",send:"Отправить",sending:"Идет отправка",cancel:"Отмена",error:"Ошибка! Что-то пошло не так..."}},n.prototype.render=function(){var e=this.state,t=this.i18n;return e.isOpen&&(0,r.default)("div",{class:"ReportTypo"},[(0,r.default)("div",{class:"ReportTypo-popup"},[(0,r.default)("button",{class:"ReportTypo-close",type:"button",onClick:this.closeDialog},""),(0,r.default)("div",{class:"ReportTypo-main active"},[(0,r.default)("div",{class:"ReportTypo-header"},t.header),(0,r.default)("div",{class:"ReportTypo-label"},t.messageLabel),(0,r.default)("div",{class:"ReportTypo-message"},e.snippet),(0,r.default)("div",{class:"floating_label"},[(0,r.default)("input",{class:"ReportTypo-comment form-control fill_listener",id:"form-comment",type:"text",onKeyup:this.handleCommentChange},e.comment),(0,r.default)("label",{for:"form-comment"},t.commentLabel)]),(0,r.default)("div",{class:"ReportTypo-label"},""),(0,r.default)("div",{style:""},[(0,r.default)("button",{type:"button",class:"ReportTypo-submit",onClick:this.submit},e.isSending?t.sending:t.send),(0,r.default)("button",{type:"button",class:"ReportTypo-cancel",onClick:this.closeDialog},t.cancel)])]),(0,r.default)("div",{class:"ReportTypo-success hidden"},[(0,r.default)("div",{class:"ReportTypo-success-image"},""),(0,r.default)("p",null,"Feedback sent successfully"),(0,r.default)("span",null,"Thank you for your input")]),(0,r.default)("div",null,e.isError&&t.error)])])},n.prototype.refresh=function(){var e=this.node,t=(e.innerHTML="",this.render());t&&e.appendChild(t)},n.prototype.submit=function(){var t=this.state,o=this.props,e=(t.isSending=!0,this.refresh(),new FormData),n={context:{tema:"Быстрое оповещение об опечатках",tip:[{code:"ispravit_opechatki",name:"Исправить опечатки"}],lokal:[{code:getLocale().toUpperCase(),name:getLocale().toLowerCase()}],produkt:[getProduct().id],ssylka_na_statyu:window.location.href,opisanie:t.comment,snippet:t.snippet}},r=(e.append(o.snippetFieldName,t.snippet),e.append(o.commentFieldName,t.comment),e.append(o.urlFieldName,window.location),this);request(this,t,o.endpointUrl+"create",n,function(e){request(r,t,o.endpointUrl+"run",e)})},n.prototype.getSnippet=function(){var e,t,o=this.props,n=document.getSelection(),r=n.toString();if(disableScroll(),r)return n=n.getRangeAt(0),t=document.createRange(),e=document.createRange(),t.setStartBefore(n.startContainer.ownerDocument.body),t.setEnd(n.startContainer,n.startOffset),e.setStart(n.endContainer,n.endOffset),e.setEndAfter(n.endContainer.ownerDocument.body),t.toString().substr(-o.offset),e.toString().substr(0,o.offset),n=r,(t=document.createElement("div")).innerHTML=n,t.innerText.replace(/\r?\n|\r/g,"").replace(/\s+/g," ")},n.prototype.showDialog=function(){var e=this.state;e.snippet=this.getSnippet(),e.snippet&&(e.isOpen=!0,this.refresh())},n.prototype.closeDialog=function(){enableScroll(),this.state={},this.refresh()},n.prototype.handleCommentChange=function(e){this.state.comment=e.target.value},t.default=n,e.exports=t.default}],r={},n.m=o,n.c=r,n.i=function(e){return e},n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1);function n(e){var t;return(r[e]||(t=r[e]={i:e,l:!1,exports:{}},o[e].call(t.exports,t,t.exports,n),t.l=!0,t)).exports}var o,r});
|