mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/DiscussionTools
synced 2024-11-27 17:51:09 +00:00
topicsubscriptions.js: No longer assume both buttons and links exist in DOM
Bug: T360942 Bug: T359751 Change-Id: I98d50a734dc9bd37d7d488ed97d5a47e65790587
This commit is contained in:
parent
30d911b649
commit
eb92db2b08
|
@ -166,7 +166,9 @@ function initTopicSubscriptions( $container, threadItemSet ) {
|
|||
buttonsByName[ name ] = button;
|
||||
|
||||
// Restore data attribute
|
||||
if ( subscribedStateTemp !== null ) {
|
||||
button.$element[ 0 ].setAttribute( 'data-mw-subscribed', String( subscribedStateTemp ) );
|
||||
}
|
||||
|
||||
var title = mw.config.get( 'wgRelevantPageName' ) + '#' + headingItem.getLinkableTitle();
|
||||
|
||||
|
@ -426,17 +428,20 @@ function updateSubscriptionStates( $container, headingsToUpdate ) {
|
|||
for ( var headingName in headingsToUpdate ) {
|
||||
var link = linksByName[ headingName ];
|
||||
var button = buttonsByName[ headingName ];
|
||||
// We can get the subscription state from the link or the button
|
||||
var subscribedState = getSubscribedStateFromElement( link );
|
||||
var subscribedState = getSubscribedStateFromElement( link || button.$element[ 0 ] );
|
||||
|
||||
if ( subscribedState === STATE_AUTOSUBSCRIBED ) {
|
||||
maybeShowFirstTimeAutoTopicSubPopup();
|
||||
} else if ( subscribedState === null || subscribedState === STATE_UNSUBSCRIBED ) {
|
||||
topicsToCheck.push( headingName );
|
||||
if ( link ) {
|
||||
pendingLinks.push( link );
|
||||
}
|
||||
if ( button ) {
|
||||
pendingButtons.push( button );
|
||||
}
|
||||
}
|
||||
}
|
||||
$( pendingLinks ).addClass( 'ext-discussiontools-init-section-subscribe-link-pending' );
|
||||
pendingButtons.forEach( function ( b ) {
|
||||
b.setDisabled( true );
|
||||
|
@ -469,8 +474,12 @@ function updateSubscriptionStates( $container, headingsToUpdate ) {
|
|||
// Update state of each topic for which there is a subscription
|
||||
for ( var subItemName in response.subscriptions ) {
|
||||
var state = response.subscriptions[ subItemName ];
|
||||
if ( linksByName[ subItemName ] ) {
|
||||
updateSubscribeLink( linksByName[ subItemName ], state );
|
||||
}
|
||||
if ( buttonsByName[ subItemName ] ) {
|
||||
updateSubscribeButton( buttonsByName[ subItemName ], state );
|
||||
}
|
||||
if ( state === STATE_AUTOSUBSCRIBED ) {
|
||||
maybeShowFirstTimeAutoTopicSubPopup();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue