Current Path : /var/www/www-root/data/www/www.monolith-realty.ru/bitrix/js/landing/client/ |
Current File : /var/www/www-root/data/www/www.monolith-realty.ru/bitrix/js/landing/client/glavred.min.js |
(function(){"use strict";BX.namespace("BX.Landing.Client");var t=BX.Landing.Utils.createSelectionRange;var n=BX.Landing.Utils.wrapSelection;var e="ok";var i="fail";var r="pending";BX.Landing.Client.Glavred=function(){this.markupMatcher=new RegExp('(<span[^>]*class="glvrd-underline"[^>]*>)(.+?)(<\\/span>)',"g");this.serviceStatus=r;this.proofStatus=e};BX.Landing.Client.Glavred.getInstance=function(){return BX.Landing.Client.Glavred.instance||(BX.Landing.Client.Glavred.instance=new BX.Landing.Client.Glavred)};BX.Landing.Client.Glavred.prototype={getStatus:function(){return new Promise(function(t,n){if(this.serviceStatus!==e){top.glvrd.getStatus(function(r){if(r.status===e){t();this.serviceStatus=e}else{n(r.message);this.serviceStatus=i}}.bind(this))}else{t()}}.bind(this))},proofread:function(t){return this.getStatus().then(function(){return new Promise(function(n){top.glvrd.proofread(t.textContent,n)})}).then(function(n){this.removeMarkup(t);this.addMarkup(t,n);return this.getScore(t.textContent,n.fragments)}.bind(this))},getScore:function(t,n){return this.getStatus().then(function(){return top.glvrd.getScore({text:t,fragments:n})})},addMarkup:function(e,i){i.fragments.forEach(function(i){var r=t(e,i.start,i.end);var a=BX.create("span",{props:{className:"glvrd-underline"}});n(a,r);a.addEventListener("mouseenter",function(){BX.Landing.UI.Tool.Suggest.getInstance().show(this,i.hint)})}.bind(this))},removeMarkup:function(t){t.innerHTML=t.innerHTML.replace(this.markupMatcher,"$2");t.innerHTML=t.innerHTML.replace(this.markupMatcher,"$2")}}})();