/*
Put repeating elments in tabbed content.
Requirements:
- All sections need to be siblings (same parentNode).
- All sections need to be siblings with nothing in between,
or (optionally?) if there is move that below sections?
// example:
// url : https://www.sublimetext.com/docs/linux_repositories.html#apt
// selector: 'section#linux-package-manager-repositories > section[id]'
//
// section#linux-package-manager-repositories
// ul li p a[href="#xxx"]
// section#xxx
TODO: Make work for any sections selector.
TODO: undo everything on 2nd try (on same section selection?)
TODO: Find links by looking for matching a[href="#SECTIONID"].
TODO: On hash change on any id matching a section or anything in it open the section.
TODO: for section selection: perhaps wait for a click on something,
and then work upwards to closest block level element, and then select similar siblings?
See: window.getComputedStyle(element).display === 'block'
*/
/*
(function(){
let section_selector = '',
sections = [],
tabs = [],
$ = document.querySelector.bind(document),
$$ = document.querySelectorAll.bind(document),
log = console.log.bind(console),
msg = (m) => {alert(m); log(m);};
section_selector = window.sections_in_tabs_last_section_selector || '';
section_selector = prompt('DOM selector for content elements:', section_selector);
if(!section_selector) {
return;
}
window.sections_in_tabs_last_section_selector = section_selector;
sections = Array.from($$(section_selector));
// sanity checks:
// - do we have 2 or more?
// - are all sections direct siblings?
// - TODO: is nothing in between the sections?
if (sections.length < 2) {
msg('Did not find 2 or more sections. Aborting.');
return;
}
let i, common_parent = sections[0].parentNode;
for (i=0; i<sections.length;i++) {
if (common_parent != sections[i].parentNode) {
msg('Section selection did not all share same parentNode. Aborting.');
return;
}
}
let already_tabbed =...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.