Debian Codegraph @

extensions/VisualEditor/modules/ve-mw-collab/ve.init.mw.DesktopCollabTarget.js

raw symbols SCIP
1 /*!
2 * VisualEditor MediaWiki Initialization DesktopCollabTarget class.
3 *
4 * @copyright See AUTHORS.txt
5 * @license The MIT License (MIT); see LICENSE.txt
6 */
7
8 /* eslint-disable no-jquery/no-global-selector */
9
10 /**
11 * MediaWiki mobile article target.
12 *
13 * @class
14 * @extends ve.init.mw.Target
15 *
16 * @constructor
17 * @param {mw.Title} title Page sub-title
18 * @param {string} rebaserUrl Rebaser server URL
19 * @param {Object} [config] Configuration options
20 * @param {mw.Title} [config.importTitle] Title to import
21 */
22 ve.init.mw.DesktopCollabTarget = function VeInitMwDesktopCollabTarget( title, rebaserUrl, config ) {
23 // Parent constructor
24 ve.init.mw.DesktopCollabTarget.super.call( this, title, rebaserUrl, config );
25
26 this.$originalContent = $( '<div>' ).addClass( 've-init-mw-desktopArticleTarget-originalContent' );
27 this.$editableContent = $( '#mw-content-text' );
28
29 // Initialization
30 this.$element.addClass( 've-init-mw-desktopArticleTarget' ).append( this.$originalContent );
31 };
32
33 /* Inheritance */
34
35 OO.inheritClass( ve.init.mw.DesktopCollabTarget, ve.init.mw.CollabTarget );
36
37 /* Methods */
38
39 /**
40 * Page modifications after editor load.
41 */
42 ve.init.mw.DesktopCollabTarget.prototype.transformPage = function () {
43 this.$originalContent.append( this.$element.siblings() );
44 let title;
45 if ( ( title = this.getImportTitle() ) ) {
46 // ve.htmlMsg returns `Node[]`
47 // eslint-disable-next-line no-jquery/no-html
48 $( '#contentSub' ).html(
49 ve.htmlMsg(
50 'collabpad-import-subtitle',
51 $( '<a>' ).attr( 'href', title.getUrl() ).text( title.getMainText() )
52 )
53 );
54 ve.targetLinksToNewWindow( $( '#contentSub' )[ 0 ] );
55 } else {
56 $( '#contentSub' ).empty();
57 }
58 };
59
60 /**
61 * Page modifications after editor teardown.
62 */
63 ve.init.mw.DesktopCollabTarget.prototype.restorePage = function () {
64 this.$element.parent().append( this.$originalContent.children() );
65 $( '#contentSub' ).empty();
66 };
67
68 /**
69 * @inheritdoc
70 */
71 ve.init.mw.DesktopCollabTarget.prototype.attachToolbar = function () {
72 const toolbar = this.getToolbar();
73
74 // Parent method
75 ve.init.mw.DesktopCollabTarget.super.prototype.attachToolbar.apply( this, arguments );
76
77 toolbar.$element.addClass(
78 've-init-mw-desktopArticleTarget-toolbar ve-init-mw-desktopArticleTarget-toolbar-open'
79 );
80 this.$element.prepend( toolbar.$element );
81 };
82
83 /**
84 * @inheritdoc
85 */
86 ve.init.mw.DesktopCollabTarget.prototype.setSurface = function ( surface ) {
87 if ( surface !== this.surface ) {
88 this.$editableContent.after( surface.$element );
89 }
90
91 // Parent method
92 ve.init.mw.DesktopCollabTarget.super.prototype.setSurface.apply( this, arguments );
93 };
94
95 /* Registration */
96
97 ve.init.mw.targetFactory.register( ve.init.mw.DesktopCollabTarget );