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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2013-06-21 02:47:10 +00:00
|
|
|
* Abstract implementation for a dialog having 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.
|
2013-04-24 19:40:56 +00:00
|
|
|
*
|
|
|
|
* @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-06-14 00:46:45 +00:00
|
|
|
* @cfg {boolean} [editable] Show controls for adding, removing and reordering items in the outline
|
2013-06-18 21:24:16 +00:00
|
|
|
* @cfg {Object[]} [adders] List of adders for controls, each an object with name, icon and title
|
|
|
|
* properties
|
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-06-14 00:46:45 +00:00
|
|
|
// Configuration initialization
|
|
|
|
config = 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
|
2013-06-14 00:46:45 +00:00
|
|
|
this.editable = !!config.editable;
|
2013-06-18 21:24:16 +00:00
|
|
|
this.adders = config.adders || null;
|
2013-04-24 19:40:56 +00:00
|
|
|
this.pages = {};
|
2013-06-11 19:07:34 +00:00
|
|
|
this.currentPageName = null;
|
2013-04-24 19:40:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
ve.inheritClass( ve.ui.PagedDialog, ve.ui.Dialog );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
ve.ui.PagedDialog.prototype.initialize = function () {
|
2013-06-21 02:47:10 +00:00
|
|
|
// Parent method
|
2013-04-24 19:40:56 +00:00
|
|
|
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-06-14 00:46:45 +00:00
|
|
|
if ( this.editable ) {
|
|
|
|
this.outlineControlsWidget = new ve.ui.OutlineControlsWidget(
|
2013-06-18 21:24:16 +00:00
|
|
|
this.outlineWidget, { '$$': this.frame.$$, 'adders': this.adders }
|
2013-06-14 00:46:45 +00:00
|
|
|
);
|
|
|
|
}
|
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
|
2013-06-14 00:46:45 +00:00
|
|
|
this.outlinePanel.$
|
|
|
|
.addClass( 've-ui-pagedDialog-outlinePanel' )
|
|
|
|
.append( this.outlineWidget.$ );
|
|
|
|
if ( this.editable ) {
|
|
|
|
this.outlinePanel.$
|
|
|
|
.addClass( 've-ui-pagedDialog-outlinePanel-editable' )
|
|
|
|
.append( this.outlineControlsWidget.$ );
|
|
|
|
}
|
2013-04-24 19:40:56 +00:00
|
|
|
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 ) {
|
2013-06-11 19:07:34 +00:00
|
|
|
this.setPage( item.getData() );
|
2013-05-01 22:21:32 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
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-06-11 19:07:34 +00:00
|
|
|
* @param {jQuery} [config.$content] Page content
|
2013-06-14 00:46:45 +00:00
|
|
|
* @param {jQuery} [config.moveable] Allow page to be moved in the outline
|
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 } );
|
2013-06-11 19:07:34 +00:00
|
|
|
if ( config.$content ) {
|
|
|
|
this.pages[name].$.append( config.$content );
|
|
|
|
}
|
2013-05-28 19:06:06 +00:00
|
|
|
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,
|
2013-06-14 00:46:45 +00:00
|
|
|
'icon': config.icon,
|
|
|
|
'moveable': config.moveable
|
2013-05-28 19:06:06 +00:00
|
|
|
} )
|
|
|
|
],
|
|
|
|
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-06-11 19:07:34 +00:00
|
|
|
/**
|
|
|
|
* Remove a page.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @chainable
|
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.removePage = function ( name ) {
|
|
|
|
var page = this.pages[name];
|
|
|
|
|
|
|
|
if ( page ) {
|
|
|
|
delete this.pages[name];
|
|
|
|
this.pagesPanel.removeItems( [ page ] );
|
|
|
|
this.outlineWidget.removeItems( [ this.outlineWidget.getItemFromData( name ) ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-select first item when nothing is selected anymore
|
|
|
|
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();
|
2013-06-11 19:07:34 +00:00
|
|
|
this.currentPageName = null;
|
2013-05-15 21:31:20 +00:00
|
|
|
|
|
|
|
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];
|
|
|
|
};
|
2013-06-11 19:07:34 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the page by name.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {string} name Symbolic name of page
|
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.setPage = function ( name ) {
|
2013-06-14 00:46:45 +00:00
|
|
|
if ( this.pages[name] ) {
|
2013-06-11 19:07:34 +00:00
|
|
|
this.currentPageName = name;
|
|
|
|
this.pagesPanel.showItem( this.pages[name] );
|
|
|
|
this.pages[name].$.find( ':input:first' ).focus();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current page name.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @returns {string|null} Current page name
|
|
|
|
*/
|
|
|
|
ve.ui.PagedDialog.prototype.getPageName = function () {
|
|
|
|
return this.currentPageName;
|
|
|
|
};
|