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
|
|
|
/*global mw */
|
2012-07-25 05:39:29 +00:00
|
|
|
|
2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface LinkInspector 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
|
|
|
|
*/
|
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
/**
|
2012-02-06 23:50:56 +00:00
|
|
|
* Creates an ve.ui.LinkInspector object.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
2011-12-09 01:28:44 +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.ui.Inspector}
|
2012-02-06 23:50:56 +00:00
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
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
|
|
|
* @param context
|
2011-12-09 01:28:44 +00:00
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.ui.LinkInspector = function VeUiLinkInspector( toolbar, context ) {
|
2012-08-28 22:06:34 +00:00
|
|
|
var inspector = this;
|
|
|
|
|
2012-09-17 23:53:03 +00:00
|
|
|
// Parent constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Inspector.call( this, toolbar, context );
|
2012-07-03 20:28:10 +00:00
|
|
|
|
2012-08-28 22:06:34 +00:00
|
|
|
// Properties
|
2012-08-15 18:26:11 +00:00
|
|
|
this.context = context;
|
2012-08-28 22:06:34 +00:00
|
|
|
this.initialValue = null;
|
2012-08-27 20:04:04 +00:00
|
|
|
this.$clearButton = $(
|
2012-08-28 22:06:34 +00:00
|
|
|
'<div class="ve-ui-inspector-button ve-ui-inspector-clearButton"></div>',
|
|
|
|
context.inspectorDoc
|
|
|
|
);
|
|
|
|
this.$title = $( '<div class="ve-ui-inspector-title"></div>', context.inspectorDoc )
|
|
|
|
.text( ve.msg( 'visualeditor-linkinspector-title' ) );
|
|
|
|
this.$locationInput = $(
|
|
|
|
'<input type="text" class="ve-ui-linkInspector-location" />',
|
|
|
|
context.inspectorDoc
|
2012-06-20 01:20:28 +00:00
|
|
|
);
|
2011-12-09 01:28:44 +00:00
|
|
|
|
|
|
|
// Events
|
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
|
|
|
this.$clearButton.click( function () {
|
2012-09-10 21:31:18 +00:00
|
|
|
if ( $( this ).hasClass( 've-ui-inspector-button-disabled' ) ) {
|
2011-12-09 23:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-09-21 23:45:57 +00:00
|
|
|
var i,
|
2012-07-03 20:28:10 +00:00
|
|
|
surfaceModel = inspector.context.getSurfaceView().getModel(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = inspector.getAllLinkAnnotationsFromSelection();
|
|
|
|
// Clear all link annotations.
|
2012-09-21 23:45:57 +00:00
|
|
|
for ( i = 0; i < annotations.length; i++ ) {
|
|
|
|
surfaceModel.annotate( 'clear', annotations[i] );
|
2012-06-20 01:20:28 +00:00
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
inspector.$locationInput.val( '' );
|
|
|
|
inspector.context.closeInspector();
|
2011-12-09 01:28:44 +00:00
|
|
|
} );
|
2012-08-15 18:26:11 +00:00
|
|
|
this.$locationInput.on( 'change mousedown keydown cut paste', function () {
|
2012-09-10 21:31:18 +00:00
|
|
|
var $input = $( this );
|
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 () {
|
2012-08-15 18:26:11 +00:00
|
|
|
// Toggle disabled class
|
2012-09-10 21:31:18 +00:00
|
|
|
if (
|
|
|
|
$input.val() !== '' &&
|
|
|
|
$input.data( 'status' ) !== 'invalid'
|
|
|
|
) {
|
2012-08-27 21:34:08 +00:00
|
|
|
inspector.$acceptButton.removeClass( 've-ui-inspector-button-disabled' );
|
2011-12-09 23:11:49 +00:00
|
|
|
} else {
|
2012-08-27 21:34:08 +00:00
|
|
|
inspector.$acceptButton.addClass( 've-ui-inspector-button-disabled' );
|
2011-12-09 23:11:49 +00:00
|
|
|
}
|
2012-08-15 18:26:11 +00:00
|
|
|
|
2011-12-09 23:11:49 +00:00
|
|
|
}, 0 );
|
|
|
|
} );
|
2012-08-15 18:26:11 +00:00
|
|
|
|
2012-08-28 22:06:34 +00:00
|
|
|
// DOM Changes
|
|
|
|
this.$.prepend( this.$title, this.$clearButton );
|
|
|
|
this.$form.append( this.$locationInput );
|
|
|
|
|
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
|
|
|
// FIXME: MediaWiki-specific
|
2012-08-15 18:26:11 +00:00
|
|
|
if ( 'mw' in window ) {
|
|
|
|
this.initMultiSuggest();
|
|
|
|
}
|
2011-12-09 01:28:44 +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.ui.LinkInspector, ve.ui.Inspector );
|
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
/* Methods */
|
|
|
|
|
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.ui.LinkInspector.prototype.getAllLinkAnnotationsFromSelection = function () {
|
2011-12-09 01:28:44 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
2012-08-24 02:06:36 +00:00
|
|
|
documentModel = surfaceModel.getDocument();
|
|
|
|
return documentModel
|
|
|
|
.getAnnotationsFromRange( surfaceModel.getSelection() )
|
2012-09-21 23:45:57 +00:00
|
|
|
.getAnnotationsOfType( /^link\// )
|
|
|
|
.get();
|
2012-06-20 01:20:28 +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.ui.LinkInspector.prototype.getFirstLinkAnnotation = function ( annotations ) {
|
2012-09-25 00:14:22 +00:00
|
|
|
var i;
|
|
|
|
for ( i = 0; i < annotations.length; i++ ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
// Use the first one with a recognized type (there should only be one, this is just in case)
|
|
|
|
if (
|
2012-09-25 00:14:22 +00:00
|
|
|
annotations[i].type === 'link/WikiLink' ||
|
|
|
|
annotations[i].type === 'link/ExtLink' ||
|
|
|
|
annotations[i].type === 'link/ExtLink/Numbered' ||
|
|
|
|
annotations[i].type === 'link/ExtLink/URL'
|
2012-08-02 18:46:13 +00:00
|
|
|
) {
|
2012-09-25 00:14:22 +00:00
|
|
|
return annotations[i];
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-09 23:04:55 +00:00
|
|
|
return null;
|
2011-12-09 01:28:44 +00:00
|
|
|
};
|
|
|
|
|
2012-07-03 20:28:10 +00:00
|
|
|
/*
|
|
|
|
* Method called prior to opening inspector which fixes up
|
|
|
|
* selection to contain the complete annotated link range
|
|
|
|
* OR unwrap outer whitespace from selection.
|
|
|
|
*/
|
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.ui.LinkInspector.prototype.prepareOpen = function () {
|
2012-07-03 20:28:10 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
|
|
|
doc = surfaceModel.getDocument(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotations = this.getAllLinkAnnotationsFromSelection(),
|
|
|
|
annotation = this.getFirstLinkAnnotation( annotations ),
|
2012-07-03 20:28:10 +00:00
|
|
|
selection = surfaceModel.getSelection(),
|
2012-07-24 17:42:29 +00:00
|
|
|
annotatedRange,
|
2012-07-03 20:28:10 +00:00
|
|
|
newSelection;
|
|
|
|
|
2012-07-24 17:42:29 +00:00
|
|
|
// Trim outer space from range if any.
|
|
|
|
newSelection = doc.trimOuterSpaceFromRange( selection );
|
|
|
|
|
2012-07-03 20:28:10 +00:00
|
|
|
if ( annotation !== null ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
annotatedRange = doc.getAnnotatedRangeFromSelection( newSelection, annotation );
|
|
|
|
|
|
|
|
// Adjust selection if it does not contain the annotated range
|
|
|
|
if ( selection.start > annotatedRange.start ||
|
|
|
|
selection.end < annotatedRange.end
|
|
|
|
) {
|
|
|
|
newSelection = annotatedRange;
|
|
|
|
// if selected from right to left
|
|
|
|
if ( selection.from > selection.start ) {
|
|
|
|
newSelection.flip();
|
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
surfaceModel.change( null, newSelection );
|
|
|
|
};
|
|
|
|
|
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.ui.LinkInspector.prototype.onOpen = function () {
|
2012-07-24 17:42:29 +00:00
|
|
|
var annotation = this.getFirstLinkAnnotation( this.getAllLinkAnnotationsFromSelection() ),
|
2012-09-07 01:04:51 +00:00
|
|
|
surfaceModel = this.context.getSurfaceView().getModel(),
|
|
|
|
documentModel = surfaceModel.getDocument(),
|
|
|
|
selection = surfaceModel.getSelection().truncate( 255 ),
|
|
|
|
initialValue = documentModel.getText( selection );
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
if ( annotation === null ) {
|
2012-09-07 01:04:51 +00:00
|
|
|
this.$locationInput.val( initialValue );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$clearButton.addClass( 've-ui-inspector-button-disabled' );
|
2012-08-09 19:36:09 +00:00
|
|
|
} else if ( annotation.type === 'link/WikiLink' ) {
|
2012-06-20 01:20:28 +00:00
|
|
|
// Internal link
|
2012-06-21 04:52:42 +00:00
|
|
|
initialValue = annotation.data.title || '';
|
|
|
|
this.$locationInput.val( initialValue );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$clearButton.removeClass( 've-ui-inspector-button-disabled' );
|
2012-06-20 01:20:28 +00:00
|
|
|
} else {
|
|
|
|
// External link
|
2012-06-21 19:40:28 +00:00
|
|
|
initialValue = annotation.data.href || '';
|
2012-06-21 04:52:42 +00:00
|
|
|
this.$locationInput.val( initialValue );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$clearButton.removeClass( 've-ui-inspector-button-disabled' );
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
2012-06-21 04:52:42 +00:00
|
|
|
this.initialValue = initialValue;
|
|
|
|
if ( this.$locationInput.val().length === 0 ) {
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$acceptButton.addClass( 've-ui-inspector-button-disabled' );
|
2012-06-21 04:52:42 +00:00
|
|
|
} else {
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$acceptButton.removeClass( 've-ui-inspector-button-disabled' );
|
2012-06-21 04:52:42 +00:00
|
|
|
}
|
2012-07-03 20:28:10 +00:00
|
|
|
|
2012-08-11 08:14:56 +00:00
|
|
|
setTimeout( ve.bind( function () {
|
2012-07-03 20:28:10 +00:00
|
|
|
this.$locationInput.focus().select();
|
|
|
|
}, this ), 0 );
|
2011-12-09 01:28:44 +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.ui.LinkInspector.prototype.onClose = function ( accept ) {
|
2012-06-25 22:40:16 +00:00
|
|
|
var surfaceView = this.context.getSurfaceView(),
|
|
|
|
surfaceModel = surfaceView.getModel(),
|
2012-09-21 23:45:57 +00:00
|
|
|
linkAnnotations = this.getAllLinkAnnotationsFromSelection(),
|
2012-06-25 22:40:16 +00:00
|
|
|
target = this.$locationInput.val(),
|
2012-09-21 23:45:57 +00:00
|
|
|
i;
|
2011-12-09 23:04:55 +00:00
|
|
|
if ( accept ) {
|
2012-07-24 17:42:29 +00:00
|
|
|
if ( !target ) {
|
2011-12-09 23:04:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-06-20 01:20:28 +00:00
|
|
|
// Clear link annotation if it exists
|
2012-09-21 23:45:57 +00:00
|
|
|
for ( i = 0; i < linkAnnotations.length; i++ ) {
|
|
|
|
surfaceModel.annotate( 'clear', linkAnnotations[i] );
|
2012-06-20 01:20:28 +00:00
|
|
|
}
|
2012-06-25 22:40:16 +00:00
|
|
|
surfaceModel.annotate( 'set', ve.ui.LinkInspector.getAnnotationForTarget( target ) );
|
2012-07-24 17:42:29 +00:00
|
|
|
|
2011-12-09 01:28:44 +00:00
|
|
|
}
|
2012-06-21 01:58:49 +00:00
|
|
|
// Restore focus
|
|
|
|
surfaceView.getDocument().getDocumentNode().$.focus();
|
2011-12-09 01:28:44 +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.ui.LinkInspector.getAnnotationForTarget = function ( target ) {
|
2012-06-25 23:25:09 +00:00
|
|
|
var title;
|
2012-06-25 22:40:16 +00:00
|
|
|
// Figure out if this is an internal or external link
|
|
|
|
if ( target.match( /^(https?:)?\/\// ) ) {
|
|
|
|
// External link
|
|
|
|
return {
|
2012-08-07 21:43:10 +00:00
|
|
|
'type': 'link/ExtLink',
|
2012-06-25 22:40:16 +00:00
|
|
|
'data': { 'href': target }
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// Internal link
|
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
|
|
|
// TODO: In the longer term we'll want to have autocompletion and existence
|
|
|
|
// and validity checks using AJAX
|
2012-06-25 23:25:09 +00:00
|
|
|
try {
|
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
|
|
|
// FIXME: MediaWiki-specific
|
2012-06-25 23:25:09 +00:00
|
|
|
title = new mw.Title( target );
|
|
|
|
if ( title.getNamespaceId() === 6 || title.getNamespaceId() === 14 ) {
|
|
|
|
// File: or Category: link
|
|
|
|
// We have to prepend a colon so this is interpreted as a link
|
|
|
|
// rather than an image inclusion or categorization
|
|
|
|
target = ':' + target;
|
|
|
|
}
|
|
|
|
} catch ( e ) { }
|
|
|
|
|
2012-06-25 22:40:16 +00:00
|
|
|
return {
|
2012-08-07 21:43:10 +00:00
|
|
|
'type': 'link/WikiLink',
|
2012-06-25 22:40:16 +00:00
|
|
|
'data': { 'title': target }
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-08-27 20:04:04 +00:00
|
|
|
ve.ui.LinkInspector.prototype.initMultiSuggest = function () {
|
2012-09-10 21:31:18 +00:00
|
|
|
var options,
|
|
|
|
inspector = this,
|
2012-08-15 18:26:11 +00:00
|
|
|
context = inspector.context,
|
|
|
|
$overlay = context.$iframeOverlay,
|
2012-09-10 21:31:18 +00:00
|
|
|
suggestionCache = {},
|
|
|
|
pageStatusCache = {},
|
|
|
|
api = new mw.Api();
|
|
|
|
|
|
|
|
function updateAcceptButtonAndLocationStatus( status ) {
|
|
|
|
if ( status !== 'invalid' ) {
|
|
|
|
inspector.$acceptButton.removeClass( 've-ui-inspector-button-disabled' );
|
|
|
|
} else {
|
|
|
|
inspector.$acceptButton.addClass( 've-ui-inspector-button-disabled' );
|
|
|
|
}
|
|
|
|
inspector.$locationInput.data( 'status', status );
|
|
|
|
}
|
2012-08-15 18:26:11 +00:00
|
|
|
|
|
|
|
// Multi Suggest configuration.
|
|
|
|
options = {
|
|
|
|
'parent': $overlay,
|
|
|
|
'prefix': 've-ui',
|
2012-08-31 20:46:03 +00:00
|
|
|
// Disable CSS Ellipsis.
|
|
|
|
// Using MediaWiki jQuery.autoEllipsis() for center ellipsis.
|
|
|
|
'cssEllipsis': false,
|
|
|
|
// Build suggestion groups in order.
|
|
|
|
'suggestions': function ( params ) {
|
2012-08-15 18:26:11 +00:00
|
|
|
var groups = {},
|
|
|
|
results = params.results,
|
|
|
|
query = params.query,
|
|
|
|
modifiedQuery,
|
|
|
|
title,
|
|
|
|
prot;
|
|
|
|
|
|
|
|
// Add existing pages.
|
|
|
|
if ( results.length > 0 ) {
|
2012-08-27 20:04:04 +00:00
|
|
|
groups.existingPage = {
|
|
|
|
'label': ve.msg( 'visualeditor-linkinspector-suggest-existing-page' ),
|
|
|
|
'items': results,
|
|
|
|
'itemClass': 've-ui-suggest-item-existingPage'
|
2012-08-15 18:26:11 +00:00
|
|
|
};
|
|
|
|
}
|
2012-09-10 21:31:18 +00:00
|
|
|
// Run the query through the mw.Title object to handle correct capitalization,
|
|
|
|
// whitespace and and namespace alias/localization resolution.
|
2012-08-15 18:26:11 +00:00
|
|
|
try {
|
|
|
|
title = new mw.Title( query );
|
|
|
|
modifiedQuery = title.getPrefixedText();
|
|
|
|
// If page doesn't exist, add New Page group.
|
2012-08-17 22:13:19 +00:00
|
|
|
if ( ve.indexOf( modifiedQuery, results ) === -1 ) {
|
2012-08-27 20:04:04 +00:00
|
|
|
groups.newPage = {
|
|
|
|
'label': ve.msg( 'visualeditor-linkinspector-suggest-new-page' ),
|
|
|
|
'items': [modifiedQuery],
|
|
|
|
'itemClass': 've-ui-suggest-item-newPage'
|
2012-08-15 18:26:11 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} catch ( e ) {
|
|
|
|
// invalid input
|
|
|
|
ve.log( e );
|
|
|
|
}
|
|
|
|
// Add external
|
2012-08-27 20:04:04 +00:00
|
|
|
groups.externalLink = {
|
|
|
|
'label': ve.msg( 'visualeditor-linkinspector-suggest-external-link' ),
|
|
|
|
'items': [],
|
|
|
|
'itemClass': 've-ui-suggest-item-externalLink'
|
2012-08-15 18:26:11 +00:00
|
|
|
};
|
|
|
|
// Find a protocol and suggest an external link.
|
|
|
|
prot = query.match(
|
|
|
|
ve.init.platform.getExternalLinkUrlProtocolsRegExp()
|
|
|
|
);
|
|
|
|
if ( prot ) {
|
2012-08-27 20:04:04 +00:00
|
|
|
groups.externalLink.items = [query];
|
2012-08-15 18:26:11 +00:00
|
|
|
// No protocol, default to http
|
|
|
|
} else {
|
2012-08-27 20:04:04 +00:00
|
|
|
groups.externalLink.items = ['http://' + query];
|
2012-08-15 18:26:11 +00:00
|
|
|
}
|
|
|
|
return groups;
|
|
|
|
},
|
|
|
|
// Called on succesfull input.
|
2012-08-27 20:04:04 +00:00
|
|
|
'input': function ( callback ) {
|
2012-08-15 18:26:11 +00:00
|
|
|
var $input = $( this ),
|
|
|
|
query = $input.val(),
|
2012-09-10 21:31:18 +00:00
|
|
|
cKey = query.toLowerCase();
|
|
|
|
|
|
|
|
// Query page and set status data on the location input.
|
|
|
|
if ( pageStatusCache[query] !== undefined ) {
|
|
|
|
updateAcceptButtonAndLocationStatus( pageStatusCache[query] );
|
|
|
|
} else {
|
|
|
|
api.get( {
|
|
|
|
'action': 'query',
|
|
|
|
'indexpageids': '',
|
|
|
|
'titles': query,
|
|
|
|
'converttitles': ''
|
|
|
|
} )
|
2012-09-17 13:30:50 +00:00
|
|
|
.done( function ( data ) {
|
2012-09-10 21:31:18 +00:00
|
|
|
var status, page;
|
|
|
|
if ( data.query ) {
|
|
|
|
page = data.query.pages[data.query.pageids[0]];
|
|
|
|
status = 'exists';
|
|
|
|
if ( page.missing !== undefined ) {
|
|
|
|
status = 'notexists';
|
|
|
|
} else if ( page.invalid !== undefined ) {
|
|
|
|
status = 'invalid';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Cache the status of the link query.
|
|
|
|
pageStatusCache[query] = status;
|
|
|
|
updateAcceptButtonAndLocationStatus( status );
|
|
|
|
} );
|
|
|
|
}
|
2012-08-24 17:46:06 +00:00
|
|
|
|
|
|
|
// Set overlay position.
|
|
|
|
options.position();
|
|
|
|
// Build from cache.
|
2012-09-10 21:31:18 +00:00
|
|
|
if ( suggestionCache[cKey] !== undefined ) {
|
2012-08-24 17:46:06 +00:00
|
|
|
callback( {
|
2012-08-27 20:04:04 +00:00
|
|
|
'query': query,
|
2012-09-10 21:31:18 +00:00
|
|
|
'results': suggestionCache[cKey]
|
2012-08-24 17:46:06 +00:00
|
|
|
} );
|
|
|
|
} else {
|
2012-09-10 21:31:18 +00:00
|
|
|
// No cache, build fresh api request.
|
2012-08-24 17:46:06 +00:00
|
|
|
api.get( {
|
2012-08-27 20:04:04 +00:00
|
|
|
'action': 'opensearch',
|
|
|
|
'search': query
|
2012-09-10 21:31:18 +00:00
|
|
|
} )
|
|
|
|
.done( function ( data ) {
|
|
|
|
suggestionCache[cKey] = data[1];
|
|
|
|
// Build
|
|
|
|
callback( {
|
|
|
|
'query': query,
|
|
|
|
'results': data[1]
|
|
|
|
} );
|
2012-08-24 17:46:06 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
},
|
2012-08-31 20:46:03 +00:00
|
|
|
// Called when multiSuggest dropdown is updated.
|
2012-09-17 13:30:50 +00:00
|
|
|
'update': function () {
|
2012-08-31 20:46:03 +00:00
|
|
|
// Ellipsis
|
|
|
|
$( '.ve-ui-suggest-item' )
|
|
|
|
.autoEllipsis( {
|
|
|
|
'hasSpan': true,
|
|
|
|
'tooltip': true
|
|
|
|
} );
|
|
|
|
},
|
2012-08-24 17:46:06 +00:00
|
|
|
// Position the iframe overlay below the input.
|
2012-08-27 20:04:04 +00:00
|
|
|
'position': function () {
|
2012-08-24 17:46:06 +00:00
|
|
|
context.positionIframeOverlay( {
|
2012-08-27 20:04:04 +00:00
|
|
|
'overlay': $overlay,
|
|
|
|
'below': inspector.$locationInput
|
2012-08-15 18:26:11 +00:00
|
|
|
} );
|
2012-09-10 21:31:18 +00:00
|
|
|
},
|
|
|
|
// Fired when a suggestion is selected.
|
|
|
|
'select': function () {
|
|
|
|
// Assume page suggestion is valid.
|
|
|
|
updateAcceptButtonAndLocationStatus( 'valid' );
|
2012-08-15 18:26:11 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
// Setup Multi Suggest
|
|
|
|
this.$locationInput.multiSuggest( options );
|
|
|
|
};
|