123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- define(["options", "jquery", "nav"], function (options, $, navConfig) {
-
- var path2root = null;
- $(document).ready ( function() {
-
- var topicRefExpandBtn = $(".wh_publication_toc .wh-expand-btn");
- topicRefExpandBtn.click(toggleTocExpand);
-
- topicRefExpandBtn.keypress(handleKeyEvent);
- });
-
- function getPathToRoot() {
- if (path2root == null) {
- path2root = $('meta[name="wh-path2root"]').attr("content");
- if (path2root == null || path2root == undefined) {
- path2root = "";
- }
- }
- return path2root;
- };
-
- function handleKeyEvent(event) {
-
- if ( event.which === 13 || event.which === 32) {
- event.preventDefault();
- toggleTocExpand.call(this);
- }
- }
- function toggleTocExpand() {
- var topicRef = $(this).closest(".topicref");
- var state = topicRef.attr(navConfig.attrs.state);
- var parentLi = $(this).closest('li');
- var titleLink = $(this).siblings(".title").children("a");
- var titleLinkID = titleLink.attr("id");
- if (state == null) {
-
- } else if (state == navConfig.states.pending) {
-
- } else if (state == navConfig.states.notReady) {
- topicRef.attr(navConfig.attrs.state, navConfig.states.pending);
- parentLi.attr('aria-expanded', 'true');
- $(this).attr("aria-labelledby", navConfig.btnIds.pending + " " + titleLinkID);
- retrieveChildNodes(topicRef);
- } else if (state == navConfig.states.expanded) {
- topicRef.attr(navConfig.attrs.state, navConfig.states.collapsed);
- $(this).attr("aria-labelledby", navConfig.btnIds.expand + " " + titleLinkID);
- parentLi.attr('aria-expanded', 'false');
- } else if (state == navConfig.states.collapsed) {
- topicRef.attr(navConfig.attrs.state, navConfig.states.expanded);
- $(this).attr("aria-labelledby", navConfig.btnIds.collapse + " " + titleLinkID);
- parentLi.attr('aria-expanded', 'true');
- }
- };
-
- function retrieveChildNodes(topicRefSpan) {
- var tocId = $(topicRefSpan).attr(navConfig.attrs.tocID);
- if (tocId != null) {
- var jsonHref = navConfig.jsonBaseDir + "/" + tocId;
- require(
- [jsonHref],
- function(data) {
- if (data != null) {
- var topics = data.topics;
- var topicLi = topicRefSpan.closest('li');
- var topicsUl = createTopicsList(topics);
- var topicsUlParent = $('<ul role="group"/>');
- topicsUl.forEach(function(topic){
- topicsUlParent.append(topic);
- });
- topicLi.append(topicsUlParent);
- var titleLink = topicRefSpan.find(".title > a");
- var titleLinkID = titleLink.attr("id");
- var expandBtn = topicRefSpan.children('.wh-expand-btn');
- expandBtn.attr("aria-labelledby", navConfig.btnIds.collapse + " " + titleLinkID);
- topicRefSpan.attr(navConfig.attrs.state, navConfig.states.expanded);
- } else {
- topicRefSpan.attr(navConfig.attrs.state, navConfig.states.leaf);
- }
- }
- );
- }
- }
-
- function createTopicsList(topics) {
- var topicsArray = [];
- topics.forEach(function(topic) {
- var topicLi = createTopicLi(topic);
- topicsArray.push(topicLi);
- });
- return topicsArray;
- };
-
- function createTopicLi(topic) {
- var li = $("<li>");
- li.attr('role', 'treeitem');
- if (hasChildren(topic)) {
- li.attr('aria-expanded', 'false');
- }
-
- var topicRefSpan = createTopicRefSpan(topic);
-
- li.append(topicRefSpan);
- return li;
- };
-
- function createTopicRefSpan(topic) {
- var isExternalReference = topic.scope == 'external';
-
- var topicRefSpan = $("<span>");
- topicRefSpan.addClass("topicref");
- if (topic.outputclass != null) {
- topicRefSpan.addClass(topic.outputclass);
- }
-
- var dataAttributes = topic.attributes;
- if (typeof dataAttributes !== 'undefined') {
- var attrsNames = Object.keys(dataAttributes);
- attrsNames.forEach(function(attr) {
- topicRefSpan.attr(attr, dataAttributes[attr]);
- });
- }
- topicRefSpan.attr(navConfig.attrs.tocID, topic.tocID);
-
- var containsChildren = hasChildren(topic);
- if (containsChildren) {
-
- topicRefSpan.attr(navConfig.attrs.state, navConfig.states.notReady);
- } else {
- topicRefSpan.attr(navConfig.attrs.state, navConfig.states.leaf);
- }
- var expandBtn = $("<span>", {
- class: "wh-expand-btn",
- role: "button"
- });
- if(containsChildren) {
- expandBtn.attr("aria-labelledby", navConfig.btnIds.expand + " " + getTopicLinkID(topic));
- expandBtn.attr("tabindex", "0");
- }
- expandBtn.click(toggleTocExpand);
- expandBtn.keypress(handleKeyEvent);
- topicRefSpan.append(expandBtn);
-
- var linkHref = '';
- if (topic.href != null && topic.href != 'javascript:void(0)') {
- if (!isExternalReference) {
- linkHref += getPathToRoot();
- }
- linkHref += topic.href;
- }
- var link = $("<a>", {
- href: linkHref,
- html: topic.title
- });
-
- var pathToRoot = getPathToRoot();
- var linksInLink = link.find("a[href]");
- linksInLink.each(function () {
- var href = $(this).attr("href");
- if (!(href.startsWith("http:") || href.startsWith("https:"))) {
- $(this).attr("href", pathToRoot + href);
- }
- });
- var imgsInLink = link.find("img[src]");
- imgsInLink.each(function () {
- var src = $(this).attr("src");
- if (!(src.startsWith("http:") || src.startsWith("https:"))) {
- $(this).attr("src", pathToRoot + src);
- }
- });
- link.attr("id", getTopicLinkID(topic));
- if (isExternalReference) {
- link.attr("target", "_blank");
- }
- var titleSpan = $("<span>", {
- class: "title"
- });
- titleSpan.append(link);
-
- if (topic.shortdesc != null) {
- var tooltipSpan = $("<span>", {
- class: "wh-tooltip",
- html: topic.shortdesc
- });
-
- if (tooltipSpan.find('.shortdesc:empty').length == 0) {
-
- var links = tooltipSpan.find("a[href]");
- links.each(function () {
- var href = $(this).attr("href");
- if (!(href.startsWith("http:") || href.startsWith("https:"))) {
- $(this).attr("href", pathToRoot + href);
- }
- });
- var imgs = tooltipSpan.find("img[src]");
- imgs.each(function () {
- var src = $(this).attr("src");
- if (!(src.startsWith("http:") || src.startsWith("https:"))) {
- $(this).attr("src", pathToRoot + src);
- }
- });
- titleSpan.append(tooltipSpan);
- }
- }
- topicRefSpan.append(titleSpan);
- return topicRefSpan;
- }
- function getTopicLinkID(topic) {
- return topic.tocID + "-link";
- }
- function hasChildren(topic) {
-
-
- var children = topic.topics;
- var hasChildren;
- if (children != null && children.length == 0) {
- hasChildren = false;
- } else {
- hasChildren = true;
- }
- return hasChildren;
- }
- });
|