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

Commit e65933a

Browse files
author
Lorenzo D'Ianni
committed
feat(config): sidebarjs-config attribute
1 parent a45989f commit e65933a

4 files changed

Lines changed: 21 additions & 14 deletions

File tree

dist/angular-sidebarjs.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
3131
this.background = options.background || SidebarJS.create(sidebarjs + '-background');
3232
this.documentMinSwipeX = options.documentMinSwipeX || 10;
3333
this.documentSwipeRange = options.documentSwipeRange || 40;
34-
this.swipeOpen = options.swipeOpen !== false;
34+
this.nativeSwipe = options.nativeSwipe !== false;
35+
this.nativeSwipeOpen = options.nativeSwipeOpen !== false;
3536

3637
if (!options.component && !options.container && !options.background) {
3738
this.container.innerHTML = this.component.innerHTML;
@@ -40,16 +41,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
4041
this.component.appendChild(this.background);
4142
}
4243

43-
if (this.swipeOpen) {
44-
document.addEventListener('touchstart', this.onDocumentTouchStart.bind(this));
45-
document.addEventListener('touchmove', this.onDocumentTouchMove.bind(this));
46-
document.addEventListener('touchend', this.onDocumentTouchEnd.bind(this));
44+
if (this.nativeSwipe) {
45+
this.component.addEventListener('touchstart', this.onTouchStart.bind(this));
46+
this.component.addEventListener('touchmove', this.onTouchMove.bind(this));
47+
this.component.addEventListener('touchend', this.onTouchEnd.bind(this));
48+
if (this.nativeSwipeOpen) {
49+
document.addEventListener('touchstart', this.onDocumentTouchStart.bind(this));
50+
document.addEventListener('touchmove', this.onDocumentTouchMove.bind(this));
51+
document.addEventListener('touchend', this.onDocumentTouchEnd.bind(this));
52+
}
4753
}
4854

4955
this.addAttrsEventsListeners();
50-
this.component.addEventListener('touchstart', this.onTouchStart.bind(this));
51-
this.component.addEventListener('touchmove', this.onTouchMove.bind(this));
52-
this.component.addEventListener('touchend', this.onTouchEnd.bind(this));
5356
this.background.addEventListener('click', this.close.bind(this));
5457
}
5558

@@ -212,11 +215,12 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
212215

213216
var container = this.elem.children[0];
214217
var background = this.elem.children[1];
215-
this._SidebarJS.init({
218+
var options = Object.assign({}, this.sidebarjsConfig, {
216219
component: this.elem,
217220
container: container,
218221
background: background
219222
});
223+
this._SidebarJS.init(options);
220224

221225
var wasVisible = false;
222226
container.addEventListener('transitionend', function () {
@@ -283,7 +287,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
283287
controller: SidebarJSCtrl,
284288
bindings: {
285289
onOpen: '&?',
286-
onClose: '&?'
290+
onClose: '&?',
291+
sidebarjsConfig: '<?'
287292
}
288293
}).directive('sidebarjsOpen', SidebarJSDirective.bind(null, 'open')).directive('sidebarjsClose', SidebarJSDirective.bind(null, 'close')).directive('sidebarjsToggle', SidebarJSDirective.bind(null, 'toggle'));
289294
})();

dist/angular-sidebarjs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-sidebarjs",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"description": "Create mobile sidebar/sidenav experiance in angularjs",
55
"main": "index.js",
66
"scripts": {
@@ -42,6 +42,6 @@
4242
},
4343
"dependencies": {
4444
"angular": "^1.5.8",
45-
"sidebarjs": "~1.7.1"
45+
"sidebarjs": "~1.8.0"
4646
}
4747
}

src/angular-sidebarjs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
$postLink() {
1616
const container = this.elem.children[0];
1717
const background = this.elem.children[1];
18-
this._SidebarJS.init({
18+
const options = Object.assign({}, this.sidebarjsConfig, {
1919
component: this.elem,
2020
container,
2121
background,
2222
});
23+
this._SidebarJS.init(options);
2324

2425
let wasVisible = false;
2526
container.addEventListener('transitionend', () => {
@@ -75,6 +76,7 @@
7576
bindings: {
7677
onOpen: '&?',
7778
onClose: '&?',
79+
sidebarjsConfig: '<?',
7880
},
7981
})
8082
.directive('sidebarjsOpen', SidebarJSDirective.bind(null, 'open'))

0 commit comments

Comments
 (0)