JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/*!
|
2015-07-29 13:41:30 +00:00
|
|
|
* VisualEditor MediaWiki Initialization DesktopArticleTarget class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2014-07-19 17:41:06 +00:00
|
|
|
/*global confirm, alert */
|
2013-01-22 22:41:22 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* MediaWiki desktop article target.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @class
|
2015-12-10 16:07:50 +00:00
|
|
|
* @extends ve.init.mw.ArticleTarget
|
2013-02-20 19:44:44 +00:00
|
|
|
*
|
2012-06-11 06:54:41 +00:00
|
|
|
* @constructor
|
2015-07-30 09:32:40 +00:00
|
|
|
* @param {Object} config Configuration options
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-07-30 09:32:40 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget = function VeInitMwDesktopArticleTarget( config ) {
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
// A workaround, as default URI does not get updated after pushState (bug 72334)
|
|
|
|
var currentUri = new mw.Uri( location.href );
|
2012-08-23 19:01:07 +00:00
|
|
|
|
2012-09-17 23:53:03 +00:00
|
|
|
// Parent constructor
|
2015-07-30 09:32:40 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.call(
|
|
|
|
this, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid, config
|
|
|
|
);
|
2012-06-11 06:54:41 +00:00
|
|
|
|
2014-12-12 02:18:46 +00:00
|
|
|
// Parent constructor bound key event handlers, but we don't want them bound until
|
|
|
|
// we activate; so unbind them again
|
|
|
|
this.unbindHandlers();
|
|
|
|
|
2015-02-05 00:05:56 +00:00
|
|
|
this.onWatchToggleHandler = this.onWatchToggle.bind( this );
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Properties
|
2012-06-21 03:16:10 +00:00
|
|
|
this.onBeforeUnloadFallback = null;
|
2014-12-02 23:21:50 +00:00
|
|
|
this.onUnloadHandler = this.onUnload.bind( this );
|
2012-06-11 06:54:41 +00:00
|
|
|
this.active = false;
|
2013-12-03 02:21:31 +00:00
|
|
|
this.activating = false;
|
|
|
|
this.deactivating = false;
|
2012-06-12 17:32:10 +00:00
|
|
|
this.edited = false;
|
2014-10-30 00:36:02 +00:00
|
|
|
this.recreating = false;
|
2015-02-23 08:44:51 +00:00
|
|
|
this.activatingDeferred = null;
|
|
|
|
this.toolbarSetupDeferred = null;
|
2015-08-13 16:39:24 +00:00
|
|
|
this.checkboxFields = null;
|
|
|
|
this.checkboxesByName = null;
|
|
|
|
this.$otherFields = null;
|
2016-03-15 01:10:51 +00:00
|
|
|
this.suppressNormalStartupDialogs = false;
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2013-06-05 22:39:43 +00:00
|
|
|
// If this is true then #transformPage / #restorePage will not call pushState
|
|
|
|
// This is to avoid adding a new history entry for the url we just got from onpopstate
|
|
|
|
// (which would mess up with the expected order of Back/Forwards browsing)
|
|
|
|
this.actFromPopState = false;
|
2014-03-12 21:26:52 +00:00
|
|
|
this.popState = {
|
|
|
|
tag: 'visualeditor'
|
|
|
|
};
|
2012-06-18 20:12:32 +00:00
|
|
|
this.scrollTop = null;
|
2012-08-23 19:01:07 +00:00
|
|
|
this.currentUri = currentUri;
|
2014-02-06 23:13:32 +00:00
|
|
|
this.section = currentUri.query.vesection;
|
2016-03-02 11:55:50 +00:00
|
|
|
if ( $( '#wpSummary' ).length ) {
|
|
|
|
this.initialEditSummary = $( '#wpSummary' ).val();
|
|
|
|
} else {
|
|
|
|
this.initialEditSummary = currentUri.query.summary;
|
|
|
|
}
|
2012-06-19 04:47:09 +00:00
|
|
|
this.namespaceName = mw.config.get( 'wgCanonicalNamespace' );
|
2013-11-07 22:21:08 +00:00
|
|
|
this.viewUri = new mw.Uri( mw.util.getUrl( this.pageName ) );
|
2012-06-18 23:18:48 +00:00
|
|
|
this.isViewPage = (
|
|
|
|
mw.config.get( 'wgAction' ) === 'view' &&
|
2012-08-23 19:01:07 +00:00
|
|
|
currentUri.query.diff === undefined
|
2012-06-18 23:18:48 +00:00
|
|
|
);
|
2013-05-17 16:09:20 +00:00
|
|
|
this.originalDocumentTitle = document.title;
|
2013-06-03 22:23:45 +00:00
|
|
|
this.tabLayout = mw.config.get( 'wgVisualEditorConfig' ).tabLayout;
|
2015-12-10 16:07:50 +00:00
|
|
|
this.events = new ve.init.mw.ArticleTargetEvents( this );
|
2012-06-18 20:12:32 +00:00
|
|
|
|
2015-07-30 09:32:40 +00:00
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-init-mw-desktopArticleTarget' );
|
|
|
|
|
2014-11-19 01:10:52 +00:00
|
|
|
if ( history.replaceState ) {
|
2015-06-15 11:45:26 +00:00
|
|
|
// We replace the current state with one that's marked with our tag. This way, when users
|
|
|
|
// use the Back button to exit the editor we can restore Read mode. This is because we want
|
|
|
|
// to ignore foreign states in onWindowPopState. Without this, the Read state is foreign.
|
|
|
|
// FIXME: There should be a much better solution than this.
|
2014-11-19 01:10:52 +00:00
|
|
|
history.replaceState( this.popState, document.title, currentUri );
|
2013-06-05 21:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setupSkinTabs();
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2014-11-25 01:44:24 +00:00
|
|
|
window.addEventListener( 'popstate', this.onWindowPopState.bind( this ) );
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
/* Inheritance */
|
|
|
|
|
2015-12-10 16:07:50 +00:00
|
|
|
OO.inheritClass( ve.init.mw.DesktopArticleTarget, ve.init.mw.ArticleTarget );
|
Object management: Object create/inherit/clone utilities
* For the most common case:
- replace ve.extendClass with ve.inheritClass (chose slightly
different names to detect usage of the old/new one, and I
like 'inherit' better).
- move it up to below the constructor, see doc block for why.
* Cases where more than 2 arguments were passed to
ve.extendClass are handled differently depending on the case.
In case of a longer inheritance tree, the other arguments
could be omitted (like in "ve.ce.FooBar, ve.FooBar,
ve.Bar". ve.ce.FooBar only needs to inherit from ve.FooBar,
because ve.ce.FooBar inherits from ve.Bar).
In the case of where it previously had two mixins with
ve.extendClass(), either one becomes inheritClass and one
a mixin, both to mixinClass().
No visible changes should come from this commit as the
instances still all have the same visible properties in the
end. No more or less than before.
* Misc.:
- Be consistent in calling parent constructors in the
same order as the inheritance.
- Add missing @extends and @param documentation.
- Replace invalid {Integer} type hint with {Number}.
- Consistent doc comments order:
@class, @abstract, @constructor, @extends, @params.
- Fix indentation errors
A fairly common mistake was a superfluous space before the
identifier on the assignment line directly below the
documentation comment.
$ ack "^ [^*]" --js modules/ve
- Typo "Inhertiance" -> "Inheritance".
- Replacing the other confusing comment "Inheritance" (inside
the constructor) with "Parent constructor".
- Add missing @abstract for ve.ui.Tool.
- Corrected ve.FormatDropdownTool to ve.ui.FormatDropdownTool.js
- Add function names to all @constructor functions. Now that we
have inheritance it is important and useful to have these
functions not be anonymous.
Example of debug shot: http://cl.ly/image/1j3c160w3D45
Makes the difference between
< documentNode;
> ve_dm_DocumentNode
...
: ve_dm_BranchNode
...
: ve_dm_Node
...
: ve_dm_Node
...
: Object
...
without names (current situation):
< documentNode;
> Object
...
: Object
...
: Object
...
: Object
...
: Object
...
though before this commit, it really looks like this
(flattened since ve.extendClass really did a mixin):
< documentNode;
> Object
...
...
...
Pattern in Sublime (case-sensitive) to find nameless
constructor functions:
"^ve\..*\.([A-Z])([^\.]+) = function \("
Change-Id: Iab763954fb8cf375900d7a9a92dec1c755d5407e
2012-09-05 06:07:47 +00:00
|
|
|
|
2015-05-09 13:47:10 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event deactivate
|
|
|
|
*/
|
|
|
|
|
2013-01-15 23:38:49 +00:00
|
|
|
/* Static Properties */
|
2012-06-11 06:54:41 +00:00
|
|
|
|
2015-12-11 16:42:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.actionGroups = [
|
|
|
|
{ include: [ 'help', 'notices' ] },
|
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
icon: 'menu',
|
|
|
|
title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
|
|
|
include: [ 'meta', 'settings', 'advancedSettings', 'categories', 'languages', 'findAndReplace' ]
|
|
|
|
},
|
|
|
|
{ include: [ 'editModeSource' ] }
|
|
|
|
];
|
|
|
|
|
2012-08-22 21:24:50 +00:00
|
|
|
/**
|
|
|
|
* Compatibility map used with jQuery.client to black-list incompatible browsers.
|
|
|
|
*
|
|
|
|
* @static
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @property
|
2012-08-22 21:24:50 +00:00
|
|
|
*/
|
2015-07-31 15:03:33 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.compatibility = {
|
2013-05-26 15:23:03 +00:00
|
|
|
// The key is the browser name returned by jQuery.client
|
|
|
|
// The value is either null (match all versions) or a list of tuples
|
|
|
|
// containing an inequality (<,>,<=,>=) and a version number
|
2014-08-22 20:50:48 +00:00
|
|
|
whitelist: {
|
2015-07-22 22:13:09 +00:00
|
|
|
firefox: [ [ '>=', 15 ] ],
|
|
|
|
iceweasel: [ [ '>=', 10 ] ],
|
|
|
|
safari: [ [ '>=', 7 ] ],
|
|
|
|
chrome: [ [ '>=', 19 ] ],
|
2016-03-01 19:46:29 +00:00
|
|
|
msie: [ [ '>=', 10 ] ],
|
|
|
|
edge: [ [ '>=', 12 ] ],
|
2015-07-22 22:13:09 +00:00
|
|
|
opera: [ [ '>=', 15 ] ]
|
2012-08-22 21:24:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-09-03 01:24:48 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.static.platformType = 'desktop';
|
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveWorkflowBegin
|
2014-10-29 01:19:52 +00:00
|
|
|
* Fired when user clicks the button to open the save dialog.
|
2013-12-10 01:39:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveWorkflowEnd
|
|
|
|
* Fired when user exits the save workflow
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveReview
|
|
|
|
* Fired when user initiates review changes in save workflow
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event saveInitiated
|
|
|
|
* Fired when user initiates saving of the document
|
|
|
|
*/
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2014-03-12 21:26:52 +00:00
|
|
|
/**
|
|
|
|
* Verify that a PopStateEvent correlates to a state we created.
|
|
|
|
*
|
|
|
|
* @param {Mixed} popState From PopStateEvent#state
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.verifyPopState = function ( popState ) {
|
2014-03-12 21:26:52 +00:00
|
|
|
return popState && popState.tag === 'visualeditor';
|
|
|
|
};
|
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupToolbar = function ( surface ) {
|
2015-02-23 08:44:51 +00:00
|
|
|
var toolbar,
|
|
|
|
wasSetup = !!this.toolbar,
|
|
|
|
target = this;
|
2015-02-21 10:42:58 +00:00
|
|
|
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.setupToolbar.enter' );
|
2014-12-16 21:14:01 +00:00
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2015-08-02 11:30:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.setupToolbar.call( this, surface );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2015-02-21 10:42:58 +00:00
|
|
|
toolbar = this.getToolbar();
|
2014-05-02 16:34:46 +00:00
|
|
|
|
2015-02-18 20:11:49 +00:00
|
|
|
ve.track( 'trace.setupToolbar.exit' );
|
2015-02-21 10:42:58 +00:00
|
|
|
if ( !wasSetup ) {
|
2015-02-23 08:44:51 +00:00
|
|
|
setTimeout( function () {
|
|
|
|
var height = toolbar.$bar.outerHeight();
|
|
|
|
toolbar.$element.css( 'height', height );
|
|
|
|
toolbar.$element.one( 'transitionend', function () {
|
|
|
|
// Clear to allow growth during use and when resizing window
|
|
|
|
toolbar.$element.css( 'height', '' );
|
|
|
|
target.toolbarSetupDeferred.resolve();
|
|
|
|
} );
|
|
|
|
} );
|
2015-02-18 20:11:49 +00:00
|
|
|
|
2015-03-07 18:02:06 +00:00
|
|
|
this.toolbarSetupDeferred.done( function () {
|
|
|
|
var surface = target.getSurface();
|
|
|
|
// Check the surface wasn't torn down while the toolbar was animating
|
|
|
|
if ( surface ) {
|
|
|
|
ve.track( 'trace.initializeToolbar.enter' );
|
|
|
|
target.getToolbar().initialize();
|
|
|
|
surface.getView().emit( 'position' );
|
|
|
|
surface.getContext().updateDimensions();
|
|
|
|
ve.track( 'trace.initializeToolbar.exit' );
|
2015-03-23 20:15:44 +00:00
|
|
|
ve.track( 'trace.activate.exit' );
|
2015-03-07 18:02:06 +00:00
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
2014-02-06 23:33:21 +00:00
|
|
|
};
|
|
|
|
|
2015-02-19 18:22:20 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.attachToolbar = function () {
|
2015-02-19 18:22:20 +00:00
|
|
|
// Move the toolbar to top of target, before heading etc.
|
|
|
|
// Avoid re-attaching as it breaks CSS animations
|
2015-02-23 08:44:51 +00:00
|
|
|
if ( !this.toolbar.$element.parent().is( this.$element ) ) {
|
|
|
|
this.toolbar.$element
|
|
|
|
// Set 0 before attach (expanded in #setupToolbar)
|
|
|
|
.css( 'height', '0' )
|
2015-07-30 11:08:56 +00:00
|
|
|
.addClass( 've-init-mw-desktopArticleTarget-toolbar' );
|
2015-02-23 08:44:51 +00:00
|
|
|
this.$element.prepend( this.toolbar.$element );
|
2015-02-19 18:22:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-05-15 19:56:13 +00:00
|
|
|
/**
|
|
|
|
* Set up notices for things like unknown browsers.
|
2014-12-16 21:14:01 +00:00
|
|
|
* Needs to be done on each activation because localNoticeMessages is cleared in clearState.
|
2014-05-15 19:56:13 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupLocalNoticeMessages = function () {
|
2014-05-15 19:56:13 +00:00
|
|
|
if ( mw.config.get( 'wgTranslatePageTranslation' ) === 'source' ) {
|
|
|
|
// Warn users if they're on a source of the Page Translation feature
|
|
|
|
this.localNoticeMessages.push( 'visualeditor-pagetranslationwarning' );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !(
|
|
|
|
'vewhitelist' in this.currentUri.query ||
|
2015-07-31 15:03:33 +00:00
|
|
|
$.client.test( this.constructor.static.compatibility.whitelist, null, true )
|
2014-05-15 19:56:13 +00:00
|
|
|
) ) {
|
|
|
|
// Show warning in unknown browsers that pass the support test
|
|
|
|
// Continue at own risk.
|
|
|
|
this.localNoticeMessages.push( 'visualeditor-browserwarning' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.loadSuccess = function ( response ) {
|
2015-10-23 16:29:56 +00:00
|
|
|
var $checkboxes, defaults, data, windowManager, editingTabDialog,
|
2015-08-19 18:05:01 +00:00
|
|
|
target = this;
|
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.loadSuccess.apply( this, arguments );
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
// Duplicate of this code in ve.init.mw.DesktopArticleTarget.init.js
|
|
|
|
if ( $( '#ca-edit' ).hasClass( 'visualeditor-showtabdialog' ) ) {
|
|
|
|
// Set up a temporary window manager
|
|
|
|
windowManager = new OO.ui.WindowManager();
|
|
|
|
$( 'body' ).append( windowManager.$element );
|
|
|
|
editingTabDialog = new mw.libs.ve.EditingTabDialog();
|
|
|
|
windowManager.addWindows( [ editingTabDialog ] );
|
|
|
|
windowManager.openWindow( editingTabDialog, { message: mw.msg(
|
2015-12-10 18:45:37 +00:00
|
|
|
'visualeditor-editingtabdialog-body'
|
2015-10-23 16:29:56 +00:00
|
|
|
) } )
|
|
|
|
.then( function ( opened ) { return opened; } )
|
|
|
|
.then( function ( closing ) { return closing; } )
|
|
|
|
.then( function ( data ) {
|
|
|
|
// Detach the temporary window manager
|
|
|
|
windowManager.destroy();
|
|
|
|
|
|
|
|
if ( data && data.action === 'prefer-wt' ) {
|
|
|
|
target.switchToWikitextEditor( true, false );
|
|
|
|
}
|
|
|
|
} );
|
2016-03-09 21:02:18 +00:00
|
|
|
|
|
|
|
// Pretend the user saw the welcome dialog before suppressing it.
|
|
|
|
if ( mw.user.isAnon() ) {
|
|
|
|
try {
|
|
|
|
localStorage.setItem( 've-beta-welcome-dialog', 1 );
|
|
|
|
} catch ( e ) {
|
|
|
|
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
|
|
|
}
|
2016-03-15 01:10:51 +00:00
|
|
|
this.suppressNormalStartupDialogs = true;
|
2015-10-23 16:29:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-19 18:05:01 +00:00
|
|
|
data = response ? response.visualeditor : {};
|
2015-08-13 16:39:24 +00:00
|
|
|
|
|
|
|
this.checkboxFields = [];
|
|
|
|
this.checkboxesByName = {};
|
|
|
|
this.$otherFields = $( [] );
|
2015-11-10 13:50:18 +00:00
|
|
|
if ( [ 'edit', 'submit' ].indexOf( mw.util.getParamValue( 'action' ) ) !== -1 ) {
|
|
|
|
$( '#content #firstHeading' ).text( mw.config.get( 'wgTitle' ) );
|
|
|
|
}
|
2015-08-13 16:39:24 +00:00
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
if ( data.checkboxes ) {
|
2015-08-13 16:39:24 +00:00
|
|
|
defaults = {
|
|
|
|
wpMinoredit: !!mw.user.options.get( 'minordefault' ),
|
|
|
|
wpWatchthis: !!mw.user.options.get( 'watchdefault' ) ||
|
|
|
|
( !!mw.user.options.get( 'watchcreations' ) && !this.pageExists ) ||
|
|
|
|
data.watched === ''
|
|
|
|
};
|
2016-03-02 11:55:50 +00:00
|
|
|
$( '.editCheckboxes input' ).each( function () {
|
|
|
|
defaults[ this.name ] = this.checked;
|
|
|
|
} );
|
2015-08-13 16:39:24 +00:00
|
|
|
|
|
|
|
$checkboxes = $( '<div>' ).html( ve.getObjectValues( data.checkboxes ).join( '' ) );
|
|
|
|
$checkboxes.find( 'input[type=checkbox]' ).each( function () {
|
|
|
|
var $label, title, checkbox,
|
|
|
|
$this = $( this ),
|
|
|
|
name = $this.attr( 'name' ),
|
|
|
|
id = $this.attr( 'id' );
|
|
|
|
|
|
|
|
if ( !name ) {
|
|
|
|
// This really shouldn't happen..
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Label with for=id
|
|
|
|
if ( id ) {
|
|
|
|
$label = $checkboxes.find( 'label[for=' + id + ']' );
|
|
|
|
}
|
|
|
|
// Label wrapped input
|
|
|
|
if ( !$label ) {
|
|
|
|
$label = $this.closest( 'label' );
|
|
|
|
}
|
|
|
|
if ( $label ) {
|
|
|
|
title = $label.attr( 'title' );
|
|
|
|
$label.find( 'a' ).attr( 'target', '_blank' );
|
|
|
|
}
|
|
|
|
checkbox = new OO.ui.CheckboxInputWidget( {
|
|
|
|
value: $this.attr( 'value' ),
|
2015-08-19 17:33:02 +00:00
|
|
|
selected: name && defaults[ name ]
|
2015-08-13 16:39:24 +00:00
|
|
|
} );
|
|
|
|
// HACK: CheckboxInputWidget doesn't support access keys
|
|
|
|
checkbox.$input.attr( 'accesskey', $( this ).attr( 'accesskey' ) );
|
|
|
|
target.checkboxFields.push(
|
|
|
|
new OO.ui.FieldLayout( checkbox, {
|
|
|
|
align: 'inline',
|
|
|
|
label: $label ? $label.contents() : undefined,
|
|
|
|
title: title
|
|
|
|
} )
|
|
|
|
);
|
2015-08-19 17:33:02 +00:00
|
|
|
target.checkboxesByName[ name ] = checkbox;
|
2015-08-13 16:39:24 +00:00
|
|
|
} );
|
|
|
|
this.$otherFields = $checkboxes.find( 'input[type!=checkbox]' );
|
2015-08-05 21:43:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-02-05 00:05:56 +00:00
|
|
|
/**
|
|
|
|
* Handle the watch button being toggled on/off.
|
2015-08-13 16:39:24 +00:00
|
|
|
*
|
2015-12-09 16:47:13 +00:00
|
|
|
* @param {jQuery.Event} e Event object which triggered the event
|
2015-02-05 00:05:56 +00:00
|
|
|
* @param {string} actionPerformed 'watch' or 'unwatch'
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onWatchToggle = function ( e, actionPerformed ) {
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( !this.active && !this.activating ) {
|
|
|
|
return;
|
|
|
|
}
|
2015-08-13 16:39:24 +00:00
|
|
|
if ( this.checkboxesByName.wpWatchthis ) {
|
|
|
|
this.checkboxesByName.wpWatchthis.setSelected(
|
|
|
|
!!mw.user.options.get( 'watchdefault' ) ||
|
|
|
|
( !!mw.user.options.get( 'watchcreations' ) && !this.pageExists ) ||
|
2015-02-05 00:05:56 +00:00
|
|
|
actionPerformed === 'watch'
|
|
|
|
);
|
2015-08-13 16:39:24 +00:00
|
|
|
}
|
2015-02-05 00:05:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.bindHandlers = function () {
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.bindHandlers.call( this );
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( this.onWatchToggleHandler ) {
|
|
|
|
$( '#ca-watch, #ca-unwatch' ).on( 'watchpage.mw', this.onWatchToggleHandler );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.unbindHandlers = function () {
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.unbindHandlers.call( this );
|
2015-02-05 00:05:56 +00:00
|
|
|
if ( this.onWatchToggleHandler ) {
|
|
|
|
$( '#ca-watch, #ca-unwatch' ).off( 'watchpage.mw', this.onWatchToggleHandler );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Switch to edit mode.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
2015-03-13 15:50:23 +00:00
|
|
|
* @param {jQuery.Promise} [dataPromise] Promise for pending request from
|
|
|
|
* mw.libs.ve.targetLoader#requestPageData, if any
|
2014-10-21 01:10:41 +00:00
|
|
|
* @return {jQuery.Promise}
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.activate = function ( dataPromise ) {
|
2015-03-10 19:15:11 +00:00
|
|
|
var surface,
|
2015-07-29 14:03:48 +00:00
|
|
|
target = this;
|
2015-03-10 19:15:11 +00:00
|
|
|
|
2012-06-14 01:26:21 +00:00
|
|
|
if ( !this.active && !this.activating ) {
|
|
|
|
this.activating = true;
|
2014-10-21 01:10:41 +00:00
|
|
|
this.activatingDeferred = $.Deferred();
|
2015-02-23 08:44:51 +00:00
|
|
|
this.toolbarSetupDeferred = $.Deferred();
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2015-03-16 16:07:14 +00:00
|
|
|
$( 'html' ).removeClass( 've-loading' ).addClass( 've-activating' );
|
2015-05-03 10:51:48 +00:00
|
|
|
$.when( this.activatingDeferred, this.toolbarSetupDeferred ).done( function () {
|
2015-02-23 08:44:18 +00:00
|
|
|
$( 'html' ).removeClass( 've-activating' ).addClass( 've-active' );
|
2015-03-10 19:15:11 +00:00
|
|
|
// We have to focus the page after hiding the original content, otherwise
|
|
|
|
// in firefox the contentEditable container was below the view page, and
|
|
|
|
// 'focus' scrolled the screen down.
|
2015-07-29 14:03:48 +00:00
|
|
|
target.getSurface().getView().focus();
|
2015-05-03 10:51:48 +00:00
|
|
|
} ).fail( function () {
|
|
|
|
$( 'html' ).removeClass( 've-activating' );
|
2015-02-05 01:45:19 +00:00
|
|
|
} );
|
|
|
|
|
2014-12-12 02:18:46 +00:00
|
|
|
this.bindHandlers();
|
|
|
|
|
2014-09-25 20:19:18 +00:00
|
|
|
this.originalEditondbclick = mw.user.options.get( 'editondblclick' );
|
|
|
|
mw.user.options.set( 'editondblclick', 0 );
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
// User interface changes
|
2013-06-05 21:38:39 +00:00
|
|
|
this.transformPage();
|
2014-05-15 19:56:13 +00:00
|
|
|
this.setupLocalNoticeMessages();
|
2013-10-06 19:50:06 +00:00
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
this.saveScrollPosition();
|
2013-10-06 19:50:06 +00:00
|
|
|
|
2015-02-21 10:42:58 +00:00
|
|
|
// Create dummy surface to show toolbar while loading
|
2015-03-10 19:15:11 +00:00
|
|
|
surface = this.addSurface( [] );
|
2015-02-21 10:42:58 +00:00
|
|
|
surface.disable();
|
|
|
|
// setSurface creates dummy toolbar
|
2015-09-01 16:47:18 +00:00
|
|
|
this.dummyToolbar = true;
|
2015-02-21 10:42:58 +00:00
|
|
|
this.setSurface( surface );
|
|
|
|
// Disconnect the tool factory listeners so the toolbar
|
|
|
|
// doesn't start showing new tools as they load, too
|
|
|
|
// much flickering
|
|
|
|
this.getToolbar().getToolFactory().off( 'register' );
|
|
|
|
// Disable all the tools
|
|
|
|
this.getToolbar().updateToolState();
|
|
|
|
|
2015-03-13 15:50:23 +00:00
|
|
|
this.load( dataPromise );
|
2012-06-11 06:54:41 +00:00
|
|
|
}
|
2014-10-21 01:10:41 +00:00
|
|
|
return this.activatingDeferred.promise();
|
2012-06-14 21:31:08 +00:00
|
|
|
};
|
|
|
|
|
2012-06-12 01:21:31 +00:00
|
|
|
/**
|
2014-04-29 14:04:19 +00:00
|
|
|
* Determines whether we want to switch to view mode or not (displaying a dialog if necessary)
|
|
|
|
* Then, if we do, actually switches to view mode.
|
2012-06-12 01:21:31 +00:00
|
|
|
*
|
2014-12-03 00:39:56 +00:00
|
|
|
* A dialog will not be shown if deactivate() is called while activation is still in progress,
|
|
|
|
* or if the noDialog parameter is set to true. If deactivate() is called while the target
|
|
|
|
* is deactivating, or while it's not active and not activating, nothing happens.
|
|
|
|
*
|
|
|
|
* @param {boolean} [noDialog] Do not display a dialog
|
2014-10-29 01:19:52 +00:00
|
|
|
* @param {string} [trackMechanism] Abort mechanism; used for event tracking if present
|
2012-06-12 01:21:31 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.deactivate = function ( noDialog, trackMechanism ) {
|
2014-07-14 21:32:49 +00:00
|
|
|
var target = this;
|
2014-12-03 00:39:56 +00:00
|
|
|
if ( this.deactivating || ( !this.active && !this.activating ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:52:06 +00:00
|
|
|
// Just in case this wasn't closed before
|
2015-03-27 18:45:26 +00:00
|
|
|
if ( this.welcomeDialog ) {
|
|
|
|
this.welcomeDialog.close();
|
|
|
|
}
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2014-12-03 00:39:56 +00:00
|
|
|
if ( noDialog || this.activating || !this.edited ) {
|
|
|
|
this.cancel( trackMechanism );
|
|
|
|
} else {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().dialogs.openWindow( 'cancelconfirm' ).then( function ( opened ) {
|
2014-12-03 00:39:56 +00:00
|
|
|
opened.then( function ( closing ) {
|
|
|
|
closing.then( function ( data ) {
|
|
|
|
if ( data && data.action === 'discard' ) {
|
|
|
|
target.cancel( trackMechanism );
|
|
|
|
}
|
2014-05-31 15:24:14 +00:00
|
|
|
} );
|
2014-05-21 02:11:45 +00:00
|
|
|
} );
|
2014-12-03 00:39:56 +00:00
|
|
|
} );
|
2012-06-12 01:21:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-04-29 14:04:19 +00:00
|
|
|
/**
|
|
|
|
* Switch to view mode
|
|
|
|
*
|
2014-10-29 01:19:52 +00:00
|
|
|
* @param {string} [trackMechanism] Abort mechanism; used for event tracking if present
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.cancel = function ( trackMechanism ) {
|
2014-12-16 21:14:01 +00:00
|
|
|
var abortType,
|
|
|
|
target = this,
|
|
|
|
promises = [];
|
2014-10-29 01:19:52 +00:00
|
|
|
|
|
|
|
// Event tracking
|
|
|
|
if ( trackMechanism ) {
|
|
|
|
if ( this.activating ) {
|
|
|
|
abortType = 'preinit';
|
|
|
|
} else if ( !this.edited ) {
|
|
|
|
abortType = 'nochange';
|
|
|
|
} else if ( this.saving ) {
|
|
|
|
abortType = 'abandonMidsave';
|
|
|
|
} else {
|
|
|
|
// switchwith and switchwithout do not go through this code path,
|
|
|
|
// they go through switchToWikitextEditor() instead
|
|
|
|
abortType = 'abandon';
|
|
|
|
}
|
|
|
|
ve.track( 'mwedit.abort', {
|
|
|
|
type: abortType,
|
|
|
|
mechanism: trackMechanism
|
|
|
|
} );
|
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2015-12-23 12:13:50 +00:00
|
|
|
// Cancel activating, start deactivating
|
2014-04-29 14:04:19 +00:00
|
|
|
this.deactivating = true;
|
2015-12-23 12:13:50 +00:00
|
|
|
this.activating = false;
|
|
|
|
this.activatingDeferred.reject();
|
2015-02-23 08:44:18 +00:00
|
|
|
$( 'html' ).addClass( 've-deactivating' ).removeClass( 've-activated ve-active' );
|
2015-12-23 12:13:50 +00:00
|
|
|
|
2014-04-29 14:04:19 +00:00
|
|
|
// User interface changes
|
|
|
|
if ( this.elementsThatHadOurAccessKey ) {
|
|
|
|
this.elementsThatHadOurAccessKey.attr( 'accesskey', ve.msg( 'accesskey-save' ) );
|
|
|
|
}
|
|
|
|
this.restorePage();
|
|
|
|
|
2014-12-12 02:18:46 +00:00
|
|
|
this.unbindHandlers();
|
2014-11-25 01:44:24 +00:00
|
|
|
|
2014-09-25 20:19:18 +00:00
|
|
|
mw.user.options.set( 'editondblclick', this.originalEditondbclick );
|
|
|
|
this.originalEditondbclick = undefined;
|
|
|
|
|
2014-07-18 23:22:37 +00:00
|
|
|
if ( this.toolbarSaveButton ) {
|
|
|
|
// If deactivate is called before a successful load, then the save button has not yet been
|
|
|
|
// fully set up so disconnecting it would throw an error when trying call methods on the
|
|
|
|
// button property (bug 46456)
|
|
|
|
this.toolbarSaveButton.disconnect( this );
|
|
|
|
this.toolbarSaveButton.$element.detach();
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().$actions.empty();
|
2014-04-29 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check we got as far as setting up the surface
|
2015-12-23 12:13:50 +00:00
|
|
|
if ( this.getSurface() ) {
|
|
|
|
if ( this.active ) {
|
|
|
|
this.teardownUnloadHandlers();
|
|
|
|
}
|
2015-08-05 21:43:23 +00:00
|
|
|
promises.push( this.teardownSurface() );
|
2015-05-06 23:04:53 +00:00
|
|
|
} else if ( this.toolbar ) {
|
|
|
|
// If a dummy toolbar was created, destroy it
|
2015-05-03 10:51:48 +00:00
|
|
|
this.toolbar.destroy();
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
$.when.apply( null, promises ).done( function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
// If there is a load in progress, abort it
|
2014-12-16 21:14:01 +00:00
|
|
|
if ( target.loading ) {
|
|
|
|
target.loading.abort();
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
target.clearState();
|
|
|
|
target.docToSave = null;
|
|
|
|
target.initialEditSummary = new mw.Uri().query.summary;
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
target.deactivating = false;
|
2015-02-23 08:44:18 +00:00
|
|
|
$( 'html' ).removeClass( 've-deactivating' );
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2015-01-21 14:55:38 +00:00
|
|
|
// Move remaining elements back out of the target
|
|
|
|
target.$element.parent().append( target.$element.children() );
|
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
mw.hook( 've.deactivationComplete' ).fire( target.edited );
|
|
|
|
} );
|
2014-04-29 14:04:19 +00:00
|
|
|
};
|
|
|
|
|
2012-06-12 17:32:10 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2012-06-12 17:32:10 +00:00
|
|
|
*/
|
2015-07-31 15:03:33 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.loadFail = function ( errorText, error ) {
|
|
|
|
// Parent method
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.loadFail.apply( this, arguments );
|
2015-07-31 15:03:33 +00:00
|
|
|
|
2013-05-17 16:44:21 +00:00
|
|
|
// Don't show an error if the load was manually aborted
|
2014-01-29 00:15:51 +00:00
|
|
|
// The response.status check here is to catch aborts triggered by navigation away from the page
|
2014-02-06 00:19:19 +00:00
|
|
|
if (
|
2015-01-24 00:22:17 +00:00
|
|
|
error &&
|
|
|
|
Object.prototype.hasOwnProperty.call( error, 'error' ) &&
|
|
|
|
Object.prototype.hasOwnProperty.call( error.error, 'info' )
|
|
|
|
) {
|
|
|
|
error = error.error.info;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
errorText === 'http' &&
|
|
|
|
( error.statusText !== 'abort' || error.xhr.status !== 504 ) &&
|
|
|
|
confirm( ve.msg( 'visualeditor-loadwarning', 'HTTP ' + error.xhr.status ) )
|
2014-02-06 00:19:19 +00:00
|
|
|
) {
|
2012-06-19 19:26:08 +00:00
|
|
|
this.load();
|
2014-03-12 23:39:30 +00:00
|
|
|
} else if (
|
2015-01-24 00:22:17 +00:00
|
|
|
errorText === 'http' && error.xhr.status === 504 &&
|
2014-03-12 23:39:30 +00:00
|
|
|
confirm( ve.msg( 'visualeditor-timeout' ) )
|
|
|
|
) {
|
|
|
|
if ( 'veaction' in this.currentUri.query ) {
|
|
|
|
delete this.currentUri.query.veaction;
|
|
|
|
}
|
|
|
|
this.currentUri.query.action = 'edit';
|
2014-11-19 00:20:08 +00:00
|
|
|
location.href = this.currentUri.toString();
|
2015-01-24 00:22:17 +00:00
|
|
|
} else if (
|
|
|
|
errorText !== 'http' &&
|
|
|
|
typeof error === 'string' &&
|
|
|
|
confirm( ve.msg( 'visualeditor-loadwarning', errorText + ': ' + error ) )
|
|
|
|
) {
|
|
|
|
this.load();
|
2012-06-19 19:26:08 +00:00
|
|
|
} else {
|
2014-10-29 01:19:52 +00:00
|
|
|
// Something weird happened? Deactivate
|
|
|
|
// Not passing trackMechanism because we don't know what happened
|
|
|
|
// and this is not a user action
|
2012-12-06 22:18:56 +00:00
|
|
|
this.deactivate( true );
|
2012-06-19 19:26:08 +00:00
|
|
|
}
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2013-10-11 18:42:46 +00:00
|
|
|
*/
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.surfaceReady = function () {
|
2015-02-17 20:22:11 +00:00
|
|
|
var surfaceReadyTime = ve.now(),
|
|
|
|
target = this;
|
|
|
|
|
2014-11-19 02:16:27 +00:00
|
|
|
if ( !this.activating ) {
|
|
|
|
// Activation was aborted before we got here. Do nothing
|
|
|
|
// TODO are there things we need to clean up?
|
|
|
|
return;
|
|
|
|
}
|
2015-02-05 01:45:19 +00:00
|
|
|
|
2013-12-03 02:21:31 +00:00
|
|
|
this.activating = false;
|
2014-03-19 22:51:23 +00:00
|
|
|
|
|
|
|
// TODO: mwTocWidget should probably live in a ve.ui.MWSurface subclass
|
2014-01-09 01:32:13 +00:00
|
|
|
if ( mw.config.get( 'wgVisualEditorConfig' ).enableTocWidget ) {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().mwTocWidget = new ve.ui.MWTocWidget( this.getSurface() );
|
2014-01-09 01:32:13 +00:00
|
|
|
}
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-12-11 00:37:18 +00:00
|
|
|
// Track how long it takes for the first transaction to happen
|
|
|
|
this.surface.getModel().getDocument().once( 'transact', function () {
|
2015-02-17 20:22:11 +00:00
|
|
|
ve.track( 'mwtiming.behavior.firstTransaction', {
|
|
|
|
duration: ve.now() - surfaceReadyTime,
|
|
|
|
targetName: target.constructor.static.name
|
|
|
|
} );
|
2014-12-11 00:37:18 +00:00
|
|
|
} );
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
// Update UI
|
|
|
|
this.changeDocumentTitle();
|
|
|
|
this.restoreScrollPosition();
|
2015-07-01 11:11:36 +00:00
|
|
|
|
|
|
|
// Parent method
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.surfaceReady.apply( this, arguments );
|
2015-07-01 11:11:36 +00:00
|
|
|
|
2015-02-12 02:35:52 +00:00
|
|
|
this.setupUnloadHandlers();
|
2016-03-15 01:10:51 +00:00
|
|
|
if ( !this.suppressNormalStartupDialogs ) {
|
2016-03-09 21:02:18 +00:00
|
|
|
this.maybeShowWelcomeDialog();
|
2016-03-15 01:10:51 +00:00
|
|
|
this.maybeShowMetaDialog();
|
2016-03-09 21:02:18 +00:00
|
|
|
}
|
2015-03-10 19:15:11 +00:00
|
|
|
|
2014-10-21 01:10:41 +00:00
|
|
|
this.activatingDeferred.resolve();
|
2015-04-09 03:48:46 +00:00
|
|
|
this.events.trackActivationComplete();
|
2015-03-10 19:15:11 +00:00
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
mw.hook( 've.activationComplete' ).fire();
|
|
|
|
};
|
|
|
|
|
2014-12-03 00:39:56 +00:00
|
|
|
/**
|
|
|
|
* Handle Escape key presses.
|
2015-08-19 18:21:01 +00:00
|
|
|
*
|
2014-12-03 00:39:56 +00:00
|
|
|
* @param {jQuery.Event} e Keydown event
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onDocumentKeyDown = function ( e ) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var target = this;
|
|
|
|
|
2014-12-12 02:18:46 +00:00
|
|
|
// Parent method
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.onDocumentKeyDown.apply( this, arguments );
|
2014-12-12 02:18:46 +00:00
|
|
|
|
2014-11-25 01:44:24 +00:00
|
|
|
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
2014-12-12 15:55:18 +00:00
|
|
|
setTimeout( function () {
|
|
|
|
// Listeners should stopPropagation if they handle the escape key, but
|
|
|
|
// also check they didn't fire after this event, as would be the case if
|
|
|
|
// they were bound to the document.
|
|
|
|
if ( !e.isPropagationStopped() ) {
|
|
|
|
target.deactivate( false, 'navigate-read' );
|
|
|
|
}
|
|
|
|
} );
|
2014-12-03 00:39:56 +00:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks on the view tab.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onViewTabClick = function ( e ) {
|
2014-12-03 00:39:56 +00:00
|
|
|
if ( ( e.which && e.which !== 1 ) || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
return;
|
2014-11-25 01:44:24 +00:00
|
|
|
}
|
2014-12-03 00:39:56 +00:00
|
|
|
this.deactivate( false, 'navigate-read' );
|
|
|
|
e.preventDefault();
|
2014-11-25 01:44:24 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.saveComplete = function (
|
2015-07-27 19:27:03 +00:00
|
|
|
html, categoriesHtml, newid, isRedirect, displayTitle, lastModified, contentSub, modules, jsconfigvars
|
2014-10-31 00:26:32 +00:00
|
|
|
) {
|
2015-08-19 18:05:01 +00:00
|
|
|
var newUrlParams, watchChecked;
|
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.saveComplete.apply( this, arguments );
|
|
|
|
|
2012-12-04 21:04:19 +00:00
|
|
|
if ( !this.pageExists || this.restoring ) {
|
|
|
|
// This is a page creation or restoration, refresh the page
|
2015-08-05 21:43:23 +00:00
|
|
|
this.teardownUnloadHandlers();
|
2014-07-29 22:37:28 +00:00
|
|
|
newUrlParams = newid === undefined ? {} : { venotify: this.restoring ? 'restored' : 'created' };
|
|
|
|
|
2014-06-10 17:10:37 +00:00
|
|
|
if ( isRedirect ) {
|
|
|
|
newUrlParams.redirect = 'no';
|
|
|
|
}
|
2014-11-19 00:20:08 +00:00
|
|
|
location.href = this.viewUri.extend( newUrlParams );
|
2012-06-20 19:15:42 +00:00
|
|
|
} else {
|
2012-06-20 23:20:17 +00:00
|
|
|
// Update watch link to match 'watch checkbox' in save dialog.
|
|
|
|
// User logged in if module loaded.
|
2012-08-01 00:49:04 +00:00
|
|
|
// Just checking for mw.page.watch is not enough because in Firefox
|
|
|
|
// there is Object.prototype.watch...
|
2015-08-05 21:43:23 +00:00
|
|
|
if ( mw.page.hasOwnProperty( 'watch' ) ) {
|
2015-08-13 16:39:24 +00:00
|
|
|
watchChecked = this.checkboxesByName.wpWatchthis && this.checkboxesByName.wpWatchthis.isSelected();
|
2012-06-20 23:20:17 +00:00
|
|
|
mw.page.watch.updateWatchLink(
|
2012-08-01 00:49:04 +00:00
|
|
|
$( '#ca-watch a, #ca-unwatch a' ),
|
2014-05-15 16:12:43 +00:00
|
|
|
watchChecked ? 'unwatch' : 'watch'
|
2012-06-20 23:20:17 +00:00
|
|
|
);
|
|
|
|
}
|
2013-07-05 07:56:28 +00:00
|
|
|
|
|
|
|
// If we were explicitly editing an older version, make sure we won't
|
|
|
|
// load the same old version again, now that we've saved the next edit
|
|
|
|
// will be against the latest version.
|
|
|
|
// TODO: What about oldid in the url?
|
|
|
|
this.restoring = false;
|
|
|
|
|
2013-05-03 12:15:54 +00:00
|
|
|
if ( newid !== undefined ) {
|
2014-04-19 16:58:12 +00:00
|
|
|
mw.config.set( {
|
2014-08-22 20:50:48 +00:00
|
|
|
wgCurRevisionId: newid,
|
|
|
|
wgRevisionId: newid
|
2014-04-19 16:58:12 +00:00
|
|
|
} );
|
2013-07-05 07:56:28 +00:00
|
|
|
this.revid = newid;
|
2013-05-03 12:15:54 +00:00
|
|
|
}
|
2015-07-27 19:27:03 +00:00
|
|
|
|
|
|
|
// Update module JS config values and notify ResourceLoader of any new
|
|
|
|
// modules needed to be added to the page
|
|
|
|
mw.config.set( jsconfigvars );
|
|
|
|
mw.loader.load( modules );
|
|
|
|
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog.reset();
|
2014-11-07 00:31:34 +00:00
|
|
|
this.replacePageContent(
|
|
|
|
html,
|
|
|
|
categoriesHtml,
|
|
|
|
displayTitle,
|
|
|
|
lastModified,
|
|
|
|
contentSub
|
|
|
|
);
|
2015-01-28 21:10:22 +00:00
|
|
|
|
|
|
|
if ( newid !== undefined ) {
|
|
|
|
$( '#t-permalink a, #coll-download-as-rl a' ).each( function () {
|
|
|
|
var uri = new mw.Uri( $( this ).attr( 'href' ) );
|
|
|
|
uri.query.oldid = newid;
|
|
|
|
$( this ).attr( 'href', uri.toString() );
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2013-06-24 21:22:54 +00:00
|
|
|
this.setupSectionEditLinks();
|
2014-10-29 01:19:52 +00:00
|
|
|
// Tear down the target now that we're done saving
|
|
|
|
// Not passing trackMechanism because this isn't an abort action
|
2012-06-20 19:15:42 +00:00
|
|
|
this.deactivate( true );
|
2014-07-29 22:37:28 +00:00
|
|
|
if ( newid !== undefined ) {
|
|
|
|
mw.hook( 'postEdit' ).fire( {
|
2014-08-22 20:50:48 +00:00
|
|
|
message: ve.msg( 'postedit-confirmation-saved', mw.user )
|
2014-07-29 22:37:28 +00:00
|
|
|
} );
|
|
|
|
}
|
2012-06-20 19:15:42 +00:00
|
|
|
}
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-04-24 00:01:44 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2013-04-24 00:01:44 +00:00
|
|
|
*/
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.serializeFail = function ( jqXHR, status ) {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.serializeFail.apply( this, arguments );
|
|
|
|
|
2013-04-24 00:01:44 +00:00
|
|
|
alert( ve.msg( 'visualeditor-serializeerror', status ) );
|
2013-11-15 21:34:59 +00:00
|
|
|
|
2015-07-25 13:30:49 +00:00
|
|
|
this.getSurface().getDialogs().closeWindow( 'wikitextswitchconfirm' );
|
|
|
|
|
2013-11-15 21:34:59 +00:00
|
|
|
// It's possible to get here while the save dialog has never been opened (if the user uses
|
|
|
|
// the switch to source mode option)
|
|
|
|
if ( this.saveDialog ) {
|
2014-04-18 20:32:25 +00:00
|
|
|
this.saveDialog.popPending();
|
2013-11-15 21:34:59 +00:00
|
|
|
}
|
2013-04-24 00:01:44 +00:00
|
|
|
};
|
|
|
|
|
2013-06-05 19:28:00 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the MwMeta button in the toolbar.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onToolbarMetaButtonClick = function () {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().openWindow( 'meta' );
|
2013-06-05 19:28:00 +00:00
|
|
|
};
|
|
|
|
|
2013-09-06 00:10:06 +00:00
|
|
|
/**
|
2014-07-07 19:51:41 +00:00
|
|
|
* Open the dialog to switch to edit source mode with the current wikitext, or just do it straight
|
|
|
|
* away if the document is unmodified. If we open the dialog, the document opacity will be set to
|
|
|
|
* half, which can be reset with the resetDocumentOpacity function.
|
2013-09-06 00:10:06 +00:00
|
|
|
*
|
2015-07-30 11:08:56 +00:00
|
|
|
* @inheritdoc
|
2013-09-06 00:10:06 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.editSource = function () {
|
2015-10-08 22:16:56 +00:00
|
|
|
if ( !this.getSurface().getModel().hasBeenModified() && !this.fromEditedState ) {
|
2015-09-04 00:42:05 +00:00
|
|
|
this.switchToWikitextEditor( true, false );
|
2014-07-18 20:28:35 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getView().getDocument().getDocumentNode().$element.css( 'opacity', 0.5 );
|
2014-07-07 19:51:41 +00:00
|
|
|
|
2016-02-06 02:02:39 +00:00
|
|
|
ve.ui.actionFactory.create( 'window', this.getSurface() )
|
|
|
|
.open( 'wikitextswitchconfirm', { target: this } );
|
2013-09-06 00:10:06 +00:00
|
|
|
};
|
|
|
|
|
2013-05-14 16:50:29 +00:00
|
|
|
/**
|
2015-08-05 21:43:23 +00:00
|
|
|
* @inheritdoc
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.getSaveFields = function () {
|
2015-08-13 16:39:24 +00:00
|
|
|
var name, fieldValues = {};
|
|
|
|
|
|
|
|
for ( name in this.checkboxesByName ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( this.checkboxesByName[ name ].isSelected() ) {
|
|
|
|
fieldValues[ name ] = this.checkboxesByName[ name ].getValue();
|
2015-08-13 16:39:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.$otherFields.each( function () {
|
|
|
|
var $this = $( this ),
|
|
|
|
name = $this.prop( 'name' );
|
|
|
|
if ( name ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
fieldValues[ name ] = $this.val();
|
2015-08-13 16:39:24 +00:00
|
|
|
}
|
|
|
|
} );
|
2013-11-15 20:30:57 +00:00
|
|
|
|
2015-08-05 21:43:23 +00:00
|
|
|
return ve.extendObject(
|
2015-08-13 16:39:24 +00:00
|
|
|
fieldValues,
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.super.prototype.getSaveFields.call( this )
|
|
|
|
);
|
2012-11-28 23:57:00 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Switch to viewing mode.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
2014-07-14 21:32:49 +00:00
|
|
|
* @return {jQuery.Promise} Promise resolved when surface is torn down
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownSurface = function () {
|
2014-12-16 21:14:01 +00:00
|
|
|
var target = this,
|
|
|
|
promises = [];
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Update UI
|
2015-12-23 12:13:50 +00:00
|
|
|
promises.push( this.teardownToolbar() );
|
2013-05-17 16:09:20 +00:00
|
|
|
this.restoreDocumentTitle();
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface().mwTocWidget ) {
|
|
|
|
this.getSurface().mwTocWidget.teardown();
|
2014-03-19 22:51:23 +00:00
|
|
|
}
|
2014-07-16 23:45:49 +00:00
|
|
|
|
Followup 1c04d32d: release saveDialog reference even if closed
It's good that we're not trying to close the save dialog
if it's not open, but we still need to release our reference
to it in that case, otherwise trying to open the save dialog
in a new incarnation of the editor will fail.
If you opened VE, opened the save dialog, closed it,
went back to read mode, opened VE again, and tried to open the
save dialog again, it would fail because it tried to open
the cached reference to the previous editor's save dialog.
Bonus: prevent JS errors in this case by only attaching an
onClose handler if the dialog actually opened successfully.
If opening the dialog failed, the callback parameter isn't
a promise but an OO.ui.Error, and calling .always() causes
a JS error.
Change-Id: I62d6d3e7cd3df2c29a0c99e2e23bf1aac5187a12
2014-12-08 22:49:39 +00:00
|
|
|
if ( this.saveDialog ) {
|
|
|
|
if ( this.saveDialog.isOpened() ) {
|
|
|
|
// If the save dialog is still open (from saving) close it
|
|
|
|
promises.push( this.saveDialog.close() );
|
|
|
|
}
|
2014-07-16 23:45:49 +00:00
|
|
|
// Release the reference
|
2013-11-27 14:00:16 +00:00
|
|
|
this.saveDialog = null;
|
|
|
|
}
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2014-12-16 21:14:01 +00:00
|
|
|
return $.when.apply( null, promises ).then( function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
// Destroy surface
|
2014-12-16 21:14:01 +00:00
|
|
|
while ( target.surfaces.length ) {
|
|
|
|
target.surfaces.pop().destroy();
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
2014-12-16 21:14:01 +00:00
|
|
|
target.active = false;
|
|
|
|
} );
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Modify tabs in the skin to support in-place editing.
|
2015-07-29 13:41:30 +00:00
|
|
|
* Edit tab is bound outside the module in mw.DesktopArticleTarget.init.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupSkinTabs = function () {
|
2014-11-27 20:51:04 +00:00
|
|
|
var target = this;
|
2012-06-18 23:18:48 +00:00
|
|
|
if ( this.isViewPage ) {
|
2012-08-01 06:40:22 +00:00
|
|
|
// Allow instant switching back to view mode, without refresh
|
|
|
|
$( '#ca-view a, #ca-nstab-visualeditor a' )
|
2015-12-09 17:34:00 +00:00
|
|
|
.on( 'click', this.onViewTabClick.bind( this ) );
|
2014-06-25 20:13:11 +00:00
|
|
|
|
2016-01-28 02:29:11 +00:00
|
|
|
}
|
|
|
|
$( '#ca-viewsource, #ca-edit' ).on( 'click', function ( e ) {
|
|
|
|
if ( !target.active || e.which !== 1 || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-15 19:30:01 +00:00
|
|
|
|
2016-01-28 02:29:11 +00:00
|
|
|
if ( target.getSurface() && !target.deactivating ) {
|
|
|
|
target.editSource();
|
2014-07-18 20:28:35 +00:00
|
|
|
|
2016-01-28 02:29:11 +00:00
|
|
|
if ( target.getSurface().getModel().hasBeenModified() || target.fromEditedState ) {
|
|
|
|
e.preventDefault();
|
2014-07-01 00:01:39 +00:00
|
|
|
}
|
2016-01-28 02:29:11 +00:00
|
|
|
}
|
|
|
|
} );
|
2013-07-09 01:35:35 +00:00
|
|
|
|
|
|
|
mw.hook( 've.skinTabSetupComplete' ).fire();
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Modify page content to make section edit links activate the editor.
|
2015-08-04 10:34:07 +00:00
|
|
|
* Dummy replaced by init.js so that we can call it again from #saveSuccess after
|
2013-07-05 06:01:31 +00:00
|
|
|
* replacing the page contents with the new html.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupSectionEditLinks = null;
|
2012-06-18 20:12:32 +00:00
|
|
|
|
|
|
|
/**
|
2015-07-01 11:11:36 +00:00
|
|
|
* @inheritdoc
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.attachToolbarSaveButton = function () {
|
2015-12-11 16:42:23 +00:00
|
|
|
this.toolbar.$actions.append( this.toolbarSaveButton.$element );
|
2015-03-07 18:04:31 +00:00
|
|
|
// Make the toolbar recalculate its sizes for narrow/wide switching.
|
|
|
|
// This really should not be necessary.
|
|
|
|
this.toolbar.narrowThreshold = this.toolbar.$group.width() + this.toolbar.$actions.width();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2012-12-11 23:19:21 +00:00
|
|
|
/**
|
2015-07-31 12:15:31 +00:00
|
|
|
* @inheritdoc
|
2012-12-11 23:19:21 +00:00
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.openSaveDialog = function () {
|
|
|
|
var windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
2014-07-14 21:32:49 +00:00
|
|
|
|
2015-07-31 12:15:31 +00:00
|
|
|
// Open the dialog
|
|
|
|
windowAction.open( 'mwSave', {
|
|
|
|
target: this,
|
|
|
|
editSummary: this.initialEditSummary,
|
2015-08-13 16:39:24 +00:00
|
|
|
checkboxFields: this.checkboxFields,
|
|
|
|
checkboxesByName: this.checkboxesByName
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Remember the window's scroll position.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.saveScrollPosition = function () {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.scrollTop = $( window ).scrollTop();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Restore the window's scroll position.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restoreScrollPosition = function () {
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this.scrollTop ) {
|
|
|
|
$( window ).scrollTop( this.scrollTop );
|
|
|
|
this.scrollTop = null;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Hide the toolbar.
|
2015-01-21 14:55:38 +00:00
|
|
|
*
|
|
|
|
* @return {jQuery.Promise} Promise which resolves when toolbar is hidden
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownToolbar = function () {
|
2015-02-23 08:44:51 +00:00
|
|
|
var target = this,
|
|
|
|
deferred = $.Deferred();
|
|
|
|
this.toolbar.$element.css( 'height', this.toolbar.$bar.outerHeight() );
|
|
|
|
setTimeout( function () {
|
|
|
|
target.toolbar.$element.css( 'height', '0' );
|
|
|
|
target.toolbar.$element.one( 'transitionend', function () {
|
|
|
|
target.toolbar.destroy();
|
|
|
|
target.toolbar = null;
|
|
|
|
deferred.resolve();
|
|
|
|
} );
|
2014-12-16 21:14:01 +00:00
|
|
|
} );
|
2015-02-23 08:44:51 +00:00
|
|
|
return deferred.promise();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2013-05-17 16:09:20 +00:00
|
|
|
/**
|
|
|
|
* Change the document title to state that we are now editing.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.changeDocumentTitle = function () {
|
2015-02-23 16:54:21 +00:00
|
|
|
var pageName = mw.config.get( 'wgPageName' ),
|
|
|
|
title = mw.Title.newFromText( pageName );
|
|
|
|
if ( title ) {
|
|
|
|
pageName = title.getPrefixedText();
|
|
|
|
}
|
2013-05-17 16:09:20 +00:00
|
|
|
document.title = ve.msg(
|
|
|
|
this.pageExists ? 'editing' : 'creating',
|
2015-02-23 16:54:21 +00:00
|
|
|
pageName
|
2013-05-17 16:09:20 +00:00
|
|
|
) + ' - ' + mw.config.get( 'wgSiteName' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the original document title.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restoreDocumentTitle = function () {
|
2013-05-17 16:09:20 +00:00
|
|
|
document.title = this.originalDocumentTitle;
|
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-06-05 21:38:39 +00:00
|
|
|
* Page modifications for switching to edit mode.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.transformPage = function () {
|
2013-06-05 22:39:43 +00:00
|
|
|
var uri;
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2014-04-30 18:56:30 +00:00
|
|
|
// Deselect current mode (e.g. "view" or "history"). In skins like monobook that don't have
|
|
|
|
// separate tab sections for content actions and namespaces the below is a no-op.
|
|
|
|
$( '#p-views' ).find( 'li.selected' ).removeClass( 'selected' );
|
|
|
|
$( '#ca-ve-edit' ).addClass( 'selected' );
|
2015-10-23 16:29:56 +00:00
|
|
|
if (
|
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).singleEditTab &&
|
|
|
|
mw.user.options.get( 'visualeditor-tabs' ) !== 'multi-tab'
|
|
|
|
) {
|
|
|
|
$( '#ca-edit' ).addClass( 'selected' );
|
|
|
|
}
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2014-05-14 23:23:07 +00:00
|
|
|
mw.hook( 've.activate' ).fire();
|
2014-05-14 22:19:39 +00:00
|
|
|
|
2015-02-21 10:42:58 +00:00
|
|
|
// Move all native content inside the target
|
|
|
|
this.$element.append( this.$element.siblings() );
|
|
|
|
|
2013-06-05 22:39:43 +00:00
|
|
|
// Push veaction=edit url in history (if not already. If we got here by a veaction=edit
|
|
|
|
// permalink then it will be there already and the constructor called #activate)
|
2015-10-23 16:29:56 +00:00
|
|
|
if (
|
|
|
|
!this.actFromPopState &&
|
|
|
|
history.pushState &&
|
|
|
|
this.currentUri.query.veaction !== 'edit' &&
|
|
|
|
this.currentUri.query.action !== 'edit'
|
|
|
|
) {
|
2014-10-21 01:10:41 +00:00
|
|
|
// Set the current URL
|
2013-06-05 22:39:43 +00:00
|
|
|
uri = this.currentUri;
|
2015-10-23 16:29:56 +00:00
|
|
|
|
|
|
|
if ( mw.config.get( 'wgVisualEditorConfig' ).singleEditTab ) {
|
|
|
|
uri.query.action = 'edit';
|
|
|
|
mw.config.set( 'wgAction', 'edit' );
|
|
|
|
} else {
|
|
|
|
uri.query.veaction = 'edit';
|
|
|
|
delete uri.query.action;
|
|
|
|
mw.config.set( 'wgAction', 'view' );
|
|
|
|
}
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2014-11-19 01:10:52 +00:00
|
|
|
history.pushState( this.popState, document.title, uri );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
|
|
|
this.actFromPopState = false;
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-05 21:38:39 +00:00
|
|
|
* Page modifications for switching back to view mode.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () {
|
2015-06-15 11:45:26 +00:00
|
|
|
var uri, keys;
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2014-04-30 18:56:30 +00:00
|
|
|
// Skins like monobook don't have a tab for view mode and instead just have the namespace tab
|
|
|
|
// selected. We didn't deselect the namespace tab, so we're ready after deselecting #ca-ve-edit.
|
|
|
|
// In skins having #ca-view (like Vector), select that.
|
|
|
|
$( '#ca-ve-edit' ).removeClass( 'selected' );
|
2015-10-23 16:29:56 +00:00
|
|
|
if (
|
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).singleEditTab &&
|
|
|
|
mw.user.options.get( 'visualeditor-tabs' ) !== 'multi-tab'
|
|
|
|
) {
|
|
|
|
$( '#ca-edit' ).removeClass( 'selected' );
|
|
|
|
}
|
2014-04-30 18:56:30 +00:00
|
|
|
$( '#ca-view' ).addClass( 'selected' );
|
2012-06-18 20:12:32 +00:00
|
|
|
|
2014-05-14 23:23:07 +00:00
|
|
|
mw.hook( 've.deactivate' ).fire();
|
2015-05-09 13:47:10 +00:00
|
|
|
this.emit( 'deactivate' );
|
2014-05-14 22:19:39 +00:00
|
|
|
|
2015-06-15 11:45:26 +00:00
|
|
|
// Push article url into history
|
2014-11-19 01:10:52 +00:00
|
|
|
if ( !this.actFromPopState && history.pushState ) {
|
2015-06-15 11:45:26 +00:00
|
|
|
// Remove the VisualEditor query parameters
|
2013-06-05 22:39:43 +00:00
|
|
|
uri = this.currentUri;
|
|
|
|
if ( 'veaction' in uri.query ) {
|
|
|
|
delete uri.query.veaction;
|
|
|
|
}
|
2014-07-10 12:16:37 +00:00
|
|
|
if ( 'vesection' in uri.query ) {
|
|
|
|
delete uri.query.vesection;
|
|
|
|
}
|
2016-02-10 02:27:50 +00:00
|
|
|
if ( 'action' in uri.query && $( '#wpTextbox1' ).length === 0 ) {
|
2015-10-08 22:16:56 +00:00
|
|
|
delete uri.query.action;
|
2015-11-04 01:40:49 +00:00
|
|
|
mw.config.set( 'wgAction', 'view' );
|
2015-10-08 22:16:56 +00:00
|
|
|
}
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2015-06-15 11:45:26 +00:00
|
|
|
// If there are any other query parameters left, re-use that uri object.
|
|
|
|
// Otherwise use the canonical style view url (T44553, T102363).
|
|
|
|
keys = Object.keys( uri.query );
|
2015-08-19 17:33:02 +00:00
|
|
|
if ( !keys.length || ( keys.length === 1 && keys[ 0 ] === 'title' ) ) {
|
2014-11-19 01:10:52 +00:00
|
|
|
history.pushState( this.popState, document.title, this.viewUri );
|
2015-06-15 11:45:26 +00:00
|
|
|
} else {
|
|
|
|
history.pushState( this.popState, document.title, uri );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.actFromPopState = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Event} e Native event object
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onWindowPopState = function ( e ) {
|
2014-03-12 21:26:52 +00:00
|
|
|
var newUri;
|
|
|
|
|
|
|
|
if ( !this.verifyPopState( e.state ) ) {
|
|
|
|
// Ignore popstate events fired for states not created by us
|
|
|
|
// This also filters out the initial fire in Chrome (bug 57901).
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-19 00:20:08 +00:00
|
|
|
newUri = this.currentUri = new mw.Uri( location.href );
|
2014-03-12 21:26:52 +00:00
|
|
|
|
2013-06-05 22:39:43 +00:00
|
|
|
if ( !this.active && newUri.query.veaction === 'edit' ) {
|
|
|
|
this.actFromPopState = true;
|
|
|
|
this.activate();
|
|
|
|
}
|
|
|
|
if ( this.active && newUri.query.veaction !== 'edit' ) {
|
|
|
|
this.actFromPopState = true;
|
2014-10-29 01:19:52 +00:00
|
|
|
this.deactivate( false, 'navigate-back' );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
2012-06-21 19:44:33 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Replace the page content with new HTML.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
2014-01-12 14:23:49 +00:00
|
|
|
* @param {string} html Rendered HTML from server
|
|
|
|
* @param {string} categoriesHtml Rendered categories HTML from server
|
2015-08-04 13:37:13 +00:00
|
|
|
* @param {string} displayTitle HTML to show as the page title
|
2014-11-17 01:00:06 +00:00
|
|
|
* @param {Object} lastModified Object containing user-formatted date
|
2015-08-04 13:37:13 +00:00
|
|
|
* and time strings, or undefined if we made no change.
|
|
|
|
* @param {string} contentSub HTML to show as the content subtitle
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.replacePageContent = function (
|
2014-11-07 00:31:34 +00:00
|
|
|
html, categoriesHtml, displayTitle, lastModified, contentSub
|
2014-10-31 00:26:32 +00:00
|
|
|
) {
|
2015-03-10 01:53:05 +00:00
|
|
|
var $editableContent, $imgContent,
|
2015-01-31 00:41:37 +00:00
|
|
|
$content = $( $.parseHTML( html ) );
|
2014-05-17 16:48:21 +00:00
|
|
|
|
2014-11-17 01:00:06 +00:00
|
|
|
if ( lastModified ) {
|
2014-11-17 01:16:29 +00:00
|
|
|
// If we were not viewing the most recent revision before (a requirement
|
|
|
|
// for lastmod to have been added by MediaWiki), we will be now.
|
|
|
|
if ( !$( '#footer-info-lastmod' ).length ) {
|
|
|
|
$( '#footer-info' ).prepend(
|
|
|
|
$( '<li>' ).attr( 'id', 'footer-info-lastmod' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-11-18 23:35:52 +00:00
|
|
|
$( '#footer-info-lastmod' ).html( ' ' + mw.msg(
|
2014-11-17 01:00:06 +00:00
|
|
|
'lastmodifiedat',
|
|
|
|
lastModified.date,
|
|
|
|
lastModified.time
|
|
|
|
) );
|
|
|
|
}
|
2014-10-31 00:26:32 +00:00
|
|
|
|
2015-03-10 01:53:05 +00:00
|
|
|
$imgContent = $( '#mw-imagepage-content' );
|
|
|
|
if ( $imgContent.length ) {
|
2014-05-17 16:48:21 +00:00
|
|
|
// On file pages, we only want to replace the (local) description.
|
2015-03-10 01:53:05 +00:00
|
|
|
$editableContent = $imgContent;
|
2014-05-30 13:04:53 +00:00
|
|
|
} else if ( $( '#mw-pages' ).length ) {
|
|
|
|
// It would be nice if MW core did this for us...
|
|
|
|
if ( !$( '#ve-cat-description' ).length ) {
|
|
|
|
$( '#mw-content-text > :not(div:has(#mw-pages))' ).wrapAll(
|
|
|
|
$( '<div>' )
|
|
|
|
.attr( 'id', 've-cat-description' )
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$editableContent = $( '#ve-cat-description' );
|
2014-05-17 16:48:21 +00:00
|
|
|
} else {
|
|
|
|
$editableContent = $( '#mw-content-text' );
|
|
|
|
}
|
|
|
|
|
|
|
|
mw.hook( 'wikipage.content' ).fire( $editableContent.empty().append( $content ) );
|
2014-06-21 01:37:30 +00:00
|
|
|
if ( displayTitle ) {
|
2015-11-10 13:50:00 +00:00
|
|
|
$( '#content #firstHeading' ).html( displayTitle );
|
2014-06-21 01:37:30 +00:00
|
|
|
}
|
2014-01-12 14:23:49 +00:00
|
|
|
$( '#catlinks' ).replaceWith( categoriesHtml );
|
2014-11-07 00:31:34 +00:00
|
|
|
$( '#contentSub' ).html( contentSub );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the numeric index of a section in the page.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {HTMLElement} heading Heading element of section
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.getEditSection = function ( heading ) {
|
2012-06-18 23:18:48 +00:00
|
|
|
var $page = $( '#mw-content-text' ),
|
2012-06-18 20:12:32 +00:00
|
|
|
section = 0;
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
$page.find( 'h1, h2, h3, h4, h5, h6' ).not( '#toc h2' ).each( function () {
|
2012-06-18 23:18:48 +00:00
|
|
|
section++;
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this === heading ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} );
|
2012-06-18 23:18:48 +00:00
|
|
|
return section;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-07-18 22:34:16 +00:00
|
|
|
* Store the section for which the edit link has been triggered.
|
2012-06-18 23:18:48 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {HTMLElement} heading Heading element of section
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.saveEditSection = function ( heading ) {
|
2012-06-18 23:18:48 +00:00
|
|
|
this.section = this.getEditSection( heading );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2012-06-21 03:16:10 +00:00
|
|
|
/**
|
2015-08-05 21:43:23 +00:00
|
|
|
* Add onunload and onbeforeunload handlers.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.setupUnloadHandlers = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
// Remember any already set beforeunload handler
|
2012-06-21 03:16:10 +00:00
|
|
|
this.onBeforeUnloadFallback = window.onbeforeunload;
|
2015-02-12 02:35:52 +00:00
|
|
|
// Attach our handlers
|
2014-12-02 23:21:50 +00:00
|
|
|
window.onbeforeunload = this.onBeforeUnload.bind( this );
|
|
|
|
window.addEventListener( 'unload', this.onUnloadHandler );
|
2012-06-21 03:16:10 +00:00
|
|
|
};
|
|
|
|
/**
|
2015-02-12 02:35:52 +00:00
|
|
|
* Remove onunload and onbeforunload handlers.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2015-08-05 21:43:23 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.teardownUnloadHandlers = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
// Restore whatever previous onbeforeunload hook existed
|
2012-06-21 03:16:10 +00:00
|
|
|
window.onbeforeunload = this.onBeforeUnloadFallback;
|
2014-12-02 23:21:50 +00:00
|
|
|
this.onBeforeUnloadFallback = null;
|
|
|
|
window.removeEventListener( 'unload', this.onUnloadHandler );
|
2012-06-21 03:16:10 +00:00
|
|
|
};
|
|
|
|
|
2015-03-25 21:52:06 +00:00
|
|
|
/**
|
|
|
|
* Show the meta dialog as needed on load.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.maybeShowMetaDialog = function () {
|
2016-02-19 17:35:11 +00:00
|
|
|
var windowAction,
|
|
|
|
target = this;
|
2015-03-25 21:52:06 +00:00
|
|
|
|
2016-03-09 21:02:18 +00:00
|
|
|
if ( this.welcomeDialogPromise ) {
|
|
|
|
this.welcomeDialogPromise
|
|
|
|
.always( function () {
|
|
|
|
// Pop out the notices when the welcome dialog is closed
|
|
|
|
target.actionsToolbar.tools.notices.getPopup().toggle( true );
|
|
|
|
} );
|
|
|
|
}
|
2013-11-13 20:15:44 +00:00
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface().getModel().metaList.getItemsInGroup( 'mwRedirect' ).length ) {
|
2016-02-19 17:35:11 +00:00
|
|
|
windowAction = ve.ui.actionFactory.create( 'window', this.getSurface() );
|
|
|
|
|
|
|
|
windowAction.open( 'meta', { page: 'settings' } );
|
2013-11-13 20:15:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-06-21 03:16:10 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle before unload event.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onBeforeUnload = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
var fallbackResult;
|
2012-06-21 03:16:10 +00:00
|
|
|
// Check if someone already set on onbeforeunload hook
|
|
|
|
if ( this.onBeforeUnloadFallback ) {
|
|
|
|
// Get the result of their onbeforeunload hook
|
|
|
|
fallbackResult = this.onBeforeUnloadFallback();
|
2014-12-02 23:21:50 +00:00
|
|
|
// If it returned something, exit here and return their message
|
|
|
|
if ( fallbackResult !== undefined ) {
|
|
|
|
return fallbackResult;
|
2012-06-21 03:16:10 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-02 23:21:50 +00:00
|
|
|
// Check if there's been an edit
|
|
|
|
if ( this.getSurface() && this.edited && !this.submitting && mw.user.options.get( 'useeditwarning' ) ) {
|
|
|
|
// Return our message
|
|
|
|
return ve.msg( 'visualeditor-viewpage-savewarning' );
|
2012-06-21 03:16:10 +00:00
|
|
|
}
|
|
|
|
};
|
2014-07-07 19:51:41 +00:00
|
|
|
|
2015-02-12 02:35:52 +00:00
|
|
|
/**
|
|
|
|
* Handle unload event.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.onUnload = function () {
|
2014-12-02 23:21:50 +00:00
|
|
|
if ( !this.submitting ) {
|
2015-02-12 02:35:52 +00:00
|
|
|
ve.track( 'mwedit.abort', {
|
|
|
|
type: this.edited ? 'unknown-edited' : 'unknown',
|
2015-03-17 19:01:08 +00:00
|
|
|
mechanism: 'navigate'
|
2015-02-12 02:35:52 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-07-07 19:51:41 +00:00
|
|
|
/**
|
|
|
|
* Switches to the wikitext editor, either keeping (default) or discarding changes.
|
|
|
|
*
|
|
|
|
* @param {boolean} [discardChanges] Whether to discard changes or not.
|
2015-09-04 00:42:05 +00:00
|
|
|
* @param {boolean} [modified] Whether there were any changes at all.
|
2014-07-07 19:51:41 +00:00
|
|
|
*/
|
2015-09-04 00:42:05 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.switchToWikitextEditor = function ( discardChanges, modified ) {
|
2015-12-18 00:39:35 +00:00
|
|
|
var uri,
|
|
|
|
oldid = this.currentUri.query.oldid || $( 'input[name=parentRevId]' ).val(),
|
|
|
|
target = this,
|
2015-12-15 01:38:05 +00:00
|
|
|
prefPromise = mw.libs.ve.setEditorPreference( 'wikitext' );
|
2015-12-12 00:51:32 +00:00
|
|
|
|
2014-07-07 19:51:41 +00:00
|
|
|
if ( discardChanges ) {
|
2015-09-04 00:42:05 +00:00
|
|
|
if ( modified ) {
|
|
|
|
ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism: 'navigate' } );
|
|
|
|
} else {
|
|
|
|
ve.track( 'mwedit.abort', { type: 'switchnochange', mechanism: 'navigate' } );
|
|
|
|
}
|
2014-07-07 19:51:41 +00:00
|
|
|
this.submitting = true;
|
2015-12-15 01:38:05 +00:00
|
|
|
prefPromise.done( function () {
|
2015-12-18 00:39:35 +00:00
|
|
|
uri = target.viewUri.clone().extend( {
|
2015-12-15 01:38:05 +00:00
|
|
|
action: 'edit',
|
|
|
|
veswitched: 1
|
2015-12-18 00:39:35 +00:00
|
|
|
} );
|
|
|
|
if ( oldid ) {
|
|
|
|
uri.extend( { oldid: oldid } );
|
|
|
|
}
|
|
|
|
location.href = uri.toString();
|
2015-12-15 01:38:05 +00:00
|
|
|
} );
|
2014-07-07 19:51:41 +00:00
|
|
|
} else {
|
|
|
|
this.serialize(
|
2015-04-10 15:07:04 +00:00
|
|
|
this.docToSave || this.getSurface().getDom(),
|
2014-11-27 00:23:52 +00:00
|
|
|
function ( wikitext ) {
|
2014-10-29 01:19:52 +00:00
|
|
|
ve.track( 'mwedit.abort', { type: 'switchwith', mechanism: 'navigate' } );
|
2015-11-10 23:01:49 +00:00
|
|
|
target.submitWithSaveFields( { wpDiff: 1 }, wikitext );
|
2014-12-16 21:14:01 +00:00
|
|
|
}
|
2014-07-07 19:51:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the document opacity when we've decided to cancel switching to the wikitext editor.
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.DesktopArticleTarget.prototype.resetDocumentOpacity = function () {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getView().getDocument().getDocumentNode().$element.css( 'opacity', 1 );
|
2014-07-07 19:51:41 +00:00
|
|
|
};
|