mirror of
https://github.com/Mibew/design.git
synced 2025-04-03 11:27:11 +03:00
18 lines
4.6 KiB
JavaScript
18 lines
4.6 KiB
JavaScript
/*
|
|
Copyright 2005-2013 the original author or authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License").
|
|
You may obtain a copy of the License at
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
*/
|
|
var Mibew={};
|
|
(function(a){a.Objects={};a.Widget=function(b){this.requestedScripts={};this.handlers=[];this.handlersDependences={};this.requestURL=b.requestURL;this.requestTimeout=b.requestTimeout;this.visitorCookieName=b.visitorCookieName;this.inviteStyle=b.inviteStyle;this.locale=b.locale;this.dataToSend={};var c=document.createElement("link");c.setAttribute("rel","stylesheet");c.setAttribute("type","text/css");c.setAttribute("href",b.inviteStyle);document.getElementsByTagName("head")[0].appendChild(c)};a.Widget.prototype.makeRequest=
|
|
function(){var b=a.Utils.readCookie(this.visitorCookieName);this.dataToSend.entry=escape(document.referrer);this.dataToSend.locale=this.locale;this.dataToSend.rnd=Math.random();!1!==b?this.dataToSend.user_id=b:this.dataToSend.user_id&&delete this.dataToSend.user_id;this.doLoadScript(this.requestURL+"?"+this.getQuery(),"responseScript");this.dataToSend={}};a.Widget.prototype.getQuery=function(){var b=[],c;for(c in this.dataToSend)this.dataToSend.hasOwnProperty(c)&&b.push(c+"="+this.dataToSend[c]);
|
|
return b.join("&")};a.Widget.prototype.sendToServer=function(b){for(var c in b)if(b.hasOwnProperty(c)){var a=b[c];"string"!==typeof a&&"number"!==typeof a||("string"===typeof a&&(a=encodeURIComponent(a)),this.dataToSend[c]=a)}};a.Widget.prototype.onResponse=function(b){var c=b.load,d=b.handlers,e=b.data;b=b.dependences;var j=this,f;for(f in c)c.hasOwnProperty(f)&&!(f in this.requestedScripts)&&(this.requestedScripts[f]={},this.requestedScripts[f].url=c[f],this.requestedScripts[f].status="loading",
|
|
this.loadScript(f));for(var h in b)b.hasOwnProperty(h)&&(h in this.handlersDependences||(this.handlersDependences[h]=b[h]));for(c=0;c<d.length;c++){var g=d[c];if(this.canRunHandler(g))a.APIFunctions[g](e);else g in this.handlers||(this.handlers[g]=function(){a.APIFunctions[g](e)})}this.cleanUpAfterRequest();window.setTimeout(function(){j.makeRequest()},this.requestTimeout)};a.Widget.prototype.cleanUpAfterRequest=function(){document.getElementsByTagName("head")[0].removeChild(document.getElementById("responseScript"))};
|
|
a.Widget.prototype.loadScript=function(b){var c=this,a=this.doLoadScript(this.requestedScripts[b].url,b);a.onload=function(){c.scriptReady(b)};a.onreadystatechange=function(){("complete"==this.readyState||"loaded"==this.readyState)&&c.scriptReady(b)}};a.Widget.prototype.doLoadScript=function(b,c){var a=document.createElement("script");a.setAttribute("type","text/javascript");a.setAttribute("src",b);a.setAttribute("id",c);document.getElementsByTagName("head")[0].appendChild(a);return a};a.Widget.prototype.scriptReady=
|
|
function(b){this.requestedScripts[b].status="ready";for(var a in this.handlers)this.handlers.hasOwnProperty(a)&&this.canRunHandler(a)&&(this.handlers[a](),delete this.handlers[a])};a.Widget.prototype.canRunHandler=function(b){b=this.handlersDependences[b];for(var a=0;a<b.length;a++)if("ready"!=this.requestedScripts[b[a]].status)return!1;return!0};a.Widget.init=function(b){a.Objects.widget=new a.Widget(b);a.Objects.widget.makeRequest()};a.Utils={};a.Utils.createCookie=function(b,a){var d=/([^\.]+\.[^\.]+)$/.exec(document.location.hostname)[1];
|
|
document.cookie=""+b+"="+a+"; path=/; "+(d?"domain="+d+";":"")};a.Utils.readCookie=function(b){var a=document.cookie.split("; ");b+="=";for(var d=!1,e=0;e<a.length;e++)if(-1!=a[e].indexOf(b)){d=a[e].substr(b.length);break}return d};a.APIFunctions={};a.APIFunctions.updateUserId=function(b){a.Utils.createCookie(a.Objects.widget.visitorCookieName,b.user.id)};a.APIFunctions.inviteOnResponse=function(b){var a=b.invitation.message,d=b.invitation.operator,e=b.invitation.avatar;b='<div id="mibewinvitationpopup"><div id="mibewinvitationclose"><a href="javascript:void(0);" onclick="Mibew.Invitation.reject();">×</a></div>';
|
|
d&&(b+='<h1 onclick="Mibew.Invitation.accept();">'+d+"</h1>");e&&(b+='<img id="mibewinvitationavatar" src="'+e+'" title="'+d+'" alt="'+d+'" onclick="Mibew.Invitation.accept();" />');b=b+('<p onclick="Mibew.Invitation.accept();">'+a+"</p>")+'<div style="clear: both;"></div></div>';if(a=document.getElementById("mibewinvitation"))a.innerHTML=b};a.Invitation={};a.Invitation.hide=function(){var a=document.getElementById("mibewinvitationpopup");a&&(a.style.display="none")};a.Invitation.accept=function(){document.getElementById("mibewAgentButton")&&
|
|
(document.getElementById("mibewAgentButton").onclick(),a.Invitation.hide())};a.Invitation.reject=function(){a.Objects.widget.sendToServer({invitation_rejected:1});a.Invitation.hide()}})(Mibew);
|