Skip to content

Commit 3ab9c58

Browse files
authored
Add files via upload
0 parents  commit 3ab9c58

File tree

100 files changed

+5345
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+5345
-0
lines changed

_modules/dom.ts

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/**
2+
* Create an element with classname.
3+
*
4+
* @param {string} selector The nodeName and classnames for the element to create.
5+
* @return {HTMLElement} The created element.
6+
*/
7+
export function create(selector: string): HTMLElement {
8+
const args = selector.split('.');
9+
const elem = document.createElement(args.shift());
10+
11+
// IE11:
12+
args.forEach((classname) => {
13+
elem.classList.add(classname);
14+
});
15+
16+
// Better browsers:
17+
// elem.classList.add(...args);
18+
19+
return elem;
20+
}
21+
22+
/**
23+
* Find all elements matching the selector.
24+
* Basically the same as element.querySelectorAll() but it returns an actuall array.
25+
*
26+
* @param {HTMLElement} element Element to search in.
27+
* @param {string} filter The filter to match.
28+
* @return {array} Array of elements that match the filter.
29+
*/
30+
export function find(
31+
element: HTMLElement | Document,
32+
filter: string
33+
): HTMLElement[] {
34+
return Array.prototype.slice.call(element.querySelectorAll(filter));
35+
}
36+
37+
/**
38+
* Find all child elements matching the (optional) selector.
39+
*
40+
* @param {HTMLElement} element Element to search in.
41+
* @param {string} filter The filter to match.
42+
* @return {array} Array of child elements that match the filter.
43+
*/
44+
export function children(element: HTMLElement, filter?: string): HTMLElement[] {
45+
const children: HTMLElement[] = Array.prototype.slice.call(
46+
element.children
47+
);
48+
return filter
49+
? children.filter((child) => child.matches(filter))
50+
: children;
51+
}
52+
53+
/**
54+
* Find text excluding text from within child elements.
55+
* @param {HTMLElement} element Element to search in.
56+
* @return {string} The text.
57+
*/
58+
export function text(element: HTMLElement): string {
59+
return Array.prototype.slice
60+
.call(element.childNodes)
61+
.filter((child) => child.nodeType == 3)
62+
.map((child) => child.textContent)
63+
.join(' ');
64+
}
65+
66+
/**
67+
* Find all preceding elements matching the selector.
68+
*
69+
* @param {HTMLElement} element Element to start searching from.
70+
* @param {string} filter The filter to match.
71+
* @return {array} Array of preceding elements that match the selector.
72+
*/
73+
export function parents(element: HTMLElement, filter?: string): HTMLElement[] {
74+
/** Array of preceding elements that match the selector. */
75+
let parents: HTMLElement[] = [];
76+
77+
/** Array of preceding elements that match the selector. */
78+
let parent = element.parentElement;
79+
while (parent) {
80+
parents.push(parent);
81+
parent = parent.parentElement;
82+
}
83+
84+
return filter
85+
? parents.filter((parent) => parent.matches(filter))
86+
: parents;
87+
}
88+
89+
/**
90+
* Find all previous siblings matching the selecotr.
91+
*
92+
* @param {HTMLElement} element Element to start searching from.
93+
* @param {string} filter The filter to match.
94+
* @return {array} Array of previous siblings that match the selector.
95+
*/
96+
export function prevAll(element: HTMLElement, filter?: string): HTMLElement[] {
97+
/** Array of previous siblings that match the selector. */
98+
let previous: HTMLElement[] = [];
99+
100+
/** Current element in the loop */
101+
let current = element.previousElementSibling as HTMLElement;
102+
103+
while (current) {
104+
if (!filter || current.matches(filter)) {
105+
previous.push(current);
106+
}
107+
current = current.previousElementSibling as HTMLElement;
108+
}
109+
110+
return previous;
111+
}
112+
113+
/**
114+
* Get an element offset relative to the document.
115+
*
116+
* @param {HTMLElement} element Element to start measuring from.
117+
* @param {string} [direction=top] Offset top or left.
118+
* @return {number} The element offset relative to the document.
119+
*/
120+
export function offset(element: HTMLElement, direction?: string): number {
121+
return (
122+
element.getBoundingClientRect()[direction] +
123+
document.body[direction === 'left' ? 'scrollLeft' : 'scrollTop']
124+
);
125+
}
126+
127+
/**
128+
* Filter out non-listitem listitems.
129+
* @param {array} listitems Elements to filter.
130+
* @return {array} The filtered set of listitems.
131+
*/
132+
export function filterLI(listitems: HTMLElement[]): HTMLElement[] {
133+
return listitems.filter((listitem) => !listitem.matches('.mm-hidden'));
134+
}
135+
136+
/**
137+
* Find anchors in listitems (excluding anchor that open a sub-panel).
138+
* @param {array} listitems Elements to filter.
139+
* @return {array} The found set of anchors.
140+
*/
141+
export function filterLIA(listitems: HTMLElement[]): HTMLElement[] {
142+
let anchors = [];
143+
filterLI(listitems).forEach((listitem) => {
144+
anchors.push(...children(listitem, 'a.mm-listitem__text'));
145+
});
146+
return anchors.filter((anchor) => !anchor.matches('.mm-btn_next'));
147+
}
148+
149+
/**
150+
* Refactor a classname on multiple elements.
151+
* @param {HTMLElement} element Element to refactor.
152+
* @param {string} oldClass Classname to remove.
153+
* @param {string} newClass Classname to add.
154+
*/
155+
export function reClass(
156+
element: HTMLElement,
157+
oldClass: string,
158+
newClass: string
159+
) {
160+
if (element.matches('.' + oldClass)) {
161+
element.classList.remove(oldClass);
162+
element.classList.add(newClass);
163+
}
164+
}

_modules/dragevents/_defaults.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/** How far from the sides the gesture can start. */
2+
export const area: dragArea = {
3+
top: 0,
4+
right: 0,
5+
bottom: 0,
6+
left: 0
7+
};
8+
9+
/** Tresholds for gestures. */
10+
export const treshold: dragTreshold = {
11+
start: 15,
12+
swipe: 15
13+
};

_modules/dragevents/_helpers.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Calculate a distance from a percentage.
3+
* @param {string|number} position The percentage (e.g. "75%").
4+
* @param {number} size The available width or height in pixels.
5+
* @return {number} The calculated distance.
6+
*/
7+
export const percentage2number = (position: string | number, size: number) => {
8+
if (typeof position == 'string') {
9+
if (position.slice(-1) == '%') {
10+
position = parseInt(position.slice(0, -1), 10);
11+
position = size * (position / 100);
12+
}
13+
}
14+
return position;
15+
};

_modules/dragevents/_settings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** Names of the possible directions. */
2+
export const directionNames = {
3+
x: ['Right', 'Left'],
4+
y: ['Down', 'Up']
5+
};
6+
7+
/** States for the gesture. */
8+
export const state = {
9+
inactive: 0,
10+
watching: 1,
11+
dragging: 2
12+
};

_modules/dragevents/_support.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/** Whether or not touch gestures are supported by the browser. */
2+
export const touch =
3+
'ontouchstart' in window ||
4+
(navigator.msMaxTouchPoints ? true : false) ||
5+
false;

_modules/dragevents/_typings.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/** Options for the drag engine. */
2+
interface dragOption {
3+
area: dragArea;
4+
}
5+
6+
/** How far from the sides the gesture can start. */
7+
interface dragArea {
8+
top?: number | string;
9+
right?: number | string;
10+
bottom?: number | string;
11+
left?: number | string;
12+
}
13+
14+
/** Tresholds for gestures. */
15+
interface dragTreshold {
16+
start?: number;
17+
swipe?: number;
18+
}
19+
20+
/** Set of x and y positions. */
21+
interface dragCoordinates {
22+
x: number;
23+
y: number;
24+
}

0 commit comments

Comments
 (0)