Skip to content

Commit

Permalink
removed legacy fallback code from sidebar.react
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Aug 14, 2020
1 parent f2e35d1 commit 5edce30
Showing 1 changed file with 4 additions and 79 deletions.
83 changes: 4 additions & 79 deletions Extensions/xkit_patches.js
Original file line number Diff line number Diff line change
Expand Up @@ -1185,81 +1185,6 @@ XKit.extensions.xkit_patches = new Object({

return;
}

const html = `<div id="xkit_sidebar"></div>`;
const priority = [
$(".small_links"),
$("#dashboard_controls_open_blog"),
$(".controls_section.inbox"),
$(".sidebar_link.explore_link"),
$(".controls_section.recommended_tumblelogs"),
$("#tumblr_radar")
];

for (let section of priority) {
if (section.length) {
section.first().after(html);
break;
}
}
if (!$("#xkit_sidebar").length) {
$("#right_column").append(html);
}

XKit.tools.add_css(`
.controls_section.recommended_tumblelogs:not(:first-child) {
margin-top: 18px !important;
}`,
"sidebar_margins_fix");
},

/**
* Constructs HTML to add to the sidebar.
* Primarily used by add, but can be used directly for custom positioning.
* @param {Object} section
* @param {String} section.id - The element ID for the whole sidebar section
* @param {String} [section.title] - Visible header text of the sidebar section
* @param {Object[]} [section.items] - Array of objects containing button data
* @param {String} section.items[].id - Button element ID
* @param {String} section.items[].text - Visible button text
* @param {Number/String} [section.items[].count] - Text to be displayed as a counter on the button
* @param {Boolean} [section.items[].carrot] - Whether to put a right-facing arrow on the button (shouldn't be combined with count)
* @param {Object[]} [section.small] - Array of objects containing small link data (shouldn't contain more than two)
* @param {String} section.small[].id - Button element ID
* @param {String} section.small[].text - Visible button text
* @return {String} Plug-ready sidebar controls section HTML
*/
construct: function(section) {
section.items = section.items || [];
section.small = section.small || [];

var html = `<ul id="${section.id}" class="controls_section">`;
if (section.title) {
html += `<li class="section_header">${section.title}</li>`;
}
for (let item of section.items) {
html += `
<li class="controls_section_item">
<a id="${item.id}" class="control-item control-anchor" style="cursor:pointer">
<div class="hide_overflow">
${item.text}
${(item.carrot ? '<i class="sub_control link_arrow icon_right icon_arrow_carrot_right"></i>' : "")}
</div>
<span class="count">${item.count || ""}</span>
</a>
</li>`;
}
html += "</ul>";

if (section.small.length !== 0) {
html += '<div class="small_links">';
for (let item of section.small) {
html += `<a id="${item.id}" style="cursor:pointer">${item.text}</a>`;
}
html += "</div>";
}

return html;
},

/**
Expand All @@ -1278,16 +1203,16 @@ XKit.extensions.xkit_patches = new Object({
* @param {String} section.small[].text - Visible button text
* @return {String} Plug-ready sidebar controls section HTML
*/
construct_react: async function(section) {
construct: async function(section) {
section.items = section.items || [];
section.small = section.small || [];

var html = `<ul id="${section.id}" class="controls_section">`;
if (section.title) {
await XKit.css_map.getCssMap();
const sidebarTitle = XKit.css_map.keyToClasses("sidebarTitle").join(" ");
const sidebarTitleClasses = XKit.css_map.keyToClasses("sidebarTitle").join(" ");

html += `<li class="${sidebarTitle}">${section.title}</li>`;
html += `<li class="${sidebarTitleClasses}">${section.title}</li>`;
}
for (let item of section.items) {
html += `
Expand Down Expand Up @@ -1322,7 +1247,7 @@ XKit.extensions.xkit_patches = new Object({
await this.init();
}

$("#xkit_sidebar").append(XKit.page.react ? await this.construct_react(section) : this.construct(section));
$("#xkit_sidebar").append(this.construct(section));
},

remove: id => $(`#${id}, #${id} + .small_links`).remove()
Expand Down

0 comments on commit 5edce30

Please sign in to comment.