2024-05-24 12:31:30 +00:00
|
|
|
const
|
2022-02-19 04:03:09 +00:00
|
|
|
// LanguageData::getLocalData()
|
2021-07-22 20:20:16 +00:00
|
|
|
parserData = require( './parser/data.json' ),
|
2021-06-24 16:21:31 +00:00
|
|
|
utils = require( './utils.js' );
|
2022-07-30 22:02:17 +00:00
|
|
|
|
2024-05-24 12:31:30 +00:00
|
|
|
const featuresEnabled = mw.config.get( 'wgDiscussionToolsFeaturesEnabled' ) || {};
|
2021-06-24 16:21:31 +00:00
|
|
|
|
2024-02-20 00:57:43 +00:00
|
|
|
function tryInfuse( $element ) {
|
|
|
|
if ( $element.length ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
let element = null;
|
2024-02-20 00:57:43 +00:00
|
|
|
// $.data() might have already been cleared by jQuery if the elements were removed, ignore
|
|
|
|
// TODO: We should keep references to the OO.ui.ButtonWidget objects instead of infusing again,
|
|
|
|
// which would avoid this issue too
|
|
|
|
try {
|
|
|
|
element = OO.ui.infuse( $element );
|
|
|
|
} catch ( e ) {}
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-06-24 16:21:31 +00:00
|
|
|
function ReplyLinksController( $pageContainer ) {
|
|
|
|
// Mixin constructors
|
|
|
|
OO.EventEmitter.call( this );
|
|
|
|
|
|
|
|
this.$pageContainer = $pageContainer;
|
2021-06-24 19:10:40 +00:00
|
|
|
this.$body = $( document.body );
|
2021-06-24 16:21:31 +00:00
|
|
|
this.onReplyLinkClickHandler = this.onReplyLinkClick.bind( this );
|
2022-08-01 20:43:05 +00:00
|
|
|
this.onReplyButtonClickHandler = this.onReplyButtonClick.bind( this );
|
2021-06-24 16:21:31 +00:00
|
|
|
this.onAddSectionLinkClickHandler = this.onAddSectionLinkClick.bind( this );
|
2021-06-24 19:10:40 +00:00
|
|
|
this.onAnyLinkClickHandler = this.onAnyLinkClick.bind( this );
|
2021-06-24 16:21:31 +00:00
|
|
|
|
2022-08-01 20:43:05 +00:00
|
|
|
// Reply links
|
2024-02-20 00:57:43 +00:00
|
|
|
this.$replyLinkSets = $pageContainer.find( '.ext-discussiontools-init-replylink-buttons[ data-mw-thread-id ]:not( :empty )' );
|
2022-08-01 20:43:05 +00:00
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$replyLinkSets.each( ( i, replyLinkContainer ) => {
|
2024-05-24 12:20:50 +00:00
|
|
|
const replyButton = tryInfuse( $( replyLinkContainer ).find( '.ext-discussiontools-init-replybutton' ) );
|
|
|
|
const $replyLink = $( replyLinkContainer ).find( '.ext-discussiontools-init-replylink-reply' );
|
2024-04-18 18:37:58 +00:00
|
|
|
$replyLink.on( 'click keypress', this.onReplyLinkClickHandler );
|
2024-02-20 00:57:43 +00:00
|
|
|
if ( replyButton ) {
|
2024-04-18 18:37:58 +00:00
|
|
|
replyButton.on( 'click', this.onReplyButtonClickHandler, [ replyButton ] );
|
2024-02-20 00:57:43 +00:00
|
|
|
}
|
2022-08-01 20:43:05 +00:00
|
|
|
} );
|
2022-04-21 13:08:59 +00:00
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$replyLinkSets.on( 'focusin mouseover touchstart', () => {
|
|
|
|
this.emit( 'link-interact' );
|
2023-01-05 22:47:36 +00:00
|
|
|
} );
|
|
|
|
|
2021-06-24 16:21:31 +00:00
|
|
|
// "Add topic" link in the skin interface
|
2021-10-13 19:59:47 +00:00
|
|
|
if ( featuresEnabled.newtopictool ) {
|
2021-06-24 16:21:31 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2024-05-24 12:20:50 +00:00
|
|
|
const $addSectionTab = $( '#ca-addsection' );
|
2021-07-29 06:12:10 +00:00
|
|
|
if ( $addSectionTab.length ) {
|
2021-06-24 16:21:31 +00:00
|
|
|
this.$addSectionLink = $addSectionTab.find( 'a' );
|
|
|
|
this.$addSectionLink.on( 'click keypress', this.onAddSectionLinkClickHandler );
|
2023-01-05 22:47:36 +00:00
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$addSectionLink.on( 'focusin mouseover touchstart', () => {
|
|
|
|
this.emit( 'link-interact' );
|
2023-01-05 22:47:36 +00:00
|
|
|
} );
|
2021-06-24 16:21:31 +00:00
|
|
|
}
|
2021-04-29 14:24:49 +00:00
|
|
|
// Handle events on all links that potentially open the new section interface,
|
|
|
|
// including links in the page content (from templates) or from gadgets.
|
2022-08-01 20:43:05 +00:00
|
|
|
this.$body.on( 'click keypress', 'a', this.onAnyLinkClickHandler );
|
2021-06-24 16:21:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OO.initClass( ReplyLinksController );
|
|
|
|
OO.mixinClass( ReplyLinksController, OO.EventEmitter );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event link-click
|
|
|
|
* @param {string} id
|
2022-08-01 20:43:05 +00:00
|
|
|
* @param {jQuery} $linkSet
|
2021-06-29 15:35:37 +00:00
|
|
|
* @param {jQuery} $link
|
|
|
|
* @param {Object} [data]
|
2021-06-24 16:21:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.onReplyLinkClick = function ( e ) {
|
|
|
|
if ( !this.isActivationEvent( e ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
|
2021-09-30 20:53:50 +00:00
|
|
|
// Browser plugins (such as Google Translate) may add extra tags inside
|
|
|
|
// the link, so find the containing link tag with the data we need.
|
2024-05-24 12:20:50 +00:00
|
|
|
const $linkSet = $( e.target ).closest( '[data-mw-thread-id]' );
|
2022-08-01 20:43:05 +00:00
|
|
|
if ( !$linkSet.length ) {
|
2021-09-30 20:53:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-12 15:22:50 +00:00
|
|
|
this.emit( 'link-click', $linkSet.data( 'mw-thread-id' ), $linkSet );
|
2022-08-01 20:43:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.onReplyButtonClick = function ( button ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const $linkSet = button.$element.closest( '[data-mw-thread-id]' );
|
2022-10-12 15:22:50 +00:00
|
|
|
this.emit( 'link-click', $linkSet.data( 'mw-thread-id' ), $linkSet );
|
2021-06-24 16:21:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.onAddSectionLinkClick = function ( e ) {
|
|
|
|
if ( !this.isActivationEvent( e ) ) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-30 16:00:34 +00:00
|
|
|
// Disable VisualEditor's new section editor (in wikitext mode / NWE), to allow our own.
|
|
|
|
// We do this on first click, because we don't control the order in which our code and NWE code
|
|
|
|
// runs, so its event handlers may not be registered yet.
|
|
|
|
$( e.target ).closest( '#ca-addsection' ).off( '.ve-target' );
|
|
|
|
|
2021-06-24 19:10:40 +00:00
|
|
|
// onAnyLinkClick() will also handle clicks on this element, so we don't emit() here to avoid
|
|
|
|
// doing it twice.
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.onAnyLinkClick = function ( e ) {
|
2022-10-12 15:22:50 +00:00
|
|
|
if ( $( e.currentTarget ).closest( '[data-mw-thread-id]' ).length ) {
|
2022-08-01 20:43:05 +00:00
|
|
|
// Handled elsewhere
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-24 19:10:40 +00:00
|
|
|
// Check query parameters to see if this is really a new topic link
|
2024-05-24 12:20:50 +00:00
|
|
|
const href = e.currentTarget.href;
|
2022-03-29 21:25:21 +00:00
|
|
|
if ( !href ) {
|
2021-06-24 19:10:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-06-29 15:35:37 +00:00
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
const data = this.parseNewTopicLink( href );
|
2021-06-29 15:35:37 +00:00
|
|
|
if ( !data ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !this.isActivationEvent( e ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this.emit( 'link-click', utils.NEW_TOPIC_COMMENT_ID, $( e.currentTarget ), data );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the given URL is a new topic link, and if so, return parsed parameters.
|
|
|
|
*
|
|
|
|
* @param {string} href
|
|
|
|
* @return {Object|null} `null` if not a new topic link, parameters otherwise
|
|
|
|
*/
|
|
|
|
ReplyLinksController.prototype.parseNewTopicLink = function ( href ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const searchParams = new URL( href ).searchParams;
|
2021-07-22 20:20:16 +00:00
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
let title = mw.Title.newFromText( utils.getTitleFromUrl( href ) || '' );
|
2021-07-22 20:20:16 +00:00
|
|
|
if ( !title ) {
|
2021-06-29 15:35:37 +00:00
|
|
|
return null;
|
2021-07-22 20:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Recognize links to add a new topic:
|
|
|
|
if (
|
|
|
|
// Special:NewSection/...
|
|
|
|
title.getNamespaceId() === mw.config.get( 'wgNamespaceIds' ).special &&
|
|
|
|
title.getMainText().split( '/' )[ 0 ] === parserData.specialNewSectionName
|
|
|
|
) {
|
|
|
|
// Get the real title from the subpage parameter
|
2024-05-24 12:20:50 +00:00
|
|
|
const param = title.getMainText().slice( parserData.specialNewSectionName.length + 1 );
|
2021-07-22 20:20:16 +00:00
|
|
|
title = mw.Title.newFromText( param );
|
|
|
|
if ( !title ) {
|
2021-06-29 15:35:37 +00:00
|
|
|
return null;
|
2021-07-22 20:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} else if (
|
|
|
|
// ?title=...&action=edit§ion=new
|
|
|
|
// ?title=...&veaction=editsource§ion=new
|
2024-03-25 18:33:16 +00:00
|
|
|
( searchParams.get( 'action' ) === 'edit' || searchParams.get( 'veaction' ) === 'editsource' ) &&
|
|
|
|
searchParams.get( 'section' ) === 'new' &&
|
|
|
|
searchParams.get( 'dtenable' ) !== '0'
|
2021-07-22 20:20:16 +00:00
|
|
|
) {
|
|
|
|
// Do nothing
|
|
|
|
|
|
|
|
} else {
|
2021-06-24 19:10:40 +00:00
|
|
|
// Not a link to add a new topic
|
2021-06-29 15:35:37 +00:00
|
|
|
return null;
|
2021-06-24 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
2021-07-22 20:20:16 +00:00
|
|
|
if ( title.getPrefixedDb() !== mw.config.get( 'wgRelevantPageName' ) ) {
|
2021-06-24 19:10:40 +00:00
|
|
|
// Link to add a section on another page, not supported yet (T282205)
|
2021-06-29 15:35:37 +00:00
|
|
|
return null;
|
2021-06-24 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
const data = {};
|
2024-03-25 18:33:16 +00:00
|
|
|
if ( searchParams.get( 'editintro' ) ) {
|
|
|
|
data.editintro = searchParams.get( 'editintro' );
|
2021-06-29 15:35:37 +00:00
|
|
|
}
|
2024-03-25 18:33:16 +00:00
|
|
|
if ( searchParams.get( 'preload' ) ) {
|
|
|
|
data.preload = searchParams.get( 'preload' );
|
2021-06-29 15:35:37 +00:00
|
|
|
}
|
2024-03-25 18:33:16 +00:00
|
|
|
if ( mw.util.getArrayParam( 'preloadparams', searchParams ) ) {
|
|
|
|
data.preloadparams = mw.util.getArrayParam( 'preloadparams', searchParams );
|
2021-06-29 15:35:37 +00:00
|
|
|
}
|
2024-03-25 18:33:16 +00:00
|
|
|
if ( searchParams.get( 'preloadtitle' ) ) {
|
|
|
|
data.preloadtitle = searchParams.get( 'preloadtitle' );
|
2021-06-24 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 15:35:37 +00:00
|
|
|
// Handle new topic with preloaded text only when requested (T269310)
|
2024-03-25 18:33:16 +00:00
|
|
|
if ( !searchParams.get( 'dtpreload' ) && !$.isEmptyObject( data ) ) {
|
2021-06-29 15:35:37 +00:00
|
|
|
return null;
|
2021-06-24 19:10:40 +00:00
|
|
|
}
|
|
|
|
|
2021-06-29 15:35:37 +00:00
|
|
|
return data;
|
2021-06-24 16:21:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.isActivationEvent = function ( e ) {
|
2022-06-01 21:43:42 +00:00
|
|
|
if ( mw.config.get( 'wgAction' ) !== 'view' ) {
|
|
|
|
// Don't do anything when we're editing/previewing
|
|
|
|
return false;
|
|
|
|
}
|
2021-06-24 16:21:31 +00:00
|
|
|
if ( e.type === 'keypress' && e.which !== OO.ui.Keys.ENTER && e.which !== OO.ui.Keys.SPACE ) {
|
|
|
|
// Only handle keypresses on the "Enter" or "Space" keys
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-06 23:38:53 +00:00
|
|
|
if ( e.type === 'click' && !utils.isUnmodifiedLeftClick( e ) ) {
|
2021-06-24 16:21:31 +00:00
|
|
|
// Only handle unmodified left clicks
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-08-01 20:43:05 +00:00
|
|
|
ReplyLinksController.prototype.focusLink = function ( $linkSet ) {
|
|
|
|
if ( $linkSet.is( this.$replyLinkSets ) ) {
|
2024-05-24 12:20:50 +00:00
|
|
|
const button = tryInfuse( $linkSet.find( '.ext-discussiontools-init-replybutton' ) );
|
2022-08-01 20:43:05 +00:00
|
|
|
// Focus whichever is visible, the link or the button
|
2024-02-20 00:57:43 +00:00
|
|
|
if ( button ) {
|
|
|
|
button.focus();
|
|
|
|
}
|
2022-08-01 20:43:05 +00:00
|
|
|
$linkSet.find( '.ext-discussiontools-init-replylink-reply' ).trigger( 'focus' );
|
2021-06-24 16:21:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-08-01 20:43:05 +00:00
|
|
|
ReplyLinksController.prototype.setActiveLink = function ( $linkSet ) {
|
|
|
|
this.$activeLink = $linkSet;
|
2021-06-24 16:21:31 +00:00
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
let isNewTopic = false;
|
|
|
|
let activeButton;
|
2022-08-01 20:43:05 +00:00
|
|
|
if ( this.$activeLink.is( this.$replyLinkSets ) ) {
|
|
|
|
this.$activeLink.addClass( 'ext-discussiontools-init-replylink-active' );
|
2024-02-20 00:57:43 +00:00
|
|
|
activeButton = tryInfuse( this.$activeLink.find( '.ext-discussiontools-init-replybutton' ) );
|
2021-07-28 10:36:58 +00:00
|
|
|
} else if ( this.$addSectionLink && this.$activeLink.is( this.$addSectionLink ) ) {
|
2022-08-09 12:54:55 +00:00
|
|
|
isNewTopic = true;
|
2021-07-28 10:36:58 +00:00
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#ca-addsection' ).addClass( 'selected' );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2022-08-01 21:19:14 +00:00
|
|
|
$( '#ca-addsection-sticky-header' ).addClass( 'ext-discussiontools-fake-disabled' );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2021-07-28 10:36:58 +00:00
|
|
|
$( '#ca-view' ).removeClass( 'selected' );
|
2021-06-24 16:21:31 +00:00
|
|
|
}
|
|
|
|
|
2024-05-24 12:20:50 +00:00
|
|
|
const title = mw.Title.newFromText( mw.config.get( 'wgRelevantPageName' ) );
|
|
|
|
const pageTitleMsg = mw.message( 'pagetitle',
|
2022-08-09 12:54:55 +00:00
|
|
|
mw.msg(
|
|
|
|
isNewTopic ?
|
|
|
|
'discussiontools-pagetitle-newtopic' :
|
|
|
|
'discussiontools-pagetitle-reply',
|
|
|
|
title.getPrefixedText()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2023-05-31 21:49:15 +00:00
|
|
|
// T317600
|
|
|
|
if ( pageTitleMsg.isParseable() ) {
|
|
|
|
this.originalDocumentTitle = document.title;
|
|
|
|
document.title = pageTitleMsg.text();
|
|
|
|
} else {
|
|
|
|
mw.log.warn( 'DiscussionTools: MediaWiki:Pagetitle contains unsupported syntax. ' +
|
|
|
|
'https://www.mediawiki.org/wiki/Manual:Messages_API#Feature_support_in_JavaScript' );
|
|
|
|
}
|
|
|
|
|
2022-11-01 13:55:01 +00:00
|
|
|
$( document.body ).addClass( 'ext-discussiontools-init-replylink-open' );
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$replyLinkSets.each( ( i, replyLinkContainer ) => {
|
2024-05-24 12:20:50 +00:00
|
|
|
const replyButton = tryInfuse( $( replyLinkContainer ).find( '.ext-discussiontools-init-replybutton' ) );
|
|
|
|
const $replyLink = $( replyLinkContainer ).find( '.ext-discussiontools-init-replylink-reply' );
|
2022-08-01 20:43:05 +00:00
|
|
|
$replyLink.attr( 'tabindex', -1 );
|
2024-02-20 00:57:43 +00:00
|
|
|
if ( !replyButton ) {
|
|
|
|
return;
|
|
|
|
}
|
2022-08-01 21:27:18 +00:00
|
|
|
if ( replyButton === activeButton ) {
|
|
|
|
replyButton.setFlags( { progressive: false } );
|
|
|
|
} else {
|
|
|
|
replyButton.setDisabled( true );
|
|
|
|
}
|
2021-06-24 16:21:31 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// Suppress page takeover behavior for VE editing so that our unload
|
|
|
|
// handler can warn of data loss.
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#ca-edit, #ca-ve-edit, .mw-editsection a, #ca-addsection' ).off( '.ve-target' );
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.clearActiveLink = function () {
|
2024-05-24 12:20:50 +00:00
|
|
|
let activeButton;
|
2022-08-01 20:43:05 +00:00
|
|
|
if ( this.$activeLink.is( this.$replyLinkSets ) ) {
|
|
|
|
this.$activeLink.removeClass( 'ext-discussiontools-init-replylink-active' );
|
2024-02-20 00:57:43 +00:00
|
|
|
activeButton = tryInfuse( this.$activeLink.find( '.ext-discussiontools-init-replybutton' ) );
|
2021-07-28 10:36:58 +00:00
|
|
|
} else if ( this.$addSectionLink && this.$activeLink.is( this.$addSectionLink ) ) {
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
|
|
|
$( '#ca-addsection' ).removeClass( 'selected' );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2022-08-01 21:19:14 +00:00
|
|
|
$( '#ca-addsection-sticky-header' ).removeClass( 'ext-discussiontools-fake-disabled' );
|
|
|
|
// eslint-disable-next-line no-jquery/no-global-selector
|
2021-07-28 10:36:58 +00:00
|
|
|
$( '#ca-view' ).addClass( 'selected' );
|
2021-06-24 16:21:31 +00:00
|
|
|
}
|
|
|
|
|
2022-08-09 12:54:55 +00:00
|
|
|
if ( this.originalDocumentTitle ) {
|
|
|
|
document.title = this.originalDocumentTitle;
|
|
|
|
}
|
|
|
|
|
2022-11-01 13:55:01 +00:00
|
|
|
$( document.body ).removeClass( 'ext-discussiontools-init-replylink-open' );
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$replyLinkSets.each( ( i, replyLinkContainer ) => {
|
2024-05-24 12:20:50 +00:00
|
|
|
const $replyLink = $( replyLinkContainer ).find( '.ext-discussiontools-init-replylink-reply' );
|
2022-08-01 20:43:05 +00:00
|
|
|
$replyLink.attr( 'tabindex', 0 );
|
2024-05-24 12:20:50 +00:00
|
|
|
const replyButton = tryInfuse( $( replyLinkContainer ).find( '.ext-discussiontools-init-replybutton' ) );
|
2024-02-20 00:57:43 +00:00
|
|
|
if ( !replyButton ) {
|
2023-02-13 14:46:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-01 21:27:18 +00:00
|
|
|
if ( replyButton === activeButton ) {
|
|
|
|
replyButton.setFlags( { progressive: true } );
|
|
|
|
} else {
|
|
|
|
replyButton.setDisabled( false );
|
|
|
|
}
|
2021-06-24 16:21:31 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
// We deliberately mangled edit links earlier so VE can't steal our page;
|
|
|
|
// have it redo setup to fix those.
|
|
|
|
if ( mw.libs.ve && mw.libs.ve.setupEditLinks ) {
|
|
|
|
mw.libs.ve.setupEditLinks();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$activeLink = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.teardown = function () {
|
|
|
|
if ( this.$activeLink ) {
|
|
|
|
this.clearActiveLink();
|
|
|
|
}
|
|
|
|
|
2024-04-18 18:37:58 +00:00
|
|
|
this.$replyLinkSets.each( ( i, replyLinkContainer ) => {
|
2024-05-24 12:20:50 +00:00
|
|
|
const replyButton = tryInfuse( $( replyLinkContainer ).find( '.ext-discussiontools-init-replybutton' ) );
|
2024-02-20 00:57:43 +00:00
|
|
|
if ( replyButton ) {
|
2024-04-18 18:37:58 +00:00
|
|
|
replyButton.off( 'click', this.onReplyButtonClickHandler );
|
2023-01-24 15:34:35 +00:00
|
|
|
}
|
2024-05-24 12:20:50 +00:00
|
|
|
const $replyLink = $( this ).find( '.ext-discussiontools-init-replylink-reply' );
|
2024-04-18 18:37:58 +00:00
|
|
|
$replyLink.off( 'click keypress', this.onReplyLinkClickHandler );
|
2022-08-01 20:43:05 +00:00
|
|
|
} );
|
|
|
|
|
2021-11-05 19:20:42 +00:00
|
|
|
if ( featuresEnabled.newtopictool ) {
|
|
|
|
if ( this.$addSectionLink ) {
|
|
|
|
this.$addSectionLink.off( 'click keypress', this.onAddSectionLinkClickHandler );
|
|
|
|
}
|
2022-08-01 20:43:05 +00:00
|
|
|
this.$body.off( 'click keypress', 'a', this.onAnyLinkClickHandler );
|
2021-07-20 20:32:25 +00:00
|
|
|
}
|
2021-06-24 16:21:31 +00:00
|
|
|
};
|
|
|
|
|
2023-05-21 06:57:49 +00:00
|
|
|
ReplyLinksController.prototype.pageHasReplyLinks = function () {
|
|
|
|
return this.$replyLinkSets.length > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
ReplyLinksController.prototype.pageHasNewTopicLink = function () {
|
|
|
|
// Note: this will miss if there are random on-page links that would
|
|
|
|
// trigger the new topic tool via onAnyLinkClick
|
|
|
|
return featuresEnabled.newtopictool && document.getElementById( 'ca-addsection' );
|
|
|
|
};
|
|
|
|
|
2021-06-24 16:21:31 +00:00
|
|
|
module.exports = ReplyLinksController;
|