Vendored
+1
-1
@@ -6,4 +6,4 @@
|
||||
* @version 0.0.2
|
||||
* Copyright 2015. MIT licensed.
|
||||
*/
|
||||
!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):e(jQuery)}(function(e){"use strict";var n=function(e){if("string"!=typeof e)return 0;var n=e.match(/\d/g);return n?Math.min.apply(null,n):1},t=function(n,t){for(;t--;)n=e("<ol/>").appendTo(n);return n},r=function(e,n){return 0>n?r(e.parent(),n+1):n>0?t(e,n):e.parent()},o=function(e,n){return function(t,r,o){var i=t.text(),a=n+"-"+o;r.text(i);var c=t[0],f=r[0],u=e?a:c.id||a;u=encodeURIComponent(u),c.id=u,f.href="#"+u}},i=function(t){var i=t.selector,a=t.scope,c=e("<ol/>"),f=c,u=n(i),h=o(t.overwrite,t.prefix);return e(a).find(i).each(function(t,o){var i=n(o.tagName),a=i-u,p=e("<li/>"),s=e("<a/>"),l=r(f,a);l.length||(l=c),h(e(o),s,t),p.append(s).appendTo(l),f=p,u=i}),c};e.fn.initTOC=function(n){var t={selector:"h1, h2, h3, h4, h5, h6",scope:"body",overwrite:!1,prefix:"toc"};n=e.extend(t,n);var r=n.selector;if("string"!=typeof r)throw new TypeError("selector must be a string");if(!r.match(/^(?:h[1-6],?\s*)+$/g))throw new TypeError("selector must contains only h1-6");e(this).append(i(n));var o=location.hash;return o&&setTimeout(function(){location.hash="",location.hash=o},0),e(this)}});
|
||||
!function(e){"function"==typeof define&&define.amd?define("jquery.toc",["jquery"],e):e(jQuery)}(function(e){"use strict";var t=function(e){if("string"!=typeof e)return 0;var t=e.match(/\d/g);return t?Math.min.apply(null,t):1},n=function(t,n){for(;n--;)t=e("<ol/>").appendTo(t);return t},r=function(e,t){return 0>t?r(e.parent(),t+1):t>0?n(e,t):e.parent()},o=function(e,t){return function(n,r,o){var i=n.text(),a=t+"-"+o;r.text(i);var c=n[0],f=r[0],u=e?a:c.id||a;u=encodeURIComponent(u),c.id=u,f.href="#"+u}},i=function(n){var i=n.selector,a=n.scope,c=e("<ol/>"),f=c,u=t(i),h=o(n.overwrite,n.prefix);return e(a).find(i).each(function(n,o){var i=t(o.tagName),a=i-u,p=e("<li/>"),s=e("<a/>"),l=r(f,a);l.length||(l=c),h(e(o),s,n),p.append(s).appendTo(l),f=p,u=i}),c};e.fn.initTOC=function(t){var n={selector:"h1, h2, h3, h4, h5, h6",scope:"body",overwrite:!1,prefix:"toc"};t=e.extend(n,t);var r=t.selector;if("string"!=typeof r)throw new TypeError("selector must be a string");if(!r.match(/^(?:h[1-6],?\s*)*$/g))throw new TypeError("selector must contains only h1-6");e(this).append(i(t));var o=location.hash;return o&&setTimeout(function(){location.hash="",location.hash=o},0),e(this)}});
|
||||
Vendored
+1
-1
@@ -6,4 +6,4 @@
|
||||
* @version 0.0.2
|
||||
* Copyright 2015. MIT licensed.
|
||||
*/
|
||||
!function(e){"use strict";var t=function(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&(e[n]=t[n]);return e},n=function(e,t){var n=[],r=document.querySelectorAll(t);return Array.prototype.forEach.call(r,function(t){var r=t.querySelectorAll(e);n=n.concat(Array.prototype.slice.call(r))}),n},r=function(e){if("string"!=typeof e)return 0;var t=e.match(/\d/g);return t?Math.min.apply(null,t):1},o=function(e,t){for(;t--;){var n=document.createElement("ol");e.appendChild(n),e=n}return e},c=function(e,t){return 0>t?c(e.parentElement,t+1):t>0?o(e,t):e.parentElement},i=function(e,t){return function(n,r,o){var c=n.textContent,i=t+"-"+o;r.textContent=c;var a=e?i:n.id||i;a=encodeURIComponent(a),n.id=a,r.href="#"+a}},a=function(e){var t=e.selector,o=e.scope,a=document.createElement("ol"),u=a,l=i(e.overwrite,e.prefix);return n(t,o).reduce(function(e,t,n){var o=r(t.tagName),i=o-e,f=c(u,i)||a,h=document.createElement("li"),p=document.createElement("a");return l(t,p,n),f.appendChild(h).appendChild(p),u=h,o},r(t)),a},u=function(e){var n={selector:"h1, h2, h3, h4, h5, h6",scope:"body",overwrite:!1,prefix:"toc"};e=t(n,e);var r=e.selector;if("string"!=typeof r)throw new TypeError("selector must be a string");if(!r.match(/^(?:h[1-6],?\s*)+$/g))throw new TypeError("selector must contains only h1-6");var o=location.hash;return o&&setTimeout(function(){location.hash="",location.hash=o},0),a(e)};"function"==typeof define&&define.amd?define(function(){return u}):e.initTOC=u}(window);
|
||||
!function(e){"use strict";var t=function(e,t){for(var n in t)t.hasOwnProperty(n)&&t[n]&&(e[n]=t[n]);return e},n=function(e,t){var n=[],r=document.querySelectorAll(t);return Array.prototype.forEach.call(r,function(t){var r=t.querySelectorAll(e);n=n.concat(Array.prototype.slice.call(r))}),n},r=function(e){if("string"!=typeof e)return 0;var t=e.match(/\d/g);return t?Math.min.apply(null,t):1},o=function(e,t){for(;t--;){var n=document.createElement("ol");e.appendChild(n),e=n}return e},c=function(e,t){return 0>t?c(e.parentElement,t+1):t>0?o(e,t):e.parentElement},i=function(e,t){return function(n,r,o){var c=(n.textContent,t+"-"+o);r.textContent=n.textContent;var i=e?c:n.id||c;i=encodeURIComponent(i),n.id=i,r.href="#"+i}},a=function(e){var t=e.selector,o=e.scope,a=document.createElement("ol"),u=a,l=i(e.overwrite,e.prefix);return n(t,o).reduce(function(e,t,n){var o=r(t.tagName),i=o-e,f=c(u,i)||a,h=document.createElement("li"),p=document.createElement("a");return l(t,p,n),f.appendChild(h).appendChild(p),u=h,o},r(t)),a},u=function(e){var n={selector:"h1, h2, h3, h4, h5, h6",scope:"body",overwrite:!1,prefix:"toc"};e=t(n,e);var r=e.selector;if("string"!=typeof r)throw new TypeError("selector must be a string");if(!r.match(/^(?:h[1-6],?\s*)*$/g))throw new TypeError("selector must contains only h1-6");var o=location.hash;return o&&setTimeout(function(){location.hash="",location.hash=o},0),a(e)};"function"==typeof define&&define.amd?define("toc",[],function(){return u}):e.initTOC=u}(window);
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define(['jquery'], factory);
|
||||
define('jquery.toc', ['jquery'], factory);
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
@@ -149,7 +149,7 @@
|
||||
throw new TypeError('selector must be a string');
|
||||
}
|
||||
|
||||
if (!selector.match(/^(?:h[1-6],?\s*)+$/g)) {
|
||||
if (!selector.match(/^(?:h[1-6],?\s*)*$/g)) {
|
||||
throw new TypeError('selector must contains only h1-6')
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -58,7 +58,7 @@
|
||||
return function (src, target, index) {
|
||||
var content = src.textContent;
|
||||
var pre = prefix + '-' + index;
|
||||
target.textContent = content;
|
||||
target.textContent = src.textContent;
|
||||
|
||||
var id = overwrite ? pre : (src.id || pre);
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
|
||||
src.id = id;
|
||||
target.href = '#' + id;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
var buildTOC = function (options) {
|
||||
@@ -113,7 +113,7 @@
|
||||
throw new TypeError('selector must be a string');
|
||||
}
|
||||
|
||||
if (!selector.match(/^(?:h[1-6],?\s*)+$/g)) {
|
||||
if (!selector.match(/^(?:h[1-6],?\s*)*$/g)) {
|
||||
throw new TypeError('selector must contains only h1-6')
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
};
|
||||
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define(function () {
|
||||
define('toc', [], function () {
|
||||
return initTOC;
|
||||
});
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user