/
widget.min.js
23 lines (23 loc) · 12.3 KB
/
widget.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if(!urturn)var urturn=function(r){var k={},s={post:{name:"posts",selectors:{id:"id",username:"username",expression:"expression_name",query:"q"}},expression:{name:"expressions",selectors:{id:"id",username:"username",expression:"expression_name",query:"q"}}};k.get=function(a,b,g){4<=arguments.length?(a={queryType:arguments[0],querySelector:arguments[1],query:arguments[2]},"number"===typeof arguments[3]?(a.id=arguments[3],b=arguments[4],g=arguments[5]):(b=arguments[3],g=arguments[4])):"string"===typeof a&&
(a={query:a,queryType:"post",querySelector:"query"});a.id||(a.id=0);if(t(a))return!0;var e=c.get(a);a.page&&e.setPage(a.page);a.perPage&&e.setPageSize(a.perPage);e.next(b,g);return!1};k.getHost=function(){return"staging-ut.urturn.com"};var t=function(a,c,g){return a.query?a.queryType?a.querySelector?"string"!==typeof a.query?(g(b("get","WRONG_FORMAT",{key:"options.query",type:typeof a.query})),!0):"string"!==typeof a.queryType?(g(b("get","WRONG_FORMAT",{key:"options.queryType",type:typeof a.queryType})),
!0):"string"!==typeof a.querySelector?(g(b("get","WRONG_FORMAT",{key:"options.querySelector",type:typeof a.querySelector})),!0):a.page&&"number"!==typeof a.page?(g(b("get","WRONG_FORMAT",{key:"options.page",type:typeof a.page})),!0):a.perPage&&"number"!==typeof a.perPage?(g(b("get","WRONG_FORMAT",{key:"options.perPage",type:typeof a.perPage})),!0):!1:(g(b("get","MISSING_QUERY_SELECTOR",{})),!0):(g(b("get","MISSING_QUERY_TYPE",{})),!0):(g(b("get","MISSING_QUERY",{})),!0)},l=function(a){this.query=
a.query;this.queryType=a.queryType;this.querySelector=a.querySelector;this.page=1;this.perPages=200;this.next=function(a,c){var e="http://staging-ut.urturn.com/api/"+s[this.queryType].name+".json?",e=e+(s[this.queryType].selectors[this.querySelector]+"="+encodeURIComponent(this.query)),e=e+("&page="+this.page++),e=e+("&per_page="+this.perPages);(e=d(e,a,c))&&c(b("get",e,{}))};this.setPage=function(a){a|0&&(this.page=a|0)};this.setPageSize=function(a){this.perPages=a}},d=function(a,c,g){var e=!1;if(r.XMLHttpRequest)e=
new XMLHttpRequest;else if(r.ActiveXObject)try{e=new r.ActiveXObject("Msxml2.XMLHTTP")}catch(d){try{e=new r.ActiveXObject("Microsoft.XMLHTTP")}catch(h){return"XHR_IE_FAIL"}}else return"NO_XHR";e.open("GET",a,!0);e.onreadystatechange=function(a){if(4!=e.readyState)return!1;a=JSON.parse(e.responseText);c(a)};e.ontimeout=function(a){g(b("get","XHR_TIMEOUT",{}))};e.onerror=function(a){g(b("get","XHR_ERROR",{}))};e.send(null)},c=new function(){this._queryHistory={};this.get=function(a){var b=a.id+"::"+
a.queryType+"::"+a.querySelector+"::"+a.query;if(this._queryHistory[b])return this._queryHistory[b];a=new l(a);return this._queryHistory[b]=a}},b=function(a,b,c){var e={};e.apiMethod="urturn."+a;e.message="An unknow Error happen!";e.code=b;a={MISSING_QUERY:"No query in options hash. We do not know what to search.",MISSING_QUERY_TYPE:"No queryType in options hash. We do not know what to search.",MISSING_QUERY_SELECTOR:"No querySelector in options hash. We do not know what to search.",WRONG_FORMAT:"{key} should be a String, was a {type} instead!",
NO_XHR:"Can not instanciate XMLHttpRequest Object.",XHR_ERROR:"There was an error on urturn server.",XHR_TIMEOUT:"Request to urturn server Timeout.",XHR_IE_FAIL:"No ActiveXObject for XMLHTTP. (ActiveX not activated?)"};if(a[b]){e.message=a[b];for(var d in c)e.message.replace("{"+d+"}",c.key)}return e};"object"!==typeof JSON&&(JSON={});(function(){function a(a){return 10>a?"0"+a:a}function b(a){d.lastIndex=0;return d.test(a)?'"'+a.replace(d,function(a){var b=l[a];return"string"===typeof b?b:"\\u"+
("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function c(a,e){var d,q,n,l,u=h,m,f=e[a];f&&"object"===typeof f&&"function"===typeof f.toJSON&&(f=f.toJSON(a));"function"===typeof p&&(f=p.call(e,a,f));switch(typeof f){case "string":return b(f);case "number":return isFinite(f)?String(f):"null";case "boolean":case "null":return String(f);case "object":if(!f)return"null";h+=k;m=[];if("[object Array]"===Object.prototype.toString.apply(f)){l=f.length;for(d=0;d<l;d+=1)m[d]=c(d,f)||"null";
n=0===m.length?"[]":h?"[\n"+h+m.join(",\n"+h)+"\n"+u+"]":"["+m.join(",")+"]";h=u;return n}if(p&&"object"===typeof p)for(l=p.length,d=0;d<l;d+=1)"string"===typeof p[d]&&(q=p[d],(n=c(q,f))&&m.push(b(q)+(h?": ":":")+n));else for(q in f)Object.prototype.hasOwnProperty.call(f,q)&&(n=c(q,f))&&m.push(b(q)+(h?": ":":")+n);n=0===m.length?"{}":h?"{\n"+h+m.join(",\n"+h)+"\n"+u+"}":"{"+m.join(",")+"}";h=u;return n}}"function"!==typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?
this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var e=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,d=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
h,k,l={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},p;"function"!==typeof JSON.stringify&&(JSON.stringify=function(a,b,e){var d;k=h="";if("number"===typeof e)for(d=0;d<e;d+=1)k+=" ";else"string"===typeof e&&(k=e);if((p=b)&&"function"!==typeof b&&("object"!==typeof b||"number"!==typeof b.length))throw Error("JSON.stringify");return c("",{"":a})});"function"!==typeof JSON.parse&&(JSON.parse=function(a,b){function c(a,d){var e,g,f=a[d];if(f&&"object"===typeof f)for(e in f)Object.prototype.hasOwnProperty.call(f,
e)&&(g=c(f,e),void 0!==g?f[e]=g:delete f[e]);return b.call(a,d,f)}var d;a=String(a);e.lastIndex=0;e.test(a)&&(a=a.replace(e,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)}));if(/^[\],:{}\s]*$/.test(a.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return d=eval("("+a+")"),"function"===typeof b?c({"":d},""):d;throw new SyntaxError("JSON.parse");})})();return k}(window);
(function(r,k){function s(d){this.rootElement=d;this.expressionName=d.getAttribute("data-expression");this.width=d.getAttribute("data-width");this.height=d.getAttribute("data-height");this.showAvatar=d.getAttribute("data-avatar");this.showAvatar="show"===this.showAvatar?!0:!1;this.urturn=this.cta=this.avatar=this.theater=this.header=null;this.urturnInHeader=!1;this.avatarBG="#eae9e8";this.headerBG="#faf9f7";this.theaterBG="#efefef";this.widgetId=1E8*Math.random()|0;this.numberOfColumns=2;this.columnMinWidth=
150;this.columns=[];this.columnsSize=[];this.init=function(){if(l){var c=this;urturn.get("post","expression",this.expressionName,this.widgetId,function(b){c.postLoaded(b)})}else urturn.get("post","expression",this.expressionName,this.widgetId,this.postLoaded.bind(this));this.initUI()};this.initUI=function(){this.adaptSize();this.header=this.createElement("div",{width:"100%",height:"75px",backgroundColor:this.headerBG});this.rootElement.appendChild(this.header);this.theater=this.createElement("div",
{width:"100%",height:this.height-75+40+"px",backgroundColor:this.theaterBG,overflow:"scroll"});this.rootElement.appendChild(this.theater);this.avatar=this.createElement("div",{width:"75px",height:"75px",overflow:"hidden",backgroundColor:this.headerBG,"float":"left"});this.header.appendChild(this.avatar);this.cta=this.createElement("div",{width:this.width-75+"px",height:"75px","float":"left",color:"#000"});this.header.appendChild(this.cta);this.urturn=this.urturnInHeader?this.createElement("img",{width:"100px",
height:"50px",position:"relative",bottom:this.height+50-22+"px",left:this.width-100-15+"px",display:"block",cursor:"pointer"}):this.createElement("img",{width:"134px",height:"60px",position:"relative",bottom:"110px",left:"50%",marginLeft:"-67px",display:"block",cursor:"hand"});if(l){var c=this;this.urturn.attachEvent("onclick",function(b){c.clickUrturn(b)})}else this.urturn.addEventListener("click",this.clickUrturn.bind(this));this.urturn.src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIYAAAA8CAMAAACU9jKwAAAAjVBMVEXXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUfXXUf7+PjosKn48O/km5HhkIT039zXXUfy1tLmpp3aa1jrurP26ObfhHbceGjvzcjtxL7mJsVCAAAAH3RSTlMABoms2wNb+d/gVVSr5Fzjivqm81FWUvLZB9eTlFP4ggbpVAAAAYNJREFUeF7t2dluwjAQBdAJENYuQPd1vGeD/v/n1djqkEJfIBRbre9DPBLK1ZGIrCgGl+xuOR7ps+fmeTnNgHI70MEyuAefvKeDppc7BimCOcBmpoNnBpBdh2dcZjDUEeQKLmJg9GESA2MC7zEwRqCjSGLYJEZiJAYzzekYgh2rQOTU0JmBKI9jFJZBDUEY9KeEZVD+FqNCH2VngZW90lqZktWI68bPQtlZ7NwsWg1dGGv04e7JN/ZKq7X5n1bbGb85DLJWQxdGKSUik3L1EwOVkIVB6ea6kAVHvseghhM9G/sMVXorzZbc7DKo4dcYrEUtiHx2hmxTgzIS4yMQQ3wxeGmXhh/OEN0ZCpUsaqN14zYKxvEwBjV0YxS4idnu7OogBjV0ZGhWI69KNynEtZS80jaK08boZlopFYp2w/96F02MxEiMxEiMxHiI4/PsYwyMSSSf7iM5yIjjWOcJYBqeMQWbeWjFHDbJX8IqXnPweQt5HDwDSjbsjxfnJyzG/WHmAJ/OfnVrBRgv5QAAAABJRU5ErkJggg==";
this.rootElement.appendChild(this.urturn);this.calculateColumns()};this.calculateColumns=function(){var c=this.width/this.columnMinWidth|0;2>c&&(c=2);this.numberOfColumns=c};this.clickUrturn=function(){r.location="http://"+urturn.getHost()+"/"+this.expressionName+"?#!/documents/new"};this.adaptSize=function(){this.style(this.rootElement,{padding:"0px",overflow:"hidden"});this.width?this.rootElement.style.width=this.width:(this.rootElement.style.width="100%",this.width=this.rootElement.offsetWidth);
this.height?this.rootElement.style.height=this.height:(this.rootElement.style.height="100%",this.height=this.rootElement.offsetHeight);this.height|=0;this.width|=0;500<=this.width&&(this.urturnInHeader=!0)};this.clear=function(c){this.style(c,{margin:"0px",padding:"0px"})};this.style=function(c,b){for(var a in b)"float"==a?(c.style[a]=b[a],l||c.style.setProperty("float",b[a])):c.style[a]=b[a]};this.createElement=function(c,b){var a=k.createElement(c);this.clear(a);b&&this.style(a,b);return a};this.postLoaded=
function(c){this.adaptSize();this.setCTA(c.expression.description,c.expression.creator.username);this.addPost(c.posts)};this.setCreatorAvatar=function(c){var b=this.createElement("img",{width:"71px",height:"71px",margin:"2px"});b.src=c;this.avatar.appendChild(b)};this.setCTA=function(c,b){var a=this.createElement("div",{color:"#000",font:"20px Helvetica",position:"relative",top:0,left:-65,width:this.width-95});a.innerHTML=c+'<br/> <span style="font-size :15px; color : #888">by '+b+"</span>";this.cta.appendChild(a);
this.style(a,{top:(75-a.offsetHeight)/2|0})};this.createPost=function(c){if(this.showAvatar){var b=this.createElement("div",{width:"100%",height:c.thumbnails.thumb_height*this.columnWidthRatio|0,overflow:"hidden"}),a=this.createElement("img",{width:"100%"});a.src=c.thumbnails.small;b.appendChild(a);a=this.createElement("img",{width:"20px",height:"20px",borderRadius:"50%",border:"2px solid #efefef",position:"relative",bottom:"30px",left:"10px"});a.src=c.creator.avatar_thumb_url;b.appendChild(a);return b}b=
this.createElement("img",{width:"100%"});b.src=c.thumbnails.small;return b};this.createColumns=function(){var c=0;for(this.columnWidth=(1E4/this.numberOfColumns|0)/100;c<this.numberOfColumns;){var b=this.createElement("div",{width:this.columnWidth+"%","float":"left"});l&&this.style(b,{width:(this.columnWidth*(this.width-17)/100|0)+"px"});this.columns.push(b);this.columnsSize.push(0);this.theater.appendChild(b);this.columnWidthPx||(this.columnWidthPx=b.offsetWidth,this.columnWidthRatio=b.offsetWidth/
290);++c}};this.pushToColumn=function(c,b){for(var a=0,d=this.columnsSize[0],g=1;g<this.columns.length;){var e=this.columnsSize[g];d>e&&(a=g,d=e);++g}this.columns[a].appendChild(c);this.columnsSize[a]=b.thumbnails.thumb_height?this.columnsSize[a]+b.thumbnails.thumb_height:this.columnsSize[a]+291};this.addPost=function(c){6>c.length?this.numberOfColumns=1:this.createColumns();for(var b=0;b<c.length;){var a=this.createPost(c[b]);1==this.numberOfColumns?this.theater.appendChild(a):this.pushToColumn(a,
c[b]);++b}};this.init()}function t(){if("complete"!==k.readyState)setTimeout(t,20);else{var d;if(l){d=k.getElementsByTagName("div");for(var c=[],b=0;b<d.length;)"urturn-expression-widget"===d[b].getAttribute("name")&&c.push(d[b]),++b;d=c}else d=k.getElementsByName("urturn-expression-widget");for(c=0;c<d.length;)d[c].getAttribute("loaded")||(d[c].setAttribute("loaded",!0),new s(d[c])),++c}}var l=IE="\v"=="v";t()})(window,document);