Browse Source

hotkey 't' to toggle 'Sort by Titles'/'Sort default'

Gilles Grandou 11 months ago
parent
commit
843c6f7f5a
2 changed files with 64 additions and 0 deletions
  1. 28 0
      plugins.local/toggle_sort_titles/init.js
  2. 36 0
      plugins.local/toggle_sort_titles/init.php

+ 28 - 0
plugins.local/toggle_sort_titles/init.js

@@ -0,0 +1,28 @@
+require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
+	ready(function () {
+		PluginHost.register(PluginHost.HOOK_INIT_COMPLETE, () => {
+			App.hotkey_actions["feed_toggle_title"] = toggleHeadlineOrderTitle;
+		});
+	});
+});
+
+
+function toggleHeadlineOrderTitle() {
+	const toolbar = document.forms["toolbar-main"];
+	const order_by = dijit.getEnclosingWidget(toolbar.order_by);
+
+	let value = order_by.attr('value');
+	switch(value) {
+		case 'date_reverse':
+			value = 'feed_dates';
+			break;
+		case 'title':
+			value = 'date_reverse';
+			break;
+		default:
+			value = 'title';
+	}
+
+	order_by.attr('value', value);
+	Feeds.reloadCurrent();
+}

+ 36 - 0
plugins.local/toggle_sort_titles/init.php

@@ -0,0 +1,36 @@
+<?php
+class Toggle_Sort_Titles extends Plugin {
+	private $host;
+
+	function about() {
+		return array(1.0,
+			"Add a 't' hotkey to toggle headlines sorting by title and by default",
+			"ggrandou" );
+	}
+
+	function init($host) {
+		$this->host = $host;
+		$host->add_hook($host::HOOK_HOTKEY_INFO, $this);
+		$host->add_hook($host::HOOK_HOTKEY_MAP, $this);
+	}
+
+	function hook_hotkey_info($hotkeys) {
+		$hotkeys[__("Feed")]["feed_toggle_title"] = __("Toggle Headlines grouping by Titles");
+		return $hotkeys;
+	}
+
+	function hook_hotkey_map($hotkeys) {
+		$hotkeys["t"] = "feed_toggle_title";
+		return $hotkeys;
+	}
+
+	function get_js() {
+		return file_get_contents(__DIR__ . "/init.js");
+	}
+	
+	function api_version() {
+		return 2;
+	}
+}
+
+?>