Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

baron

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

baron - npm Package Compare versions

Comparing version 0.8.0 to 1.0.0

169

baron.js

@@ -1,2 +0,2 @@

(function(window, $, undefined) {
(function(window, undefined) {
'use strict';

@@ -6,2 +6,3 @@

var $ = window.$;
var _baron = baron; // Stored baron value for noConflict usage

@@ -32,31 +33,38 @@ var pos = ['left', 'top', 'right', 'bottom', 'width', 'height'];

function each(obj, iterator) {
var i = 0;
// window.baron and jQuery.fn.baron points to this function
function baron(params) {
var jQueryMode;
var roots;
var empty = !params;
var defaultParams = {
$: window.jQuery,
direction: 'v',
barOnCls: 'baron',
resizeDebounce: 0,
event: function(elem, event, func, mode) {
params.$(elem)[mode || 'on'](event, func);
},
cssGuru: false
};
if (obj.length === undefined || obj === window) obj = [obj];
params = params || {};
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// Extending default params by user-defined params
for (var key in defaultParams) {
if (params[key] === undefined) {
params[key] = defaultParams[key];
}
};
function baron(params) {
var jQueryMode,
roots,
$;
jQueryMode = this instanceof params.$; // this - global context or jQuery instance
params = params || {};
$ = params.$ || $ || window.jQuery;
jQueryMode = this instanceof $; // this - window or jQuery instance
if (jQueryMode) {
params.root = roots = this;
} else {
roots = $(params.root || params.scroller);
roots = params.$(params.root || params.scroller);
}
var instance = new baron.fn.constructor(roots, params, $);
var instance = new baron.fn.constructor(roots, params, empty);
if (instance.autoUpdate) {
if (instance.autoUpdate && !empty) {
instance.autoUpdate();

@@ -68,2 +76,13 @@ }

function arrayEach(obj, iterator) {
var i = 0;
if (obj.length === undefined || obj === window) obj = [obj];
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// shortcut for getTime

@@ -77,8 +96,15 @@ function getTime() {

baron.fn = {
constructor: function(roots, input, $) {
var params = validate(input);
constructor: function(roots, totalParams, noUserParams) {
var params = clone(totalParams);
params.$ = $;
// Intrinsic params.event is not the same as totalParams.event
params.event = function(elems, e, func, mode) {
arrayEach(elems, function(elem) {
totalParams.event(elem, e, func, mode);
});
};
this.length = 0;
each.call(this, roots, function(root, i) {
arrayEach.call(this, roots, function(root, i) {
var attr = manageAttr(root, params.direction);

@@ -89,19 +115,19 @@ var id = +attr; // Could be NaN

// but baron(params) will throw an Error as a second initialization
if (id == id && attr != undefined && instances[id] && !input) {
if (id == id && attr != undefined && instances[id] && noUserParams) {
this[i] = instances[id];
} else {
var localParams = clone(params);
var perInstanceParams = clone(params);
// root and scroller can be different nodes
if (params.root && params.scroller) {
localParams.scroller = params.$(params.scroller, root);
if (!localParams.scroller.length) {
localParams.scroller = root;
perInstanceParams.scroller = params.$(params.scroller, root);
if (!perInstanceParams.scroller.length) {
perInstanceParams.scroller = root;
}
} else {
localParams.scroller = root;
perInstanceParams.scroller = root;
}
localParams.root = root;
this[i] = init(localParams);
perInstanceParams.root = root;
this[i] = init(perInstanceParams);
}

@@ -118,3 +144,3 @@

each(this, function(item) {
arrayEach(this, function(item) {
item.dispose(params);

@@ -139,3 +165,3 @@ });

each.call(this, this, function(elem) {
arrayEach.call(this, this, function(elem) {
params.root.push(elem.root);

@@ -250,3 +276,3 @@ });

each(item._eventHandlers, function(event) {
arrayEach(item._eventHandlers, function(event) {
if (event.element) {

@@ -322,11 +348,5 @@ eventManager(event.element, event.type, event.handler, mode);

output.direction = output.direction || 'v';
var event = input.event || function(elem, event, func, mode) {
output.$(elem)[mode || 'on'](event, func);
};
output.event = function(elems, e, func, mode) {
each(elems, function(elem) {
event(elem, e, func, mode);
arrayEach(elems, function(elem) {
input.event(elem, e, func, mode);
});

@@ -353,2 +373,3 @@ };

// underscore.js realization
// used in autoUpdate plugin
_debounce: function(func, wait) {

@@ -400,5 +421,3 @@ var self = this,

resizePauseTimer,
scrollPauseTimer,
scrollingTimer,
pause,
scrollLastFire,

@@ -436,8 +455,4 @@ resizeLastFire,

this.barTopLimit = 0;
pause = params.pause * 1000 || 0;
this.resizeDebounce = params.resizeDebounce;
if (params.pause) {
console.warn('Baronjs: "pause" param will be removed in 0.8+ version');
}
// Updating height or width of bar

@@ -554,9 +569,11 @@ function setBarSize(size) {

// onResize & DOM modified handler
// also fires on init
this.resize = function() {
var self = this,
delay = 0;
var self = this;
var minPeriod = (self.resizeDebounce === undefined) ? 300 : self.resizeDebounce;
var delay = 0;
if (getTime() - resizeLastFire < pause) {
if (getTime() - resizeLastFire < minPeriod) {
clearTimeout(resizePauseTimer);
delay = pause;
delay = minPeriod;
}

@@ -648,21 +665,9 @@

this.scroll = function() {
var delay = 0,
self = this;
var self = this;
if (getTime() - scrollLastFire < pause) {
clearTimeout(scrollPauseTimer);
delay = pause;
}
self.updatePositions();
if (delay) {
scrollPauseTimer = setTimeout(function() {
self.updatePositions();
}, delay);
} else {
self.updatePositions();
}
if (self.scrollingCls) {
if (!scrollingTimer) {
this.$(this.scroller).addClass(this.scrollingCls);
self.$(self.scroller).addClass(self.scrollingCls);
}

@@ -691,8 +696,29 @@ clearTimeout(scrollingTimer);

// Set most common css rules
this._dumbCss = function(on) {
if (params.cssGuru) return;
var overflow = on ? 'hidden' : null;
var scroll = on ? 'scroll' : null;
this.$(this.clipper).css({overflow: overflow});
var axis = this.direction == 'v' ? 'y' : 'x';
var scrollerCss = {};
scrollerCss['overflow-' + axis] = scroll;
scrollerCss['box-sizing'] = 'border-box';
scrollerCss.margin = '0';
scrollerCss.border = '0';
this.$(this.scroller).css(scrollerCss);
};
return this;
},
// fires on any update and on init
update: function(params) {
fire.call(this, 'upd', params); // Update all plugins' params
this._dumbCss(true);
this.resize(1);

@@ -713,2 +739,3 @@ this.updatePositions();

}
this._dumbCss(false);
this.barOn(true);

@@ -746,3 +773,3 @@ fire.call(this, 'dispose');

baron.version = '0.8.0';
baron.version = '0.9.0-alpha';

@@ -757,3 +784,3 @@ if ($ && $.fn) { // Adding baron to jQuery as plugin

}
})(window, window.$);
})(window);

@@ -760,0 +787,0 @@ /* Fixable elements plugin for baron 0.6+ */

@@ -1,1 +0,1 @@

!function(t,i,s){"use strict";function e(i,e){var r=0;for((i.length===s||i===t)&&(i=[i]);i[r];)e.call(this,i[r],r),r++}function r(i){var s,e,o;i=i||{},o=i.$||o||t.jQuery,s=this instanceof o,s?i.root=e=this:e=o(i.root||i.scroller);var n=new r.fn.constructor(e,i,o);return n.autoUpdate&&n.autoUpdate(),n}function o(){return(new Date).getTime()}function n(s,r,o){s._eventHandlers=s._eventHandlers||[{element:s.scroller,handler:function(t){s.scroll(t)},type:"scroll"},{element:s.root,handler:function(){s.update()},type:"transitionend animationend"},{element:s.scroller,handler:function(){s.update()},type:"keyup"},{element:s.bar,handler:function(t){t.preventDefault(),s.selection(),s.drag.now=1,s.draggingCls&&i(s.bar).addClass(s.draggingCls)},type:"touchstart mousedown"},{element:document,handler:function(){s.selection(1),s.drag.now=0,s.draggingCls&&i(s.bar).removeClass(s.draggingCls)},type:"mouseup blur touchend"},{element:document,handler:function(t){2!=t.button&&s._pos0(t)},type:"touchstart mousedown"},{element:document,handler:function(t){s.drag.now&&s.drag(t)},type:"mousemove touchmove"},{element:t,handler:function(){s.update()},type:"resize"},{element:s.root,handler:function(){s.update()},type:"sizeChange"}],e(s._eventHandlers,function(t){t.element&&r(t.element,t.type,t.handler,o)})}function l(t,i,s,e){var r="data-baron-"+i+"-id";if("on"==s)t.setAttribute(r,e);else{if("off"!=s)return t.getAttribute(r);t.removeAttribute(r)}}function a(t){l(t.root,t.direction)&&console.log("Error! Baron for this node already initialized",t.root);var i=new g.prototype.constructor(t);return n(i,t.event,"on"),l(i.root,t.direction,"on",d.length),d.push(i),i.update(),i}function c(t){var i={};t=t||{};for(var s in t)t.hasOwnProperty(s)&&(i[s]=t[s]);return i}function h(t){var i=c(t);i.direction=i.direction||"v";var s=t.event||function(t,s,e,r){i.$(t)[r||"on"](s,e)};return i.event=function(t,i,r,o){e(t,function(t){s(t,i,r,o)})},i}function u(t){if(this.events&&this.events[t])for(var i=0;i<this.events[t].length;i++){var s=Array.prototype.slice.call(arguments,1);this.events[t][i].apply(this,s)}}if(t){var f=r,p=["left","top","right","bottom","width","height"],d=[],v={v:{x:"Y",pos:p[1],oppos:p[3],crossPos:p[0],crossOpPos:p[2],size:p[5],crossSize:p[4],crossMinSize:"min-"+p[4],crossMaxSize:"max-"+p[4],client:"clientHeight",crossClient:"clientWidth",crossScroll:"scrollWidth",offset:"offsetHeight",crossOffset:"offsetWidth",offsetPos:"offsetTop",scroll:"scrollTop",scrollSize:"scrollHeight"},h:{x:"X",pos:p[0],oppos:p[2],crossPos:p[1],crossOpPos:p[3],size:p[4],crossSize:p[5],crossMinSize:"min-"+p[5],crossMaxSize:"max-"+p[5],client:"clientWidth",crossClient:"clientHeight",crossScroll:"scrollHeight",offset:"offsetWidth",crossOffset:"offsetHeight",offsetPos:"offsetLeft",scroll:"scrollLeft",scrollSize:"scrollWidth"}};r._instances=d,r.fn={constructor:function(t,i,r){var o=h(i);o.$=r,this.length=0,e.call(this,t,function(t,e){var r=l(t,o.direction),n=+r;if(n==n&&r!=s&&d[n]&&!i)this[e]=d[n];else{var h=c(o);o.root&&o.scroller?(h.scroller=o.$(o.scroller,t),h.scroller.length||(h.scroller=t)):h.scroller=t,h.root=t,this[e]=a(h)}this.length=e+1}),this.params=o},dispose:function(){var t=this.params;e(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,e.call(this,this,function(i){t.root.push(i.root)}),t.direction="v"==this.params.direction?"h":"v",t._chain=!0,r(t)}};var g={};g.prototype={_debounce:function(t,i){var e,r,n=this,l=function(){if(n._disposed)return clearTimeout(e),e=n=null,s;var a=o()-r;i>a&&a>=0?e=setTimeout(l,i-a):(e=null,t())};return function(){r=o(),e||(e=setTimeout(l,i))}},constructor:function(t){function i(t,i){return h(t,i)[0]}function e(t){var i=this.barMinSize||20;t>0&&i>t&&(t=i),this.bar&&h(this.bar).css(this.origin.size,parseInt(t,10)+"px")}function r(t){if(this.bar){var i=h(this.bar).css(this.origin.pos),s=+t+"px";s&&s!=i&&h(this.bar).css(this.origin.pos,s)}}function n(){return d[this.origin.client]-this.barTopLimit-this.bar[this.origin.offset]}function l(t){return t*n.call(this)+this.barTopLimit}function a(t){return(t-this.barTopLimit)/n.call(this)}function c(){return!1}var h,f,p,d,g,m,b,C,y,w,z;return w=y=o(),h=this.$=t.$,this.event=t.event,this.events={},this.root=t.root,this.scroller=i(t.scroller),this.bar=i(t.bar,this.root),d=this.track=i(t.track,this.root),!this.track&&this.bar&&(d=this.bar.parentNode),this.clipper=this.scroller.parentNode,this.direction=t.direction,this.origin=v[this.direction],this.barOnCls=t.barOnCls||"_baron",this.scrollingCls=t.scrollingCls,this.draggingCls=t.draggingCls,this.impact=t.impact,this.barTopLimit=0,C=1e3*t.pause||0,t.pause&&console.warn('Baronjs: "pause" param will be removed in 0.8+ version'),this.cursor=function(t){return t["client"+this.origin.x]||(((t.originalEvent||t).touches||{})[0]||{})["page"+this.origin.x]},this.pos=function(t){var i="page"+this.origin.x+"Offset",e=this.scroller[i]?i:this.origin.scroll;return t!==s&&(this.scroller[e]=t),this.scroller[e]},this.rpos=function(t){var i,s=this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client];return i=t?this.pos(t*s):this.pos(),i/(s||1)},this.barOn=function(t){this.barOnCls&&(t||this.scroller[this.origin.client]>=this.scroller[this.origin.scrollSize]?h(this.root).hasClass(this.barOnCls)&&h(this.root).removeClass(this.barOnCls):h(this.root).hasClass(this.barOnCls)||h(this.root).addClass(this.barOnCls))},this._pos0=function(t){p=this.cursor(t)-f},this.drag=function(t){var i=a.call(this,this.cursor(t)-p),s=this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client];this.scroller[this.origin.scroll]=i*s},this.selection=function(t){this.event(document,"selectpos selectstart",c,t?"off":"on")},this.resize=function(){function t(){var t,s,e=i.scroller[i.origin.crossOffset],r=i.scroller[i.origin.crossClient];if(r>0&&0===e&&(e=r+17),e){i.barOn(),r=i.scroller[i.origin.crossClient];var n=i.impact?"scroller"==i.impact:"v"==i.direction;if(n){var l=e-r;t=h(i.clipper).css(i.origin.crossSize),s=i.clipper[i.origin.crossClient]+l+"px",t!=s&&i._setCrossSizes(i.scroller,s)}else t=h(i.clipper).css(i.origin.crossSize),s=r+"px",t!=s&&i._setCrossSizes(i.clipper,s)}Array.prototype.unshift.call(arguments,"resize"),u.apply(i,arguments),w=o()}var i=this,s=0;o()-w<C&&(clearTimeout(g),s=C),s?g=setTimeout(t,s):t()},this.updatePositions=function(){var t,i=this;i.bar&&(t=(d[i.origin.client]-i.barTopLimit)*i.scroller[i.origin.client]/i.scroller[i.origin.scrollSize],parseInt(z,10)!=parseInt(t,10)&&(e.call(i,t),z=t),f=l.call(i,i.rpos()),r.call(i,f)),Array.prototype.unshift.call(arguments,"scroll"),u.apply(i,arguments),y=o()},this.scroll=function(){var t=0,i=this;o()-y<C&&(clearTimeout(m),t=C),t?m=setTimeout(function(){i.updatePositions()},t):i.updatePositions(),i.scrollingCls&&(b||this.$(this.scroller).addClass(this.scrollingCls),clearTimeout(b),b=setTimeout(function(){i.$(i.scroller).removeClass(i.scrollingCls),b=s},300))},this._setCrossSizes=function(t,i){var s={};s[this.origin.crossSize]=i,s[this.origin.crossMinSize]=i,s[this.origin.crossMaxSize]=i,this.$(t).css(s)},this},update:function(t){return u.call(this,"upd",t),this.resize(1),this.updatePositions(),this},dispose:function(t){n(this,this.event,"off"),l(this.root,t.direction,"off"),"v"==t.direction?this._setCrossSizes(this.scroller,""):this._setCrossSizes(this.clipper,""),this.barOn(!0),u.call(this,"dispose"),this._disposed=!0},on:function(t,i,s){for(var e=t.split(" "),r=0;r<e.length;r++)"init"==e[r]?i.call(this,s):(this.events[e[r]]=this.events[e[r]]||[],this.events[e[r]].push(function(t){i.call(this,t||s)}))}},r.fn.constructor.prototype=r.fn,g.prototype.constructor.prototype=g.prototype,r.noConflict=function(){return t.baron=f,r},r.version="0.8.0",i&&i.fn&&(i.fn.baron=r),t.baron=r,"undefined"!=typeof module&&(module.exports=r.noConflict())}}(window,window.$),function(t,s){var e=function(t){function e(t,i,e){var r=1==e?"pos":"oppos";l<(a.minView||0)&&(i=s),this.$(n[t]).css(this.origin.pos,"").css(this.origin.oppos,"").removeClass(a.outside),i!==s&&(i+="px",this.$(n[t]).css(this.origin[r],i).addClass(a.outside))}function r(t){try{i=document.createEvent("WheelEvent"),i.initWebKitWheelEvent(t.originalEvent.wheelDeltaX,t.originalEvent.wheelDeltaY),f.dispatchEvent(i),t.preventDefault()}catch(t){}}function o(t){var i;for(var s in t)a[s]=t[s];if(n=this.$(a.elements,this.scroller)){l=this.scroller[this.origin.client];for(var e=0;e<n.length;e++)i={},i[this.origin.size]=n[e][this.origin.offset],n[e].parentNode!==this.scroller&&this.$(n[e].parentNode).css(i),i={},i[this.origin.crossSize]=n[e].parentNode[this.origin.crossClient],this.$(n[e]).css(i),l-=n[e][this.origin.offset],u[e]=n[e].parentNode[this.origin.offsetPos],c[e]=c[e-1]||0,h[e]=h[e-1]||Math.min(u[e],0),n[e-1]&&(c[e]+=n[e-1][this.origin.offset],h[e]+=n[e-1][this.origin.offset]),(0!=e||0!=u[e])&&(this.event(n[e],"mousewheel",r,"off"),this.event(n[e],"mousewheel",r));a.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()),a.limiter===!1&&(this.barTopLimit=0)}var o={element:n,handler:function(){for(var t,i=d(this)[0].parentNode,s=i.offsetTop,e=0;e<n.length;e++)n[e]===this&&(t=e);var r=s-c[t];a.scroll?a.scroll({x1:v.scroller.scrollTop,x2:r}):v.scroller.scrollTop=r},type:"click"};a.clickable&&(this._eventHandlers.push(o),p(o.element,o.type,o.handler,"on"))}var n,l,a={outside:"",inside:"",before:"",after:"",past:"",future:"",radius:0,minView:0},c=[],h=[],u=[],f=this.scroller,p=this.event,d=this.$,v=this;this.on("init",o,t);var g=[],m=[];this.on("init scroll",function(){var t,i,r;if(n){for(var o,f=0;f<n.length;f++)t=0,u[f]-this.pos()<h[f]+a.radius?(t=1,i=c[f]):u[f]-this.pos()>h[f]+l-a.radius?(t=2,i=this.scroller[this.origin.client]-n[f][this.origin.offset]-c[f]-l):(t=3,i=s),r=!1,(u[f]-this.pos()<h[f]||u[f]-this.pos()>h[f]+l)&&(r=!0),(t!=g[f]||r!=m[f])&&(e.call(this,f,i,t),g[f]=t,m[f]=r,o=!0);if(o)for(f=0;f<n.length;f++)1==g[f]&&a.past&&this.$(n[f]).addClass(a.past).removeClass(a.future),2==g[f]&&a.future&&this.$(n[f]).addClass(a.future).removeClass(a.past),3==g[f]?((a.future||a.past)&&this.$(n[f]).removeClass(a.past).removeClass(a.future),a.inside&&this.$(n[f]).addClass(a.inside)):a.inside&&this.$(n[f]).removeClass(a.inside),g[f]!=g[f+1]&&1==g[f]&&a.before?this.$(n[f]).addClass(a.before).removeClass(a.after):g[f]!=g[f-1]&&2==g[f]&&a.after?this.$(n[f]).addClass(a.after).removeClass(a.before):this.$(n[f]).removeClass(a.before).removeClass(a.after),a.grad&&(m[f]?this.$(n[f]).addClass(a.grad):this.$(n[f]).removeClass(a.grad))}}),this.on("resize upd",function(t){o.call(this,t&&t.fix)})};baron.fn.fix=function(t){for(var i=0;this[i];)e.call(this[i],t),i++;return this}}(window),function(t){var i=t.MutationObserver||t.WebKitMutationObserver||t.MozMutationObserver||null,s=function(){function t(){o.root[o.origin.offset]?e():s()}function s(){r||(r=setInterval(function(){o.root[o.origin.offset]&&(e(),o.update())},300))}function e(){clearInterval(r),r=null}var r,o=this,n=o._debounce(function(){o.update()},300);this._observer=new i(function(){t(),o.update(),n()}),this.on("init",function(){o._observer.observe(o.root,{childList:!0,subtree:!0,characterData:!0}),t()}),this.on("dispose",function(){o._observer.disconnect(),e(),delete o._observer})};baron.fn.autoUpdate=function(t){if(!i)return this;for(var e=0;this[e];)s.call(this[e],t),e++;return this}}(window),function(t,i){var s=function(t){var i,s,e,r,o,n=this;r=t.screen||.9,t.forward&&(i=this.$(t.forward,this.clipper),o={element:i,handler:function(){var i=n.pos()-t.delta||30;n.pos(i)},type:"click"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")),t.backward&&(s=this.$(t.backward,this.clipper),o={element:s,handler:function(){var i=n.pos()+t.delta||30;n.pos(i)},type:"click"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")),t.track&&(e=t.track===!0?this.track:this.$(t.track,this.clipper)[0],e&&(o={element:e,handler:function(t){var i=t["offset"+n.origin.x],s=n.bar[n.origin.offsetPos],e=0;s>i?e=-1:i>s+n.bar[n.origin.offset]&&(e=1);var o=n.pos()+e*r*n.scroller[n.origin.client];n.pos(o)},type:"mousedown"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")))};baron.fn.controls=function(t){for(var i=0;this[i];)s.call(this[i],t),i++;return this}}(window),function(t,i){var s=function(t){function i(){return m.scroller[m.origin.scroll]+m.scroller[m.origin.offset]}function s(){return m.scroller[m.origin.scrollSize]}function e(){return m.scroller[m.origin.client]}function r(t,i){var s=5e-4*t;return Math.floor(i-s*(t+550))}function o(t){h=t,t?(n(),l=setInterval(n,200)):clearInterval(l)}function n(){var n,l,h={},z=i(),$=s(),S=1==b;if(l=0,b>0&&(l=40),n=r(y,l),z>=$-y&&b>-1?S&&(y+=n):y=0,0>y&&(y=0),h[f]=y+"px",e()<=s()){m.$(u).css(h);for(var _=0;_<v.length;_++)m.$(v[_].self).css(v[_].property,Math.min(y/p*100,100)+"%")}g&&y&&m.$(m.root).addClass(g),0==y&&t.onCollapse&&t.onCollapse(),b=0,a=setTimeout(function(){b=-1},w),d&&y>p&&!c&&(d(),c=!0),0==y?C++:C=0,C>1&&(o(!1),c=!1,g&&m.$(m.root).removeClass(g))}var l,a,c,h,u=this.$(t.block),f=t.size||this.origin.size,p=t.limit||80,d=t.onExpand,v=t.elements||[],g=t.inProgress||"",m=this,b=0,C=0,y=0,w=t.waiting||500;this.on("init",function(){o(!0)}),this.on("dispose",function(){o(!1)}),this.event(this.scroller,"mousewheel DOMMouseScroll",function(t){var e=t.wheelDelta<0||t.originalEvent&&t.originalEvent.wheelDelta<0||t.detail>0;e&&(b=1,clearTimeout(a),!h&&i()>=s()&&o(!0))})};baron.fn.pull=function(t){for(var i=0;this[i];)s.call(this[i],t),i++;return this}}(window);
!function(t,i){"use strict";function s(e){var r,o,n=!e,l={$:t.jQuery,direction:"v",barOnCls:"baron",resizeDebounce:0,event:function(t,i,s,r){e.$(t)[r||"on"](i,s)},cssGuru:!1};e=e||{};for(var c in l)e[c]===i&&(e[c]=l[c]);r=this instanceof e.$,r?e.root=o=this:o=e.$(e.root||e.scroller);var a=new s.fn.constructor(o,e,n);return a.autoUpdate&&!n&&a.autoUpdate(),a}function e(s,e){var r=0;for((s.length===i||s===t)&&(s=[s]);s[r];)e.call(this,s[r],r),r++}function r(){return(new Date).getTime()}function o(i,s,r){i._eventHandlers=i._eventHandlers||[{element:i.scroller,handler:function(t){i.scroll(t)},type:"scroll"},{element:i.root,handler:function(){i.update()},type:"transitionend animationend"},{element:i.scroller,handler:function(){i.update()},type:"keyup"},{element:i.bar,handler:function(t){t.preventDefault(),i.selection(),i.drag.now=1,i.draggingCls&&h(i.bar).addClass(i.draggingCls)},type:"touchstart mousedown"},{element:document,handler:function(){i.selection(1),i.drag.now=0,i.draggingCls&&h(i.bar).removeClass(i.draggingCls)},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"}],e(i._eventHandlers,function(t){t.element&&s(t.element,t.type,t.handler,r)})}function n(t,i,s,e){var r="data-baron-"+i+"-id";if("on"==s)t.setAttribute(r,e);else{if("off"!=s)return t.getAttribute(r);t.removeAttribute(r)}}function l(t){n(t.root,t.direction)&&console.log("Error! Baron for this node already initialized",t.root);var i=new v.prototype.constructor(t);return o(i,t.event,"on"),n(i.root,t.direction,"on",p.length),p.push(i),i.update(),i}function c(t){var i={};t=t||{};for(var s in t)t.hasOwnProperty(s)&&(i[s]=t[s]);return i}function a(t){if(this.events&&this.events[t])for(var i=0;i<this.events[t].length;i++){var s=Array.prototype.slice.call(arguments,1);this.events[t][i].apply(this,s)}}if(t){var h=t.$,u=s,f=["left","top","right","bottom","width","height"],p=[],d={v:{x:"Y",pos:f[1],oppos:f[3],crossPos:f[0],crossOpPos:f[2],size:f[5],crossSize:f[4],crossMinSize:"min-"+f[4],crossMaxSize:"max-"+f[4],client:"clientHeight",crossClient:"clientWidth",crossScroll:"scrollWidth",offset:"offsetHeight",crossOffset:"offsetWidth",offsetPos:"offsetTop",scroll:"scrollTop",scrollSize:"scrollHeight"},h:{x:"X",pos:f[0],oppos:f[2],crossPos:f[1],crossOpPos:f[3],size:f[4],crossSize:f[5],crossMinSize:"min-"+f[5],crossMaxSize:"max-"+f[5],client:"clientWidth",crossClient:"clientHeight",crossScroll:"scrollHeight",offset:"offsetWidth",crossOffset:"offsetHeight",offsetPos:"offsetLeft",scroll:"scrollLeft",scrollSize:"scrollWidth"}};s._instances=p,s.fn={constructor:function(t,s,r){var o=c(s);o.event=function(t,i,r,o){e(t,function(t){s.event(t,i,r,o)})},this.length=0,e.call(this,t,function(t,s){var e=n(t,o.direction),a=+e;if(a==a&&e!=i&&p[a]&&r)this[s]=p[a];else{var h=c(o);o.root&&o.scroller?(h.scroller=o.$(o.scroller,t),h.scroller.length||(h.scroller=t)):h.scroller=t,h.root=t,this[s]=l(h)}this.length=s+1}),this.params=o},dispose:function(){var t=this.params;e(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,e.call(this,this,function(i){t.root.push(i.root)}),t.direction="v"==this.params.direction?"h":"v",t._chain=!0,s(t)}};var v={};v.prototype={_debounce:function(t,s){var e,o,n=this,l=function(){if(n._disposed)return clearTimeout(e),e=n=null,i;var c=r()-o;s>c&&c>=0?e=setTimeout(l,s-c):(e=null,t())};return function(){o=r(),e||(e=setTimeout(l,s))}},constructor:function(t){function s(t,i){return u(t,i)[0]}function e(t){var i=this.barMinSize||20;t>0&&i>t&&(t=i),this.bar&&u(this.bar).css(this.origin.size,parseInt(t,10)+"px")}function o(t){if(this.bar){var i=u(this.bar).css(this.origin.pos),s=+t+"px";s&&s!=i&&u(this.bar).css(this.origin.pos,s)}}function n(){return v[this.origin.client]-this.barTopLimit-this.bar[this.origin.offset]}function l(t){return t*n.call(this)+this.barTopLimit}function c(t){return(t-this.barTopLimit)/n.call(this)}function h(){return!1}var u,f,p,v,g,m,b,C,z;return C=b=r(),u=this.$=t.$,this.event=t.event,this.events={},this.root=t.root,this.scroller=s(t.scroller),this.bar=s(t.bar,this.root),v=this.track=s(t.track,this.root),!this.track&&this.bar&&(v=this.bar.parentNode),this.clipper=this.scroller.parentNode,this.direction=t.direction,this.origin=d[this.direction],this.barOnCls=t.barOnCls||"_baron",this.scrollingCls=t.scrollingCls,this.draggingCls=t.draggingCls,this.impact=t.impact,this.barTopLimit=0,this.resizeDebounce=t.resizeDebounce,this.cursor=function(t){return t["client"+this.origin.x]||(((t.originalEvent||t).touches||{})[0]||{})["page"+this.origin.x]},this.pos=function(t){var s="page"+this.origin.x+"Offset",e=this.scroller[s]?s:this.origin.scroll;return t!==i&&(this.scroller[e]=t),this.scroller[e]},this.rpos=function(t){var i,s=this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client];return i=t?this.pos(t*s):this.pos(),i/(s||1)},this.barOn=function(t){this.barOnCls&&(t||this.scroller[this.origin.client]>=this.scroller[this.origin.scrollSize]?u(this.root).hasClass(this.barOnCls)&&u(this.root).removeClass(this.barOnCls):u(this.root).hasClass(this.barOnCls)||u(this.root).addClass(this.barOnCls))},this._pos0=function(t){p=this.cursor(t)-f},this.drag=function(t){var i=c.call(this,this.cursor(t)-p),s=this.scroller[this.origin.scrollSize]-this.scroller[this.origin.client];this.scroller[this.origin.scroll]=i*s},this.selection=function(t){this.event(document,"selectpos selectstart",h,t?"off":"on")},this.resize=function(){function t(){var t,i,e=s.scroller[s.origin.crossOffset],o=s.scroller[s.origin.crossClient];if(o>0&&0===e&&(e=o+17),e){s.barOn(),o=s.scroller[s.origin.crossClient];var n=s.impact?"scroller"==s.impact:"v"==s.direction;if(n){var l=e-o;t=u(s.clipper).css(s.origin.crossSize),i=s.clipper[s.origin.crossClient]+l+"px",t!=i&&s._setCrossSizes(s.scroller,i)}else t=u(s.clipper).css(s.origin.crossSize),i=o+"px",t!=i&&s._setCrossSizes(s.clipper,i)}Array.prototype.unshift.call(arguments,"resize"),a.apply(s,arguments),C=r()}var s=this,e=s.resizeDebounce===i?300:s.resizeDebounce,o=0;r()-C<e&&(clearTimeout(g),o=e),o?g=setTimeout(t,o):t()},this.updatePositions=function(){var t,i=this;i.bar&&(t=(v[i.origin.client]-i.barTopLimit)*i.scroller[i.origin.client]/i.scroller[i.origin.scrollSize],parseInt(z,10)!=parseInt(t,10)&&(e.call(i,t),z=t),f=l.call(i,i.rpos()),o.call(i,f)),Array.prototype.unshift.call(arguments,"scroll"),a.apply(i,arguments),b=r()},this.scroll=function(){var t=this;t.updatePositions(),t.scrollingCls&&(m||t.$(t.scroller).addClass(t.scrollingCls),clearTimeout(m),m=setTimeout(function(){t.$(t.scroller).removeClass(t.scrollingCls),m=i},300))},this._setCrossSizes=function(t,i){var s={};s[this.origin.crossSize]=i,s[this.origin.crossMinSize]=i,s[this.origin.crossMaxSize]=i,this.$(t).css(s)},this._dumbCss=function(i){if(!t.cssGuru){var s=i?"hidden":null,e=i?"scroll":null;this.$(this.clipper).css({overflow:s});var r="v"==this.direction?"y":"x",o={};o["overflow-"+r]=e,o["box-sizing"]="border-box",o.margin="0",o.border="0",this.$(this.scroller).css(o)}},this},update:function(t){return a.call(this,"upd",t),this._dumbCss(!0),this.resize(1),this.updatePositions(),this},dispose:function(t){o(this,this.event,"off"),n(this.root,t.direction,"off"),"v"==t.direction?this._setCrossSizes(this.scroller,""):this._setCrossSizes(this.clipper,""),this._dumbCss(!1),this.barOn(!0),a.call(this,"dispose"),this._disposed=!0},on:function(t,i,s){for(var e=t.split(" "),r=0;r<e.length;r++)"init"==e[r]?i.call(this,s):(this.events[e[r]]=this.events[e[r]]||[],this.events[e[r]].push(function(t){i.call(this,t||s)}))}},s.fn.constructor.prototype=s.fn,v.prototype.constructor.prototype=v.prototype,s.noConflict=function(){return t.baron=u,s},s.version="0.9.0-alpha",h&&h.fn&&(h.fn.baron=s),t.baron=s,"undefined"!=typeof module&&(module.exports=s.noConflict())}}(window),function(t,s){var e=function(t){function e(t,i,e){var r=1==e?"pos":"oppos";l<(c.minView||0)&&(i=s),this.$(n[t]).css(this.origin.pos,"").css(this.origin.oppos,"").removeClass(c.outside),i!==s&&(i+="px",this.$(n[t]).css(this.origin[r],i).addClass(c.outside))}function r(t){try{i=document.createEvent("WheelEvent"),i.initWebKitWheelEvent(t.originalEvent.wheelDeltaX,t.originalEvent.wheelDeltaY),f.dispatchEvent(i),t.preventDefault()}catch(t){}}function o(t){var i;for(var s in t)c[s]=t[s];if(n=this.$(c.elements,this.scroller)){l=this.scroller[this.origin.client];for(var e=0;e<n.length;e++)i={},i[this.origin.size]=n[e][this.origin.offset],n[e].parentNode!==this.scroller&&this.$(n[e].parentNode).css(i),i={},i[this.origin.crossSize]=n[e].parentNode[this.origin.crossClient],this.$(n[e]).css(i),l-=n[e][this.origin.offset],u[e]=n[e].parentNode[this.origin.offsetPos],a[e]=a[e-1]||0,h[e]=h[e-1]||Math.min(u[e],0),n[e-1]&&(a[e]+=n[e-1][this.origin.offset],h[e]+=n[e-1][this.origin.offset]),(0!=e||0!=u[e])&&(this.event(n[e],"mousewheel",r,"off"),this.event(n[e],"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,s=i.offsetTop,e=0;e<n.length;e++)n[e]===this&&(t=e);var r=s-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,"on"))}var n,l,c={outside:"",inside:"",before:"",after:"",past:"",future:"",radius:0,minView:0},a=[],h=[],u=[],f=this.scroller,p=this.event,d=this.$,v=this;this.on("init",o,t);var g=[],m=[];this.on("init scroll",function(){var t,i,r;if(n){for(var o,f=0;f<n.length;f++)t=0,u[f]-this.pos()<h[f]+c.radius?(t=1,i=a[f]):u[f]-this.pos()>h[f]+l-c.radius?(t=2,i=this.scroller[this.origin.client]-n[f][this.origin.offset]-a[f]-l):(t=3,i=s),r=!1,(u[f]-this.pos()<h[f]||u[f]-this.pos()>h[f]+l)&&(r=!0),(t!=g[f]||r!=m[f])&&(e.call(this,f,i,t),g[f]=t,m[f]=r,o=!0);if(o)for(f=0;f<n.length;f++)1==g[f]&&c.past&&this.$(n[f]).addClass(c.past).removeClass(c.future),2==g[f]&&c.future&&this.$(n[f]).addClass(c.future).removeClass(c.past),3==g[f]?((c.future||c.past)&&this.$(n[f]).removeClass(c.past).removeClass(c.future),c.inside&&this.$(n[f]).addClass(c.inside)):c.inside&&this.$(n[f]).removeClass(c.inside),g[f]!=g[f+1]&&1==g[f]&&c.before?this.$(n[f]).addClass(c.before).removeClass(c.after):g[f]!=g[f-1]&&2==g[f]&&c.after?this.$(n[f]).addClass(c.after).removeClass(c.before):this.$(n[f]).removeClass(c.before).removeClass(c.after),c.grad&&(m[f]?this.$(n[f]).addClass(c.grad):this.$(n[f]).removeClass(c.grad))}}),this.on("resize upd",function(t){o.call(this,t&&t.fix)})};baron.fn.fix=function(t){for(var i=0;this[i];)e.call(this[i],t),i++;return this}}(window),function(t){var i=t.MutationObserver||t.WebKitMutationObserver||t.MozMutationObserver||null,s=function(){function t(){o.root[o.origin.offset]?e():s()}function s(){r||(r=setInterval(function(){o.root[o.origin.offset]&&(e(),o.update())},300))}function e(){clearInterval(r),r=null}var r,o=this,n=o._debounce(function(){o.update()},300);this._observer=new i(function(){t(),o.update(),n()}),this.on("init",function(){o._observer.observe(o.root,{childList:!0,subtree:!0,characterData:!0}),t()}),this.on("dispose",function(){o._observer.disconnect(),e(),delete o._observer})};baron.fn.autoUpdate=function(t){if(!i)return this;for(var e=0;this[e];)s.call(this[e],t),e++;return this}}(window),function(t,i){var s=function(t){var i,s,e,r,o,n=this;r=t.screen||.9,t.forward&&(i=this.$(t.forward,this.clipper),o={element:i,handler:function(){var i=n.pos()-t.delta||30;n.pos(i)},type:"click"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")),t.backward&&(s=this.$(t.backward,this.clipper),o={element:s,handler:function(){var i=n.pos()+t.delta||30;n.pos(i)},type:"click"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")),t.track&&(e=t.track===!0?this.track:this.$(t.track,this.clipper)[0],e&&(o={element:e,handler:function(t){var i=t["offset"+n.origin.x],s=n.bar[n.origin.offsetPos],e=0;s>i?e=-1:i>s+n.bar[n.origin.offset]&&(e=1);var o=n.pos()+e*r*n.scroller[n.origin.client];n.pos(o)},type:"mousedown"},this._eventHandlers.push(o),this.event(o.element,o.type,o.handler,"on")))};baron.fn.controls=function(t){for(var i=0;this[i];)s.call(this[i],t),i++;return this}}(window),function(t,i){var s=function(t){function i(){return m.scroller[m.origin.scroll]+m.scroller[m.origin.offset]}function s(){return m.scroller[m.origin.scrollSize]}function e(){return m.scroller[m.origin.client]}function r(t,i){var s=5e-4*t;return Math.floor(i-s*(t+550))}function o(t){h=t,t?(n(),l=setInterval(n,200)):clearInterval(l)}function n(){var n,l,h={},w=i(),$=s(),S=1==b;if(l=0,b>0&&(l=40),n=r(z,l),w>=$-z&&b>-1?S&&(z+=n):z=0,0>z&&(z=0),h[f]=z+"px",e()<=s()){m.$(u).css(h);for(var _=0;_<v.length;_++)m.$(v[_].self).css(v[_].property,Math.min(z/p*100,100)+"%")}g&&z&&m.$(m.root).addClass(g),0==z&&t.onCollapse&&t.onCollapse(),b=0,c=setTimeout(function(){b=-1},y),d&&z>p&&!a&&(d(),a=!0),0==z?C++:C=0,C>1&&(o(!1),a=!1,g&&m.$(m.root).removeClass(g))}var l,c,a,h,u=this.$(t.block),f=t.size||this.origin.size,p=t.limit||80,d=t.onExpand,v=t.elements||[],g=t.inProgress||"",m=this,b=0,C=0,z=0,y=t.waiting||500;this.on("init",function(){o(!0)}),this.on("dispose",function(){o(!1)}),this.event(this.scroller,"mousewheel DOMMouseScroll",function(t){var e=t.wheelDelta<0||t.originalEvent&&t.originalEvent.wheelDelta<0||t.detail>0;e&&(b=1,clearTimeout(c),!h&&i()>=s()&&o(!0))})};baron.fn.pull=function(t){for(var i=0;this[i];)s.call(this[i],t),i++;return this}}(window);
{
"name": "baron",
"main": "baron.js",
"version": "0.7.14",
"version": "1.0.0",
"homepage": "https://github.com/Diokuz/baron",

@@ -6,0 +6,0 @@ "authors": [

@@ -0,1 +1,9 @@

## 0.9.0
- add `cssGuru` option for css guru.
- add default css.
- remove resizeDebounce param.
- fix phantom tests.
- remove pause param.
## 0.8.0

@@ -2,0 +10,0 @@

@@ -1,2 +0,2 @@

(function(window, $, undefined) {
(function(window, undefined) {
'use strict';

@@ -6,2 +6,3 @@

var $ = window.$;
var _baron = baron; // Stored baron value for noConflict usage

@@ -32,31 +33,38 @@ var pos = ['left', 'top', 'right', 'bottom', 'width', 'height'];

function each(obj, iterator) {
var i = 0;
// window.baron and jQuery.fn.baron points to this function
function baron(params) {
var jQueryMode;
var roots;
var empty = !params;
var defaultParams = {
$: window.jQuery,
direction: 'v',
barOnCls: 'baron',
resizeDebounce: 0,
event: function(elem, event, func, mode) {
params.$(elem)[mode || 'on'](event, func);
},
cssGuru: false
};
if (obj.length === undefined || obj === window) obj = [obj];
params = params || {};
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// Extending default params by user-defined params
for (var key in defaultParams) {
if (params[key] === undefined) {
params[key] = defaultParams[key];
}
};
function baron(params) {
var jQueryMode,
roots,
$;
jQueryMode = this instanceof params.$; // this - global context or jQuery instance
params = params || {};
$ = params.$ || $ || window.jQuery;
jQueryMode = this instanceof $; // this - window or jQuery instance
if (jQueryMode) {
params.root = roots = this;
} else {
roots = $(params.root || params.scroller);
roots = params.$(params.root || params.scroller);
}
var instance = new baron.fn.constructor(roots, params, $);
var instance = new baron.fn.constructor(roots, params, empty);
if (instance.autoUpdate) {
if (instance.autoUpdate && !empty) {
instance.autoUpdate();

@@ -68,2 +76,13 @@ }

function arrayEach(obj, iterator) {
var i = 0;
if (obj.length === undefined || obj === window) obj = [obj];
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// shortcut for getTime

@@ -77,8 +96,15 @@ function getTime() {

baron.fn = {
constructor: function(roots, input, $) {
var params = validate(input);
constructor: function(roots, totalParams, noUserParams) {
var params = clone(totalParams);
params.$ = $;
// Intrinsic params.event is not the same as totalParams.event
params.event = function(elems, e, func, mode) {
arrayEach(elems, function(elem) {
totalParams.event(elem, e, func, mode);
});
};
this.length = 0;
each.call(this, roots, function(root, i) {
arrayEach.call(this, roots, function(root, i) {
var attr = manageAttr(root, params.direction);

@@ -89,19 +115,19 @@ var id = +attr; // Could be NaN

// but baron(params) will throw an Error as a second initialization
if (id == id && attr != undefined && instances[id] && !input) {
if (id == id && attr != undefined && instances[id] && noUserParams) {
this[i] = instances[id];
} else {
var localParams = clone(params);
var perInstanceParams = clone(params);
// root and scroller can be different nodes
if (params.root && params.scroller) {
localParams.scroller = params.$(params.scroller, root);
if (!localParams.scroller.length) {
localParams.scroller = root;
perInstanceParams.scroller = params.$(params.scroller, root);
if (!perInstanceParams.scroller.length) {
perInstanceParams.scroller = root;
}
} else {
localParams.scroller = root;
perInstanceParams.scroller = root;
}
localParams.root = root;
this[i] = init(localParams);
perInstanceParams.root = root;
this[i] = init(perInstanceParams);
}

@@ -118,3 +144,3 @@

each(this, function(item) {
arrayEach(this, function(item) {
item.dispose(params);

@@ -139,3 +165,3 @@ });

each.call(this, this, function(elem) {
arrayEach.call(this, this, function(elem) {
params.root.push(elem.root);

@@ -250,3 +276,3 @@ });

each(item._eventHandlers, function(event) {
arrayEach(item._eventHandlers, function(event) {
if (event.element) {

@@ -322,11 +348,5 @@ eventManager(event.element, event.type, event.handler, mode);

output.direction = output.direction || 'v';
var event = input.event || function(elem, event, func, mode) {
output.$(elem)[mode || 'on'](event, func);
};
output.event = function(elems, e, func, mode) {
each(elems, function(elem) {
event(elem, e, func, mode);
arrayEach(elems, function(elem) {
input.event(elem, e, func, mode);
});

@@ -353,2 +373,3 @@ };

// underscore.js realization
// used in autoUpdate plugin
_debounce: function(func, wait) {

@@ -400,5 +421,3 @@ var self = this,

resizePauseTimer,
scrollPauseTimer,
scrollingTimer,
pause,
scrollLastFire,

@@ -436,8 +455,4 @@ resizeLastFire,

this.barTopLimit = 0;
pause = params.pause * 1000 || 0;
this.resizeDebounce = params.resizeDebounce;
if (params.pause) {
console.warn('Baronjs: "pause" param will be removed in 0.8+ version');
}
// Updating height or width of bar

@@ -554,9 +569,11 @@ function setBarSize(size) {

// onResize & DOM modified handler
// also fires on init
this.resize = function() {
var self = this,
delay = 0;
var self = this;
var minPeriod = (self.resizeDebounce === undefined) ? 300 : self.resizeDebounce;
var delay = 0;
if (getTime() - resizeLastFire < pause) {
if (getTime() - resizeLastFire < minPeriod) {
clearTimeout(resizePauseTimer);
delay = pause;
delay = minPeriod;
}

@@ -648,21 +665,9 @@

this.scroll = function() {
var delay = 0,
self = this;
var self = this;
if (getTime() - scrollLastFire < pause) {
clearTimeout(scrollPauseTimer);
delay = pause;
}
self.updatePositions();
if (delay) {
scrollPauseTimer = setTimeout(function() {
self.updatePositions();
}, delay);
} else {
self.updatePositions();
}
if (self.scrollingCls) {
if (!scrollingTimer) {
this.$(this.scroller).addClass(this.scrollingCls);
self.$(self.scroller).addClass(self.scrollingCls);
}

@@ -691,8 +696,29 @@ clearTimeout(scrollingTimer);

// Set most common css rules
this._dumbCss = function(on) {
if (params.cssGuru) return;
var overflow = on ? 'hidden' : null;
var scroll = on ? 'scroll' : null;
this.$(this.clipper).css({overflow: overflow});
var axis = this.direction == 'v' ? 'y' : 'x';
var scrollerCss = {};
scrollerCss['overflow-' + axis] = scroll;
scrollerCss['box-sizing'] = 'border-box';
scrollerCss.margin = '0';
scrollerCss.border = '0';
this.$(this.scroller).css(scrollerCss);
};
return this;
},
// fires on any update and on init
update: function(params) {
fire.call(this, 'upd', params); // Update all plugins' params
this._dumbCss(true);
this.resize(1);

@@ -713,2 +739,3 @@ this.updatePositions();

}
this._dumbCss(false);
this.barOn(true);

@@ -746,3 +773,3 @@ fire.call(this, 'dispose');

baron.version = '0.8.0';
baron.version = '0.9.0-alpha';

@@ -757,3 +784,3 @@ if ($ && $.fn) { // Adding baron to jQuery as plugin

}
})(window, window.$);
})(window);

@@ -760,0 +787,0 @@ /* Fixable elements plugin for baron 0.6+ */

{
"name": "baron",
"description": "A small, fast and crossbrowser custom scrollbar with native system scroll mechanic.",
"version": "0.8.0",
"version": "1.0.0",
"readmeFilename": "README.md",

@@ -35,3 +35,3 @@ "homepage": "https://github.com/Diokuz/baron",

"mocha": "~2.3.2",
"mocha-phantomjs": "~3.6.0",
"mocha-phantomjs": "~4.0.1",
"phantomjs": "~1.9.7",

@@ -38,0 +38,0 @@ "run-sequence": "^1.1.3",

[![Build Status](https://travis-ci.org/Diokuz/baron.svg)](https://travis-ci.org/Diokuz/baron)
*You cannot change the world, but you can change a scrollbar!*
Baron — a small, fast and crossbrowser custom scrollbar with native system scroll mechanic.

@@ -20,2 +22,6 @@

## 1.0 migration
If you have any problems, just set [`cssGuru`](#params) option to `true`.
## Simple usage

@@ -108,4 +114,11 @@

<a name="params"></a>
```js
var params = {
// Flag, indicating that you know your css,
// and baron must minimize the count of setted inline css rules
// (i.e. overflow: hidden for clipper and overflow-y: scroll for scroller)
// Default: false
cssGuru: true,
// Whos width (height) will be setted?

@@ -132,3 +145,3 @@ // Default: 'scroller' for vertical, 'clipper' for horizontal direction.

// CSS classname for `scroller` when its needed (when content height above scroller heights)
// Default: ''
// Default: 'baron'
barOnCls: 'baron',

@@ -139,3 +152,3 @@ // Note: by default scroller__bar should be invisible

// You can boost performance by using `_scrolling {pointer-events: none}`
// Default: ''
// Default: undefined
scrollingCls: '_scrolling',

@@ -145,3 +158,3 @@

// Its better than `.bar:hover` rule
// Default: ''
// Default: undefined
draggingCls: '_dragging',

@@ -153,6 +166,5 @@

// Minimum time delay between two scroll or resize events fires in seconds
// Default: 0
// @deprecated
pause: .2,
// Minimum time delay between two resize events fires in seconds [0..1] or milliseconds (1..∞)
// Default: 300 ms
resizeDebounce: .2, // s

@@ -159,0 +171,0 @@ // Local copy of jQuery-like utility

@@ -1,2 +0,2 @@

(function(window, $, undefined) {
(function(window, undefined) {
'use strict';

@@ -6,2 +6,3 @@

var $ = window.$;
var _baron = baron; // Stored baron value for noConflict usage

@@ -32,31 +33,38 @@ var pos = ['left', 'top', 'right', 'bottom', 'width', 'height'];

function each(obj, iterator) {
var i = 0;
// window.baron and jQuery.fn.baron points to this function
function baron(params) {
var jQueryMode;
var roots;
var empty = !params;
var defaultParams = {
$: window.jQuery,
direction: 'v',
barOnCls: 'baron',
resizeDebounce: 0,
event: function(elem, event, func, mode) {
params.$(elem)[mode || 'on'](event, func);
},
cssGuru: false
};
if (obj.length === undefined || obj === window) obj = [obj];
params = params || {};
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// Extending default params by user-defined params
for (var key in defaultParams) {
if (params[key] === undefined) {
params[key] = defaultParams[key];
}
};
function baron(params) {
var jQueryMode,
roots,
$;
jQueryMode = this instanceof params.$; // this - global context or jQuery instance
params = params || {};
$ = params.$ || $ || window.jQuery;
jQueryMode = this instanceof $; // this - window or jQuery instance
if (jQueryMode) {
params.root = roots = this;
} else {
roots = $(params.root || params.scroller);
roots = params.$(params.root || params.scroller);
}
var instance = new baron.fn.constructor(roots, params, $);
var instance = new baron.fn.constructor(roots, params, empty);
if (instance.autoUpdate) {
if (instance.autoUpdate && !empty) {
instance.autoUpdate();

@@ -68,2 +76,13 @@ }

function arrayEach(obj, iterator) {
var i = 0;
if (obj.length === undefined || obj === window) obj = [obj];
while (obj[i]) {
iterator.call(this, obj[i], i);
i++;
}
}
// shortcut for getTime

@@ -77,8 +96,15 @@ function getTime() {

baron.fn = {
constructor: function(roots, input, $) {
var params = validate(input);
constructor: function(roots, totalParams, noUserParams) {
var params = clone(totalParams);
params.$ = $;
// Intrinsic params.event is not the same as totalParams.event
params.event = function(elems, e, func, mode) {
arrayEach(elems, function(elem) {
totalParams.event(elem, e, func, mode);
});
};
this.length = 0;
each.call(this, roots, function(root, i) {
arrayEach.call(this, roots, function(root, i) {
var attr = manageAttr(root, params.direction);

@@ -89,19 +115,19 @@ var id = +attr; // Could be NaN

// but baron(params) will throw an Error as a second initialization
if (id == id && attr != undefined && instances[id] && !input) {
if (id == id && attr != undefined && instances[id] && noUserParams) {
this[i] = instances[id];
} else {
var localParams = clone(params);
var perInstanceParams = clone(params);
// root and scroller can be different nodes
if (params.root && params.scroller) {
localParams.scroller = params.$(params.scroller, root);
if (!localParams.scroller.length) {
localParams.scroller = root;
perInstanceParams.scroller = params.$(params.scroller, root);
if (!perInstanceParams.scroller.length) {
perInstanceParams.scroller = root;
}
} else {
localParams.scroller = root;
perInstanceParams.scroller = root;
}
localParams.root = root;
this[i] = init(localParams);
perInstanceParams.root = root;
this[i] = init(perInstanceParams);
}

@@ -118,3 +144,3 @@

each(this, function(item) {
arrayEach(this, function(item) {
item.dispose(params);

@@ -139,3 +165,3 @@ });

each.call(this, this, function(elem) {
arrayEach.call(this, this, function(elem) {
params.root.push(elem.root);

@@ -250,3 +276,3 @@ });

each(item._eventHandlers, function(event) {
arrayEach(item._eventHandlers, function(event) {
if (event.element) {

@@ -322,11 +348,5 @@ eventManager(event.element, event.type, event.handler, mode);

output.direction = output.direction || 'v';
var event = input.event || function(elem, event, func, mode) {
output.$(elem)[mode || 'on'](event, func);
};
output.event = function(elems, e, func, mode) {
each(elems, function(elem) {
event(elem, e, func, mode);
arrayEach(elems, function(elem) {
input.event(elem, e, func, mode);
});

@@ -353,2 +373,3 @@ };

// underscore.js realization
// used in autoUpdate plugin
_debounce: function(func, wait) {

@@ -400,5 +421,3 @@ var self = this,

resizePauseTimer,
scrollPauseTimer,
scrollingTimer,
pause,
scrollLastFire,

@@ -436,8 +455,4 @@ resizeLastFire,

this.barTopLimit = 0;
pause = params.pause * 1000 || 0;
this.resizeDebounce = params.resizeDebounce;
if (params.pause) {
console.warn('Baronjs: "pause" param will be removed in 0.8+ version');
}
// Updating height or width of bar

@@ -554,9 +569,11 @@ function setBarSize(size) {

// onResize & DOM modified handler
// also fires on init
this.resize = function() {
var self = this,
delay = 0;
var self = this;
var minPeriod = (self.resizeDebounce === undefined) ? 300 : self.resizeDebounce;
var delay = 0;
if (getTime() - resizeLastFire < pause) {
if (getTime() - resizeLastFire < minPeriod) {
clearTimeout(resizePauseTimer);
delay = pause;
delay = minPeriod;
}

@@ -648,21 +665,9 @@

this.scroll = function() {
var delay = 0,
self = this;
var self = this;
if (getTime() - scrollLastFire < pause) {
clearTimeout(scrollPauseTimer);
delay = pause;
}
self.updatePositions();
if (delay) {
scrollPauseTimer = setTimeout(function() {
self.updatePositions();
}, delay);
} else {
self.updatePositions();
}
if (self.scrollingCls) {
if (!scrollingTimer) {
this.$(this.scroller).addClass(this.scrollingCls);
self.$(self.scroller).addClass(self.scrollingCls);
}

@@ -691,8 +696,29 @@ clearTimeout(scrollingTimer);

// Set most common css rules
this._dumbCss = function(on) {
if (params.cssGuru) return;
var overflow = on ? 'hidden' : null;
var scroll = on ? 'scroll' : null;
this.$(this.clipper).css({overflow: overflow});
var axis = this.direction == 'v' ? 'y' : 'x';
var scrollerCss = {};
scrollerCss['overflow-' + axis] = scroll;
scrollerCss['box-sizing'] = 'border-box';
scrollerCss.margin = '0';
scrollerCss.border = '0';
this.$(this.scroller).css(scrollerCss);
};
return this;
},
// fires on any update and on init
update: function(params) {
fire.call(this, 'upd', params); // Update all plugins' params
this._dumbCss(true);
this.resize(1);

@@ -713,2 +739,3 @@ this.updatePositions();

}
this._dumbCss(false);
this.barOn(true);

@@ -746,3 +773,3 @@ fire.call(this, 'dispose');

baron.version = '0.8.0';
baron.version = '1.0.0';

@@ -757,2 +784,2 @@ if ($ && $.fn) { // Adding baron to jQuery as plugin

}
})(window, window.$);
})(window);

@@ -50,13 +50,36 @@ var barOnCls = 'baron';

it.skip("Повторная инициализация бросает ошибку", function(done) {
try {
baron = $('.wrapper._origin .scroller').baron({
bar: '.scroller__bar',
barOnCls: barOnCls
});
} catch (e) {
done();
}
it("Повторная инициализация бросает ошибку", function() {
var _log = console.log;
var i = 0;
console.log = function() {
i++;
};
baron = $('.wrapper._origin .scroller').baron({
bar: '.scroller__bar',
barOnCls: barOnCls
});
assert(i == 3);
console.log = _log;
});
it("Повторный вызов барона без параметров не бросает ошибку", function() {
var _log = console.log;
var i = 0;
console.log = function() {
i++;
};
$('.wrapper._origin .scroller').baron({
bar: '.scroller__bar',
barOnCls: barOnCls
});
$('.wrapper._origin .scroller').baron(); // another three times
assert.equal(i, 3);
console.log = _log;
});
it("После вызова метода dispose удаляет атрибуты и классы", function() {

@@ -94,2 +117,6 @@ var sizeDim = baron[0].origin.crossSize;

describe("noParams mode", function() {
before(function() {
$('.wrapper._origin').html(originalHTML);
});
it("Инициализация без параметров при имеющемся на странице бароне", function() {

@@ -109,12 +136,51 @@ // Суть бага в следующем: manageAttr возвращал undefined, который

// uncomment in 0.8
// first.baron().dispose();
// second.baron().dispose;
first.baron().dispose();
second.baron().dispose();
// var disposeAttr = second.attr('data-baron-v-id');
var disposeAttr = second.attr('data-baron-v-id');
// assert.equal(disposeAttr, "");
assert.equal(disposeAttr, undefined);
});
});
describe("cssGuru param", function() {
before(function() {
$('.wrapper._origin').html(originalHTML);
});
it("Навешиваются все дефолтные стили", function() {
var notCssGuru = $('.wrapper._origin.wrapper_headers .scroller');
var cssGuru = $('.wrapper._origin.wrapper_ .scroller');
notCssGuru.baron({cssGuru: false});
cssGuru.baron({cssGuru: true});
var notCssGuruStyles = {
margin: notCssGuru[0].style.margin,
border: notCssGuru[0].style.border,
padding: notCssGuru[0].style.padding,
boxSizing: notCssGuru[0].style.boxSizing
};
var cssGuruStyles = {
margin: cssGuru[0].style.margin,
border: cssGuru[0].style.border,
padding: cssGuru[0].style.padding,
boxSizing: cssGuru[0].style.boxSizing
};
assert.deepEqual(notCssGuruStyles, {
margin: '0px',
border: '0px',
padding: '',
boxSizing: 'border-box'
});
assert.deepEqual(cssGuruStyles, {
margin: '',
border: '',
padding: '',
boxSizing: ''
});
});
});
describe("Навешивание классов", function() {

@@ -157,20 +223,14 @@ it("После инициализации нет блокирующего класса _scrolling", function() {

it("Toggling barOnCls.", function() {
$('.scroller').text('sadkvbalsjdfasjdkhfakjsdhflaksdhflakjhsdafjh');
$('.scroller').each(function() {
// $(this).trigger('scroll');
it("Toggling barOnCls.", function(done) {
$('.scroller').text('sadkvbalsjdfasjdkhf akjsdhflaksdhf lakjhsdafjh sadkvbalsjdfasjdkhf akjsdhflaksdhf lakjhsdafjh');
baron.update();
setTimeout(function() {
assert( $('.wrapper').hasClass(barOnCls), 'При большом количестве контента навешивается класс' );
$('.scroller').text('');
baron.update();
});
assert( $('.wrapper').hasClass(barOnCls), 'При большом количестве контента навешивается класс' );
$('.scroller').text('');
$('.scroller').each(function() {
// $(this).trigger('scroll');
baron.update();
});
assert( !$('.wrapper').hasClass(barOnCls), 'В отсутствии текста класса нет' );
setTimeout(function() {
assert( !$('.wrapper').hasClass(barOnCls), 'В отсутствии текста класса нет' );
done();
}, 0);
}, 0);
});

@@ -177,0 +237,0 @@

@@ -217,2 +217,5 @@ var b;

$('.wrapper_noParams .scroller').baron();
// paddings
$('.wrapper_mbp .scroller').baron();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc