From 720b31879634f21ea7db85f49d6f07ec7d7344bc Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 14 Dec 2021 21:53:45 +0300 Subject: * fox.form.Select: add several properties allowing it to better imitate other controls like DropDownButton, etc. * rework several main toolbar items to use fox.form.Select instead of other controls * replace HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM with HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM2 because of markup change (option instead of menuitem) * PluginHost: add some explicit typecasts to make intellephense shut up --- js/Feeds.js | 4 +++ js/Headlines.js | 94 ++++++++++++++++++++++++++++++++++++++++++++----------- js/form/Select.js | 64 +++++++++++++++++++++++++++++++++++-- 3 files changed, 141 insertions(+), 21 deletions(-) (limited to 'js') diff --git a/js/Feeds.js b/js/Feeds.js index 5ef554af0..714eb77d2 100644 --- a/js/Feeds.js +++ b/js/Feeds.js @@ -282,6 +282,10 @@ const Feeds = { CommonDialogs.safeModeWarning(); } + dojo.connect(dijit.byId("main-catchup-dropdown"), 'onItemClick', + (item) => Feeds.catchupCurrent(item.option.value) + ); + // bw_limit disables timeout() so we request initial counters separately if (App.getInitParam("bw_limit")) { this.requestCounters(); diff --git a/js/Headlines.js b/js/Headlines.js index 7557676ee..b64ba6bca 100755 --- a/js/Headlines.js +++ b/js/Headlines.js @@ -626,6 +626,12 @@ const Headlines = { const search_query = Feeds._search_query ? Feeds._search_query.query : ""; const target = dijit.byId('toolbar-headlines'); + // TODO: is this needed? destroyDescendants() below might take care of it (?) + if (this._headlinesSelectClickHandle) + dojo.disconnect(this._headlinesSelectClickHandle); + + target.destroyDescendants(); + if (tb && typeof tb == 'object') { target.attr('innerHTML', ` @@ -646,27 +652,37 @@ const Headlines = { -
- ${__("Select...")} -
-
${__('All')}
-
${__('Unread')}
-
${__('Invert')}
-
${__('None')}
-
-
${__('Toggle unread')}
-
${__('Toggle starred')}
-
${__('Toggle published')}
-
-
${__('Mark as read')}
-
${__('Set score')}
- ${tb.plugin_menu_items} + + + ${tb.plugin_buttons} `); @@ -675,6 +691,48 @@ const Headlines = { } dojo.parser.parse(target.domNode); + + this._headlinesSelectClickHandle = dojo.connect(dijit.byId("headlines-select-articles-dropdown"), 'onItemClick', + (item) => { + const action = item.option.value; + + switch (action) { + case 'headlines_select_all': + Headlines.select('all'); + break; + case 'headlines_select_unread': + Headlines.select('unread'); + break; + case 'headlines_select_invert': + Headlines.select('invert'); + break; + case 'headlines_select_none': + Headlines.select('none'); + break; + case 'headlines_selectionToggleUnread': + Headlines.selectionToggleUnread(); + break; + case 'headlines_selectionToggleMarked': + Headlines.selectionToggleMarked(); + break; + case 'headlines_selectionTogglePublished': + Headlines.selectionTogglePublished(); + break; + case 'headlines_catchupSelection': + Headlines.catchupSelection(); + break; + case 'article_selectionSetScore': + Article.selectionSetScore(); + break; + case 'headlines_deleteSelection': + Headlines.deleteSelection(); + break; + default: + if (!PluginHost.run_until(PluginHost.HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM2, true, action)) + console.warn('unknown headlines action', action); + } + } + ); }, onLoaded: function (reply, offset, append) { console.log("Headlines.onLoaded: offset=", offset, "append=", append); diff --git a/js/form/Select.js b/js/form/Select.js index 530880e2d..0c73cd52c 100755 --- a/js/form/Select.js +++ b/js/form/Select.js @@ -1,8 +1,66 @@ -/* global dijit, define */ -define(["dojo/_base/declare", "dijit/form/Select"], function (declare) { - return declare("fox.form.Select", dijit.form.Select, { +/* eslint-disable prefer-rest-params */ +/* global define */ +// FIXME: there probably is a better, more dojo-like notation for custom data- properties +define(["dojo/_base/declare", + "dijit/form/Select", + "dojo/_base/lang", // lang.hitch + "dijit/MenuItem", + "dijit/MenuSeparator", + "dojo/aspect", + ], function (declare, select, lang, MenuItem, MenuSeparator, aspect) { + return declare("fox.form.Select", select, { focus: function() { return; // Stop dijit.form.Select from keeping focus after closing the menu }, + startup: function() { + this.inherited(arguments); + + if (this.attr('data-dropdown-skip-first') == 'true') { + aspect.before(this, "_loadChildren", () => { + this.options = this.options.splice(1); + }); + } + }, + // hook invoked when dropdown MenuItem is clicked + onItemClick: function(/*item, menu*/) { + // + }, + _setValueAttr: function(/*anything*/ newValue, /*Boolean?*/ priorityChange){ + if (this.attr('data-prevent-value-change') == 'true' && newValue != '') + return; + + this.inherited(arguments); + }, + // the only difference from dijit/form/Select is _onItemClicked() handler + _getMenuItemForOption: function(/*_FormSelectWidget.__SelectOption*/ option){ + // summary: + // For the given option, return the menu item that should be + // used to display it. This can be overridden as needed + if (!option.value && !option.label){ + // We are a separator (no label set for it) + return new MenuSeparator({ownerDocument: this.ownerDocument}); + } else { + // Just a regular menu option + const click = lang.hitch(this, "_setValueAttr", option); + const item = new MenuItem({ + option: option, + label: (this.labelType === 'text' ? (option.label || '').toString() + .replace(/&/g, '&').replace(/ { + this.onItemClick(item, this.dropDown); + + click(); + }, + ownerDocument: this.ownerDocument, + dir: this.dir, + textDir: this.textDir, + disabled: option.disabled || false + }); + item.focusNode.setAttribute("role", "option"); + + return item; + } + }, }); }); -- cgit v1.2.3