diff options
author | Andrew Dolgov <[email protected]> | 2022-01-13 13:59:36 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-01-13 13:59:36 +0300 |
commit | 304845f3807cc1021de1f29a35e2e3c370ff9882 (patch) | |
tree | 12206fcb33d26907254ee6adfe2bb20a553bbbca /js | |
parent | 8cf9c451dc1d5f3ed23ead40bee41592f7c07254 (diff) | |
parent | f1607902e6953aa5c486157835105c0c8f08779f (diff) |
Merge branch 'master' of git.fakecake.org:fox/tt-rss
Diffstat (limited to 'js')
-rw-r--r-- | js/CommonFilters.js | 3 | ||||
-rw-r--r-- | js/Feeds.js | 4 | ||||
-rwxr-xr-x | js/Headlines.js | 94 | ||||
-rw-r--r-- | js/PluginHost.js | 12 | ||||
-rwxr-xr-x | js/form/Select.js | 64 |
5 files changed, 155 insertions, 22 deletions
diff --git a/js/CommonFilters.js b/js/CommonFilters.js index 8a20480f0..434ee72c7 100644 --- a/js/CommonFilters.js +++ b/js/CommonFilters.js @@ -16,7 +16,8 @@ const Filters = { ACTION_SCORE: 6, ACTION_LABEL: 7, ACTION_PLUGIN: 9, - PARAM_ACTIONS: [4, 6, 7, 9], + ACTION_REMOVE_TAG: 10, + PARAM_ACTIONS: [4, 6, 7, 9, 10], filter_info: {}, test: function() { const test_dialog = new fox.SingleUseDialog({ 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 18e47d740..2be3cd697 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 = { </span> <span class='right'> <span id='selected_prompt'></span> - <div class='select-articles-dropdown' dojoType='fox.form.DropDownButton' title='"${__('Select articles')}'> - <span>${__("Select...")}</span> - <div dojoType='dijit.Menu' style='display: none;'> - <div dojoType='dijit.MenuItem' onclick='Headlines.select("all")'>${__('All')}</div> - <div dojoType='dijit.MenuItem' onclick='Headlines.select("unread")'>${__('Unread')}</div> - <div dojoType='dijit.MenuItem' onclick='Headlines.select("invert")'>${__('Invert')}</div> - <div dojoType='dijit.MenuItem' onclick='Headlines.select("none")'>${__('None')}</div> - <div dojoType='dijit.MenuSeparator'></div> - <div dojoType='dijit.MenuItem' onclick='Headlines.selectionToggleUnread()'>${__('Toggle unread')}</div> - <div dojoType='dijit.MenuItem' onclick='Headlines.selectionToggleMarked()'>${__('Toggle starred')}</div> - <div dojoType='dijit.MenuItem' onclick='Headlines.selectionTogglePublished()'>${__('Toggle published')}</div> - <div dojoType='dijit.MenuSeparator'></div> - <div dojoType='dijit.MenuItem' onclick='Headlines.catchupSelection()'>${__('Mark as read')}</div> - <div dojoType='dijit.MenuItem' onclick='Article.selectionSetScore()'>${__('Set score')}</div> - ${tb.plugin_menu_items} + + <select class='select-articles-dropdown' + id='headlines-select-articles-dropdown' + data-prevent-value-change="true" + data-dropdown-skip-first="true" + dojoType="fox.form.Select" + title="${__('Show articles')}"> + <option value='' selected="selected">${__("Select...")}</option> + <option value='headlines_select_all'>${__('All')}</option> + <option value='headlines_select_unread'>${__('Unread')}</option> + <option value='headlines_select_invert'>${__('Invert')}</option> + <option value='headlines_select_none'>${__('None')}</option> + <option></option> + <option value='headlines_selectionToggleUnread'>${__('Toggle unread')}</option> + <option value='headlines_selectionToggleMarked'>${__('Toggle starred')}</option> + <option value='headlines_selectionTogglePublished'>${__('Toggle published')}</option> + <option></option> + <option value='headlines_catchupSelection'>${__('Mark as read')}</option> + <option value='article_selectionSetScore'>${__('Set score')}</option> + ${tb.plugin_menu_items != '' ? + ` + <option></option> + ${tb.plugin_menu_items} + ` : ''} ${headlines.id === 0 && !headlines.is_cat ? ` - <div dojoType='dijit.MenuSeparator'></div> - <div dojoType='dijit.MenuItem' class='text-error' onclick='Headlines.deleteSelection()'>${__('Delete permanently')}</div> + <option></option> + <option class='text-error' value='headlines_deleteSelection'>${__('Delete permanently')}</option> ` : ''} - </div> + </select> + ${tb.plugin_buttons} </span> `); @@ -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/PluginHost.js b/js/PluginHost.js index deb7c0645..513429e4a 100644 --- a/js/PluginHost.js +++ b/js/PluginHost.js @@ -21,6 +21,7 @@ const PluginHost = { HOOK_HEADLINE_MUTATIONS_SYNCED: 16, HOOK_HEADLINES_RENDERED: 17, HOOK_HEADLINES_SCROLL_HANDLER: 18, + HOOK_HEADLINE_TOOLBAR_SELECT_MENU_ITEM2: 19, hooks: [], register: function (name, callback) { if (typeof(this.hooks[name]) == 'undefined') @@ -36,6 +37,17 @@ const PluginHost = { this.hooks[name][i](args); } }, + run_until: function (name, check, ...args) { + //console.warn('PluginHost.run_until', name, check, args); + + if (typeof(this.hooks[name]) != 'undefined') + for (let i = 0; i < this.hooks[name].length; i++) { + if (this.hooks[name][i](args) == check) + return true; + } + + return false; + }, unregister: function (name, callback) { for (let i = 0; i < this.hooks[name].length; i++) if (this.hooks[name][i] == callback) 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(/</g, '<') : + option.label) || this.emptyLabel, + onClick: () => { + 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; + } + }, }); }); |