📄 slidy.js
字号:
if (lastShown == null && slidenum < slides.length - 1)
{
slide = slides[slidenum];
hideSlide(slide);
slidenum = slides.length - 1;
slide = slides[slidenum];
setVisibilityAllIncremental("visible");
lastShown = previousIncrementalItem(null);
showSlide(slide);
}
else
{
setVisibilityAllIncremental("visible");
lastShown = previousIncrementalItem(null);
}
setEosStatus(true);
setLocation();
}
}
function setEosStatus(state)
{
if (eos)
eos.style.color = (state ? "rgb(240,240,240)" : "red");
}
function showSlide(slide)
{
syncBackground(slide);
window.scrollTo(0,0);
slide.style.visibility = "visible";
slide.style.display = "block";
}
function hideSlide(slide)
{
slide.style.visibility = "hidden";
slide.style.display = "none";
}
function beforePrint()
{
showAllSlides();
hideToolbar();
}
function afterPrint()
{
if (!viewAll)
{
singleSlideView();
showToolbar();
}
}
function printSlides()
{
beforePrint();
window.print();
afterPrint();
}
function toggleView()
{
if (viewAll)
{
singleSlideView();
showToolbar();
viewAll = 0;
}
else
{
showAllSlides();
hideToolbar();
viewAll = 1;
}
}
// prepare for printing
function showAllSlides()
{
var slide;
for (var i = 0; i < slides.length; ++i)
{
slide = slides[i];
slide.style.position = "relative";
slide.style.borderTopStyle = "solid";
slide.style.borderTopWidth = "thin";
slide.style.borderTopColor = "black";
try {
if (i == 0)
slide.style.pageBreakBefore = "avoid";
else
slide.style.pageBreakBefore = "always";
}
catch (e)
{
//do nothing
}
setVisibilityAllIncremental("visible");
showSlide(slide);
}
var note;
for (var i = 0; i < notes.length; ++i)
{
showSlide(notes[i]);
}
// no easy way to render background under each slide
// without duplicating the background divs for each slide
// therefore hide backgrounds to avoid messing up slides
hideBackgrounds();
}
// restore after printing
function singleSlideView()
{
var slide;
for (var i = 0; i < slides.length; ++i)
{
slide = slides[i];
slide.style.position = "absolute";
if (i == slidenum)
{
slide.style.borderStyle = "none";
showSlide(slide);
}
else
{
slide.style.borderStyle = "none";
hideSlide(slide);
}
}
setVisibilityAllIncremental("visible");
lastShown = previousIncrementalItem(null);
var note;
for (var i = 0; i < notes.length; ++i)
{
hideSlide(notes[i]);
}
}
// the string str is a whitespace separated list of tokens
// test if str contains a particular token, e.g. "slide"
function hasToken(str, token)
{
if (str)
{
// define pattern as regular expression
var pattern = /\w+/g;
// check for matches
// place result in array
var result = str.match(pattern);
// now check if desired token is present
for (var i = 0; i < result.length; i++)
{
if (result[i] == token)
return true;
}
}
return false;
}
function getClassList(element)
{
if (typeof window.pageYOffset =='undefined')
return element.getAttribute("className");
return element.getAttribute("class");
}
function hasClass(element, name)
{
var regexp = new RegExp("(^| )" + name + "\W*");
if (regexp.test(getClassList(element)))
return true;
return false;
}
function removeClass(element, name)
{
// IE getAttribute requires "class" to be "className"
var clsname = ns_pos ? "class" : "className";
var clsval = element.getAttribute(clsname);
var regexp = new RegExp("(^| )" + name + "\W*");
if (clsval)
{
clsval = clsval.replace(regexp, "");
element.setAttribute(clsname, clsval);
}
}
function addClass(element, name)
{
if (!hasClass(element, name))
{
// IE getAttribute requires "class" to be "className"
var clsname = ns_pos ? "class" : "className";
var clsval = element.getAttribute(clsname);
element.setAttribute(clsname, (clsval ? clsval + " " + name : name));
}
}
// wysiwyg editors make it hard to use div elements
// e.g. amaya loses the div when you copy and paste
// this function wraps div elements around implicit
// slides which start with an h1 element and continue
// up to the next heading or div element
function wrapImplicitSlides()
{
var i, heading, node, next, div;
var headings = document.getElementsByTagName("h1");
if (!headings)
return;
for (i = 0; i < headings.length; ++i)
{
heading = headings[i];
if (heading.parentNode != document.body)
continue;
node = heading.nextSibling;
div = document.createElement("div");
div.setAttribute((ns_pos ? "class" : "className"), "slide");
document.body.replaceChild(div, heading);
div.appendChild(heading);
while (node)
{
if (node.nodeType == 1 && // an element
(node.nodeName == "H1" ||
node.nodeName == "h1" ||
node.nodeName == "DIV" ||
node.nodeName == "div"))
break;
next = node.nextSibling;
node = document.body.removeChild(node);
div.appendChild(node);
node = next;
}
}
}
// return new array of all slides
function collectSlides()
{
var slides = new Array();
var divs = document.body.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i)
{
div = divs.item(i);
if (hasClass(div, "slide"))
{
// add slide to collection
slides[slides.length] = div;
// hide each slide as it is found
div.style.display = "none";
div.style.visibility = "hidden";
// add dummy <br/> at end for scrolling hack
var node1 = document.createElement("br");
div.appendChild(node1);
var node2 = document.createElement("br");
div.appendChild(node2);
}
else if (hasClass(div, "background"))
{ // work around for Firefox SVG reload bug
// which otherwise replaces 1st SVG graphic with 2nd
div.style.display = "block";
}
}
return slides;
}
// return new array of all <div class="handout">
function collectNotes()
{
var notes = new Array();
var divs = document.body.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i)
{
div = divs.item(i);
if (hasClass(div, "handout"))
{
// add slide to collection
notes[notes.length] = div;
// hide handout notes as they are found
div.style.display = "none";
div.style.visibility = "hidden";
}
}
return notes;
}
// return new array of all <div class="background">
// including named backgrounds e.g. class="background titlepage"
function collectBackgrounds()
{
var backgrounds = new Array();
var divs = document.body.getElementsByTagName("div");
for (var i = 0; i < divs.length; ++i)
{
div = divs.item(i);
if (hasClass(div, "background"))
{
// add slide to collection
backgrounds[backgrounds.length] = div;
// hide named backgrounds as they are found
// e.g. class="background epilog"
if (getClassList(div) != "background")
{
div.style.display = "none";
div.style.visibility = "hidden";
}
}
}
return backgrounds;
}
// show just the backgrounds pertinent to this slide
function syncBackground(slide)
{
var background;
var bgColor;
if (slide.currentStyle)
bgColor = slide.currentStyle["backgroundColor"];
else if (document.defaultView)
{
var styles = document.defaultView.getComputedStyle(slide,null);
if (styles)
bgColor = styles.getPropertyValue("background-color");
else // broken implementation probably due Safari or Konqueror
{
//alert("defective implementation of getComputedStyle()");
bgColor = "transparent";
}
}
else
bgColor == "transparent";
if (bgColor == "transparent")
{
var slideClass = getClassList(slide);
for (var i = 0; i < backgrounds.length; i++)
{
background = backgrounds[i];
var bgClass = getClassList(background);
if (matchingBackground(slideClass, bgClass))
{
background.style.display = "block";
background.style.visibility = "visible";
}
else
{
background.style.display = "none";
background.style.visibility = "hidden";
}
}
}
else // forcibly hide all backgrounds
hideBackgrounds();
}
function hideBackgrounds()
{
for (var i = 0; i < backgrounds.length; i++)
{
background = backgrounds[i];
background.style.display = "none";
background.style.visibility = "hidden";
}
}
// compare classes for slide and background
function matchingBackground(slideClass, bgClass)
{
if (bgClass == "background")
return true;
// define pattern as regular expression
var pattern = /\w+/g;
// check for matches and place result in array
var result = slideClass.match(pattern);
// now check if desired name is present for background
for (var i = 0; i < result.length; i++)
{
if (hasToken(bgClass, result[i]))
return true;
}
return false;
}
// left to right traversal of root's content
function nextNode(root, node)
{
if (node == null)
return root.firstChild;
if (node.firstChild)
return node.firstChild;
if (node.nextSibling)
return node.nextSibling;
for (;;)
{
node = node.parentNode;
if (!node || node == root)
break;
if (node && node.nextSibling)
return node.nextSibling;
}
return null;
}
// right to left traversal of root's content
function previousNode(root, node)
{
if (node == null)
{
node = root.lastChild;
if (node)
{
while (node.lastChild)
node = node.lastChild;
}
return node;
}
if (node.previousSibling)
{
node = node.previousSibling;
while (node.lastChild)
node = node.lastChild;
return node;
}
if (node.parentNode != root)
return node.parentNode;
return null;
}
// HTML elements that can be used with class="incremental"
// note that you can also put the class on containers like
// up, ol, dl, and div to make their contents appear
// incrementally. Upper case is used since this is what
// browsers report for HTML node names (text/html).
function incrementalElementList()
{
var inclist = new Array();
inclist["P"] = true;
inclist["PRE"] = true;
inclist["LI"] = true;
inclist["BLOCKQUOTE"] = true;
inclist["DT"] = true;
inclist["DD"] = true;
inclist["H2"] = true;
inclist["H3"] = true;
inclist["H4"] = true;
inclist["H5"] = true;
inclist["H6"] = true;
inclist["SPAN"] = true;
inclist["ADDRESS"] = true;
inclist["TABLE"] = true;
inclist["TR"] = true;
inclist["TH"] = true;
inclist["TD"] = true;
inclist["IMG"] = true;
inclist["OBJECT"] = true;
return inclist;
}
function nextIncrementalItem(node)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -