diff --git a/Compass QoL Enhancer.user.js b/Compass QoL Enhancer.user.js index 8bf0fd5..aee58f3 100644 --- a/Compass QoL Enhancer.user.js +++ b/Compass QoL Enhancer.user.js @@ -2,7 +2,7 @@ // @name Compass QoL Enhancer // @namespace blankie-scripts // @match http*://*.compass.education/* -// @version 1.29.0 +// @version 1.30.0 // @author blankie // @description A userscript that adds small but useful features for Compass, such as the ability to close windows by clicking on the background // @inject-into page @@ -230,7 +230,7 @@ if (LearningTasksDetailsWidgetNew) { let isStudentView = widget.isStudentView; let isStudentOrParent = widget.isStudentOrParent; widget.isStudentView = widget.isStudentOrParent = false; - let ret = originalRenderer.apply(this, arguments); + let ret = originalRenderer.apply(widget, arguments); widget.isStudentView = isStudentView; widget.isStudentOrParent = isStudentOrParent; return ret; @@ -363,11 +363,10 @@ if (InstanceDetailsWidget) { } // Sort by name in wiki/resources +function isFolder(node) { + return node.data.type === unsafeWindow.Compass.enums.WikiNodeType.Folder; +} function wikiNodeSort(lhs, rhs) { - function isFolder(node) { - return node.data.type === unsafeWindow.Compass.enums.WikiNodeType.Folder; - } - if (isFolder(lhs) && !isFolder(rhs)) { return -1; } else if (!isFolder(lhs) && isFolder(rhs)) { @@ -384,13 +383,38 @@ function wikiNodeSort(lhs, rhs) { return 1; } } + +function wikiHandleSorting() { + // check if root node exists, otherwise pages like /Communicate/SchoolDocumentation.aspx will die + if (this.sort && this.treePanel.getRootNode()) { + this.treePanel.store.sort({sorterFn: wikiNodeSort}); + } else if (!this.sort) { + this.treePanel.store.sorters.clear(); + } +} +// Add "Enable/Disable sorting" button +function wikiAddSortButton() { + let refreshButton = this.treePanel.down("#refreshButton"); + toolbar = refreshButton.up(); + toolbar.remove("toggleSortButton"); + toolbar.insert(toolbar.items.items.indexOf(refreshButton), { + xtype: "button", + itemId: "toggleSortButton", + text: `${this.sort ? "Disable" : "Enable"} Sorting`, + handler: () => { + this.sort = !this.sort; + wikiHandleSorting.call(this); + this.rebindTreePanel(true); + } + }); +} + let WikiBrowserPanel = getExtClass("Compass.widgets.WikiBrowserPanel"); if (WikiBrowserPanel) { let originalInitComponent = WikiBrowserPanel.prototype.initComponent; WikiBrowserPanel.prototype.initComponent = function() { - this.on("treeDataLoaded", function() { - this.treePanel.store.sort({sorterFn: wikiNodeSort}); - }); + this.sort = true; + this.on("treeDataLoaded", wikiHandleSorting); originalInitComponent.apply(this, arguments); } @@ -406,10 +430,8 @@ if (WikiBrowserPanel) { this.treePanel.down("#toolButton").hidden = true; this.treePanel.events.itemcontextmenu = true; - // check if root node exists, otherwise pages like /Communicate/SchoolDocumentation.aspx will die - if (this.treePanel.getRootNode()) { - this.treePanel.store.sort({sorterFn: wikiNodeSort}); - } + wikiHandleSorting.call(this); + wikiAddSortButton.call(this); }; let originalSelectedNodeChanged = WikiBrowserPanel.prototype.selectedNodeChanged; @@ -427,6 +449,8 @@ if (WikiBrowserPanel) { toolbar.remove(item); } } + + wikiAddSortButton.call(this); }; let originalUpdateNodePermissions = WikiBrowserPanel.prototype.updateNodePermissions;