-
-
Save dvdsmpsn/f7000489c5fac689648d to your computer and use it in GitHub Desktop.
Hacking the Confluence Space Directory to show all spaces. Break open the jar, go to line 99: pageSize: +AJS.params.pageSize, edit it. See below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
/* module-key = 'com.atlassian.confluence.plugins.confluence-space-directory:space-directory', location = 'js/space-directory.js' */ | |
AJS.toInit(function ($) { | |
var contextPath = AJS.Meta.get("context-path"); | |
var $spaceLabelItems = $(".space-label-item"); | |
var bindLabels = function () { | |
$(".space-label").click(function (e) { | |
$spaceLabelItems.removeClass('active-tab'); | |
var label = $(this); | |
AJS.tabs.change($(".team-label a[data-tab-name='" + label.text() + "']"), e) | |
}); | |
}; | |
var url = AJS.Meta.get("context-path") + "/rest/spacedirectory/1/search", | |
pageUrl = AJS.Meta.get("context-path") + "/spacedirectory/view.action", | |
userString = AJS.Meta.get("remote-user"), | |
queryValue = "", | |
timer; | |
var getSelectedSpaceCategory = function() { | |
return $(".tabs-nav").data("selected-tab"); | |
}; | |
var getActiveTabDetails = function() { | |
var activeTab = $(".tabs-nav .active-tab"); | |
return { | |
type: activeTab.parent().attr("id"), | |
tabName: activeTab.find("a").data("tab-name") | |
}; | |
}; | |
var saveActiveTab = function() { | |
localStorage.setItem("lastSelectedSpaceDirectoryTab", JSON.stringify(getActiveTabDetails())); | |
}; | |
var isAllTabActive = function() { | |
var activeTab = getActiveTabDetails(); | |
return activeTab.type == "space-system-list" && activeTab.tabName == "all"; | |
}; | |
var getLastVisitedTab = function() { | |
return JSON.parse(localStorage.getItem("lastSelectedSpaceDirectoryTab")); | |
}; | |
var setActiveTab = function (tab) { | |
if (tab && tab.type && tab.tabName) { | |
$("#" + tab.type + " a[data-tab-name=" + tab.tabName + "]").parent().addClass("active-tab"); | |
} else { | |
$("#space-system-list a[data-tab-name=site]").parent().addClass("active-tab"); | |
} | |
}; | |
$spaceLabelItems.click(function(){ | |
$spaceLabelItems.removeClass('active-tab'); | |
}); | |
$("#space-search-result").paginate({ | |
nameSpace : "space-directory", | |
url : url, | |
cache: false, // Results may change for the same request | |
pageUrl : pageUrl, | |
getParams : function () { | |
var status = "current", labels = [], type; | |
if (userString && $("#favourites-toggle").hasClass("active-tab")) { | |
labels = ["~" + userString + ":favourite", "~" + userString + ":favorite"]; | |
$("#space-search-title-bar .space-search-title").text("Favourite Spaces"); | |
} | |
var selectedTeamLabel = $(".team-label.active-tab a"); | |
if (selectedTeamLabel.length > 0) { | |
labels.push("team:" + selectedTeamLabel.attr("data-tab-name")); | |
status = selectedTeamLabel.attr("data-status-name"); | |
$("#space-search-title-bar .space-search-title").text(selectedTeamLabel.text()); | |
} | |
if (!labels.length) { | |
var selectedTypeLabel = $(".space-type.active-tab a"); | |
if (selectedTypeLabel.length > 0) { | |
type = selectedTypeLabel.attr("data-type-name"); | |
status = selectedTypeLabel.attr("data-status-name"); | |
$("#space-search-title-bar .space-search-title").text(selectedTypeLabel.text()); | |
} | |
if (!type) | |
$("#space-search-title-bar .space-search-title").text("All Spaces"); | |
} | |
return { | |
query : queryValue, | |
label : labels, | |
type : type, | |
status : status | |
} | |
}, | |
//pageSize: +AJS.params.pageSize, | |
pageSize: 10000000000000, | |
startIndex: 0, | |
preprocess: function(listContainer) { | |
$(".no-results").addClass("hidden"); | |
$("#aui-message-bar").empty(); | |
}, | |
insertResults : function(response, container) { | |
var spaces = response.spaces; | |
var noSpaces = spaces.length == 0; | |
// Do not show the no results message if we're on the all tab and there is no query string. | |
// In that case, we'll already be showing the blank experience panel instead. | |
$(".no-results").toggleClass("hidden", (!noSpaces || (isAllTabActive() && !queryTextBox.val()))); | |
$(".space-list-section").toggleClass("hidden", noSpaces); | |
$("#space-directory-help").toggleClass("hidden", noSpaces); | |
for (var i = 0, il = spaces.length; i < il; i++) { | |
var space = spaces[i]; | |
var spaceItemString = AJS.template.load("space-list-item").fill({ | |
spaceKey : space.key, | |
spaceName : space.name, | |
truncatedSpaceName : space.name, | |
spaceUrl : space.link[1].href, | |
logoUrl : space.logo.href | |
}).fillHtml({ | |
spaceDesc: space.description | |
}).toString(); | |
var spaceItem = $(spaceItemString); | |
container.append(spaceItem); | |
// Load in the extra details | |
var isFav = space.favourite; | |
$(".space-favourites a.icon-remove-fav", spaceItem).toggleClass("hidden", !isFav); | |
$(".space-favourites a.icon-add-fav", spaceItem).toggleClass("hidden", isFav); | |
// Load categories | |
var labels = space.labels.label; | |
if (labels.length > 0) { | |
var labelList = $(".space-labels", spaceItem); | |
var labelsVisible = 0; | |
for (var j =0, ll = labels.length; j < ll; j++) { | |
if (labels[j].namespace == "team") | |
{ | |
var labelItem = $(AJS.template.load("space-label").fill({spaceLabel : labels[j].name}).toString()); | |
// Only show 3 labels | |
if (labelsVisible > 2) { | |
labelItem.addClass("hidden"); | |
} else { | |
labelsVisible++; | |
} | |
$("ul", labelList).append(labelItem); | |
} | |
} | |
if (labelsVisible > 2) { | |
$("ul", labelList).append(AJS.template.load("space-label-ellipsis")); | |
} | |
} | |
} | |
$(".space-favourites").favourites({}); | |
bindLabels(); | |
}, | |
handleError: function() { | |
AJS.messages.error({ | |
body: "An error occurred while searching for spaces.", | |
closeable: false | |
}) | |
} | |
}); | |
var selectedSpaceCategory = getSelectedSpaceCategory(); | |
if (selectedSpaceCategory) { | |
setActiveTab({ | |
type: "space-labels-list", | |
tabName: selectedSpaceCategory | |
}); | |
} else { | |
setActiveTab(getLastVisitedTab()); | |
} | |
var updateList = function () { | |
if (!$("#space-search-result").hasClass("updating-container")) { | |
AJS.trigger("update-list.space-directory", {startIndex: 0}); | |
} | |
saveActiveTab(); | |
}; | |
var queryTextBox = $("#space-search-query"); | |
// Populate the space directory list based on the selected category tab | |
updateList(); | |
AJS.$(document).bind("tabSelect", function (e) { | |
updateList(); | |
return AJS.stopEvent(e); | |
}); | |
queryTextBox.keyup(function (e) { | |
var queryString = $.trim(queryTextBox.val()); | |
if (queryTextBox.hasClass("placeholded")) { | |
queryString = ""; | |
} | |
// Don't run the search if the string is short | |
if (!(/^\S{1,2}$/).test(queryString)) { | |
// Perform a partial text search | |
if (queryString != "") { | |
var temp = queryString; | |
queryString = temp + " OR " + temp + "*" | |
} | |
if (queryValue != queryString) { | |
queryValue = queryString; | |
clearTimeout(timer); | |
timer = setTimeout(updateList, 200); | |
} | |
} | |
}); | |
$("#space-search-form").submit(function(e) { | |
var spaceItems = $("#space-list .space-list-item"); | |
if (!$("#space-search-result").hasClass("updating-container") && spaceItems.length == 1) { | |
window.location = $(spaceItems[0]).find(".space-name a").attr("href"); | |
return AJS.stopEvent(e); | |
} | |
}); | |
bindLabels(); | |
}); | |
} catch (err) { | |
if (console && console.log && console.error) { | |
console.log("Error running batched script."); | |
console.error(err); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment