JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
/*!
|
2012-07-19 00:11:26 +00:00
|
|
|
* VisualEditor Surface class.
|
2012-07-19 21:25:16 +00:00
|
|
|
*
|
2013-02-19 23:37:34 +00:00
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
2012-07-19 00:11:26 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
*
|
2013-02-09 01:33:48 +00:00
|
|
|
* @example
|
|
|
|
* new ve.Surface(
|
2013-03-28 20:26:15 +00:00
|
|
|
* new ve.init.sa.Target( $( '<div>' ).appendTo( document.body ) ),
|
|
|
|
* ve.createDocumentFromHTML( '<p>Hello world.</p>' )
|
2013-02-09 01:33:48 +00:00
|
|
|
* );
|
|
|
|
*
|
2012-03-29 22:55:33 +00:00
|
|
|
* @class
|
Context, frame, window, dialog and inspector refactor
This is a major refactor of user interface context, frame, dialog
and inspector classes, including adding several new classes which
generalize managing inspectors/dialogs (which are now subclasses
of window).
New classes:
* ve.ui.Window.js - base class for inspector and dialog classes
* ve.ui.WindowSet.js - manages mutually exclusive windows, used
by surface and context for dialogs and inspectors respectively
* ve.ui.DialogFactory - generates dialogs
* ve.ui.IconButtonWidget - used in inspector for buttons in the head
Refactored classes:
* ve.ui.Context - moved inspector management to window set
* ve.ui.Frame - made iframes initialize asynchronously
* ve.ui.Dialog and ve.ui.Inspector - moved initialization to async
initialize method
Other interesting bits:
ve.ui.*Icons*.css, *.svg, *.png, *.ai
* Merged icon stylesheets so all icons are available inside windows
* Renamed inspector icon to window
ve.ui.*.css
* Reorganized styles so that different windows can include only
what they need
* Moved things to where they belonged (some things were in strange places)
ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js
* Removed dialog management - dialogs are managed by the surface now
ve.ui.*Dialog.js
* Renamed title message static property
* Added registration
ve.ui.*Inspector.js
* Switch to accept surface object rather than context, which conforms
to the more general window class without losing any functionality
(in fact, most of the time the surface was what we actually wanted)
ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js
* Using surface overly rather than passing an overlay around
through constructors
Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
|
|
|
*
|
2012-03-29 22:55:33 +00:00
|
|
|
* @constructor
|
2013-02-20 19:44:44 +00:00
|
|
|
* @param {ve.init.Target} target Integration target to add views to
|
2013-02-11 19:46:58 +00:00
|
|
|
* @param {HTMLDocument} doc HTML document to edit
|
2012-03-29 22:55:33 +00:00
|
|
|
* @param {Object} options Configuration options
|
|
|
|
*/
|
2013-02-20 19:44:44 +00:00
|
|
|
ve.Surface = function VeSurface( target, doc, options ) {
|
2012-03-29 22:55:33 +00:00
|
|
|
// Properties
|
2013-01-16 21:06:05 +00:00
|
|
|
this.$ = $( '<div>' );
|
Context, frame, window, dialog and inspector refactor
This is a major refactor of user interface context, frame, dialog
and inspector classes, including adding several new classes which
generalize managing inspectors/dialogs (which are now subclasses
of window).
New classes:
* ve.ui.Window.js - base class for inspector and dialog classes
* ve.ui.WindowSet.js - manages mutually exclusive windows, used
by surface and context for dialogs and inspectors respectively
* ve.ui.DialogFactory - generates dialogs
* ve.ui.IconButtonWidget - used in inspector for buttons in the head
Refactored classes:
* ve.ui.Context - moved inspector management to window set
* ve.ui.Frame - made iframes initialize asynchronously
* ve.ui.Dialog and ve.ui.Inspector - moved initialization to async
initialize method
Other interesting bits:
ve.ui.*Icons*.css, *.svg, *.png, *.ai
* Merged icon stylesheets so all icons are available inside windows
* Renamed inspector icon to window
ve.ui.*.css
* Reorganized styles so that different windows can include only
what they need
* Moved things to where they belonged (some things were in strange places)
ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js
* Removed dialog management - dialogs are managed by the surface now
ve.ui.*Dialog.js
* Renamed title message static property
* Added registration
ve.ui.*Inspector.js
* Switch to accept surface object rather than context, which conforms
to the more general window class without losing any functionality
(in fact, most of the time the surface was what we actually wanted)
ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js
* Using surface overly rather than passing an overlay around
through constructors
Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
|
|
|
this.$overlay = $( '<div>' );
|
2013-02-20 19:44:44 +00:00
|
|
|
this.target = target;
|
2013-03-20 22:35:05 +00:00
|
|
|
this.documentModel = new ve.dm.Document( doc );
|
2012-08-27 21:34:08 +00:00
|
|
|
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 );
|
Context, frame, window, dialog and inspector refactor
This is a major refactor of user interface context, frame, dialog
and inspector classes, including adding several new classes which
generalize managing inspectors/dialogs (which are now subclasses
of window).
New classes:
* ve.ui.Window.js - base class for inspector and dialog classes
* ve.ui.WindowSet.js - manages mutually exclusive windows, used
by surface and context for dialogs and inspectors respectively
* ve.ui.DialogFactory - generates dialogs
* ve.ui.IconButtonWidget - used in inspector for buttons in the head
Refactored classes:
* ve.ui.Context - moved inspector management to window set
* ve.ui.Frame - made iframes initialize asynchronously
* ve.ui.Dialog and ve.ui.Inspector - moved initialization to async
initialize method
Other interesting bits:
ve.ui.*Icons*.css, *.svg, *.png, *.ai
* Merged icon stylesheets so all icons are available inside windows
* Renamed inspector icon to window
ve.ui.*.css
* Reorganized styles so that different windows can include only
what they need
* Moved things to where they belonged (some things were in strange places)
ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js
* Removed dialog management - dialogs are managed by the surface now
ve.ui.*Dialog.js
* Renamed title message static property
* Added registration
ve.ui.*Inspector.js
* Switch to accept surface object rather than context, which conforms
to the more general window class without losing any functionality
(in fact, most of the time the surface was what we actually wanted)
ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js
* Using surface overly rather than passing an overlay around
through constructors
Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
|
|
|
this.dialogs = new ve.ui.WindowSet( this, ve.ui.dialogFactory );
|
2012-08-27 21:34:08 +00:00
|
|
|
this.toolbars = {};
|
2012-10-24 22:03:01 +00:00
|
|
|
this.commands = {};
|
2012-12-12 00:28:39 +00:00
|
|
|
this.enabled = true;
|
2012-08-02 18:46:13 +00:00
|
|
|
|
2012-08-27 21:34:08 +00:00
|
|
|
// Initialization
|
Context, frame, window, dialog and inspector refactor
This is a major refactor of user interface context, frame, dialog
and inspector classes, including adding several new classes which
generalize managing inspectors/dialogs (which are now subclasses
of window).
New classes:
* ve.ui.Window.js - base class for inspector and dialog classes
* ve.ui.WindowSet.js - manages mutually exclusive windows, used
by surface and context for dialogs and inspectors respectively
* ve.ui.DialogFactory - generates dialogs
* ve.ui.IconButtonWidget - used in inspector for buttons in the head
Refactored classes:
* ve.ui.Context - moved inspector management to window set
* ve.ui.Frame - made iframes initialize asynchronously
* ve.ui.Dialog and ve.ui.Inspector - moved initialization to async
initialize method
Other interesting bits:
ve.ui.*Icons*.css, *.svg, *.png, *.ai
* Merged icon stylesheets so all icons are available inside windows
* Renamed inspector icon to window
ve.ui.*.css
* Reorganized styles so that different windows can include only
what they need
* Moved things to where they belonged (some things were in strange places)
ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js
* Removed dialog management - dialogs are managed by the surface now
ve.ui.*Dialog.js
* Renamed title message static property
* Added registration
ve.ui.*Inspector.js
* Switch to accept surface object rather than context, which conforms
to the more general window class without losing any functionality
(in fact, most of the time the surface was what we actually wanted)
ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js
* Using surface overly rather than passing an overlay around
through constructors
Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-13 00:06:57 +00:00
|
|
|
this.$.addClass( 've-surface' ).appendTo( this.target.$ );
|
|
|
|
this.$overlay
|
|
|
|
.addClass( 've-surface-overlay' )
|
|
|
|
.append( this.context.$, this.dialogs.$ )
|
|
|
|
.appendTo( $( 'body' ) );
|
2012-11-26 21:36:07 +00:00
|
|
|
this.view.getDocument().getDocumentNode().setLive( true );
|
2012-04-26 18:49:36 +00:00
|
|
|
this.setupToolbars();
|
2012-11-07 20:09:18 +00:00
|
|
|
this.setupCommands();
|
2012-11-22 00:22:40 +00:00
|
|
|
this.resetSelection();
|
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
|
|
|
};
|
|
|
|
|
2013-01-15 23:38:49 +00:00
|
|
|
/* Static Properties */
|
2012-08-27 21:34:08 +00:00
|
|
|
|
|
|
|
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
|
2013-01-15 20:15:15 +00:00
|
|
|
'commands': ['bold', 'italic', 'link', 'undo', 'redo', 'indent', 'outdent']
|
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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the surface model.
|
2012-10-24 22:22:27 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the document model.
|
2012-10-24 22:22:27 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the surface view.
|
2012-10-24 22:22:27 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Get the context menu.
|
2012-10-24 22:20:41 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.ui.Context} Context user interface
|
|
|
|
*/
|
|
|
|
ve.Surface.prototype.getContext = function () {
|
|
|
|
return this.context;
|
|
|
|
};
|
|
|
|
|
2012-12-03 21:45:38 +00:00
|
|
|
/**
|
|
|
|
* Destroy the surface, releasing all memory and removing all DOM elements.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {ve.ui.Context} Context user interface
|
|
|
|
*/
|
|
|
|
ve.Surface.prototype.destroy = function () {
|
|
|
|
ve.instances.splice( ve.instances.indexOf( this ), 1 );
|
|
|
|
this.$.remove();
|
|
|
|
this.view.destroy();
|
|
|
|
this.context.destroy();
|
|
|
|
};
|
|
|
|
|
2012-12-12 00:28:39 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Disable editing.
|
2012-12-12 00:28:39 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.Surface.prototype.disable = function () {
|
|
|
|
this.view.disable();
|
|
|
|
this.model.disable();
|
|
|
|
this.enabled = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Enable editing.
|
2012-12-12 00:28:39 +00:00
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.Surface.prototype.enable = function () {
|
|
|
|
this.enabled = true;
|
|
|
|
this.view.enable();
|
|
|
|
this.model.enable();
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Check if editing is enabled.
|
2012-12-12 00:28:39 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-01-15 23:38:49 +00:00
|
|
|
* @returns {boolean} Editing is enabled
|
2012-12-12 00:28:39 +00:00
|
|
|
*/
|
|
|
|
ve.Surface.prototype.isEnabled = function () {
|
|
|
|
return this.enabled;
|
|
|
|
};
|
|
|
|
|
2012-11-22 00:22:40 +00:00
|
|
|
/**
|
|
|
|
* Fix up the initial selection.
|
|
|
|
*
|
|
|
|
* Reselect the selection and force a poll. This forces the selection to be something reasonable.
|
|
|
|
* In Firefox, the initial selection is (0,0), which causes problems (bug 42277).
|
2013-01-15 23:38:49 +00:00
|
|
|
*
|
|
|
|
* @method
|
2012-11-22 00:22:40 +00:00
|
|
|
*/
|
|
|
|
ve.Surface.prototype.resetSelection = function () {
|
Death and/or destruction
So. It turns out that the design of SurfaceFragment is a little -
shall we say - wonky.
One of the best things about ve.dm.SurfaceFragment is its magical
ability to retain the intention of its range, even as transactions
are being processed. This ability is granted by each fragment
listening to the surface's change event, and responding by using
translateRange for each transaction that gets processed. Surface
fragments also have these clever methods that allow you to get a
fragment based on another, which makes adjusting the range easy to do
inline without having to manually store multiple fragments or
modifying the original.
This sounded good, and we seemed to all be convinced it was well
designed. But if you add a console.log( 'hello' ); to the first line
of ve.dm.SurfaceFragment.prototype.onTransact, and then start using
the bold tool on various selections of text, you will find that there
may indeed be a flaw. What you will probably realize is that the
number of times that particular line of code is being called is
disturbingly large, and increases each time you do just about anything
in the editor. What's going on? How did we get here? Read on…
It turns out that fragments are immortal. We create them, they listen
to the surface's transact event, we are done with them, but the
surface keeps on emitting events to the now long forgotten about
fragments. They continue to build up over time, never go out of scope,
and bloat the hell out of our program.
The same ended up being true of toolbars - and each time the context
menu fired up a new one the old one was left in limbo, still
responding to events, still taking up memory, but not being visible to
the user.
All of this immortality was causing strange and difficult to track
down problems. This patch fixes this by introducing a destroy method.
This method unbinds events, allowing the object to finally fall out of
scope and die - and more importantly stop receiving notifications of
changes.
This is a hack, but Ed will no doubt get this situation sorted out
properly by making fragments lazy-evaluate their selections by only
storing an identifier of the most recent transaction they were based
on, see bug 47343.
Change-Id: I18bb986001a44732a7871b9d79dc3015eedfb168
2013-04-18 18:44:40 +00:00
|
|
|
this.model.getFragment().select().destroy();
|
2012-11-22 00:22:40 +00:00
|
|
|
this.view.surfaceObserver.poll();
|
|
|
|
};
|
|
|
|
|
2012-10-24 21:34:01 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Execute an action or command.
|
2012-10-24 21:34:01 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-01-26 03:29:21 +00:00
|
|
|
* @param {string|ve.Trigger} action Name of action or command object
|
JSDuck: Generated code documentation!
See CODING.md for how to run it.
Mistakes fixed:
* Warning: Unknown type function
-> Function
* Warning: Unknown type DOMElement
-> HTMLElement
* Warning: Unknown type DOM Node
-> HTMLElement
* Warning: Unknown type Integer
-> Mixed
* Warning: Unknown type Command
-> ve.Command
* Warning: Unknown type any
-> number
* Warning: Unknown type ve.Transaction
-> ve.dm.Transaction
* Warning: Unknown type ve.dm.AnnotationSet
-> ve.AnnotationSet
* Warning: Unknown type false
-> boolean
* Warning: Unknown type ve.dm.AlienNode
ve.dm doesn't have a generic AlienNode like ve.ce
-> Unknown type ve.dm.AlienInlineNode|ve.dm.AlienBlockNode
* Warning: Unknown type ve.ve.Surface
-> ve.ce.Surface
* ve.example.lookupNode:
-> Last @param should be @return
* ve.dm.Transaction.prototype.pushReplace:
-> @param {Array] should be @param {Array}
* Warning: ve.BranchNode.js:27: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
* Warning: ve.LeafNode.js:21: {@link ve.Node#hasChildren} links to non-existing member
-> (removed)
Differences fixed:
* Variadic arguments are like @param {Type...} [name]
instead of @param {Type} [name...]
* Convert all file headers from /** to /*! because JSDuck tries
to parse all /** blocks and fails to parse with all sorts of
errors for "Global property", "Unnamed property", and
"Duplicate property".
Find: \/\*\*([^@]+)(@copyright)
Replace: /*!$1$2
* Indented blocks are considered code examples.
A few methods had documentation with numbered lists that were
indented, which have now been updated to not be intended.
* The free-form text descriptions are parsed with Markdown,
which requires lists to be separated from paragraphs by an
empty line.
And we should use `backticks` instead of {braces} for inline
code in text paragraphs.
* Doc blocks for classes and their constructor have to be
in the correct order (@constructor, @param, @return must be
before @class, @abstract, @extends etc.)
* `@extends Class` must not have Class {wrapped}
* @throws must start with a {Type}
* @example means something else. It is used for an inline demo
iframe, not code block. For that simply indent with spaces.
* @member means something else.
Non-function properties are marked with @property, not @member.
* To create a link to a class or member, in most cases the name
is enough to create a link. E.g. Foo, Foo.bar, Foo.bar#quux,
where a hash stands for "instance member", so Foo.bar#quux,
links to Foo.bar.prototype.quux (the is not supported, as
"prototype" is considered an implementation detail, it only
indexes class name and method name).
If the magic linker doesn't work for some case, the
verbose syntax is {@link #target label}.
* @property can't have sub-properties (nested @param and @return
values are supported, only @static @property can't be nested).
We only have one case of this, which can be worked around by
moving those in a new virtual class. The code is unaltered
(only moved down so that it isn't with the scope of the main
@class block). ve.dm.TransactionProcessor.processors.
New:
* @mixins: Classes mixed into the current class.
* @event: Events that can be emitted by a class. These are also
inherited by subclasses. (+ @param, @return and @preventable).
So ve.Node#event-attach is inherited to ve.dm.BreakNode,
just like @method is.
* @singleton: Plain objects such as ve, ve.dm, ve.ce were missing
documentation causing a tree error. Documented those as a
JSDuck singleton, which they but just weren't documented yet.
NB: Members of @singleton don't need @static (if present,
triggers a compiler warning).
* @chainable: Shorthand for "@return this". We were using
"@return {classname}" which is ambiguous (returns the same
instance or another instance?), @chainable is specifically
for "@return this". Creates proper labels in the generated
HTML pages.
Removed:
* @mixin: (not to be confused with @mixins). Not supported by
JSDuck. Every class is standalone anyway. Where needed marked
them @class + @abstract instead.
Change-Id: I6a7c9e8ee8f995731bc205d666167874eb2ebe23
2013-01-04 08:54:17 +00:00
|
|
|
* @param {string} [method] Name of method
|
|
|
|
* @param {Mixed...} [args] Additional arguments for action
|
|
|
|
* @returns {boolean} Action or command was executed
|
2012-10-24 21:34:01 +00:00
|
|
|
*/
|
|
|
|
ve.Surface.prototype.execute = function ( action, method ) {
|
2012-12-12 00:28:39 +00:00
|
|
|
if ( !this.enabled ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-11-07 23:36:03 +00:00
|
|
|
var trigger, obj, ret;
|
2013-01-26 03:29:21 +00:00
|
|
|
if ( action instanceof ve.Trigger ) {
|
2012-11-07 00:09:38 +00:00
|
|
|
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
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Add 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.
|
2013-01-15 20:15:15 +00:00
|
|
|
* Setup Triggers registered through {ve.triggerRegistry} prior to constructing the surface.
|
|
|
|
* Add listener method to {ve.triggerRegistry} to lazy load triggers.
|
2012-10-24 22:03:01 +00:00
|
|
|
*
|
|
|
|
* @method
|
2013-01-08 21:02:12 +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 () {
|
2013-01-15 20:15:15 +00:00
|
|
|
var i, len, command,
|
|
|
|
commands = this.options.commands,
|
|
|
|
surface = this;
|
|
|
|
|
|
|
|
function loadTriggers( triggers, command ) {
|
|
|
|
var i, len, trigger;
|
2012-11-07 20:09:18 +00:00
|
|
|
if ( !ve.isArray( triggers ) ) {
|
|
|
|
triggers = [triggers];
|
|
|
|
}
|
2013-01-15 20:15:15 +00:00
|
|
|
for ( i = 0, len = triggers.length; i < len; i++ ) {
|
2012-11-07 20:09:18 +00:00
|
|
|
// Normalize
|
2013-01-26 03:29:21 +00:00
|
|
|
trigger = triggers[i].toString();
|
2012-11-07 20:09:18 +00:00
|
|
|
// Validate
|
|
|
|
if ( trigger.length === 0 ) {
|
2013-01-26 03:29:21 +00:00
|
|
|
throw new Error( 'Incomplete trigger: ' + triggers[i] );
|
2012-10-24 22:03:01 +00:00
|
|
|
}
|
2013-01-15 20:15:15 +00:00
|
|
|
surface.commands[trigger] = command.action;
|
2012-10-24 22:03:01 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-15 20:15:15 +00:00
|
|
|
|
|
|
|
for ( i = 0, len = commands.length; i < len; i++ ) {
|
|
|
|
command = ve.commandRegistry.lookup( commands[i] );
|
|
|
|
if ( !command ) {
|
|
|
|
throw new Error( 'No command registered by that name: ' + commands[i] );
|
|
|
|
}
|
2013-01-26 03:29:21 +00:00
|
|
|
loadTriggers( ve.triggerRegistry.lookup( commands[i] ), command );
|
2013-01-15 20:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Bind register event to lazy load triggers
|
2013-01-26 03:29:21 +00:00
|
|
|
ve.triggerRegistry.on( 'register', function ( name, trigger ) {
|
|
|
|
loadTriggers( trigger, ve.commandRegistry.lookup( name ) );
|
2013-01-15 20:15:15 +00:00
|
|
|
} );
|
|
|
|
|
2012-10-24 22:03:01 +00:00
|
|
|
};
|
|
|
|
|
2012-10-24 21:49:08 +00:00
|
|
|
/**
|
2013-01-15 23:38:49 +00:00
|
|
|
* Initialize the toolbar.
|
2012-10-24 21:49:08 +00:00
|
|
|
*
|
2013-01-17 20:24:28 +00:00
|
|
|
* This method uses {this.options} for its configuration.
|
2012-10-24 21:49:08 +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.Surface.prototype.setupToolbars = function () {
|
2012-11-07 20:09:18 +00:00
|
|
|
var name, config, toolbar,
|
|
|
|
toolbars = this.options.toolbars;
|
2013-02-20 19:44:44 +00:00
|
|
|
|
2012-11-07 20:09:18 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
2013-01-15 23:38:49 +00:00
|
|
|
* Move the toolbar to the top of the screen if it would normally be out of view.
|
2012-10-24 21:49:08 +00:00
|
|
|
*
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
};
|