Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 907bf98

Browse files
committed
build(version): updated sidebarjs dependecy
1 parent 2985d9e commit 907bf98

4 files changed

Lines changed: 57 additions & 32 deletions

File tree

dist/angular-sidebarjs.js

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
1919
var sidebarjs = 'sidebarjs';
2020
var isVisible = sidebarjs + "--is-visible";
2121
var isMoving = sidebarjs + "--is-moving";
22+
var LEFT_POSITION = 'left';
23+
var RIGHT_POSITION = 'right';
24+
var TRANSITION_DURATION = 400;
25+
var POSITIONS = [LEFT_POSITION, RIGHT_POSITION];
2226
var SidebarJS = (function () {
2327
function SidebarJS(_a) {
24-
var _b = _a === void 0 ? {} : _a, component = _b.component, container = _b.container, background = _b.background, documentMinSwipeX = _b.documentMinSwipeX, documentSwipeRange = _b.documentSwipeRange, nativeSwipe = _b.nativeSwipe, nativeSwipeOpen = _b.nativeSwipeOpen;
28+
var _b = _a === void 0 ? {} : _a, component = _b.component, container = _b.container, background = _b.background, documentMinSwipeX = _b.documentMinSwipeX, documentSwipeRange = _b.documentSwipeRange, nativeSwipe = _b.nativeSwipe, nativeSwipeOpen = _b.nativeSwipeOpen, position = _b.position;
2529
this.component = component || document.querySelector("[" + sidebarjs + "]");
2630
this.container = container || SidebarJS.create(sidebarjs + "-container");
2731
this.background = background || SidebarJS.create(sidebarjs + "-background");
@@ -44,6 +48,7 @@ var SidebarJS = (function () {
4448
this.addNativeOpenGestures();
4549
}
4650
}
51+
this.setPosition(position);
4752
this.addAttrsEventsListeners();
4853
this.background.addEventListener('click', this.close.bind(this));
4954
}
@@ -59,6 +64,14 @@ var SidebarJS = (function () {
5964
SidebarJS.prototype.isVisible = function () {
6065
return this.component.classList.contains(isVisible);
6166
};
67+
SidebarJS.prototype.setPosition = function (position) {
68+
var _this = this;
69+
this.component.classList.add(isMoving);
70+
this.position = POSITIONS.indexOf(position) >= 0 ? position : LEFT_POSITION;
71+
POSITIONS.forEach(function (POS) { return _this.component.classList.remove(sidebarjs + "--" + POS); });
72+
this.component.classList.add(sidebarjs + "--" + (this.hasRightPosition() ? RIGHT_POSITION : LEFT_POSITION));
73+
setTimeout(function () { return _this.component.classList.remove(isMoving); }, TRANSITION_DURATION);
74+
};
6275
SidebarJS.prototype.addAttrsEventsListeners = function () {
6376
var actions = ['toggle', 'open', 'close'];
6477
for (var i = 0; i < actions.length; i++) {
@@ -71,6 +84,12 @@ var SidebarJS = (function () {
7184
}
7285
}
7386
};
87+
SidebarJS.prototype.hasLeftPosition = function () {
88+
return this.position === LEFT_POSITION;
89+
};
90+
SidebarJS.prototype.hasRightPosition = function () {
91+
return this.position === RIGHT_POSITION;
92+
};
7493
SidebarJS.prototype.transcludeContent = function () {
7594
this.container.innerHTML = this.component.innerHTML;
7695
this.component.innerHTML = '';
@@ -83,22 +102,24 @@ var SidebarJS = (function () {
83102
this.component.addEventListener('touchend', this.onTouchEnd.bind(this));
84103
};
85104
SidebarJS.prototype.addNativeOpenGestures = function () {
86-
document.addEventListener('touchstart', this.onDocumentTouchStart.bind(this));
87-
document.addEventListener('touchmove', this.onDocumentTouchMove.bind(this));
88-
document.addEventListener('touchend', this.onDocumentTouchEnd.bind(this));
105+
document.addEventListener('touchstart', this.onSwipeOpenStart.bind(this));
106+
document.addEventListener('touchmove', this.onSwipeOpenMove.bind(this));
107+
document.addEventListener('touchend', this.onSwipeOpenEnd.bind(this));
89108
};
90109
SidebarJS.prototype.onTouchStart = function (e) {
91110
this.initialTouch = e.touches[0].pageX;
92111
};
93112
SidebarJS.prototype.onTouchMove = function (e) {
94-
this.touchMoveSidebar = this.initialTouch - e.touches[0].pageX;
95-
if (this.touchMoveSidebar >= 0) {
96-
this.moveSidebar(-this.touchMoveSidebar);
113+
var documentSwiped = this.initialTouch - e.touches[0].clientX;
114+
var sidebarMovement = this.getSidebarPosition(documentSwiped);
115+
this.touchMoveSidebar = -documentSwiped;
116+
if (sidebarMovement <= this.container.clientWidth) {
117+
this.moveSidebar(this.touchMoveSidebar);
97118
}
98119
};
99120
SidebarJS.prototype.onTouchEnd = function () {
100121
this.component.classList.remove(isMoving);
101-
this.touchMoveSidebar > (this.container.clientWidth / 3.5) ? this.close() : this.open();
122+
Math.abs(this.touchMoveSidebar) > (this.container.clientWidth / 3.5) ? this.close() : this.open();
102123
this.container.removeAttribute('style');
103124
this.background.removeAttribute('style');
104125
delete this.initialTouch;
@@ -110,35 +131,39 @@ var SidebarJS = (function () {
110131
this.changeBackgroundOpacity(movement);
111132
};
112133
SidebarJS.prototype.changeBackgroundOpacity = function (movement) {
113-
var opacity = 0.3 - (-movement / (this.container.clientWidth * 3.5));
134+
var opacity = 0.3 - (Math.abs(movement) / (this.container.clientWidth * 3.5));
114135
this.background.style.opacity = (opacity).toString();
115136
};
116-
SidebarJS.prototype.onDocumentTouchStart = function (e) {
137+
SidebarJS.prototype.onSwipeOpenStart = function (e) {
138+
var clientWidth = document.body.clientWidth;
117139
var touchPositionX = e.touches[0].clientX;
118-
if (touchPositionX < this.documentSwipeRange) {
140+
var documentTouch = this.hasLeftPosition() ? touchPositionX : clientWidth - touchPositionX;
141+
if (documentTouch < this.documentSwipeRange) {
119142
this.onTouchStart(e);
120143
}
121144
};
122-
SidebarJS.prototype.onDocumentTouchMove = function (e) {
145+
SidebarJS.prototype.onSwipeOpenMove = function (e) {
123146
if (this.initialTouch && !this.isVisible()) {
124147
var documentSwiped = e.touches[0].clientX - this.initialTouch;
125-
if (documentSwiped > this.documentMinSwipeX) {
126-
this.touchMoveDocument = e.touches[0].pageX - this.container.clientWidth;
148+
var sidebarMovement = this.getSidebarPosition(documentSwiped);
149+
if (sidebarMovement > 0) {
127150
SidebarJS.vendorify(this.component, 'transform', 'translate(0, 0)');
128151
SidebarJS.vendorify(this.component, 'transition', 'none');
129-
if (this.touchMoveDocument <= 0) {
130-
this.moveSidebar(this.touchMoveDocument);
131-
}
152+
this.openMovement = sidebarMovement * (this.hasLeftPosition() ? -1 : 1);
153+
this.moveSidebar(this.openMovement);
132154
}
133155
}
134156
};
135-
SidebarJS.prototype.onDocumentTouchEnd = function () {
136-
if (this.touchMoveDocument) {
137-
delete this.touchMoveDocument;
157+
SidebarJS.prototype.onSwipeOpenEnd = function () {
158+
if (this.openMovement) {
159+
delete this.openMovement;
138160
this.component.removeAttribute('style');
139161
this.onTouchEnd();
140162
}
141163
};
164+
SidebarJS.prototype.getSidebarPosition = function (swiped) {
165+
return (this.container.clientWidth - (this.hasLeftPosition() ? swiped : -swiped));
166+
};
142167
SidebarJS.create = function (element) {
143168
var el = document.createElement('div');
144169
el.setAttribute(element, '');
@@ -158,7 +183,7 @@ var SidebarJS = (function () {
158183
};
159184
Object.defineProperty(SidebarJS, "version", {
160185
get: function () {
161-
return '1.9.0';
186+
return '1.10.0';
162187
},
163188
enumerable: true,
164189
configurable: true
@@ -245,16 +270,16 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
245270
return instance = new _SidebarJS(options);
246271
},
247272
open: function open() {
248-
return instance.open();
273+
return instance && instance.open();
249274
},
250275
close: function close() {
251-
return instance.close();
276+
return instance && instance.close();
252277
},
253278
toggle: function toggle() {
254-
return instance.toggle();
279+
return instance && instance.toggle();
255280
},
256281
isVisible: function isVisible() {
257-
return instance.isVisible();
282+
return !!instance && instance.isVisible();
258283
},
259284
elemHasListener: _SidebarJS.elemHasListener
260285
};

0 commit comments

Comments
 (0)