2013-04-24 19:40:56 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor user interface PagedDialog class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Paged dialog.
|
|
|
|
*
|
|
|
|
* A paged dialog has an outline in the left third, and a series of pages in the right two-thirds.
|
|
|
|
* Pages can be added using the #addPage method, and later accessed using `this.pages[name]` or
|
|
|
|
* through the #getPage method.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.ui.Dialog
|
|
|
|
*
|
|
|
|
* @constructor
|
2013-05-14 23:45:42 +00:00
|
|
|
* @param {ve.ui.Surface} surface
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
* @param {Object} [config] Config options
|
2013-04-24 19:40:56 +00:00
|
|
|
*/
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
ve.ui.PagedDialog = function VeUiPagedDialog( surface, config ) {
|
2013-04-24 19:40:56 +00:00
|
|
|
// Parent constructor
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
ve.ui.Dialog.call( this, surface, config );
|
2013-04-24 19:40:56 +00:00
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.pages = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.PagedDialog, ve.ui.Dialog );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle frame ready events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.initialize = function () {
|
|
|
|
// Call parent method
|
|
|
|
ve.ui.Dialog.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
this.outlinePanel = new ve.ui.PanelLayout( { '$$': this.frame.$$, 'scroll': true } );
|
|
|
|
this.pagesPanel = new ve.ui.StackPanelLayout( { '$$': this.frame.$$ } );
|
2013-04-24 19:40:56 +00:00
|
|
|
this.layout = new ve.ui.GridLayout(
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
[this.outlinePanel, this.pagesPanel], { '$$': this.frame.$$, 'widths': [1, 2] }
|
2013-04-24 19:40:56 +00:00
|
|
|
);
|
The Great ve.ui.Surface refactor of 2013
Prologue:
Farewell ve.Editor my good chap… Oh, hey there HTML frames - I didn't
see you there! In a world where iframes are outlaws, and symbols like
document and window are global, there were more than a few assumptions
about which document or window was being used. But fear not - for this
commit (probably) tracks them all down, leaving a trail of
iframe-compatible awesomeness in its wake. With the great ve.ui.Surface
now able to be used inside of iframes, let the reference editing
commence. But there, lurking in the darkness is a DM issue so fierce it
may take Roan and/or Ed up to 3 whole hours to sort it out.
Note to Roan and/or Ed:
Editing references seems to work fine, but when saving the page there
are "no changes" which is a reasonable indication to the contrary.
Objectives:
* Make it possible to have multiple surfaces be instantiated, get along
nicely, and be embedded inside of iframes if needed.
* Make reference content editable within a dialog
Approach:
* Move what's left of ve.Editor to ve.ui.Surface and essentially
obliterate all use of it
* Make even more stuff inherit from ve.Element (long live this.$$)
* Use the correct document or window anywhere it was being assumed to be
the top level one
* Resolve stacking order issues by removing the excessive use of z-index
and introducing global and local overlay elements for each editor
* Add a surface to the reference dialog, load up the reference contents
and save them back on apply
* Actually destroy what we create in ce and ui surfaces
* Add recursive frame offset calculation method to ve.Element
* Moved ve.ce.Surface's getSelectionRect method to the prototype
Bonus:
* Move ve.ce.DocumentNode.css contents to ve.ce.Node.css (not sure why it
was separate in the first place, but I'm likely the one to blame)
* Fix blatant lies in documentation
* Whitespace cleanup here and there
* Get rid of ve.ui.Window overlays - not used or needed
Change-Id: Iede83e7d24f7cb249b6ba3dc45d770445b862e08
2013-05-20 22:45:50 +00:00
|
|
|
this.outlineWidget = new ve.ui.OutlineWidget( { '$$': this.frame.$$ } );
|
2013-04-24 19:40:56 +00:00
|
|
|
|
|
|
|
// Events
|
2013-05-01 22:21:32 +00:00
|
|
|
this.outlineWidget.connect( this, { 'select': 'onOutlineSelect' } );
|
2013-04-24 19:40:56 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.outlinePanel.$.append( this.outlineWidget.$ ).addClass( 've-ui-pagedDialog-outlinePanel' );
|
|
|
|
this.pagesPanel.$.addClass( 've-ui-pagedDialog-pagesPanel' );
|
|
|
|
this.$body.append( this.layout.$ );
|
|
|
|
};
|
|
|
|
|
2013-05-01 22:21:32 +00:00
|
|
|
/**
|
|
|
|
* Handle outline select events.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.ui.OptionWidget} item Selected item
|
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.onOutlineSelect = function ( item ) {
|
|
|
|
if ( item ) {
|
|
|
|
this.pagesPanel.showItem( this.pages[item.getData()] );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-24 19:40:56 +00:00
|
|
|
/**
|
|
|
|
* Add a page to the dialog.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Symbolic name of page
|
2013-05-28 19:06:06 +00:00
|
|
|
* @param {Object} [config] Condifugration options
|
|
|
|
* @param {jQuery|string} [config.label] Page label
|
|
|
|
* @param {string} [config.icon] Symbolic name of icon
|
|
|
|
* @param {number} [config.level=0] Indentation level
|
|
|
|
* @param {number} [config.index] Specific index to insert page at
|
2013-04-24 19:40:56 +00:00
|
|
|
* @chainable
|
|
|
|
*/
|
2013-05-28 19:06:06 +00:00
|
|
|
ve.ui.PagedDialog.prototype.addPage = function ( name, config ) {
|
2013-04-24 19:40:56 +00:00
|
|
|
// Create and add page panel and outline item
|
2013-05-28 19:06:06 +00:00
|
|
|
this.pages[name] = new ve.ui.PanelLayout( { '$$': this.frame.$$, 'scroll': true } );
|
|
|
|
this.pagesPanel.addItems( [this.pages[name]], config.index );
|
|
|
|
this.outlineWidget.addItems(
|
|
|
|
[
|
|
|
|
new ve.ui.OutlineItemWidget( name, {
|
|
|
|
'$$': this.frame.$$,
|
|
|
|
'label': config.label || name,
|
|
|
|
'level': config.level || 0,
|
|
|
|
'icon': config.icon
|
|
|
|
} )
|
|
|
|
],
|
|
|
|
config.index
|
|
|
|
);
|
2013-04-24 19:40:56 +00:00
|
|
|
|
|
|
|
// Auto-select first item when nothing is selected yet
|
|
|
|
if ( !this.outlineWidget.getSelectedItem() ) {
|
|
|
|
this.outlineWidget.selectItem( this.outlineWidget.getClosestSelectableItem( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-05-15 21:31:20 +00:00
|
|
|
/**
|
|
|
|
* Clear all pages.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @chainable
|
|
|
|
*/
|
2013-06-06 12:02:16 +00:00
|
|
|
ve.ui.PagedDialog.prototype.clearPages = function () {
|
2013-05-15 21:31:20 +00:00
|
|
|
this.pages = [];
|
|
|
|
this.pagesPanel.clearItems();
|
|
|
|
this.outlineWidget.clearItems();
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2013-04-24 19:40:56 +00:00
|
|
|
/**
|
|
|
|
* Get a page by name.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Symbolic name of page
|
2013-05-03 22:17:35 +00:00
|
|
|
* @returns {ve.ui.PanelLayout|undefined} Page, if found
|
2013-04-24 19:40:56 +00:00
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.getPage = function ( name ) {
|
|
|
|
return this.pages[name];
|
|
|
|
};
|