text: define("Lib/Control/HTMLView/HTMLView",["Core/helpers/Number/randomId","Core/helpers/Function/forAliveOnly","Core/dom/wheel","Core/dom/keyDown","Core/helpers/Hcontrol/getScrollWidth","Core/helpers/Hcontrol/hasScrollbar","Core/helpers/Hcontrol/setElementCachedSize","Core/ParallelDeferred","Core/Deferred","Env/Env","Lib/Control/TemplatedAreaAbstract/TemplatedAreaAbstract","Lib/Control/LoadingIndicator/LoadingIndicator","Core/helpers/getResourceUrl","css!Lib/Control/HTMLView/HTMLView"],function(t,l,e,i,c,f,u,m,p,_,n,r,o){"use strict";var s=750;function g(t){return t.complete&&("undefined"===typeof t.naturalWidth||t.naturalWidth>0)}function a(t){var e=_.constants.hosts.length,i="";if(e>0)if(i=_.constants.hosts[Math.floor(Math.random()*e)],"."==t.substring(0,1)){var n=window.location.pathname;t=i+(n=n.substring(0,n.lastIndexOf("/")+1))+t.substring(2)}else t=i+("/"==t.substring(0,1)?"":"/")+t;return t}var w=n.extend({$protected:{_width:"",_height:"",_options:{docType:"string",url:"",string:"",safeContent:false,tensorFontsUrl:void 0,activableByClick:false},_iframeReady:void 0,_dReady:void 0,_iframe:void 0,_iframeContainer:void 0,_loaded:true,_iframeId:"",_resizerHeight:0,_resizerWidth:0,_oldResizerHeight:0,_oldResizerWidth:0,_loadingIndicatorTimer:null},$constructor:function(){this._publish("onContentSet","onContentReady","onBeforePrint","onIframeCreate"),this.once("onDestroy",function(){this._iframe=$(),this._iframeContainer=$()}),this.getContainer().addClass("ws-HTMLView"),this._redraw()},_removeLoadingIndicator:function(){if(this._loadingIndicatorTimer)clearTimeout(this._loadingIndicatorTimer);var t=this._getIndicator();if(t)t.destroy()},_createLoadingIndicator:function(){if(this._loadingIndicatorTimer)clearTimeout(this._loadingIndicatorTimer);this._loadingIndicatorTimer=setTimeout(function(){new r({showInWindow:false,element:$("<div />",{class:"ws-HTMLView__loadingIndicator"}).appendTo(this._container)})}.bind(this),s)},_redraw:function(){var t=this;if(this._dReady=new p,this._iframeReady=new p,void 0===this._options.maxWidth)this._options.maxWidth=1/0;if(void 0===this._options.maxHeight)this._options.maxHeight=1/0;switch(this._options.docType){case"string":if(this._options.string)this.setHTML(this._options.string);else this._dReady.callback();break;case"url":if(this._options.url)this.setUrl(this._options.url);else this._dReady.callback();break;case"template":this.setTemplate(this._options.template);break;default:throw new Error("HTMLView does not support this docType")}this._dReady.addCallback(l(function(){t._dChildReady.done(),t._isReady=true},t))},_getIndicator:function(){return this.getContainer().find(".ws-HTMLView__loadingIndicator").wsControl()},_waitResources:function(){var r=this.getIframeDocument(),t=l(this.setAutoSize,this),e=l(function(){this.showIframeContainer(),this._removeLoadingIndicator(),t(),this._notify("onContentReady")},this),i,n,o,s,a;if(r)n=r.body,o=$("img",n),s=$("link",r),a=$("style",r);else o=$(),s=$(),a=$();if(i=o.toArray().reduce(function(t,e){var i,n;if(!g(e))n=(i=new p).callback.bind(i),$(e).bind("load",n).bind("error",n),t.push(i);return t},[]),s.length||a.length){var h=s.toArray().map(function(t){var e=$("<img />",{style:"position: absolute; visibility: hidden; left: 0; top: 0; display: block;"}),i=new p,n=l(function t(){e.remove(),i.callback()},this);return e.bind("load",n).bind("error",n).appendTo(r.body).prop("src",$(t).attr("href")),i},this);i=i.concat(h),p.fromTimer(500).addCallback(t)}if(0!==i.length){var d=new m({steps:i}).done().getResult().addCallback(t);p.nearestOf([d,p.fromTimer(2e3)]).addBoth(e)}else e()},_dispatchIframeWheelEventsToParentDocument:function(s){if(s.contentDocument){var r={target:true,eventPhase:true,explicitOriginalTarget:true,originalTarget:true,timeStamp:true,isTrusted:true,defaultPrevented:true,cancelable:true,bubbles:true},a=function t(e,i){for(var n in i)if(!(n in r)&&n.charAt(0)===n.charAt(0).toLowerCase())try{e[n]=i[n]}catch(t){}return e},h=$(s.contentDocument);if(e(h,function(t){var e,i;if(!$(t.target,h).parents().filter(function(){return this.scrollHeight>this.offsetHeight&&/auto|scroll/.test($(this).css("overflow-y"))}).length){var n,r=h.get(0),o=t.originalEvent;if(r.createEvent)(n=r.createEvent("Event")).initEvent(o.type,true,false),n=a(n,o),s.dispatchEvent(n);else if(r.createEventObject)n=r.createEventObject(),n=a(n,o),s.fireEvent("on"+o.type,n)}}),_.constants.browser.retailOffline)h.bind("touchstart touchmove touchend",function(t){var e=h.get(0),i=t.originalEvent,n=e.createEvent("Event");n.initEvent(i.type,true,false),s.dispatchEvent(a(n,i))})}},_dispatchIframeEscEventsToParentDocument:function(o){if((o=$(o).get(0)).contentDocument){var s={target:true,eventPhase:true,explicitOriginalTarget:true,originalTarget:true,timeStamp:true,isTrusted:true,defaultPrevented:true,cancelable:true,bubbles:true},a=$(o.contentDocument);i(a,function(t){if(t.which==_.constants.key.esc){var e=a.get(0).createEvent("Event"),i=t.originalEvent;for(var n in e.initEvent(i.type,true,false),i)if(i.hasOwnProperty(n)){var r=i[n];if(!(n in s)&&n.charAt(0)===n.charAt(0).toLowerCase())try{e[n]=r}catch(t){}}e.which=t.which,o.dispatchEvent(e)}})}},_contentLoaded:function(){if(!this._dReady.isReady())this._dReady.callback();this._dispatchIframeWheelEventsToParentDocument(this._iframe),this._dispatchIframeEscEventsToParentDocument(this._iframe),this._mouseUpHandler=function(t){$(this._iframe).trigger(t)}.bind(this),$(this._iframe.contentDocument).on("mouseup touchend",this._mouseUpHandler),this._waitResources()},_getIframeBodySize:function(t,e,i){var n=t.contents(),r=$("body",n),o=$("html",n),s,a;if(r.length>0&&(e||i)){if(e)t.css("width",0);else this._width&&t.css("width",this._width);if(i)t.css("height",0);else this._height&&t.css("height",this._height);if(o.css("margin","0"),!e)o.css("width","100%");var h=r.outerWidth(true)-r.innerWidth()+o.outerWidth(true)-o.innerWidth(),d=r.outerHeight(true)-r.innerHeight()+o.outerHeight(true)-o.innerHeight();if(e)a=Math.max(parseInt(r.prop("scrollWidth"),10),r.outerWidth(true)+h,this._options.minWidth);else a=0;if(i)s=Math.max(parseInt(r.prop("scrollHeight"),10),r.outerHeight(true)+d);else s=0;if(i&&!e&&f.horizontal(r))s+=c();if(e&&!i&&f.vertical(r))a+=c();o.css("width",""),o.css("position",""),r.css("position","")}else s=i?this._options.minHeight:0,a=e?this._options.minWidth:0;return{height:s,width:a}},_restoreSize:function(){},_updateResizer:function(){function t(t){var e,i,n,r;if(this._options.autoHeight)if("Stretch"==this._verticalAlignment)e="100%";else e=t.height;else e=this._container.height();if(this._options.autoWidth)if("Stretch"==this._horizontalAlignment)i="100%";else i=t.width;else i=this._container.width();if("100%"!==i)r=i=Math.max(Math.min(parseInt(i,10),this._options.maxWidth),this._options.minWidth);else r=0;if("100%"!==e)n=e=Math.max(Math.min(parseInt(e,10),this._options.maxHeight),this._options.minHeight);else n=0;var o=$("html",s.contents());if(h&&a)o.css("overflow","hidden");else if(a)o.css("overflow-x","hidden");else if(h)o.css("overflow-y","hidden");if(s.width(i).height(e),a)this._container.width(i);if(this._options.autoHeight&&"100%"!==e&&this._container.width()<t.width)n=e+=c();if(h)this._container.height(Math.max(this._iframeContainer.height(),e));return u(this._resizer,{width:r,height:n}),this._resizerHeight=n,{width:this._resizerWidth=r,height:n}}if("template"==this._options.docType)w.superclass._updateResizer();else{var s=this._getCurrIframeCtrl();if(!s)return;var a=this._options.autoWidth&&"Stretch"!==this._horizontalAlignment,h=this._options.autoHeight&&"Stretch"!==this._verticalAlignment,e=this._getIframeBodySize(s,a,h);if(e=t.call(this,e),_.constants.browser.isIE&&(a||h)){var i=s.contents(),n=$("body",i),r;if(n.length>0){if(r=$("html",i),a){var o=n.prop("scrollWidth");if(o>e.width)e.width=o+1,e=t.call(this,e)}if(h){var d=n.prop("scrollHeight");if(d>e.height)e.height=d+1,t.call(this,e)}}}}},setAutoSize:function(){if(this._getCurrIframeCtrl()){if(!this._resizer)this._initResizers();else this._updateResizer();if(this._resizerHeight!==this._oldResizerHeight||this._resizerWidth!==this._oldResizerWidth)this._notifyOnSizeChanged(this,this);this._oldResizerWidth=this._resizerWidth,this._oldResizerHeight=this._resizerHeight}},_loadDescendents:function(){},_createIFrame:function(t,e){var i=this._createFrameId();if(this._iframeReady.isReady())this._iframeReady=new p;if("function"==typeof t&&"undefined"==typeof e)e=t,t={};this._removeLoadingIndicator(),this._container.empty(),this._createLoadingIndicator(),this._iframeContainer=$("<div />",{id:"htmlview_"+this.getId()}).appendTo(this._container);var n=/%/,r=this._options.autoWidth?"auto":n.test(this._options.width)?this._options.width:this._options.width+"px",o=this._options.autoHeight?"auto":n.test(this._options.height)?this._options.height:this._options.height+"px",s={position:"absolute",left:0,top:0,width:this._options.autoWidth&&"Stretch"!=this._horizontalAlignment?r:"100%",height:this._options.autoHeight&&"Stretch"!=this._verticalAlignment?o:"100%"};if(_.constants.browser.isMobileSafari)s["-webkit-overflow-scrolling"]="touch",s.overflow="auto";if(_.constants.browser.isIE)s.overflow="visible";this._iframeContainer.css(s),this.hideIframeContainer();var a=$("<iframe>iFrame not supported!</iframe>"),h={id:i,name:i,frameborder:0};if(this._options.safeContent)h.sandbox="allow-forms allow-popups allow-same-origin";return a.attr(h).css({width:"100%",height:"100%"}),this._notify("onIframeCreate",a),a.on("load",e.bind(this,a.get(0))).attr(t).appendTo(this._iframeContainer)},setHTML:function(a,t){var h=this,d=function(t){return l(t,h)};if("number"===typeof t&&a.length>t)return false;function c(t){return t=o(t),'<link rel="stylesheet" href="'+_.constants.resourceRoot+t+'">'}return this._options.docType="string",this._loaded=false,this._createIFrame(d(function(t){if(!h._loaded){h._loaded=true,h._iframe=t;var e=h._container.get(0),i=e&&e.style.visibility||"",n=h.getIframeDocument(),r=h.getIframeWindow(),o,s;if(h._container.css("visibility","visible"),n.open(),n.write(a),n.close(),h._container.css("visibility",i),o=d(function(){var e,t;if("interactive"!==n.readyState&&"complete"!==n.readyState)return;if(e=$(n).find("head"),t=h._options.tensorFontsUrl||_.constants.tensorFontsUrl,s)n.removeEventListener(s,o);if(e.append('<meta name="format-detection" content="telephone=no">'),e.append('<style media="screen, print">body { margin: 0; } a[href^="tel:"] { text-decoration: none; color: inherit; }</style>'),h._options.minWidth)e.append("<style>.ws-register-table { min-width: "+h._options.minWidth+"px; } </style>");if(t instanceof Array)t.forEach(function(t){if(t)e.append(c(t))});else if(t)e.append(c(t));var i="window.printPage = function printPage() {window.print();};";if(r["eval"])r.eval(i);else r.execScript(i);h._iframeReady.addCallback(d(function(){h._notify("onContentSet","string",a),h._contentLoaded()})),h._iframeReady.callback()},h),"interactive"===n.readyState||"complete"===n.readyState)o();else{if(_.detection.isIE&&_.detection.IEVersion<=10)s="readystatechange";else s="DOMContentLoaded";n.addEventListener(s,o)}}})),true},getHTML:function(){return this.getIframeDocument().body.innerHTML},setTemplate:function(t){var e=this;return this._options.template=t,this._options.docType="template",this._iframe=void 0,this._runInBatchUpdate("setTemplate",function(){return e._loadTemplate().addCallback(l(function(){e._notify("onContentSet","template",t)},e))})},setUrl:function(i){var n=this,r=function(t){return l(t,n)};this._loaded=false,this._createIFrame({src:i},r(function(t){n._iframe=t,n._loaded=true;var e=n.getIframeDocument();$(e).ready(r(function(){n._iframeReady.addCallback(r(function(){n._notify("onContentSet","url",i),n._contentLoaded()})),n._iframeReady.callback()}))}))},print:function(){var e=new p;if(this._iframe)if(false!==this._notify("onBeforePrint",this._iframe)){var i=this.getIframeWindow(),n=this,r=function(t){return l(t,n)};if(!i.document.title)i.document.title=window.document.title;if(_.constants.browser.opera){var o=this.getIframeDocument().documentElement,s=window.document.documentElement,a=$('<style type="text/css">'+"@media screen{"+"body > *, body {display: none !important;}"+"}"+"</style>");window.document.replaceChild(o,window.document.documentElement),$("head").append(a),setTimeout(r(function(){window.focus(),window.print(),setTimeout(r(function(){window.document.replaceChild(s,window.document.documentElement);var t=n.getIframeDocument();t.replaceChild(o,t.documentElement),setTimeout(r(function(){a.remove(),e.callback()}),100)}),100)}),500)}else{var h=false,d=$(this._iframe),c;if(_.constants.browser.isIE&&!d.is(":visible"))h=true,d.parents().addBack().each(function(){var t=$(this);t.data("display",t.css("display")),t.data("visibility",t.css("visibility")),t.data("ws-hidden",t.hasClass("ws-hidden")),t.css({display:"block",visibility:"visible"}),t.removeClass("ws-hidden")}),c=d.css("opacity"),d.css({opacity:0});setTimeout(r(function(){(n._iframe.contentWindow||i).focus(),setTimeout(r(function(){if(_.constants.browser.chrome&&window.opener){var t=r(function(){return"Покидая эту страницу, вы заблокируете родительское окно!\n"+'Пожалуйста, выберите "Остаться на этой странице" и используйте кнопку'+'"Отмена" перед закрытием вкладки.\n'});_.constants.$win.bind("beforeunload",t),i.printPage(),_.constants.$win.unbind("beforeunload",t)}else i.printPage();if(h)d.css("opacity",c).parents().addBack().each(function(){var t=$(this);if(t.data("display",t.css("display")),t.data("visibility",t.css("visibility")),t.css({display:t.data("display"),visibility:t.data("visibility")}),t.data("ws-hidden"))t.addClass("ws-hidden")});e.callback()}),0)}),100)}}return e},_createFrameId:function(){return this._iframeId||(this._iframeId=t("ws-htmlview-frame-"))},_getCurrIframeCtrl:function(){var t=$("#"+this._createFrameId());if(0!==t.length&&t.get(0).contentDocument&&t.get(0).contentWindow)return t;else return false},getIframeDocument:function(){if(this._iframe&&this._iframe.contentDocument)return this._iframe.contentDocument;else if(_.constants.browser.isIE)return window.frames[this._createFrameId()].document},getIframeWindow:function(){if(this._iframe&&this._iframe.contentWindow)return this._iframe.contentWindow;else if(_.constants.browser.isIE)return window.frames[this._createFrameId()]},getReadyDeferred:function(){return this._dReady},addStyle:function(r){if("template"===this._options.docType)throw new Error('Функцию $ws.proto.HTMLView.addStyle нельзя использовать при опции docType === "template"');var o=this,s=function(t){return l(t,o)};return this._iframeReady.addCallback(s(function(){var t=o.getIframeDocument().createElement("link"),e=new p,i=o.getIframeDocument();r="/"==r.substr(0,1)?a(r):a(_.constants.wsRoot+r),t.setAttribute("rel","stylesheet"),t.setAttribute("href",r),$(i).find("head").append(t);var n=$("<img />",{style:"position: absolute; visibility: hidden; left: 0; top: 0; display: block;"});return n.on("error",s(function(){n.remove(),e.callback()})).appendTo(i.body).prop("src",r),e}))},getIframe:function(){return this._iframe},getIframeContainer:function(){return this._iframeContainer},hideIframeContainer:function(){if(_.constants.browser.isIE)this._iframeContainer.css("opacity",0);else if(_.constants.browser.opera)this._iframeContainer.css("display","none");else this._iframeContainer.css("visibility","hidden")},showIframeContainer:function(){if(_.constants.browser.isIE)this._iframeContainer.css("opacity",1);else if(_.constants.browser.opera)this._iframeContainer.css("display","block");else this._iframeContainer.css("visibility","visible")},destroy:function(){if(this._iframe&&this._iframe.contentDocument)$(this._iframe.contentDocument).off("mouseup touchend",this._mouseUpHandler);w.superclass.destroy.apply(this,arguments)}});return w});