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
|
|
|
/*!
|
2013-01-15 23:38:49 +00:00
|
|
|
* VisualEditor MediaWiki Initialization ViewPageTarget class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Initialization MediaWiki view page target.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @class
|
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
|
|
|
* @extends ve.init.mw.Target
|
2013-02-20 19:44:44 +00:00
|
|
|
*
|
2012-06-11 06:54:41 +00:00
|
|
|
* @constructor
|
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.init.mw.ViewPageTarget = function VeInitMwViewPageTarget() {
|
2014-01-06 08:43:37 +00:00
|
|
|
var prefName,
|
2013-12-18 01:29:04 +00:00
|
|
|
prefValue,
|
2014-11-19 00:20:08 +00:00
|
|
|
// A workaround, as default URI does not get updated after pushState (bug 72334)
|
|
|
|
currentUri = new mw.Uri( location.href ),
|
2014-01-06 08:43:37 +00:00
|
|
|
conf = mw.config.get( 'wgVisualEditorConfig' );
|
2012-08-23 19:01:07 +00:00
|
|
|
|
2012-09-17 23:53:03 +00:00
|
|
|
// Parent constructor
|
2013-02-20 19:44:44 +00:00
|
|
|
ve.init.mw.Target.call(
|
2013-06-18 01:38:18 +00:00
|
|
|
this, $( '#content' ),
|
|
|
|
mw.config.get( 'wgRelevantPageName' ),
|
|
|
|
currentUri.query.oldid
|
2013-02-20 19:44:44 +00:00
|
|
|
);
|
2012-06-11 06:54:41 +00:00
|
|
|
|
|
|
|
// Properties
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
this.toolbarSaveButton = null;
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog = null;
|
2012-06-21 03:16:10 +00:00
|
|
|
this.onBeforeUnloadFallback = null;
|
2013-05-01 22:21:32 +00:00
|
|
|
this.onBeforeUnloadHandler = null;
|
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;
|
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;
|
2014-11-18 20:47:11 +00:00
|
|
|
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 ) );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.veEditUri = this.viewUri.clone().extend( { veaction: 'edit' } );
|
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;
|
2012-06-18 20:12:32 +00:00
|
|
|
|
2014-02-26 00:50:20 +00:00
|
|
|
// Add modules specific to desktop (modules shared with mobile go in MWTarget)
|
|
|
|
this.modules.push(
|
|
|
|
'ext.visualEditor.mwformatting',
|
|
|
|
'ext.visualEditor.mwgallery',
|
|
|
|
'ext.visualEditor.mwimage',
|
2014-07-16 22:34:41 +00:00
|
|
|
'ext.visualEditor.mwmeta'
|
2014-02-26 00:50:20 +00:00
|
|
|
);
|
|
|
|
|
2014-01-06 08:43:37 +00:00
|
|
|
// Load preference modules
|
|
|
|
for ( prefName in conf.preferenceModules ) {
|
2013-12-18 01:29:04 +00:00
|
|
|
prefValue = mw.config.get( 'wgUserName' ) === null ?
|
|
|
|
conf.defaultUserOptions[prefName] :
|
|
|
|
mw.user.options.get( prefName, conf.defaultUserOptions[prefName] );
|
|
|
|
if ( prefValue && prefValue !== '0' ) {
|
2014-01-06 08:43:37 +00:00
|
|
|
this.modules.push( conf.preferenceModules[prefName] );
|
2013-12-18 01:29:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
// Events
|
2013-05-01 22:21:32 +00:00
|
|
|
this.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
save: 'onSave',
|
|
|
|
saveErrorEmpty: 'onSaveErrorEmpty',
|
|
|
|
saveErrorSpamBlacklist: 'onSaveErrorSpamBlacklist',
|
|
|
|
saveErrorAbuseFilter: 'onSaveErrorAbuseFilter',
|
|
|
|
saveErrorNewUser: 'onSaveErrorNewUser',
|
|
|
|
saveErrorCaptcha: 'onSaveErrorCaptcha',
|
|
|
|
saveErrorUnknown: 'onSaveErrorUnknown',
|
2014-10-30 00:36:02 +00:00
|
|
|
saveErrorPageDeleted: 'onSaveErrorPageDeleted',
|
2014-08-22 20:50:48 +00:00
|
|
|
loadError: 'onLoadError',
|
|
|
|
surfaceReady: 'onSurfaceReady',
|
|
|
|
editConflict: 'onEditConflict',
|
|
|
|
showChanges: 'onShowChanges',
|
|
|
|
showChangesError: 'onShowChangesError',
|
|
|
|
noChanges: 'onNoChanges',
|
|
|
|
serializeError: 'onSerializeError',
|
|
|
|
sanityCheckComplete: 'updateToolbarSaveButtonState'
|
2012-06-18 20:12:32 +00:00
|
|
|
} );
|
2012-06-11 06:54:41 +00:00
|
|
|
|
2013-06-05 21:38:39 +00:00
|
|
|
if ( currentUri.query.venotify ) {
|
|
|
|
// The following messages can be used here:
|
2014-05-01 20:51:32 +00:00
|
|
|
// postedit-confirmation-saved
|
|
|
|
// postedit-confirmation-created
|
|
|
|
// postedit-confirmation-restored
|
2013-06-21 12:44:56 +00:00
|
|
|
mw.hook( 'postEdit' ).fire( {
|
2014-08-22 20:50:48 +00:00
|
|
|
message: ve.msg( 'postedit-confirmation-' + currentUri.query.venotify, mw.user )
|
2013-06-21 12:44:56 +00:00
|
|
|
} );
|
2014-04-14 16:19:30 +00:00
|
|
|
|
|
|
|
delete currentUri.query.venotify;
|
|
|
|
}
|
|
|
|
|
2014-11-19 01:10:52 +00:00
|
|
|
if ( history.replaceState ) {
|
2014-04-14 16:19:30 +00:00
|
|
|
// This is to stop the back button breaking when it's supposed to take us back out
|
|
|
|
// of VE. It used to only be called when venotify is used. 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 */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.init.mw.ViewPageTarget, ve.init.mw.Target );
|
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
|
|
|
|
2013-01-15 23:38:49 +00:00
|
|
|
/* Static Properties */
|
2012-06-11 06:54:41 +00:00
|
|
|
|
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
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.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: {
|
|
|
|
firefox: [['>=', 15]],
|
|
|
|
iceweasel: [['>=', 10]],
|
|
|
|
safari: [['>=', 6]],
|
|
|
|
chrome: [['>=', 19]],
|
|
|
|
opera: [['>=', 15]]
|
2012-08-22 21:24:50 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.verifyPopState = function ( popState ) {
|
|
|
|
return popState && popState.tag === 'visualeditor';
|
|
|
|
};
|
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-12-03 00:04:07 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.setupToolbar = function ( surface ) {
|
2014-05-02 16:34:46 +00:00
|
|
|
var $firstHeading;
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2014-12-03 00:04:07 +00:00
|
|
|
ve.init.mw.Target.prototype.setupToolbar.call( this, surface );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2014-05-02 16:34:46 +00:00
|
|
|
// Keep it hidden so that we can slide it down smoothly (avoids sudden
|
|
|
|
// offset flash when original content is hidden, and replaced in-place with a
|
|
|
|
// similar-looking surface).
|
|
|
|
// FIXME: This is not ideal, the parent class creates it and appends
|
|
|
|
// to target (visibly), only for us to hide it again 0ms later.
|
|
|
|
// Though we can't hide it by default because it needs visible dimensions
|
|
|
|
// to compute stuff during setup.
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().$bar.hide();
|
2014-05-02 16:34:46 +00:00
|
|
|
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().$element
|
2014-02-07 22:04:35 +00:00
|
|
|
.addClass( 've-init-mw-viewPageTarget-toolbar' );
|
2014-05-02 16:34:46 +00:00
|
|
|
|
2014-02-07 22:04:35 +00:00
|
|
|
// Move the toolbar to before #firstHeading if it exists
|
2014-05-02 16:34:46 +00:00
|
|
|
$firstHeading = $( '#firstHeading' );
|
2014-02-07 22:04:35 +00:00
|
|
|
if ( $firstHeading.length ) {
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().$element.insertBefore( $firstHeading );
|
2014-02-07 22:04:35 +00:00
|
|
|
}
|
2014-05-02 16:34:46 +00:00
|
|
|
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().$bar.slideDown( 'fast', function () {
|
2014-02-06 23:33:21 +00:00
|
|
|
// Check the surface wasn't torn down while the toolbar was animating
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface() ) {
|
2014-12-03 00:04:07 +00:00
|
|
|
this.getToolbar().initialize();
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getView().emit( 'position' );
|
|
|
|
this.getSurface().getContext().updateDimensions();
|
2014-02-06 23:33:21 +00:00
|
|
|
}
|
2014-07-08 22:33:32 +00:00
|
|
|
}.bind( this ) );
|
2014-02-06 23:33:21 +00:00
|
|
|
};
|
|
|
|
|
2014-05-15 19:56:13 +00:00
|
|
|
/**
|
|
|
|
* Set up notices for things like unknown browsers.
|
|
|
|
* Needs to be done on each activation because localNoticeMessages is cleared in clearState
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.setupLocalNoticeMessages = function () {
|
|
|
|
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 ||
|
|
|
|
$.client.test( ve.init.mw.ViewPageTarget.compatibility.whitelist, null, true )
|
|
|
|
) ) {
|
|
|
|
// Show warning in unknown browsers that pass the support test
|
|
|
|
// Continue at own risk.
|
|
|
|
this.localNoticeMessages.push( 'visualeditor-browserwarning' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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
|
|
|
*
|
|
|
|
* @method
|
2014-10-21 01:10:41 +00:00
|
|
|
* @return {jQuery.Promise}
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.activate = function () {
|
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();
|
2013-06-05 21:38:39 +00:00
|
|
|
|
2014-09-25 20:19:18 +00:00
|
|
|
this.originalEditondbclick = mw.user.options.get( 'editondblclick' );
|
|
|
|
mw.user.options.set( 'editondblclick', 0 );
|
|
|
|
|
2014-11-25 01:44:24 +00:00
|
|
|
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this );
|
|
|
|
$( document ).on( 'keydown', this.onDocumentKeyDownHandler );
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
// User interface changes
|
2013-06-05 21:38:39 +00:00
|
|
|
this.transformPage();
|
2014-05-02 16:45:38 +00:00
|
|
|
this.hideReadOnlyContent();
|
2012-06-18 20:12:32 +00:00
|
|
|
this.mutePageContent();
|
|
|
|
this.mutePageTitle();
|
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
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
this.load( [ 'site', 'user' ] );
|
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
|
|
|
*/
|
2014-12-03 00:39:56 +00:00
|
|
|
ve.init.mw.ViewPageTarget.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.cancel = function ( trackMechanism ) {
|
|
|
|
var abortType, promises = [];
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2014-04-29 14:04:19 +00:00
|
|
|
this.deactivating = true;
|
|
|
|
// User interface changes
|
|
|
|
if ( this.elementsThatHadOurAccessKey ) {
|
|
|
|
this.elementsThatHadOurAccessKey.attr( 'accesskey', ve.msg( 'accesskey-save' ) );
|
|
|
|
}
|
|
|
|
this.restorePage();
|
|
|
|
this.showReadOnlyContent();
|
|
|
|
|
2014-11-25 01:44:24 +00:00
|
|
|
$( document ).off( 'keydown', this.onDocumentKeyDownHandler );
|
|
|
|
|
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
|
|
|
|
if ( this.active ) {
|
2014-11-19 02:58:17 +00:00
|
|
|
this.tearDownBeforeUnloadHandler();
|
2014-04-29 14:04:19 +00:00
|
|
|
// If we got as far as setting up the surface, tear that down
|
2014-07-14 21:32:49 +00:00
|
|
|
promises.push( this.tearDownSurface() );
|
2014-04-29 14:04:19 +00:00
|
|
|
}
|
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
$.when.apply( $, promises ).then( function () {
|
|
|
|
// Show/restore components that are otherwise handled by tearDownSurface
|
|
|
|
this.showPageContent();
|
|
|
|
this.restorePageTitle();
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
// If there is a load in progress, abort it
|
|
|
|
if ( this.loading ) {
|
|
|
|
this.loading.abort();
|
|
|
|
}
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
this.clearState();
|
|
|
|
this.docToSave = null;
|
2014-08-28 01:56:14 +00:00
|
|
|
this.initialEditSummary = new mw.Uri().query.summary;
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
this.deactivating = false;
|
2014-12-03 00:39:56 +00:00
|
|
|
this.activating = false;
|
2014-10-21 01:10:41 +00:00
|
|
|
this.activatingDeferred.reject();
|
2014-04-29 14:04:19 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
mw.hook( 've.deactivationComplete' ).fire( this.edited );
|
|
|
|
}.bind( this ) );
|
2014-04-29 14:04:19 +00:00
|
|
|
};
|
|
|
|
|
2012-06-12 17:32:10 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle failed DOM load event.
|
2012-06-12 17:32:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
2014-02-06 00:19:19 +00:00
|
|
|
* @param {jqXHR|null} jqXHR jQuery XHR object
|
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
|
|
|
* @param {string} status Text status message
|
2014-02-06 00:19:19 +00:00
|
|
|
* @param {Mixed|null} error Thrown exception or HTTP error string
|
2012-06-12 17:32:10 +00:00
|
|
|
*/
|
2014-02-06 00:19:19 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onLoadError = function ( jqXHR, status ) {
|
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 (
|
|
|
|
status !== 'abort' &&
|
2014-03-12 23:39:30 +00:00
|
|
|
( !jqXHR || ( jqXHR.status !== 0 && jqXHR.status !== 504 ) ) &&
|
2014-02-06 00:19:19 +00:00
|
|
|
confirm( ve.msg( 'visualeditor-loadwarning', status ) )
|
|
|
|
) {
|
2012-06-19 19:26:08 +00:00
|
|
|
this.load();
|
2014-03-12 23:39:30 +00:00
|
|
|
} else if (
|
|
|
|
jqXHR && jqXHR.status === 504 &&
|
|
|
|
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();
|
2012-06-19 19:26:08 +00:00
|
|
|
} else {
|
2014-10-29 01:19:52 +00:00
|
|
|
// Something weird happened? Deactivate
|
|
|
|
// TODO: how does this handle load errors triggered from
|
|
|
|
// calling this.loading.abort()?
|
2012-06-19 19:26:08 +00:00
|
|
|
this.activating = false;
|
2014-10-29 01:19:52 +00:00
|
|
|
// 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
|
|
|
/**
|
|
|
|
* Once surface is ready ready, init UI
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSurfaceReady = function () {
|
2014-12-11 00:37:18 +00:00
|
|
|
var surfaceReadyTime = ve.now();
|
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;
|
|
|
|
}
|
2013-12-03 02:21:31 +00:00
|
|
|
this.activating = false;
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getModel().connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
history: 'updateToolbarSaveButtonState'
|
2013-10-11 18:42:46 +00:00
|
|
|
} );
|
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 () {
|
|
|
|
ve.track( 'mwtiming.behavior.firstTransaction', { duration: ve.now() - surfaceReadyTime } );
|
|
|
|
} );
|
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
// Update UI
|
|
|
|
this.transformPageTitle();
|
|
|
|
this.changeDocumentTitle();
|
|
|
|
this.hidePageContent();
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getView().focus();
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-07-18 23:22:37 +00:00
|
|
|
this.setupToolbarSaveButton();
|
|
|
|
this.attachToolbarSaveButton();
|
2013-10-11 18:42:46 +00:00
|
|
|
this.restoreScrollPosition();
|
|
|
|
this.restoreEditSection();
|
|
|
|
this.setupBeforeUnloadHandler();
|
2013-11-13 20:15:44 +00:00
|
|
|
this.maybeShowDialogs();
|
2014-10-21 01:10:41 +00:00
|
|
|
this.activatingDeferred.resolve();
|
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.
|
|
|
|
* @param {jQuery.Event} e Keydown event
|
|
|
|
*/
|
2014-11-25 01:44:24 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onDocumentKeyDown = function ( e ) {
|
|
|
|
if ( e.which === OO.ui.Keys.ESCAPE ) {
|
2014-12-03 00:39:56 +00:00
|
|
|
this.deactivate( false, 'navigate-read' );
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle clicks on the view tab.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jQuery.Event} e Mouse click event
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onViewTabClick = function ( e ) {
|
|
|
|
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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle successful DOM save event.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
2014-01-12 14:23:49 +00:00
|
|
|
* @param {string} html Rendered page HTML from server
|
|
|
|
* @param {string} categoriesHtml Rendered categories HTML from server
|
2014-06-21 01:37:30 +00:00
|
|
|
* @param {number} newid New revision id, undefined if unchanged
|
|
|
|
* @param {boolean} isRedirect Whether this page is a redirect or not
|
|
|
|
* @param {string} displayTitle What HTML to show as the page title
|
2014-11-17 01:00:06 +00:00
|
|
|
* @param {Object} lastModified Object containing user-formatted date
|
|
|
|
and time strings, or undefined if we made no change.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2014-10-31 00:26:32 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSave = function (
|
2014-11-07 00:31:34 +00:00
|
|
|
html, categoriesHtml, newid, isRedirect, displayTitle, lastModified, contentSub
|
2014-10-31 00:26:32 +00:00
|
|
|
) {
|
2014-06-10 17:10:37 +00:00
|
|
|
var newUrlParams, watchChecked;
|
2014-05-28 22:05:17 +00:00
|
|
|
this.saveDeferred.resolve();
|
2012-12-04 21:04:19 +00:00
|
|
|
if ( !this.pageExists || this.restoring ) {
|
|
|
|
// This is a page creation or restoration, refresh the page
|
2012-11-30 23:09:34 +00:00
|
|
|
this.tearDownBeforeUnloadHandler();
|
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...
|
|
|
|
if ( mw.page.watch && mw.page.watch.updateWatchLink ) {
|
2014-06-10 17:10:37 +00:00
|
|
|
watchChecked = this.saveDialog.$saveOptions
|
2013-10-16 22:32:39 +00:00
|
|
|
.find( '.ve-ui-mwSaveDialog-checkboxes' )
|
|
|
|
.find( '#wpWatchthis' )
|
|
|
|
.prop( 'checked' );
|
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
|
|
|
}
|
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
|
|
|
|
);
|
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
|
|
|
};
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveError = function () {
|
|
|
|
this.pageDeletedWarning = false;
|
|
|
|
ve.init.mw.ViewPageTarget.super.prototype.onSaveError.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog message on general error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorEmpty = function () {
|
2014-05-28 22:05:17 +00:00
|
|
|
this.showSaveError( ve.msg( 'visualeditor-saveerror', 'Empty server response' ), false /* prevents reapply */ );
|
2013-11-26 19:29:14 +00:00
|
|
|
};
|
2013-06-30 18:40:57 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog message on spam blacklist error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorSpamBlacklist = function ( editApi ) {
|
|
|
|
this.showSaveError(
|
2014-11-18 22:22:30 +00:00
|
|
|
ve.msg( 'spamprotectiontext' ) + ' ' +
|
|
|
|
ve.msg(
|
|
|
|
'spamprotectionmatch', mw.language.listToText( editApi.spamblacklist.split( '|' ) )
|
|
|
|
),
|
2014-05-28 22:05:17 +00:00
|
|
|
false // prevents reapply
|
2013-11-26 19:29:14 +00:00
|
|
|
);
|
|
|
|
};
|
2013-07-16 14:07:20 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog message on spam blacklist error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorAbuseFilter = function ( editApi ) {
|
2014-05-28 22:05:17 +00:00
|
|
|
this.showSaveError( $( $.parseHTML( editApi.warning ) ) );
|
2013-11-26 19:29:14 +00:00
|
|
|
// Don't disable the save button. If the action is not disallowed the user may save the
|
|
|
|
// edit by pressing Save again. The AbuseFilter API currently has no way to distinguish
|
|
|
|
// between filter triggers that are and aren't disallowing the action.
|
|
|
|
};
|
2013-07-17 01:11:19 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog when token fetch indicates another user is logged in
|
|
|
|
*
|
|
|
|
* @method
|
2014-11-22 02:19:14 +00:00
|
|
|
* @param {string|null} username Name of newly logged-in user, or null if anonymous
|
2013-11-26 19:29:14 +00:00
|
|
|
*/
|
2014-11-22 02:19:14 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorNewUser = function ( username ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
var badToken, userMsg;
|
|
|
|
badToken = document.createTextNode( mw.msg( 'visualeditor-savedialog-error-badtoken' ) + ' ' );
|
|
|
|
// mediawiki.jqueryMsg has a bug with [[User:$1|$1]] (bug 51388)
|
2014-11-22 02:19:14 +00:00
|
|
|
if ( username === null ) {
|
2013-11-26 19:29:14 +00:00
|
|
|
userMsg = 'visualeditor-savedialog-identify-anon';
|
|
|
|
} else {
|
2014-11-22 02:19:14 +00:00
|
|
|
userMsg = 'visualeditor-savedialog-identify-user---' + username;
|
2013-07-11 18:10:59 +00:00
|
|
|
}
|
2013-11-26 19:29:14 +00:00
|
|
|
this.showSaveError(
|
2014-05-28 22:05:17 +00:00
|
|
|
$( badToken ).add( $.parseHTML( mw.message( userMsg ).parse() ) )
|
2013-11-26 19:29:14 +00:00
|
|
|
);
|
|
|
|
};
|
2013-07-11 18:10:59 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog on captcha error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorCaptcha = function ( editApi ) {
|
2014-04-23 22:24:46 +00:00
|
|
|
var $captchaDiv = $( '<div>' ), $captchaParagraph = $( '<p>' );
|
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
this.captcha = {
|
|
|
|
input: new OO.ui.TextInputWidget(),
|
|
|
|
id: editApi.captcha.id
|
|
|
|
};
|
2014-04-23 22:24:46 +00:00
|
|
|
$captchaDiv.append( $captchaParagraph );
|
|
|
|
$captchaParagraph.append(
|
|
|
|
$( '<strong>' ).text( mw.msg( 'captcha-label' ) ),
|
|
|
|
document.createTextNode( mw.msg( 'colon-separator' ) )
|
2013-11-26 19:29:14 +00:00
|
|
|
);
|
2014-04-23 22:24:46 +00:00
|
|
|
if ( editApi.captcha.url ) { // FancyCaptcha
|
|
|
|
$captchaParagraph.append(
|
|
|
|
$( $.parseHTML( mw.message( 'fancycaptcha-edit' ).parse() ) )
|
|
|
|
.filter( 'a' ).attr( 'target', '_blank' ).end()
|
|
|
|
);
|
|
|
|
$captchaDiv.append(
|
|
|
|
$( '<img>' ).attr( 'src', editApi.captcha.url )
|
|
|
|
);
|
2014-04-24 19:17:21 +00:00
|
|
|
} else if ( editApi.captcha.type === 'simple' || editApi.captcha.type === 'math' ) {
|
|
|
|
// SimpleCaptcha and MathCaptcha
|
2014-04-23 22:24:46 +00:00
|
|
|
$captchaParagraph.append(
|
|
|
|
mw.message( 'captcha-edit' ).parse(),
|
|
|
|
'<br>',
|
|
|
|
document.createTextNode( editApi.captcha.question )
|
|
|
|
);
|
2014-04-24 19:17:21 +00:00
|
|
|
} else if ( editApi.captcha.type === 'question' ) {
|
|
|
|
// QuestyCaptcha
|
|
|
|
$captchaParagraph.append(
|
|
|
|
mw.message( 'questycaptcha-edit' ).parse(),
|
|
|
|
'<br>',
|
|
|
|
editApi.captcha.question
|
|
|
|
);
|
2014-04-23 22:24:46 +00:00
|
|
|
}
|
2014-04-24 19:17:21 +00:00
|
|
|
|
2014-04-23 22:24:46 +00:00
|
|
|
$captchaDiv.append( this.captcha.input.$element );
|
2014-05-28 22:05:17 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
// ProcessDialog's error system isn't great for this yet.
|
2014-05-28 22:05:17 +00:00
|
|
|
this.saveDialog.clearMessage( 'api-save-error' );
|
|
|
|
this.saveDialog.showMessage( 'api-save-error', $captchaDiv );
|
|
|
|
this.saveDialog.popPending();
|
2013-11-26 19:29:14 +00:00
|
|
|
};
|
2013-07-11 18:10:59 +00:00
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog message on unknown error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} editApi
|
|
|
|
* @param {Object|null} data API response data
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorUnknown = function ( editApi, data ) {
|
|
|
|
this.showSaveError(
|
2014-05-28 22:05:17 +00:00
|
|
|
$( document.createTextNode(
|
2013-07-30 23:45:13 +00:00
|
|
|
( editApi && editApi.info ) ||
|
2013-11-26 19:29:14 +00:00
|
|
|
( data.error && data.error.info ) ||
|
|
|
|
( editApi && editApi.code ) ||
|
|
|
|
( data.error && data.error.code ) ||
|
|
|
|
'Unknown error'
|
2014-05-28 22:05:17 +00:00
|
|
|
) ),
|
|
|
|
false // prevents reapply
|
2013-06-30 18:40:57 +00:00
|
|
|
);
|
2012-06-12 17:32:10 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog message on page deleted error
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveErrorPageDeleted = function () {
|
2014-11-27 20:33:35 +00:00
|
|
|
var continueLabel = mw.msg( 'ooui-dialog-process-continue' );
|
|
|
|
|
2014-10-30 00:36:02 +00:00
|
|
|
this.pageDeletedWarning = true;
|
2014-11-27 20:33:35 +00:00
|
|
|
this.showSaveError( mw.msg( 'visualeditor-recreate', continueLabel ), true, true );
|
2014-10-30 00:36:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle MWSaveDialog retry events
|
|
|
|
* So we can handle trying to save again after page deletion warnings
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveRetry = function () {
|
|
|
|
if ( this.pageDeletedWarning ) {
|
|
|
|
this.recreating = true;
|
|
|
|
this.pageExists = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-26 19:29:14 +00:00
|
|
|
/**
|
|
|
|
* Update save dialog api-save-error message
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string|jQuery|Node[]} msg Message content (string of HTML, jQuery object or array of
|
|
|
|
* Node objects)
|
2014-05-28 22:05:17 +00:00
|
|
|
* @param {boolean} [allowReapply=true] Whether or not to allow the user to reapply.
|
|
|
|
* Reset when swapping panels. Assumed to be true unless explicitly set to false.
|
2014-10-30 00:36:02 +00:00
|
|
|
* @param {boolean} [warning=false] Whether or not this is a warning.
|
2013-11-26 19:29:14 +00:00
|
|
|
*/
|
2014-10-30 00:36:02 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.showSaveError = function ( msg, allowReapply, warning ) {
|
|
|
|
this.saveDeferred.reject( [ new OO.ui.Error( msg, { recoverable: allowReapply, warning: warning } ) ] );
|
2013-11-26 19:29:14 +00:00
|
|
|
};
|
|
|
|
|
2012-12-07 16:23:23 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle Show changes event.
|
2012-12-07 16:23:23 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} diffHtml
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onShowChanges = function ( diffHtml ) {
|
2013-05-08 18:17:50 +00:00
|
|
|
// Invalidate the viewer diff on next change
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getModel().getDocument().once( 'transact',
|
2014-07-08 22:33:32 +00:00
|
|
|
this.saveDialog.clearDiff.bind( this.saveDialog )
|
2013-11-14 23:14:16 +00:00
|
|
|
);
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog.setDiffAndReview( diffHtml );
|
2012-12-07 16:23:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle failed show changes event.
|
2012-12-07 16:23:23 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Object} jqXHR
|
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
|
|
|
* @param {string} status Text status message
|
2012-12-07 16:23:23 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onShowChangesError = function ( jqXHR, status ) {
|
|
|
|
alert( ve.msg( 'visualeditor-differror', status ) );
|
2014-04-18 20:32:25 +00:00
|
|
|
this.saveDialog.popPending();
|
2012-12-07 16:23:23 +00:00
|
|
|
};
|
|
|
|
|
2013-04-24 00:01:44 +00:00
|
|
|
/**
|
|
|
|
* Called if a call to target.serialize() failed.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {jqXHR|null} jqXHR
|
|
|
|
* @param {string} status Text status message
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSerializeError = function ( jqXHR, status ) {
|
|
|
|
alert( ve.msg( 'visualeditor-serializeerror', status ) );
|
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
|
|
|
};
|
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle edit conflict event.
|
2012-11-28 23:57:00 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onEditConflict = function () {
|
2014-04-18 20:32:25 +00:00
|
|
|
this.saveDialog.popPending();
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog.swapPanel( 'conflict' );
|
2012-11-28 23:57:00 +00:00
|
|
|
};
|
|
|
|
|
2013-05-14 17:40:00 +00:00
|
|
|
/**
|
|
|
|
* Handle failed show changes event.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onNoChanges = function () {
|
2014-04-18 20:32:25 +00:00
|
|
|
this.saveDialog.popPending();
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog.swapPanel( 'nochanges' );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.saveDialog.getActions().setAbilities( { approve: true } );
|
2013-05-14 17:40:00 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Handle clicks on the save button in the toolbar.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
* @param {jQuery.Event} e Mouse click event
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
Make use of new jshint options
* Restricting "camelcase":
No changes, we were passing all of these already
* Explicitly unrestricting "forin" and "plusplus"
These are off by default in node-jshint, but some distro of jshint
and editors that use their own wrapper around jshint instead of
node-jshint (Eclipse?) may have different defaults. Therefor
setting them to false explicitly. This also serves as a reminder
for the future so we'll always know we don't pass that, in case
we would want to change that.
* Fix order ("quotemark" before "regexp")
* Restricting "unused"
We're not passing all of this, which is why I've set it to false
for now. But I did put it in .jshintrc as placeholder.
I've fixed most of them, there's some left where there is no clean
solution.
* While at it fix a few issues:
- Unused variables ($target, $window)
- Bad practices (using jQuery context for find instead of creation)
- Redundant /*global */ comments
- Parameters that are not used and don't have documentation either
- Lines longer than 100 chars @ 4 spaces/tab
* Note:
- ve.ce.Surface.prototype.onChange takes two arguments but never
uses the former. And even the second one can be null/undefined.
Aside from that, the .change() function emits
another event for the transaction already. Looks like this
should be refactored a bit, two more separated events probably
or one that is actually used better.
- Also cleaned up a lot of comments, some of which were missing,
others were incorrect
- Reworked the contentChange event so we are no longer using the
word new as an object key; expanded a complex object into multiple
arguments being passed through the event to make it easier to work
with and document
Change-Id: I8490815a508c6c379d5f9a743bb4aefd14576aa6
2012-08-07 06:02:18 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onToolbarSaveButtonClick = function () {
|
2012-12-04 21:04:19 +00:00
|
|
|
if ( this.edited || this.restoring ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.showSaveDialog();
|
2012-06-12 17:32:10 +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
|
|
|
|
*/
|
2013-10-02 00:00:57 +00:00
|
|
|
ve.init.mw.ViewPageTarget.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-03-15 15:51:22 +00:00
|
|
|
/**
|
2013-06-23 23:09:47 +00:00
|
|
|
* Re-evaluate whether the toolbar save button should be disabled or not.
|
2013-03-15 15:51:22 +00:00
|
|
|
*/
|
2013-06-23 23:09:47 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.updateToolbarSaveButtonState = function () {
|
2014-05-25 19:13:51 +00:00
|
|
|
var isDisabled;
|
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
this.edited = this.getSurface().getModel().hasBeenModified();
|
2013-06-23 23:09:47 +00:00
|
|
|
// Disable the save button if we have no history or if the sanity check is not finished
|
2014-05-25 19:13:51 +00:00
|
|
|
isDisabled = ( !this.edited && !this.restoring ) || !this.sanityCheckFinished;
|
|
|
|
this.toolbarSaveButton.setDisabled( isDisabled );
|
2013-11-01 19:45:59 +00:00
|
|
|
this.toolbarSaveButton.$element.toggleClass( 've-init-mw-viewPageTarget-waiting', !this.sanityCheckFinished );
|
2014-05-25 19:13:51 +00:00
|
|
|
mw.hook( 've.toolbarSaveButton.stateChanged' ).fire( isDisabled );
|
2013-03-15 15:51:22 +00:00
|
|
|
};
|
|
|
|
|
2013-06-07 19:00:38 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the review button in the save dialog.
|
|
|
|
*
|
|
|
|
* @method
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires saveReview
|
2013-06-07 19:00:38 +00:00
|
|
|
*/
|
2013-10-07 10:01:43 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveDialogReview = function () {
|
|
|
|
this.sanityCheckVerified = true;
|
|
|
|
this.saveDialog.setSanityCheck( this.sanityCheckVerified );
|
|
|
|
|
|
|
|
if ( !this.saveDialog.$reviewViewer.find( 'table, pre' ).length ) {
|
2013-12-10 01:39:46 +00:00
|
|
|
this.emit( 'saveReview' );
|
2014-08-22 20:50:48 +00:00
|
|
|
this.saveDialog.getActions().setAbilities( { approve: false } );
|
2014-04-18 20:32:25 +00:00
|
|
|
this.saveDialog.pushPending();
|
2013-10-07 10:01:43 +00:00
|
|
|
if ( this.pageExists ) {
|
|
|
|
// Has no callback, handled via target.onShowChanges
|
2013-11-06 08:22:11 +00:00
|
|
|
this.showChanges( this.docToSave );
|
2013-10-07 10:01:43 +00:00
|
|
|
} else {
|
2014-07-08 22:33:32 +00:00
|
|
|
this.serialize( this.docToSave, this.onSaveDialogReviewComplete.bind( this ) );
|
2013-10-07 10:01:43 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.saveDialog.swapPanel( 'review' );
|
|
|
|
}
|
2013-06-07 19:00:38 +00:00
|
|
|
};
|
|
|
|
|
2014-03-12 19:05:02 +00:00
|
|
|
/**
|
|
|
|
* Handle completed serialize request for diff views for new page creations.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} wikitext
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveDialogReviewComplete = function ( wikitext ) {
|
|
|
|
// Invalidate the viewer wikitext on next change
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getModel().getDocument().once( 'transact',
|
2014-07-08 22:33:32 +00:00
|
|
|
this.saveDialog.clearDiff.bind( this.saveDialog )
|
2014-03-12 19:05:02 +00:00
|
|
|
);
|
|
|
|
this.saveDialog.setDiffAndReview( $( '<pre>' ).text( wikitext ) );
|
|
|
|
};
|
|
|
|
|
mw.ViewPageTarget: Refetch token if session expired
* Rephrased visualeditor-savedialog-error-badtoken to emphasise
that it is the old session that become invalid, not the one
the user started browsing with since in a different window.
* If the session changed, the user will be asked whether they
agree to save with this new session instead.
* We explictly update mw.config so that future save attempts
in the same window compare against the correct environment.
Without this there are two problems when saving and then
making a second edit in the same window and saving that:
- It will bring up the same question again (user A -> user B),
which is annoying.
- If the user logged back in again (new session, but for
user A again) it would silently try with that new token
without asking, thus saving as user A when the user still
thinks it switched to user B. It switching back automatically
is not obvious since we asked them from A->B, so we should
also ask the other way around.
This can be reproduced by opending ve-edit logged-in, then
logging out in a new window, save, confirm anon, save,
open edit again, log back in in a new window, save open edit
in the old window, confirm new logged-in, save.
Bug: 50424
Change-Id: Id055eca1886f85aeaf615f645de29898afc0373c
2013-07-12 18:27:35 +00:00
|
|
|
/**
|
|
|
|
* Try to save the current document.
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires saveInitiated
|
2014-05-28 22:05:17 +00:00
|
|
|
* @param {jQuery.Deferred} saveDeferred Deferred object to resolve/reject when the save
|
|
|
|
* succeeds/fails.
|
mw.ViewPageTarget: Refetch token if session expired
* Rephrased visualeditor-savedialog-error-badtoken to emphasise
that it is the old session that become invalid, not the one
the user started browsing with since in a different window.
* If the session changed, the user will be asked whether they
agree to save with this new session instead.
* We explictly update mw.config so that future save attempts
in the same window compare against the correct environment.
Without this there are two problems when saving and then
making a second edit in the same window and saving that:
- It will bring up the same question again (user A -> user B),
which is annoying.
- If the user logged back in again (new session, but for
user A again) it would silently try with that new token
without asking, thus saving as user A when the user still
thinks it switched to user B. It switching back automatically
is not obvious since we asked them from A->B, so we should
also ask the other way around.
This can be reproduced by opending ve-edit logged-in, then
logging out in a new window, save, confirm anon, save,
open edit again, log back in in a new window, save open edit
in the old window, confirm new logged-in, save.
Bug: 50424
Change-Id: Id055eca1886f85aeaf615f645de29898afc0373c
2013-07-12 18:27:35 +00:00
|
|
|
*/
|
2014-05-28 22:05:17 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.saveDocument = function ( saveDeferred ) {
|
2014-07-16 16:50:41 +00:00
|
|
|
if ( this.deactivating ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-06 08:22:11 +00:00
|
|
|
var saveOptions = this.getSaveOptions();
|
2013-12-10 01:39:46 +00:00
|
|
|
this.emit( 'saveInitiated' );
|
2013-06-29 01:52:29 +00:00
|
|
|
|
2013-10-11 22:00:10 +00:00
|
|
|
// Reset any old captcha data
|
2013-06-29 01:52:29 +00:00
|
|
|
if ( this.captcha ) {
|
2013-10-15 07:30:30 +00:00
|
|
|
this.saveDialog.clearMessage( 'captcha' );
|
2013-06-29 01:52:29 +00:00
|
|
|
delete this.captcha;
|
|
|
|
}
|
|
|
|
|
2013-05-17 14:27:33 +00:00
|
|
|
if (
|
|
|
|
+mw.user.options.get( 'forceeditsummary' ) &&
|
|
|
|
saveOptions.summary === '' &&
|
2013-10-07 10:01:43 +00:00
|
|
|
!this.saveDialog.messages.missingsummary
|
2013-05-17 14:27:33 +00:00
|
|
|
) {
|
2013-10-07 10:01:43 +00:00
|
|
|
this.saveDialog.showMessage(
|
2013-06-30 18:40:57 +00:00
|
|
|
'missingsummary',
|
|
|
|
// Wrap manually since this core message already includes a bold "Warning:" label
|
|
|
|
$( '<p>' ).append( ve.init.platform.getParsedMessage( 'missingsummary' ) ),
|
|
|
|
{ wrap: false }
|
|
|
|
);
|
2014-07-01 14:53:27 +00:00
|
|
|
this.saveDialog.popPending();
|
2013-05-17 14:27:33 +00:00
|
|
|
} else {
|
2013-11-06 08:22:11 +00:00
|
|
|
this.save( this.docToSave, saveOptions );
|
2014-05-28 22:05:17 +00:00
|
|
|
this.saveDeferred = saveDeferred;
|
2013-05-17 14:27:33 +00:00
|
|
|
}
|
2012-12-07 16:23:23 +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
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.editSource = function () {
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( !this.getSurface().getModel().hasBeenModified() ) {
|
2014-07-07 19:51:41 +00:00
|
|
|
this.switchToWikitextEditor( true );
|
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
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().openWindow( 'wikitextswitchconfirm', { target: this } );
|
2013-09-06 00:10:06 +00:00
|
|
|
};
|
|
|
|
|
2013-05-14 16:50:29 +00:00
|
|
|
/**
|
|
|
|
* Handle clicks on the resolve conflict button in the conflict dialog.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-11-06 08:22:11 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveDialogResolveConflict = function () {
|
2013-05-14 16:50:29 +00:00
|
|
|
// Get Wikitext from the DOM, and set up a submit call when it's done
|
|
|
|
this.serialize(
|
2013-11-06 08:22:11 +00:00
|
|
|
this.docToSave,
|
2014-08-22 20:50:48 +00:00
|
|
|
this.submitWithSaveFields.bind( this, { wpSave: 1 } )
|
2013-05-14 16:50:29 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2012-11-28 23:57:00 +00:00
|
|
|
/**
|
2013-11-15 20:30:57 +00:00
|
|
|
* Get save form fields from the save dialog form.
|
|
|
|
* @returns {Object} Form data for submission to the MediaWiki action=edit UI
|
2012-11-28 23:57:00 +00:00
|
|
|
*/
|
2013-11-15 20:30:57 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.getSaveFields = function () {
|
|
|
|
var fields = {};
|
2013-11-15 21:31:40 +00:00
|
|
|
this.$checkboxes
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
.each( function () {
|
|
|
|
var $this = $( this );
|
|
|
|
// We can't just use $this.val() because .val() always returns the value attribute of
|
|
|
|
// a checkbox even when it's unchecked
|
2013-12-18 23:32:49 +00:00
|
|
|
if ( $this.prop ( 'name' ) && ( $this.prop( 'type' ) !== 'checkbox' || $this.prop( 'checked' ) ) ) {
|
2013-11-15 20:30:57 +00:00
|
|
|
fields[$this.prop( 'name' )] = $this.val();
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-02-20 21:30:29 +00:00
|
|
|
ve.extendObject( fields, {
|
2014-08-22 20:50:48 +00:00
|
|
|
wpSummary: this.saveDialog ? this.saveDialog.editSummaryInput.getValue() : this.initialEditSummary,
|
|
|
|
wpCaptchaId: this.captcha && this.captcha.id,
|
|
|
|
wpCaptchaWord: this.captcha && this.captcha.input.getValue()
|
2013-11-15 20:30:57 +00:00
|
|
|
} );
|
2014-10-30 00:36:02 +00:00
|
|
|
if ( this.recreating ) {
|
|
|
|
fields.wpRecreate = true;
|
|
|
|
}
|
2013-11-15 20:30:57 +00:00
|
|
|
return fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoke #submit with the data from #getSaveFields
|
|
|
|
* @param {Object} fields Fields to add in addition to those from #getSaveFields
|
|
|
|
* @param {string} wikitext Wikitext to submit
|
|
|
|
* @returns {boolean} Whether submission was started
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.submitWithSaveFields = function ( fields, wikitext ) {
|
|
|
|
return this.submit( wikitext, $.extend( this.getSaveFields(), fields ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get edit API options from the save dialog form.
|
|
|
|
* @returns {Object} Save options for submission to the MediaWiki API
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.getSaveOptions = function () {
|
|
|
|
var key, options = this.getSaveFields(),
|
|
|
|
fieldMap = {
|
2014-08-22 20:50:48 +00:00
|
|
|
wpSummary: 'summary',
|
|
|
|
wpMinoredit: 'minor',
|
|
|
|
wpWatchthis: 'watch',
|
|
|
|
wpCaptchaId: 'captchaid',
|
|
|
|
wpCaptchaWord: 'captchaword'
|
2013-11-15 20:30:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for ( key in fieldMap ) {
|
|
|
|
if ( options[key] !== undefined ) {
|
|
|
|
options[fieldMap[key]] = options[key];
|
|
|
|
delete options[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( this.sanityCheckPromise.state() === 'rejected' ) {
|
|
|
|
options.needcheck = 1;
|
|
|
|
}
|
|
|
|
|
Render check boxes from EditPage
EditPage has a lovely getCheckboxes() function which includes the
minor and watch checkboxes as rendered by MW core, as well as any
checkboxes extensions like FlaggedRevs might have added. Output
these in the API, render them, and send their values back.
ApiVisualEditor.php:
* Build a fake EditPage, get its checkboxes, and return them
ApiVisualEditorEdit.php:
* Pass through posted request data to ApiEdit, which passes it
through to EditPage thanks to Idab5b524b0e3 in core
ve.init.mw.ViewPageTarget.js:
* Remove minor and watch checkboxes from the save dialog template
and replace them with a generic checkbox container
* Have getSaveOptions() pull the state of all checkboxes in
** Special-case minor and watch, and pass the rest straight through
** Move normalization from true/false to presence/absence here, from
ve.init.mw.Target.prototype.save(), because here we know which ones
are checkboxes and we don't know that in save() without
special-casing
* Remove getSaveDialogHtml(), we don't need to hide checkboxes based on
rights anymore because in that case the API just won't send them to us.
** Moved logic for checking the watch checkbox down to where the same
logic for the minor checkbox already is
* Unwrap getSaveDialogHtml() in setupSaveDialog()
* Access minor and watch by their new IDs throughout
ve.init.mw.Target.js:
* Get and store checkboxes from the API
* Pass all keys straight through to the API
Bug: 49699
Change-Id: I09d02a42b05146bc9b7080ab38338ae869bf15e3
2013-07-24 06:39:03 +00:00
|
|
|
return options;
|
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
|
|
|
*
|
|
|
|
* @method
|
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
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.tearDownSurface = function () {
|
2014-07-14 21:32:49 +00:00
|
|
|
var promises = [];
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Update UI
|
2013-05-14 23:45:42 +00:00
|
|
|
this.tearDownToolbar();
|
2014-06-06 10:04:24 +00:00
|
|
|
this.tearDownDebugBar();
|
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
|
|
|
|
|
|
|
return $.when.apply( $, promises ).then( function () {
|
|
|
|
// Destroy surface
|
2014-11-27 20:51:04 +00:00
|
|
|
while ( this.surfaces.length ) {
|
|
|
|
this.surfaces.pop().destroy();
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
this.active = false;
|
|
|
|
}.bind( this ) );
|
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.
|
2013-07-03 22:14:52 +00:00
|
|
|
* Edit tab is bound outside the module in mw.ViewPageTarget.init.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.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' )
|
2014-07-08 22:33:32 +00:00
|
|
|
.click( this.onViewTabClick.bind( this ) );
|
2014-06-25 20:13:11 +00:00
|
|
|
|
|
|
|
$( '#ca-viewsource, #ca-edit' ).click( function ( e ) {
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( target.getSurface() && !target.deactivating ) {
|
|
|
|
target.editSource();
|
2014-07-18 20:28:35 +00:00
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( target.getSurface().getModel().hasBeenModified() ) {
|
2014-07-22 22:21:29 +00:00
|
|
|
e.preventDefault();
|
|
|
|
}
|
2014-07-01 00:01:39 +00:00
|
|
|
}
|
2014-06-25 20:13:11 +00:00
|
|
|
} );
|
2012-06-18 21:13:26 +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.
|
2013-07-05 06:01:31 +00:00
|
|
|
* Dummy replaced by init.js so that we can call it again from #onSave after
|
|
|
|
* replacing the page contents with the new html.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2013-07-05 06:01:31 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.setupSectionEditLinks = null;
|
2012-06-18 20:12:32 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-18 23:22:37 +00:00
|
|
|
* Add content and event bindings to toolbar save button.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2014-07-18 23:22:37 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.setupToolbarSaveButton = function () {
|
2014-01-17 14:24:12 +00:00
|
|
|
this.toolbarSaveButton = new OO.ui.ButtonWidget( {
|
2014-08-22 20:50:48 +00:00
|
|
|
label: ve.msg( 'visualeditor-toolbar-savedialog' ),
|
|
|
|
flags: ['constructive'],
|
|
|
|
disabled: !this.restoring
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
} );
|
2014-01-30 19:33:30 +00:00
|
|
|
|
2014-08-20 15:26:36 +00:00
|
|
|
// NOTE (phuedx, 2014-08-20): This class is used by the firsteditve guided
|
|
|
|
// tour to attach a guider to the "Save page" button.
|
|
|
|
this.toolbarSaveButton.$element.addClass( 've-ui-toolbar-saveButton' );
|
|
|
|
|
2014-01-30 19:33:30 +00:00
|
|
|
if ( ve.msg( 'accesskey-save' ) !== '-' && ve.msg( 'accesskey-save' ) !== '' ) {
|
|
|
|
// FlaggedRevs tries to use this - it's useless on VE pages because all that stuff gets hidden, but it will still conflict so get rid of it
|
|
|
|
this.elementsThatHadOurAccessKey = $( '[accesskey="' + ve.msg( 'accesskey-save' ) + '"]' ).removeAttr( 'accesskey' );
|
|
|
|
this.toolbarSaveButton.$button.attr( 'accesskey', ve.msg( 'accesskey-save' ) );
|
|
|
|
}
|
|
|
|
|
2013-06-23 23:09:47 +00:00
|
|
|
this.updateToolbarSaveButtonState();
|
Major UI refactoring and improvements
Objective:
Refactor UI widgets, improve usability and accessibility of menus, general cleanup and style improvements.
Extras:
Fixed documentation in a few other files to make descriptions of jQuery event arguments more consistent, classes inherit correctly, and made use of the @cfg functionality in jsduck.
Changes:
.docs/config.json
* Added window, HTMLDocument, HTMLElement, DocumentFragment and XMLHttpRequest to externals, so jsduck doesn't throw warnings when they are used
demos/ve/index.php, modules/ve/test/index.php, VisualEditor.php
* Moved widgets above tools (since tools use widgets)
demos/ve/index.php
* Refactored widget initialization to use options
* Renamed variables to match widget names
ve.init.mw.ViewPageTarget.css
* Adjusted text sizes to make widgets work normally
* Added margins for buttons in toolbar (since button widgets
don't have any)
* Removed styles for init buttons (button widgets now)
ve.init.mw.ViewPageTarget.js
* Switched to using button widgets (involved moving things around
a bit)
ve.ui.LinkInspector.js, ve.ui.MWLinkInspector.js
* Renamed static property "inputWidget" to
"linkTargetInputWidget" to better reflect the required base class
for the properties value
icons.ai, check.png, check.svg
* Added "check" icon, used in menu right now to show which item
is selected
ve.ui.Icons-raster.css, ve.ui.Icons-vector.css
* Added check icon
* Removed :before pseudo selectors from most of the icon classes (not need by button tool anymore, makes them more reusable now)
ve.ui.Tool.css
* Adjusted drop down tool styles so menu appears below, instead
of on top, of the label
* Adjusted paragraph font size to better match actual content
* Updated class names to still work with menu widget changes
(items are their own widgets now)
* Updated selectors as per changes in the structure of button tools
ve.ui.Widget.css
* Added styles for buttons and menu items
* Adjusted menu styles
ve.ui.*ButtonTool.js
* Added config options argument passthrough
ve.ui.ButtonTool.js
* Moved var statement to the top inside constructor
* Switched to using "a" tag to get cross-browser :active support
* Added icon to inside of button to make icon styles more reusable
* Removed disabled support (now provided by widget parent class)
ve.ui.FormatDropDownTool.js
* Updated options initialization to construct menu item objects
* Modified handling of items to account for changes in menu and
item classes
* Optimized onUpdateState method a bit, adding early exit to
inner loop
ve.ui.ButtonTool.js, ve.ui.DropdownTool.js, ve.ui.Context.js,
ve.ui.Frame, ve.ui.Tool.js, ve.ui.Widget.js
* Added chain ability to non-getter methods
ve.ui.DropdownTool.js
* Removed items argument to constructor
* Updated code as per changes in menu class
* Fixed inconsistent naming of event handler methods
* Removed item event handling (now handled by items directly)
* Made use of this.$$ to ensure tool works in other frames
ve.ui.Tool.js
* Made tools inherit from widget
* Moved trigger registry event handler to a method
ve.ui.Context.js
* Switched from using menu to contain toolbar to a simple wrapper
ve.ui.js
* Added get$$ method, a convenience function for binding jQuery
to a specific document context
ve.ui.*Widget.js
* Switched to using a config options object instead of individual arguments
* Added options
* Factored out flags and labels into their own classes
* Refactored value setting methods for inputs
ve.ui.MenuWidget.js, ve.ui.MenuItemWidget.js
* Broke items out into their own classes
* Redesigned API
* Updated code that uses these classes
* Added support for keyboard interaction
* Made items flash when selected (delaying the hiding of the menu for 200ms)
ve.ui.LinkTargetInputWidget.js, ve.ui.MWLinkTargetInputWidget
* Refactored annotation setting methods
Change-Id: I7769bd5a5b79f1ab36f258ef9f2be583ca503ce6
2013-02-20 23:25:12 +00:00
|
|
|
|
2014-08-22 20:50:48 +00:00
|
|
|
this.toolbarSaveButton.connect( this, { click: 'onToolbarSaveButtonClick' } );
|
2012-11-30 23:09:34 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Add the save button to the user interface.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2014-07-18 23:22:37 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.attachToolbarSaveButton = function () {
|
2013-10-17 17:35:16 +00:00
|
|
|
var $actionTools = $( '<div>' ),
|
|
|
|
$pushButtons = $( '<div>' ),
|
2014-12-03 00:04:07 +00:00
|
|
|
actions = new ve.ui.TargetToolbar( this );
|
2013-06-12 01:17:10 +00:00
|
|
|
|
2013-10-17 22:09:48 +00:00
|
|
|
actions.setup( [
|
2014-08-22 20:50:48 +00:00
|
|
|
{ include: [ 'help', 'notices' ] },
|
2013-10-17 22:09:48 +00:00
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
type: 'list',
|
|
|
|
icon: 'menu',
|
|
|
|
title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
2014-12-03 18:32:45 +00:00
|
|
|
include: [ 'meta', 'settings', 'advancedSettings', 'categories', 'languages', 'editModeSource', 'findAndReplace' ]
|
2014-01-13 14:56:49 +00:00
|
|
|
}
|
2014-12-03 00:04:07 +00:00
|
|
|
], this.getSurface() );
|
2013-10-17 17:35:16 +00:00
|
|
|
|
|
|
|
$actionTools
|
2014-11-21 13:00:50 +00:00
|
|
|
.addClass( 've-init-mw-viewPageTarget-toolbar-utilities' )
|
2013-11-01 19:45:59 +00:00
|
|
|
.append( actions.$element );
|
2013-10-02 00:00:57 +00:00
|
|
|
|
|
|
|
$pushButtons
|
|
|
|
.addClass( 've-init-mw-viewPageTarget-toolbar-actions' )
|
2014-07-18 23:22:37 +00:00
|
|
|
.append( this.toolbarSaveButton.$element );
|
2013-10-02 00:00:57 +00:00
|
|
|
|
2013-10-17 17:35:16 +00:00
|
|
|
this.toolbar.$actions.append( $actionTools, $pushButtons );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2012-12-11 23:19:21 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Show the save dialog.
|
2012-12-11 23:19:21 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires saveWorkflowBegin
|
2012-12-11 23:19:21 +00:00
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.showSaveDialog = function () {
|
2014-10-29 01:19:52 +00:00
|
|
|
this.emit( 'saveWorkflowBegin' );
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().getWindow( 'mwSave' ).then( function ( win ) {
|
|
|
|
var currentWindow = this.getSurface().getContext().getInspectors().getCurrentWindow(),
|
2014-10-29 01:43:03 +00:00
|
|
|
target = this;
|
2014-11-27 20:51:04 +00:00
|
|
|
this.origSelection = this.getSurface().getModel().getSelection();
|
2014-02-12 14:14:23 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
// Make sure any open inspectors are closed
|
|
|
|
if ( currentWindow ) {
|
|
|
|
currentWindow.close();
|
|
|
|
}
|
2013-11-06 08:22:11 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
// Preload the serialization
|
|
|
|
if ( !this.docToSave ) {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.docToSave = ve.dm.converter.getDomFromModel( this.getSurface().getModel().getDocument() );
|
2014-07-14 21:32:49 +00:00
|
|
|
}
|
|
|
|
this.prepareCacheKey( this.docToSave );
|
2013-11-15 21:34:59 +00:00
|
|
|
|
2014-07-14 21:32:49 +00:00
|
|
|
if ( !this.saveDialog ) {
|
|
|
|
this.saveDialog = win;
|
|
|
|
|
|
|
|
// Connect to save dialog
|
|
|
|
this.saveDialog.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
save: 'saveDocument',
|
|
|
|
review: 'onSaveDialogReview',
|
2014-10-30 00:36:02 +00:00
|
|
|
resolve: 'onSaveDialogResolveConflict',
|
|
|
|
retry: 'onSaveRetry'
|
2014-07-14 21:32:49 +00:00
|
|
|
} );
|
|
|
|
// Setup edit summary and checkboxes
|
|
|
|
this.saveDialog.setEditSummary( this.initialEditSummary );
|
|
|
|
this.saveDialog.setupCheckboxes( this.$checkboxes );
|
|
|
|
}
|
|
|
|
|
|
|
|
this.saveDialog.setSanityCheck( this.sanityCheckVerified );
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().openWindow(
|
2014-08-21 19:00:40 +00:00
|
|
|
this.saveDialog,
|
2014-11-27 20:51:04 +00:00
|
|
|
{ dir: this.getSurface().getModel().getDocument().getLang() }
|
2014-07-25 20:12:35 +00:00
|
|
|
)
|
|
|
|
// Call onSaveDialogClose() when the save dialog starts closing
|
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
|
|
|
.done( function ( opened ) {
|
2014-10-29 01:43:03 +00:00
|
|
|
opened.always( target.onSaveDialogClose.bind( target ) );
|
|
|
|
} );
|
2014-07-14 21:32:49 +00:00
|
|
|
}.bind( this ) );
|
2013-11-07 03:15:47 +00:00
|
|
|
};
|
|
|
|
|
2014-06-12 00:35:46 +00:00
|
|
|
/**
|
|
|
|
* Handle dialog close events.
|
|
|
|
*
|
2013-12-10 01:39:46 +00:00
|
|
|
* @fires saveWorkflowEnd
|
2013-11-07 03:15:47 +00:00
|
|
|
*/
|
2014-07-25 20:12:35 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onSaveDialogClose = function () {
|
2013-11-06 08:22:11 +00:00
|
|
|
// Clear the cached HTML and cache key once the document changes
|
2014-07-08 22:33:32 +00:00
|
|
|
var clear = function () {
|
2013-11-06 08:22:11 +00:00
|
|
|
this.docToSave = null;
|
|
|
|
this.clearPreparedCacheKey();
|
2014-07-08 22:33:32 +00:00
|
|
|
}.bind( this );
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface() ) {
|
|
|
|
this.getSurface().getModel().getDocument().once( 'transact', clear );
|
2013-11-06 08:22:11 +00:00
|
|
|
} else {
|
|
|
|
clear();
|
|
|
|
}
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getModel().setSelection( this.origSelection );
|
2013-12-10 01:39:46 +00:00
|
|
|
this.emit( 'saveWorkflowEnd' );
|
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
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.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
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.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
|
|
|
* Show the page content.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.showPageContent = function () {
|
2012-08-01 00:49:04 +00:00
|
|
|
$( '#bodyContent > .ve-init-mw-viewPageTarget-content' )
|
2012-07-20 23:59:59 +00:00
|
|
|
.removeClass( 've-init-mw-viewPageTarget-content' )
|
2012-06-19 00:39:31 +00:00
|
|
|
.show()
|
|
|
|
.fadeTo( 0, 1 );
|
2014-04-22 22:13:15 +00:00
|
|
|
$( '#t-print, #t-permalink, #p-coll-print_export, #t-cite' ).show();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Mute the page content.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.mutePageContent = function () {
|
2014-01-13 12:29:52 +00:00
|
|
|
$( '#bodyContent > :visible:not(#siteSub)' )
|
2012-07-20 23:59:59 +00:00
|
|
|
.addClass( 've-init-mw-viewPageTarget-content' )
|
2012-06-19 04:47:09 +00:00
|
|
|
.fadeTo( 'fast', 0.6 );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Hide the page content.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.hidePageContent = function () {
|
2014-01-09 01:32:13 +00:00
|
|
|
$( '#bodyContent > :visible:not(#siteSub,.ve-ui-mwTocWidget)' )
|
2012-07-20 23:59:59 +00:00
|
|
|
.addClass( 've-init-mw-viewPageTarget-content' )
|
2012-06-19 00:39:31 +00:00
|
|
|
.hide();
|
2014-04-22 22:13:15 +00:00
|
|
|
$( '#t-print, #t-permalink, #p-coll-print_export, #t-cite' ).hide();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-05-02 16:45:38 +00:00
|
|
|
* Show elements that didn't have a counter-part in the edit view.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2014-05-02 16:45:38 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.showReadOnlyContent = function () {
|
2012-09-05 07:38:19 +00:00
|
|
|
var $toc = $( '#toc' ),
|
|
|
|
$wrap = $toc.parent();
|
|
|
|
if ( $wrap.data( 've.hideTableOfContents' ) ) {
|
2014-01-09 01:32:13 +00:00
|
|
|
$wrap.show( function () {
|
2012-09-05 07:38:19 +00:00
|
|
|
$toc.unwrap();
|
2013-06-24 17:51:59 +00:00
|
|
|
} );
|
2012-09-05 07:38:19 +00:00
|
|
|
}
|
2014-05-02 16:45:38 +00:00
|
|
|
|
|
|
|
$( '#contentSub' ).show();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-05-02 16:45:38 +00:00
|
|
|
* Hide elements that don't have a counter-part in the edit view.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
2014-05-02 16:45:38 +00:00
|
|
|
* Call this when puting the page content, so that when we replace the
|
|
|
|
* muted content with the edit surface, everything aligns in the same
|
|
|
|
* place. If things like contentSub and TOC remain visible in mute mode,
|
|
|
|
* there is an additional visual shift that is unpleasant to the user.
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2014-05-02 16:45:38 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.hideReadOnlyContent = function () {
|
2012-09-05 07:38:19 +00:00
|
|
|
$( '#toc' )
|
|
|
|
.wrap( '<div>' )
|
|
|
|
.parent()
|
|
|
|
.data( 've.hideTableOfContents', true )
|
2014-01-09 01:32:13 +00:00
|
|
|
.hide();
|
2014-05-02 16:45:38 +00:00
|
|
|
|
|
|
|
$( '#contentSub' ).hide();
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Hide the toolbar.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2013-05-14 23:45:42 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.tearDownToolbar = function () {
|
2014-07-08 22:33:32 +00:00
|
|
|
this.toolbar.$bar.slideUp( 'fast', function () {
|
2013-05-14 23:45:42 +00:00
|
|
|
this.toolbar.destroy();
|
|
|
|
this.toolbar = null;
|
2014-07-08 22:33:32 +00:00
|
|
|
}.bind( this ) );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
2014-06-06 10:04:24 +00:00
|
|
|
/**
|
|
|
|
* Hide the debug bar.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.tearDownDebugBar = function () {
|
2014-06-16 22:54:12 +00:00
|
|
|
if ( this.debugBar ) {
|
2014-07-08 22:33:32 +00:00
|
|
|
this.debugBar.$element.slideUp( 'fast', function () {
|
2014-06-16 22:54:12 +00:00
|
|
|
this.debugBar.$element.remove();
|
|
|
|
this.debugBar = null;
|
2014-07-08 22:33:32 +00:00
|
|
|
}.bind( this ) );
|
2014-06-16 22:54:12 +00:00
|
|
|
}
|
2014-06-06 10:04:24 +00:00
|
|
|
};
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/**
|
2013-05-17 15:38:48 +00:00
|
|
|
* Transform the page title into a VE-style title.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.transformPageTitle = function () {
|
2012-07-20 23:59:59 +00:00
|
|
|
$( '#firstHeading' ).addClass( 've-init-mw-viewPageTarget-pageTitle' );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-05-17 15:38:48 +00:00
|
|
|
* Fade the page title to indicate it is not editable.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
Remainder JSHint fixes on modules/ve/*
[jshint]
ce/ve.ce.Surface.js: line 670, col 9, Too many var statements.
ce/ve.ce.Surface.js: line 695, col 6, Missing semicolon.
ce/ve.ce.Surface.js: line 726, col 22, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 726, col 41, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 733, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 734, col 24, Expected '===' and instead saw '=='.
ce/ve.ce.Surface.js: line 1013, col 13, Too many var statements.
ce/ve.ce.Surface.js: line 1019, col 17, Too many var statements.
ce/ve.ce.Surface.js: line 1023, col 18, Too many ar statements.
ce/ve.ce.Surface.js: line 1027, col 13, Too many var statements.
dm/annotations/ve.dm.LinkAnnotation.js: line 70, col 52, Insecure '.'.
dm/ve.dm.Converter.js: line 383, col 29, Empty block.
dm/ve.dm.Converter.js: line 423, col 33, Empty block.
Commands:
* jshint .
* ack '(if|else|function|switch|for|while)\('
* Sublime Text 2:
Find(*): (if|else|function|switch|for|while)\(
Replace: $1 (
* ack ' ' -Q # double spaces, except in certain comments
Change-Id: I8e34bf2924bc8688fdf8acef08bbc4f6707e93be
2012-09-02 21:45:01 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.mutePageTitle = function () {
|
2013-10-06 20:09:33 +00:00
|
|
|
$( '#firstHeading, #siteSub' )
|
|
|
|
.addClass( 've-init-mw-viewPageTarget-transform ve-init-mw-viewPageTarget-transform-muted' );
|
2012-06-18 20:12:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-05-17 15:38:48 +00:00
|
|
|
* Restore the page title to its original style.
|
2012-06-18 20:12:32 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.restorePageTitle = function () {
|
2014-01-13 12:29:52 +00:00
|
|
|
var $els = $( '#firstHeading, #siteSub' )
|
2014-01-13 19:18:42 +00:00
|
|
|
.removeClass( 've-init-mw-viewPageTarget-transform-muted' );
|
2013-10-06 20:09:33 +00:00
|
|
|
|
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
|
|
|
setTimeout( function () {
|
2013-10-06 20:09:33 +00:00
|
|
|
$els.removeClass( 've-init-mw-viewPageTarget-transform' );
|
2012-07-20 23:59:59 +00:00
|
|
|
$( '#firstHeading' ).removeClass( 've-init-mw-viewPageTarget-pageTitle' );
|
2012-06-18 20:12:32 +00:00
|
|
|
}, 1000 );
|
|
|
|
};
|
|
|
|
|
2013-05-17 16:09:20 +00:00
|
|
|
/**
|
|
|
|
* Change the document title to state that we are now editing.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.changeDocumentTitle = function () {
|
|
|
|
document.title = ve.msg(
|
|
|
|
this.pageExists ? 'editing' : 'creating',
|
|
|
|
mw.config.get( 'wgTitle' )
|
|
|
|
) + ' - ' + mw.config.get( 'wgSiteName' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the original document title.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.restoreDocumentTitle = function () {
|
|
|
|
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
|
|
|
*/
|
2013-06-05 21:38:39 +00:00
|
|
|
ve.init.mw.ViewPageTarget.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' );
|
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
|
|
|
|
2013-06-05 21:38:39 +00:00
|
|
|
// Hide site notice (if present)
|
|
|
|
$( '#siteNotice:visible' )
|
|
|
|
.addClass( 've-hide' )
|
|
|
|
.slideUp( 'fast' );
|
2014-09-29 11:45:10 +00:00
|
|
|
// Hide page status indicators (if present)
|
2014-10-29 20:52:38 +00:00
|
|
|
$( '.mw-indicators' )
|
2014-09-29 11:45:10 +00:00
|
|
|
.addClass( 've-hide' )
|
|
|
|
.fadeOut( 'fast' );
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2013-11-26 09:52:12 +00:00
|
|
|
// Add class to document
|
|
|
|
$( 'html' ).addClass( 've-activated' );
|
|
|
|
|
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)
|
2014-11-19 01:10:52 +00:00
|
|
|
if ( !this.actFromPopState && history.pushState && this.currentUri.query.veaction !== 'edit' ) {
|
2014-10-21 01:10:41 +00:00
|
|
|
// Set the current URL
|
2013-06-05 22:39:43 +00:00
|
|
|
uri = this.currentUri;
|
|
|
|
uri.query.veaction = 'edit';
|
|
|
|
|
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
|
|
|
*/
|
2013-06-05 21:38:39 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.restorePage = 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
|
|
|
// 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' );
|
|
|
|
$( '#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();
|
2014-05-14 22:19:39 +00:00
|
|
|
|
2013-06-05 21:38:39 +00:00
|
|
|
// Make site notice visible again (if present)
|
2013-06-24 17:51:59 +00:00
|
|
|
$( '#siteNotice.ve-hide' )
|
2012-06-21 20:01:42 +00:00
|
|
|
.slideDown( 'fast' );
|
2014-09-29 11:45:10 +00:00
|
|
|
// Make page status indicators visible again (if present)
|
|
|
|
$( '.mw-indicators.ve-hide' )
|
|
|
|
.fadeIn( 'fast' );
|
2013-06-05 22:39:43 +00:00
|
|
|
|
2013-11-26 09:52:12 +00:00
|
|
|
// Remove class from document
|
|
|
|
$( 'html' ).removeClass( 've-activated' );
|
|
|
|
|
2013-06-05 22:39:43 +00:00
|
|
|
// Push non-veaction=edit url in history
|
2014-11-19 01:10:52 +00:00
|
|
|
if ( !this.actFromPopState && history.pushState ) {
|
2013-06-05 22:39:43 +00:00
|
|
|
// Remove the veaction query parameter
|
|
|
|
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;
|
|
|
|
}
|
2013-06-05 22:39:43 +00:00
|
|
|
|
|
|
|
// If there are other query parameters, set the url to the current url (with veaction removed).
|
|
|
|
// Otherwise use the canonical style view url (bug 42553).
|
|
|
|
if ( ve.getObjectValues( uri.query ).length ) {
|
2014-11-19 01:10:52 +00:00
|
|
|
history.pushState( this.popState, document.title, uri );
|
2013-06-05 22:39:43 +00:00
|
|
|
} else {
|
2014-11-19 01:10:52 +00:00
|
|
|
history.pushState( this.popState, document.title, this.viewUri );
|
2013-06-05 22:39:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
this.actFromPopState = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Event} e Native event object
|
|
|
|
*/
|
2014-03-12 21:26:52 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.onWindowPopState = function ( e ) {
|
|
|
|
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
|
2014-06-21 01:37:30 +00:00
|
|
|
* @param {string} displayTitle What HTML to show as the page title
|
2014-11-17 01:00:06 +00:00
|
|
|
* @param {Object} lastModified Object containing user-formatted date
|
|
|
|
and time strings, or undefined if we made no change.
|
2014-11-07 00:31:34 +00:00
|
|
|
* @param {string} contentSub What HTML to show as the content subtitle
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2014-10-31 00:26:32 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.replacePageContent = function (
|
2014-11-07 00:31:34 +00:00
|
|
|
html, categoriesHtml, displayTitle, lastModified, contentSub
|
2014-10-31 00:26:32 +00:00
|
|
|
) {
|
2014-05-17 16:48:21 +00:00
|
|
|
var $content = $( $.parseHTML( html ) ), $editableContent;
|
|
|
|
|
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
|
|
|
|
2014-05-17 16:48:21 +00:00
|
|
|
if ( $( '#mw-imagepage-content' ).length ) {
|
|
|
|
// On file pages, we only want to replace the (local) description.
|
|
|
|
$editableContent = $( '#mw-imagepage-content' );
|
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 ) {
|
2014-08-21 16:36:01 +00:00
|
|
|
$( '#content > #firstHeading > span:first' ).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
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.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
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.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
|
|
|
/**
|
2014-08-28 21:38:49 +00:00
|
|
|
* Add onbeforeunload handler.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.setupBeforeUnloadHandler = function () {
|
2012-06-21 03:16:10 +00:00
|
|
|
// Remember any already set on before unload handler
|
|
|
|
this.onBeforeUnloadFallback = window.onbeforeunload;
|
|
|
|
// Attach before unload handler
|
2014-07-08 22:33:32 +00:00
|
|
|
window.onbeforeunload = this.onBeforeUnloadHandler = this.onBeforeUnload.bind( this );
|
2012-06-21 03:16:10 +00:00
|
|
|
// Attach page show handlers
|
|
|
|
if ( window.addEventListener ) {
|
2014-07-08 22:33:32 +00:00
|
|
|
window.addEventListener( 'pageshow', this.onPageShow.bind( this ), false );
|
2012-06-21 03:16:10 +00:00
|
|
|
} else if ( window.attachEvent ) {
|
2014-07-08 22:33:32 +00:00
|
|
|
window.attachEvent( 'pageshow', this.onPageShow.bind( this ) );
|
2012-06-21 03:16:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Remove onbeforunload handler.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-11-30 23:09:34 +00:00
|
|
|
ve.init.mw.ViewPageTarget.prototype.tearDownBeforeUnloadHandler = function () {
|
2012-06-21 03:16:10 +00:00
|
|
|
// Restore whatever previous onbeforeload hook existed
|
|
|
|
window.onbeforeunload = this.onBeforeUnloadFallback;
|
|
|
|
};
|
|
|
|
|
2013-11-13 20:15:44 +00:00
|
|
|
/**
|
|
|
|
* Show dialogs as needed on load.
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.maybeShowDialogs = function () {
|
2014-04-14 23:40:19 +00:00
|
|
|
var usePrefs, prefSaysShow, urlSaysHide;
|
2013-11-13 20:15:44 +00:00
|
|
|
if ( mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome ) {
|
2014-04-14 23:40:19 +00:00
|
|
|
|
|
|
|
// Only use the preference value if the user is logged-in.
|
|
|
|
// If the user is anonymous, we can't save the preference
|
|
|
|
// after showing the dialog. And we don't intend to use this
|
|
|
|
// preference to influence anonymous users (use the config
|
|
|
|
// variable for that; besides the pref value would be stale if
|
|
|
|
// the wiki uses static html caching).
|
|
|
|
usePrefs = !mw.user.isAnon();
|
|
|
|
prefSaysShow = usePrefs && !mw.user.options.get( 'visualeditor-hidebetawelcome' );
|
|
|
|
urlSaysHide = 'vehidebetadialog' in this.currentUri.query;
|
|
|
|
|
2014-03-17 22:50:07 +00:00
|
|
|
if (
|
2014-04-14 23:40:19 +00:00
|
|
|
!urlSaysHide &&
|
|
|
|
(
|
|
|
|
prefSaysShow ||
|
2014-11-20 20:41:41 +00:00
|
|
|
(
|
|
|
|
!usePrefs &&
|
|
|
|
localStorage.getItem( 've-beta-welcome-dialog' ) === null &&
|
|
|
|
$.cookie( 've-beta-welcome-dialog' ) === null
|
|
|
|
)
|
2014-04-14 23:40:19 +00:00
|
|
|
)
|
2014-03-17 22:50:07 +00:00
|
|
|
) {
|
2014-11-27 20:51:04 +00:00
|
|
|
this.getSurface().getDialogs().openWindow( 'betaWelcome' );
|
2014-03-17 22:50:07 +00:00
|
|
|
}
|
2014-04-14 23:40:19 +00:00
|
|
|
|
|
|
|
if ( prefSaysShow ) {
|
2014-05-23 09:57:58 +00:00
|
|
|
ve.init.target.constructor.static.apiRequest( {
|
2014-08-22 20:50:48 +00:00
|
|
|
action: 'options',
|
|
|
|
token: mw.user.tokens.get( 'editToken' ),
|
|
|
|
change: 'visualeditor-hidebetawelcome=1'
|
|
|
|
}, { type: 'POST' } );
|
2014-04-14 23:40:19 +00:00
|
|
|
|
|
|
|
// No need to set a cookie every time for logged-in users that have already
|
|
|
|
// set the hidebetawelcome=1 preference, but only if this isn't a one-off
|
|
|
|
// view of the page via the hiding GET parameter.
|
|
|
|
} else if ( !usePrefs && !urlSaysHide ) {
|
2014-11-20 20:41:41 +00:00
|
|
|
try {
|
|
|
|
localStorage.setItem( 've-beta-welcome-dialog', 1 );
|
|
|
|
} catch ( e ) {
|
|
|
|
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
|
|
|
}
|
2014-04-14 23:40:19 +00:00
|
|
|
}
|
2013-11-13 20:15:44 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface().getModel().metaList.getItemsInGroup( 'mwRedirect' ).length ) {
|
|
|
|
this.getSurface().getDialogs().openWindow( 'meta', {
|
2014-08-22 20:50:48 +00:00
|
|
|
page: 'settings',
|
2014-11-27 20:51:04 +00:00
|
|
|
fragment: this.getSurface().getModel().getFragment()
|
2014-07-14 21:32:49 +00:00
|
|
|
} );
|
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 page show event.
|
2012-06-21 03:16:10 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.onPageShow = function () {
|
2012-06-21 03:16:10 +00:00
|
|
|
// Re-add onbeforeunload handler
|
2013-05-01 22:21:32 +00:00
|
|
|
window.onbeforeunload = this.onBeforeUnloadHandler;
|
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
|
|
|
|
*/
|
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
|
|
|
ve.init.mw.ViewPageTarget.prototype.onBeforeUnload = function () {
|
2012-06-21 03:16:10 +00:00
|
|
|
var fallbackResult,
|
|
|
|
message,
|
2013-05-01 22:21:32 +00:00
|
|
|
onBeforeUnloadHandler = this.onBeforeUnloadHandler;
|
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();
|
|
|
|
}
|
|
|
|
// Check if their onbeforeunload hook returned something
|
|
|
|
if ( fallbackResult !== undefined ) {
|
|
|
|
// Exit here, returning their message
|
|
|
|
message = fallbackResult;
|
|
|
|
} else {
|
2012-11-28 23:57:00 +00:00
|
|
|
// Override if submitting
|
|
|
|
if ( this.submitting ) {
|
2014-08-28 21:38:49 +00:00
|
|
|
return undefined;
|
2012-11-28 23:57:00 +00:00
|
|
|
}
|
2012-06-21 03:16:10 +00:00
|
|
|
// Check if there's been an edit
|
2014-11-27 20:51:04 +00:00
|
|
|
if ( this.getSurface() && this.edited && mw.user.options.get( 'useeditwarning' ) ) {
|
2012-06-21 03:16:10 +00:00
|
|
|
// Return our message
|
|
|
|
message = ve.msg( 'visualeditor-viewpage-savewarning' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Unset the onbeforeunload handler so we don't break page caching in Firefox
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
if ( message !== undefined ) {
|
|
|
|
// ...but if the user chooses not to leave the page, we need to rebind it
|
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
|
|
|
setTimeout( function () {
|
2013-05-01 22:21:32 +00:00
|
|
|
window.onbeforeunload = onBeforeUnloadHandler;
|
2013-02-26 00:16:57 +00:00
|
|
|
} );
|
2012-06-21 03:16:10 +00:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
};
|
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.
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.prototype.switchToWikitextEditor = function ( discardChanges ) {
|
|
|
|
if ( discardChanges ) {
|
2014-10-29 01:19:52 +00:00
|
|
|
ve.track( 'mwedit.abort', { type: 'switchwithout', mechanism: 'navigate' } );
|
2014-07-07 19:51:41 +00:00
|
|
|
this.submitting = true;
|
2014-11-19 00:20:08 +00:00
|
|
|
location.href = this.viewUri.clone().extend( {
|
2014-07-07 19:51:41 +00:00
|
|
|
action: 'edit',
|
|
|
|
veswitched: 1
|
|
|
|
} ).toString();
|
|
|
|
} else {
|
|
|
|
this.serialize(
|
2014-11-27 20:51:04 +00:00
|
|
|
this.docToSave || ve.dm.converter.getDomFromModel( this.getSurface().getModel().getDocument() ),
|
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' } );
|
2014-11-27 00:23:52 +00:00
|
|
|
this.submitWithSaveFields( { wpDiff: 1, veswitched: 1 }, wikitext );
|
2014-10-29 01:19:52 +00:00
|
|
|
}.bind( this )
|
2014-07-07 19:51:41 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets the document opacity when we've decided to cancel switching to the wikitext editor.
|
|
|
|
*/
|
|
|
|
ve.init.mw.ViewPageTarget.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
|
|
|
};
|