Add history and talk page icons to sticky header

Bug: T290597
Change-Id: Ib590399df09a9da8e181b331d4227b0de30b9a8e
This commit is contained in:
jdlrobson 2021-09-14 09:53:35 -07:00
parent b7ef3d9a0e
commit 52204c0f1a
5 changed files with 80 additions and 2 deletions

View file

@ -49,6 +49,22 @@ class SkinVector extends SkinMustache {
'is-quiet' => true, 'is-quiet' => true,
'class' => 'sticky-header-icon' 'class' => 'sticky-header-icon'
]; ];
private const TALK_ICON = [
'href' => '#',
'id' => 'ca-talk-sticky-header',
'event' => 'talk-sticky-header',
'icon' => 'wikimedia-speechBubbles',
'is-quiet' => true,
'class' => 'sticky-header-icon'
];
private const HISTORY_ICON = [
'href' => '#',
'id' => 'ca-history-sticky-header',
'event' => 'history-sticky-header',
'icon' => 'wikimedia-history',
'is-quiet' => true,
'class' => 'sticky-header-icon'
];
/** /**
* T243281: Code used to track clicks to opt-out link. * T243281: Code used to track clicks to opt-out link.
@ -311,7 +327,7 @@ class SkinVector extends SkinMustache {
'data-primary-action' => !$this->shouldHideLanguages() ? $this->getULSButtonData() : '', 'data-primary-action' => !$this->shouldHideLanguages() ? $this->getULSButtonData() : '',
'data-button-start' => self::NO_ICON, 'data-button-start' => self::NO_ICON,
'data-buttons' => [ 'data-buttons' => [
self::NO_ICON, self::NO_ICON, self::NO_ICON, self::NO_ICON self::TALK_ICON, self::HISTORY_ICON, self::NO_ICON, self::NO_ICON
] ]
]; ];
} }

View file

@ -1,6 +1,7 @@
{{#href}}<a href="{{.}}"{{/href}} {{#href}}<a href="{{.}}"{{/href}}
{{^href}}<button{{/href}} {{^href}}<button{{/href}}
id="{{id}}" {{#id}}id="{{.}}"{{/id}}
{{#event}}data-event-name="{{.}}"{{/event}}
class="mw-ui-button {{#is-quiet}}mw-ui-quiet{{/is-quiet}} {{#icon}}mw-ui-icon mw-ui-icon-element mw-ui-icon-{{.}}{{/icon}} {{class}}"> class="mw-ui-button {{#is-quiet}}mw-ui-quiet{{/is-quiet}} {{#icon}}mw-ui-icon mw-ui-icon-element mw-ui-icon-{{.}}{{/icon}} {{class}}">
{{{html-vector-button-icon}}} {{{html-vector-button-icon}}}
<span>{{label}}</span> <span>{{label}}</span>

View file

@ -19,6 +19,7 @@
"linkMap": { "linkMap": {
"\"addEventListener\"": "https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener", "\"addEventListener\"": "https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener",
"Document": "https://developer.mozilla.org/docs/Web/API/Document", "Document": "https://developer.mozilla.org/docs/Web/API/Document",
"Element": "https://developer.mozilla.org/docs/Web/API/Element",
"Event": "https://developer.mozilla.org/docs/Web/API/Event", "Event": "https://developer.mozilla.org/docs/Web/API/Event",
"HTMLElement": "https://developer.mozilla.org/docs/Web/API/HTMLElement", "HTMLElement": "https://developer.mozilla.org/docs/Web/API/HTMLElement",
"HTMLInputElement": "https://developer.mozilla.org/docs/Web/API/HTMLInputElement", "HTMLInputElement": "https://developer.mozilla.org/docs/Web/API/HTMLInputElement",

View file

@ -8,6 +8,49 @@ var
VECTOR_USER_LINKS_SELECTOR = '.vector-user-links', VECTOR_USER_LINKS_SELECTOR = '.vector-user-links',
VECTOR_MENU_CONTENT_LIST_SELECTOR = '.vector-menu-content-list'; VECTOR_MENU_CONTENT_LIST_SELECTOR = '.vector-menu-content-list';
/**
* Copies attribute from an element to another.
*
* @param {Element} from
* @param {Element} to
* @param {string} attribute
*/
function copyAttribute( from, to, attribute ) {
var fromAttr = from.getAttribute( attribute );
if ( fromAttr ) {
to.setAttribute( attribute, fromAttr );
}
}
/**
* Makes sticky header icons functional for modern Vector.
*
* @param {HTMLElement} header
* @param {HTMLElement|null} history
* @param {HTMLElement|null} talk
*/
function prepareIcons( header, history, talk ) {
var historySticky = header.querySelector( '#ca-history-sticky-header' ),
talkSticky = header.querySelector( '#ca-talk-sticky-header' );
if ( !historySticky || !talkSticky ) {
throw new Error( 'Sticky header has unexpected HTML' );
}
if ( history ) {
copyAttribute( history, historySticky, 'href' );
} else {
// @ts-ignore
historySticky.parentNode.removeChild( historySticky );
}
if ( talk ) {
copyAttribute( talk, talkSticky, 'href' );
} else {
// @ts-ignore
talkSticky.parentNode.removeChild( talkSticky );
}
}
/** /**
* Makes sticky header functional for modern Vector. * Makes sticky header functional for modern Vector.
* *
@ -78,6 +121,10 @@ function makeStickyHeaderFunctional(
// Clone the updated user menu to the sticky header. // Clone the updated user menu to the sticky header.
userMenuStickyContainerInner.appendChild( userMenuClone ); userMenuStickyContainerInner.appendChild( userMenuClone );
prepareIcons( header,
document.querySelector( '#ca-history a' ),
document.querySelector( '#ca-talk a' )
);
stickyObserver.observe( stickyIntersection ); stickyObserver.observe( stickyIntersection );
} }

View file

@ -164,6 +164,18 @@
"parentheses-end" "parentheses-end"
] ]
}, },
"skins.vector.icons.js": {
"selectorWithVariant": ".mw-ui-icon-wikimedia-{name}-{variant}:before",
"selectorWithoutVariant": ".mw-ui-icon-wikimedia-{name}:before",
"useDataURI": false,
"defaultColor": "#000",
"class": "ResourceLoaderOOUIIconPackModule",
"variants": [],
"icons": [
"history",
"speechBubbles"
]
},
"skins.vector.icons": { "skins.vector.icons": {
"selectorWithVariant": ".mw-ui-icon-wikimedia-{name}-{variant}:before", "selectorWithVariant": ".mw-ui-icon-wikimedia-{name}-{variant}:before",
"selectorWithoutVariant": ".mw-ui-icon-wikimedia-{name}:before", "selectorWithoutVariant": ".mw-ui-icon-wikimedia-{name}:before",
@ -205,6 +217,7 @@
"resources/skins.vector.js/searchToggle.js" "resources/skins.vector.js/searchToggle.js"
], ],
"dependencies": [ "dependencies": [
"skins.vector.icons.js",
"mediawiki.page.ready", "mediawiki.page.ready",
"mediawiki.util" "mediawiki.util"
], ],