Commit 16524a76 authored by jonnybradley's avatar jonnybradley

[FIX] JSLint: Part 2 of JSLint* corrections: autoToc.js - mostly missing line...

[FIX] JSLint: Part 2 of JSLint* corrections: autoToc.js - mostly missing line terminations and var declarations (*actually phpStorm code inspections)
parent 64ade55a
......@@ -48,7 +48,7 @@ $.buildAutoToc = function () {
//if a wiki page, and if there is no toc-off div
if (document.getElementById("page-data") && !document.getElementById("toc-off") && document.location.href.indexOf("tiki-print.php") == -1) {
//get headers
headers = $("div#page-data").find(":header");
var headers = $("div#page-data").find(":header");
//if there are more than one headers on the page
if (headers.length > 1) {
......@@ -57,32 +57,32 @@ $.buildAutoToc = function () {
//set target div IDs. these divs will be populated with an autoToc
//innerToc and toc-static are required. Additional divs may be specified.
tocDivs = ["innerToc", "toc-static"];
var tocDivs = ["innerToc", "toc-static"];
//string to add html for toc divs
tocString = "<div id='outerToc' contenteditable='false'> <div id='outerTocTitle'> <a href='#'> Table of Contents, or Click for Page Top</a></div><div id='innerToc' contenteditable='false'></div></div><div id='outerToc-static' contenteditable='false' class='opaque'><div id='toc-static'></div></div>";
var tocString = "<div id='outerToc' contenteditable='false'> <div id='outerTocTitle'> <a href='#'> Table of Contents, or Click for Page Top</a></div><div id='innerToc' contenteditable='false'></div></div><div id='outerToc-static' contenteditable='false' class='opaque'><div id='toc-static'></div></div>";
//create the div to hold the tocs, and populate its inner HTML with the tocString
tocContainer = document.createElement("div");
var tocContainer = document.createElement("div");
tocContainer.innerHTML = tocString;
//get pageData div, as we want to add toc before that
page = document.getElementById("page-data");
var page = document.getElementById("page-data");
//add the tocContainer as first child of page-data div
firstChild = page.firstChild;
var firstChild = page.firstChild;
page.insertBefore(tocContainer, firstChild);
//Configure starting header and ending header
largestHeader = 1;
smallestHeader = 6;
var largestHeader = 1;
var smallestHeader = 6;
//**************Iterate over headers and create autoToc HTML List**************//
//start from indentation level 0, with header one as base
previousHeaderLevel = 1;
var previousHeaderLevel = 1;
//create object to store processed IDs.
var processedId = new Object();
var processedId = {};
//function to process header Id generation. If an ID which has been processed is generated again and passed in again, the id name will be incremented to id_[1*]
function processId(id) {
......@@ -91,7 +91,7 @@ $.buildAutoToc = function () {
//iterate count for header with this ane
processedId[id] += 1;
//set the new id to id plus count for header
newId = id + "_" + processedId[id];
var newId = id + "_" + processedId[id];
} else {
//if not processed before
//add to "dictionary' with count of 0
......@@ -106,31 +106,31 @@ $.buildAutoToc = function () {
var str = '<ul>';
//Iterate over the headers
for (i = 0; i < headers.length; i++) {
for (var i = 0; i < headers.length; i++) {
//get header level for header to see if this header should be processed or not
headerLevel = parseInt(headers[i].tagName[1]);
var headerLevel = parseInt(headers[i].tagName[1]);
//If the header level in range of acceptable headers, begin processing it
if (headerLevel >= largestHeader && headerLevel <= smallestHeader) {
//store browser location to append the #[1*/header text] to
browserLocation = document.location.href;
var browserLocation = document.location.href;
//Make the base URL for the link as everything up to page name plus hash. multistructure pages might have issues with this, but we are avoiding multistruction pages to avoid multicategory pages, so should be fine. For links to headers (via ids) to work, you need to have a clean url like cewiki/pagename#id, with nothing after the id string: https://cewiki-dev.colorado.edu/es-Searching+for+a+Student+Record#Overview will work, but https://cewiki-dev.colorado.edu/es-Searching+for+a+Student+Record#Overview&structure=es-Enrollment+Services will not.
pointTo = browserLocation.substring(0, browserLocation.indexOf('&')) + "#";
var pointTo = browserLocation.substring(0, browserLocation.indexOf('&')) + "#";
//current header
currentHeader = headers[i]; // header is a reserved word in IE
var currentHeader = headers[i]; // header is a reserved word in IE
//grab the whole header element to show as the anchor text
// aText = $.trim(currentHeader.innerHTML); //trim incase inner html is text (if <hx>text</hx>)
aText = $.trim(currentHeader.textContent);
var aText = $.trim(currentHeader.textContent);
//generate and set id if necessary (if element does not already have an id, create one)
if (!currentHeader.id){
//set the id to the the inner text of the header, with underscores instead of "<", ">", and spaces (" "). Increment Id checks if the ID has been assigned yet, and if so, increments the Id with a number at the end of the id name
id = processId(currentHeader.textContent.trim().replace(/ /g, "_").replace(/&lt;/g, "_").replace(/&gt;/g, "_"));
var id = processId(currentHeader.textContent.trim().replace(/ /g, "_").replace(/&lt;/g, "_").replace(/&gt;/g, "_"));
//set the element's id to the constructed ID
currentHeader.setAttribute("id", id);
......@@ -138,10 +138,10 @@ $.buildAutoToc = function () {
id = currentHeader.id;
}
//construct the URL from the base URL with a # and the ID for the Div
url = pointTo + id; //url is baseurl#divId
var url = pointTo + id; //url is baseurl#divId
//create the HTML anchor item with the text from the header and pointing to baseurl#divId
itm = '<li><a href=' + url + '>' + aText + '</a></li>';
var itm = '<li><a href=' + url + '>' + aText + '</a></li>';
//*****use the information gathered to write the string of the HTML for the list of anchors*****//
......@@ -154,7 +154,7 @@ $.buildAutoToc = function () {
//Above, if it had just written the h3, and it went to write the h1, its initial indentLevel would be 1, while previous would be 3, so it would know it needs to close sublists equal to the difference beteen its indentation level and that of h3. So, it would need to close two levels from h3 to get to h1, and then write the item.
//To do this, the code below either applies ++ or -- on the indentLevel variable while closing or opening sublists until the current indentLevel matches the previousHeaderLevel.
indentLevel = headerLevel;
var indentLevel = headerLevel;
//if header is a sub header (nested on a child level of the previous header), meaning its indent level is greater than that of the previousHeaderLevel
if (indentLevel > previousHeaderLevel) {
......@@ -212,8 +212,8 @@ $.buildAutoToc = function () {
//make it so when you scroll past the bottom of the innerToc overflow it doesn't scroll the page, preventing the autoToc from dissapearing
//determine where the "mobile toc" should start showing up
static_toc = $('#outerToc-static');
start = $(static_toc).offset().top + $(static_toc).height();
var static_toc = $('#outerToc-static');
var start = $(static_toc).offset().top + $(static_toc).height();
var outer = $('#outerToc');
var inner = $('#innerToc');
......@@ -222,7 +222,7 @@ $.buildAutoToc = function () {
//set on scroll window event to do: on scroll, hide the floating toc if you would overlap with the toc on the top of the page, otherwise hide the inner toc
$.event.add(window, "scroll", function () {
//position
p = $(window).scrollTop();
var p = $(window).scrollTop();
//if current position is below the other toc and start of the page
if (p > start) {
......@@ -242,14 +242,14 @@ $.buildAutoToc = function () {
//set onmouseover for outerToc to show inner toc and adjust inner toc height to parent so overflow correctly
document.getElementById("outerToc").onmouseover = function () {
document.getElementById("outerToc").onmouseover = function () {
//make the outerToc container more opaque
outer.css('opacity','1');
//show the inner toc div, displaying the toc
inner.css('display','block');
//set innerToc to appropriate height for overflow-y scroll
inner.height(outer.height() - title.height() + "px");
}
};
//set mouse scroll on innerToc to not scroll main page when hit bottom of innerToc overflow
//code via http://stackoverflow.com/questions/16323770/stop-page-from-scrolling-if-hovering-div, thanks Troy Alford!
......@@ -268,7 +268,7 @@ $.buildAutoToc = function () {
ev.preventDefault();
ev.returnValue = false;
return false;
}
};
if (!up && -delta > scrollHeight - height - scrollTop) {
// Scrolling down, but this will take us past the bottom.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment