Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/assets/misc/talk-20121004/ui/default/slides.js
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// S5 v1.1 slides.js -- released into the Public Domain6//7// Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information8// about all the wonderful and talented contributors to this code!910var undef;11var slideCSS = '';12var snum = 0;13var smax = 1;14var incpos = 0;15var number = undef;16var s5mode = true;17var defaultView = 'slideshow';18var controlVis = 'visible';1920var isIE = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;21var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;22var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;2324function hasClass(object, className) {25if (!object.className) return false;26return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);27}2829function hasValue(object, value) {30if (!object) return false;31return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);32}3334function removeClass(object,className) {35if (!object) return;36object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);37}3839function addClass(object,className) {40if (!object || hasClass(object, className)) return;41if (object.className) {42object.className += ' '+className;43} else {44object.className = className;45}46}4748function GetElementsWithClassName(elementName,className) {49var allElements = document.getElementsByTagName(elementName);50var elemColl = new Array();51for (var i = 0; i< allElements.length; i++) {52if (hasClass(allElements[i], className)) {53elemColl[elemColl.length] = allElements[i];54}55}56return elemColl;57}5859function isParentOrSelf(element, id) {60if (element == null || element.nodeName=='BODY') return false;61else if (element.id == id) return true;62else return isParentOrSelf(element.parentNode, id);63}6465function nodeValue(node) {66var result = "";67if (node.nodeType == 1) {68var children = node.childNodes;69for (var i = 0; i < children.length; ++i) {70result += nodeValue(children[i]);71}72}73else if (node.nodeType == 3) {74result = node.nodeValue;75}76return(result);77}7879function slideLabel() {80var slideColl = GetElementsWithClassName('*','slide');81var list = document.getElementById('jumplist');82smax = slideColl.length;83for (var n = 0; n < smax; n++) {84var obj = slideColl[n];8586var did = 'slide' + n.toString();87obj.setAttribute('id',did);88if (isOp) continue;8990var otext = '';91var menu = obj.firstChild;92if (!menu) continue; // to cope with empty slides93while (menu && menu.nodeType == 3) {94menu = menu.nextSibling;95}96if (!menu) continue; // to cope with slides with only text nodes9798var menunodes = menu.childNodes;99for (var o = 0; o < menunodes.length; o++) {100otext += nodeValue(menunodes[o]);101}102list.options[list.length] = new Option(n + ' : ' + otext, n);103}104}105106function currentSlide() {107var cs;108if (document.getElementById) {109cs = document.getElementById('currentSlide');110} else {111cs = document.currentSlide;112}113cs.innerHTML = '<span id="csHere">' + snum + '<\/span> ' +114'<span id="csSep">\/<\/span> ' +115'<span id="csTotal">' + (smax-1) + '<\/span>';116if (snum == 0) {117cs.style.visibility = 'hidden';118} else {119cs.style.visibility = 'visible';120}121}122123function go(step) {124if (document.getElementById('slideProj').disabled || step == 0) return;125var jl = document.getElementById('jumplist');126var cid = 'slide' + snum;127var ce = document.getElementById(cid);128if (incrementals[snum].length > 0) {129for (var i = 0; i < incrementals[snum].length; i++) {130removeClass(incrementals[snum][i], 'current');131removeClass(incrementals[snum][i], 'incremental');132}133}134if (step != 'j') {135snum += step;136lmax = smax - 1;137if (snum > lmax) snum = lmax;138if (snum < 0) snum = 0;139} else140snum = parseInt(jl.value);141var nid = 'slide' + snum;142var ne = document.getElementById(nid);143if (!ne) {144ne = document.getElementById('slide0');145snum = 0;146}147if (step < 0) {incpos = incrementals[snum].length;} else {incpos = 0;}148if (incrementals[snum].length > 0 && incpos == 0) {149for (var i = 0; i < incrementals[snum].length; i++) {150if (hasClass(incrementals[snum][i], 'current'))151incpos = i + 1;152else153addClass(incrementals[snum][i], 'incremental');154}155}156if (incrementals[snum].length > 0 && incpos > 0)157addClass(incrementals[snum][incpos - 1], 'current');158ce.style.visibility = 'hidden';159ne.style.visibility = 'visible';160jl.selectedIndex = snum;161currentSlide();162number = 0;163}164165function goTo(target) {166if (target >= smax || target == snum) return;167go(target - snum);168}169170function subgo(step) {171if (step > 0) {172removeClass(incrementals[snum][incpos - 1],'current');173removeClass(incrementals[snum][incpos], 'incremental');174addClass(incrementals[snum][incpos],'current');175incpos++;176} else {177incpos--;178removeClass(incrementals[snum][incpos],'current');179addClass(incrementals[snum][incpos], 'incremental');180addClass(incrementals[snum][incpos - 1],'current');181}182}183184function toggle() {185var slideColl = GetElementsWithClassName('*','slide');186var slides = document.getElementById('slideProj');187var outline = document.getElementById('outlineStyle');188if (!slides.disabled) {189slides.disabled = true;190outline.disabled = false;191s5mode = false;192fontSize('1em');193for (var n = 0; n < smax; n++) {194var slide = slideColl[n];195slide.style.visibility = 'visible';196}197} else {198slides.disabled = false;199outline.disabled = true;200s5mode = true;201fontScale();202for (var n = 0; n < smax; n++) {203var slide = slideColl[n];204slide.style.visibility = 'hidden';205}206slideColl[snum].style.visibility = 'visible';207}208}209210function showHide(action) {211var obj = GetElementsWithClassName('*','hideme')[0];212switch (action) {213case 's': obj.style.visibility = 'visible'; break;214case 'h': obj.style.visibility = 'hidden'; break;215case 'k':216if (obj.style.visibility != 'visible') {217obj.style.visibility = 'visible';218} else {219obj.style.visibility = 'hidden';220}221break;222}223}224225// 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)226function keys(key) {227if (!key) {228key = event;229key.which = key.keyCode;230}231if (key.which == 84) {232toggle();233return;234}235if (s5mode) {236switch (key.which) {237case 10: // return238case 13: // enter239if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;240if (key.target && isParentOrSelf(key.target, 'controls')) return;241if(number != undef) {242goTo(number);243break;244}245case 32: // spacebar246case 34: // page down247case 39: // rightkey248case 40: // downkey249if(number != undef) {250go(number);251} else if (!incrementals[snum] || incpos >= incrementals[snum].length) {252go(1);253} else {254subgo(1);255}256break;257case 33: // page up258case 37: // leftkey259case 38: // upkey260if(number != undef) {261go(-1 * number);262} else if (!incrementals[snum] || incpos <= 0) {263go(-1);264} else {265subgo(-1);266}267break;268case 36: // home269goTo(0);270break;271case 35: // end272goTo(smax-1);273break;274case 67: // c275showHide('k');276break;277}278if (key.which < 48 || key.which > 57) {279number = undef;280} else {281if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;282if (key.target && isParentOrSelf(key.target, 'controls')) return;283number = (((number != undef) ? number : 0) * 10) + (key.which - 48);284}285}286return false;287}288289function clicker(e) {290number = undef;291var target;292if (window.event) {293target = window.event.srcElement;294e = window.event;295} else target = e.target;296if (target.getAttribute('href') != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target,'object')) return true;297if (!e.which || e.which == 1) {298if (!incrementals[snum] || incpos >= incrementals[snum].length) {299go(1);300} else {301subgo(1);302}303}304}305306function findSlide(hash) {307var target = null;308var slides = GetElementsWithClassName('*','slide');309for (var i = 0; i < slides.length; i++) {310var targetSlide = slides[i];311if ( (targetSlide.name && targetSlide.name == hash)312|| (targetSlide.id && targetSlide.id == hash) ) {313target = targetSlide;314break;315}316}317while(target != null && target.nodeName != 'BODY') {318if (hasClass(target, 'slide')) {319return parseInt(target.id.slice(5));320}321target = target.parentNode;322}323return null;324}325326function slideJump() {327if (window.location.hash == null) return;328var sregex = /^#slide(\d+)$/;329var matches = sregex.exec(window.location.hash);330var dest = null;331if (matches != null) {332dest = parseInt(matches[1]);333} else {334dest = findSlide(window.location.hash.slice(1));335}336if (dest != null)337go(dest - snum);338}339340function fixLinks() {341var thisUri = window.location.href;342thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);343var aelements = document.getElementsByTagName('A');344for (var i = 0; i < aelements.length; i++) {345var a = aelements[i].href;346var slideID = a.match('\#slide[0-9]{1,2}');347if ((slideID) && (slideID[0].slice(0,1) == '#')) {348var dest = findSlide(slideID[0].slice(1));349if (dest != null) {350if (aelements[i].addEventListener) {351aelements[i].addEventListener("click", new Function("e",352"if (document.getElementById('slideProj').disabled) return;" +353"go("+dest+" - snum); " +354"if (e.preventDefault) e.preventDefault();"), true);355} else if (aelements[i].attachEvent) {356aelements[i].attachEvent("onclick", new Function("",357"if (document.getElementById('slideProj').disabled) return;" +358"go("+dest+" - snum); " +359"event.returnValue = false;"));360}361}362}363}364}365366function externalLinks() {367if (!document.getElementsByTagName) return;368var anchors = document.getElementsByTagName('a');369for (var i=0; i<anchors.length; i++) {370var anchor = anchors[i];371if (anchor.getAttribute('href') && hasValue(anchor.rel, 'external')) {372anchor.target = '_blank';373addClass(anchor,'external');374}375}376}377378function createControls() {379var controlsDiv = document.getElementById("controls");380if (!controlsDiv) return;381var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';382var hideDiv, hideList = '';383if (controlVis == 'hidden') {384hideDiv = hider;385} else {386hideList = hider;387}388controlsDiv.innerHTML = '<form action="#" id="controlForm"' + hideDiv + '>' +389'<div id="navLinks">' +390'<a accesskey="t" id="toggle" href="javascript:toggle();">Ø<\/a>' +391'<a accesskey="z" id="prev" href="javascript:go(-1);">«<\/a>' +392'<a accesskey="x" id="next" href="javascript:go(1);">»<\/a>' +393'<div id="navList"' + hideList + '><select id="jumplist" onchange="go(\'j\');"><\/select><\/div>' +394'<\/div><\/form>';395if (controlVis == 'hidden') {396var hidden = document.getElementById('navLinks');397} else {398var hidden = document.getElementById('jumplist');399}400addClass(hidden,'hideme');401}402403function fontScale() { // causes layout problems in FireFox that get fixed if browser's Reload is used; same may be true of other Gecko-based browsers404if (!s5mode) return false;405var vScale = 22; // both yield 32 (after rounding) at 1024x768406var hScale = 32; // perhaps should auto-calculate based on theme's declared value?407if (window.innerHeight) {408var vSize = window.innerHeight;409var hSize = window.innerWidth;410} else if (document.documentElement.clientHeight) {411var vSize = document.documentElement.clientHeight;412var hSize = document.documentElement.clientWidth;413} else if (document.body.clientHeight) {414var vSize = document.body.clientHeight;415var hSize = document.body.clientWidth;416} else {417var vSize = 700; // assuming 1024x768, minus chrome and such418var hSize = 1024; // these do not account for kiosk mode or Opera Show419}420var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));421fontSize(newSize + 'px');422if (isGe) { // hack to counter incremental reflow bugs423var obj = document.getElementsByTagName('body')[0];424obj.style.display = 'none';425obj.style.display = 'block';426}427}428429function fontSize(value) {430if (!(s5ss = document.getElementById('s5ss'))) {431if (!isIE) {432document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));433s5ss.setAttribute('media','screen, projection');434s5ss.setAttribute('id','s5ss');435} else {436document.createStyleSheet();437document.s5ss = document.styleSheets[document.styleSheets.length - 1];438}439}440if (!isIE) {441while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);442s5ss.appendChild(document.createTextNode('body {font-size: ' + value + ' !important;}'));443} else {444document.s5ss.addRule('body','font-size: ' + value + ' !important;');445}446}447448function notOperaFix() {449slideCSS = document.getElementById('slideProj').href;450var slides = document.getElementById('slideProj');451var outline = document.getElementById('outlineStyle');452slides.setAttribute('media','screen');453outline.disabled = true;454if (isGe) {455slides.setAttribute('href','null'); // Gecko fix456slides.setAttribute('href',slideCSS); // Gecko fix457}458if (isIE && document.styleSheets && document.styleSheets[0]) {459document.styleSheets[0].addRule('img', 'behavior: url(ui/default/iepngfix.htc)');460document.styleSheets[0].addRule('div', 'behavior: url(ui/default/iepngfix.htc)');461document.styleSheets[0].addRule('.slide', 'behavior: url(ui/default/iepngfix.htc)');462}463}464465function getIncrementals(obj) {466var incrementals = new Array();467if (!obj)468return incrementals;469var children = obj.childNodes;470for (var i = 0; i < children.length; i++) {471var child = children[i];472if (hasClass(child, 'incremental')) {473if (child.nodeName == 'OL' || child.nodeName == 'UL') {474removeClass(child, 'incremental');475for (var j = 0; j < child.childNodes.length; j++) {476if (child.childNodes[j].nodeType == 1) {477addClass(child.childNodes[j], 'incremental');478}479}480} else {481incrementals[incrementals.length] = child;482removeClass(child,'incremental');483}484}485if (hasClass(child, 'show-first')) {486if (child.nodeName == 'OL' || child.nodeName == 'UL') {487removeClass(child, 'show-first');488if (child.childNodes[isGe].nodeType == 1) {489removeClass(child.childNodes[isGe], 'incremental');490}491} else {492incrementals[incrementals.length] = child;493}494}495incrementals = incrementals.concat(getIncrementals(child));496}497return incrementals;498}499500function createIncrementals() {501var incrementals = new Array();502for (var i = 0; i < smax; i++) {503incrementals[i] = getIncrementals(document.getElementById('slide'+i));504}505return incrementals;506}507508function defaultCheck() {509var allMetas = document.getElementsByTagName('meta');510for (var i = 0; i< allMetas.length; i++) {511if (allMetas[i].name == 'defaultView') {512defaultView = allMetas[i].content;513}514if (allMetas[i].name == 'controlVis') {515controlVis = allMetas[i].content;516}517}518}519520// Key trap fix, new function body for trap()521function trap(e) {522if (!e) {523e = event;524e.which = e.keyCode;525}526try {527modifierKey = e.ctrlKey || e.altKey || e.metaKey;528}529catch(e) {530modifierKey = false;531}532return modifierKey || e.which == 0;533}534535function startup() {536defaultCheck();537if (!isOp)538createControls();539slideLabel();540fixLinks();541externalLinks();542fontScale();543if (!isOp) {544notOperaFix();545incrementals = createIncrementals();546slideJump();547if (defaultView == 'outline') {548toggle();549}550document.onkeyup = keys;551document.onkeypress = trap;552document.onclick = clicker;553}554}555556window.onload = startup;557window.onresize = function(){setTimeout('fontScale()', 50);}558559560