New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

angular-wheelie

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-wheelie - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

2

bower.json
{
"name": "angular-wheelie",
"version": "1.1.2",
"version": "2.0.0",
"description": "Mousewheel as an angular service",

@@ -5,0 +5,0 @@ "main": "dist/angular-wheelie.js",

/**
* angular-wheelie
* Version: 1.1.2
* Version: 2.0.0
* (c) 2016 Joel Mukuthu
* MIT License
* Built on: 13-08-2016 17:06:59 GMT+0200
* Built on: 05-11-2016 17:55:10 GMT+0100
**/

@@ -14,14 +14,29 @@

.factory('wheelie', [function () {
var isDefined = angular.isDefined;
var isFunction = angular.isFunction;
return {
bind: function (element, callbacks) {
callbacks = callbacks || {};
if (angular.isDefined(callbacks.up) && !angular.isFunction(callbacks.up)) {
if (isDefined(callbacks.up) && !isFunction(callbacks.up)) {
throw new Error('The \'up\' callback must be a function');
}
if (angular.isDefined(callbacks.down) && !angular.isFunction(callbacks.down)) {
if (isDefined(callbacks.down) && !isFunction(callbacks.down)) {
throw new Error('The \'down\' callback must be a function');
}
if (!angular.isDefined(callbacks.up) && !angular.isDefined(callbacks.down)) {
throw new Error('At least one callback (\'up\' or \'down\') must be provided');
if (isDefined(callbacks.left) && !isFunction(callbacks.left)) {
throw new Error('The \'left\' callback must be a function');
}
if (isDefined(callbacks.right) && !isFunction(callbacks.right)) {
throw new Error('The \'right\' callback must be a function');
}
if (!isDefined(callbacks.up) &&
!isDefined(callbacks.down) &&
!isDefined(callbacks.left) &&
!isDefined(callbacks.right)) {
throw new Error(
'At least one callback (\'up\', \'down\', \'left\' or \'right\') must be provided'
);
}

@@ -32,15 +47,11 @@ function bindWheel(e) {

}
var delta;
delta = Math.max(-1, Math.min(1, (e.wheelDelta || -(e.deltaY || e.detail))));
if (isNaN(delta) || delta === 0) {
return;
if (e.deltaX) {
e.deltaX < 0 && callbacks.left && callbacks.left(e);
e.deltaX > 0 && callbacks.right && callbacks.right(e);
}
if (delta > 0) {
if (callbacks.up) {
callbacks.up(e);
}
} else {
if (callbacks.down) {
callbacks.down(e);
}
if (e.deltaY) {
e.deltaY < 0 && callbacks.up && callbacks.up(e);
e.deltaY > 0 && callbacks.down && callbacks.down(e);
}

@@ -50,3 +61,3 @@ }

element.data('___wheelie_bindWheel___', bindWheel);
element.on('wheel mousewheel onmousewheel', bindWheel);
element.on('wheel', bindWheel);
},

@@ -56,5 +67,5 @@

var bindWheel = element.data('___wheelie_bindWheel___');
if (angular.isFunction(bindWheel)) {
if (isFunction(bindWheel)) {
element.data('___wheelie_bindWheel___', null);
element.off('wheel mousewheel onmousewheel', bindWheel);
element.off('wheel', bindWheel);
}

@@ -61,0 +72,0 @@ }

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

/* angular-wheelie v1.1.2, (c) 2016 Joel Mukuthu, MIT License, built: 13-08-2016 17:06:59 GMT+0200 */
angular.module("wheelie",[]),angular.module("wheelie").factory("wheelie",[function(){return{bind:function(a,b){function c(a){a.originalEvent&&(a=a.originalEvent);var c;c=Math.max(-1,Math.min(1,a.wheelDelta||-(a.deltaY||a.detail))),isNaN(c)||0===c||(c>0?b.up&&b.up(a):b.down&&b.down(a))}if(b=b||{},angular.isDefined(b.up)&&!angular.isFunction(b.up))throw new Error("The 'up' callback must be a function");if(angular.isDefined(b.down)&&!angular.isFunction(b.down))throw new Error("The 'down' callback must be a function");if(!angular.isDefined(b.up)&&!angular.isDefined(b.down))throw new Error("At least one callback ('up' or 'down') must be provided");a.data("___wheelie_bindWheel___",c),a.on("wheel mousewheel onmousewheel",c)},unbind:function(a){var b=a.data("___wheelie_bindWheel___");angular.isFunction(b)&&(a.data("___wheelie_bindWheel___",null),a.off("wheel mousewheel onmousewheel",b))}}}]);
/* angular-wheelie v2.0.0, (c) 2016 Joel Mukuthu, MIT License, built: 05-11-2016 17:55:10 GMT+0100 */
angular.module("wheelie",[]),angular.module("wheelie").factory("wheelie",[function(){var a=angular.isDefined,b=angular.isFunction;return{bind:function(c,d){function e(a){a.originalEvent&&(a=a.originalEvent),a.deltaX&&(a.deltaX<0&&d.left&&d.left(a),a.deltaX>0&&d.right&&d.right(a)),a.deltaY&&(a.deltaY<0&&d.up&&d.up(a),a.deltaY>0&&d.down&&d.down(a))}if(d=d||{},a(d.up)&&!b(d.up))throw new Error("The 'up' callback must be a function");if(a(d.down)&&!b(d.down))throw new Error("The 'down' callback must be a function");if(a(d.left)&&!b(d.left))throw new Error("The 'left' callback must be a function");if(a(d.right)&&!b(d.right))throw new Error("The 'right' callback must be a function");if(!(a(d.up)||a(d.down)||a(d.left)||a(d.right)))throw new Error("At least one callback ('up', 'down', 'left' or 'right') must be provided");c.data("___wheelie_bindWheel___",e),c.on("wheel",e)},unbind:function(a){var c=a.data("___wheelie_bindWheel___");b(c)&&(a.data("___wheelie_bindWheel___",null),a.off("wheel",c))}}}]);
{
"name": "angular-wheelie",
"version": "1.1.2",
"version": "2.0.0",
"description": "Mousewheel as an angular service",

@@ -5,0 +5,0 @@ "main": "dist/angular-wheelie.js",

angular
.module('wheelie')
.factory('wheelie', [function () {
var isDefined = angular.isDefined;
var isFunction = angular.isFunction;
return {
bind: function (element, callbacks) {
callbacks = callbacks || {};
if (angular.isDefined(callbacks.up) && !angular.isFunction(callbacks.up)) {
if (isDefined(callbacks.up) && !isFunction(callbacks.up)) {
throw new Error('The \'up\' callback must be a function');
}
if (angular.isDefined(callbacks.down) && !angular.isFunction(callbacks.down)) {
if (isDefined(callbacks.down) && !isFunction(callbacks.down)) {
throw new Error('The \'down\' callback must be a function');
}
if (!angular.isDefined(callbacks.up) && !angular.isDefined(callbacks.down)) {
throw new Error('At least one callback (\'up\' or \'down\') must be provided');
if (isDefined(callbacks.left) && !isFunction(callbacks.left)) {
throw new Error('The \'left\' callback must be a function');
}
if (isDefined(callbacks.right) && !isFunction(callbacks.right)) {
throw new Error('The \'right\' callback must be a function');
}
if (!isDefined(callbacks.up) &&
!isDefined(callbacks.down) &&
!isDefined(callbacks.left) &&
!isDefined(callbacks.right)) {
throw new Error(
'At least one callback (\'up\', \'down\', \'left\' or \'right\') must be provided'
);
}

@@ -21,15 +36,11 @@ function bindWheel(e) {

}
var delta;
delta = Math.max(-1, Math.min(1, (e.wheelDelta || -(e.deltaY || e.detail))));
if (isNaN(delta) || delta === 0) {
return;
if (e.deltaX) {
e.deltaX < 0 && callbacks.left && callbacks.left(e);
e.deltaX > 0 && callbacks.right && callbacks.right(e);
}
if (delta > 0) {
if (callbacks.up) {
callbacks.up(e);
}
} else {
if (callbacks.down) {
callbacks.down(e);
}
if (e.deltaY) {
e.deltaY < 0 && callbacks.up && callbacks.up(e);
e.deltaY > 0 && callbacks.down && callbacks.down(e);
}

@@ -39,3 +50,3 @@ }

element.data('___wheelie_bindWheel___', bindWheel);
element.on('wheel mousewheel onmousewheel', bindWheel);
element.on('wheel', bindWheel);
},

@@ -45,5 +56,5 @@

var bindWheel = element.data('___wheelie_bindWheel___');
if (angular.isFunction(bindWheel)) {
if (isFunction(bindWheel)) {
element.data('___wheelie_bindWheel___', null);
element.off('wheel mousewheel onmousewheel', bindWheel);
element.off('wheel', bindWheel);
}

@@ -50,0 +61,0 @@ }

@@ -48,6 +48,24 @@ describe('Service: wheelie', function () {

it('throws an error if neither \'up\' or \'down\' callbacks are provided', function () {
it('throws an error if a \'left\' callback is provided but is not a function', function () {
expect(function () {
wheelie.bind(element, {
left: 1
});
}, 'to throw', new Error('The \'left\' callback must be a function'));
});
it('throws an error if an \'right\' callback is provided but is not a function', function () {
expect(function () {
wheelie.bind(element, {
right: 1
});
}, 'to throw', new Error('The \'right\' callback must be a function'));
});
it('throws an error if no callbacks are provided', function () {
expect(function () {
wheelie.bind(element, {});
}, 'to throw', new Error('At least one callback (\'up\' or \'down\') must be provided'));
}, 'to throw', new Error(
'At least one callback (\'up\', \'down\', \'left\' or \'right\') must be provided'
));
});

@@ -71,2 +89,18 @@

it('does not throw an error if only a \'left\' callback is provided', function () {
expect(function () {
wheelie.bind(element, {
left: function () {}
});
}, 'not to error');
});
it('does not throw an error if only a \'right\' callback is provided', function () {
expect(function () {
wheelie.bind(element, {
right: function () {}
});
}, 'not to error');
});
it('stores a reference to the \'bindWheel\' function in the element\'s data', function () {

@@ -83,19 +117,23 @@ wheelie.bind(element, {

var upSpy,
downSpy;
downSpy,
leftSpy,
rightSpy;
beforeEach(inject(function (_wheelie_) {
upSpy = sinon.spy().named('mousewheelUp');
downSpy = sinon.spy().named('mousewheelDown');
upSpy = sinon.spy().named('wheelUp');
downSpy = sinon.spy().named('wheelDown');
leftSpy = sinon.spy().named('wheelLeft');
rightSpy = sinon.spy().named('wheelRight');
_wheelie_.bind(element, {
up: upSpy,
down: downSpy
down: downSpy,
left: leftSpy,
right: rightSpy
});
}));
it('calls the \'up\' callback with the event on mousewheel up', function () {
it('calls the \'up\' callback with the event on wheel up', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: 120,
detail: -120,
deltaY: -120

@@ -106,4 +144,2 @@ });

type: 'wheel',
wheelDelta: 120,
detail: -120,
deltaY: -120

@@ -114,7 +150,5 @@ });

it('calls the \'down\' callback with the event on mousewheel down', function () {
it('calls the \'down\' callback with the event on wheel down', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: -120,
detail: 120,
deltaY: 120

@@ -125,4 +159,2 @@ });

type: 'wheel',
wheelDelta: -120,
detail: 120,
deltaY: 120

@@ -133,7 +165,31 @@ });

it('does not call the \'up\' callback on mousewheel down', function () {
it('calls the \'left\' callback with the event on wheel left', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: -120,
detail: 120,
deltaX: -120
});
expect(leftSpy, 'to have calls satisfying', function () {
leftSpy({
type: 'wheel',
deltaX: -120
});
});
});
it('calls the \'right\' callback with the event on wheel right', function () {
element.triggerHandler({
type: 'wheel',
deltaX: 120
});
expect(rightSpy, 'to have calls satisfying', function () {
rightSpy({
type: 'wheel',
deltaX: 120
});
});
});
it('does not call the \'up\' callback on wheel down', function () {
element.triggerHandler({
type: 'wheel',
deltaY: 120

@@ -144,7 +200,5 @@ });

it('does not call the \'down\' callback on mousewheel up', function () {
it('does not call the \'down\' callback on wheel up', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: 120,
detail: -120,
deltaY: -120

@@ -155,8 +209,39 @@ });

// from a bug report: https://github.com/joelmukuthu/angular-snapscroll/issues/16
it('does not call any callback if mousewheel delta is 0', function () {
it('does not call the \'up\' callback on wheel left', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: 0,
detail: 0,
deltaX: -120
});
expect(upSpy, 'was not called');
});
it('does not call the \'down\' callback on wheel right', function () {
element.triggerHandler({
type: 'wheel',
deltaX: 120
});
expect(downSpy, 'was not called');
});
it('does not call the \'left\' callback on wheel up', function () {
element.triggerHandler({
type: 'wheel',
deltaY: -120
});
expect(leftSpy, 'was not called');
});
it('does not call the \'right\' callback on wheel down', function () {
element.triggerHandler({
type: 'wheel',
deltaY: 120
});
expect(leftSpy, 'was not called');
});
// from a bug report: https://github.com/joelmukuthu/angular-snapscroll/issues/16
it('does not call any callback if wheel delta is 0', function () {
element.triggerHandler({
type: 'wheel',
deltaX: 0,
deltaY: 0

@@ -166,21 +251,24 @@ });

expect(downSpy, 'was not called');
expect(leftSpy, 'was not called');
expect(rightSpy, 'was not called');
});
it('does not call any callback if mousewheel delta is NaN', function () {
it('does not call any callback if wheel delta is undefined', function () {
element.triggerHandler({
type: 'wheel',
wheelDelta: NaN,
detail: NaN,
deltaY: NaN
deltaX: undefined,
deltaY: undefined
});
expect(upSpy, 'was not called');
expect(downSpy, 'was not called');
expect(leftSpy, 'was not called');
expect(rightSpy, 'was not called');
});
it('uses event.originalEvent to get the mousewheel delta if the property is set', function () {
it('uses event.originalEvent to get the wheel delta if the property is set', function () {
element.triggerHandler({
type: 'wheel',
// this represents mousewheel up
// this represents wheel up
deltaY: -120,
// but this represents mousewheel down
// but this represents wheel down
originalEvent: {

@@ -207,4 +295,4 @@ deltaY: 120

wheelie = _wheelie_;
upSpy = sinon.spy().named('mousewheelUp');
downSpy = sinon.spy().named('mousewheelDown');
upSpy = sinon.spy().named('wheelUp');
downSpy = sinon.spy().named('wheelDown');

@@ -211,0 +299,0 @@ wheelie.bind(element, {

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