Skip to content

Commit

Permalink
⬆️ bump version from 4.2.2 → 4.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanbraun committed Oct 22, 2020
1 parent ebaabf6 commit 409cc09
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
4 changes: 2 additions & 2 deletions anchor.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anchor-js",
"version": "4.2.2",
"version": "4.3.0",
"authors": [
"Bryan Braun"
],
Expand Down
35 changes: 21 additions & 14 deletions docs/anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
* @param {Object} opts - Options object
*/
function _applyRemainingDefaultOptions(opts) {
opts.icon = opts.hasOwnProperty('icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'.
opts.visible = opts.hasOwnProperty('visible') ? opts.visible : 'hover'; // Also accepts 'always' & 'touch'
opts.placement = opts.hasOwnProperty('placement') ? opts.placement : 'right'; // Also accepts 'left'
opts.ariaLabel = opts.hasOwnProperty('ariaLabel') ? opts.ariaLabel : 'Anchor'; // Accepts any text.
opts.class = opts.hasOwnProperty('class') ? opts.class : ''; // Accepts any class name.
opts.base = opts.hasOwnProperty('base') ? opts.base : ''; // Accepts any base URI.
opts.icon = Object.prototype.hasOwnProperty.call(opts, 'icon') ? opts.icon : '\ue9cb'; // Accepts characters (and also URLs?), like '#', '¶', '❡', or '§'.
opts.visible = Object.prototype.hasOwnProperty.call(opts, 'visible') ? opts.visible : 'hover'; // Also accepts 'always' & 'touch'
opts.placement = Object.prototype.hasOwnProperty.call(opts, 'placement') ? opts.placement : 'right'; // Also accepts 'left'
opts.ariaLabel = Object.prototype.hasOwnProperty.call(opts, 'ariaLabel') ? opts.ariaLabel : 'Anchor'; // Accepts any text.
opts.class = Object.prototype.hasOwnProperty.call(opts, 'class') ? opts.class : ''; // Accepts any class name.
opts.base = Object.prototype.hasOwnProperty.call(opts, 'base') ? opts.base : ''; // Accepts any base URI.
// Using Math.floor here will ensure the value is Number-cast and an integer.
opts.truncate = opts.hasOwnProperty('truncate') ? Math.floor(opts.truncate) : 64; // Accepts any value that can be typecast to a number.
opts.titleText = opts.hasOwnProperty('titleText') ? opts.titleText : ''; // Accepts any text.
opts.truncate = Object.prototype.hasOwnProperty.call(opts, 'truncate') ? Math.floor(opts.truncate) : 64; // Accepts any value that can be typecast to a number.
opts.titleText = Object.prototype.hasOwnProperty.call(opts, 'titleText') ? opts.titleText : ''; // Accepts any text.
}

_applyRemainingDefaultOptions(this.options);
Expand All @@ -49,7 +49,7 @@
* @return {Boolean} - true if the current device supports touch.
*/
this.isTouchDevice = function() {
return !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch);
return Boolean('ontouchstart' in window || window.TouchEvent || window.DocumentTouch && document instanceof DocumentTouch);
};

/**
Expand Down Expand Up @@ -99,7 +99,7 @@

// We produce a list of existing IDs so we don't generate a duplicate.
elsWithIds = document.querySelectorAll('[id]');
idList = [].map.call(elsWithIds, function assign(el) {
idList = [].map.call(elsWithIds, function(el) {
return el.id;
});

Expand Down Expand Up @@ -128,6 +128,7 @@
index = idList.indexOf(newTidyText);
count += 1;
} while (index !== -1);

index = undefined;
idList.push(newTidyText);

Expand All @@ -149,6 +150,7 @@
if (this.options.titleText) {
anchor.title = this.options.titleText;
}

// Adjust the href if there's a <base> tag. See https://github.com/bryanbraun/anchorjs/issues/98
hrefBase = document.querySelector('base') ? window.location.pathname + window.location.search : '';
hrefBase = this.options.base || hrefBase;
Expand Down Expand Up @@ -184,6 +186,7 @@
for (i = 0; i < indexesToDrop.length; i++) {
elements.splice(indexesToDrop[i] - i, 1);
}

this.elements = this.elements.concat(elements);

return this;
Expand All @@ -208,10 +211,12 @@
if (index !== -1) {
this.elements.splice(index, 1);
}

// Remove the anchor from the DOM.
elements[i].removeChild(domAnchor);
}
}

return this;
};

Expand All @@ -237,8 +242,9 @@
textareaElement.innerHTML = text;
text = textareaElement.value;

// Regex for finding the non-safe URL characters (many need escaping): & +$,:;=?@"#{}|^~[`%!'<>]./()*\ (newlines, tabs, backspace, & vertical tabs)
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]\.\/\(\)\*\\\n\t\b\v\u00A0]/g,
// Regex for finding the non-safe URL characters (many need escaping):
// & +$,:;=?@"#{}|^~[`%!'<>]./()*\ (newlines, tabs, backspace, vertical tabs, and non-breaking space)
var nonsafeChars = /[& +$,:;=?@"#{}|^~[`%!'<>\]./()*\\\n\t\b\v\u00A0]/g,
urlText;

// The reason we include this _applyRemainingDefaultOptions is so urlify can be called independently,
Expand All @@ -250,7 +256,7 @@
// Note: we trim hyphens after truncating because truncating can cause dangling hyphens.
// Example string: // " ⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
urlText = text.trim() // "⚡⚡ Don't forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(/\'/gi, '') // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(/'/gi, '') // "⚡⚡ Dont forget: URL fragments should be i18n-friendly, hyphenated, short, and clean."
.replace(nonsafeChars, '-') // "⚡⚡-Dont-forget--URL-fragments-should-be-i18n-friendly--hyphenated--short--and-clean-"
.replace(/-{2,}/g, '-') // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-short-and-clean-"
.substring(0, this.options.truncate) // "⚡⚡-Dont-forget-URL-fragments-should-be-i18n-friendly-hyphenated-"
Expand Down Expand Up @@ -289,8 +295,9 @@
} else if (Array.isArray(input) || input instanceof NodeList) {
elements = [].slice.call(input);
} else {
throw new Error('The selector provided to AnchorJS was invalid.');
throw new TypeError('The selector provided to AnchorJS was invalid.');
}

return elements;
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "anchor-js",
"version": "4.2.2",
"version": "4.3.0",
"main": "anchor.js",
"author": "Bryan Braun (https://github.com/bryanbraun)",
"description": "A JavaScript utility for adding deep anchor links to online docs.",
Expand Down

0 comments on commit 409cc09

Please sign in to comment.