⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slidy.js

📁 大学的算法分析与设计
💻 JS
📖 第 1 页 / 共 5 页
字号:
{
   var slide = slides[slidenum];

   for (;;)
   {
      node = nextNode(slide, node);

      if (node == null || node.parentNode == null)
         break;

      if (node.nodeType == 1)  // ELEMENT
      {
         if (node.nodeName == "BR")
           continue;

         if (hasClass(node, "incremental")
             && okayForIncremental[node.nodeName])
            return node;

         if (hasClass(node.parentNode, "incremental")
             && !hasClass(node, "non-incremental"))
            return node;
      }
   }

   return node;
}

function previousIncrementalItem(node)
{
   var slide = slides[slidenum];

   for (;;)
   {
      node = previousNode(slide, node);

      if (node == null || node.parentNode == null)
         break;

      if (node.nodeType == 1)
      {
         if (node.nodeName == "BR")
           continue;

         if (hasClass(node, "incremental")
             && okayForIncremental[node.nodeName])
            return node;

         if (hasClass(node.parentNode, "incremental")
             && !hasClass(node, "non-incremental"))
            return node;
      }
   }

   return node;
}

// set visibility for all elements on current slide with
// a parent element with attribute class="incremental"
function setVisibilityAllIncremental(value)
{
   var node = nextIncrementalItem(null);

   while (node)
   {
      node.style.visibility = value;
      node = nextIncrementalItem(node);
   }
}

// reveal the next hidden item on the slide
// node is null or the node that was last revealed
function revealNextItem(node)
{
   node = nextIncrementalItem(node);

   if (node && node.nodeType == 1)  // an element
      node.style.visibility = "visible";

   return node;
}


// exact inverse of revealNextItem(node)
function hidePreviousItem(node)
{
   if (node && node.nodeType == 1)  // an element
      node.style.visibility = "hidden";

   return previousIncrementalItem(node);
}


/* set click handlers on all anchors */
function patchAnchors()
{
   var anchors = document.body.getElementsByTagName("a");

   for (var i = 0; i < anchors.length; ++i)
   {
      anchors[i].onclick = clickedAnchor;
   }
}

function clickedAnchor(e)
{
   if (!e)
      var e = window.event;

   // compare this.href with location.href
   // for link to another slide in this doc

   if (pageAddress(this.href) == pageAddress(location.href))
   {
      // yes, so find new slide number
      var newslidenum = findSlideNumber(this.href);

      if (newslidenum != slidenum)
      {
         slide = slides[slidenum];
         hideSlide(slide);
         slidenum = newslidenum;
         slide = slides[slidenum];
         showSlide(slide);
         setLocation();
      }
   }
   else if (this.target == null)
      location.href = this.href;

   this.blur();
   stopPropagation(e);
}

function pageAddress(uri)
{
   var i = uri.indexOf("#");

   // check if anchor is entire page

   if (i < 0)
      return uri;  // yes

   return uri.substr(0, i);
}

function showSlideNumber()//xuan slidenumber
{
   slideNumElement.innerHTML = "".localize() + " " +
           (slidenum + 1) + "/" + slides.length;
}

function setLocation()
{
   var uri = pageAddress(location.href);

   //if (slidenum > 0)
      uri = uri + "#(" + (slidenum+1) + ")";

   if (uri != location.href && !khtml)
      location.href = uri;

   document.title = title + " (" + (slidenum+1) + ")";
   //document.title = (slidenum+1) + ") " + slideName(slidenum);

   showSlideNumber();
}

// find current slide based upon location
// first find target anchor and then look
// for associated div element enclosing it
// finally map that to slide number
function findSlideNumber(uri)
{
   // first get anchor from page location

   var i = uri.indexOf("#");

   // check if anchor is entire page

   if (i < 0)
      return 0;  // yes

   var anchor = unescape(uri.substr(i+1));

   // now use anchor as XML ID to find target
   var target = document.getElementById(anchor);

   if (!target)
   {
      // does anchor look like "(2)" for slide 2 ??
      // where first slide is (1)
      var re = /\((\d)+\)/;

      if (anchor.match(re))
      {
         var num = parseInt(anchor.substring(1, anchor.length-1));

         if (num > slides.length)
            num = 1;

         if (--num < 0)
            num = 0;

         return num;
      }

      // accept [2] for backwards compatibility
      re = /\[(\d)+\]/;

      if (anchor.match(re))
      {
         var num = parseInt(anchor.substring(1, anchor.length-1));

         if (num > slides.length)
            num = 1;

         if (--num < 0)
            num = 0;

         return num;
      }

      // oh dear unknown anchor
      return 0;
   }

   // search for enclosing slide

   while (true)
   {
      // browser coerces html elements to uppercase!
      if (target.nodeName.toLowerCase() == "div" &&
            hasClass(target, "slide"))
      {
         // found the slide element
         break;
      }

      // otherwise try parent element if any

      target = target.parentNode;

      if (!target)
      {
         return 0;   // no luck!
      }
   };

   for (i = 0; i < slides.length; ++i)
   {
      if (slides[i] == target)
         return i;  // success
   }

   // oh dear still no luck
   return 0;
}

// find slide name from first h1 element
// default to document title + slide number
function slideName(index)
{
   var name = null;
   var slide = slides[index];

   var heading = findHeading(slide);

   if (heading)
     name = extractText(heading);

   if (!name)
     name = title + "(" + (index + 1) + ")";

   name.replace(/\&/g, "&amp;");
   name.replace(/\</g, "&lt;");
   name.replace(/\>/g, "&gt;");

   return name;
}

// find first h1 element in DOM tree
function findHeading(node)
{
  if (!node || node.nodeType != 1)
    return null;

  if (node.nodeName == "H1" || node.nodeName == "h1")
    return node;

  var child = node.firstChild;

  while (child)
  {
    node = findHeading(child);

    if (node)
      return node;

    child = child.nextSibling;
  }

  return null;
}

// recursively extract text from DOM tree
function extractText(node)
{
  if (!node)
    return "";

  // text nodes
  if (node.nodeType == 3)
    return node.nodeValue;

  // elements
  if (node.nodeType == 1)
  {
    node = node.firstChild;
    var text = "";

    while (node)
    {
      text = text + extractText(node);
      node = node.nextSibling;
    }

    return text;
  }

  return "";
}


// find copyright text from meta element
function findCopyright()
{
   var name, content;
   var meta = document.getElementsByTagName("meta");

   for (var i = 0; i < meta.length; ++i)
   {
      name = meta[i].getAttribute("name");
      content = meta[i].getAttribute("content");

      if (name == "copyright")
         return content;
   }

   return null;
}

function findSizeAdjust()
{
   var name, content, offset;
   var meta = document.getElementsByTagName("meta");

   for (var i = 0; i < meta.length; ++i)
   {
      name = meta[i].getAttribute("name");
      content = meta[i].getAttribute("content");

      if (name == "font-size-adjustment")
         return 1 * content;
   }

   return 0;
}

function addToolbar()
{
   var slideCounter, page;

   var toolbar = createElement("div");
   toolbar.setAttribute("class", "toolbar");

   if (ns_pos) // a reasonably behaved browser
   {
      var right = document.createElement("div");
      right.setAttribute("style", "float: right; text-align: right");

      slideCounter = document.createElement("div")
      slideCounter.innerHTML = "slide000".localize() + " n/m";
      right.appendChild(slideCounter);
      toolbar.appendChild(right);

      var left = document.createElement("div");
      left.setAttribute("style", "text-align: left");

      // global end of slide indicator
      eos = document.createElement("span");
      eos.innerHTML = "* ";
      left.appendChild(eos);

      var help = document.createElement("a");
      help.setAttribute("href", helpPage);
      help.setAttribute("title", helpText.localize());
      help.innerHTML = "help?".localize();
      left.appendChild(help);
      helpAnchor = help;  // save for focus hack

      var gap1 = document.createTextNode(" ");
      left.appendChild(gap1);

      var contents = document.createElement("a");
      contents.setAttribute("href", "javascript:toggleTableOfContents()");//xuan
      contents.setAttribute("title", "table of contents".localize());
      contents.innerHTML = "contents?".localize();
      left.appendChild(contents);
	  

      var gap2 = document.createTextNode(" ");
      left.appendChild(gap2);

      var i = location.href.indexOf("#");

      // check if anchor is entire page

      if (i > 0)
         page = location.href.substr(0, i);
      else
         page = location.href;

      var start = document.createElement("a");
      start.setAttribute("href", page);
      start.setAttribute("title", "restart presentation".localize());
      start.innerHTML = "restart?".localize();
//    start.setAttribute("href", "javascript:printSlides()");
//    start.setAttribute("title", "print all slides".localize());
//    start.innerHTML = "print!".localize();
      left.appendChild(start);

      var copyright = findCopyright();

      if (copyright)
      {
         var span = document.createElement("span");
         span.innerHTML = copyright;
         span.style.color = "white";
         span.style.marginLeft = "4em";
         left.appendChild(span);
      }

      toolbar.appendChild(left);
   }
   else // IE so need to work around its poor CSS support
   {
      toolbar.style.position = (ie7 ? "fixed" : "absolute");
      toolbar.style.zIndex = "200";
      toolbar.style.width = "99.9%";
      toolbar.style.height = "2.5em";//xuan toolbarheight
      toolbar.style.top = "auto";
      toolbar.style.bottom = "0";
      toolbar.style.left = "0";
      toolbar.style.right = "0";
      toolbar.style.textAlign = "left";
      toolbar.style.fontSize = "100%";
      toolbar.style.color = "red";
      toolbar.borderWidth = 0;
	  toolbar.style.fontFamily="黑体";
      toolbar.style.background = "rgb(28,72,120)";

      // would like to have help text left aligned
      // and page counter right aligned, floating
      // div's don't work, so instead use nested
      // absolutely positioned div's.

      var sp1 = document.createElement("span");
      sp1.innerHTML = "&nbsp;&nbsp;<br>";
	  sp1.style.fontSize="30%";
      toolbar.appendChild(sp1);
      
	  var sp = document.createElement("span");
      sp.innerHTML = "&nbsp;&nbsp;&nbsp;";
      toolbar.appendChild(sp);
      eos = sp;  // end of slide indicator

      

      var gap2 = document.createTextNode(" ");
      toolbar.appendChild(gap2);

      var i = location.href.indexOf("#");

      // check if anchor is entire page

      if (i > 0)
         page = location.href.substr(0, i);
      else
         page = location.href;

      var start = document.createElement("a");
      start.setAttribute("href", page);
      start.setAttribute("title", "返回首页".localize());
      start.innerHTML = "&nbsp;首页&nbsp;".localize();
//    start.setAttribute("href", "javascript:printSlides()");
//    start.setAttribute("title", "print all slides".localize());
//    start.innerHTML = "print!".localize();
      toolbar.appendChild(start);
	  
	  //var firstpage = document.createElement("a");
     // firstpage.setAttribute("href", "javascript:firstSlide();");//xuan uppage
      //firstpage.setAttribute("title", "首页".localize());
     // firstpage.innerHTML = "/*首页*/".localize();
      //toolbar.appendChild(firstpage);
	  
	  var uppage = document.createElement("a");
      uppage.setAttribute("href", "javascript:previousSlide(false)");//xuan uppage
      uppage.setAttribute("title", "上一页".localize());
      uppage.innerHTML = " &nbsp;上一页&nbsp;".localize();
	 //uppage.innerHTML = "<SCRIPT LANGUAGE="JavaScript"><!--document.write('<IMG SRC="face4.gif'>');--></SCRIPT>";
      toolbar.appendChild(uppage);
	  
	  var downpage = document.createElement("a");
      downpage.setAttribute("href", "javascript:nextSlide(false)");//xuan downpage
      downpage.setAttribute("title", "下一页".localize());
      downpage.innerHTML = " &nbsp;下一页&nbsp;".localize();
      toolbar.appendChild(downpage);
	  
	  var lastpage = document.createElement("a");
      lastpage.setAttribute("href", "javascript:lastSlide()");//xuan downpage
      lastpage.setAttribute("title", "末页".localize());
      lastpage.innerHTML = "&nbsp;末页&nbsp;".localize();
      toolbar.appendChild(lastpage);
	  	  
      var gap1 = document.createTextNode(" ");
      toolbar.appendChild(gap1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -