mirror of
https://github.com/weewx/weewx.git
synced 2026-04-18 16:46:56 -04:00
23 lines
3.7 KiB
JavaScript
23 lines
3.7 KiB
JavaScript
/*!
|
|
* samaxesJS JavaScript Library
|
|
* http://code.google.com/p/samaxesjs/
|
|
*
|
|
* Copyright (c) 2011 samaxes.com
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
var samaxesJS={bindReady:function(d){var f=false;function c(){if(f){return}f=true;d()}if(document.addEventListener){document.addEventListener("DOMContentLoaded",c,false)}else{if(document.attachEvent){try{var a=window.frameElement!=null}catch(g){}if(document.documentElement.doScroll&&!a){function h(){if(f){return}try{document.documentElement.doScroll("left");c()}catch(i){setTimeout(h,20)}}h()}document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){c()}})}}if(window.addEventListener){window.addEventListener("load",c,false)}else{if(window.attachEvent){window.attachEvent("onload",c)}else{var b=window.onload;window.onload=function(){b&&b();c()}}}},trim:function(a){return(a||"").replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,"")},size:function(c){var b=0,a;for(a in c){if(c.hasOwnProperty(a)){b++}}return b},getChildrenByTagName:function(e,a){var c=e.children;var f=c.length;var d=[];for(var b=0;b<f;b++){if(c[b].tagName.match(new RegExp(a,"i"))){d.push(c[b])}}return d}};
|
|
/*!
|
|
* samaxesJS TOC v1.5
|
|
*/
|
|
samaxesJS.toc=function(){var a=this.document;function e(i,j){var h=a.createElement("a");if(i!==""){h.setAttribute("href","#"+i)}h.innerHTML=j;return h}function c(i,h){if(i===0&&h.getElementsByTagName("li").length>0&&!h.getElementsByTagName("li")[h.getElementsByTagName("li").length-1].lastChild.nodeName.match(new RegExp("ul","i"))){h.getElementsByTagName("li")[h.getElementsByTagName("li").length-1].appendChild(a.createElement("ul"))}}function d(j,k){for(var h=1;h<=samaxesJS.size(j);h++){if("h"+h===k){++j["h"+h]}else{if("h"+h>k){j["h"+h]=0}}}}function b(h){return h.replace(/[ <>#\/\\?&\n]/g,"_")}function g(l,m,k){var h="";for(var j=1;j<=samaxesJS.size(l);j++){if("h"+j<=m&&l["h"+j]>0){h+=l["h"+j]+"."}}return h+" "+k}function f(n,h,m,l){var k=n;for(var j=1;j<h;j++){if(samaxesJS.getChildrenByTagName(k,"li").length===0){k.appendChild(a.createElement("li")).appendChild(a.createElement("ul"))}k=samaxesJS.getChildrenByTagName(samaxesJS.getChildrenByTagName(k,"li")[samaxesJS.getChildrenByTagName(k,"li").length-1],"ul")[0]}if(m==null){k.appendChild(a.createElement("li")).innerHTML=l}else{k.appendChild(a.createElement("li")).appendChild(e(m,l))}}return function(h){samaxesJS.bindReady(function(){var m=(!h||h.exclude===undefined)?"h1, h5, h6":h.exclude;var l=(h&&h.context)?a.getElementById(h.context):a.body;var v=h&&h.autoId;var j=(!h||h.numerate===undefined)?true:h.numerate;var o=[];var k=l.getElementsByTagName("*");for(var p in k){if(/h\d/i.test(k[p].nodeName)&&!m.match(new RegExp(k[p].nodeName,"i"))){o.push(k[p])}}if(o.length>0){var q=a.getElementById((h&&h.container)||"toc").appendChild(a.createElement("ul"));var u=0;var n={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};var t={h1:0,h2:0,h3:0,h4:0,h5:0,h6:0};for(var r=1;r<=6;r++){t["h"+r]=(m.match(new RegExp("h"+r,"i"))===null&&a.getElementsByTagName("h"+r).length>0)?++u:0}for(var s in o){for(var r=6;r>=1;r--){if(o[s].nodeName.match(new RegExp("h"+r,"i"))){if(j){c(n["h"+r],q);d(n,"h"+r);if(v&&!o[s].getAttribute("id")){o[s].setAttribute("id",b(o[s].innerHTML))}o[s].innerHTML=g(n,"h"+r,o[s].innerHTML)}f(q,t["h"+r],o[s].getAttribute("id"),o[s].innerHTML)}}}}})}}(); |