2012-07-19 03:40:49 +00:00
|
|
|
/*global mw */
|
|
|
|
|
2012-07-19 00:11:26 +00:00
|
|
|
/**
|
2012-07-20 23:59:59 +00:00
|
|
|
* VisualEditor MediaWiki initialization Target class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2012-07-19 00:11:26 +00:00
|
|
|
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/**
|
2012-07-20 23:59:59 +00:00
|
|
|
* MediaWiki target.
|
2012-06-11 06:54:41 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
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
|
|
|
* @extends {ve.EventEmitter}
|
2012-06-19 04:46:49 +00:00
|
|
|
* @param {String} pageName Name of target page
|
2012-06-11 06:54:41 +00:00
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.init.mw.Target = function VeInitMwTarget( pageName, oldId ) {
|
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
|
|
|
// Parent constructor
|
2012-06-18 20:12:32 +00:00
|
|
|
ve.EventEmitter.call( this );
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
// Properties
|
2012-06-19 04:46:49 +00:00
|
|
|
this.pageName = pageName;
|
2012-08-23 19:01:07 +00:00
|
|
|
this.oldId = oldId;
|
2012-06-11 06:54:41 +00:00
|
|
|
this.editToken = mw.user.tokens.get( 'editToken' );
|
|
|
|
this.apiUrl = mw.util.wikiScript( 'api' );
|
2012-08-30 20:04:22 +00:00
|
|
|
this.modules = ['ext.visualEditor.core', 'ext.visualEditor.specialMessages']
|
|
|
|
.concat(
|
|
|
|
window.devicePixelRatio > 1 ?
|
|
|
|
['ext.visualEditor.viewPageTarget.icons-vector', 'ext.visualEditor.icons-vector'] :
|
|
|
|
['ext.visualEditor.viewPageTarget.icons-raster', 'ext.visualEditor.icons-raster']
|
|
|
|
);
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
|
|
|
this.saving = false;
|
|
|
|
this.dom = null;
|
2012-06-11 06:54:41 +00:00
|
|
|
this.isMobileDevice = (
|
|
|
|
'ontouchstart' in window ||
|
2012-07-19 03:40:49 +00:00
|
|
|
( window.DocumentTouch && document instanceof window.DocumentTouch )
|
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 */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.init.mw.Target, ve.EventEmitter );
|
|
|
|
|
2012-06-18 20:12:32 +00:00
|
|
|
/* Static Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle response to a successful load request.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance. If successful the DOM from the
|
2012-07-20 23:59:59 +00:00
|
|
|
* server will be parsed, stored in {this.dom} and then {ve.init.mw.Target.onReady} will be called once
|
2012-06-18 20:12:32 +00:00
|
|
|
* the modules are ready.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} response XHR Response object
|
|
|
|
* @param {String} status Text status message
|
2012-06-19 06:07:54 +00:00
|
|
|
* @emits loadError (null, message, null)
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-09-17 13:30:50 +00:00
|
|
|
ve.init.mw.Target.onLoad = function ( response ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
var data = response['ve-parsoid'];
|
|
|
|
if ( !data ) {
|
|
|
|
this.loading = false;
|
2012-06-19 06:07:54 +00:00
|
|
|
this.emit( 'loadError', null, 'Invalid response from server', null );
|
2012-06-19 19:15:41 +00:00
|
|
|
} else if ( typeof data.result === 'error' ) {
|
|
|
|
this.loading = false;
|
|
|
|
this.emit( 'loadError', null, 'Server error', null );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else if ( typeof data.parsed !== 'string' ) {
|
|
|
|
this.loading = false;
|
2012-06-19 19:15:41 +00:00
|
|
|
this.emit( 'loadError', null, 'No HTML content in response from server', null );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
2012-08-01 00:49:04 +00:00
|
|
|
this.dom = $( '<div>' ).html( data.parsed )[0];
|
2012-06-18 20:12:32 +00:00
|
|
|
// Everything worked, the page was loaded, continue as soon as the module is ready
|
2012-08-11 08:14:56 +00:00
|
|
|
mw.loader.using( this.modules, ve.bind( ve.init.mw.Target.onReady, this ) );
|
2012-06-18 20:12:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle both DOM and modules being loaded and ready.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance. After the load event is emitted
|
|
|
|
* this.dom is cleared, allowing it to be garbage collected.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @emits load (dom)
|
|
|
|
*/
|
2012-08-01 00:49:04 +00:00
|
|
|
ve.init.mw.Target.onReady = function () {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
|
|
|
this.emit( 'load', this.dom );
|
|
|
|
// Release DOM data
|
|
|
|
this.dom = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle response to a successful load request.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} response XHR Response object
|
|
|
|
* @param {String} status Text status message
|
|
|
|
* @param {Mixed} error Thrown exception or HTTP error string
|
2012-06-19 06:07:54 +00:00
|
|
|
* @emits loadError (response, text, exception)
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-08-01 00:49:04 +00:00
|
|
|
ve.init.mw.Target.onLoadError = function ( response, text, exception ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = false;
|
|
|
|
this.emit( 'loadError', response, text, exception );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle response to a successful save request.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} response XHR Response object
|
|
|
|
* @param {String} status Text status message
|
|
|
|
* @emits save (html)
|
2012-06-19 06:07:54 +00:00
|
|
|
* @emits saveError (null, message, null)
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-09-17 13:30:50 +00:00
|
|
|
ve.init.mw.Target.onSave = function ( response ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.saving = false;
|
|
|
|
var data = response['ve-parsoid'];
|
2012-06-19 00:37:12 +00:00
|
|
|
if ( !data ) {
|
2012-06-19 06:07:54 +00:00
|
|
|
this.emit( 'saveError', null, 'Invalid response from server', null );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else if ( data.result !== 'success' ) {
|
2012-06-19 06:07:54 +00:00
|
|
|
this.emit( 'saveError', null, 'Unsuccessful request: ' + data.result, null );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else if ( typeof data.content !== 'string' ) {
|
2012-06-19 06:07:54 +00:00
|
|
|
this.emit( 'saveError', null, 'Invalid HTML content in response from server', null );
|
2012-06-18 20:12:32 +00:00
|
|
|
} else {
|
|
|
|
this.emit( 'save', data.content );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle response to a successful save request.
|
|
|
|
*
|
|
|
|
* This method is called within the context of a target instance.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
* @method
|
|
|
|
* @param {Object} data HTTP Response object
|
|
|
|
* @param {String} status Text status message
|
|
|
|
* @param {Mixed} error Thrown exception or HTTP error string
|
2012-06-19 06:07:54 +00:00
|
|
|
* @emits saveError (response, status, error)
|
2012-06-18 20:12:32 +00:00
|
|
|
*/
|
2012-08-01 00:49:04 +00:00
|
|
|
ve.init.mw.Target.onSaveError = function ( response, status, error ) {
|
2012-06-18 20:12:32 +00:00
|
|
|
this.saving = false;
|
|
|
|
this.emit( 'saveError', response, status, error );
|
|
|
|
};
|
|
|
|
|
2012-06-11 06:54:41 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets DOM from Parsoid API.
|
|
|
|
*
|
|
|
|
* This method performs an asynchronous action and uses a callback function to handle the result.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* target.loadDom(
|
2012-08-07 01:50:44 +00:00
|
|
|
* function ( error, dom ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
* // Handle errors and do something with the loaded DOM
|
|
|
|
* }
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {Function} callback Function to call when complete, accepts error and dom arguments
|
|
|
|
* @returns {Boolean} Loading is now in progress
|
|
|
|
*/
|
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.Target.prototype.load = function () {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Prevent duplicate requests
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this.loading ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Start loading the module immediately
|
2012-06-12 01:21:31 +00:00
|
|
|
mw.loader.load( this.modules );
|
2012-06-11 06:54:41 +00:00
|
|
|
// Load DOM
|
2012-06-18 20:12:32 +00:00
|
|
|
this.loading = true;
|
2012-06-11 06:54:41 +00:00
|
|
|
$.ajax( {
|
|
|
|
'url': this.apiUrl,
|
|
|
|
'data': {
|
|
|
|
'action': 've-parsoid',
|
|
|
|
'paction': 'parse',
|
2012-06-19 04:46:49 +00:00
|
|
|
'page': this.pageName,
|
2012-08-23 19:01:07 +00:00
|
|
|
'oldid': this.oldId,
|
2012-06-11 06:54:41 +00:00
|
|
|
'format': 'json'
|
|
|
|
},
|
|
|
|
'dataType': 'json',
|
|
|
|
'type': 'GET',
|
2012-06-19 19:15:41 +00:00
|
|
|
// Wait up to 10 seconds before giving up
|
|
|
|
'timeout': 10000,
|
2012-06-11 06:54:41 +00:00
|
|
|
'cache': 'false',
|
2012-08-11 08:14:56 +00:00
|
|
|
'success': ve.bind( ve.init.mw.Target.onLoad, this ),
|
|
|
|
'error': ve.bind( ve.init.mw.Target.onLoadError, this )
|
2012-06-11 06:54:41 +00:00
|
|
|
} );
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Posts DOM to Parsoid API.
|
|
|
|
*
|
|
|
|
* This method performs an asynchronous action and uses a callback function to handle the result.
|
|
|
|
*
|
|
|
|
* @example
|
|
|
|
* target.saveDom(
|
|
|
|
* dom,
|
|
|
|
* { 'summary': 'test', 'minor': true, 'watch': false },
|
2012-08-07 01:50:44 +00:00
|
|
|
* function ( error, html ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
* // Handle errors and do something with the rendered HTML
|
|
|
|
* }
|
|
|
|
* );
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {HTMLElement} dom DOM to save
|
|
|
|
* @param {Object} options Saving options
|
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
|
|
|
* - {String} summary Edit summary
|
|
|
|
* - {Boolean} minor Edit is a minor edit
|
|
|
|
* - {Boolean} watch Watch this page
|
2012-06-11 06:54:41 +00:00
|
|
|
* @param {Function} callback Function to call when complete, accepts error and html arguments
|
|
|
|
* @returns {Boolean} Saving is now in progress
|
|
|
|
*/
|
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.Target.prototype.save = function ( dom, options ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Prevent duplicate requests
|
2012-06-18 20:12:32 +00:00
|
|
|
if ( this.saving ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Save DOM
|
2012-06-18 20:12:32 +00:00
|
|
|
this.saving = true;
|
2012-06-11 06:54:41 +00:00
|
|
|
$.ajax( {
|
|
|
|
'url': this.apiUrl,
|
|
|
|
'data': {
|
|
|
|
'format': 'json',
|
|
|
|
'action': 've-parsoid',
|
|
|
|
'paction': 'save',
|
2012-06-19 04:46:49 +00:00
|
|
|
'page': this.pageName,
|
2012-08-23 19:01:07 +00:00
|
|
|
'oldid': this.oldId,
|
2012-06-11 06:54:41 +00:00
|
|
|
'html': $( dom ).html(),
|
|
|
|
'token': this.editToken,
|
|
|
|
'summary': options.summary,
|
|
|
|
'minor': options.minor,
|
|
|
|
'watch': options.watch
|
|
|
|
},
|
|
|
|
'dataType': 'json',
|
|
|
|
'type': 'POST',
|
2012-06-19 19:15:41 +00:00
|
|
|
// Wait up to 10 seconds before giving up
|
|
|
|
'timeout': 10000,
|
2012-08-11 08:14:56 +00:00
|
|
|
'success': ve.bind( ve.init.mw.Target.onSave, this ),
|
|
|
|
'error': ve.bind( ve.init.mw.Target.onSaveError, this )
|
2012-06-11 06:54:41 +00:00
|
|
|
} );
|
|
|
|
return true;
|
|
|
|
};
|