1 function getLabelName(innerHTML) {
2 var str = innerHTML.toLowerCase();
3 // Replace all '+' with 'p'
4 str = str.split('+').join('p');
5 // Replace all ' ' with '_'
6 str = str.split(' ').join('_');
7 // Replace all '#' with 'sharp'
8 str = str.split('#').join('sharp');
9 // Replace other special characters with 'ascii' + code
10 for (var i = 0; i < str.length; i++) {
11 var charCode = str.charCodeAt(i);
12 if (!(charCode == 95 || (charCode > 96 && charCode < 123) || (charCode > 47 && charCode < 58)))
13 str = str.substr(0, i) + 'ascii' + charCode + str.substr(i + 1);
18 function addToggle() {
19 var $getDiv = $('div.newInnerHTML').last();
20 var buttonName = $getDiv.html();
21 var label = getLabelName(buttonName.trim());
22 $getDiv.attr("title", label);
24 $getDiv = $getDiv.next();
25 $getDiv.attr("class", "toggleable_div label_" + label);
29 function addButton(label, buttonName) {
30 var b = document.createElement("BUTTON");
31 b.innerHTML = buttonName;
32 b.setAttribute('class', 'toggleable_button label_' + label);
33 b.onclick = function() {
34 $('.toggleable_button').css({
36 'border-radius': '4px'
38 $('.toggleable_button.label_' + label).css({
40 'border-radius': '4px'
42 $('.toggleable_div').css('display', 'none');
43 $('.toggleable_div.label_' + label).css('display', 'block');
45 b.style.border = '2px outset';
46 b.style.borderRadius = '4px';
47 b.style.margin = '2px';
51 function buttonsToAdd($elements, $heading, $type) {
52 if ($elements.length === 0) {
53 $elements = $("" + $type + ":contains(" + $heading.html() + ")").parent().prev("div.newInnerHTML");
55 var arr = jQuery.makeArray($elements);
57 arr.forEach(function(e) {
58 var txt = e.innerHTML;
60 $button = addButton(e.title, txt);
61 if (Object.keys(seen).length == 0) {
62 var linebreak1 = document.createElement("br");
63 var linebreak2 = document.createElement("br");
64 ($heading).append(linebreak1);
65 ($heading).append(linebreak2);
67 ($heading).append($button);
74 function addTutorialsButtons() {
75 $("h2").each(function() {
77 $smallerHeadings = $(this).nextUntil("h2").filter("h3").add($(this).nextUntil("h2").find("h3"));
78 if ($smallerHeadings.length) {
79 $smallerHeadings.each(function() {
80 var $elements = $(this).nextUntil("h2,h3").filter("div.newInnerHTML");
81 buttonsToAdd($elements, $(this), "h3");
84 var $elements = $(this).nextUntil("h2").filter("div.newInnerHTML");
85 buttonsToAdd($elements, $heading, "h2");
88 $(".toggleable_button").first().click();
89 var $clickDefault = $('.toggleable_button.label_python').first();
90 if ($clickDefault.length) {
91 $clickDefault.click();
93 $clickDefault = $('.toggleable_button.label_cpp').first();
94 if ($clickDefault.length) {
95 $clickDefault.click();