2012-07-19 00:11:26 +00:00
|
|
|
/**
|
|
|
|
* VisualEditor Surface 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-03-29 22:55:33 +00:00
|
|
|
/**
|
|
|
|
* Creates an ve.Surface object.
|
2012-04-19 22:14:57 +00:00
|
|
|
*
|
2012-03-29 22:55:33 +00:00
|
|
|
* A surface is a top-level object which contains both a surface model and a surface view.
|
2012-04-19 22:14:57 +00:00
|
|
|
*
|
2012-03-29 22:55:33 +00:00
|
|
|
* @class
|
|
|
|
* @constructor
|
2012-04-26 18:49:36 +00:00
|
|
|
* @param {String} parent Selector of element to attach to
|
2012-08-27 21:34:08 +00:00
|
|
|
* @param {HTMLElement} dom HTML element of document to edit
|
2012-03-29 22:55:33 +00:00
|
|
|
* @param {Object} options Configuration options
|
|
|
|
*/
|
2012-09-06 23:15:55 +00:00
|
|
|
ve.Surface = function VeSurface( parent, dom, options ) {
|
2012-03-29 22:55:33 +00:00
|
|
|
// Properties
|
2012-08-28 22:06:34 +00:00
|
|
|
this.$ = $( '<div class="ve-surface"></div>' );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.documentModel = new ve.dm.Document( ve.dm.converter.getDataFromDom( dom ) );
|
|
|
|
this.options = ve.extendObject( true, ve.Surface.defaultOptions, options );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.model = new ve.dm.Surface( this.documentModel );
|
2012-10-24 22:20:41 +00:00
|
|
|
this.view = new ve.ce.Surface( this.$, this.model, this );
|
|
|
|
this.context = new ve.ui.Context( this );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.toolbars = {};
|
2012-10-24 22:03:01 +00:00
|
|
|
this.commands = {};
|
2012-08-02 18:46:13 +00:00
|
|
|
|
2012-08-28 22:06:34 +00:00
|
|
|
// DOM Changes
|
|
|
|
$( parent ).append( this.$ );
|
|
|
|
this.$.append(
|
|
|
|
// Contain floating content
|
|
|
|
$( '<div style="clear: both;"></div>' ),
|
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
|
|
|
// Temporary paste buffer
|
|
|
|
// TODO: make 'paste' in surface stateful and remove this attrib
|
|
|
|
// TODO: Use a less generic id than "paste", or get rid of the ID alltogether
|
2012-08-28 22:06:34 +00:00
|
|
|
$( '<div id="paste" class="paste" contenteditable="true"></div>' )
|
|
|
|
);
|
|
|
|
|
2012-08-27 21:34:08 +00:00
|
|
|
// Initialization
|
2012-04-26 18:49:36 +00:00
|
|
|
this.setupToolbars();
|
2012-11-07 20:09:18 +00:00
|
|
|
this.setupCommands();
|
2012-03-29 22:55:33 +00:00
|
|
|
ve.instances.push( this );
|
2012-06-20 01:20:28 +00:00
|
|
|
this.model.startHistoryTracking();
|
2012-11-15 01:14:45 +00:00
|
|
|
|
|
|
|
// Turn off native object editing. This must be tried after the surface has been added to DOM.
|
|
|
|
try {
|
|
|
|
document.execCommand( 'enableObjectResizing', false, false );
|
|
|
|
document.execCommand( 'enableInlineTableEditing', false, false );
|
|
|
|
} catch ( e ) { /* Silently ignore */ }
|
2012-08-27 21:34:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
ve.Surface.defaultOptions = {
|
|
|
|
'toolbars': {
|
|
|
|
'top': {
|
2012-11-07 20:09:18 +00:00
|
|
|
'float': true,
|
2012-08-27 21:34:08 +00:00
|
|
|
'tools': [
|
|
|
|
{ 'name': 'history', 'items' : ['undo', 'redo'] },
|
|
|
|
{ 'name': 'textStyle', 'items' : ['format'] },
|
|
|
|
{ 'name': 'textStyle', 'items' : ['bold', 'italic', 'link', 'clear'] },
|
|
|
|
{ 'name': 'list', 'items' : ['number', 'bullet', 'outdent', 'indent'] }
|
|
|
|
]
|
|
|
|
}
|
2012-10-24 22:03:01 +00:00
|
|
|
},
|
|
|
|
// Items can either be symbolic names or objects with trigger and action properties
|
2012-11-07 23:36:03 +00:00
|
|
|
'commands': ['bold', 'italic', 'link', 'undo', 'redo', 'indent', 'unindent']
|
2012-10-24 22:03:01 +00:00
|
|
|
};
|
|
|
|
|
2012-06-20 01:20:28 +00:00
|
|
|
/* Methods */
|
|
|
|
|
2012-10-24 22:22:27 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the surface model.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.dm.Surface} Surface 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.Surface.prototype.getModel = function () {
|
2012-06-20 01:20:28 +00:00
|
|
|
return this.model;
|
|
|
|
};
|
|
|
|
|
2012-10-24 22:22:27 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the document model.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.dm.Document} Document 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.Surface.prototype.getDocumentModel = function () {
|
2012-06-20 01:20:28 +00:00
|
|
|
return this.documentModel;
|
|
|
|
};
|
|
|
|
|
2012-10-24 22:22:27 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the surface view.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.ce.Surface} Surface view
|
|
|
|
*/
|
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.Surface.prototype.getView = function () {
|
2012-06-20 01:20:28 +00:00
|
|
|
return this.view;
|
2012-04-26 18:49:36 +00:00
|
|
|
};
|
|
|
|
|
2012-10-24 22:20:41 +00:00
|
|
|
/**
|
|
|
|
* Gets a reference to the context user interface.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.ui.Context} Context user interface
|
|
|
|
*/
|
|
|
|
ve.Surface.prototype.getContext = function () {
|
|
|
|
return this.context;
|
|
|
|
};
|
|
|
|
|
2012-10-24 21:34:01 +00:00
|
|
|
/**
|
2012-11-07 00:09:38 +00:00
|
|
|
* Executes an action or command.
|
2012-10-24 21:34:01 +00:00
|
|
|
*
|
|
|
|
* @method
|
2012-11-07 00:09:38 +00:00
|
|
|
* @param {String|Command} action Name of action or command object
|
|
|
|
* @param {String} [method] Name of method
|
2012-10-24 21:34:01 +00:00
|
|
|
* @param {Mixed} [...] Additional arguments for action
|
2012-11-07 00:09:38 +00:00
|
|
|
* @returns {Boolean} Action or command was executed
|
2012-10-24 21:34:01 +00:00
|
|
|
*/
|
|
|
|
ve.Surface.prototype.execute = function ( action, method ) {
|
2012-11-07 23:36:03 +00:00
|
|
|
var trigger, obj, ret;
|
2012-11-07 00:09:38 +00:00
|
|
|
if ( action instanceof ve.Command ) {
|
|
|
|
trigger = action.toString();
|
|
|
|
if ( trigger in this.commands ) {
|
2012-11-07 23:36:03 +00:00
|
|
|
return this.execute.apply( this, this.commands[trigger] );
|
2012-11-07 00:09:38 +00:00
|
|
|
}
|
|
|
|
} else if ( typeof action === 'string' && typeof method === 'string' ) {
|
|
|
|
// Validate method
|
|
|
|
if ( ve.actionFactory.doesActionSupportMethod( action, method ) ) {
|
|
|
|
// Create an action object and execute the method on it
|
|
|
|
obj = ve.actionFactory.create( action, this );
|
2012-11-07 23:36:03 +00:00
|
|
|
ret = obj[method].apply( obj, Array.prototype.slice.call( arguments, 2 ) );
|
|
|
|
return ret === undefined || !!ret;
|
2012-11-07 00:09:38 +00:00
|
|
|
}
|
2012-10-24 21:34:01 +00:00
|
|
|
}
|
2012-11-07 00:09:38 +00:00
|
|
|
return false;
|
2012-10-24 21:34:01 +00:00
|
|
|
};
|
|
|
|
|
2012-10-24 22:03:01 +00:00
|
|
|
/**
|
2012-11-07 20:09:18 +00:00
|
|
|
* Adds all commands from initialization options.
|
2012-10-24 22:03:01 +00:00
|
|
|
*
|
2012-11-07 20:09:18 +00:00
|
|
|
* Commands must be registered through {ve.commandRegsitry} prior to constructing the surface.
|
2012-10-24 22:03:01 +00:00
|
|
|
*
|
|
|
|
* @method
|
2012-11-07 20:09:18 +00:00
|
|
|
* @param {String[]} commands Array of symbolic names of registered commands
|
2012-10-24 22:03:01 +00:00
|
|
|
*/
|
2012-11-07 20:09:18 +00:00
|
|
|
ve.Surface.prototype.setupCommands = function () {
|
|
|
|
var i, iLen, j, jLen, triggers, trigger, command,
|
|
|
|
commands = this.options.commands;
|
|
|
|
for ( i = 0, iLen = commands.length; i < iLen; i++ ) {
|
|
|
|
command = ve.commandRegistry.lookup( commands[i] );
|
|
|
|
if ( !command ) {
|
|
|
|
throw new Error( 'No command registered by that name: ' + commands[i] );
|
|
|
|
}
|
|
|
|
triggers = command.trigger;
|
|
|
|
if ( !ve.isArray( triggers ) ) {
|
|
|
|
triggers = [triggers];
|
|
|
|
}
|
|
|
|
for ( j = 0, jLen = triggers.length; j < jLen; j++ ) {
|
|
|
|
// Normalize
|
|
|
|
trigger = ( new ve.Command( triggers[j] ) ).toString();
|
|
|
|
// Validate
|
|
|
|
if ( trigger.length === 0 ) {
|
|
|
|
throw new Error( 'Incomplete command: ' + triggers[j] );
|
2012-10-24 22:03:01 +00:00
|
|
|
}
|
2012-11-07 20:09:18 +00:00
|
|
|
this.commands[trigger] = command.action;
|
2012-10-24 22:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-24 21:49:08 +00:00
|
|
|
/**
|
|
|
|
* Initializes the toolbar.
|
|
|
|
*
|
|
|
|
* This method uses {this.options} for it's configuration.
|
|
|
|
*
|
|
|
|
* @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.Surface.prototype.setupToolbars = function () {
|
2012-11-07 20:09:18 +00:00
|
|
|
var name, config, toolbar,
|
|
|
|
toolbars = this.options.toolbars;
|
|
|
|
for ( name in toolbars ) {
|
|
|
|
config = toolbars[name];
|
|
|
|
if ( ve.isPlainObject( config ) ) {
|
|
|
|
this.toolbars[name] = toolbar = { '$': $( '<div class="ve-ui-toolbar"></div>' ) };
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( name === 'top' ) {
|
2012-11-07 20:09:18 +00:00
|
|
|
// Add extra sections to the toolbar
|
|
|
|
toolbar.$.append(
|
|
|
|
'<div class="ve-ui-actions"></div>' +
|
|
|
|
'<div style="clear:both"></div>' +
|
|
|
|
'<div class="ve-ui-toolbar-shadow"></div>'
|
|
|
|
);
|
|
|
|
// Wrap toolbar for floating
|
|
|
|
toolbar.$wrapper = $( '<div class="ve-ui-toolbar-wrapper"></div>' )
|
|
|
|
.append( this.toolbars[name].$ );
|
|
|
|
// Add toolbar to surface
|
|
|
|
this.$.before( toolbar.$wrapper );
|
2012-07-03 16:57:19 +00:00
|
|
|
if ( 'float' in config && config.float === true ) {
|
|
|
|
// Float top toolbar
|
2012-11-07 20:09:18 +00:00
|
|
|
this.floatTopToolbar();
|
2012-07-03 16:57:19 +00:00
|
|
|
}
|
2012-04-26 18:49:36 +00:00
|
|
|
}
|
2012-11-07 20:09:18 +00:00
|
|
|
toolbar.instance = new ve.ui.Toolbar( toolbar.$, this, config.tools );
|
2012-04-26 18:49:36 +00:00
|
|
|
}
|
2012-11-07 20:09:18 +00:00
|
|
|
}
|
2012-04-26 18:49:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2012-10-24 21:49:08 +00:00
|
|
|
* Overlays the toolbar to the top of the screen when it would normally be out of view.
|
|
|
|
*
|
2012-04-26 18:49:36 +00:00
|
|
|
* TODO: Determine if this would be better in ui.toolbar vs here.
|
|
|
|
* TODO: This needs to be refactored so that it only works on the main editor top tool bar.
|
2012-10-24 21:49:08 +00:00
|
|
|
*
|
|
|
|
* @method
|
2012-04-26 18:49:36 +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.Surface.prototype.floatTopToolbar = function () {
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( !this.toolbars.top ) {
|
2012-04-26 18:49:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-08-27 21:34:08 +00:00
|
|
|
var $wrapper = this.toolbars.top.$wrapper,
|
|
|
|
$toolbar = this.toolbars.top.$,
|
2012-04-26 18:49:36 +00:00
|
|
|
$window = $( window );
|
|
|
|
|
2012-08-20 22:43:47 +00:00
|
|
|
$window.on( {
|
|
|
|
'resize': function () {
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( $wrapper.hasClass( 've-ui-toolbar-wrapper-floating' ) ) {
|
|
|
|
var toolbarsOffset = $wrapper.offset(),
|
|
|
|
left = toolbarsOffset.left,
|
|
|
|
right = $window.width() - $wrapper.outerWidth() - left;
|
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
|
|
|
$toolbar.css( {
|
|
|
|
'left': left,
|
|
|
|
'right': right
|
|
|
|
} );
|
2012-08-20 22:43:47 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
'scroll': function () {
|
|
|
|
var left, right,
|
2012-08-27 21:34:08 +00:00
|
|
|
toolbarsOffset = $wrapper.offset(),
|
|
|
|
$editorDocument = $wrapper.parent().find('.ve-surface .ve-ce-documentNode'),
|
2012-08-20 22:43:47 +00:00
|
|
|
$lastBranch = $editorDocument.children( '.ve-ce-branchNode:last' );
|
|
|
|
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( $window.scrollTop() > toolbarsOffset.top ) {
|
|
|
|
left = toolbarsOffset.left;
|
|
|
|
right = $window.width() - $wrapper.outerWidth() - left;
|
2012-08-20 22:43:47 +00:00
|
|
|
// If not floating, set float
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( !$wrapper.hasClass( 've-ui-toolbar-wrapper-floating' ) ) {
|
|
|
|
$wrapper
|
|
|
|
.css( 'height', $wrapper.height() )
|
|
|
|
.addClass( 've-ui-toolbar-wrapper-floating' );
|
2012-08-20 22:43:47 +00:00
|
|
|
$toolbar.css( {
|
|
|
|
'left': left,
|
|
|
|
'right': right
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
// Toolbar is floated
|
|
|
|
if (
|
|
|
|
// There's at least one branch
|
|
|
|
$lastBranch.length &&
|
|
|
|
// Toolbar is at or below the top of last node in the document
|
|
|
|
$window.scrollTop() + $toolbar.height() >= $lastBranch.offset().top
|
|
|
|
) {
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( !$wrapper.hasClass( 've-ui-toolbar-wrapper-bottom' ) ) {
|
|
|
|
$wrapper
|
|
|
|
.removeClass( 've-ui-toolbar-wrapper-floating' )
|
|
|
|
.addClass( 've-ui-toolbar-wrapper-bottom' );
|
2012-08-20 22:43:47 +00:00
|
|
|
$toolbar.css({
|
|
|
|
'top': $window.scrollTop() + 'px',
|
|
|
|
'left': left,
|
|
|
|
'right': right
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else { // Unattach toolbar
|
2012-08-27 21:34:08 +00:00
|
|
|
if ( $wrapper.hasClass( 've-ui-toolbar-wrapper-bottom' ) ) {
|
|
|
|
$wrapper
|
|
|
|
.removeClass( 've-ui-toolbar-wrapper-bottom' )
|
|
|
|
.addClass( 've-ui-toolbar-wrapper-floating' );
|
2012-08-20 22:43:47 +00:00
|
|
|
$toolbar.css( {
|
|
|
|
'top': 0,
|
|
|
|
'left': left,
|
|
|
|
'right': right
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { // Return toolbar to top position
|
2012-07-03 16:57:19 +00:00
|
|
|
if (
|
2012-08-27 21:34:08 +00:00
|
|
|
$wrapper.hasClass( 've-ui-toolbar-wrapper-floating' ) ||
|
|
|
|
$wrapper.hasClass( 've-ui-toolbar-wrapper-bottom' )
|
2012-07-03 16:57:19 +00:00
|
|
|
) {
|
2012-08-27 21:34:08 +00:00
|
|
|
$wrapper.css( 'height', 'auto' )
|
|
|
|
.removeClass( 've-ui-toolbar-wrapper-floating' )
|
|
|
|
.removeClass( 've-ui-toolbar-wrapper-bottom' );
|
2012-08-20 22:43:47 +00:00
|
|
|
$toolbar.css( {
|
|
|
|
'top': 0,
|
|
|
|
'left': 0,
|
|
|
|
'right': 0
|
|
|
|
} );
|
2012-07-03 16:57:19 +00:00
|
|
|
}
|
2012-04-26 18:49:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|