UNPKG

2gis-maps

Version:

Interactive 2GIS maps API, based on Leaflet

2 lines 10.7 kB
/*! baron 11-09-2013 */ (function(t,i){"use strict";function e(i,e,s){i._eventHandlers=i._eventHandlers||[{element:i.scroller,handler:function(t){i.scroll(t)},type:"scroll"},{element:i.bar,handler:function(t){t.preventDefault(),i.selection(),i.drag.now=1},type:"touchstart mousedown"},{element:document,handler:function(){i.selection(1),i.drag.now=0},type:"mouseup blur touchend"},{element:document,handler:function(t){2!=t.button&&i._pos0(t)},type:"touchstart mousedown"},{element:document,handler:function(t){i.drag.now&&i.drag(t)},type:"mousemove touchmove"},{element:t,handler:function(){i.update()},type:"resize"},{element:i.root,handler:function(){i.update()},type:"sizeChange"}],f(i._eventHandlers,function(t){t.element&&e(t.element,t.type,t.handler,s)})}function s(t,i,e){var s="data-baron-"+i;if("on"==e)t.setAttribute(s,"inited");else{if("off"!=e)return t.getAttribute(s);t.removeAttribute(s)}}function r(t){if(!s(t.root,t.direction)){var i=new p.prototype.constructor(t);return e(i,t.event,"on"),s(i.root,t.direction,"on"),i.update(),i}}function o(t){var i={};t=t||{};for(var e in t)t.hasOwnProperty(e)&&(i[e]=t[e]);return i}function n(t){var i=o(t);i.direction=i.direction||"v";var e=t.event||function(t,e,s,r){i.$(t)[r||"on"](e,s)};return i.event=function(t,i,s,r){f(t,function(t){e(t,i,s,r)})},i}function l(t){if(this.events&&this.events[t])for(var i=0;this.events[t].length>i;i++){var e=Array.prototype.slice.call(arguments,1);this.events[t][i].apply(this,e)}}if(t){var c=t.baron,a=t.jQuery,h={v:{x:"Y",pos:"top",crossPos:"left",size:"height",crossSize:"width",client:"clientHeight",crossClient:"clientWidth",offset:"offsetHeight",crossOffset:"offsetWidth",offsetPos:"offsetTop",scroll:"scrollTop",scrollSize:"scrollHeight"},h:{x:"X",pos:"left",crossPos:"top",size:"width",crossSize:"height",client:"clientWidth",crossClient:"clientHeight",offset:"offsetWidth",crossOffset:"offsetHeight",offsetPos:"offsetLeft",scroll:"scrollLeft",scrollSize:"scrollWidth"}},f=function(e,s){var r=0;for((e.length===i||e===t)&&(e=[e]);e[r];)s.call(this,e[r],r),r++},u=function(i){var e,s,r=this&&this[0]&&this[0].nodeType;return i=i||{},s=i.$||t.jQuery,r?i.root=e=this:e=s(i.root||i.scroller),new u.fn.constructor(e,i,s)};u.fn={constructor:function(t,i,e){var s=n(i);s.$=e,f.call(this,t,function(t,i){var e=o(s);s.root&&s.scroller?(e.scroller=s.$(s.scroller,t),e.scroller.length||(e.scroller=t)):e.scroller=t,e.root=t,this[i]=r(e),this.length=i+1}),this.params=s},dispose:function(){var t=this.params;f(this,function(i){i.dispose(t)}),this.params=null},update:function(){for(var t=0;this[t];)this[t].update.apply(this[t],arguments),t++},baron:function(t){return t.root=[],t.scroller=this.params.scroller,f.call(this,this,function(i){t.root.push(i.root)}),t.direction="v"==this.params.direction?"h":"v",t._chain=!0,u(t)}};var p={};p.prototype={constructor:function(t){function e(t,i){return f(t,i)[0]}function s(t){var i=this.barMinSize||20;t>0&&i>t&&(t=i),this.bar&&f(this.bar).css(this.origin.size,parseInt(t,10)+"px")}function r(t){this.bar&&f(this.bar).css(this.origin.pos,+t+"px")}function o(){return d[this.origin.client]-this.barTopLimit-this.bar[this.origin.offset]}function n(t){return t*o.call(this)+this.barTopLimit}function c(t){return(t-this.barTopLimit)/o.call(this)}function a(){return!1}var f,u,p,d,v,g,m,b,w;return w=b=(new Date).getTime(),f=this.$=t.$,this.event=t.event,this.events={},this.root=t.root,this.scroller=e(t.scroller),this.bar=e(t.bar,this.root),d=this.track=e(t.track,this.root),!this.track&&this.bar&&(d=this.bar.parentNode),this.clipper=this.scroller.parentNode,this.direction=t.direction,this.origin=h[this.direction],this.barOnCls=t.barOnCls,this.barTopLimit=0,m=1e3*t.pause||0,this.cursor=function(t){return t["client"+this.origin.x]||(((t.originalEvent||t).touches||{})[0]||{})["page"+this.origin.x]},this.pos=function(t){var e="page"+this.origin.x+"Offset",s=this.scroller[e]?e:this.origin.scroll;return t!==i&&(this.scroller[s]=t),this.scroller[s]},this.rpos=function(t){var i,e=this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client];return i=t?this.pos(t*e):this.pos(),i/(e||1)},this.barOn=function(t){this.barOnCls&&(t||this.scroller[this.origin.client]>=this.scroller[this.origin.scrollSize]?f(this.root).removeClass(this.barOnCls):f(this.root).addClass(this.barOnCls))},this._pos0=function(t){p=this.cursor(t)-u},this.drag=function(t){this.scroller[this.origin.scroll]=c.call(this,this.cursor(t)-p)*(this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client])},this.selection=function(t){this.event(document,"selectpos selectstart",a,t?"off":"on")},this.resize=function(){function i(){var i=e.scroller[e.origin.crossOffset]-e.scroller[e.origin.crossClient];t.freeze&&!e.clipper.style[e.origin.crossSize]&&f(e.clipper).css(e.origin.crossSize,e.clipper[e.origin.crossClient]-i+"px"),f(e.scroller).css(e.origin.crossSize,e.clipper[e.origin.crossClient]+i+"px"),Array.prototype.unshift.call(arguments,"resize"),l.apply(e,arguments),w=(new Date).getTime()}var e=this,s=0;m>(new Date).getTime()-w&&(clearTimeout(v),s=m),s?v=setTimeout(i,s):i()},this.scroll=function(){function t(){c.bar&&(e=(d[c.origin.client]-c.barTopLimit)*c.scroller[c.origin.client]/c.scroller[c.origin.scrollSize],i!=e&&(s.call(c,e),i=e),u=n.call(c,c.rpos()),r.call(c,u)),Array.prototype.unshift.call(arguments,"scroll"),l.apply(c,arguments),b=(new Date).getTime()}var i,e,o=0,c=this;m>(new Date).getTime()-b&&(clearTimeout(g),o=m),o?g=setTimeout(t,o):t()},this},update:function(t){return l.call(this,"upd",t),this.resize(1),this.barOn(),this.scroll(),this},dispose:function(t){e(this,this.event,"off"),s(this.root,t.direction,"off"),a(this.scroller).css(this.origin.crossSize,""),this.barOn(!0),l.call(this,"dispose")},on:function(t,i,e){for(var s=t.split(" "),r=0;s.length>r;r++)"init"==s[r]?i.call(this,e):(this.events[s[r]]=this.events[s[r]]||[],this.events[s[r]].push(function(t){i.call(this,t||e)}))}},u.fn.constructor.prototype=u.fn,p.prototype.constructor.prototype=p.prototype,u.noConflict=function(){return t.baron=c,u},u.version="0.6.6",a&&a.fn&&(a.fn.baron=u),t.baron=u,t.module&&module.exports&&(module.exports=u.noConflict())}})(window),function(t,e){var s=function(t){function s(t,i){(c.minView||0)>l&&(i=e),i!==e?(i+="px",this.$(n[t]).css(this.origin.pos,i).addClass(c.outside)):this.$(n[t]).css(this.origin.pos,"").removeClass(c.outside)}function r(t){try{i=document.createEvent("WheelEvent"),i.initWebKitWheelEvent(t.originalEvent.wheelDeltaX,t.originalEvent.wheelDeltaY),u.dispatchEvent(i),t.preventDefault()}catch(t){}}function o(t){var i;for(var e in t)c[e]=t[e];if(n=this.$(c.elements,this.scroller)){l=this.scroller[this.origin.client];for(var s=0;n.length>s;s++)i={},i[this.origin.size]=n[s][this.origin.offset],n[s].parentNode!==this.scroller&&this.$(n[s].parentNode).css(i),i={},i[this.origin.crossSize]=n[s].parentNode[this.origin.crossClient],this.$(n[s]).css(i),l-=n[s][this.origin.offset],f[s]=n[s].parentNode[this.origin.offsetPos],a[s]=a[s-1]||0,h[s]=h[s-1]||Math.min(f[s],0),n[s-1]&&(a[s]+=n[s-1][this.origin.offset],h[s]+=n[s-1][this.origin.offset]),(0!=s||0!=f[s])&&(this.event(n[s],"mousewheel",r,"off"),this.event(n[s],"mousewheel",r));c.limiter&&n[0]&&(this.track&&this.track!=this.scroller?(i={},i[this.origin.pos]=n[0].parentNode[this.origin.offset],this.$(this.track).css(i)):this.barTopLimit=n[0].parentNode[this.origin.offset],this.scroll()),c.limiter===!1&&(this.barTopLimit=0)}var o={element:n,handler:function(){for(var t,i=d(this)[0].parentNode,e=i.offsetTop,s=0;n.length>s;s++)n[s]===this&&(t=s);var r=e-a[t];c.scroll?c.scroll({x1:v.scroller.scrollTop,x2:r}):v.scroller.scrollTop=r},type:"click"};c.clickable&&(this._eventHandlers.push(o),p(o.element,o.type,o.handler,"off"),p(o.element,o.type,o.handler,"on"))}var n,l,c={outside:"",before:"",after:"",past:"",future:"",radius:0,minView:0},a=[],h=[],f=[],u=this.scroller,p=this.event,d=this.$,v=this;this.on("init",o,t),this.on("init scroll",function(){var t,i,r=[];if(n){for(var o,u=0;n.length>u;u++)t=0,f[u]-this.pos()<h[u]+c.radius?(t=1,i=a[u]):f[u]-this.pos()>h[u]+l-c.radius?(t=2,i=a[u]+l):(t=3,i=e),t!=r[u]&&(s.call(this,u,i),r[u]=t,o=!0);if(o)for(u=0;n.length>u;u++)1==r[u]&&c.past&&this.$(n[u]).addClass(c.past).removeClass(c.future),2==r[u]&&c.future&&this.$(n[u]).addClass(c.future).removeClass(c.past),3==r[u]&&(c.future||c.past)&&this.$(n[u]).removeClass(c.past).removeClass(c.future),r[u]!=r[u+1]&&1==r[u]&&c.before?this.$(n[u]).addClass(c.before).removeClass(c.after):r[u]!=r[u-1]&&2==r[u]&&c.after?this.$(n[u]).addClass(c.after).removeClass(c.before):this.$(n[u]).removeClass(c.before).removeClass(c.after)}}),this.on("resize upd",function(t){o.call(this,t&&t.fix)})};baron.fn.fix=function(t){for(var i=0;this[i];)s.call(this[i],t),i++;return this}}(window),function(){var t=function(t){var i,e,s,r,o=this;r=t.screen||.9,t.forward&&(i=this.$(t.forward,this.clipper),this.event(i,"click",function(){var i=o.pos()-t.delta||30;o.pos(i)})),t.backward&&(e=this.$(t.backward,this.clipper),this.event(e,"click",function(){var i=o.pos()+t.delta||30;o.pos(i)})),t.track&&(s=t.track===!0?this.track:this.$(t.track,this.clipper)[0],s&&this.event(s,"mousedown",function(t){var i=t["offset"+o.origin.x],e=o.bar[o.origin.offsetPos],s=0;e>i?s=-1:i>e+o.bar[o.origin.offset]&&(s=1);var n=o.pos()+s*r*o.scroller[o.origin.client];o.pos(n)}))};baron.fn.controls=function(i){for(var e=0;this[e];)t.call(this[e],i),e++;return this}}(window),function(){var t=function(t){function i(){return m.scroller[m.origin.scroll]+m.scroller[m.origin.offset]}function e(){return m.scroller[m.origin.scrollSize]}function s(){return m.scroller[m.origin.client]}function r(t,i){var e=5e-4*t;return Math.floor(i-e*(t+550))}function o(t){h=t,t?(n(),l=setInterval(n,200)):clearInterval(l)}function n(){var n,l,h={},z=i(),$=e(),T=1==b;if(l=0,b>0&&(l=40),n=r(y,l),z>=$-y&&b>-1?T&&(y+=n):y=0,0>y&&(y=0),h[u]=y+"px",s()<=e()){m.$(f).css(h);for(var x=0;v.length>x;x++)m.$(v[x].self).css(v[x].property,Math.min(100*(y/p),100)+"%")}g&&y&&m.$(m.root).addClass(g),0==y&&t.onCollapse&&t.onCollapse(),b=0,c=setTimeout(function(){b=-1},C),d&&y>p&&!a&&(d(),a=!0),0==y?w++:w=0,w>1&&(o(!1),a=!1,g&&m.$(m.root).removeClass(g))}var l,c,a,h,f=this.$(t.block),u=t.size||this.origin.size,p=t.limit||80,d=t.onExpand,v=t.elements||[],g=t.inProgress||"",m=this,b=0,w=0,y=0,C=t.waiting||500;this.on("init",function(){o(!0)}),this.on("dispose",function(){o(!1)}),this.event(this.scroller,"mousewheel DOMMouseScroll",function(t){var s=0>t.wheelDelta||t.originalEvent&&0>t.originalEvent.wheelDelta||t.detail>0;s&&(b=1,clearTimeout(c),!h&&i()>=e()&&o(!0))})};baron.fn.pull=function(i){for(var e=0;this[e];)t.call(this[e],i),e++;return this}}(window);