this.containment[2]&&(o=this.containment[2]+this.offset.click.left),e.pageY-this.offset.click.top>this.containment[3]&&(a=this.containment[3]+this.offset.click.top)),n.grid&&(i=this.originalPageY+Math.round((a-this.originalPageY)/n.grid[1])*n.grid[1],a=this.containment?i-this.offset.click.top>=this.containment[1]&&i-this.offset.click.top<=this.containment[3]?i:i-this.offset.click.top>=this.containment[1]?i-n.grid[1]:i+n.grid[1]:i,s=this.originalPageX+Math.round((o-this.originalPageX)/n.grid[0])*n.grid[0],o=this.containment?s-this.offset.click.left>=this.containment[0]&&s-this.offset.click.left<=this.containment[2]?s:s-this.offset.click.left>=this.containment[0]?s-n.grid[0]:s+n.grid[0]:s)),{top:a-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+("fixed"===this.cssPosition?-this.scrollParent.scrollTop():l?0:r.scrollTop()),left:o-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+("fixed"===this.cssPosition?-this.scrollParent.scrollLeft():l?0:r.scrollLeft())}},_rearrange:function(t,e,i,s){i?i[0].appendChild(this.placeholder[0]):e.item[0].parentNode.insertBefore(this.placeholder[0],"down"===this.direction?e.item[0]:e.item[0].nextSibling),this.counter=this.counter?++this.counter:1;var n=this.counter;this._delay(function(){n===this.counter&&this.refreshPositions(!s)})},_clear:function(t,e){function i(t,e,i){return function(s){i._trigger(t,s,e._uiHash(e))}}this.reverting=!1;var s,n=[];if(!this._noFinalSort&&this.currentItem.parent().length&&this.placeholder.before(this.currentItem),this._noFinalSort=null,this.helper[0]===this.currentItem[0]){for(s in this._storedCSS)("auto"===this._storedCSS[s]||"static"===this._storedCSS[s])&&(this._storedCSS[s]="");this.currentItem.css(this._storedCSS).removeClass("ui-sortable-helper")}else this.currentItem.show();for(this.fromOutside&&!e&&n.push(function(t){this._trigger("receive",t,this._uiHash(this.fromOutside))}),!this.fromOutside&&this.domPosition.prev===this.currentItem.prev().not(".ui-sortable-helper")[0]&&this.domPosition.parent===this.currentItem.parent()[0]||e||n.push(function(t){this._trigger("update",t,this._uiHash())}),this!==this.currentContainer&&(e||(n.push(function(t){this._trigger("remove",t,this._uiHash())}),n.push(function(t){return function(e){t._trigger("receive",e,this._uiHash(this))}}.call(this,this.currentContainer)),n.push(function(t){return function(e){t._trigger("update",e,this._uiHash(this))}}.call(this,this.currentContainer)))),s=this.containers.length-1;s>=0;s--)e||n.push(i("deactivate",this,this.containers[s])),this.containers[s].containerCache.over&&(n.push(i("out",this,this.containers[s])),this.containers[s].containerCache.over=0);if(this.storedCursor&&(this.document.find("body").css("cursor",this.storedCursor),this.storedStylesheet.remove()),this._storedOpacity&&this.helper.css("opacity",this._storedOpacity),this._storedZIndex&&this.helper.css("zIndex","auto"===this._storedZIndex?"":this._storedZIndex),this.dragging=!1,e||this._trigger("beforeStop",t,this._uiHash()),this.placeholder[0].parentNode.removeChild(this.placeholder[0]),this.cancelHelperRemoval||(this.helper[0]!==this.currentItem[0]&&this.helper.remove(),this.helper=null),!e){for(s=0;n.length>s;s++)n[s].call(this,t);this._trigger("stop",t,this._uiHash())}return this.fromOutside=!1,!this.cancelHelperRemoval},_trigger:function(){t.Widget.prototype._trigger.apply(this,arguments)===!1&&this.cancel()},_uiHash:function(e){var i=e||this;return{helper:i.helper,placeholder:i.placeholder||t([]),position:i.position,originalPosition:i.originalPosition,offset:i.positionAbs,item:i.currentItem,sender:e?e.element:null}}}),t.widget("ui.slider",t.ui.mouse,{version:"1.11.4",widgetEventPrefix:"slide",options:{animate:!1,distance:0,max:100,min:0,orientation:"horizontal",range:!1,step:1,value:0,values:null,change:null,slide:null,start:null,stop:null},numPages:5,_create:function(){this._keySliding=!1,this._mouseSliding=!1,this._animateOff=!0,this._handleIndex=null,this._detectOrientation(),this._mouseInit(),this._calculateNewMax(),this.element.addClass("ui-slider ui-slider-"+this.orientation+" ui-widget"+" ui-widget-content"+" ui-corner-all"),this._refresh(),this._setOption("disabled",this.options.disabled),this._animateOff=!1},_refresh:function(){this._createRange(),this._createHandles(),this._setupEvents(),this._refreshValue()},_createHandles:function(){var e,i,s=this.options,n=this.element.find(".ui-slider-handle").addClass("ui-state-default ui-corner-all"),o="",a=[];for(i=s.values&&s.values.length||1,n.length>i&&(n.slice(i).remove(),n=n.slice(0,i)),e=n.length;i>e;e++)a.push(o);this.handles=n.add(t(a.join("")).appendTo(this.element)),this.handle=this.handles.eq(0),this.handles.each(function(e){t(this).data("ui-slider-handle-index",e)})},_createRange:function(){var e=this.options,i="";e.range?(e.range===!0&&(e.values?e.values.length&&2!==e.values.length?e.values=[e.values[0],e.values[0]]:t.isArray(e.values)&&(e.values=e.values.slice(0)):e.values=[this._valueMin(),this._valueMin()]),this.range&&this.range.length?this.range.removeClass("ui-slider-range-min ui-slider-range-max").css({left:"",bottom:""}):(this.range=t("").appendTo(this.element),i="ui-slider-range ui-widget-header ui-corner-all"),this.range.addClass(i+("min"===e.range||"max"===e.range?" ui-slider-range-"+e.range:""))):(this.range&&this.range.remove(),this.range=null)},_setupEvents:function(){this._off(this.handles),this._on(this.handles,this._handleEvents),this._hoverable(this.handles),this._focusable(this.handles)},_destroy:function(){this.handles.remove(),this.range&&this.range.remove(),this.element.removeClass("ui-slider ui-slider-horizontal ui-slider-vertical ui-widget ui-widget-content ui-corner-all"),this._mouseDestroy()},_mouseCapture:function(e){var i,s,n,o,a,r,l,h,c=this,u=this.options;return u.disabled?!1:(this.elementSize={width:this.element.outerWidth(),height:this.element.outerHeight()},this.elementOffset=this.element.offset(),i={x:e.pageX,y:e.pageY},s=this._normValueFromMouse(i),n=this._valueMax()-this._valueMin()+1,this.handles.each(function(e){var i=Math.abs(s-c.values(e));(n>i||n===i&&(e===c._lastChangedValue||c.values(e)===u.min))&&(n=i,o=t(this),a=e)}),r=this._start(e,a),r===!1?!1:(this._mouseSliding=!0,this._handleIndex=a,o.addClass("ui-state-active").focus(),l=o.offset(),h=!t(e.target).parents().addBack().is(".ui-slider-handle"),this._clickOffset=h?{left:0,top:0}:{left:e.pageX-l.left-o.width()/2,top:e.pageY-l.top-o.height()/2-(parseInt(o.css("borderTopWidth"),10)||0)-(parseInt(o.css("borderBottomWidth"),10)||0)+(parseInt(o.css("marginTop"),10)||0)},this.handles.hasClass("ui-state-hover")||this._slide(e,a,s),this._animateOff=!0,!0))},_mouseStart:function(){return!0},_mouseDrag:function(t){var e={x:t.pageX,y:t.pageY},i=this._normValueFromMouse(e);return this._slide(t,this._handleIndex,i),!1},_mouseStop:function(t){return this.handles.removeClass("ui-state-active"),this._mouseSliding=!1,this._stop(t,this._handleIndex),this._change(t,this._handleIndex),this._handleIndex=null,this._clickOffset=null,this._animateOff=!1,!1},_detectOrientation:function(){this.orientation="vertical"===this.options.orientation?"vertical":"horizontal"},_normValueFromMouse:function(t){var e,i,s,n,o;return"horizontal"===this.orientation?(e=this.elementSize.width,i=t.x-this.elementOffset.left-(this._clickOffset?this._clickOffset.left:0)):(e=this.elementSize.height,i=t.y-this.elementOffset.top-(this._clickOffset?this._clickOffset.top:0)),s=i/e,s>1&&(s=1),0>s&&(s=0),"vertical"===this.orientation&&(s=1-s),n=this._valueMax()-this._valueMin(),o=this._valueMin()+s*n,this._trimAlignValue(o)},_start:function(t,e){var i={handle:this.handles[e],value:this.value()};return this.options.values&&this.options.values.length&&(i.value=this.values(e),i.values=this.values()),this._trigger("start",t,i)},_slide:function(t,e,i){var s,n,o;this.options.values&&this.options.values.length?(s=this.values(e?0:1),2===this.options.values.length&&this.options.range===!0&&(0===e&&i>s||1===e&&s>i)&&(i=s),i!==this.values(e)&&(n=this.values(),n[e]=i,o=this._trigger("slide",t,{handle:this.handles[e],value:i,values:n}),s=this.values(e?0:1),o!==!1&&this.values(e,i))):i!==this.value()&&(o=this._trigger("slide",t,{handle:this.handles[e],value:i}),o!==!1&&this.value(i))},_stop:function(t,e){var i={handle:this.handles[e],value:this.value()};this.options.values&&this.options.values.length&&(i.value=this.values(e),i.values=this.values()),this._trigger("stop",t,i)},_change:function(t,e){if(!this._keySliding&&!this._mouseSliding){var i={handle:this.handles[e],value:this.value()};this.options.values&&this.options.values.length&&(i.value=this.values(e),i.values=this.values()),this._lastChangedValue=e,this._trigger("change",t,i)}},value:function(t){return arguments.length?(this.options.value=this._trimAlignValue(t),this._refreshValue(),this._change(null,0),void 0):this._value()},values:function(e,i){var s,n,o;if(arguments.length>1)return this.options.values[e]=this._trimAlignValue(i),this._refreshValue(),this._change(null,e),void 0;if(!arguments.length)return this._values();if(!t.isArray(arguments[0]))return this.options.values&&this.options.values.length?this._values(e):this.value();for(s=this.options.values,n=arguments[0],o=0;s.length>o;o+=1)s[o]=this._trimAlignValue(n[o]),this._change(null,o);this._refreshValue()},_setOption:function(e,i){var s,n=0;switch("range"===e&&this.options.range===!0&&("min"===i?(this.options.value=this._values(0),this.options.values=null):"max"===i&&(this.options.value=this._values(this.options.values.length-1),this.options.values=null)),t.isArray(this.options.values)&&(n=this.options.values.length),"disabled"===e&&this.element.toggleClass("ui-state-disabled",!!i),this._super(e,i),e){case"orientation":this._detectOrientation(),this.element.removeClass("ui-slider-horizontal ui-slider-vertical").addClass("ui-slider-"+this.orientation),this._refreshValue(),this.handles.css("horizontal"===i?"bottom":"left","");break;case"value":this._animateOff=!0,this._refreshValue(),this._change(null,0),this._animateOff=!1;break;case"values":for(this._animateOff=!0,this._refreshValue(),s=0;n>s;s+=1)this._change(null,s);this._animateOff=!1;break;case"step":case"min":case"max":this._animateOff=!0,this._calculateNewMax(),this._refreshValue(),this._animateOff=!1;break;case"range":this._animateOff=!0,this._refresh(),this._animateOff=!1}},_value:function(){var t=this.options.value;return t=this._trimAlignValue(t)},_values:function(t){var e,i,s;if(arguments.length)return e=this.options.values[t],e=this._trimAlignValue(e);if(this.options.values&&this.options.values.length){for(i=this.options.values.slice(),s=0;i.length>s;s+=1)i[s]=this._trimAlignValue(i[s]);return i}return[]},_trimAlignValue:function(t){if(this._valueMin()>=t)return this._valueMin();if(t>=this._valueMax())return this._valueMax();var e=this.options.step>0?this.options.step:1,i=(t-this._valueMin())%e,s=t-i;return 2*Math.abs(i)>=e&&(s+=i>0?e:-e),parseFloat(s.toFixed(5))},_calculateNewMax:function(){var t=this.options.max,e=this._valueMin(),i=this.options.step,s=Math.floor(+(t-e).toFixed(this._precision())/i)*i;t=s+e,this.max=parseFloat(t.toFixed(this._precision()))},_precision:function(){var t=this._precisionOf(this.options.step);return null!==this.options.min&&(t=Math.max(t,this._precisionOf(this.options.min))),t},_precisionOf:function(t){var e=""+t,i=e.indexOf(".");return-1===i?0:e.length-i-1},_valueMin:function(){return this.options.min},_valueMax:function(){return this.max},_refreshValue:function(){var e,i,s,n,o,a=this.options.range,r=this.options,l=this,h=this._animateOff?!1:r.animate,c={};this.options.values&&this.options.values.length?this.handles.each(function(s){i=100*((l.values(s)-l._valueMin())/(l._valueMax()-l._valueMin())),c["horizontal"===l.orientation?"left":"bottom"]=i+"%",t(this).stop(1,1)[h?"animate":"css"](c,r.animate),l.options.range===!0&&("horizontal"===l.orientation?(0===s&&l.range.stop(1,1)[h?"animate":"css"]({left:i+"%"},r.animate),1===s&&l.range[h?"animate":"css"]({width:i-e+"%"},{queue:!1,duration:r.animate})):(0===s&&l.range.stop(1,1)[h?"animate":"css"]({bottom:i+"%"},r.animate),1===s&&l.range[h?"animate":"css"]({height:i-e+"%"},{queue:!1,duration:r.animate}))),e=i}):(s=this.value(),n=this._valueMin(),o=this._valueMax(),i=o!==n?100*((s-n)/(o-n)):0,c["horizontal"===this.orientation?"left":"bottom"]=i+"%",this.handle.stop(1,1)[h?"animate":"css"](c,r.animate),"min"===a&&"horizontal"===this.orientation&&this.range.stop(1,1)[h?"animate":"css"]({width:i+"%"},r.animate),"max"===a&&"horizontal"===this.orientation&&this.range[h?"animate":"css"]({width:100-i+"%"},{queue:!1,duration:r.animate}),"min"===a&&"vertical"===this.orientation&&this.range.stop(1,1)[h?"animate":"css"]({height:i+"%"},r.animate),"max"===a&&"vertical"===this.orientation&&this.range[h?"animate":"css"]({height:100-i+"%"},{queue:!1,duration:r.animate}))},_handleEvents:{keydown:function(e){var i,s,n,o,a=t(e.target).data("ui-slider-handle-index");switch(e.keyCode){case t.ui.keyCode.HOME:case t.ui.keyCode.END:case t.ui.keyCode.PAGE_UP:case t.ui.keyCode.PAGE_DOWN:case t.ui.keyCode.UP:case t.ui.keyCode.RIGHT:case t.ui.keyCode.DOWN:case t.ui.keyCode.LEFT:if(e.preventDefault(),!this._keySliding&&(this._keySliding=!0,t(e.target).addClass("ui-state-active"),i=this._start(e,a),i===!1))return}switch(o=this.options.step,s=n=this.options.values&&this.options.values.length?this.values(a):this.value(),e.keyCode){case t.ui.keyCode.HOME:n=this._valueMin();break;case t.ui.keyCode.END:n=this._valueMax();break;case t.ui.keyCode.PAGE_UP:n=this._trimAlignValue(s+(this._valueMax()-this._valueMin())/this.numPages);break;case t.ui.keyCode.PAGE_DOWN:n=this._trimAlignValue(s-(this._valueMax()-this._valueMin())/this.numPages);break;case t.ui.keyCode.UP:case t.ui.keyCode.RIGHT:if(s===this._valueMax())return;n=this._trimAlignValue(s+o);break;case t.ui.keyCode.DOWN:case t.ui.keyCode.LEFT:if(s===this._valueMin())return;n=this._trimAlignValue(s-o)}this._slide(e,a,n)},keyup:function(e){var i=t(e.target).data("ui-slider-handle-index");this._keySliding&&(this._keySliding=!1,this._stop(e,i),this._change(e,i),t(e.target).removeClass("ui-state-active"))}}});var a="ui-effects-",r=t;t.effects={effect:{}},function(t,e){function i(t,e,i){var s=u[e.type]||{};return null==t?i||!e.def?null:e.def:(t=s.floor?~~t:parseFloat(t),isNaN(t)?e.def:s.mod?(t+s.mod)%s.mod:0>t?0:t>s.max?s.max:t)}function s(i){var s=h(),n=s._rgba=[];return i=i.toLowerCase(),f(l,function(t,o){var a,r=o.re.exec(i),l=r&&o.parse(r),h=o.space||"rgba";return l?(a=s[h](l),s[c[h].cache]=a[c[h].cache],n=s._rgba=a._rgba,!1):e}),n.length?("0,0,0,0"===n.join()&&t.extend(n,o.transparent),s):o[i]}function n(t,e,i){return i=(i+1)%1,1>6*i?t+6*(e-t)*i:1>2*i?e:2>3*i?t+6*(e-t)*(2/3-i):t}var o,a="backgroundColor borderBottomColor borderLeftColor borderRightColor borderTopColor color columnRuleColor outlineColor textDecorationColor textEmphasisColor",r=/^([\-+])=\s*(\d+\.?\d*)/,l=[{re:/rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(t){return[t[1],t[2],t[3],t[4]]}},{re:/rgba?\(\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,parse:function(t){return[2.55*t[1],2.55*t[2],2.55*t[3],t[4]]}},{re:/#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})/,parse:function(t){return[parseInt(t[1],16),parseInt(t[2],16),parseInt(t[3],16)]}},{re:/#([a-f0-9])([a-f0-9])([a-f0-9])/,parse:function(t){return[parseInt(t[1]+t[1],16),parseInt(t[2]+t[2],16),parseInt(t[3]+t[3],16)]}},{re:/hsla?\(\s*(\d+(?:\.\d+)?)\s*,\s*(\d+(?:\.\d+)?)\%\s*,\s*(\d+(?:\.\d+)?)\%\s*(?:,\s*(\d?(?:\.\d+)?)\s*)?\)/,space:"hsla",parse:function(t){return[t[1],t[2]/100,t[3]/100,t[4]]}}],h=t.Color=function(e,i,s,n){return new t.Color.fn.parse(e,i,s,n)},c={rgba:{props:{red:{idx:0,type:"byte"},green:{idx:1,type:"byte"},blue:{idx:2,type:"byte"}}},hsla:{props:{hue:{idx:0,type:"degrees"},saturation:{idx:1,type:"percent"},lightness:{idx:2,type:"percent"}}}},u={"byte":{floor:!0,max:255},percent:{max:1},degrees:{mod:360,floor:!0}},d=h.support={},p=t("")[0],f=t.each;p.style.cssText="background-color:rgba(1,1,1,.5)",d.rgba=p.style.backgroundColor.indexOf("rgba")>-1,f(c,function(t,e){e.cache="_"+t,e.props.alpha={idx:3,type:"percent",def:1}}),h.fn=t.extend(h.prototype,{parse:function(n,a,r,l){if(n===e)return this._rgba=[null,null,null,null],this;(n.jquery||n.nodeType)&&(n=t(n).css(a),a=e);var u=this,d=t.type(n),p=this._rgba=[];return a!==e&&(n=[n,a,r,l],d="array"),"string"===d?this.parse(s(n)||o._default):"array"===d?(f(c.rgba.props,function(t,e){p[e.idx]=i(n[e.idx],e)}),this):"object"===d?(n instanceof h?f(c,function(t,e){n[e.cache]&&(u[e.cache]=n[e.cache].slice())}):f(c,function(e,s){var o=s.cache;f(s.props,function(t,e){if(!u[o]&&s.to){if("alpha"===t||null==n[t])return;u[o]=s.to(u._rgba)}u[o][e.idx]=i(n[t],e,!0)}),u[o]&&0>t.inArray(null,u[o].slice(0,3))&&(u[o][3]=1,s.from&&(u._rgba=s.from(u[o])))}),this):e},is:function(t){var i=h(t),s=!0,n=this;return f(c,function(t,o){var a,r=i[o.cache];return r&&(a=n[o.cache]||o.to&&o.to(n._rgba)||[],f(o.props,function(t,i){return null!=r[i.idx]?s=r[i.idx]===a[i.idx]:e})),s}),s},_space:function(){var t=[],e=this;return f(c,function(i,s){e[s.cache]&&t.push(i)}),t.pop()},transition:function(t,e){var s=h(t),n=s._space(),o=c[n],a=0===this.alpha()?h("transparent"):this,r=a[o.cache]||o.to(a._rgba),l=r.slice();return s=s[o.cache],f(o.props,function(t,n){var o=n.idx,a=r[o],h=s[o],c=u[n.type]||{};null!==h&&(null===a?l[o]=h:(c.mod&&(h-a>c.mod/2?a+=c.mod:a-h>c.mod/2&&(a-=c.mod)),l[o]=i((h-a)*e+a,n)))}),this[n](l)},blend:function(e){if(1===this._rgba[3])return this;var i=this._rgba.slice(),s=i.pop(),n=h(e)._rgba;return h(t.map(i,function(t,e){return(1-s)*n[e]+s*t}))},toRgbaString:function(){var e="rgba(",i=t.map(this._rgba,function(t,e){return null==t?e>2?1:0:t});return 1===i[3]&&(i.pop(),e="rgb("),e+i.join()+")"},toHslaString:function(){var e="hsla(",i=t.map(this.hsla(),function(t,e){return null==t&&(t=e>2?1:0),e&&3>e&&(t=Math.round(100*t)+"%"),t});return 1===i[3]&&(i.pop(),e="hsl("),e+i.join()+")"},toHexString:function(e){var i=this._rgba.slice(),s=i.pop();return e&&i.push(~~(255*s)),"#"+t.map(i,function(t){return t=(t||0).toString(16),1===t.length?"0"+t:t}).join("")},toString:function(){return 0===this._rgba[3]?"transparent":this.toRgbaString()}}),h.fn.parse.prototype=h.fn,c.hsla.to=function(t){if(null==t[0]||null==t[1]||null==t[2])return[null,null,null,t[3]];var e,i,s=t[0]/255,n=t[1]/255,o=t[2]/255,a=t[3],r=Math.max(s,n,o),l=Math.min(s,n,o),h=r-l,c=r+l,u=.5*c;return e=l===r?0:s===r?60*(n-o)/h+360:n===r?60*(o-s)/h+120:60*(s-n)/h+240,i=0===h?0:.5>=u?h/c:h/(2-c),[Math.round(e)%360,i,u,null==a?1:a]},c.hsla.from=function(t){if(null==t[0]||null==t[1]||null==t[2])return[null,null,null,t[3]];var e=t[0]/360,i=t[1],s=t[2],o=t[3],a=.5>=s?s*(1+i):s+i-s*i,r=2*s-a;return[Math.round(255*n(r,a,e+1/3)),Math.round(255*n(r,a,e)),Math.round(255*n(r,a,e-1/3)),o]},f(c,function(s,n){var o=n.props,a=n.cache,l=n.to,c=n.from;h.fn[s]=function(s){if(l&&!this[a]&&(this[a]=l(this._rgba)),s===e)return this[a].slice();var n,r=t.type(s),u="array"===r||"object"===r?s:arguments,d=this[a].slice();return f(o,function(t,e){var s=u["object"===r?t:e.idx];null==s&&(s=d[e.idx]),d[e.idx]=i(s,e)}),c?(n=h(c(d)),n[a]=d,n):h(d)},f(o,function(e,i){h.fn[e]||(h.fn[e]=function(n){var o,a=t.type(n),l="alpha"===e?this._hsla?"hsla":"rgba":s,h=this[l](),c=h[i.idx];return"undefined"===a?c:("function"===a&&(n=n.call(this,c),a=t.type(n)),null==n&&i.empty?this:("string"===a&&(o=r.exec(n),o&&(n=c+parseFloat(o[2])*("+"===o[1]?1:-1))),h[i.idx]=n,this[l](h)))})})}),h.hook=function(e){var i=e.split(" ");f(i,function(e,i){t.cssHooks[i]={set:function(e,n){var o,a,r="";if("transparent"!==n&&("string"!==t.type(n)||(o=s(n)))){if(n=h(o||n),!d.rgba&&1!==n._rgba[3]){for(a="backgroundColor"===i?e.parentNode:e;(""===r||"transparent"===r)&&a&&a.style;)try{r=t.css(a,"backgroundColor"),a=a.parentNode}catch(l){}n=n.blend(r&&"transparent"!==r?r:"_default")}n=n.toRgbaString()}try{e.style[i]=n}catch(l){}}},t.fx.step[i]=function(e){e.colorInit||(e.start=h(e.elem,i),e.end=h(e.end),e.colorInit=!0),t.cssHooks[i].set(e.elem,e.start.transition(e.end,e.pos))}})},h.hook(a),t.cssHooks.borderColor={expand:function(t){var e={};return f(["Top","Right","Bottom","Left"],function(i,s){e["border"+s+"Color"]=t}),e}},o=t.Color.names={aqua:"#00ffff",black:"#000000",blue:"#0000ff",fuchsia:"#ff00ff",gray:"#808080",green:"#008000",lime:"#00ff00",maroon:"#800000",navy:"#000080",olive:"#808000",purple:"#800080",red:"#ff0000",silver:"#c0c0c0",teal:"#008080",white:"#ffffff",yellow:"#ffff00",transparent:[null,null,null,0],_default:"#ffffff"}}(r),function(){function e(e){var i,s,n=e.ownerDocument.defaultView?e.ownerDocument.defaultView.getComputedStyle(e,null):e.currentStyle,o={};if(n&&n.length&&n[0]&&n[n[0]])for(s=n.length;s--;)i=n[s],"string"==typeof n[i]&&(o[t.camelCase(i)]=n[i]);else for(i in n)"string"==typeof n[i]&&(o[i]=n[i]);return o}function i(e,i){var s,o,a={};for(s in i)o=i[s],e[s]!==o&&(n[s]||(t.fx.step[s]||!isNaN(parseFloat(o)))&&(a[s]=o));return a}var s=["add","remove","toggle"],n={border:1,borderBottom:1,borderColor:1,borderLeft:1,borderRight:1,borderTop:1,borderWidth:1,margin:1,padding:1};t.each(["borderLeftStyle","borderRightStyle","borderBottomStyle","borderTopStyle"],function(e,i){t.fx.step[i]=function(t){("none"!==t.end&&!t.setAttr||1===t.pos&&!t.setAttr)&&(r.style(t.elem,i,t.end),t.setAttr=!0)}}),t.fn.addBack||(t.fn.addBack=function(t){return this.add(null==t?this.prevObject:this.prevObject.filter(t))}),t.effects.animateClass=function(n,o,a,r){var l=t.speed(o,a,r);return this.queue(function(){var o,a=t(this),r=a.attr("class")||"",h=l.children?a.find("*").addBack():a;h=h.map(function(){var i=t(this);return{el:i,start:e(this)}}),o=function(){t.each(s,function(t,e){n[e]&&a[e+"Class"](n[e])})},o(),h=h.map(function(){return this.end=e(this.el[0]),this.diff=i(this.start,this.end),this}),a.attr("class",r),h=h.map(function(){var e=this,i=t.Deferred(),s=t.extend({},l,{queue:!1,complete:function(){i.resolve(e)}});return this.el.animate(this.diff,s),i.promise()}),t.when.apply(t,h.get()).done(function(){o(),t.each(arguments,function(){var e=this.el;t.each(this.diff,function(t){e.css(t,"")})}),l.complete.call(a[0])})})},t.fn.extend({addClass:function(e){return function(i,s,n,o){return s?t.effects.animateClass.call(this,{add:i},s,n,o):e.apply(this,arguments)}}(t.fn.addClass),removeClass:function(e){return function(i,s,n,o){return arguments.length>1?t.effects.animateClass.call(this,{remove:i},s,n,o):e.apply(this,arguments)}}(t.fn.removeClass),toggleClass:function(e){return function(i,s,n,o,a){return"boolean"==typeof s||void 0===s?n?t.effects.animateClass.call(this,s?{add:i}:{remove:i},n,o,a):e.apply(this,arguments):t.effects.animateClass.call(this,{toggle:i},s,n,o)}}(t.fn.toggleClass),switchClass:function(e,i,s,n,o){return t.effects.animateClass.call(this,{add:i,remove:e},s,n,o)}})}(),function(){function e(e,i,s,n){return t.isPlainObject(e)&&(i=e,e=e.effect),e={effect:e},null==i&&(i={}),t.isFunction(i)&&(n=i,s=null,i={}),("number"==typeof i||t.fx.speeds[i])&&(n=s,s=i,i={}),t.isFunction(s)&&(n=s,s=null),i&&t.extend(e,i),s=s||i.duration,e.duration=t.fx.off?0:"number"==typeof s?s:s in t.fx.speeds?t.fx.speeds[s]:t.fx.speeds._default,e.complete=n||i.complete,e}function i(e){return!e||"number"==typeof e||t.fx.speeds[e]?!0:"string"!=typeof e||t.effects.effect[e]?t.isFunction(e)?!0:"object"!=typeof e||e.effect?!1:!0:!0}t.extend(t.effects,{version:"1.11.4",save:function(t,e){for(var i=0;e.length>i;i++)null!==e[i]&&t.data(a+e[i],t[0].style[e[i]])},restore:function(t,e){var i,s;for(s=0;e.length>s;s++)null!==e[s]&&(i=t.data(a+e[s]),void 0===i&&(i=""),t.css(e[s],i))},setMode:function(t,e){return"toggle"===e&&(e=t.is(":hidden")?"show":"hide"),e},getBaseline:function(t,e){var i,s;switch(t[0]){case"top":i=0;break;case"middle":i=.5;break;case"bottom":i=1;break;default:i=t[0]/e.height}switch(t[1]){case"left":s=0;break;case"center":s=.5;break;case"right":s=1;break;default:s=t[1]/e.width}return{x:s,y:i}},createWrapper:function(e){if(e.parent().is(".ui-effects-wrapper"))return e.parent();var i={width:e.outerWidth(!0),height:e.outerHeight(!0),"float":e.css("float")},s=t("
").addClass("ui-effects-wrapper").css({fontSize:"100%",background:"transparent",border:"none",margin:0,padding:0}),n={width:e.width(),height:e.height()},o=document.activeElement;try{o.id}catch(a){o=document.body}return e.wrap(s),(e[0]===o||t.contains(e[0],o))&&t(o).focus(),s=e.parent(),"static"===e.css("position")?(s.css({position:"relative"}),e.css({position:"relative"})):(t.extend(i,{position:e.css("position"),zIndex:e.css("z-index")}),t.each(["top","left","bottom","right"],function(t,s){i[s]=e.css(s),isNaN(parseInt(i[s],10))&&(i[s]="auto")}),e.css({position:"relative",top:0,left:0,right:"auto",bottom:"auto"})),e.css(n),s.css(i).show()},removeWrapper:function(e){var i=document.activeElement;return e.parent().is(".ui-effects-wrapper")&&(e.parent().replaceWith(e),(e[0]===i||t.contains(e[0],i))&&t(i).focus()),e},setTransition:function(e,i,s,n){return n=n||{},t.each(i,function(t,i){var o=e.cssUnit(i);o[0]>0&&(n[i]=o[0]*s+o[1])}),n}}),t.fn.extend({effect:function(){function i(e){function i(){t.isFunction(o)&&o.call(n[0]),t.isFunction(e)&&e()}var n=t(this),o=s.complete,r=s.mode;(n.is(":hidden")?"hide"===r:"show"===r)?(n[r](),i()):a.call(n[0],s,i)}var s=e.apply(this,arguments),n=s.mode,o=s.queue,a=t.effects.effect[s.effect];
+return t.fx.off||!a?n?this[n](s.duration,s.complete):this.each(function(){s.complete&&s.complete.call(this)}):o===!1?this.each(i):this.queue(o||"fx",i)},show:function(t){return function(s){if(i(s))return t.apply(this,arguments);var n=e.apply(this,arguments);return n.mode="show",this.effect.call(this,n)}}(t.fn.show),hide:function(t){return function(s){if(i(s))return t.apply(this,arguments);var n=e.apply(this,arguments);return n.mode="hide",this.effect.call(this,n)}}(t.fn.hide),toggle:function(t){return function(s){if(i(s)||"boolean"==typeof s)return t.apply(this,arguments);var n=e.apply(this,arguments);return n.mode="toggle",this.effect.call(this,n)}}(t.fn.toggle),cssUnit:function(e){var i=this.css(e),s=[];return t.each(["em","px","%","pt"],function(t,e){i.indexOf(e)>0&&(s=[parseFloat(i),e])}),s}})}(),function(){var e={};t.each(["Quad","Cubic","Quart","Quint","Expo"],function(t,i){e[i]=function(e){return Math.pow(e,t+2)}}),t.extend(e,{Sine:function(t){return 1-Math.cos(t*Math.PI/2)},Circ:function(t){return 1-Math.sqrt(1-t*t)},Elastic:function(t){return 0===t||1===t?t:-Math.pow(2,8*(t-1))*Math.sin((80*(t-1)-7.5)*Math.PI/15)},Back:function(t){return t*t*(3*t-2)},Bounce:function(t){for(var e,i=4;((e=Math.pow(2,--i))-1)/11>t;);return 1/Math.pow(4,3-i)-7.5625*Math.pow((3*e-2)/22-t,2)}}),t.each(e,function(e,i){t.easing["easeIn"+e]=i,t.easing["easeOut"+e]=function(t){return 1-i(1-t)},t.easing["easeInOut"+e]=function(t){return.5>t?i(2*t)/2:1-i(-2*t+2)/2}})}(),t.effects,t.effects.effect.slide=function(e,i){var s,n=t(this),o=["position","top","bottom","left","right","width","height"],a=t.effects.setMode(n,e.mode||"show"),r="show"===a,l=e.direction||"left",h="up"===l||"down"===l?"top":"left",c="up"===l||"left"===l,u={};t.effects.save(n,o),n.show(),s=e.distance||n["top"===h?"outerHeight":"outerWidth"](!0),t.effects.createWrapper(n).css({overflow:"hidden"}),r&&n.css(h,c?isNaN(s)?"-"+s:-s:s),u[h]=(r?c?"+=":"-=":c?"-=":"+=")+s,n.animate(u,{queue:!1,duration:e.duration,easing:e.easing,complete:function(){"hide"===a&&n.hide(),t.effects.restore(n,o),t.effects.removeWrapper(n),i()}})}});
\ No newline at end of file
diff --git a/data/tsf.telegram.org/js/main-aj.js b/data/tsf.telegram.org/js/main-aj.js
new file mode 100644
index 0000000000..1813fd5404
--- /dev/null
+++ b/data/tsf.telegram.org/js/main-aj.js
@@ -0,0 +1,1079 @@
+function ajInit(options) {
+ if (!window.history || !history.pushState) {
+ return false;
+ }
+
+ var nav_url = location.href;
+ var short_url = layerUrlToShort(nav_url);
+ if (options.layer && !short_url) {
+ nav_url = layerUrlToNav(nav_url);
+ }
+ if (!history.state) {
+ history.replaceState({i: 0, u: nav_url}, null, short_url);
+ } else if (!history.state.u) {
+ history.replaceState({i: history.state.i, u: nav_url}, null, short_url);
+ } else if (short_url && location.href != short_url) {
+ history.replaceState(history.state, null, short_url);
+ }
+
+ var $progress = $('#aj_progress'),
+ progressBoxShadow = 'inset 0 2px 0 #39ade7',
+ progressNoBoxShadow = 'inset 0 0 0 #39ade7',
+ progressTransition = 'width .3s linear, box-shadow .2s ease',
+ progressTo,
+ progressVal = 0;
+ $progress.css({
+ width: 0,
+ transition: progressTransition,
+ position: 'fixed',
+ zIndex: 1000,
+ top: 0,
+ height: 3
+ });
+
+ var skipPopState = false;
+ var curHistoryState = history.state;
+ var curLocation = loc(curHistoryState.u);
+ var layerCloseLocation = layerCloseLoc(curHistoryState.u);
+ var underLayerTitle = document.title;
+ var curOnLoad = [], curOnUnload = [];
+ var curOnLayerLoad = [], curOnLayerUnload = [];
+ var curBeforeUnload = false, curBeforeLayerUnload = false;
+ var ajContainer = $('#aj_content');
+
+ console.log('history init', 'curState =', curHistoryState);
+
+ window.Aj = {
+ apiUrl: options.apiUrl,
+ version: options.version,
+ unauth: options.unauth || false,
+ onLoad: onLoad,
+ onUnload: onUnload,
+ onLayerLoad: onLayerLoad,
+ onLayerUnload: onLayerUnload,
+ pageLoaded: pageLoaded,
+ layerLoaded: layerLoaded,
+ showProgress: showProgress,
+ hideProgress: hideProgress,
+ onBeforeUnload: onBeforeUnload,
+ onBeforeLayerUnload: onBeforeLayerUnload,
+ linkHandler: linkHandler,
+ location: _location,
+ layerLocation: layerLocation,
+ setLocation: setLocation,
+ setLayerLocation: setLayerLocation,
+ apiRequest: apiRequest,
+ needAuth: needAuth,
+ ajContainer: ajContainer,
+ state: options.state || {},
+ layerState: {},
+ layer: false
+ };
+
+ if (options.layer) {
+ Aj.layer = $('#layer-popup-container');
+ Aj.layerState = options.layerState || {};
+ if (options.layerTitle) {
+ document.title = options.layerTitle;
+ }
+ }
+
+ function showProgress() {
+ clearTimeout(progressTo);
+ if (!progressVal) {
+ $progress.css({width: 0, transition: 'none'});
+ progressTo = setTimeout(function() {
+ $progress.css({transition: progressTransition});
+ showProgress();
+ }, 50);
+ } else {
+ progressTo = setTimeout(showProgress, 300);
+ }
+ $progress.css({width: progressVal + '%', boxShadow: progressBoxShadow});
+ progressVal = progressVal + (99 - progressVal) / 4;
+ }
+
+ function hideProgress(cancel) {
+ clearTimeout(progressTo);
+ progressTo = false;
+ progressVal = 0;
+ $progress.css({width: cancel ? '0%' : '100%'});
+ setTimeout(function() {
+ $progress.css({boxShadow: progressNoBoxShadow});
+ }, 300);
+ }
+
+ function apiRequest(method, data, onSuccess) {
+ return $.ajax(Aj.apiUrl, {
+ type: 'POST',
+ data: $.extend(data, {method: method}),
+ dataType: 'json',
+ xhrFields: {
+ withCredentials: true
+ },
+ success: function(result) {
+ if (result._dlog) {
+ $('#dlog').append(result._dlog);
+ }
+ onSuccess && onSuccess(result);
+ },
+ error: function(xhr) {
+ if (!xhr.readyState && !xhr.status) {
+ // was aborted
+ } else if (xhr.status == 401) {
+ location.href = '/auth';
+ } else {
+ location.reload();
+ }
+ }
+ });
+ }
+
+ function loc(href) {
+ var url = document.createElement('a');
+ url.href = href;
+ return url;
+ }
+
+ function layerHref(href) {
+ var url = document.createElement('a');
+ url.href = href;
+ var search = url.search;
+ if (search.substr(0, 1) == '?') {
+ search = search.substr(1);
+ }
+ var params = search.split('&');
+ for (var i = 0; i < params.length; i++) {
+ var kv = params[i].split('=');
+ if (kv[0] == 'l') {
+ return decodeURIComponent(kv[1] || '');
+ }
+ }
+ return null;
+ }
+
+ function layerOpenHref(href, l) {
+ var url = document.createElement('a');
+ url.href = href;
+ url.search = url.search.replace(/&l=[^&]*/g, '', url.search);
+ url.search = url.search.replace(/(\?)l=[^&]*&|\?l=[^&]*$/g, '$1', url.search);
+ url.search += (url.search ? '&' : '?') + 'l=' + encodeURIComponent(l);
+ return url.href;
+ }
+
+ function layerCloseLoc(href) {
+ var url = document.createElement('a');
+ url.href = href;
+ url.search = url.search.replace(/&l=[^&]*/g, '', url.search);
+ url.search = url.search.replace(/(\?)l=[^&]*&|\?l=[^&]*$/g, '$1', url.search);
+ return url;
+ }
+
+ function layerUrlToShort(href) {
+ var url = document.createElement('a');
+ url.href = href;
+ var match = url.search.match(/(\?|&)l=([^&]*)/);
+ if (match) {
+ return '/' + decodeURIComponent(match[2]);
+ }
+ return null;
+ }
+
+ function layerUrlToNav(href, cur_loc) {
+ if (layerUrlToShort(href)) {
+ return href;
+ }
+ var url = document.createElement('a');
+ url.href = href;
+ var layer_url = url.pathname.replace(/^\/+|\/+$/g, '');
+ return layerOpenHref(cur_loc || '/', layer_url);
+ }
+
+ function changeLocation(url, push_state) {
+ if (push_state) {
+ location.href = url;
+ } else {
+ location.replace(url);
+ }
+ }
+
+ function scrollToEl(elem) {
+ $(window).scrollTop($(elem).offset().top);
+ }
+
+ function scrollToHash(hash) {
+ hash = hash || curLocation.hash;
+ if (hash[0] == '#') hash = hash.substr(1);
+ if (!hash) return;
+ var elem = document.getElementById(hash);
+ if (elem) {
+ return scrollToEl(elem);
+ }
+ elem = $('a[name]').filter(function() {
+ return $(this).attr('name') == hash;
+ }).eq(0);
+ if (elem.length) {
+ scrollToEl(elem);
+ }
+ }
+
+ function onLoad(func) {
+ console.log('added to onLoad');
+ curOnLoad.push(func);
+ }
+
+ function onUnload(func) {
+ console.log('added to onUnload');
+ curOnUnload.push(func);
+ }
+
+ function onLayerLoad(func) {
+ console.log('added to onLayerLoad');
+ curOnLayerLoad.push(func);
+ }
+
+ function onLayerUnload(func) {
+ console.log('added to onLayerUnload');
+ curOnLayerUnload.push(func);
+ }
+
+ function onBeforeUnload(func) {
+ curBeforeUnload = func;
+ }
+
+ function onBeforeLayerUnload(func) {
+ curBeforeLayerUnload = func;
+ }
+
+ function pageLoaded() {
+ curBeforeUnload = false;
+ if (curOnLoad.length) {
+ for (var i = 0; i < curOnLoad.length; i++) {
+ console.log('onLoad', i);
+ curOnLoad[i](Aj.state);
+ }
+ }
+ onUnload(function() {
+ $(ajContainer).off('.curPage');
+ $(document).off('.curPage');
+ });
+ if (Aj.layer) {
+ layerLoaded();
+ }
+ }
+
+ function layerLoaded() {
+ curBeforeLayerUnload = false;
+ if (curOnLayerLoad.length) {
+ for (var i = 0; i < curOnLayerLoad.length; i++) {
+ console.log('onLayerLoad', i);
+ curOnLayerLoad[i](Aj.layerState);
+ }
+ }
+ onLayerUnload(function() {
+ Aj.layer.off('.curLayer');
+ });
+ Aj.layer.one('popup:close', function() {
+ if (curOnLayerUnload.length) {
+ for (var i = 0; i < curOnLayerUnload.length; i++) {
+ console.log('onLayerUnload', i);
+ curOnLayerUnload[i](Aj.layerState);
+ }
+ }
+ Aj.layer.remove();
+ if (underLayerTitle) {
+ document.title = underLayerTitle;
+ }
+ if (layerCloseLocation) {
+ setLocation(layerCloseLocation.href);
+ layerCloseLocation = false;
+ }
+ Aj.layer = false;
+ Aj.layerState = {};
+ curOnLayerLoad = [];
+ curOnLayerUnload = [];
+ });
+ Aj.layer.on('click.curLayer', 'a[data-layer-close]', function(e) {
+ e.preventDefault();
+ e.stopImmediatePropagation();
+ closePopup(Aj.layer);
+ });
+ openPopup(Aj.layer, {
+ closeByClickOutside: '.popup-no-close',
+ onBeforeClose: function($popup) {
+ var unloaded = checkBeforeUnload(function() {
+ var options = $popup.data('options');
+ options.onBeforeClose = null;
+ closePopup($popup);
+ });
+ return unloaded;
+ }
+ });
+ }
+
+ function onResult(url, http_code, result, push_state) {
+ hideProgress();
+ if (http_code != 200 || !result || !result.v || result.v != Aj.version) {
+ changeLocation(url, push_state);
+ return;
+ }
+ var url_hash = loc(url).hash;
+ if (result.r) {
+ var redirect_url = result.r;
+ if (url_hash) {
+ redirect_url = redirect_url.split('#')[0] + url_hash;
+ }
+ if (result.hr || !loadPage(loc(redirect_url), push_state)) {
+ changeLocation(redirect_url, push_state);
+ }
+ return;
+ }
+ var saved_ult = underLayerTitle;
+ var saved_lcl = (!Aj.layer || !push_state) ? layerCloseLocation : false;
+ underLayerTitle = false;
+ layerCloseLocation = false;
+ closeAllPopups();
+ underLayerTitle = saved_ult;
+ layerCloseLocation = saved_lcl;
+
+ if (result.h) {
+ if (curOnUnload.length) {
+ for (var i = 0; i < curOnUnload.length; i++) {
+ console.log('onUnload', i);
+ curOnUnload[i](Aj.state);
+ }
+ }
+ if (push_state) {
+ if (result.l) {
+ url = layerUrlToNav(url);
+ }
+ setLocation(url);
+ }
+ Aj.state = {};
+ curOnLoad = [];
+ curOnUnload = [];
+ if (result.t) {
+ document.title = result.t;
+ underLayerTitle = document.title;
+ }
+ if (result.h) {
+ ajContainer.html(result.h);
+ }
+ if (result.s) {
+ $.extend(Aj.state, result.s);
+ }
+ if (result._dlog) {
+ $('#dlog').html(result._dlog);
+ }
+ if (push_state || !Aj._useScrollHack) {
+ $(window).scrollTop(0);
+ }
+ $('body').css({height: '', overflow: ''});
+ if (url_hash) {
+ scrollToHash();
+ }
+ if (result.l) {
+ Aj.layer = $('');
+ Aj.layerState = {};
+ curOnLayerLoad = [];
+ curOnLayerUnload = [];
+ if (result.lt) {
+ document.title = result.lt;
+ }
+ if (result.ls) {
+ $.extend(Aj.layerState, result.ls);
+ }
+ Aj.layer.html(result.l).appendTo(document.body);
+ }
+ if (result.j) {
+ window.execScript ? window.execScript(result.j) : eval(result.j);
+ }
+ pageLoaded();
+ return;
+ } else if (result.l) {
+ if (push_state) {
+ url = layerUrlToNav(url);
+ setLocation(url);
+ }
+ if (result.s) {
+ $.extend(Aj.state, result.s);
+ }
+ if (result._dlog) {
+ $('#dlog').html(result._dlog);
+ }
+ Aj.layer = $('');
+ Aj.layerState = {};
+ curOnLayerLoad = [];
+ curOnLayerUnload = [];
+ if (result.lt) {
+ document.title = result.lt;
+ }
+ if (result.ls) {
+ $.extend(Aj.layerState, result.ls);
+ }
+ Aj.layer.html(result.l).appendTo(document.body);
+ if (result.j) {
+ window.execScript ? window.execScript(result.j) : eval(result.j);
+ }
+ Aj.layerLoaded();
+ return;
+ }
+ return changeLocation(url, push_state);
+ }
+
+ function loadPage(link, push_state, state_go) {
+ var url = link.href;
+ var cur_url = curLocation.href;
+ if (link.origin != curLocation.origin) {
+ return false;
+ }
+ if (link.pathname == curLocation.pathname &&
+ link.search == curLocation.search &&
+ link.hash != curLocation.hash) {
+ return false;
+ }
+ var load_fn, interrupted = false;
+ load_fn = function() {
+ if (!push_state) {
+ if (interrupted) {
+ historyJump(state_go);
+ }
+ curLocation = loc(url);
+ layerCloseLocation = layerCloseLoc(url);
+ }
+ if (interrupted && Aj.layer) {
+ var options = Aj.layer.data('options');
+ options.onBeforeClose = null;
+ }
+ showProgress();
+ $.ajax(url, {
+ dataType: 'json',
+ xhrFields: {withCredentials: true},
+ headers: {'X-Aj-Referer': cur_url},
+ success: function(result, t, xhr) {
+ onResult(url, xhr.status, result, push_state);
+ },
+ error: function(xhr) {
+ onResult(url, xhr.status, false, push_state);
+ }
+ });
+ };
+ interrupted = !checkBeforeUnload(load_fn);
+ if (interrupted && !push_state) {
+ historyJump(-state_go);
+ }
+ return true;
+ }
+
+ function _location(href) {
+ if (typeof href !== 'undefined') {
+ loadPage(loc(href), true);
+ } else {
+ return loc(curLocation.href);
+ }
+ }
+
+ function layerLocation(layer_url) {
+ if (typeof layer_url !== 'undefined') {
+ var layer_href = layerOpenHref(curLocation, layer_url);
+ loadPage(loc(layer_href), true);
+ } else {
+ return layerHref(curLocation.href);
+ }
+ }
+
+ function setLocation(href) {
+ var url = loc(href).href;
+ var short_url = layerUrlToShort(url) || url;
+ history.pushState({i: curHistoryState.i + 1, u: url}, null, short_url);
+ console.log('history push', 'oldState =', curHistoryState, 'newState =', history.state);
+ curHistoryState = history.state;
+ curLocation = loc(curHistoryState.u);
+ layerCloseLocation = layerCloseLoc(curHistoryState.u);
+ }
+
+ function setLayerLocation(layer_url) {
+ layer_url = layer_url.toString().replace(/^\/+|\/+$/g, '');
+ var layer_href = layerOpenHref(curLocation, layer_url);
+ var url = loc(layer_href).href;
+ var short_url = layerUrlToShort(url) || url;
+ history.pushState({i: curHistoryState.i + 1, u: url}, null, short_url);
+ console.log('history push', 'oldState =', curHistoryState, 'newState =', history.state);
+ curHistoryState = history.state;
+ curLocation = loc(curHistoryState.u);
+ }
+
+ function historyJump(delta) {
+ if (delta) {
+ skipPopState = true;
+ history.go(delta);
+ }
+ }
+
+ function needAuth() {
+ if (Aj.unauth) {
+ openPopup('#login-popup-container');
+ return true;
+ }
+ return false;
+ }
+
+ function linkHandler(e) {
+ if (e.metaKey || e.ctrlKey) return true;
+ var href = this.href;
+ if (this.hasAttribute('data-unsafe') &&
+ href != $(this).text()) {
+ var $confirm = showConfirm(l('WEB_OPEN_LINK_CONFIRM', {url: cleanHTML(href)}, 'Do you want to open {url}?'), null, l('WEB_OPEN_LINK', 'Open'));
+ $('.popup-primary-btn', $confirm).attr({
+ href: href,
+ target: $(this).attr('target'),
+ rel: $(this).attr('rel')
+ });
+ return false;
+ }
+ if ($(this).attr('target') == '_blank') return true;
+ if (this.hasAttribute('data-layer')) {
+ href = layerUrlToNav(href, curLocation);
+ }
+ if ($(this).hasClass('need-auth') && needAuth() ||
+ loadPage(loc(href), true)) {
+ e.preventDefault();
+ }
+ }
+
+ function beforeUnloadHandler(e) {
+ var message = null;
+ if (Aj.layer && curBeforeLayerUnload) {
+ message = curBeforeLayerUnload();
+ }
+ if (!message && curBeforeUnload) {
+ message = curBeforeUnload();
+ }
+ if (message) {
+ if (typeof e === 'undefined') e = window.e;
+ if (e) e.returnValue = message;
+ return message;
+ }
+ }
+ function checkBeforeUnload(load_fn) {
+ var message = null;
+ if (Aj.layer && curBeforeLayerUnload) {
+ message = curBeforeLayerUnload();
+ }
+ if (!message && curBeforeUnload) {
+ message = curBeforeUnload();
+ }
+ if (message) {
+ var message_html = $('').text(message).html();
+ showConfirm(message_html, load_fn, l('WEB_LEAVE_PAGE', 'Leave'));
+ return false;
+ } else {
+ load_fn();
+ return true;
+ }
+ }
+
+ $(document).on('click', 'a[href]', linkHandler);
+ $(document.body).removeClass('no-transition');
+
+ $(window).on('popstate', function(e) {
+ var popstate = e.originalEvent.state;
+ var state_go = popstate ? (popstate.i - curHistoryState.i) : 0;
+ if (!popstate) {
+ popstate = {i: 0, u: location.href};
+ } else if (!popstate.u) {
+ popstate.u = location.href;
+ }
+ console.log('history popstate', 'oldState =', curHistoryState, 'newState =', popstate, 'go(' + state_go + ')');
+ curHistoryState = popstate;
+ if (skipPopState) {
+ skipPopState = false;
+ return;
+ }
+ if (Aj._useScrollHack) {
+ $('body').css({height: '100000px', overflow: 'hidden'}); // for correct scroll restoration
+ }
+ var link = loc(curHistoryState.u);
+ loadPage(link, false, state_go);
+ });
+ window.onbeforeunload = beforeUnloadHandler;
+}
+
+function updateNavBar() {
+ var $nav_menu = $('.nav-menu');
+ $nav_menu.addClass('nav-menu-can-fix');
+ if ($nav_menu.css('position') == 'fixed') {
+ $nav_menu.width($nav_menu.parent().width());
+ } else {
+ $nav_menu.css('width', 'auto');
+ }
+}
+
+function getBR() {
+ if (window._brHTML) return window._brHTML;
+ return window._brHTML = $('
').html();
+}
+
+function cleanHTML(value) {
+ return value.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/\n/g, getBR());
+}
+
+function cleanRE(value) {
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&");
+}
+
+var Keys = {
+ BACKSPACE: 8,
+ ESC: 27,
+ TAB: 9,
+ RETURN: 13,
+ LEFT: 37,
+ UP: 38,
+ RIGHT: 39,
+ DOWN: 40,
+ on: function(key, callback) {
+ return function(e){ if(e.which == key) callback.apply(this, Array.prototype.slice.apply(arguments)); };
+ }
+};
+
+var Popups = [];
+
+function openPopup(popup, options) {
+ if (!popup) return false;
+ options = options || {};
+ var $popup = $(popup);
+ var popup_id = $popup.data('puid');
+ if (!popup_id) {
+ if (!Popups._pid) Popups._pid = 0;
+ popup_id = ++Popups._pid;
+ $popup.data('puid', popup_id);
+ }
+ $popup.data('options', options);
+ var i = Popups.indexOf(popup_id);
+ if (i >= 0) {
+ Popups.splice(i, 1);
+ }
+ Popups.push(popup_id);
+ $('body').css('overflow', 'hidden');
+ $popup.appendTo(window.Aj && Aj.ajContainer || 'body');
+ $popup.removeClass('hide');
+ if (document.activeElement) {
+ document.activeElement.blur();
+ }
+ if (options.closeByClickOutside) {
+ $popup.on('click', function(e) {
+ if ($(e.target).closest('body').length &&
+ !$(e.target).closest(options.closeByClickOutside).length) {
+ closePopup($popup);
+ }
+ });
+ }
+ $('.popup-cancel-btn', $popup).on('click', function(e) {
+ closePopup($popup);
+ });
+ $popup.trigger('popup:open');
+}
+
+function getPopupById(popup_id) {
+ var $popups = $('.popup-container');
+ var found = false;
+ for (var i = 0; i < $popups.length; i++) {
+ $popup = $popups.eq(i);
+ if (popup_id == $popup.data('puid')) {
+ return $popup;
+ }
+ }
+ return false;
+}
+
+function closePopup(popup) {
+ if (!Popups.length) return false;
+ var $popup, popup_id;
+ if (popup) {
+ $popup = $(popup);
+ popup_id = $popup.data('puid');
+ } else {
+ popup_id = Popups[Popups.length - 1];
+ $popup = getPopupById(popup_id);
+ if (!$popup) {
+ return false;
+ }
+ }
+ var options = $popup.data('options');
+ if (options.onBeforeClose) {
+ var result = options.onBeforeClose($popup);
+ if (result === false) {
+ return false;
+ }
+ }
+ var i = Popups.indexOf(popup_id);
+ if (i >= 0) {
+ Popups.splice(i, 1);
+ }
+ if (!Popups.length) {
+ $('body').css('overflow', '');
+ }
+ if (options.closeByClickOutside) {
+ $popup.off('click');
+ }
+ $('.popup-cancel-btn', $popup).off('click');
+ $popup.addClass('hide');
+ $popup.trigger('popup:close');
+}
+
+function closeAllPopups() {
+ for (var i = Popups.length - 1; i >= 0; i--) {
+ var $popup = getPopupById(Popups[i]);
+ if ($popup) {
+ closePopup($popup);
+ }
+ }
+}
+
+function showAlert(html, options) {
+ options = options || {};
+ var $alert = $('');
+ var onEnterPress = function(e) {
+ if (e.keyCode == Keys.RETURN) {
+ e.stopImmediatePropagation();
+ closePopup($alert);
+ }
+ };
+ $('.popup-text', $alert).html(html);
+ $(document).on('keydown', onEnterPress);
+ $alert.one('popup:close', function() {
+ $(document).off('keydown', onEnterPress);
+ $alert.remove();
+ });
+ openPopup($alert);
+ return $alert;
+}
+
+function showConfirm(html, onConfirm, confirm_btn, onCancel, cancel_btn) {
+ var $confirm = $('');
+ var confirm = function() {
+ onConfirm && onConfirm($confirm);
+ closePopup($confirm);
+ }
+ var onEnterPress = function(e) {
+ if (e.keyCode == Keys.RETURN) {
+ e.stopImmediatePropagation();
+ confirm();
+ }
+ };
+ $('.popup-text', $confirm).html(html);
+ var $primaryBtn = $('.popup-primary-btn', $confirm);
+ $primaryBtn.on('click', confirm);
+ if (onCancel) {
+ var cancel = function(){ onCancel($confirm); };
+ var $cancelBtn = $('.popup-cancel-btn', $confirm);
+ $cancelBtn.on('click', cancel);
+ }
+ $(document).on('keydown', onEnterPress);
+ $confirm.one('popup:close', function() {
+ $primaryBtn.off('click', confirm);
+ if (onCancel) {
+ $cancelBtn.off('click', cancel);
+ }
+ $(document).off('keydown', onEnterPress);
+ $confirm.remove();
+ });
+ openPopup($confirm);
+ return $confirm;
+}
+
+function showMedia(src, is_video, options) {
+ var media_html = is_video ? '
' : '
';
+ var $popup = $('');
+ var media = {
+ $wrap: $('.media-popup-wrap', $popup),
+ $cover: $('.media-popup-cover', $popup),
+ $pwrap: $('.circle-progress-wrap', $popup),
+ $media: $('.media', $popup),
+ width: null,
+ height: null,
+ cover: null,
+ timeout: null,
+ checkMediaSize: function() {
+ if (is_video) {
+ var video = media.mediaEl;
+ if (video.videoWidth && video.videoHeight) {
+ media.width = video.videoWidth;
+ media.height = video.videoHeight;
+ media.$media.removeClass('ohide');
+ media.$wrap.removeClass('file-loading').addClass('file-loaded');
+ media.onResize();
+ return;
+ }
+ } else {
+ var img = media.mediaEl;
+ if (img.naturalWidth && img.naturalHeight) {
+ media.width = img.naturalWidth;
+ media.height = img.naturalHeight;
+ media.onResize();
+ return;
+ }
+ }
+ media.timeout = setTimeout(media.checkMediaSize, 50);
+ },
+ onResize: function() {
+ if (!media.width || !media.height) {
+ return;
+ }
+ var w = media.width, h = media.height;
+ var de = document.documentElement;
+ var vw = de.clientWidth, vh = de.clientHeight;
+ vw -= parseInt($popup.css('paddingLeft') || 0)
+ + parseInt($popup.css('paddingRight') || 0)
+ + parseInt(media.$wrap.css('paddingRight') || 0);
+ vh -= parseInt($popup.css('paddingTop') || 0)
+ + parseInt($popup.css('paddingBottom') || 0)
+ + parseInt(media.$wrap.css('paddingBottom') || 0);
+ var min_vw = Math.max(320, vw);
+ var min_vh = Math.max(320, vh);
+ var sw = w / min_vw;
+ var sh = h / min_vh;
+ var s = Math.max(sw, sh);
+ var iw = w / s, ih = h / s;
+ if (!is_video) {
+ var can_zoom = (s > 1);
+ if (!can_zoom || $popup.hasClass('fullsize')) {
+ var iw = w, ih = h;
+ }
+ $popup.toggleClass('can-zoom', can_zoom);
+ }
+ var scroll_x = iw > vw;
+ var scroll_y = ih > vh;
+ $popup.toggleClass('scroll-x', scroll_x);
+ $popup.toggleClass('scroll-y', scroll_y);
+ media.$media.width(iw);
+ media.$media.height(ih);
+ },
+ onLoad: function() {
+ if (!is_video) {
+ media.$media.css('background-image', "url('" + media.mediaEl.src + "')");
+ media.$media.removeClass('ohide');
+ media.$wrap.removeClass('ohide').removeClass('file-loading').addClass('file-loaded');
+ media.onResize();
+ }
+ },
+ onZoomInOut: function(e) {
+ if (!is_video) {
+ var photo = media.$media.get(0);
+ var dx, dy, px, py, sx, sy, rect;
+ rect = photo.getBoundingClientRect();
+ dx = e.clientX - rect.left;
+ dy = e.clientY - rect.top;
+ px = dx / rect.width;
+ py = dy / rect.height;
+ $popup.toggleClass('fullsize');
+ media.onResize();
+ rect = photo.getBoundingClientRect();
+ dx = px * rect.width;
+ dy = py * rect.height;
+ sx = e.clientX - dx - rect.left - $popup.scrollLeft();
+ sy = e.clientY - dy - rect.top - $popup.scrollTop();
+ $popup.scrollLeft(-sx);
+ $popup.scrollTop(-sy);
+ }
+ }
+ };
+ if (is_video) {
+ media.mediaEl = media.$media.get(0);
+ } else {
+ media.mediaEl = new Image();
+ media.mediaEl.onload = media.onLoad;
+ media.$wrap.on('click', media.onZoomInOut);
+ }
+ $(window).on('resize', media.onResize);
+ media.checkMediaSize();
+ $popup.one('popup:close', function() {
+ if (!is_video) {
+ media.$media.off('click', media.onZoomInOut);
+ }
+ $(window).off('resize', media.onResize);
+ clearTimeout(media.timeout);
+ $popup.remove();
+ });
+ openPopup($popup, {
+ closeByClickOutside: '.popup-no-close',
+ });
+ if (options.width && options.height && options.cover) {
+ media.width = parseInt(options.width);
+ media.height = parseInt(options.height);
+ media.cover = options.cover;
+ media.$cover.css('background-image', "url('" + media.cover + "')").removeClass('ohide');
+ media.onResize();
+ }
+ setTimeout(function() {
+ media.$pwrap.get(0).classList.remove('ohide');
+ }, 250);
+ media.mediaEl.src = src;
+ return $popup;
+}
+
+function showPhoto(image_src, options) {
+ showMedia(image_src, false, options);
+}
+
+function showVideo(video_src, options) {
+ showMedia(video_src, true, options);
+}
+
+function showToast(html, delay) {
+ var $toast = $('
');
+ $('.toast', $toast).html(html);
+ var to, close = function() {
+ clearTimeout(to);
+ $toast.fadeHide();
+ setTimeout(function() { $toast.remove(); }, 200);
+ };
+ $toast.appendTo('body').redraw().fadeShow();
+ $(document).one('mousedown touchstart', close);
+ to = setTimeout(close, delay || 2000);
+}
+
+function l(lang_key, params, def_value) {
+ if (typeof params === 'string') {
+ def_value = params;
+ params = {};
+ }
+ params = params || {};
+ var value = l._keys[lang_key] || def_value || lang_key;
+ value = value.replace(/\{\{([A-Za-z_\-\d]{1,32}):(.+?)\}\}/g, function(lang_value, token, options) {
+ var number = +params[token] || 0;
+ var numeric_options = options.split('|');
+ var i;
+ if (number == 1) i = 0;
+ else i = 1;
+ if (typeof numeric_options[i] === 'undefined') {
+ i = 1;
+ }
+ var numeric_option = numeric_options[i] || '#';
+ return numeric_option.replace(/#/g, number);
+ });
+ value = value.replace(/\{([A-Za-z_\-\d]{1,32}):(.{1,256}?)\}/g, function(lang_value, token, options) {
+ var number = +params[token] || 0;
+ var numeric_options = options.split('|');
+ var i;
+ if (!number) i = 0;
+ else if (number == 1) i = 1;
+ else i = 2;
+ if (typeof numeric_options[i] === 'undefined') {
+ i = 0;
+ }
+ var numeric_option = numeric_options[i] || '#';
+ return numeric_option.replace(/#/g, number);
+ });
+ for (var param in params) {
+ value = value.split('{' + param + '}').join(params[param]);
+ }
+ return value;
+}
+l._keys = {};
+l.add = function(lang_values) {
+ for (var lang_key in lang_values) {
+ l._keys[lang_key] = lang_values[lang_key];
+ }
+}
+
+function redraw(el) {
+ el.offsetTop + 1;
+}
+
+$(document).on('keydown', function(e) {
+ if (e.keyCode == Keys.ESC && Popups.length > 0) {
+ var last_popup_id = Popups[Popups.length - 1];
+ var $popup = getPopupById(last_popup_id);
+ if ($popup && !$popup.hasClass('popup-ignore-esc')) {
+ e.stopImmediatePropagation();
+ e.preventDefault();
+ closePopup($popup);
+ }
+ }
+});
+
+$(document).on('keydown', 'textarea', function(e) {
+ if (e.keyCode == Keys.RETURN && (e.metaKey || e.ctrlKey)) {
+ $(this.form).submit();
+ }
+});
+
+(function($) {
+ function onTextRippleStart(evt) {
+ var e = evt.originalEvent;
+ if (document.activeElement === this) return;
+ var rect = this.getBoundingClientRect();
+ if (e.type == 'touchstart') {
+ var clientX = e.targetTouches[0].clientX;
+ } else {
+ var clientX = e.clientX;
+ }
+ var ripple = this.parentNode.querySelector('.textfield-item-underline');
+ var rippleX = (clientX - rect.left) / this.offsetWidth * 100;
+ ripple.style.transition = 'none';
+ redraw(ripple);
+ ripple.style.left = rippleX + '%';
+ ripple.style.right = (100 - rippleX) + '%';
+ redraw(ripple);
+ ripple.style.left = '';
+ ripple.style.right = '';
+ ripple.style.transition = '';
+ }
+ function onRippleStart(evt) {
+ var e = evt.originalEvent;
+ var rippleMask = this.querySelector('.ripple-mask');
+ if (!rippleMask) return;
+ var rect = rippleMask.getBoundingClientRect();
+ if (e.type == 'touchstart') {
+ var clientX = e.targetTouches[0].clientX;
+ var clientY = e.targetTouches[0].clientY;
+ } else {
+ var clientX = e.clientX;
+ var clientY = e.clientY;
+ }
+ var rippleX = (clientX - rect.left) - rippleMask.offsetWidth / 2;
+ var rippleY = (clientY - rect.top) - rippleMask.offsetHeight / 2;
+ var ripple = this.querySelector('.ripple');
+ ripple.style.transition = 'none';
+ redraw(ripple);
+ ripple.style.transform = 'translate3d(' + rippleX + 'px, ' + rippleY + 'px, 0) scale3d(0.2, 0.2, 1)';
+ ripple.style.opacity = 1;
+ redraw(ripple);
+ ripple.style.transform = 'translate3d(' + rippleX + 'px, ' + rippleY + 'px, 0) scale3d(1, 1, 1)';
+ ripple.style.transition = '';
+
+ function onRippleEnd(e) {
+ ripple.style.transitionDuration = '.2s';
+ ripple.style.opacity = 0;
+ document.removeEventListener('mouseup', onRippleEnd);
+ document.removeEventListener('touchend', onRippleEnd);
+ document.removeEventListener('touchcancel', onRippleEnd);
+ }
+ document.addEventListener('mouseup', onRippleEnd);
+ document.addEventListener('touchend', onRippleEnd);
+ document.addEventListener('touchcancel', onRippleEnd);
+ }
+ $.fn.initRipple = function() {
+ return this.map(function(){
+ $(this).off('.ripple');
+ $(this).on('mousedown.ripple touchstart.ripple', '.textfield-item input.form-control', onTextRippleStart);
+ $(this).on('mousedown.ripple touchstart.ripple', '.ripple-handler', onRippleStart);
+ return this;
+ });
+ };
+ $.fn.destroyRipple = function() {
+ return this.map(function(){
+ $(this).off('.ripple');
+ return this;
+ });
+ };
+})(jQuery);
+$(document).initRipple();
+
+Function.prototype.pbind = function() {
+ var func = this, args = Array.prototype.slice.apply(arguments);
+ return function() {
+ return func.apply(this, args.concat(Array.prototype.slice.apply(arguments)));
+ }
+}