Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
5e627e14ae | |||
01e8ddf502 | |||
112f6bf41c | |||
ab302610b0 | |||
be7d36956c | |||
16cfc341f5 | |||
81aca40016 | |||
44a466e64d | |||
3257c7e7ec | |||
bc0bab1867 | |||
8c7d16500a | |||
6e1632cd14 | |||
f2f377e362 | |||
6bf6aab82f | |||
b0a1c8b9dc |
53
README.md
53
README.md
@@ -2,31 +2,48 @@
|
|||||||
Module for creating "hot lines"
|
Module for creating "hot lines"
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
```html
|
||||||
|
<section id="wrap" style="display: flex">
|
||||||
|
<!-- First element -->
|
||||||
|
<article>
|
||||||
|
<h3>Place</h3>
|
||||||
|
</article>
|
||||||
|
|
||||||
|
<!-- Second element -->
|
||||||
|
<div>
|
||||||
|
<p>here</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Third element -->
|
||||||
|
<a>anything</a>
|
||||||
|
</section>
|
||||||
|
```
|
||||||
```js
|
```js
|
||||||
// Initializing an instance of hotline manually
|
import("/js/modules/hotline.mjs").then((module) => {
|
||||||
const instance = new hotline(
|
// Imported the hotline.mjs module
|
||||||
'articles',
|
|
||||||
document.getElementById('wrap_articles')
|
|
||||||
);
|
|
||||||
|
|
||||||
// Initializing settings of the hotline instance
|
// Initializing an instance of the hotline.mjs
|
||||||
instance.move = false;
|
const instance = new module.hotline(document.getElementById('wrap'));
|
||||||
instance.wheel = true;
|
|
||||||
instance.delta = 15;
|
|
||||||
|
|
||||||
// Starting the hotline instance
|
// Initializing settings of the hotline instance
|
||||||
instance.start();
|
instance.alive = false;
|
||||||
|
instance.wheel = true;
|
||||||
|
instance.delta = 15;
|
||||||
|
|
||||||
|
// Starting the hotline instance
|
||||||
|
instance.start();
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Preview
|
## Preview
|
||||||
### Site of Svoboda anarchist organization [svoboda/works](https://git.mirzaev.sexy/svoboda/works)
|
### Site of the Svoboda anarchist organization [svoboda/works](https://git.mirzaev.sexy/svoboda/works)
|
||||||
<br><br>
|
<br><br>
|
||||||
### Telegram chat-robot market [mirzaev/arming](https://git.mirzaev.sexy/mirzaev/arming)
|
### Telegram chat-robot market [mirzaev/arming](https://git.mirzaev.sexy/mirzaev/arming)
|
||||||
<br><br>
|
<br><br>
|
||||||
### Large project, marketplace system [mirzaev/skillparts](https://git.mirzaev.sexy/mirzaev/skillparts)
|
### Large project, marketplace system [mirzaev/skillparts](https://git.mirzaev.sexy/mirzaev/skillparts)
|
||||||
but the example is taken from another project that was copied and corrupted by another programmer<br><br>
|
but the example is taken from another project that was copied and corrupted by another programmer<br><br>
|
||||||
<br><br>
|
<br><br>
|
||||||
### Pen in the [CodePen](https://codepen.io/mirzaev-sexy/pen/gOzBZOP)<br><br>
|
### Pen in the [CodePen](https://codepen.io/mirzaev-sexy/pen/gOzBZOP)<br><br>
|
||||||

|

|
||||||

|

|
||||||

|

|
20
hotline.min.mjs
Normal file
20
hotline.min.mjs
Normal file
File diff suppressed because one or more lines are too long
60
hotline.mjs
60
hotline.mjs
@@ -21,7 +21,7 @@
|
|||||||
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
* @license http://www.wtfpl.net/ Do What The Fuck You Want To Public License
|
||||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||||
*/
|
*/
|
||||||
export default class hotline {
|
export class hotline {
|
||||||
/**
|
/**
|
||||||
* @name Shell
|
* @name Shell
|
||||||
*
|
*
|
||||||
@@ -476,16 +476,16 @@ export default class hotline {
|
|||||||
* @name Constructor
|
* @name Constructor
|
||||||
*
|
*
|
||||||
* @description
|
* @description
|
||||||
* Initialize a hotline instance and shell of elements
|
* Initialize a hotline instance
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} shell Shell
|
* @param {HTMLElement} shell The shell element
|
||||||
* @param {boolean} [inject=false] Write the hotline instance into the shell element?
|
* @param {boolean} [inject=false] Write the hotline instance into the shell element?
|
||||||
**/
|
**/
|
||||||
constructor(shell, inject = false) {
|
constructor(shell, inject = false) {
|
||||||
if (shell instanceof HTMLElement) {
|
if (shell instanceof HTMLElement) {
|
||||||
// Initialized the shell of elements
|
// Initialized the shell
|
||||||
|
|
||||||
// Writing the shell of elements
|
// Writing the shell
|
||||||
this.#shell = shell;
|
this.#shell = shell;
|
||||||
|
|
||||||
// Writing the hotline instance into the shell element
|
// Writing the hotline instance into the shell element
|
||||||
@@ -535,15 +535,16 @@ export default class hotline {
|
|||||||
instance.#first.position =
|
instance.#first.position =
|
||||||
parseFloat(instance.#first.element.style.marginTop) || 0;
|
parseFloat(instance.#first.element.style.marginTop) || 0;
|
||||||
|
|
||||||
// Initializing offset of the first element (elements are separated like this)
|
// Initializing offsets of the first element
|
||||||
instance.#first.offset =
|
instance.#first.offsets =
|
||||||
parseFloat(getComputedStyle(instance.#first.element).marginBottom) || 0;
|
(parseFloat(getComputedStyle(instance.#first.element).marginBottom) || 0)
|
||||||
|
+ (parseFloat(getComputedStyle(instance.#shell).gap) || 0);
|
||||||
|
|
||||||
// Initializing coordinate of the end of the first element
|
// Initializing coordinate of the end of the first element
|
||||||
instance.#first.end =
|
instance.#first.end =
|
||||||
instance.#first.rectangle.y +
|
instance.#first.rectangle.y +
|
||||||
instance.#first.rectangle.height +
|
instance.#first.rectangle.height +
|
||||||
instance.#first.offset;
|
instance.#first.offsets;
|
||||||
} else {
|
} else {
|
||||||
// Horizontal
|
// Horizontal
|
||||||
|
|
||||||
@@ -551,22 +552,23 @@ export default class hotline {
|
|||||||
instance.#first.position =
|
instance.#first.position =
|
||||||
parseFloat(instance.#first.element.style.marginLeft) || 0;
|
parseFloat(instance.#first.element.style.marginLeft) || 0;
|
||||||
|
|
||||||
// Initializing offset of the first element (elements are separated like this)
|
// Initializing offsets of the first element
|
||||||
instance.#first.offset =
|
instance.#first.offsets =
|
||||||
parseFloat(getComputedStyle(instance.#first.element).marginRight) || 0;
|
(parseFloat(getComputedStyle(instance.#first.element).marginRight) || 0)
|
||||||
|
+ (parseFloat(getComputedStyle(instance.#shell).gap) || 0);
|
||||||
|
|
||||||
// Initializing coordinate of the end of the first element
|
// Initializing coordinate of the end of the first element
|
||||||
instance.#first.end =
|
instance.#first.end =
|
||||||
instance.#first.rectangle.x +
|
instance.#first.rectangle.x +
|
||||||
instance.#first.rectangle.width +
|
instance.#first.rectangle.width +
|
||||||
instance.#first.offset;
|
instance.#first.offsets;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(instance.vertical &&
|
(instance.vertical &&
|
||||||
Math.round(instance.#first.end) < instance.#shell.offsetTop) ||
|
Math.round(instance.#first.end) < instance.#shell.offsetTop + instance.#shell.offsetParent.offsetTop - window.scrollY) ||
|
||||||
(!instance.vertical &&
|
(!instance.vertical &&
|
||||||
Math.round(instance.#first.end) < instance.#shell.offsetLeft)
|
Math.round(instance.#first.end) < instance.#shell.offsetLeft + instance.#shell.offsetParent.offsetLeft - window.scrollX)
|
||||||
) {
|
) {
|
||||||
// The first element with its separator went beyond the shell
|
// The first element with its separator went beyond the shell
|
||||||
|
|
||||||
@@ -590,7 +592,7 @@ export default class hotline {
|
|||||||
new CustomEvent("hotline.transfer.end", {
|
new CustomEvent("hotline.transfer.end", {
|
||||||
detail: {
|
detail: {
|
||||||
element: instance.#first.element,
|
element: instance.#first.element,
|
||||||
offset: -(instance.#first.rectangle.height + instance.#first.offset)
|
offset: -(instance.#first.rectangle.height + instance.#first.offsets)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -612,7 +614,7 @@ export default class hotline {
|
|||||||
new CustomEvent("hotline.transfer.end", {
|
new CustomEvent("hotline.transfer.end", {
|
||||||
detail: {
|
detail: {
|
||||||
element: instance.#first.element,
|
element: instance.#first.element,
|
||||||
offset: -(instance.#first.rectangle.width + instance.#first.offset)
|
offset: -(instance.#first.rectangle.width + instance.#first.offsets)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -624,9 +626,9 @@ export default class hotline {
|
|||||||
}
|
}
|
||||||
} else if (
|
} else if (
|
||||||
(instance.vertical &&
|
(instance.vertical &&
|
||||||
Math.round(instance.#first.rectangle.y) > instance.#shell.offsetTop) ||
|
Math.round(instance.#first.rectangle.y) > instance.#shell.offsetTop + instance.#shell.offsetParent.offsetTop - window.scrollY) ||
|
||||||
(!instance.vertical &&
|
(!instance.vertical &&
|
||||||
Math.round(instance.#first.rectangle.x) > instance.#shell.offsetLeft)
|
Math.round(instance.#first.rectangle.x) > instance.#shell.offsetLeft + instance.#shell.offsetParent.offsetLeft - window.scrollX)
|
||||||
) {
|
) {
|
||||||
// Beginning border of first element with its separator went beyond the shell
|
// Beginning border of first element with its separator went beyond the shell
|
||||||
|
|
||||||
@@ -649,9 +651,9 @@ export default class hotline {
|
|||||||
// Vertical
|
// Vertical
|
||||||
|
|
||||||
// Initializing offset of the last element (elements are separated like this)
|
// Initializing offset of the last element (elements are separated like this)
|
||||||
instance.#last.offset =
|
instance.#last.offsets =
|
||||||
parseFloat(getComputedStyle(instance.#last.element).marginBottom) ||
|
((parseFloat(getComputedStyle(instance.#last.element).marginBottom) || 0) + (parseFloat(getComputedStyle(instance.#shell).gap) || 0)) ||
|
||||||
instance.#first.offset ||
|
instance.#first.offsets ||
|
||||||
0;
|
0;
|
||||||
|
|
||||||
if (instance.events.get("transfer.beginning")) {
|
if (instance.events.get("transfer.beginning")) {
|
||||||
@@ -662,7 +664,7 @@ export default class hotline {
|
|||||||
new CustomEvent("hotline.transfer.beginning", {
|
new CustomEvent("hotline.transfer.beginning", {
|
||||||
detail: {
|
detail: {
|
||||||
element: instance.#last.element,
|
element: instance.#last.element,
|
||||||
offset: instance.#last.rectangle.height + instance.#last.offset
|
offset: instance.#last.rectangle.height + instance.#last.offsets
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -670,7 +672,7 @@ export default class hotline {
|
|||||||
|
|
||||||
// Initializing the position of the last element with the end boundary beyond the beginning boundary of the shell
|
// Initializing the position of the last element with the end boundary beyond the beginning boundary of the shell
|
||||||
instance.#last.element.style.marginTop =
|
instance.#last.element.style.marginTop =
|
||||||
-instance.#last.rectangle.height - instance.#last.offset + "px";
|
-instance.#last.rectangle.height - instance.#last.offsets + "px";
|
||||||
|
|
||||||
// Deleting position of the second (previously first) element (the movement is based on this property)
|
// Deleting position of the second (previously first) element (the movement is based on this property)
|
||||||
instance.#first.element.style.marginTop = null;
|
instance.#first.element.style.marginTop = null;
|
||||||
@@ -681,9 +683,9 @@ export default class hotline {
|
|||||||
// Horizontal
|
// Horizontal
|
||||||
|
|
||||||
// Initializing offset of the last element (elements are separated like this)
|
// Initializing offset of the last element (elements are separated like this)
|
||||||
instance.#last.offset =
|
instance.#last.offsets =
|
||||||
parseFloat(getComputedStyle(instance.#last.element).marginRight) ||
|
((parseFloat(getComputedStyle(instance.#last.element).marginRight) || 0) + (parseFloat(getComputedStyle(instance.#shell).gap) || 0)) ||
|
||||||
instance.#first.offset ||
|
instance.#first.offsets ||
|
||||||
0;
|
0;
|
||||||
|
|
||||||
if (instance.events.get("transfer.beginning")) {
|
if (instance.events.get("transfer.beginning")) {
|
||||||
@@ -694,7 +696,7 @@ export default class hotline {
|
|||||||
new CustomEvent("hotline.transfer.beginning", {
|
new CustomEvent("hotline.transfer.beginning", {
|
||||||
detail: {
|
detail: {
|
||||||
element: instance.#last.element,
|
element: instance.#last.element,
|
||||||
offset: instance.#last.rectangle.width + instance.#last.offset
|
offset: instance.#last.rectangle.width + instance.#last.offsets
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -702,7 +704,7 @@ export default class hotline {
|
|||||||
|
|
||||||
// Initializing the position of the last element with the end boundary beyond the beginning boundary of the shell
|
// Initializing the position of the last element with the end boundary beyond the beginning boundary of the shell
|
||||||
instance.#last.element.style.marginLeft =
|
instance.#last.element.style.marginLeft =
|
||||||
-instance.#last.rectangle.width - instance.#last.offset + "px";
|
-instance.#last.rectangle.width - instance.#last.offsets + "px";
|
||||||
|
|
||||||
// Deleting position of the second (previously first) element (the movement is based on this property)
|
// Deleting position of the second (previously first) element (the movement is based on this property)
|
||||||
instance.#first.element.style.marginLeft = null;
|
instance.#first.element.style.marginLeft = null;
|
||||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user