2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor content editable TextNode 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-05-01 00:36:22 +00:00
|
|
|
/**
|
|
|
|
* ContentEditable node for text.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 00:36:22 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.ce.LeafNode}
|
|
|
|
* @param model {ve.dm.TextNode} Model to observe
|
|
|
|
*/
|
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.ce.TextNode = function ( model ) {
|
2012-05-01 00:36:22 +00:00
|
|
|
// Inheritance
|
2012-05-05 00:50:54 +00:00
|
|
|
ve.ce.LeafNode.call( this, 'text', model, $( document.createTextNode('') ) );
|
2012-05-04 00:19:01 +00:00
|
|
|
|
|
|
|
// Events
|
|
|
|
this.model.addListenerMethod( this, 'update', 'onUpdate' );
|
|
|
|
|
|
|
|
// Intialization
|
2012-06-14 04:46:29 +00:00
|
|
|
this.onUpdate( true );
|
2012-05-01 00:36:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/**
|
2012-05-02 18:29:44 +00:00
|
|
|
* Node rules.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 00:36:22 +00:00
|
|
|
* @see ve.ce.NodeFactory
|
2012-05-02 18:29:44 +00:00
|
|
|
* @static
|
|
|
|
* @member
|
2012-05-01 00:36:22 +00:00
|
|
|
*/
|
|
|
|
ve.ce.TextNode.rules = {
|
|
|
|
'canBeSplit': true
|
|
|
|
};
|
|
|
|
|
2012-05-03 05:28:57 +00:00
|
|
|
/**
|
|
|
|
* Mapping of character and HTML entities or renderings.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-03 05:28:57 +00:00
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.ce.TextNode.htmlCharacters = {
|
|
|
|
'&': '&',
|
|
|
|
'<': '<',
|
|
|
|
'>': '>',
|
|
|
|
'\'': ''',
|
|
|
|
'"': '"',
|
2012-06-12 17:40:44 +00:00
|
|
|
'\n': '↵',
|
|
|
|
'\t': '➞'
|
2012-05-03 05:28:57 +00:00
|
|
|
};
|
|
|
|
|
2012-05-01 02:38:42 +00:00
|
|
|
/**
|
|
|
|
* List of annotation rendering implementations.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 02:38:42 +00:00
|
|
|
* Each supported annotation renderer must have an open and close property, each either a string or
|
|
|
|
* a function which accepts a data argument.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 02:38:42 +00:00
|
|
|
* @static
|
|
|
|
* @member
|
|
|
|
*/
|
|
|
|
ve.ce.TextNode.annotationRenderers = {
|
|
|
|
'textStyle/italic': {
|
|
|
|
'open': '<i>',
|
|
|
|
'close': '</i>'
|
|
|
|
},
|
2012-06-21 21:46:43 +00:00
|
|
|
'textStyle/bold': {
|
|
|
|
'open': '<b>',
|
|
|
|
'close': '</b>'
|
|
|
|
},
|
2012-05-03 05:28:57 +00:00
|
|
|
'textStyle/underline': {
|
|
|
|
'open': '<u>',
|
|
|
|
'close': '</u>'
|
|
|
|
},
|
2012-06-21 21:46:43 +00:00
|
|
|
'textStyle/strike': {
|
|
|
|
'open': '<s>',
|
|
|
|
'close': '</s>'
|
|
|
|
},
|
|
|
|
'textStyle/small': {
|
|
|
|
'open': '<small>',
|
|
|
|
'close': '</small>'
|
|
|
|
},
|
|
|
|
'textStyle/big': {
|
|
|
|
'open': '<big>',
|
|
|
|
'close': '</big>'
|
|
|
|
},
|
|
|
|
'textStyle/span': {
|
|
|
|
// TODO recognize attributes
|
|
|
|
'open': '<span>',
|
|
|
|
'close': '</span>'
|
|
|
|
},
|
2012-05-01 02:38:42 +00:00
|
|
|
'textStyle/strong': {
|
2012-06-08 23:20:28 +00:00
|
|
|
'open': '<strong>',
|
|
|
|
'close': '</strong>'
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
|
|
|
'textStyle/emphasize': {
|
2012-06-08 23:20:28 +00:00
|
|
|
'open': '<em>',
|
|
|
|
'close': '<em>'
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
|
|
|
'textStyle/superScript': {
|
2012-06-08 23:20:28 +00:00
|
|
|
'open': '<sup>',
|
|
|
|
'close': '</sup>'
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
|
|
|
'textStyle/subScript': {
|
2012-06-08 23:20:28 +00:00
|
|
|
'open': '<sub>',
|
|
|
|
'close': '</sub>'
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
2012-07-26 03:46:57 +00:00
|
|
|
'link/ExtLink': {
|
2012-08-23 19:19:32 +00:00
|
|
|
'open': function ( data ) {
|
|
|
|
return '<a href="#" title="' + ve.escapeHtml( data.href ) + '">';
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
2012-06-08 23:20:28 +00:00
|
|
|
'close': '</a>'
|
2012-05-01 02:38:42 +00:00
|
|
|
},
|
2012-08-09 19:53:54 +00:00
|
|
|
'link/ExtLink/Numbered': {
|
2012-08-23 19:19:32 +00:00
|
|
|
'open': function ( data ) {
|
|
|
|
return '<a href="#" title="' + ve.escapeHtml( data.href ) + '">';
|
2012-07-26 03:46:57 +00:00
|
|
|
},
|
|
|
|
'close': '</a>'
|
|
|
|
},
|
2012-08-09 19:53:54 +00:00
|
|
|
'link/ExtLink/URL': {
|
2012-08-23 19:19:32 +00:00
|
|
|
'open': function ( data ) {
|
|
|
|
return '<a href="#" title="' + ve.escapeHtml( data.href ) + '">';
|
2012-07-26 03:46:57 +00:00
|
|
|
},
|
|
|
|
'close': '</a>'
|
|
|
|
},
|
|
|
|
'link/WikiLink': {
|
2012-08-23 19:19:32 +00:00
|
|
|
'open': function ( data ) {
|
|
|
|
return '<a href="#" title="' + ve.escapeHtml( data.title ) + '">';
|
2012-07-26 03:46:57 +00:00
|
|
|
},
|
|
|
|
'close': '</a>'
|
|
|
|
},
|
2012-06-08 22:15:43 +00:00
|
|
|
'link/unknown': {
|
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
|
|
|
'open': function () {
|
2012-06-08 23:20:28 +00:00
|
|
|
return '<a href="#">';
|
2012-06-08 22:15:43 +00:00
|
|
|
},
|
2012-06-08 23:20:28 +00:00
|
|
|
'close': '</a>'
|
2012-05-01 02:38:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-05-01 00:36:22 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-05-01 02:38:42 +00:00
|
|
|
/**
|
2012-05-04 00:19:01 +00:00
|
|
|
* Responds to model update events.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-04 00:19:01 +00:00
|
|
|
* If the source changed since last update the image's src attribute will be updated accordingly.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 02:38:42 +00:00
|
|
|
* @method
|
|
|
|
*/
|
Kranitor #1: On-boarding
'''Kranitor commits''' are commits by Krinkle with his janitor hat on.
Must never contain functional changes mixed with miscellaneous changes.
.gitignore:
* Add .DS_Store to the ignore list so that browsing the directories
on Mac OS X, will not add these files to the list of untracked
files.
* Fix missing newline at end of file
.jshintrc
* raises -> throws
* +module (QUnit.module)
* remove 'Node' (as of node-jshint 1.7.2 this is now part of
'browser:true', as it should be)
Authors:
* Adding myself
MWExtension/VisualEditor.php
* Fix default value of wgVisualEditorParsoidURL to not
point to the experimental instance in WMF Labs.
Issues:
* ve.ce.TextNode:
- Fix TODO: Don't perform a useless clone of an already-jQuerified object.
- Use .html() to set html content instead of encapsulating between
two strings. This is slightly faster but more importantly safer,
and prevents situations where the resulting jQuery collection
actually contains 2 elements instead of 1, thus messing up
what .contents() is iterating over.
* ve.ce.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Document.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.Transaction.test.js
- Fix: ReferenceError: assert is not defined
* ve.dm.TransactionProcessor.test.js
- Fix: ReferenceError: assert is not defined
* ext.visualEditor.viewPageTarget
- Missing dependency on 'mediawiki.Title'
Code conventions / Misc cleanup
* Various JSHint warnings.
* Whitespace
* jQuery(): Use '<tag>' for element creation,
use '<valid><xml/></valid>' for parsing
* Use the default operator instead of ternary when the condition and
first value are the same.
x = foo ? foo : bar; -> x = foo || bar;
Because contrary to some programming language (PHP...), in JS the
default operator does not enforce a boolean result but returns the
original value, hence it being called the 'default' operator, as
opposed to the 'or' operator.
* No need to call addClass() twice, it takes a space-separated list
(jQuery splits by space and adds if needed)
* Use .on( event[, selector], fn ) instead of the deprecated
routers to it such as .bind(), .delegate() and .live().
All these three are now built-in and fully compatible with .on()
* Add 'XXX:' comments for suspicious code that I don't want to change
as part of a clean up commit.
* Remove unused variables (several var x = this; where x was not
used anywhere, possibly from boilerplate copy/paste)
* Follows-up Trevor's commit that converts test suites to the new
QUnit format. Also removed the globals since we no longer use those
any more.
Change-Id: I7e37c9bff812e371c7f65a6fd85d9e2af3e0a22f
2012-07-27 08:43:33 +00:00
|
|
|
ve.ce.TextNode.prototype.onUpdate = function ( force ) {
|
2012-06-21 06:20:42 +00:00
|
|
|
if ( !force && !this.root.getSurface ) {
|
2012-08-08 17:48:53 +00:00
|
|
|
throw new Error( 'Can not update a text node that is not attached to a document' );
|
2012-06-21 06:20:42 +00:00
|
|
|
}
|
|
|
|
if ( force === true || this.root.getSurface().render === true ) {
|
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
|
|
|
var $new = $( '<span>' ).html( this.getHtml() ).contents();
|
2012-06-14 04:46:29 +00:00
|
|
|
if ( $new.length === 0 ) {
|
|
|
|
$new = $new.add( document.createTextNode( '' ) );
|
|
|
|
}
|
|
|
|
this.$.replaceWith( $new );
|
|
|
|
this.$ = $new;
|
|
|
|
if ( this.parent ) {
|
|
|
|
this.parent.clean();
|
2012-06-14 22:00:29 +00:00
|
|
|
if ( ve.debug ) {
|
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.parent.$.css( 'backgroundColor', '#F6F6F6' );
|
2012-08-11 08:14:56 +00:00
|
|
|
setTimeout( ve.bind( function () {
|
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.parent.$.css( 'backgroundColor', 'transparent' );
|
2012-06-14 22:00:29 +00:00
|
|
|
}, this ), 350 );
|
|
|
|
}
|
2012-06-14 04:46:29 +00:00
|
|
|
}
|
2012-06-07 18:33:21 +00:00
|
|
|
}
|
2012-05-01 02:38:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-05-02 21:21:41 +00:00
|
|
|
* Gets an HTML rendering of data within content model.
|
2012-05-14 22:05:09 +00:00
|
|
|
*
|
2012-05-01 02:38:42 +00:00
|
|
|
* @method
|
|
|
|
* @param {String} Rendered HTML of data within content model
|
|
|
|
*/
|
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.ce.TextNode.prototype.getHtml = function () {
|
2012-05-03 02:29:03 +00:00
|
|
|
var data = this.model.getDocument().getDataFromNode( this.model ),
|
|
|
|
htmlChars = ve.ce.TextNode.htmlCharacters,
|
2012-05-03 05:28:57 +00:00
|
|
|
renderers = ve.ce.TextNode.annotationRenderers,
|
2012-05-03 02:29:03 +00:00
|
|
|
out = '',
|
2012-06-01 00:18:28 +00:00
|
|
|
i,
|
|
|
|
j,
|
|
|
|
hash,
|
2012-05-03 02:29:03 +00:00
|
|
|
left = '',
|
|
|
|
right,
|
2012-06-21 06:17:48 +00:00
|
|
|
character,
|
|
|
|
nextCharacter,
|
2012-06-01 00:18:28 +00:00
|
|
|
open,
|
|
|
|
close,
|
|
|
|
index,
|
2012-05-03 02:29:03 +00:00
|
|
|
leftPlain,
|
2012-05-03 05:28:57 +00:00
|
|
|
rightPlain,
|
|
|
|
hashStack = [],
|
2012-07-19 03:40:49 +00:00
|
|
|
annotationStack = {},
|
|
|
|
chr;
|
2012-05-03 02:29:03 +00:00
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
function replaceWithNonBreakingSpace( index, data ) {
|
2012-06-20 22:31:50 +00:00
|
|
|
if ( ve.isArray( data[index] ) ) {
|
2012-08-10 22:39:57 +00:00
|
|
|
// Don't modify the original array, clone it first
|
|
|
|
data[index] = data[index].slice( 0 );
|
2012-06-20 22:31:50 +00:00
|
|
|
data[index][0] = ' ';
|
|
|
|
} else {
|
|
|
|
data[index] = ' ';
|
|
|
|
}
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
|
|
|
|
2012-06-20 22:31:50 +00:00
|
|
|
if ( data.length > 0 ) {
|
2012-06-21 06:17:48 +00:00
|
|
|
character = data[0];
|
|
|
|
if ( ve.isArray( character ) ? character[0] === ' ' : character === ' ' ) {
|
2012-06-20 22:31:50 +00:00
|
|
|
replaceWithNonBreakingSpace( 0, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( data.length > 1 ) {
|
2012-06-21 06:17:48 +00:00
|
|
|
character = data[data.length - 1];
|
|
|
|
if ( ve.isArray( character ) ? character[0] === ' ' : character === ' ' ) {
|
2012-06-20 22:31:50 +00:00
|
|
|
replaceWithNonBreakingSpace( data.length - 1, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( data.length > 2 ) {
|
2012-06-21 06:17:48 +00:00
|
|
|
for ( i = 1; i < data.length - 1; i++ ) {
|
|
|
|
character = data[i];
|
|
|
|
nextCharacter = data[i + 1];
|
|
|
|
if (
|
|
|
|
( ve.isArray( character ) ? character[0] === ' ' : character === ' ' ) &&
|
|
|
|
( ve.isArray( nextCharacter ) ? nextCharacter[0] === ' ' : nextCharacter === ' ' )
|
|
|
|
) {
|
2012-06-20 22:31:50 +00:00
|
|
|
replaceWithNonBreakingSpace( i + 1, data );
|
2012-06-19 05:24:18 +00:00
|
|
|
i++;
|
|
|
|
}
|
2012-06-14 04:46:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
function openAnnotations( annotations ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
var out = '',
|
2012-07-19 03:40:49 +00:00
|
|
|
annotation, hash;
|
|
|
|
for ( hash in annotations ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
annotation = annotations[hash];
|
2012-06-01 00:18:28 +00:00
|
|
|
out += typeof renderers[annotation.type].open === 'function' ?
|
|
|
|
renderers[annotation.type].open( annotation.data ) :
|
|
|
|
renderers[annotation.type].open;
|
2012-05-03 05:28:57 +00:00
|
|
|
hashStack.push( hash );
|
|
|
|
annotationStack[hash] = annotation;
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
2012-05-03 05:28:57 +00:00
|
|
|
return out;
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-05-03 02:29:03 +00:00
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
function closeAnnotations( annotations ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
var out = '',
|
2012-07-19 03:40:49 +00:00
|
|
|
annotation, hash;
|
|
|
|
for ( hash in annotations ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
annotation = annotations[hash];
|
2012-06-01 00:18:28 +00:00
|
|
|
out += typeof renderers[annotation.type].close === 'function' ?
|
|
|
|
renderers[annotation.type].close( annotation.data ) :
|
|
|
|
renderers[annotation.type].close;
|
2012-05-03 17:11:39 +00:00
|
|
|
hashStack.pop();
|
|
|
|
delete annotationStack[hash];
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
2012-05-03 05:28:57 +00:00
|
|
|
return out;
|
2012-07-19 03:40:49 +00:00
|
|
|
}
|
2012-05-03 02:29:03 +00:00
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
for ( i = 0; i < data.length; i++ ) {
|
2012-05-03 02:29:03 +00:00
|
|
|
right = data[i];
|
|
|
|
leftPlain = typeof left === 'string';
|
|
|
|
rightPlain = typeof right === 'string';
|
|
|
|
|
|
|
|
if ( !leftPlain && rightPlain ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
// [formatted][plain]
|
2012-06-01 00:18:28 +00:00
|
|
|
close = {};
|
|
|
|
for ( j = hashStack.length - 1; j >= 0; j-- ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
close[hashStack[j]] = annotationStack[hashStack[j]];
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
2012-06-01 00:18:28 +00:00
|
|
|
out += closeAnnotations( close );
|
2012-05-03 02:29:03 +00:00
|
|
|
} else if ( leftPlain && !rightPlain ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
// [plain][formatted]
|
|
|
|
out += openAnnotations( right[1] );
|
2012-05-03 02:29:03 +00:00
|
|
|
} else if ( !leftPlain && !rightPlain ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
// [formatted][formatted]
|
2012-05-03 02:29:03 +00:00
|
|
|
|
2012-05-03 18:11:46 +00:00
|
|
|
// setting index to undefined is is necessary to it does not use value from
|
|
|
|
// the previous iteration
|
2012-08-10 23:49:14 +00:00
|
|
|
open = {};
|
2012-06-01 00:18:28 +00:00
|
|
|
index = undefined;
|
2012-05-03 02:29:03 +00:00
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
for ( hash in left[1] ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
if ( !( hash in right[1] ) ) {
|
2012-06-01 00:18:28 +00:00
|
|
|
index = ( index === undefined ) ?
|
|
|
|
hashStack.indexOf( hash ) :
|
|
|
|
Math.min( index, hashStack.indexOf( hash ) );
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:11:46 +00:00
|
|
|
if ( index !== undefined ) {
|
2012-06-01 00:18:28 +00:00
|
|
|
close = {};
|
|
|
|
for ( j = hashStack.length - 1; j >= index; j-- ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
close[hashStack[j]] = annotationStack[hashStack[j]];
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
for ( j = index; j < hashStack.length; j++ ) {
|
2012-05-03 05:32:34 +00:00
|
|
|
if ( hashStack[j] in right[1] && hashStack[j] in left[1] ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
open[hashStack[j]] = annotationStack[hashStack[j]];
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
2012-05-03 05:28:57 +00:00
|
|
|
out += closeAnnotations( close );
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
for ( hash in right[1] ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
if ( !( hash in left[1] ) ) {
|
|
|
|
open[hash] = right[1][hash];
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-03 05:28:57 +00:00
|
|
|
out += openAnnotations( open );
|
2012-05-03 02:29:03 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 03:40:49 +00:00
|
|
|
chr = rightPlain ? right : right[0];
|
2012-05-03 02:29:03 +00:00
|
|
|
out += chr in htmlChars ? htmlChars[chr] : chr;
|
|
|
|
left = right;
|
|
|
|
}
|
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
close = {};
|
|
|
|
for ( j = hashStack.length - 1; j >= 0; j-- ) {
|
2012-05-03 05:28:57 +00:00
|
|
|
close[hashStack[j]] = annotationStack[hashStack[j]];
|
2012-05-01 02:38:42 +00:00
|
|
|
}
|
2012-06-01 00:18:28 +00:00
|
|
|
out += closeAnnotations( close );
|
2012-05-01 02:38:42 +00:00
|
|
|
return out;
|
|
|
|
};
|
|
|
|
|
2012-05-01 00:36:22 +00:00
|
|
|
/* Registration */
|
|
|
|
|
2012-05-31 22:20:58 +00:00
|
|
|
ve.ce.nodeFactory.register( 'text', ve.ce.TextNode );
|
2012-05-01 00:36:22 +00:00
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2012-06-01 00:18:28 +00:00
|
|
|
ve.extendClass( ve.ce.TextNode, ve.ce.LeafNode );
|