@ucd-lib/theme-elements 0.0.2 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/brand/ucd-theme-header/ucd-theme-header.js +67 -31
- package/brand/ucd-theme-header/ucd-theme-header.tpl.js +58 -23
- package/brand/ucd-theme-pagination/ucd-theme-pagination.js +12 -6
- package/brand/ucd-theme-primary-nav/ucd-theme-primary-nav.js +32 -104
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.js +9 -34
- package/brand/ucd-theme-quick-links/ucd-theme-quick-links.tpl.js +1 -1
- package/brand/ucd-theme-search-form/ucd-theme-search-form.js +7 -1
- package/brand/ucd-theme-search-form/ucd-theme-search-form.tpl.js +8 -3
- package/brand/ucd-theme-search-popup/ucd-theme-search-popup.js +3 -3
- package/brand/ucd-theme-slim-select/ucd-theme-slim-select.js +62 -0
- package/brand/ucd-theme-slim-select/ucd-theme-slim-select.tpl.js +26 -0
- package/brand/ucd-theme-subnav/ucd-theme-subnav.js +196 -0
- package/brand/ucd-theme-subnav/ucd-theme-subnav.tpl.js +60 -0
- package/package.json +5 -4
- package/ucdlib/ucdlib-branding-bar/book.js +4 -0
- package/ucdlib/ucdlib-branding-bar/logo.js +67 -0
- package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.js +101 -0
- package/ucdlib/ucdlib-branding-bar/ucdlib-branding-bar.tpl.js +102 -0
- package/ucdlib/ucdlib-icon/ucdlib-icon.tpl.js +2 -0
- package/ucdlib/ucdlib-icons/sitefarm.js +107 -0
- package/ucdlib/ucdlib-icons/ucdlib-icons.js +7 -1
- package/ucdlib/ucdlib-icons/utils.js +3 -3
- package/ucdlib/ucdlib-iconset/ucdlib-iconset.js +5 -2
- package/ucdlib/ucdlib-pages/ucdlib-pages.js +4 -4
- package/utils/{break-points.js → controllers/break-points.js} +8 -9
- package/utils/controllers/index.js +11 -0
- package/utils/controllers/intersection-observer.js +58 -0
- package/utils/controllers/mutation-observer.js +52 -0
- package/utils/controllers/wait.js +43 -0
- package/utils/mixins/index.js +8 -0
- package/utils/{main-dom-element.js → mixins/main-dom-element.js} +0 -0
- package/utils/{mixin.js → mixins/mixin.js} +0 -0
- package/utils/mixins/nav-element.js +103 -0
- package/utils/index.js +0 -6
- package/utils/mutation-observer.js +0 -47
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @function NavElement
|
|
3
|
+
* @param {Class} superClass - LitElement or child class.
|
|
4
|
+
* @description Adds utilities for navigation to a LitElement
|
|
5
|
+
*
|
|
6
|
+
* @returns {Class} LitElement with Nav utilities attached
|
|
7
|
+
*/
|
|
8
|
+
const NavElement = (superClass) => class extends superClass {
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
this.navItems = [];
|
|
13
|
+
this.maxDepth = 2;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @method parseChildren
|
|
18
|
+
* @description Creates a tree-like nav Array structure from element children
|
|
19
|
+
* @param {HTMLCollection} children - Element children (non-shadow)
|
|
20
|
+
* @returns {Array}
|
|
21
|
+
*/
|
|
22
|
+
parseNavChildren( children=this.children ){
|
|
23
|
+
if ( !children ) return [];
|
|
24
|
+
children = Array.from(this.children);
|
|
25
|
+
let navItems = children.map((child) => this._makeNavItemTree(child)).filter(navItem => navItem.linkText);
|
|
26
|
+
return navItems;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @method _makeNavItemTree
|
|
31
|
+
* @private
|
|
32
|
+
* @description Extracts menu item data from DOM Element
|
|
33
|
+
* @param {Element} ele - Element
|
|
34
|
+
* @returns {Object} Formatted object describing the menu item and its children
|
|
35
|
+
*/
|
|
36
|
+
_makeNavItemTree(ele){
|
|
37
|
+
let linkText, href, subItems = [], isOpen=false, inlineStyles={}, newTab=false;
|
|
38
|
+
if ( ele.tagName === 'LI' && ele.children.length > 0) ele = ele.children[0];
|
|
39
|
+
|
|
40
|
+
if ( ele.tagName === 'A' ) {
|
|
41
|
+
linkText = ele.innerText;
|
|
42
|
+
href = ele.href;
|
|
43
|
+
} else if ( ele.tagName === 'LI' ) {
|
|
44
|
+
linkText = ele.innerText;
|
|
45
|
+
} else if ( ele.tagName === 'OL' || ele.tagName === 'UL' ) {
|
|
46
|
+
linkText = ele.getAttribute('link-text');
|
|
47
|
+
href = ele.getAttribute('href');
|
|
48
|
+
isOpen = ele.hasAttribute('is-open');
|
|
49
|
+
|
|
50
|
+
for (const child of Array.from(ele.children)) {
|
|
51
|
+
let childItem = this._makeNavItemTree(child);
|
|
52
|
+
if ( childItem.linkText ) subItems.push(childItem);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (ele.getAttribute('target') == '_blank') newTab = true;
|
|
56
|
+
|
|
57
|
+
if ( linkText ) linkText = linkText.trim();
|
|
58
|
+
return {linkText, href, subItems, isOpen, inlineStyles, newTab};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @method getNavItem
|
|
63
|
+
* @description Retrieves an item from the navItems array.
|
|
64
|
+
* @param {Array} location - Coordinates of the item in the 'navItems' array. i.e. [0, 1, 4].
|
|
65
|
+
* @returns {Object}
|
|
66
|
+
*/
|
|
67
|
+
getNavItem(location){
|
|
68
|
+
let accessor = "this.navItems";
|
|
69
|
+
if ( location && location.length > 0) {
|
|
70
|
+
accessor += "[" + location.join("].subItems[") + "]";
|
|
71
|
+
}
|
|
72
|
+
return eval(accessor);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @method itemHasSubNav
|
|
77
|
+
* @description Utility function for determining if a menu has subitems
|
|
78
|
+
* @param {Object} navItem - A member of the navItems array.
|
|
79
|
+
* @returns {Boolean}
|
|
80
|
+
*/
|
|
81
|
+
itemHasSubNav(navItem){
|
|
82
|
+
if ( navItem && navItem.subItems && navItem.subItems.length) return true;
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @method clearMobileAnimationStyles
|
|
88
|
+
* @description Removes inline styles on a nav element (used for mobile transition animation)
|
|
89
|
+
* @param {Object} navItem - Member of the this.navItems array
|
|
90
|
+
*/
|
|
91
|
+
clearItemInlineStyles(navItem){
|
|
92
|
+
if (
|
|
93
|
+
navItem &&
|
|
94
|
+
navItem.inlineStyles &&
|
|
95
|
+
Object.keys(navItem.inlineStyles).length > 0
|
|
96
|
+
) {
|
|
97
|
+
navItem.inlineStyles = {};
|
|
98
|
+
this.requestUpdate();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export {NavElement};
|
package/utils/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import Mixin from './mixin.js';
|
|
2
|
-
import {MutationObserverElement} from './mutation-observer.js';
|
|
3
|
-
import {MainDomElement} from './main-dom-element.js';
|
|
4
|
-
import { BreakPoints } from './break-points.js';
|
|
5
|
-
|
|
6
|
-
export {Mixin, MutationObserverElement, MainDomElement, BreakPoints};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @function MutationObserverElement
|
|
3
|
-
* @param {Class} superClass - LitElement or child class.
|
|
4
|
-
* @description add default functionality for mutation observer
|
|
5
|
-
*
|
|
6
|
-
* @returns {Class} LitElement with mutation observer attached.
|
|
7
|
-
*/
|
|
8
|
-
const MutationObserverElement = (superClass) => class extends superClass {
|
|
9
|
-
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
this._childListObserver = null;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @method firstUpdated
|
|
17
|
-
* @description called on first DOM render. Call the _onChildListMutation method
|
|
18
|
-
*
|
|
19
|
-
* @param {Set} props
|
|
20
|
-
*/
|
|
21
|
-
firstUpdated(props) {
|
|
22
|
-
super.firstUpdated(props);
|
|
23
|
-
this._onChildListMutation();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @method connectedCallback
|
|
28
|
-
* @description Native lifecycle method called when element is connected
|
|
29
|
-
*/
|
|
30
|
-
connectedCallback(){
|
|
31
|
-
super.connectedCallback();
|
|
32
|
-
this._childListObserver = new MutationObserver(
|
|
33
|
-
(mutationsList, observer) => this._onChildListMutation(mutationsList, observer));
|
|
34
|
-
this._childListObserver.observe(this, {childList: true});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* @method disconnectedCallback
|
|
39
|
-
* @description Native lifecycle method called when element is disconnected
|
|
40
|
-
*/
|
|
41
|
-
disconnectedCallback(){
|
|
42
|
-
this._childListObserver.disconnect();
|
|
43
|
-
super.disconnectedCallback();
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export {MutationObserverElement};
|