Skip to content

Commit 688a638

Browse files
committed
Docs: Clean JS imports
1 parent 8e02895 commit 688a638

12 files changed

+237
-3384
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/
22
*.DS_Store
33
TODO.md
4-
prepros.config
54
test.html

docs/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,6 @@ <h2>We love <code>.classes</code></h2>
12571257
</main><!-- ./ Main -->
12581258

12591259
<!-- JavaScript -->
1260-
<script src="//unpkg.com/most-visible@1.5.0/dist/most-visible.min.js"></script>
12611260
<script src="js/pico.docs.min.js"></script>
12621261

12631262
</body>

docs/js/pico.docs.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
*/
77

88
// Imports
9-
import { aside } from './src/aside.js';
10-
import { themeSwitcher } from './src/theme-switcher.js';
11-
import { materialDesignColors } from './src/material-design-colors.js';
12-
import { colorPicker } from './src/color-picker.js';
13-
import { grid } from './src/grid.js';
14-
import { scrollspy } from './src/scrollspy.js';
9+
import aside from './src/aside.js';
10+
import themeSwitcher from './src/theme-switcher.js';
11+
import materialDesignColors from './src/material-design-colors.js';
12+
import colorPicker from './src/color-picker.js';
13+
import grid from './src/grid.js';
14+
import scrollspy from './src/scrollspy.js';
1515

1616
// Aside initial state
1717
aside.init();

docs/js/pico.docs.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.

docs/js/src/aside.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ export const aside = {
2828
}
2929
}
3030
}
31+
32+
export default aside;

docs/js/src/color-picker.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,5 @@ export const colorPicker = {
170170
throw new Error('Bad Hex');
171171
}
172172
}
173+
174+
export default colorPicker;

docs/js/src/grid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,5 @@ export const grid = {
102102
}
103103
}
104104
};
105+
106+
export default grid;

docs/js/src/material-design-colors.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,5 @@ export const materialDesignColors = {
299299
inverse: "#FFF"
300300
}
301301
};
302+
303+
export default materialDesignColors;

docs/js/src/most-visible.js

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/**
2+
* Most Visible v1.5.0
3+
*
4+
* @author Andy Palmer <andy@andypalmer.me>
5+
* @license MIT
6+
*/
7+
(function (root, factory) {
8+
// Universal Module Definition
9+
10+
/* jshint strict:false */
11+
12+
/* global define: false, module: false */
13+
if (typeof define === 'function' && define.amd) {
14+
define([], function () {
15+
return factory(root);
16+
});
17+
} else if (typeof module === 'object' && module.exports) {
18+
module.exports = factory(root);
19+
} else {
20+
root.mostVisible = factory(root);
21+
}
22+
})(typeof self !== 'undefined' ? self : this, function (window) {
23+
/* jshint unused: vars */
24+
'use strict';
25+
/**
26+
* MostVisible constructor
27+
*
28+
* @param {NodeList|string} elements
29+
* @param {{}} options
30+
* @constructor
31+
*/
32+
33+
function MostVisible(elements, options) {
34+
if (!(this instanceof MostVisible)) {
35+
return new MostVisible(elements, options).getMostVisible();
36+
}
37+
38+
if (typeof elements === 'string') {
39+
elements = document.querySelectorAll(elements);
40+
}
41+
42+
this.elements = elements;
43+
this.options = extend({}, MostVisible.defaults, options);
44+
}
45+
/**
46+
* MostVisible default options
47+
*
48+
* @namespace
49+
* @property {{}} defaults Default options hash.
50+
* @property {boolean} defaults.percentage Whether to calculate visibility as a percentage of height.
51+
* @property {number} defaults.offset An offset to take into account when calculating visibility.
52+
*/
53+
54+
55+
MostVisible.defaults = {
56+
percentage: false,
57+
offset: 0
58+
};
59+
MostVisible.prototype = {
60+
/**
61+
* Returns the most visible element from the instance's NodeList.
62+
*
63+
* @returns {HTMLElement} Most visible element.
64+
*/
65+
getMostVisible: function () {
66+
var _this = this;
67+
68+
var viewportHeight = document.documentElement.clientHeight;
69+
return Array.prototype.reduce.call(this.elements, function (carry, element) {
70+
var value = _this.getVisibleHeight(element, viewportHeight);
71+
72+
return value > carry[0] ? [value, element] : carry;
73+
}, [0, null])[1];
74+
},
75+
76+
/**
77+
* Returns the visible height of an element.
78+
*
79+
* @param {HTMLElement} element Element to check the visibility of.
80+
* @param {number} viewportHeight
81+
* @returns {number} Visible height of the element in pixels or a percentage of the element's total height.
82+
*/
83+
getVisibleHeight: function (element, viewportHeight) {
84+
var rect = element.getBoundingClientRect(),
85+
rectTopOffset = rect.top - this.options.offset,
86+
rectBottomOffset = rect.bottom - this.options.offset,
87+
height = rect.bottom - rect.top,
88+
visible = {
89+
top: rectTopOffset >= 0 && rectTopOffset < viewportHeight,
90+
bottom: rectBottomOffset > 0 && rectBottomOffset < viewportHeight
91+
};
92+
var visiblePx = 0;
93+
94+
if (visible.top && visible.bottom) {
95+
// Whole element is visible
96+
visiblePx = height;
97+
} else if (visible.top) {
98+
visiblePx = viewportHeight - rect.top;
99+
} else if (visible.bottom) {
100+
visiblePx = rectBottomOffset;
101+
} else if (height > viewportHeight && rectTopOffset < 0) {
102+
var absTop = Math.abs(rectTopOffset);
103+
104+
if (absTop < height) {
105+
// Part of the element is visible
106+
visiblePx = height - absTop;
107+
}
108+
}
109+
110+
if (this.options.percentage) {
111+
return visiblePx / height * 100;
112+
}
113+
114+
return visiblePx;
115+
}
116+
};
117+
118+
MostVisible.makeJQueryPlugin = function ($) {
119+
if (!$) {
120+
return;
121+
}
122+
123+
$.fn.mostVisible = function (options) {
124+
var instance = new MostVisible(this.get(), options);
125+
return this.filter(instance.getMostVisible());
126+
};
127+
}; // Try adding the jQuery plugin to window.jQuery
128+
129+
130+
MostVisible.makeJQueryPlugin(window.jQuery);
131+
/**
132+
* Extends obj by adding the properties of all other objects passed to the function.
133+
*
134+
* @param {...{}} obj
135+
* @returns {{}} The extended object.
136+
*/
137+
138+
function extend(obj) {
139+
for (var i = 1; i < arguments.length; i++) {
140+
for (var key in arguments[i]) {
141+
obj[key] = arguments[i][key];
142+
}
143+
}
144+
145+
return obj;
146+
}
147+
148+
return MostVisible;
149+
});

docs/js/src/scrollspy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
* Copyright 2019-2021 - Licensed under MIT
99
*/
1010

11+
import * as MostVisible from './most-visible.js';
12+
1113
export const scrollspy = {
1214

15+
mostVisible() {
16+
new MostVisible()
17+
},
18+
1319
// Config
1420
minWidth: '992px',
1521
interval: 75,
@@ -61,3 +67,5 @@ export const scrollspy = {
6167
}.bind(this), false);
6268
}
6369
}
70+
71+
export default scrollspy;

docs/js/src/theme-switcher.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,5 @@ export const themeSwitcher = {
110110
}.bind(this));
111111
}
112112
}
113+
114+
export default themeSwitcher;

0 commit comments

Comments
 (0)