diff --git a/assets/js/multicodetab.js b/assets/js/multicodetab.js index 38db414ffb..1a0f743f06 100644 --- a/assets/js/multicodetab.js +++ b/assets/js/multicodetab.js @@ -47,30 +47,67 @@ all copies or substantial portions of the Software. */ jQuery.fn.minitabs = function(speed,effect) { + + function saveToLocal(lang){ + window.localStorage.setItem('user-preferred-devlanguage', lang); + } + + function setTabsToFirst(id){ + $(".multicode[id='"+id+"']" + ">DIV").hide(); + $(".multicode[id='"+id+"']" + ">UL>LI>A").removeClass("current"); + // + $(".multicode[id='"+id+"']" + ">DIV:first").show(); + $(".multicode[id='"+id+"']" + ">UL>LI>A:first").addClass("current"); + } + + function setTabsToLang(id, lang){ + $(".multicode[id='"+id+"']" + ">DIV").hide(); + $(".multicode[id='"+id+"']" + ">UL>LI>A").removeClass("current"); + // + $(".multicode[id='"+id+"']" + ">UL>LI>A[class="+lang+"]").addClass("current"); + $(".multicode[id='"+id+"']" + ">DIV."+lang).show(); + } + + function showSelectedTabFromSaved(id){ + var savedValue = window.localStorage.getItem('user-preferred-devlanguage'); + + if(savedValue !== null) { + showSlectedTab(savedValue); + }else { + setTabsToFirst(id); + } + } + + function showSlectedTab(lang) { + $('.multicode').each(function() { + var hasLang = false; + $(this).find(">UL>LI>A").each(function() { + if ($(this).attr('class') == lang ) { + hasLang = true; + } + }) + + if(hasLang) { + setTabsToLang($(this).attr('id'), lang); + } else { + setTabsToFirst($(this).attr('id')); + } + }) + + // save in localstorage. + saveToLocal(lang); + } + this.each(function() { var id = "#" + $(this).attr('id') - $(id + ">DIV:gt(0)").hide(); - $(id + ">UL>LI>A:first").addClass("current"); + //Use saved value or set to first tab + showSelectedTabFromSaved($(this).attr('id')); + + //Add click on each tab $(id + ">UL>LI>A").click( function(){ - $(id + ">UL>LI>A").removeClass("current"); - $(this).addClass("current"); - $(this).blur(); - var re = /([_\-\w]+$)/i; - var target = $('#' + re.exec(this.href)[1]); - var old = $(id + ">DIV"); - switch (effect) { - case 'fade': - old.fadeOut(speed).fadeOut(speed); - target.fadeIn(speed); - break; - case 'slide': - old.slideUp(speed); - target.fadeOut(speed).fadeIn(speed); - break; - default : - old.hide(speed); - target.show(speed) + if(!$(this).hasClass("current") ){ + showSlectedTab($(this).attr('class')) } return false; } diff --git a/tool/filter_multicode_tabs.py b/tool/filter_multicode_tabs.py new file mode 100644 index 0000000000..e313714a60 --- /dev/null +++ b/tool/filter_multicode_tabs.py @@ -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"") +MC_END_REGEX = re.compile(r"") + +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, "