Skip to content

Commit 563163c

Browse files
committed
1 parent b07c700 commit 563163c

Some content is hidden

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

66 files changed

+19585
-0
lines changed

js/v16.0.0/assets/anchor.js

+350
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
/*!
2+
* AnchorJS - v4.0.0 - 2017-06-02
3+
* https://github.com/bryanbraun/anchorjs
4+
* Copyright (c) 2017 Bryan Braun; Licensed MIT
5+
*/
6+
/* eslint-env amd, node */
7+
8+
// https://github.com/umdjs/umd/blob/master/templates/returnExports.js
9+
(function(root, factory) {
10+
'use strict';
11+
if (typeof define === 'function' && define.amd) {
12+
// AMD. Register as an anonymous module.
13+
define([], factory);
14+
} else if (typeof module === 'object' && module.exports) {
15+
// Node. Does not work with strict CommonJS, but
16+
// only CommonJS-like environments that support module.exports,
17+
// like Node.
18+
module.exports = factory();
19+
} else {
20+
// Browser globals (root is window)
21+
root.AnchorJS = factory();
22+
root.anchors = new root.AnchorJS();
23+
}
24+
})(this, function() {
25+
'use strict';
26+
function AnchorJS(options) {
27+
this.options = options || {};
28+
this.elements = [];
29+
30+
/**
31+
* Assigns options to the internal options object, and provides defaults.
32+
* @param {Object} opts - Options object
33+
*/
34+
function _applyRemainingDefaultOptions(opts) {
35+
opts.icon = opts.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'.
36+
opts.visible = opts.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always' & 'touch'
37+
opts.placement = opts.hasOwnProperty('placement')
38+
? opts.placement
39+
: 'right'; // Also accepts 'left'
40+
opts.class = opts.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name.
41+
// Using Math.floor here will ensure the value is Number-cast and an integer.
42+
opts.truncate = opts.hasOwnProperty('truncate')
43+
? Math.floor(opts.truncate)
44+
: 64; // Accepts any value that can be typecast to a number.
45+
}
46+
47+
_applyRemainingDefaultOptions(this.options);
48+
49+
/**
50+
* Checks to see if this device supports touch. Uses criteria pulled from Modernizr:
51+
* https://github.com/Modernizr/Modernizr/blob/da22eb27631fc4957f67607fe6042e85c0a84656/feature-detects/touchevents.js#L40
52+
* @returns {Boolean} - true if the current device supports touch.
53+
*/
54+
this.isTouchDevice = function() {
55+
return !!(
56+
'ontouchstart' in window ||
57+
(window.DocumentTouch && document instanceof DocumentTouch)
58+
);
59+
};
60+
61+
/**
62+
* Add anchor links to page elements.
63+
* @param {String|Array|Nodelist} selector - A CSS selector for targeting the elements you wish to add anchor links
64+
* to. Also accepts an array or nodeList containing the relavant elements.
65+
* @returns {this} - The AnchorJS object
66+
*/
67+
this.add = function(selector) {
68+
var elements,
69+
elsWithIds,
70+
idList,
71+
elementID,
72+
i,
73+
index,
74+
count,
75+
tidyText,
76+
newTidyText,
77+
readableID,
78+
anchor,
79+
visibleOptionToUse,
80+
indexesToDrop = [];
81+
82+
// We reapply options here because somebody may have overwritten the default options object when setting options.
83+
// For example, this overwrites all options but visible:
84+
//
85+
// anchors.options = { visible: 'always'; }
86+
_applyRemainingDefaultOptions(this.options);
87+
88+
visibleOptionToUse = this.options.visible;
89+
if (visibleOptionToUse === 'touch') {
90+
visibleOptionToUse = this.isTouchDevice() ? 'always' : 'hover';
91+
}
92+
93+
// Provide a sensible default selector, if none is given.
94+
if (!selector) {
95+
selector = 'h2, h3, h4, h5, h6';
96+
}
97+
98+
elements = _getElements(selector);
99+
100+
if (elements.length === 0) {
101+
return this;
102+
}
103+
104+
_addBaselineStyles();
105+
106+
// We produce a list of existing IDs so we don't generate a duplicate.
107+
elsWithIds = document.querySelectorAll('[id]');
108+
idList = [].map.call(elsWithIds, function assign(el) {
109+
return el.id;
110+
});
111+
112+
for (i = 0; i < elements.length; i++) {
113+
if (this.hasAnchorJSLink(elements[i])) {
114+
indexesToDrop.push(i);
115+
continue;
116+
}
117+
118+
if (elements[i].hasAttribute('id')) {
119+
elementID = elements[i].getAttribute('id');
120+
} else if (elements[i].hasAttribute('data-anchor-id')) {
121+
elementID = elements[i].getAttribute('data-anchor-id');
122+
} else {
123+
tidyText = this.urlify(elements[i].textContent);
124+
125+
// Compare our generated ID to existing IDs (and increment it if needed)
126+
// before we add it to the page.
127+
newTidyText = tidyText;
128+
count = 0;
129+
do {
130+
if (index !== undefined) {
131+
newTidyText = tidyText + '-' + count;
132+
}
133+
134+
index = idList.indexOf(newTidyText);
135+
count += 1;
136+
} while (index !== -1);
137+
index = undefined;
138+
idList.push(newTidyText);
139+
140+
elements[i].setAttribute('id', newTidyText);
141+
elementID = newTidyText;
142+
}
143+
144+
readableID = elementID.replace(/-/g, ' ');
145+
146+
// The following code builds the following DOM structure in a more effiecient (albeit opaque) way.
147+
// '<a class="anchorjs-link ' + this.options.class + '" href="#' + elementID + '" aria-label="Anchor link for: ' + readableID + '" data-anchorjs-icon="' + this.options.icon + '"></a>';
148+
anchor = document.createElement('a');
149+
anchor.className = 'anchorjs-link ' + this.options.class;
150+
anchor.href = '#' + elementID;
151+
anchor.setAttribute('aria-label', 'Anchor link for: ' + readableID);
152+
anchor.setAttribute('data-anchorjs-icon', this.options.icon);
153+
154+
if (visibleOptionToUse === 'always') {
155+
anchor.style.opacity = '1';
156+
}
157+
158+
if (this.options.icon === '\ue9cb') {
159+
anchor.style.font = '1em/1 anchorjs-icons';
160+
161+
// We set lineHeight = 1 here because the `anchorjs-icons` font family could otherwise affect the
162+
// height of the heading. This isn't the case for icons with `placement: left`, so we restore
163+
// line-height: inherit in that case, ensuring they remain positioned correctly. For more info,
164+
// see https://github.com/bryanbraun/anchorjs/issues/39.
165+
if (this.options.placement === 'left') {
166+
anchor.style.lineHeight = 'inherit';
167+
}
168+
}
169+
170+
if (this.options.placement === 'left') {
171+
anchor.style.position = 'absolute';
172+
anchor.style.marginLeft = '-1em';
173+
anchor.style.paddingRight = '0.5em';
174+
elements[i].insertBefore(anchor, elements[i].firstChild);
175+
} else {
176+
// if the option provided is `right` (or anything else).
177+
anchor.style.paddingLeft = '0.375em';
178+
elements[i].appendChild(anchor);
179+
}
180+
}
181+
182+
for (i = 0; i < indexesToDrop.length; i++) {
183+
elements.splice(indexesToDrop[i] - i, 1);
184+
}
185+
this.elements = this.elements.concat(elements);
186+
187+
return this;
188+
};
189+
190+
/**
191+
* Removes all anchorjs-links from elements targed by the selector.
192+
* @param {String|Array|Nodelist} selector - A CSS selector string targeting elements with anchor links,
193+
* OR a nodeList / array containing the DOM elements.
194+
* @returns {this} - The AnchorJS object
195+
*/
196+
this.remove = function(selector) {
197+
var index,
198+
domAnchor,
199+
elements = _getElements(selector);
200+
201+
for (var i = 0; i < elements.length; i++) {
202+
domAnchor = elements[i].querySelector('.anchorjs-link');
203+
if (domAnchor) {
204+
// Drop the element from our main list, if it's in there.
205+
index = this.elements.indexOf(elements[i]);
206+
if (index !== -1) {
207+
this.elements.splice(index, 1);
208+
}
209+
// Remove the anchor from the DOM.
210+
elements[i].removeChild(domAnchor);
211+
}
212+
}
213+
return this;
214+
};
215+
216+
/**
217+
* Removes all anchorjs links. Mostly used for tests.
218+
*/
219+
this.removeAll = function() {
220+
this.remove(this.elements);
221+
};
222+
223+
/**
224+
* Urlify - Refine text so it makes a good ID.
225+
*
226+
* To do this, we remove apostrophes, replace nonsafe characters with hyphens,
227+
* remove extra hyphens, truncate, trim hyphens, and make lowercase.
228+
*
229+
* @param {String} text - Any text. Usually pulled from the webpage element we are linking to.
230+
* @returns {String} - hyphen-delimited text for use in IDs and URLs.
231+
*/
232+
this.urlify = function(text) {
233+
// Regex for finding the nonsafe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\
234+
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\]/g,
235+
urlText;
236+
237+
// The reason we include this _applyRemainingDefaultOptions is so urlify can be called independently,
238+
// even after setting options. This can be useful for tests or other applications.
239+
if (!this.options.truncate) {
240+
_applyRemainingDefaultOptions(this.options);
241+
}
242+
243+
// Note: we trim hyphens after truncating because truncating can cause dangling hyphens.
244+
// Example string: // " ⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
245+
urlText = text
246+
.trim() // "⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
247+
.replace(/\'/gi, '') // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
248+
.replace(nonsafeChars, '-') // "⚡⚡-Dont-forget--URL-fragments-should-be-i18n-friendly--hyphenated--short--and-clean-"
249+
.replace(/-{2,}/g, '-') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-short-and-clean-"
250+
.substring(0, this.options.truncate) // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-"
251+
.replace(/^-+|-+$/gm, '') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated"
252+
.toLowerCase(); // "⚡⚡-dont-forget-url-fragments-should-be-i18n-friendly-hyphenated"
253+
254+
return urlText;
255+
};
256+
257+
/**
258+
* Determines if this element already has an AnchorJS link on it.
259+
* Uses this technique: http://stackoverflow.com/a/5898748/1154642
260+
* @param {HTMLElemnt} el - a DOM node
261+
* @returns {Boolean} true/false
262+
*/
263+
this.hasAnchorJSLink = function(el) {
264+
var hasLeftAnchor =
265+
el.firstChild &&
266+
(' ' + el.firstChild.className + ' ').indexOf(' anchorjs-link ') > -1,
267+
hasRightAnchor =
268+
el.lastChild &&
269+
(' ' + el.lastChild.className + ' ').indexOf(' anchorjs-link ') > -1;
270+
271+
return hasLeftAnchor || hasRightAnchor || false;
272+
};
273+
274+
/**
275+
* Turns a selector, nodeList, or array of elements into an array of elements (so we can use array methods).
276+
* It also throws errors on any other inputs. Used to handle inputs to .add and .remove.
277+
* @param {String|Array|Nodelist} input - A CSS selector string targeting elements with anchor links,
278+
* OR a nodeList / array containing the DOM elements.
279+
* @returns {Array} - An array containing the elements we want.
280+
*/
281+
function _getElements(input) {
282+
var elements;
283+
if (typeof input === 'string' || input instanceof String) {
284+
// See https://davidwalsh.name/nodelist-array for the technique transforming nodeList -> Array.
285+
elements = [].slice.call(document.querySelectorAll(input));
286+
// I checked the 'input instanceof NodeList' test in IE9 and modern browsers and it worked for me.
287+
} else if (Array.isArray(input) || input instanceof NodeList) {
288+
elements = [].slice.call(input);
289+
} else {
290+
throw new Error('The selector provided to AnchorJS was invalid.');
291+
}
292+
return elements;
293+
}
294+
295+
/**
296+
* _addBaselineStyles
297+
* Adds baseline styles to the page, used by all AnchorJS links irregardless of configuration.
298+
*/
299+
function _addBaselineStyles() {
300+
// We don't want to add global baseline styles if they've been added before.
301+
if (document.head.querySelector('style.anchorjs') !== null) {
302+
return;
303+
}
304+
305+
var style = document.createElement('style'),
306+
linkRule =
307+
' .anchorjs-link {' +
308+
' opacity: 0;' +
309+
' text-decoration: none;' +
310+
' -webkit-font-smoothing: antialiased;' +
311+
' -moz-osx-font-smoothing: grayscale;' +
312+
' }',
313+
hoverRule =
314+
' *:hover > .anchorjs-link,' +
315+
' .anchorjs-link:focus {' +
316+
' opacity: 1;' +
317+
' }',
318+
anchorjsLinkFontFace =
319+
' @font-face {' +
320+
' font-family: "anchorjs-icons";' + // Icon from icomoon; 10px wide & 10px tall; 2 empty below & 4 above
321+
' src: url(data:n/a;base64,AAEAAAALAIAAAwAwT1MvMg8yG2cAAAE4AAAAYGNtYXDp3gC3AAABpAAAAExnYXNwAAAAEAAAA9wAAAAIZ2x5ZlQCcfwAAAH4AAABCGhlYWQHFvHyAAAAvAAAADZoaGVhBnACFwAAAPQAAAAkaG10eASAADEAAAGYAAAADGxvY2EACACEAAAB8AAAAAhtYXhwAAYAVwAAARgAAAAgbmFtZQGOH9cAAAMAAAAAunBvc3QAAwAAAAADvAAAACAAAQAAAAEAAHzE2p9fDzz1AAkEAAAAAADRecUWAAAAANQA6R8AAAAAAoACwAAAAAgAAgAAAAAAAAABAAADwP/AAAACgAAA/9MCrQABAAAAAAAAAAAAAAAAAAAAAwABAAAAAwBVAAIAAAAAAAIAAAAAAAAAAAAAAAAAAAAAAAMCQAGQAAUAAAKZAswAAACPApkCzAAAAesAMwEJAAAAAAAAAAAAAAAAAAAAARAAAAAAAAAAAAAAAAAAAAAAQAAg//0DwP/AAEADwABAAAAAAQAAAAAAAAAAAAAAIAAAAAAAAAIAAAACgAAxAAAAAwAAAAMAAAAcAAEAAwAAABwAAwABAAAAHAAEADAAAAAIAAgAAgAAACDpy//9//8AAAAg6cv//f///+EWNwADAAEAAAAAAAAAAAAAAAAACACEAAEAAAAAAAAAAAAAAAAxAAACAAQARAKAAsAAKwBUAAABIiYnJjQ3NzY2MzIWFxYUBwcGIicmNDc3NjQnJiYjIgYHBwYUFxYUBwYGIwciJicmNDc3NjIXFhQHBwYUFxYWMzI2Nzc2NCcmNDc2MhcWFAcHBgYjARQGDAUtLXoWOR8fORYtLTgKGwoKCjgaGg0gEhIgDXoaGgkJBQwHdR85Fi0tOAobCgoKOBoaDSASEiANehoaCQkKGwotLXoWOR8BMwUFLYEuehYXFxYugC44CQkKGwo4GkoaDQ0NDXoaShoKGwoFBe8XFi6ALjgJCQobCjgaShoNDQ0NehpKGgobCgoKLYEuehYXAAAADACWAAEAAAAAAAEACAAAAAEAAAAAAAIAAwAIAAEAAAAAAAMACAAAAAEAAAAAAAQACAAAAAEAAAAAAAUAAQALAAEAAAAAAAYACAAAAAMAAQQJAAEAEAAMAAMAAQQJAAIABgAcAAMAAQQJAAMAEAAMAAMAAQQJAAQAEAAMAAMAAQQJAAUAAgAiAAMAAQQJAAYAEAAMYW5jaG9yanM0MDBAAGEAbgBjAGgAbwByAGoAcwA0ADAAMABAAAAAAwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAH//wAP) format("truetype");' +
322+
' }',
323+
pseudoElContent =
324+
' [data-anchorjs-icon]::after {' +
325+
' content: attr(data-anchorjs-icon);' +
326+
' }',
327+
firstStyleEl;
328+
329+
style.className = 'anchorjs';
330+
style.appendChild(document.createTextNode('')); // Necessary for Webkit.
331+
332+
// We place it in the head with the other style tags, if possible, so as to
333+
// not look out of place. We insert before the others so these styles can be
334+
// overridden if necessary.
335+
firstStyleEl = document.head.querySelector('[rel="stylesheet"], style');
336+
if (firstStyleEl === undefined) {
337+
document.head.appendChild(style);
338+
} else {
339+
document.head.insertBefore(style, firstStyleEl);
340+
}
341+
342+
style.sheet.insertRule(linkRule, style.sheet.cssRules.length);
343+
style.sheet.insertRule(hoverRule, style.sheet.cssRules.length);
344+
style.sheet.insertRule(pseudoElContent, style.sheet.cssRules.length);
345+
style.sheet.insertRule(anchorjsLinkFontFace, style.sheet.cssRules.length);
346+
}
347+
}
348+
349+
return AnchorJS;
350+
});

js/v16.0.0/assets/bass-addons.css

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.input {
2+
font-family: inherit;
3+
display: block;
4+
width: 100%;
5+
height: 2rem;
6+
padding: .5rem;
7+
margin-bottom: 1rem;
8+
border: 1px solid #ccc;
9+
font-size: .875rem;
10+
border-radius: 3px;
11+
box-sizing: border-box;
12+
}

0 commit comments

Comments
 (0)