mirror of
https://github.com/XRPLF/xrpl-dev-portal.git
synced 2025-11-20 11:45:50 +00:00
Add save lang to code tabs.
WIP. If multiple tab blocks have different names it will hide all.
This commit is contained in:
@@ -47,31 +47,74 @@ all copies or substantial portions of the Software.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
jQuery.fn.minitabs = function(speed,effect) {
|
jQuery.fn.minitabs = function(speed,effect) {
|
||||||
this.each(function() {
|
|
||||||
var id = "#" + $(this).attr('id')
|
function saveToLocal(lang){
|
||||||
|
console.log("saving language > " + lang);
|
||||||
|
window.localStorage.setItem('user-preferred-devlanguage', lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSelectedTabFromSaved(id){
|
||||||
|
// get any data from local stores.
|
||||||
|
$savedValue = window.localStorage.getItem('user-preferred-devlanguage');
|
||||||
|
// show all tabs if value present
|
||||||
|
if($savedValue !== null) {
|
||||||
|
showSlectedTab($savedValue);
|
||||||
|
}else {
|
||||||
$(id + ">DIV:gt(0)").hide();
|
$(id + ">DIV:gt(0)").hide();
|
||||||
$(id + ">UL>LI>A:first").addClass("current");
|
$(id + ">UL>LI>A:first").addClass("current");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSlectedTab(lang) {
|
||||||
|
// Hide all.
|
||||||
|
// Tab heads
|
||||||
|
$(".multicode>UL>LI>A").removeClass("current");
|
||||||
|
// Tab contents
|
||||||
|
$(".multicode>DIV").hide(speed);
|
||||||
|
|
||||||
|
$(this).blur();
|
||||||
|
//show selcted.
|
||||||
|
$(".multicode>UL>LI>."+lang).addClass("current");
|
||||||
|
$(".multicode>DIV."+lang).show(speed);
|
||||||
|
|
||||||
|
// TODO: Only add/remove on samples that DO contain that value.
|
||||||
|
// Example
|
||||||
|
// if javascript is lang.
|
||||||
|
// only add current if the UL has javascript in the tabs.
|
||||||
|
// Otherwise this will hide all tabs and not show anything.
|
||||||
|
|
||||||
|
// save in localstorage.
|
||||||
|
saveToLocal(lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.each(function() {
|
||||||
|
var id = "#" + $(this).attr('id')
|
||||||
|
//Use saved value or set to first tab
|
||||||
|
showSelectedTabFromSaved(id);
|
||||||
|
|
||||||
|
//Add click on each tab
|
||||||
$(id + ">UL>LI>A").click(
|
$(id + ">UL>LI>A").click(
|
||||||
function(){
|
function(){
|
||||||
$(id + ">UL>LI>A").removeClass("current");
|
showSlectedTab($(this).attr('class'))
|
||||||
$(this).addClass("current");
|
|
||||||
$(this).blur();
|
//Old
|
||||||
var re = /([_\-\w]+$)/i;
|
|
||||||
var target = $('#' + re.exec(this.href)[1]);
|
// var re = /([_\-\w]+$)/i;
|
||||||
var old = $(id + ">DIV");
|
// var target = $('#' + re.exec(this.href)[1]);
|
||||||
switch (effect) {
|
// var old = $(id + ">DIV");
|
||||||
case 'fade':
|
// switch (effect) {
|
||||||
old.fadeOut(speed).fadeOut(speed);
|
// case 'fade':
|
||||||
target.fadeIn(speed);
|
// old.fadeOut(speed).fadeOut(speed);
|
||||||
break;
|
// target.fadeIn(speed);
|
||||||
case 'slide':
|
// break;
|
||||||
old.slideUp(speed);
|
// case 'slide':
|
||||||
target.fadeOut(speed).fadeIn(speed);
|
// old.slideUp(speed);
|
||||||
break;
|
// target.fadeOut(speed).fadeIn(speed);
|
||||||
default :
|
// break;
|
||||||
old.hide(speed);
|
// default :
|
||||||
target.show(speed)
|
// old.hide(speed);
|
||||||
}
|
// target.show(speed)
|
||||||
|
// }
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
77
tool/filter_multicode_tabs.py
Normal file
77
tool/filter_multicode_tabs.py
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
################################################################################
|
||||||
|
## Multicode Tabs 2 filter ##
|
||||||
|
## Author: Rome Reginelli ##
|
||||||
|
## Copyright: Ripple Labs, Inc. 2016 ##
|
||||||
|
## ##
|
||||||
|
## Finds multicode tab sections and turns them into properly-formatted ##
|
||||||
|
## HTML syntax to use with minitabs jQuery ##
|
||||||
|
################################################################################
|
||||||
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
|
MC_START_REGEX = re.compile(r"<!--\s*MULTICODE_BLOCK_START\s*-->")
|
||||||
|
MC_END_REGEX = re.compile(r"<!--\s*MULTICODE_BLOCK_END\s*-->")
|
||||||
|
|
||||||
|
def filter_html(html, mode="html", **kwargs):
|
||||||
|
"""
|
||||||
|
Turn multicode comments into a div (after markdown inside is parsed). You
|
||||||
|
can use this div for styling even in PDF format. Doesn't apply to Markdown
|
||||||
|
since most parsers won't parse markdown inside HTML blocks.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if mode == "md":
|
||||||
|
return html
|
||||||
|
|
||||||
|
html = re.sub(MC_START_REGEX, "<div class='multicode'>", html)
|
||||||
|
html = re.sub(MC_END_REGEX, "</div>", html)
|
||||||
|
return html
|
||||||
|
|
||||||
|
def filter_soup(soup, mode="html", **kwargs):
|
||||||
|
"""Turn a multicode block into the correct syntax for minitabs, but only
|
||||||
|
in the HTML version."""
|
||||||
|
if mode != "html":
|
||||||
|
return
|
||||||
|
|
||||||
|
multicodes = soup.find_all(class_="multicode")
|
||||||
|
index1 = 0
|
||||||
|
for cb_area in multicodes:
|
||||||
|
cb_area["id"] = "code-%d" % index1
|
||||||
|
|
||||||
|
codetabs_ul = soup.new_tag("ul")
|
||||||
|
codetabs_ul["class"] = "codetabs"
|
||||||
|
cb_area.insert(0,codetabs_ul)
|
||||||
|
|
||||||
|
pres = cb_area.find_all(class_="codehilite")
|
||||||
|
index2 = 0
|
||||||
|
for pre in pres:
|
||||||
|
#make a unique ID for this code sample
|
||||||
|
linkid = "code-%d-%d" % (index1, index2)
|
||||||
|
|
||||||
|
#wrap this code sample in an ID'd div
|
||||||
|
code_sample_wrapper = soup.new_tag("div", id=linkid)
|
||||||
|
code_sample_wrapper["style"] = "position: static;"
|
||||||
|
pre.wrap(code_sample_wrapper)
|
||||||
|
|
||||||
|
#add a link to the tabs ul
|
||||||
|
linkback = soup.new_tag("a", href=("#%s" % linkid))
|
||||||
|
linkback_li = soup.new_tag("li")
|
||||||
|
|
||||||
|
linkback_li.append(linkback)
|
||||||
|
codetabs_ul.append(linkback_li)
|
||||||
|
|
||||||
|
#find the text label for this sample
|
||||||
|
prev_p = code_sample_wrapper.find_previous_sibling("p")
|
||||||
|
try:
|
||||||
|
label = "".join(prev_p.em.strings)
|
||||||
|
except AttributeError:
|
||||||
|
label = "Code Sample %d-%d" % (index1, index2)
|
||||||
|
linkback.string = label
|
||||||
|
#add class with name of tab label
|
||||||
|
label_class = label.replace(" ","").replace("-","").lower()
|
||||||
|
linkback["class"] = label_class
|
||||||
|
code_sample_wrapper["class"] = "code_sample " + label_class
|
||||||
|
prev_p.decompose()
|
||||||
|
|
||||||
|
index2 += 1
|
||||||
|
|
||||||
|
index1 += 1
|
||||||
Reference in New Issue
Block a user