2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor user interface FormatDropdownTool 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-05 21:10:19 +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
|
|
|
* Creates an ve.ui.FormatDropdownTool object.
|
2012-06-20 01:20:28 +00:00
|
|
|
*
|
2011-12-05 21:10:19 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-02-06 23:50:56 +00:00
|
|
|
* @extends {ve.ui.DropdownTool}
|
|
|
|
* @param {ve.ui.Toolbar} toolbar
|
2011-12-05 21:10:19 +00:00
|
|
|
* @param {String} name
|
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 title
|
2011-12-05 21:10:19 +00:00
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.ui.FormatDropdownTool = function VeUiFormatDropdownTool( toolbar, name, title ) {
|
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-02-06 23:50:56 +00:00
|
|
|
ve.ui.DropdownTool.call( this, toolbar, name, title, [
|
2012-03-05 22:08:35 +00:00
|
|
|
{
|
2011-12-04 02:59:53 +00:00
|
|
|
'name': 'paragraph',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-paragraph' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'paragraph'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-1',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading1' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 1 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-2',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading2' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 2 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-3',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading3' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 3 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-4',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading4' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 4 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-5',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading5' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 5 }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'heading-6',
|
2012-06-20 01:20:28 +00:00
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-heading6' ),
|
2011-12-04 02:59:53 +00:00
|
|
|
'type' : 'heading',
|
|
|
|
'attributes': { 'level': 6 }
|
|
|
|
},
|
|
|
|
{
|
2012-06-20 01:20:28 +00:00
|
|
|
'name': 'preformatted',
|
|
|
|
'label': ve.msg( 'visualeditor-formatdropdown-format-preformatted' ),
|
|
|
|
'type' : 'preformatted'
|
2011-12-04 02:59:53 +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.FormatDropdownTool, ve.ui.DropdownTool );
|
|
|
|
|
2011-12-04 02:59:53 +00:00
|
|
|
/* Methods */
|
|
|
|
|
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
|
|
|
ve.ui.FormatDropdownTool.splitAndUnwrap = function ( model, list, firstItem, lastItem, selection ) {
|
2012-07-20 00:24:54 +00:00
|
|
|
var doc = model.getDocument(),
|
2012-06-21 17:46:09 +00:00
|
|
|
start = firstItem.getOuterRange().start,
|
|
|
|
end = lastItem.getOuterRange().end,
|
|
|
|
tx;
|
|
|
|
// First split the list before, if needed
|
|
|
|
if ( list.indexOf( firstItem ) > 0 ) {
|
|
|
|
tx = ve.dm.Transaction.newFromInsertion(
|
|
|
|
doc, start, [{ 'type': '/list' }, list.getClonedElement()]
|
|
|
|
);
|
|
|
|
start += 2;
|
|
|
|
end += 2;
|
|
|
|
selection = tx.translateRange( selection );
|
|
|
|
model.change( tx, selection );
|
|
|
|
}
|
|
|
|
// Split the list after, if needed
|
|
|
|
if ( list.indexOf( lastItem ) < list.getChildren().length - 1 ) {
|
|
|
|
tx = ve.dm.Transaction.newFromInsertion(
|
|
|
|
doc, end, [{ 'type': '/list' }, list.getClonedElement()]
|
|
|
|
);
|
|
|
|
selection = tx.translateRange( selection );
|
|
|
|
model.change( tx, selection );
|
|
|
|
}
|
|
|
|
// Unwrap the list
|
|
|
|
tx = ve.dm.Transaction.newFromWrap( doc, new ve.Range( start, end ),
|
|
|
|
[{ 'type': 'list' }], [], [{ 'type': 'listItem' }], []
|
|
|
|
);
|
|
|
|
selection = tx.translateRange( selection );
|
|
|
|
model.change( tx, selection );
|
|
|
|
return selection;
|
|
|
|
};
|
2012-06-20 01:20:28 +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
|
|
|
ve.ui.FormatDropdownTool.prototype.onSelect = function ( item ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var selected, prevList, firstInList, lastInList, i, contentBranch, listItem, txs,
|
|
|
|
surfaceView = this.toolbar.getSurfaceView(),
|
2012-06-21 17:46:09 +00:00
|
|
|
model = surfaceView.getModel(),
|
|
|
|
selection = model.getSelection(),
|
|
|
|
doc = model.getDocument();
|
|
|
|
if ( item.type !== 'paragraph' ) {
|
|
|
|
// We can't have headings or pre's in a list, so if we're trying to convert
|
|
|
|
// things that are in lists to a heading or a pre, split the list
|
2012-08-02 18:46:13 +00:00
|
|
|
selected = doc.selectNodes( selection, 'leaves' );
|
|
|
|
for ( i = 0; i < selected.length; i++ ) {
|
|
|
|
contentBranch = selected[i].node.isContent() ?
|
2012-06-21 17:46:09 +00:00
|
|
|
selected[i].node.getParent() :
|
|
|
|
selected[i].node;
|
|
|
|
// Check if it's in a list
|
2012-08-02 18:46:13 +00:00
|
|
|
listItem = contentBranch;
|
2012-06-21 17:46:09 +00:00
|
|
|
while ( listItem && listItem.getType() !== 'listItem' ) {
|
|
|
|
listItem = listItem.getParent();
|
|
|
|
}
|
|
|
|
if ( !listItem || listItem.getParent() !== prevList ) {
|
|
|
|
// Not in a list or in a different list
|
|
|
|
if ( prevList ) {
|
|
|
|
// Split and unwrap prevList
|
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
|
|
|
selection = ve.ui.FormatDropdownTool.splitAndUnwrap(
|
2012-06-21 17:46:09 +00:00
|
|
|
model, prevList, firstInList, lastInList, selection
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ( listItem ) {
|
|
|
|
prevList = listItem.getParent();
|
|
|
|
firstInList = listItem;
|
|
|
|
lastInList = firstInList;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// This node is in the current list
|
|
|
|
lastInList = listItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( prevList ) {
|
|
|
|
// Split and unwrap prevList
|
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
|
|
|
selection = ve.ui.FormatDropdownTool.splitAndUnwrap(
|
2012-06-21 17:46:09 +00:00
|
|
|
model, prevList, firstInList, lastInList, selection
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2012-08-02 18:46:13 +00:00
|
|
|
txs = ve.dm.Transaction.newFromContentBranchConversion(
|
2012-06-20 01:20:28 +00:00
|
|
|
doc,
|
2012-04-12 23:21:10 +00:00
|
|
|
selection,
|
2011-12-04 02:59:53 +00:00
|
|
|
item.type,
|
|
|
|
item.attributes
|
|
|
|
);
|
2012-06-21 17:46:09 +00:00
|
|
|
model.change( txs, selection );
|
2012-06-20 01:20:28 +00:00
|
|
|
surfaceView.showSelection( selection );
|
2011-12-04 02:59:53 +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
|
|
|
ve.ui.FormatDropdownTool.prototype.getMatchingMenuItems = function ( nodes ) {
|
2012-08-02 18:46:13 +00:00
|
|
|
var i, j, nodeType, nodeAttributes, item, key,
|
|
|
|
matches = [],
|
2012-06-21 21:13:36 +00:00
|
|
|
items = this.menuView.getItems();
|
2012-08-02 18:46:13 +00:00
|
|
|
for ( i = 0; i < nodes.length; i++ ) {
|
|
|
|
nodeType = nodes[i].getType();
|
|
|
|
nodeAttributes = nodes[i].getAttributes();
|
2012-06-21 21:13:36 +00:00
|
|
|
// Outer loop continue point
|
|
|
|
itemLoop:
|
2012-08-02 18:46:13 +00:00
|
|
|
for ( j = 0; j < items.length; j++ ) {
|
|
|
|
item = items[j];
|
2012-07-19 03:40:49 +00:00
|
|
|
if ( item.type === nodeType ) {
|
2012-06-21 21:13:36 +00:00
|
|
|
if ( item.attributes && nodeAttributes ) {
|
|
|
|
// Compare attributes
|
2012-08-02 18:46:13 +00:00
|
|
|
for ( key in item.attributes ) {
|
2012-06-21 21:13:36 +00:00
|
|
|
if (
|
|
|
|
// Node must have all the required attributes
|
|
|
|
!( key in nodeAttributes ) ||
|
|
|
|
// Use weak comparison because numbers sometimes come through as strings
|
2012-07-19 03:40:49 +00:00
|
|
|
item.attributes[key] !== nodeAttributes[key]
|
2012-06-21 21:13:36 +00:00
|
|
|
) {
|
|
|
|
// Skip to the next menu item
|
|
|
|
continue itemLoop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ( item.attributes && !nodeAttributes ) {
|
|
|
|
// Node is required to have certain attributes but doesn't
|
|
|
|
// have any, so it doesn't match
|
|
|
|
continue itemLoop;
|
|
|
|
}
|
|
|
|
matches.push( item );
|
|
|
|
}
|
2011-12-04 02:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
2012-06-21 21:13:36 +00:00
|
|
|
return matches;
|
|
|
|
};
|
|
|
|
|
2012-09-18 23:09:43 +00:00
|
|
|
ve.ui.FormatDropdownTool.prototype.onUpdateState = function ( annotations, nodes ) {
|
2012-06-21 21:13:36 +00:00
|
|
|
if ( nodes.length ) {
|
|
|
|
var items = this.getMatchingMenuItems( nodes );
|
|
|
|
if ( items.length === 1 ) {
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$labelText.text( items[0].label );
|
2012-06-21 21:13:36 +00:00
|
|
|
} else {
|
2012-08-27 21:34:08 +00:00
|
|
|
this.$labelText.html( ' ' );
|
2011-12-04 02:59:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
2012-02-06 23:50:56 +00:00
|
|
|
ve.ui.Tool.tools.format = {
|
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
|
|
|
'constructor': ve.ui.FormatDropdownTool,
|
2011-12-09 21:16:42 +00:00
|
|
|
'name': 'format',
|
2012-07-06 23:28:16 +00:00
|
|
|
'title': ve.msg( 'visualeditor-formatdropdown-title' )
|
2011-12-04 02:59:53 +00:00
|
|
|
};
|