| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
(function(tocify) { |
| 7 |
|
| 8 |
|
| 9 |
"use strict"; |
| 10 |
|
| 11 |
|
| 12 |
tocify(window.jQuery, window, document); |
| 13 |
|
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
(function($, window, document, undefined) { |
| 18 |
|
| 19 |
|
| 20 |
"use strict"; |
| 21 |
|
| 22 |
var tocClassName = "tocify", |
| 23 |
tocClass = "." + tocClassName, |
| 24 |
tocFocusClassName = "tocify-focus", |
| 25 |
tocHoverClassName = "tocify-hover", |
| 26 |
hideTocClassName = "tocify-hide", |
| 27 |
hideTocClass = "." + hideTocClassName, |
| 28 |
headerClassName = "tocify-header", |
| 29 |
headerClass = "." + headerClassName, |
| 30 |
subheaderClassName = "tocify-subheader", |
| 31 |
subheaderClass = "." + subheaderClassName, |
| 32 |
itemClassName = "tocify-item", |
| 33 |
itemClass = "." + itemClassName, |
| 34 |
extendPageClassName = "tocify-extend-page", |
| 35 |
extendPageClass = "." + extendPageClassName; |
| 36 |
|
| 37 |
|
| 38 |
$.widget("toc.tocify", { |
| 39 |
|
| 40 |
|
| 41 |
version: "1.9.1", |
| 42 |
|
| 43 |
|
| 44 |
options: { |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
context: "body", |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
ignoreSelector: null, |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
selectors: "h1, h2, h3", |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
showAndHide: true, |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
showEffect: "slideDown", |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
showEffectSpeed: "medium", |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
hideEffect: "slideUp", |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
hideEffectSpeed: "medium", |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
smoothScroll: true, |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
smoothScrollSpeed: "medium", |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
scrollTo: 0, |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
showAndHideOnScroll: true, |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
highlightOnScroll: true, |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
highlightOffset: 40, |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
theme: "bootstrap", |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
extendPage: true, |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
extendPageOffset: 100, |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
history: true, |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
scrollHistory: false, |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
hashGenerator: "compact", |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
highlightDefault: true |
| 134 |
|
| 135 |
}, |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
_create: function() { |
| 141 |
|
| 142 |
var self = this; |
| 143 |
|
| 144 |
self.extendPageScroll = true; |
| 145 |
|
| 146 |
|
| 147 |
self.items = []; |
| 148 |
|
| 149 |
|
| 150 |
self._generateToc(); |
| 151 |
|
| 152 |
|
| 153 |
self._addCSSClasses(); |
| 154 |
|
| 155 |
self.webkit = (function() { |
| 156 |
|
| 157 |
for (var prop in window) { |
| 158 |
|
| 159 |
if (prop) { |
| 160 |
|
| 161 |
if (prop.toLowerCase().indexOf("webkit") !== -1) { |
| 162 |
|
| 163 |
return true; |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
} |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
return false; |
| 172 |
|
| 173 |
}()); |
| 174 |
|
| 175 |
|
| 176 |
self._setEventHandlers(); |
| 177 |
|
| 178 |
|
| 179 |
$(window).on("load", function() { |
| 180 |
|
| 181 |
|
| 182 |
self._setActiveElement(true); |
| 183 |
|
| 184 |
|
| 185 |
$("html, body").promise().done(function() { |
| 186 |
|
| 187 |
setTimeout(function() { |
| 188 |
|
| 189 |
self.extendPageScroll = false; |
| 190 |
|
| 191 |
}, 0); |
| 192 |
|
| 193 |
}); |
| 194 |
|
| 195 |
}); |
| 196 |
|
| 197 |
}, |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
_generateToc: function() { |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
var self = this, |
| 208 |
|
| 209 |
|
| 210 |
firstElem, |
| 211 |
|
| 212 |
|
| 213 |
ul, |
| 214 |
ignoreSelector = self.options.ignoreSelector; |
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
firstElem = []; |
| 220 |
var selectors = this.options.selectors.replace(/ /g, "").split(","); |
| 221 |
|
| 222 |
for(var i = 0; i < selectors.length; i++) { |
| 223 |
var foundSelectors = $(this.options.context).find(selectors[i]); |
| 224 |
for (var s = 0; s < foundSelectors.length; s++) { |
| 225 |
if (!$(foundSelectors[s]).is(ignoreSelector)) { |
| 226 |
firstElem = foundSelectors; |
| 227 |
break; |
| 228 |
} |
| 229 |
} |
| 230 |
if (firstElem.length> 0) |
| 231 |
break; |
| 232 |
} |
| 233 |
|
| 234 |
if (!firstElem.length) { |
| 235 |
|
| 236 |
self.element.addClass(hideTocClassName); |
| 237 |
|
| 238 |
return; |
| 239 |
|
| 240 |
} |
| 241 |
|
| 242 |
self.element.addClass(tocClassName); |
| 243 |
|
| 244 |
|
| 245 |
firstElem.each(function(index) { |
| 246 |
|
| 247 |
|
| 248 |
if ($(this).is(ignoreSelector)) { |
| 249 |
return; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
ul = $("<ul/>", { |
| 254 |
"id": headerClassName + index, |
| 255 |
"class": headerClassName |
| 256 |
}). |
| 257 |
|
| 258 |
|
| 259 |
append(self._nestElements($(this), index)); |
| 260 |
|
| 261 |
|
| 262 |
self.element.append(ul); |
| 263 |
|
| 264 |
|
| 265 |
$(this).nextUntil(this.nodeName.toLowerCase()).each(function() { |
| 266 |
|
| 267 |
|
| 268 |
if ($(this).find(self.options.selectors).length === 0) { |
| 269 |
|
| 270 |
|
| 271 |
$(this).filter(self.options.selectors).each(function() { |
| 272 |
|
| 273 |
|
| 274 |
if ($(this).is(ignoreSelector)) { |
| 275 |
return; |
| 276 |
} |
| 277 |
|
| 278 |
self._appendSubheaders.call(this, self, ul); |
| 279 |
|
| 280 |
}); |
| 281 |
|
| 282 |
} |
| 283 |
|
| 284 |
|
| 285 |
else { |
| 286 |
|
| 287 |
|
| 288 |
$(this).find(self.options.selectors).each(function() { |
| 289 |
|
| 290 |
|
| 291 |
if ($(this).is(ignoreSelector)) { |
| 292 |
return; |
| 293 |
} |
| 294 |
|
| 295 |
self._appendSubheaders.call(this, self, ul); |
| 296 |
|
| 297 |
}); |
| 298 |
|
| 299 |
} |
| 300 |
|
| 301 |
}); |
| 302 |
|
| 303 |
}); |
| 304 |
|
| 305 |
}, |
| 306 |
|
| 307 |
_setActiveElement: function(pageload) { |
| 308 |
|
| 309 |
var self = this, |
| 310 |
|
| 311 |
hash = window.location.hash.substring(1), |
| 312 |
|
| 313 |
elem = self.element.find('li[data-unique="' + hash + '"]'); |
| 314 |
|
| 315 |
if (hash.length) { |
| 316 |
|
| 317 |
|
| 318 |
self.element.find("." + self.focusClass).removeClass(self.focusClass); |
| 319 |
|
| 320 |
|
| 321 |
elem.addClass(self.focusClass); |
| 322 |
|
| 323 |
|
| 324 |
elem.click(); |
| 325 |
|
| 326 |
} else { |
| 327 |
|
| 328 |
|
| 329 |
self.element.find("." + self.focusClass).removeClass(self.focusClass); |
| 330 |
|
| 331 |
if (!hash.length && pageload && self.options.highlightDefault) { |
| 332 |
|
| 333 |
|
| 334 |
self.element.find(itemClass).first().addClass(self.focusClass); |
| 335 |
|
| 336 |
} |
| 337 |
|
| 338 |
} |
| 339 |
|
| 340 |
return self; |
| 341 |
|
| 342 |
}, |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
_nestElements: function(self, index) { |
| 348 |
|
| 349 |
var arr, item, hashValue; |
| 350 |
|
| 351 |
arr = $.grep(this.items, function(item) { |
| 352 |
|
| 353 |
return item === self.text(); |
| 354 |
|
| 355 |
}); |
| 356 |
|
| 357 |
|
| 358 |
if (arr.length) { |
| 359 |
|
| 360 |
|
| 361 |
this.items.push(self.text() + index); |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
else { |
| 367 |
|
| 368 |
|
| 369 |
this.items.push(self.text()); |
| 370 |
|
| 371 |
} |
| 372 |
|
| 373 |
hashValue = this._generateHashValue(arr, self, index); |
| 374 |
|
| 375 |
|
| 376 |
item = $("<li/>", { |
| 377 |
|
| 378 |
|
| 379 |
"class": itemClassName, |
| 380 |
|
| 381 |
"data-unique": hashValue |
| 382 |
|
| 383 |
}); |
| 384 |
|
| 385 |
if (this.options.theme !== "bootstrap3") { |
| 386 |
|
| 387 |
item.append($("<a/>", { |
| 388 |
|
| 389 |
"html": self.html() |
| 390 |
|
| 391 |
})); |
| 392 |
|
| 393 |
} else { |
| 394 |
|
| 395 |
item.html(self.html()); |
| 396 |
|
| 397 |
} |
| 398 |
|
| 399 |
|
| 400 |
self.before($("<div/>", { |
| 401 |
|
| 402 |
|
| 403 |
"name": hashValue, |
| 404 |
|
| 405 |
"data-unique": hashValue |
| 406 |
|
| 407 |
})); |
| 408 |
|
| 409 |
return item; |
| 410 |
|
| 411 |
}, |
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
_generateHashValue: function(arr, self, index) { |
| 417 |
|
| 418 |
var hashValue = "", |
| 419 |
hashGeneratorOption = this.options.hashGenerator; |
| 420 |
|
| 421 |
if (hashGeneratorOption === "pretty") { |
| 422 |
|
| 423 |
|
| 424 |
hashValue = self.text().toLowerCase().replace(/\s/g, "-"); |
| 425 |
|
| 426 |
|
| 427 |
while (hashValue.indexOf("--") > -1) { |
| 428 |
hashValue = hashValue.replace(/--/g, "-"); |
| 429 |
} |
| 430 |
|
| 431 |
|
| 432 |
while (hashValue.indexOf(":-") > -1) { |
| 433 |
hashValue = hashValue.replace(/:-/g, "-"); |
| 434 |
} |
| 435 |
|
| 436 |
} else if (typeof hashGeneratorOption === "function") { |
| 437 |
|
| 438 |
|
| 439 |
hashValue = hashGeneratorOption(self.text(), self); |
| 440 |
|
| 441 |
} else { |
| 442 |
|
| 443 |
|
| 444 |
hashValue = self.text().replace(/\s/g, ""); |
| 445 |
|
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
if (arr.length) { |
| 450 |
hashValue += "" + index; |
| 451 |
} |
| 452 |
|
| 453 |
|
| 454 |
return hashValue; |
| 455 |
|
| 456 |
}, |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
_appendSubheaders: function(self, ul) { |
| 463 |
|
| 464 |
|
| 465 |
var index = $(this).index(self.options.selectors), |
| 466 |
|
| 467 |
|
| 468 |
previousHeader = $(self.options.selectors).eq(index - 1), |
| 469 |
|
| 470 |
currentTagName = +$(this).prop("tagName").charAt(1), |
| 471 |
|
| 472 |
previousTagName = +previousHeader.prop("tagName").charAt(1), |
| 473 |
|
| 474 |
lastSubheader; |
| 475 |
|
| 476 |
|
| 477 |
if (currentTagName < previousTagName) { |
| 478 |
|
| 479 |
|
| 480 |
self.element.find(subheaderClass + "[data-tag=" + currentTagName + "]").last().append(self._nestElements($(this), index)); |
| 481 |
|
| 482 |
} |
| 483 |
|
| 484 |
|
| 485 |
else if (currentTagName === previousTagName) { |
| 486 |
|
| 487 |
ul.find(itemClass).last().after(self._nestElements($(this), index)); |
| 488 |
|
| 489 |
} else { |
| 490 |
|
| 491 |
|
| 492 |
ul.find(itemClass).last(). |
| 493 |
|
| 494 |
|
| 495 |
after($("<ul/>", { |
| 496 |
|
| 497 |
"class": subheaderClassName, |
| 498 |
|
| 499 |
"data-tag": currentTagName |
| 500 |
|
| 501 |
})).next(subheaderClass). |
| 502 |
|
| 503 |
|
| 504 |
append(self._nestElements($(this), index)); |
| 505 |
} |
| 506 |
|
| 507 |
}, |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
_setEventHandlers: function() { |
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
var self = this, |
| 518 |
|
| 519 |
|
| 520 |
$self, |
| 521 |
|
| 522 |
|
| 523 |
duration; |
| 524 |
|
| 525 |
|
| 526 |
this.element.on("click.tocify", "li", function(event) { |
| 527 |
|
| 528 |
if (self.options.history) { |
| 529 |
|
| 530 |
window.location.hash = $(this).attr("data-unique"); |
| 531 |
|
| 532 |
} |
| 533 |
|
| 534 |
|
| 535 |
self.element.find("." + self.focusClass).removeClass(self.focusClass); |
| 536 |
|
| 537 |
|
| 538 |
$(this).addClass(self.focusClass); |
| 539 |
|
| 540 |
|
| 541 |
if (self.options.showAndHide) { |
| 542 |
|
| 543 |
var elem = $('li[data-unique="' + $(this).attr("data-unique") + '"]'); |
| 544 |
|
| 545 |
self._triggerShow(elem); |
| 546 |
|
| 547 |
} |
| 548 |
|
| 549 |
self._scrollTo($(this)); |
| 550 |
|
| 551 |
}); |
| 552 |
|
| 553 |
|
| 554 |
this.element.find("li").on({ |
| 555 |
|
| 556 |
|
| 557 |
"mouseenter.tocify": function() { |
| 558 |
|
| 559 |
|
| 560 |
$(this).addClass(self.hoverClass); |
| 561 |
|
| 562 |
|
| 563 |
$(this).css("cursor", "pointer"); |
| 564 |
|
| 565 |
}, |
| 566 |
|
| 567 |
|
| 568 |
"mouseleave.tocify": function() { |
| 569 |
|
| 570 |
if (self.options.theme !== "bootstrap") { |
| 571 |
|
| 572 |
|
| 573 |
$(this).removeClass(self.hoverClass); |
| 574 |
|
| 575 |
} |
| 576 |
|
| 577 |
} |
| 578 |
}); |
| 579 |
|
| 580 |
|
| 581 |
if (self.options.extendPage || self.options.highlightOnScroll || self.options.scrollHistory || self.options.showAndHideOnScroll) { |
| 582 |
|
| 583 |
$(window).on("scroll.tocify", function() { |
| 584 |
|
| 585 |
|
| 586 |
$("html, body").promise().done(function() { |
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
var winScrollTop = $(window).scrollTop(), |
| 592 |
|
| 593 |
|
| 594 |
winHeight = $(window).height(), |
| 595 |
|
| 596 |
|
| 597 |
docHeight = $(document).height(), |
| 598 |
|
| 599 |
scrollHeight = $("body")[0].scrollHeight, |
| 600 |
|
| 601 |
|
| 602 |
elem, |
| 603 |
|
| 604 |
lastElem, |
| 605 |
|
| 606 |
lastElemOffset, |
| 607 |
|
| 608 |
currentElem; |
| 609 |
|
| 610 |
if (self.options.extendPage) { |
| 611 |
|
| 612 |
|
| 613 |
if ((self.webkit && winScrollTop >= scrollHeight - winHeight - self.options.extendPageOffset) || (!self.webkit && winHeight + winScrollTop > docHeight - self.options.extendPageOffset)) { |
| 614 |
|
| 615 |
if (!$(extendPageClass).length) { |
| 616 |
|
| 617 |
lastElem = $('div[data-unique="' + $(itemClass).last().attr("data-unique") + '"]'); |
| 618 |
|
| 619 |
if (!lastElem.length) return; |
| 620 |
|
| 621 |
|
| 622 |
lastElemOffset = lastElem.offset().top; |
| 623 |
|
| 624 |
|
| 625 |
$(self.options.context).append($("<div/>", { |
| 626 |
|
| 627 |
"class": extendPageClassName, |
| 628 |
|
| 629 |
"height": Math.abs(lastElemOffset - winScrollTop) + "px", |
| 630 |
|
| 631 |
"data-unique": extendPageClassName |
| 632 |
|
| 633 |
})); |
| 634 |
|
| 635 |
if (self.extendPageScroll) { |
| 636 |
|
| 637 |
currentElem = self.element.find('li.' + self.focusClass); |
| 638 |
|
| 639 |
self._scrollTo($('div[data-unique="' + currentElem.attr("data-unique") + '"]')); |
| 640 |
|
| 641 |
} |
| 642 |
|
| 643 |
} |
| 644 |
|
| 645 |
} |
| 646 |
|
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
setTimeout(function() { |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
var closestAnchorDistance = null, |
| 656 |
|
| 657 |
|
| 658 |
closestAnchorIdx = null, |
| 659 |
|
| 660 |
|
| 661 |
anchors = $(self.options.context).find("div[data-unique]"), |
| 662 |
|
| 663 |
anchorText; |
| 664 |
|
| 665 |
|
| 666 |
anchors.each(function(idx) { |
| 667 |
var distance = Math.abs(($(this).next().length ? $(this).next() : $(this)).offset().top - winScrollTop - self.options.highlightOffset); |
| 668 |
if (closestAnchorDistance == null || distance < closestAnchorDistance) { |
| 669 |
closestAnchorDistance = distance; |
| 670 |
closestAnchorIdx = idx; |
| 671 |
} else { |
| 672 |
return false; |
| 673 |
} |
| 674 |
}); |
| 675 |
|
| 676 |
anchorText = $(anchors[closestAnchorIdx]).attr("data-unique"); |
| 677 |
|
| 678 |
|
| 679 |
elem = $('li[data-unique="' + anchorText + '"]'); |
| 680 |
|
| 681 |
|
| 682 |
if (self.options.highlightOnScroll && elem.length) { |
| 683 |
|
| 684 |
|
| 685 |
self.element.find("." + self.focusClass).removeClass(self.focusClass); |
| 686 |
|
| 687 |
|
| 688 |
elem.addClass(self.focusClass); |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
if (self.options.scrollHistory) { |
| 693 |
|
| 694 |
if (window.location.hash !== "#" + anchorText) { |
| 695 |
|
| 696 |
window.location.replace("#" + anchorText); |
| 697 |
|
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
|
| 702 |
if (self.options.showAndHideOnScroll && self.options.showAndHide) { |
| 703 |
|
| 704 |
self._triggerShow(elem, true); |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
}, 0); |
| 709 |
|
| 710 |
}); |
| 711 |
|
| 712 |
}); |
| 713 |
} |
| 714 |
|
| 715 |
}, |
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
show: function(elem, scroll) { |
| 721 |
|
| 722 |
|
| 723 |
var self = this, |
| 724 |
element = elem; |
| 725 |
|
| 726 |
|
| 727 |
if (!elem.is(":visible")) { |
| 728 |
|
| 729 |
|
| 730 |
if (!elem.find(subheaderClass).length && !elem.parent().is(headerClass) && !elem.parent().is(":visible")) { |
| 731 |
|
| 732 |
|
| 733 |
elem = elem.parents(subheaderClass).add(elem); |
| 734 |
|
| 735 |
} |
| 736 |
|
| 737 |
|
| 738 |
else if (!elem.children(subheaderClass).length && !elem.parent().is(headerClass)) { |
| 739 |
|
| 740 |
|
| 741 |
elem = elem.closest(subheaderClass); |
| 742 |
|
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
switch (self.options.showEffect) { |
| 747 |
|
| 748 |
|
| 749 |
case "none": |
| 750 |
|
| 751 |
elem.show(); |
| 752 |
|
| 753 |
break; |
| 754 |
|
| 755 |
|
| 756 |
case "show": |
| 757 |
|
| 758 |
elem.show(self.options.showEffectSpeed); |
| 759 |
|
| 760 |
break; |
| 761 |
|
| 762 |
|
| 763 |
case "slideDown": |
| 764 |
|
| 765 |
elem.slideDown(self.options.showEffectSpeed); |
| 766 |
|
| 767 |
break; |
| 768 |
|
| 769 |
|
| 770 |
case "fadeIn": |
| 771 |
|
| 772 |
elem.fadeIn(self.options.showEffectSpeed); |
| 773 |
|
| 774 |
break; |
| 775 |
|
| 776 |
|
| 777 |
default: |
| 778 |
|
| 779 |
elem.show(); |
| 780 |
|
| 781 |
break; |
| 782 |
|
| 783 |
} |
| 784 |
|
| 785 |
} |
| 786 |
|
| 787 |
|
| 788 |
if (elem.parent().is(headerClass)) { |
| 789 |
|
| 790 |
|
| 791 |
self.hide($(subheaderClass).not(elem)); |
| 792 |
|
| 793 |
} |
| 794 |
|
| 795 |
|
| 796 |
else { |
| 797 |
|
| 798 |
|
| 799 |
self.hide($(subheaderClass).not(elem.closest(headerClass).find(subheaderClass).not(elem.siblings()))); |
| 800 |
|
| 801 |
} |
| 802 |
|
| 803 |
|
| 804 |
return self; |
| 805 |
|
| 806 |
}, |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
hide: function(elem) { |
| 812 |
|
| 813 |
|
| 814 |
var self = this; |
| 815 |
|
| 816 |
|
| 817 |
switch (self.options.hideEffect) { |
| 818 |
|
| 819 |
|
| 820 |
case "none": |
| 821 |
|
| 822 |
elem.hide(); |
| 823 |
|
| 824 |
break; |
| 825 |
|
| 826 |
|
| 827 |
case "hide": |
| 828 |
|
| 829 |
elem.hide(self.options.hideEffectSpeed); |
| 830 |
|
| 831 |
break; |
| 832 |
|
| 833 |
|
| 834 |
case "slideUp": |
| 835 |
|
| 836 |
elem.slideUp(self.options.hideEffectSpeed); |
| 837 |
|
| 838 |
break; |
| 839 |
|
| 840 |
|
| 841 |
case "fadeOut": |
| 842 |
|
| 843 |
elem.fadeOut(self.options.hideEffectSpeed); |
| 844 |
|
| 845 |
break; |
| 846 |
|
| 847 |
|
| 848 |
default: |
| 849 |
|
| 850 |
elem.hide(); |
| 851 |
|
| 852 |
break; |
| 853 |
|
| 854 |
} |
| 855 |
|
| 856 |
|
| 857 |
return self; |
| 858 |
}, |
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
_triggerShow: function(elem, scroll) { |
| 864 |
|
| 865 |
var self = this; |
| 866 |
|
| 867 |
|
| 868 |
if (elem.parent().is(headerClass) || elem.next().is(subheaderClass)) { |
| 869 |
|
| 870 |
|
| 871 |
self.show(elem.next(subheaderClass), scroll); |
| 872 |
|
| 873 |
} |
| 874 |
|
| 875 |
|
| 876 |
else if (elem.parent().is(subheaderClass)) { |
| 877 |
|
| 878 |
|
| 879 |
self.show(elem.parent(), scroll); |
| 880 |
|
| 881 |
} |
| 882 |
|
| 883 |
|
| 884 |
return self; |
| 885 |
|
| 886 |
}, |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
_addCSSClasses: function() { |
| 892 |
|
| 893 |
|
| 894 |
if (this.options.theme === "jqueryui") { |
| 895 |
|
| 896 |
this.focusClass = "ui-state-default"; |
| 897 |
|
| 898 |
this.hoverClass = "ui-state-hover"; |
| 899 |
|
| 900 |
|
| 901 |
this.element.addClass("ui-widget").find(".toc-title").addClass("ui-widget-header").end().find("li").addClass("ui-widget-content"); |
| 902 |
|
| 903 |
} |
| 904 |
|
| 905 |
|
| 906 |
else if (this.options.theme === "bootstrap") { |
| 907 |
|
| 908 |
this.element.find(headerClass + "," + subheaderClass).addClass("nav nav-list"); |
| 909 |
|
| 910 |
this.focusClass = "active"; |
| 911 |
|
| 912 |
} |
| 913 |
|
| 914 |
|
| 915 |
else if (this.options.theme === "bootstrap3") { |
| 916 |
|
| 917 |
this.element.find(headerClass + "," + subheaderClass).addClass("list-group"); |
| 918 |
|
| 919 |
this.element.find(itemClass).addClass("list-group-item"); |
| 920 |
|
| 921 |
this.focusClass = "active"; |
| 922 |
|
| 923 |
} |
| 924 |
|
| 925 |
|
| 926 |
else { |
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
this.focusClass = tocFocusClassName; |
| 931 |
|
| 932 |
this.hoverClass = tocHoverClassName; |
| 933 |
|
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
return this; |
| 938 |
|
| 939 |
}, |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
setOption: function() { |
| 945 |
|
| 946 |
|
| 947 |
$.Widget.prototype._setOption.apply(this, arguments); |
| 948 |
|
| 949 |
}, |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
setOptions: function() { |
| 955 |
|
| 956 |
|
| 957 |
$.Widget.prototype._setOptions.apply(this, arguments); |
| 958 |
|
| 959 |
}, |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
_scrollTo: function(elem) { |
| 965 |
|
| 966 |
var self = this, |
| 967 |
duration = self.options.smoothScroll || 0, |
| 968 |
scrollTo = self.options.scrollTo, |
| 969 |
currentDiv = $('div[data-unique="' + elem.attr("data-unique") + '"]'); |
| 970 |
|
| 971 |
if (!currentDiv.length) { |
| 972 |
|
| 973 |
return self; |
| 974 |
|
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
$("html, body").promise().done(function() { |
| 979 |
|
| 980 |
|
| 981 |
$("html, body").animate({ |
| 982 |
|
| 983 |
|
| 984 |
"scrollTop": currentDiv.offset().top - ($.isFunction(scrollTo) ? scrollTo.call() : scrollTo) + "px" |
| 985 |
|
| 986 |
}, { |
| 987 |
|
| 988 |
|
| 989 |
"duration": duration |
| 990 |
|
| 991 |
}); |
| 992 |
|
| 993 |
}); |
| 994 |
|
| 995 |
|
| 996 |
return self; |
| 997 |
|
| 998 |
} |
| 999 |
|
| 1000 |
}); |
| 1001 |
|
| 1002 |
})); |