Comparing version 0.3.1 to 0.4.0
/*! | ||
* AnchorJS - v0.3.1 - 2015-03-06 | ||
* AnchorJS - v0.4.0 - 2015-04-20 | ||
* https://github.com/bryanbraun/anchorjs | ||
@@ -45,8 +45,11 @@ * Copyright (c) 2015 Bryan Braun; Licensed MIT | ||
// Refine it so it makes a good ID. Strip out non-safe characters, replace | ||
// spaces with hyphens, make lowercase, and truncate to 32 characters. | ||
// Ex. Hello World --> hello-world | ||
var tidyText = roughText.replace(/[^\w\s-]/gi, '') | ||
.replace(/\s+/g, '-') | ||
.toLowerCase() | ||
.substring(0, 32); | ||
// spaces with hyphens, truncate to 32 characters, and make toLowerCase. | ||
// | ||
// Example string: // "⚡⚡⚡ Unicode icons are cool--but don't belong in a URL." | ||
var tidyText = roughText.replace(/[^\w\s-]/gi, '') // " Unicode icons are cool--but dont belong in a URL" | ||
.replace(/\s+/g, '-') // "-Unicode-icons-are-cool--but-dont-belong-in-a-URL" | ||
.replace(/-{2,}/g, '-') // "-Unicode-icons-are-cool-but-dont-belong-in-a-URL" | ||
.substring(0, 32) // "-Unicode-icons-are-cool-but-dont" | ||
.replace(/^-+|-+$/gm, '') // "Unicode-icons-are-cool-but-dont" | ||
.toLowerCase(); // "unicode-icons-are-cool-but-dont" | ||
@@ -53,0 +56,0 @@ // Compare our generated ID to existing IDs (and increment it if needed) |
/*! | ||
* AnchorJS - v0.3.1 - 2015-03-06 | ||
* AnchorJS - v0.4.0 - 2015-04-20 | ||
* https://github.com/bryanbraun/anchorjs | ||
* Copyright (c) 2015 Bryan Braun; Licensed MIT | ||
*/ | ||
function addAnchors(e){"use strict";if(e){if("string"!=typeof e)throw new Error("AnchorJS accepts only strings; you used a "+typeof e)}else e="h1, h2, h3, h4, h5, h6";var t=document.querySelectorAll(e);if(0===t.length)return!1;for(var r=document.querySelectorAll("[id]"),n=[].map.call(r,function(e){return e.id}),i=0;i<t.length;i++){var s;if(t[i].hasAttribute("id"))s=t[i].getAttribute("id");else{var o,a=document.body.textContent?"textContent":"innerText",c=t[i][a],l=c.replace(/[^\w\s-]/gi,"").replace(/\s+/g,"-").toLowerCase().substring(0,32),h=0,d=l;do void 0!==o&&(d=l+"-"+h),o=n.indexOf(d),h+=1;while(-1!==o);o=void 0,n.push(d),t[i].setAttribute("id",d),s=d}var u=s.replace(/-/g," "),p='<a class="anchorjs-link" href="#'+s+'"><span class="anchorjs-description">Anchor link for: '+u+'</span><span class="anchorjs-icon" aria-hidden="true"></span></a>';t[i].innerHTML+=p}} | ||
function addAnchors(e){"use strict";if(e){if("string"!=typeof e)throw new Error("AnchorJS accepts only strings; you used a "+typeof e)}else e="h1, h2, h3, h4, h5, h6";var r=document.querySelectorAll(e);if(0===r.length)return!1;for(var t=document.querySelectorAll("[id]"),n=[].map.call(t,function(e){return e.id}),i=0;i<r.length;i++){var s;if(r[i].hasAttribute("id"))s=r[i].getAttribute("id");else{var a,o=document.body.textContent?"textContent":"innerText",c=r[i][o],l=c.replace(/[^\w\s-]/gi,"").replace(/\s+/g,"-").replace(/-{2,}/g,"-").substring(0,32).replace(/^-+|-+$/gm,"").toLowerCase(),h=0,d=l;do void 0!==a&&(d=l+"-"+h),a=n.indexOf(d),h+=1;while(-1!==a);a=void 0,n.push(d),r[i].setAttribute("id",d),s=d}var u=s.replace(/-/g," "),p='<a class="anchorjs-link" href="#'+s+'"><span class="anchorjs-description">Anchor link for: '+u+'</span><span class="anchorjs-icon" aria-hidden="true"></span></a>';r[i].innerHTML+=p}} |
{ | ||
"name": "anchor-js", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"authors": [ | ||
@@ -5,0 +5,0 @@ "Bryan Braun" |
{ | ||
"name": "anchor-js", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"author": "bryanbraun (https://github.com/bryanbraun)", | ||
@@ -21,4 +21,4 @@ "description": "A tiny javscript utility for adding anchor links to existing page content.", | ||
"devDependencies": { | ||
"eslint": "~0.15.1", | ||
"jshint": "~2.6.3", | ||
"eslint": "~0.19.0", | ||
"jshint": "~2.7.0", | ||
"uglify-js": "~2.4.16" | ||
@@ -25,0 +25,0 @@ }, |
Sorry, the diff of this file is not supported yet
26300
186