📄 slidy.js
字号:
/* slidy.js
Copyright (c) 2005 W3C (MIT, ERCIM, Keio), All Rights Reserved.
W3C liability, trademark, document use and software licensing
rules apply, see:
http://www.w3.org/Consortium/Legal/copyright-documents
http://www.w3.org/Consortium/Legal/copyright-software
*/
var ns_pos = (typeof window.pageYOffset!='undefined');
var khtml = ((navigator.userAgent).indexOf("KHTML") >= 0 ? true : false);
var opera = ((navigator.userAgent).indexOf("Opera") >= 0 ? true : false);
var ie7 = (!ns_pos && navigator.userAgent.indexOf("MSIE 7") != -1);
window.onload = startup; // equivalent to onload on body element
// IE only event handlers to ensure all slides are printed
// I don't yet know how to emulate these for other browsers
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
// hack to hide slides while loading
setTimeout(hideAll, 50);
function hideAll()
{
if (document.body)
document.body.style.visibility = "hidden";
else
setTimeout(hideAll, 50);
}
var slidenum = 0; // integer slide count: 0, 1, 2, ...
var slides; // set to array of slide div's
var slideNumElement; // element containing slide number
var notes; // set to array of handout div's
var backgrounds; // set to array of background div's
var toolbar; // element containing toolbar
var title; // document title
var lastShown = null; // last incrementally shown item
var eos = null; // span element for end of slide indicator
var toc = null; // table of contents
var outline = null; // outline element with the focus
var selectedTextLen; // length of drag selection on document
var viewAll = 0; // 1 to view all slides + handouts
var wantToolbar = 1; // 0 if toolbar isn't wanted
var mouseClickEnabled = true; // enables left click for next slide
var scrollhack = 0; // IE work around for position: fixed
var helpAnchor; // used for keyboard focus hack in showToolbar()
var helpPage = "http://www.sdnu.edu.cn";// xuan help
var helpText = "Navigate with mouse click, space bar, Cursor Left/Right, " +
"or Pg Up and Pg Dn. Use S and B to change font size.";//xuan kjj
var sizeIndex = 0;
var sizeAdjustment = 0;
var sizes = new Array("10pt", "12pt", "14pt", "16pt", "18pt", "20pt",
"22pt", "24pt", "26pt", "28pt", "30pt", "32pt");
var okayForIncremental = incrementalElementList();
// needed for efficient resizing
var lastWidth = 0;
var lastHeight = 0;
// Needed for cross browser support for relative width/height on
// object elements. The work around is to save width/height attributes
// and then to recompute absolute width/height dimensions on resizing
var objects;
// updated to language specified by html file
var lang = "en";
//var localize = {};
// for each language there is an associative array xuan
var strings_es = {
"slide":"pág.",
"help?":"Ayuda",
"contents?":"Índice",
"table of contents":"tabla de contenidos",
"Table of Contents":"Tabla de Contenidos",
"restart presentation":"Reiniciar presentación",
"restart?":"Inicio"
};
strings_es[helpText] =
"Utilice el ratón, barra espaciadora, teclas Izda/Dhca, " +
"o Re pág y Av pág. Use S y B para cambiar el tamaño de fuente.";
var strings_nl = {
"slide":"pagina",
"help?":"Help?",
"contents?":"Inhoud?",
"table of contents":"inhoudsopgave",
"Table of Contents":"Inhoudsopgave",
"restart presentation":"herstart presentatie",
"restart?":"Herstart?"
};
strings_nl[helpText] =
"Navigeer d.m.v. het muis, spatiebar, Links/Rechts toetsen, " +
"of PgUp en PgDn. Gebruik S en B om de karaktergrootte te veranderen.";
var strings_de = {
"slide":"Seite",
"help?":"Hilfe",
"contents?":"Übersicht",
"table of contents":"Inhaltsverzeichnis",
"Table of Contents":"Inhaltsverzeichnis",
"restart presentation":"Präsentation neu starten",
"restart?":"Neustart"
};
strings_de[helpText] =
"Benutzen Sie die Maus, Leerschlag, die Cursortasten links/rechts" +
"oder Page up/Page Down zum Wechseln der Seiten und S und B für die Schriftgrösse.";
var strings_pl = {
"slide":"slajd",
"help?":"pomoc?",
"contents?":"spis treści?",
"table of contents":"spis treści",
"Table of Contents":"Spis Treści",
"restart presentation":"Restartuj prezentację",
"restart?":"restart?"
};
strings_pl[helpText] =
"Zmieniaj slajdy klikając myszą, naciskając spację, strzałki lewo/prawo" +
"lub PgUp / PgDn. Użyj klawiszy S i B, aby zmienić rozmiar czczionki.";
var strings_fr = {
"slide":"page",
"help?":"Aide",
"contents?":"Index",
"table of contents":"table des matières",
"Table of Contents":"Table des matières",
"restart presentation":"Recommencer l'exposé",
"restart?":"Début"
};
strings_fr[helpText] =
"Naviguez avec la souris, la barre d'espace, les flèches" +
"gauche/droite ou les touches Pg Up, Pg Dn. Utilisez " +
"les touches S et B pour modifier la taille de la police.";
var strings_hu = {
"slide":"oldal",
"help?":"segítség",
"contents?":"tartalom",
"table of contents":"tartalomjegyzék",
"Table of Contents":"Tartalomjegyzék",
"restart presentation":"bemutató újraindítása",
"restart?":"újraindítás"
};
strings_hu[helpText] =
"Az oldalak közti lépkedéshez kattintson az egérrel, vagy használja a szóköz, a bal, vagy a jobb nyíl, " +
"illetve a Page Down, Page Up billentyűket. Az S és a B billentyűkkel változtathatja a szöveg méretét.";
var strings_it = {
"slide":"pag.",
"help?":"Aiuto",
"contents?":"Indice",
"table of contents":"indice",
"Table of Contents":"Indice",
"restart presentation":"Ricominciare la presentazione",
"restart?":"Inizio"
};
strings_it[helpText] =
"Navigare con mouse, barra spazio, frecce sinistra/destra o " +
"PgUp e PgDn. Usare S e B per cambiare la dimensione dei caratteri.";
var strings_el = {
"slide":"σελίδα",
"help?":"βοήθεια;",
"contents?":"περιεχόμενα;",
"table of contents":"πίνακας περιεχομένων",
"Table of Contents":"Πίνακας Περιεχομένων",
"restart presentation":"επανεκκίνηση παρουσίασης",
"restart?":"επανεκκίνηση;"
};
strings_el[helpText] =
"Πλοηγηθείτε με το κλίκ του ποντικιού, το space, τα βέλη αριστερά/δεξιά, " +
"ή Page Up και Page Down. Χρησιμοποιήστε τα πλήκτρα S και B για να αλλάξετε " +
"το μέγεθος της γραμματοσειράς.";
var strings_ja = {
"slide":"スライド",
"help?":"ヘルプ",
"contents?":"目次",
"table of contents":"目次を表示",
"Table of Contents":"目次",
"restart presentation":"最初から再生",
"restart?":"最初から"
};
strings_ja[helpText] =
"マウス左クリック ・ スペース ・ 左右キー " +
"または Page Up ・ Page Downで操作, S ・ Bでフォントサイズ変更";
// each such language array is declared in the localize array
// used indirectly as in help.innerHTML = "help".localize();
var localize = {
"es":strings_es,
"nl":strings_nl,
"de":strings_de,
"pl":strings_pl,
"fr":strings_fr,
"hu":strings_hu,
"it":strings_it,
"el":strings_el,
"jp":strings_ja
};
/* general initialization */
function startup()
{
// find human language from html element
// for use in localizing strings
lang = document.body.parentNode.getAttribute("lang");
if (!lang)
lang = document.body.parentNode.getAttribute("xml:lang");
if (!lang)
lang = "en";
document.body.style.visibility = "visible";
title = document.title;
toolbar = addToolbar();
wrapImplicitSlides();
slides = collectSlides();
notes = collectNotes();
objects = document.body.getElementsByTagName("object");
backgrounds = collectBackgrounds();
patchAnchors();
slidenum = findSlideNumber(location.href);
window.offscreenbuffering = true;
sizeAdjustment = findSizeAdjust();
hideImageToolbar(); // suppress IE image toolbar popup
initOutliner(); // activate fold/unfold support
if (slides.length > 0)
{
var slide = slides[slidenum];
slide.style.position = "absolute";
if (slidenum > 0)
{
setVisibilityAllIncremental("visible");
lastShown = previousIncrementalItem(null);
setEosStatus(true);
}
else
{
lastShown = null;
setVisibilityAllIncremental("hidden");
setEosStatus(!nextIncrementalItem(lastShown));
}
setLocation();
}
toc = tableOfContents();
hideTableOfContents();
// bind event handlers
document.onclick = mouseButtonClick;
document.onmouseup = mouseButtonUp;
document.onkeydown = keyDown;
window.onresize = resized;
window.onscroll = scrolled;
singleSlideView();
setLocation();
resized();
if (ie7)
setTimeout("ieHack()", 100);
showToolbar();
}
// add localize method to all strings for use
// as in help.innerHTML = "help".localize();
String.prototype.localize = function()
{
if (this == "")
return this;
// try full language code, e.g. en-US
var s, lookup = localize[lang];
if (lookup)
{
s = lookup[this];
if (s)
return s;
}
// try en if undefined for en-US
var lg = lang.split("-");
if (lg.length > 1)
{
lookup = localize[lg[0]];
if (lookup)
{
s = lookup[this];
if (s)
return s;
}
}
// otherwise string as is
return this;
}
// suppress IE's image toolbar pop up
function hideImageToolbar()
{
if (!ns_pos)
{
var images = document.getElementsByTagName("IMG");
for (var i = 0; i < images.length; ++i)
images[i].setAttribute("galleryimg", "no");
}
}
// hack to persuade IE to compute correct document height
// as needed for simulating fixed positioning of toolbar
function ieHack()
{
window.resizeBy(0,-1);
window.resizeBy(0, 1);
}
// Firefox reload SVG bug work around
function reload(e)
{
if (!e)
var e = window.event;
hideBackgrounds();
setTimeout("document.reload();", 100);
stopPropagation(e);
e.cancel = true;
e.returnValue = false;
return false;
}
// Safari and Konqueror don't yet support getComputedStyle()
// and they always reload page when location.href is updated
function isKHTML()
{
var agent = navigator.userAgent;
return (agent.indexOf("KHTML") >= 0 ? true : false);
}
function resized()
{
var width = 0;
if ( typeof( window.innerWidth ) == 'number' )
width = window.innerWidth; // Non IE browser
else if (document.documentElement && document.documentElement.clientWidth)
width = document.documentElement.clientWidth; // IE6
else if (document.body && document.body.clientWidth)
width = document.body.clientWidth; // IE4
var height = 0;
if ( typeof( window.innerHeight ) == 'number' )
height = window.innerHeight; // Non IE browser
else if (document.documentElement && document.documentElement.clientHeight)
height = document.documentElement.clientHeight; // IE6
else if (document.body && document.body.clientHeight)
height = document.body.clientHeight; // IE4
// IE fires onresize even when only font size is changed!
// so we do a check to avoid blocking < and > actions
if (width != lastWidth || height != lastHeight)
{
if (width >= 1100)
sizeIndex = 5; // 4
else if (width >= 1000)
sizeIndex = 4; // 3
else if (width >= 800)
sizeIndex = 3; // 2
else if (width >= 600)
sizeIndex = 2; // 1
else if (width)
sizeIndex = 0;
// add in font size adjustment from meta element e.g.
// <meta name="font-size-adjustment" content="-2" />
// useful when slides have too much content ;-)
if (0 <= sizeIndex + sizeAdjustment &&
sizeIndex + sizeAdjustment < sizes.length)
sizeIndex = sizeIndex + sizeAdjustment;
// enables cross browser use of relative width/height
// on object elements for use with SVG and Flash media
adjustObjectDimensions(width, height);
document.body.style.fontSize = sizes[sizeIndex];
lastWidth = width;
lastHeight = height;
// force reflow to work around Mozilla bug
//if (ns_pos)
{
var slide = slides[slidenum];
hideSlide(slide);
showSlide(slide);
}
// force correct positioning of toolbar
refreshToolbar(200);
}
}
function scrolled()
{
if (toolbar && !ns_pos && !ie7)
{
hackoffset = scrollXOffset();
// hide toolbar
toolbar.style.display = "none";
// make it reappear later
if (scrollhack == 0 && !viewAll)
{
setTimeout(showToolbar, 1000);
scrollhack = 1;
}
}
}
// used to ensure IE refreshes toolbar in correct position
function refreshToolbar(interval)
{
if (!ns_pos && !ie7)
{
hideToolbar();
setTimeout(showToolbar, interval);
}
}
// restores toolbar after short delay
function showToolbar()//xuan showtoolbar
{
if (wantToolbar)
{
if (!ns_pos)
{
// adjust position to allow for scrolling
var xoffset = scrollXOffset();
toolbar.style.left = xoffset;
toolbar.style.right = xoffset;
// determine vertical scroll offset
//var yoffset = scrollYOffset();
// bottom is doc height - window height - scroll offset
//var bottom = documentHeight() - lastHeight - yoffset
//if (yoffset > 0 || documentHeight() > lastHeight)
// bottom += 16; // allow for height of scrollbar
toolbar.style.bottom = 0; //bottom;
}
toolbar.style.display = "block";
toolbar.style.visibility = "visible";
}
scrollhack = 0;
// set the keyboard focus to the help link on the
// toolbar to ensure that document has the focus
// IE doesn't always work with window.focus()
// and this hack has benefit of Enter for help
try
{
if (!opera)
helpAnchor.focus();
}
catch (e)
{
}
}
function test()
{
var s = "docH: " + documentHeight() +
" winH: " + lastHeight +
" yoffset: " + scrollYOffset() +
" toolbot: " + (documentHeight() - lastHeight - scrollYOffset());
//alert(s);
var slide = slides[slidenum];
// IE getAttribute requires "class" to be "className"
var name = ns_pos ? "class" : "className";
var style = (slide.currentStyle ? slide.currentStyle["backgroundColor"] :
document.defaultView.getComputedStyle(slide, '').getPropertyValue("background-color"));
alert("class='" + slide.getAttribute(name) + "' backgroundColor: " + style);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -