summaryrefslogtreecommitdiff
path: root/minionlivesmatter/templates/assets/tether/src/js/abutment.js
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-03-24 17:12:23 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2017-03-24 17:12:23 +0100
commit54b8482223288a4d5df41267f3c9235bab06c15e (patch)
tree2df9f4e43168ab4fcda02e67740bf9772985eb5a /minionlivesmatter/templates/assets/tether/src/js/abutment.js
parenta2d5335f18e053c14e8f88efa5f97368777341be (diff)
downloadmeta-54b8482223288a4d5df41267f3c9235bab06c15e.tar.gz
meta-54b8482223288a4d5df41267f3c9235bab06c15e.zip
add minionlivesmatter
Diffstat (limited to 'minionlivesmatter/templates/assets/tether/src/js/abutment.js')
-rw-r--r--minionlivesmatter/templates/assets/tether/src/js/abutment.js61
1 files changed, 61 insertions, 0 deletions
diff --git a/minionlivesmatter/templates/assets/tether/src/js/abutment.js b/minionlivesmatter/templates/assets/tether/src/js/abutment.js
new file mode 100644
index 0000000..9605635
--- /dev/null
+++ b/minionlivesmatter/templates/assets/tether/src/js/abutment.js
@@ -0,0 +1,61 @@
+/* globals TetherBase */
+
+const {getBounds, updateClasses, defer} = TetherBase.Utils;
+
+TetherBase.modules.push({
+ position({top, left}) {
+ const {height, width} = this.cache('element-bounds', () => {
+ return getBounds(this.element);
+ });
+
+ const targetPos = this.getTargetBounds();
+
+ const bottom = top + height;
+ const right = left + width;
+
+ const abutted = [];
+ if (top <= targetPos.bottom && bottom >= targetPos.top) {
+ ['left', 'right'].forEach(side => {
+ const targetPosSide = targetPos[side];
+ if (targetPosSide === left || targetPosSide === right) {
+ abutted.push(side);
+ }
+ });
+ }
+
+ if (left <= targetPos.right && right >= targetPos.left) {
+ ['top', 'bottom'].forEach(side => {
+ const targetPosSide = targetPos[side];
+ if (targetPosSide === top || targetPosSide === bottom) {
+ abutted.push(side);
+ }
+ });
+ }
+
+ const allClasses = [];
+ const addClasses = [];
+
+ const sides = ['left', 'top', 'right', 'bottom'];
+ allClasses.push(this.getClass('abutted'));
+ sides.forEach(side => {
+ allClasses.push(`${ this.getClass('abutted') }-${ side }`);
+ });
+
+ if (abutted.length) {
+ addClasses.push(this.getClass('abutted'));
+ }
+
+ abutted.forEach(side => {
+ addClasses.push(`${ this.getClass('abutted') }-${ side }`);
+ });
+
+ defer(() => {
+ if (!(this.options.addTargetClasses === false)) {
+ updateClasses(this.target, addClasses, allClasses);
+ }
+ updateClasses(this.element, addClasses, allClasses);
+ });
+
+ return true;
+ }
+});