打开/关闭菜单
1683
2.2万
6536
11.8万
舰R百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

舰R百科是靠无数志愿编辑者持续地建设更新完善的。编辑非常简单,无需代码知识,请勇于更新页面!
编辑入门 | 资助百科 | 留言讨论页 | 微博@舰R百科 | 百科编辑讨论Q群:366818861

微件:TabberDefault

舰R百科,玩家自由编辑的战舰少女R百科
Donnyjie留言 | 贡献2025年5月18日 (日) 09:56的版本 (创建页面,内容为“<script> ******************** this comment is 80 characters long ********************:​ (function () { setting strict mode and double-run prevention:​ "use strict"; if (window.andrewds1021 && window.andrewds1021.tabber_default && window.andrewds1021.tabber_default.has_run) return; if (!window.andrewds1021) { window.andrewds1021 = { tabber_default: {} }; } else if (!window.andrewds1021.tabber_d…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

<script> /********************* this comment is 80 characters long *********************/

(function () {

/* setting strict mode and double-run prevention */

   "use strict";
   if (window.andrewds1021 && window.andrewds1021.tabber_default
       && window.andrewds1021.tabber_default.has_run) return;
   if (!window.andrewds1021) {
       window.andrewds1021 = {
           tabber_default: {}
       };
   } else if (!window.andrewds1021.tabber_default) {
       window.andrewds1021.tabber_default = {};
   }
   window.andrewds1021.tabber_default.has_run = true;
   

/* find instances of Tabber */

   var tabbers = Array.prototype.slice.call(document.getElementsByClassName("tabber"));
   if (tabbers.length) tabbers.forEach(setTabberDefault);
   

/*

* process a Tabber instance with the following procedure
* if there should not be any remaining instances, return
* find instance in pre-collected instances list
  * if not found, return
  * else remove instance from list and proceed
  * this ensures an instance is processed at most once
* retrieve fragment from URL
* find tab labels, content boxes, first hash-matching descendant, and first descendant
  with default marker
* if a tab label hash-matches, return
  * this prevents the default tab from overriding a tab specified by fragment
* find index of content box to display
  * if hash-matching descendant was found, find the content box it is inside
  * if no hash-matching descendant or content box not found, find first content
    box with default marker
    * to account for potential nesting, marker must be either a direct
      descendant or a direct descendant of the wrapper paragraph tag
  * if still no content box found and descendant with default marker was found,
    find the content box the descendant is inside
* if no content box found for display, return
* set the display and class for each pair of content box and navigation link
* NOTE: when editing this procedure, remember that instances may be nested
  • /
   function setTabberDefault(tabs) {
       if (!tabbers.length) return;
       var index = tabbers.indexOf(tabs);
       if (index == -1) return;
       tabbers.splice(index, 1);
       var hash = location.hash.substring(1);
       var labels = [];
       var content = [];
       var nested_hash, nested_mark, iter;
       Array.prototype.slice.call(tabs.getElementsByClassName("wds-tabs__tab"))
           .forEach(function (val) {
           if (tabs == val.parentElement.parentElement.parentElement) {
               labels.push(val);
           } else if (!nested_hash && hash && (hash == val.getAttribute("data-hash"))) {
               nested_hash = val;
           }
       });
       Array.prototype.slice.call(tabs.getElementsByClassName("wds-tab__content"))
           .forEach(function (val1) {
           if (tabs == val1.parentElement) {
               content.push(val1);
           } else if (!nested_mark && val1.getElementsByClassName("TabberDefault")
               .length) {
               nested_mark = val1;
           }
       });
       if (hash && labels.some(function (val) {
           return hash == val.getAttribute("data-hash");
       })) return;
       index = -1;
       while ((index == -1) && nested_hash) {
           nested_hash = nested_hash.parentElement;
           index = content.indexOf(nested_hash);
       }
       for (iter = 0; (index == -1) && (iter < content.length); iter++) {
           if (Array.prototype.slice.call(content[iter]
               .getElementsByClassName("TabberDefault")).filter(function (val) {
               while (!val.classList.contains("wds-tab__content"))
                   val = val.parentElement;
               return content[iter] == val;
           }).length) index = iter;
       }
       while ((index == -1) && nested_mark) {
           nested_mark = nested_mark.parentElement;
           index = content.indexOf(nested_mark);
       }
       if (index == -1) return;
       content.forEach(function (val, idx) {
           if (index == idx) {
               val.classList.add("wds-is-current");
               labels[index].classList.add("wds-is-current");
           } else {
               val.classList.remove("wds-is-current");
               labels[idx].classList.remove("wds-is-current");
           }
       });
   }
   

})(); </script>