Merge "Add history and talk page icons to sticky header"

This commit is contained in:
jenkins-bot 2021-09-14 23:26:06 +00:00 committed by Gerrit Code Review
commit 8f2a5c58f2
5 changed files with 80 additions and 2 deletions

View File

@ -49,6 +49,22 @@ class SkinVector extends SkinMustache {
'is-quiet' => true,
'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.
@ -311,7 +327,7 @@ class SkinVector extends SkinMustache {
'data-primary-action' => !$this->shouldHideLanguages() ? $this->getULSButtonData() : '',
'data-button-start' => self::NO_ICON,
'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}}<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}}">
{{{html-vector-button-icon}}}
<span>{{label}}</span>

View File

@ -19,6 +19,7 @@
"linkMap": {
"\"addEventListener\"": "https://developer.mozilla.org/docs/Web/API/EventTarget/addEventListener",
"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",
"HTMLElement": "https://developer.mozilla.org/docs/Web/API/HTMLElement",
"HTMLInputElement": "https://developer.mozilla.org/docs/Web/API/HTMLInputElement",

View File

@ -8,6 +8,49 @@ var
VECTOR_USER_LINKS_SELECTOR = '.vector-user-links',
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.
*
@ -78,6 +121,10 @@ function makeStickyHeaderFunctional(
// Clone the updated user menu to the sticky header.
userMenuStickyContainerInner.appendChild( userMenuClone );
prepareIcons( header,
document.querySelector( '#ca-history a' ),
document.querySelector( '#ca-talk a' )
);
stickyObserver.observe( stickyIntersection );
}

View File

@ -164,6 +164,18 @@
"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": {
"selectorWithVariant": ".mw-ui-icon-wikimedia-{name}-{variant}:before",
"selectorWithoutVariant": ".mw-ui-icon-wikimedia-{name}:before",
@ -205,6 +217,7 @@
"resources/skins.vector.js/searchToggle.js"
],
"dependencies": [
"skins.vector.icons.js",
"mediawiki.page.ready",
"mediawiki.util"
],