Skip to content

Commit 9f8c2bc

Browse files
committed
refactor(pushpin): remove jquery
1 parent ab9a3e1 commit 9f8c2bc

File tree

2 files changed

+5
-42
lines changed

2 files changed

+5
-42
lines changed

src/component.ts

+3-16
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,33 @@ import cash from "cash-dom";
22

33
export class Component {
44
$el: any;
5-
/**
6-
* Generic constructor for all components
7-
* @constructor
8-
* @param {Element} el
9-
* @param {Object} options
10-
*/
5+
116
constructor(classDef, protected el: Element, protected options) {
127
// Display error if el is valid HTML Element
138
if (!(el instanceof Element)) {
149
console.error(Error(el + ' is not an HTML Element'));
1510
}
16-
1711
// If exists, destroy and reinitialize in child
1812
let ins = classDef.getInstance(el);
1913
if (!!ins) {
2014
ins.destroy();
2115
}
22-
2316
this.el = el;
2417
this.$el = cash(el);
2518
}
2619

27-
/**
28-
* Initializes components
29-
* @param {class} classDef
30-
* @param {Element | NodeList | jQuery} els
31-
* @param {Object} options
32-
*/
3320
static init(classDef, els, options) {
3421
let instances = null;
3522
if (els instanceof Element) {
3623
instances = new classDef(els, options);
37-
} else if (!!els && (els.jquery || els.cash || els instanceof NodeList || els instanceof HTMLCollection)) {
24+
}
25+
else if (!!els && (els.jquery || els.cash || els instanceof NodeList || els instanceof HTMLCollection)) {
3826
let instancesArr = [];
3927
for (let i = 0; i < els.length; i++) {
4028
instancesArr.push(new classDef(els[i], options));
4129
}
4230
instances = instancesArr;
4331
}
44-
4532
return instances;
4633
}
4734
}

src/pushpin.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component } from "./component";
2-
import $ from "cash-dom";
32
import { M } from "./global";
43

54
let _defaults = {
@@ -9,30 +8,14 @@ import { M } from "./global";
98
onPositionChange: null
109
};
1110

12-
/**
13-
* @class
14-
*
15-
*/
1611
export class Pushpin extends Component {
1712
static _pushpins: any[];
1813
originalOffset: any;
19-
/**
20-
* Construct Pushpin instance
21-
* @constructor
22-
* @param {Element} el
23-
* @param {Object} options
24-
*/
14+
2515
constructor(el, options) {
2616
super(Pushpin, el, options);
27-
2817
(this.el as any).M_Pushpin = this;
29-
30-
/**
31-
* Options for the modal
32-
* @member Pushpin#options
33-
*/
34-
this.options = $.extend({}, Pushpin.defaults, options);
35-
18+
this.options = {...Pushpin.defaults, ...options};
3619
this.originalOffset = (this.el as HTMLElement).offsetTop;
3720
Pushpin._pushpins.push(this);
3821
this._setupEventHandlers();
@@ -47,21 +30,14 @@ import { M } from "./global";
4730
return super.init(this, els, options);
4831
}
4932

50-
/**
51-
* Get Instance
52-
*/
5333
static getInstance(el) {
5434
let domElem = !!el.jquery ? el[0] : el;
5535
return domElem.M_Pushpin;
5636
}
5737

58-
/**
59-
* Teardown component
60-
*/
6138
destroy() {
6239
(this.el as HTMLElement).style.top = null;
6340
this._removePinClasses();
64-
6541
// Remove pushpin Inst
6642
let index = Pushpin._pushpins.indexOf(this);
6743
Pushpin._pushpins.splice(index, 1);

0 commit comments

Comments
 (0)