1ae266bd874ab509a4a6fb29a273ca369e00aeb414dc59c02de583a5d5f3e7e3

Source Code:

"use strict";!function(e){window.Traqli.registerWidget("_base",function(e,t,o){function i(e,t){r.StateMachine.create({target:this,events:this.StateMachineEvents,error:this.__stateMachineErrorHandler}),this.config=s.extend(!0,{},e,{email:t.email,visitor:t.visitor,tqid:t.tqid}),this.__$events=new o.EventEmitter,this.__$hooks={},e.iframe&&e.iframe.contentWindow&&(this.__iframe=e.iframe),this.init()}function n(e,t){return function(){return o.loge(this.__me()+" Override method "+o.stringify(e)),t.apply(this,arguments)}}var r=o.window,s=o.$(),a=s(o.window.document),_=s(o.window);return i.prototype.addHookHandler=function(e,t,o){o=parseInt(o),isNaN(o)&&(o=100),s.isArray(this.__$hooks[e])||(this.__$hooks[e]=[]),this.__$hooks[e].push({handler:t,priority:o}),this.__$hooks[e].sort(function(e,t){return t.priority-e.priority})},i.prototype.getMyName=function(){return"Widget"},i.prototype.isShown=function(){return this.isVisible()||this.is("widgetShown")},i.prototype.isVisible=function(){return o.isNodeVisible(this.__$form||this.__frame)},i.prototype.notify=function(e){o.logi(this.__me(),"notified, that data has been obtained:",e),this.__sendMessage("__notify",e)},i.prototype.on=function(e,t){this.__$events.on(e,t)},i.prototype.off=function(e,t){this.__$events.off(e,t)},i.prototype.StateMachineEvents=[{from:"none",name:"init",to:"initiated"},{from:"initiated",name:"formInitiated",to:"ready"},{from:"ready",name:"showOnDelay",to:"showAnimationInner"},{from:"ready",name:"showOnEvent",to:"showAnimationInner"},{from:"ready",name:"waitForMouseOut",to:"waitingForMouseOut"},{from:"ready",name:"waitForScroll",to:"waitingForScroll"},{from:"waitingForMouseOut",name:"showOnDelay",to:"showAnimationInner"},{from:"waitingForMouseOut",name:"showOnEvent",to:"showAnimationInner"},{from:"waitingForMouseOut",name:"mouseOut",to:"showAnimationInner"},{from:"waitingForMouseOut",name:"waitForScroll",to:"waitingForMouseOutOrScroll"},{from:"waitingForScroll",name:"showOnDelay",to:"showAnimationInner"},{from:"waitingForScroll",name:"showOnEvent",to:"showAnimationInner"},{from:"waitingForScroll",name:"scrolled",to:"showAnimationInner"},{from:"waitingForScroll",name:"waitForMouseOut",to:"waitingForMouseOutOrScroll"},{from:"waitingForMouseOutOrScroll",name:"showOnDelay",to:"showAnimationInner"},{from:"waitingForMouseOutOrScroll",name:"showOnEvent",to:"showAnimationInner"},{from:"waitingForMouseOutOrScroll",name:"scrolled",to:"showAnimationInner"},{from:"waitingForMouseOutOrScroll",name:"mouseOut",to:"showAnimationInner"},{from:"showAnimationInner",name:"formShown",to:"showAnimationOuter"},{from:"showAnimationOuter",name:"animationFinished",to:"widgetShown"},{from:"widgetShown",name:"submit",to:"showAfterSendAnimation"},{from:"widgetShown",name:"alreadySubscribed",to:"hideAnimationInner"},{from:"widgetShown",name:"close",to:"hideAnimationInner"},{from:"hideAnimationInner",name:"formHidden",to:"hideAnimationOuter"},{from:"hideAnimationOuter",name:"animationFinished",to:"widgetHidden"},{from:"showAfterSendAnimation",name:"afterSendShown",to:"waitActionAfterSend"},{from:"waitActionAfterSend",name:"close",to:"hideAnimationInner"},{from:"waitActionAfterSend",name:"showFormAgain",to:"showAnimationInnerOnly"},{from:"showAnimationInnerOnly",name:"formShown",to:"widgetShown"},{from:"widgetHidden",name:"waitForMouseOut",to:"waitingForMouseOut"}],i.prototype.StateMachinePassedEvents=["showOnEvent","showOnDelay","mouseOut","scrolled","close"],i.prototype.onenterstate=function(e,t,i){var n=Array.prototype.slice.call(arguments,3);if(o.log.apply(o,[this.__me(),"("+t+") -{"+e+"}-> ("+i+")"].concat(n)),"function"==typeof this["_"+e])try{this["_"+e].apply(this,n)}catch(o){throw new Error(this.error(e,t,i,n,r.StateMachine.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function: "+o))}else this.__defaultEventHandler.apply(this,[e].concat(n))},i.prototype._afterSendShown=function(e){var t=this;setTimeout(function(){if(o.shouldWidgetShowFormInsteadOfHide(t.config))return t.showFormAgain();t.close(e)},t.config.behavior.show_after_send_duration||0)},i.prototype._animationFinished=function(){this.is("widgetHidden")&&this.__unlocker&&(this.__unlocker(),delete this.__unlocker)},i.prototype._alreadySubscribed=function(e){this.__innerCloseReason=o.ALREADY_SUBSCRIBED,e.reason=o.ALREADY_SUBSCRIBED,this.__trackEvent("w_closed",{reason:"already_subscribed"}),this._close(e)},i.prototype._close=function(e){var t=this.__innerCloseReason;if(this.__innerCloseReason=this.__innerCloseReason||o.CLOSE_BUTTON_CLICK,this.__innerCloseReason===o.CLOSE_BUTTON_CLICK&&this.__trackEvent("w_closed",{reason:e&&e.reason}),this.__$events.emit("close",{reason:this.__innerCloseReason}),this.__sendMessage("hideForm"),!t&&this.__innerCloseReason===o.CLOSE_BUTTON_CLICK){var i=this.config.behavior;this.__canDisplayOnOutAfterClose()&&i.display_on_out_after_close&&this.__initMouseOutTrigger(i.display_on_out_after_close_timeout)}},i.prototype._formHidden=function(){this.__closeForm({duration:this.config.behavior.hide_animation_duration,type:this.config.behavior.hide_animation_type})},i.prototype._formInitiated=function(){this.__$events.emit("ready"),this.__initShowTriggers()},i.prototype._formShown=function(e){if(!e||!e.afterSubmitShowRequest){var t=this;t.__ensureWidgetShouldBeShown().then(function(o){if(o)return t.__openForm(e).then(function(){t.__trackEvent("w_shown",e),t.__initVisibilityTracker(e)})}).error(function(e){o.loge(t.__me()+"::"+t.config.id+" formShown handling failed because of:",e)})}},i.prototype._hideForm=function(){this.__sendMessage("hideForm",{duration:this.config.behavior.hide_animation_duration,type:this.config.behavior.hide_animation_type})},i.prototype._init=function(){var e=this;return o.try(function(){return!1===e.__prepareConfig()?o.reject("Wrong config"):e.__loadForm().then(function(t){return t?(e.__addMessageReceiver(),e.__initForm(),!0):o.reject("Form has not been loaded")})}).then(function(){return o.logi(e.__me()+"::"+e.config.id+" initialization is succeed"),!0}).error(function(t){return o.loge(e.__me()+"::"+e.config.id+" initialization is failed because of:",t),!1})},i.prototype._mouseOut=function(){this.__showInnerForm({reason:"mouse_out"})},i.prototype._scrolled=function(){this.__showInnerForm({reason:"scrolled"})},i.prototype._showFormAgain=function(){this.__showInnerForm({reason:"after_submit",afterSubmitShowRequest:!0})},i.prototype._showOnDelay=function(){this.__showInnerForm({reason:"after_delay"})},i.prototype._showOnEvent=function(){this.__showInnerForm({reason:"after_event"})},i.prototype._submit=function(e){this.__innerCloseReason=o.SUBSCRIBED,e||(e={}),e.reason=o.SUBSCRIBED,this.__trackEvent("w_closed",{reason:"subscribed"}),this.__$events.emit("submit",e),this.__sendMessage("showAfterSend",{duration:this.config.behavior.show_after_send_animation_duration,reason:"subscribed"})},i.prototype._waitForMouseOut=function(){this.__startMouseOutTrigger()},i.prototype._waitForScroll=function(e,t){this.__startScrollTrigger(e,t)},i.prototype.__addMessageReceiver=function(){var e=this;if(e.__iframe&&e.__iframe.contentWindow){var t=e.__iframe.contentWindow;_.on("message.tq_wgt",function(i){var n=i&&i.originalEvent;if(n&&n.source&&n.source===t){var r=n.data;try{if(0!==r.indexOf(o.NAMESPACE))return;r=o.parse(r.substr(o.NAMESPACE.length)),e.__handleMessage(r.type,r.value)}catch(t){o.loge(e.__me()+"::__addMessageReceiver",t,r)}}})}else o.loge(e.__me()+"::__addMessageReceiver called w/o target (widget) iframe")},i.prototype.__attachIframeResizer=function(){if(!this.config.view.iframe_resizer_is_needed||this.__iframeResizerAttached)return!0;var e=this.__iframe;try{var t=this.__getIframeResizerArgs();return r.iFrameResize?r.iFrameResize(t,e):s.fn&&s.fn.iFrameResize?s(e).iFrameResize(t):void 0!==r.jQuery&&r.jQuery.fn&&r.jQuery.fn.iFrameResize?r.jQuery(e).iFrameResize(t):void 0!==r.$&&r.$.fn&&r.$.fn.iFrameResize&&r.$(e).iFrameResize(t),this.__iframeResizerAttached=!0,!0}catch(e){return o.loge(this.__me()+"::__attachIframeResizer failed with",e),!1}},i.prototype.__canDisplayOnOutAfterClose=function(){return!0},i.prototype.__closeForm=function(e){var t=this;return o.promise(function(o){return t.__runOuterHideAnimation(e,function(){setTimeout(function(){t.animationFinished(),o(!0)},0)})})},i.prototype.__defaultEventHandler=function(e){var t=Array.prototype.slice.call(arguments,1);o.logw(this.__me()+"::__defaultEventHandler - caught unexpected event: ("+e+") "+o.stringify(t)+'; you should add "_'+e+'" method to your widget or handle it in "__defaultEventHandler" method')},i.prototype.__ensureWidgetShouldBeShown=function(){var e=this;return e.__handleLocksPromise().then(function(){return e.__runHook("checkShowStatus",{show:!0})}).then(function(t){return!!t.show||(o.logw(e.__me()+"::__ensureWidgetShouldBeShown stopped with",t),!1)})},i.prototype.__genFormUrl=function(){return o.API_HOST+"/publisher/unattended/"+this.config.id+"?wv="+this.config.version},i.prototype.__getFormPlacement=n("__getFormPlacement",function(){return null}),i.prototype.__getFormStyles=n("__getFormStyles",function(){return null}),i.prototype.__getIframeResizerArgs=function(){return{}},i.prototype.__getIosStyles=function(){return{height:"100%","-webkit-overflow-scrolling":"touch"}},i.prototype.__getScrollHandler=function(){return a},i.prototype.__handleLocksPromise=function(){var e=this;return o.try(function(){var t=e.config.id,i=e.config.type;if(e.config.behavior.can_be_locked){if(o.isWidgetLocked([t,i],e.__unlocker))return o.logw(e.__me()+" is locked, waiting for unlocking..."),o.waitForWidgetUnlockPromise(t,i).then(function(){return o.logw(e.__me()+" is unlocked, try to show"),e.__handleLocksPromise()},function(t){o.loge(e.__me()+".__handleLocksPromise [waitForWidgetUnlockPromise] failed with",t)})}else o.logw(e.__me()+" can't be locked");if(e.__unlocker)return e.is("showAnimationOuter")||o.loge(e.__me()+".__handleLocksPromise called with unlocker in wrong state: actual -",e.current,"expected - showAnimationOuter"),!0;var n,r,s,a=[];if(e.config.behavior.locks_other_by_id_str){var _=String(e.config.behavior.locks_other_by_id_str).split(/, */g);for(n=0,r=_.length,s;n<r;n++)s=parseInt(_[n]),isNaN(s)||a.push(s)}if(e.config.behavior.locks_other_by_type_str){var u=String(e.config.behavior.locks_other_by_type_str).split(/, */g);for(n=0,r=u.length;n<r;n++)u[n]&&a.push(u[n])}a.length&&(o.logw(e.__me()+" locked other",a),e.__unlocker=o.setWidgetLocks(a))}).catch(function(t){o.loge(e.__me()+".__handleLocksPromise failed with",t)})},i.prototype.__handleMessage=function(e,t){o.log(this.__me(),">>>",e,t),"function"==typeof this[e]?this[e](t):o.loge(this.__me()+"::__handleMessage - caught unexpected message: ("+e+") "+o.stringify(t)+'; you should add "'+e+'" transition to your state machine')},i.prototype.__initDelayTrigger=function(e){var t=this;e=Number(e),isNaN(e)||setTimeout(function(){t.showOnDelay()},e)},i.prototype.__initForm=function(){this.__sendMessage("initForm",{config:this.config})},i.prototype.__initMouseOutTrigger=function(e){var t=this;e=Number(e),isNaN(e)||setTimeout(function(){t.waitForMouseOut()},e)},i.prototype.__initScrollTrigger=function(e,t,o){var i=this;e=Number(e),isNaN(e)||(t=Number(t),isNaN(t)||(o=Number(o),isNaN(o)||setTimeout(function(){i.waitForScroll(o,t)},e)))},i.prototype.__initShowTriggers=function(){var e=this.config.behavior;e.display_on_delay&&this.__initDelayTrigger(e.display_on_delay_timeout),e.display_on_out&&this.__initMouseOutTrigger(e.display_on_out_timeout),e.display_on_scroll&&this.__initScrollTrigger(e.display_on_scroll_timeout,e.display_on_scroll_interval,e.display_on_scroll_offset)},i.prototype.__initVisibilityTracker=function(e){var t=this;t.__visibilityTracker&&clearInterval(t.__visibilityTracker);var i=t.__iframe;if(e=s.extend(!0,{},e),o.isNodeVisible(i))return e.display_time=0,void t.__trackEvent("w_visible",e);var n=s.now();t.__visibilityTracker=setInterval(function(){o.isNodeVisible(i)&&(clearInterval(t.__visibilityTracker),delete t.__visibilityTracker,e.display_time=Math.floor((s.now()-n)/1e3),t.__trackEvent("w_visible",e))},500)},i.prototype.__loadForm=function(){var e=this;return o.try(function(){if(e.__iframe)return e.__$form=e.__$form||null,!0;var t=e.__getFormPlacement();if(!t||!t.length)return!1;var i=e.__getFormStyles();if(!i)return!1;var n=i.form||{};t.css(n);var r=i.iframe||{};return o.loadIframePromise(e.__genFormUrl(),r,t).then(function(o){return e.__iframe=o,e.__$form=t,!0})})},i.prototype.__me=function(){return["[",this.getMyName(),"](",this.config&&this.config.id||"?",")"].join("")},i.prototype.__openForm=function(e){var t=this;return o.promise(function(o){return t.__runOuterShowAnimation(e,function(){setTimeout(function(){t.animationFinished(),o(!0)},0)})})},i.prototype.__prepareConfig=function(){var e=this.config.behavior;e.display_on_delay=e.display_on_delay||!1,e.display_on_delay_timeout=e.display_on_delay_timeout||0,e.display_on_out=e.display_on_out||!1,e.display_on_out_after_close=e.display_on_out_after_close||!1,e.display_on_out_after_close_timeout=e.display_on_out_after_close_timeout||0,e.display_on_out_timeout=e.display_on_out_timeout||0,e.display_on_scroll=e.display_on_scroll||!1,e.display_on_scroll_interval=e.display_on_scroll_interval||0,e.display_on_scroll_offset=e.display_on_scroll_offset||0,e.display_on_scroll_timeout=e.display_on_scroll_timeout||0,e.hide_animation_duration=e.hide_animation_duration||0,e.show_after_send_animation_duration=e.show_after_send_animation_duration||0,e.show_after_send_duration=e.show_after_send_duration||0,e.show_form_animation_duration=e.show_form_animation_duration||0},i.prototype.__prepareStatEventData=function(e,t){switch(e){case"w_shown":case"w_closed":return{reason:t&&t.reason};case"w_visible":return{reason:t&&t.reason,display_time:t&&t.display_time};default:return{}}},i.prototype.__prepareStyleAttr=function(e,t){var o={},i=e&&e.replace(/\s/g,"").split(";");return i&&i.forEach(function(e){if(e){var i=e.split(":")[0],n=e.split(":")[1];i&&n&&i in t&&(o[i]=n)}}),o},i.prototype.__runHook=function(e,t){var i=this,n=i.__$hooks[e];if(!s.isArray(n)||!n.length)return o.resolve(t);n=s.map(n,function(e){return e.handler});var r=function(t){if(!n.length)return o.resolve(t);var s=n.shift();return o.try(s,t).error(function(n){return o.loge(i.__me(),"::__runHook ["+e+"] failed step with",n,"for handler",s,"with passed value",t),t}).then(r)};return r(t)},i.prototype.__runOuterHideAnimation=function(e,t){this.__$form.hide(),t()},i.prototype.__runOuterShowAnimation=function(e,t){if(!this.__attachIframeResizer())return o.reject(new Error("IframeResizer was not attached"));this.__$form.show(),t()},i.prototype.__setStylesForElement=function(e){var t=this,o=t.__getIosStyles(),i=t.__prepareStyleAttr(e.attr("style"),o);return e.css(o),function(){for(var t in o)o.hasOwnProperty(t)&&e.css(t,i[t]||"")}},i.prototype.__sendMessage=function(e,t){return this.__iframe?(o.log(this.__me(),"<<<",e,t),o.sendMessageToIframe(this.__iframe,e,t)):(o.loge(this.__me()+"::__sendMessage called w/o target (widget) iframe"),!1)},i.prototype.__trackEvent=function(e,t){o.sendStatEventPromise(e,this.config.id,this.__prepareStatEventData(e,t))},i.prototype.__showInnerForm=function(e){var t=this;if(s.isPlainObject(e)||(e={}),e.duration=t.config.behavior.show_form_animation_duration,e.type=t.config.behavior.show_form_animation_type,e&&e.afterSubmitShowRequest)return t.__sendMessage("showForm",e);t.__ensureWidgetShouldBeShown().then(function(o){if(o)return t.__runHook("preShowInnerForm").then(function(){t.__sendMessage("showForm",e)})})},i.prototype.__startMouseOutTrigger=function(){var e=this;a.on("mouseleave.tq_wgt",o.throttle(1e3,function(){a.off("mouseleave.tq_wgt"),e.mouseOut()}))},i.prototype.__startScrollTrigger=function(e,t){var o=this,i=o.__getScrollHandler(),n=function(){i.scrollTop()>e&&(clearInterval(r),o.scrolled())},r=setInterval(n,t);n()},i.prototype.__stateMachineErrorHandler=function(e,t,i,n,r,s){if(!(this.StateMachinePassedEvents.indexOf(e)>=0))return o.loge(this.__me()+":: StateMachine error:",e,"|",t,"|",i,"|",n,"|",r,"|",s),s},i})}();