2012-06-11 06:54:41 +00:00
|
|
|
/**
|
|
|
|
* Edit page target.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @constructor
|
|
|
|
* @extends {ve.init.Target}
|
|
|
|
* @param {String} title Page title of target
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget = function() {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Inheritance
|
|
|
|
ve.init.Target.call( this, mw.config.get( 'wgPageName' ) );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.$content = $( '#content' );
|
|
|
|
this.$view = this.$content.find( '#mw-content-text, #bodyContent' );
|
|
|
|
this.$heading = $( '#firstHeading' );
|
|
|
|
this.$surface = $( '<div class="ve-surface"></div>' );
|
|
|
|
this.$toolbar = null;
|
|
|
|
this.surface = null;
|
|
|
|
this.active = false;
|
|
|
|
this.surfaceOptions = {
|
|
|
|
'toolbars': {
|
|
|
|
'top': {
|
|
|
|
// If mobile device, float false
|
|
|
|
'float': !this.isMobileDevice,
|
|
|
|
// Toolbar modes
|
|
|
|
'modes': ['wikitext']
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
if ( mw.config.get('wgCanonicalNamespace') === 'VisualEditor' ) {
|
|
|
|
// Clicking the edit tab is the only way any other code gets run, and this sets that up
|
|
|
|
this.setupTabs();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Static Members */
|
|
|
|
|
|
|
|
/*jshint multistr: true*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.saveDialogTemplate = '\
|
|
|
|
<div class="es-inspector ve-init-viewPageTarget-saveDialog">\
|
|
|
|
<div class="es-inspector-title ve-init-viewPageTarget-saveDialog-title"></div>\
|
|
|
|
<div class="es-inspector-button ve-init-viewPageTarget-saveDialog-closeButton"></div>\
|
|
|
|
<div class="ve-init-viewPageTarget-saveDialog-body">\
|
|
|
|
<div class="ve-init-viewPageTarget-saveDialog-editSummary-label"></div>\
|
|
|
|
<input name="editSummary" id="ve-init-viewPageTarget-saveDialog-editSummary" type="text">\
|
2012-06-11 06:54:41 +00:00
|
|
|
<div class="clear:both"></div>\
|
2012-06-11 23:06:35 +00:00
|
|
|
<div class="ve-init-viewPageTarget-saveDialog-options">\
|
2012-06-11 06:54:41 +00:00
|
|
|
<input type="checkbox" name="minorEdit" \
|
2012-06-11 23:06:35 +00:00
|
|
|
id="ve-init-viewPageTarget-saveDialog-minorEdit">\
|
|
|
|
<label class="ve-init-viewPageTarget-saveDialog-minorEdit-label" \
|
|
|
|
for="ve-init-viewPageTarget-saveDialog-minorEdit">This is a minor edit</label>\
|
2012-06-11 06:54:41 +00:00
|
|
|
<div style="clear:both"></div>\
|
|
|
|
<input type="checkbox" name="watchList" \
|
2012-06-11 23:06:35 +00:00
|
|
|
id="ve-init-viewPageTarget-saveDialog-watchList">\
|
|
|
|
<label class="ve-init-viewPageTarget-saveDialog-watchList-label" \
|
|
|
|
for="ve-init-viewPageTarget-saveDialog-watchList">Watch this page</label>\
|
2012-06-11 06:54:41 +00:00
|
|
|
</div>\
|
2012-06-11 23:06:35 +00:00
|
|
|
<div class="ve-init-viewPageTarget-button ve-init-viewPageTarget-saveDialog-saveButton">\
|
|
|
|
<span class="ve-init-viewPageTarget-saveDialog-saveButton-label"></span>\
|
|
|
|
<div class="ve-init-viewPageTarget-saveDialog-saveButton-icon"></div>\
|
2012-06-11 06:54:41 +00:00
|
|
|
</div>\
|
|
|
|
<div style="clear:both"></div>\
|
|
|
|
</div>\
|
2012-06-11 23:06:35 +00:00
|
|
|
<div class="ve-init-viewPageTarget-saveDialog-foot">\
|
|
|
|
<p class="ve-init-viewPageTarget-saveDialog-license"></p>\
|
2012-06-11 06:54:41 +00:00
|
|
|
</div>\
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.onEditTabClick = function( e ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Ignore multiple clicks while editor is active
|
|
|
|
if ( !this.active ) {
|
|
|
|
// UI updates
|
|
|
|
this.setSelectedTab( 'ca-edit' );
|
|
|
|
this.showSpinner();
|
|
|
|
// Asynchronous initialization - load ve modules at the same time as the content
|
|
|
|
this.load( ve.proxy( this.onLoad, this ) );
|
|
|
|
}
|
|
|
|
// Prevent the edit tab's normal behavior
|
|
|
|
e.preventDefault();
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.onSaveDialogSaveButtonClick = function( e ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
this.showSpinner();
|
|
|
|
// Save
|
|
|
|
this.save(
|
|
|
|
ve.dm.converter.getDomFromData( this.surface.getDocumentModel().getData() ),
|
|
|
|
{
|
2012-06-11 23:06:35 +00:00
|
|
|
'summary': $( '#ve-init-viewPageTarget-saveDialog-editSummary' ).val(),
|
|
|
|
'minor': $( '#ve-init-viewPageTarget-saveDialog-minorEdit' ).prop( 'checked' ),
|
|
|
|
'watch': $( '#ve-init-viewPageTarget-saveDialog-watchList' ).prop( 'checked' )
|
2012-06-11 06:54:41 +00:00
|
|
|
},
|
|
|
|
ve.proxy( this.onSave, this )
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.onLoad = function( error, dom ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
if ( error ) {
|
|
|
|
// TODO: Error handling in the UI
|
|
|
|
} else {
|
|
|
|
this.setUpSurface( dom );
|
2012-06-11 20:24:20 +00:00
|
|
|
this.$surface.find( '.ve-ce-documentNode' ).focus();
|
2012-06-11 06:54:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.onSave = function( error, content ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
if ( error ) {
|
|
|
|
// TODO: Handle error in UI
|
|
|
|
} else {
|
|
|
|
// Hide the save dialog
|
2012-06-11 19:16:17 +00:00
|
|
|
this.$dialog.fadeOut();
|
2012-06-11 06:54:41 +00:00
|
|
|
// Refresh page with changed content
|
|
|
|
this.$content.find( '#mw-content-text' ).html( content );
|
|
|
|
// Restore the page to how it used to be
|
|
|
|
this.tearDownSurface();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.setUpSurface = function( dom ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Initialize surface
|
|
|
|
this.$surface.appendTo( this.$content );
|
|
|
|
this.surface = new ve.Surface( this.$surface, dom, this.surfaceOptions );
|
|
|
|
// Transplant the toolbar
|
|
|
|
this.$toolbar = this.$surface.find( '.es-toolbar-wrapper' ).insertBefore( this.$heading );
|
2012-06-11 19:16:17 +00:00
|
|
|
this.$heading.animate( { 'margin-top': this.$toolbar.outerHeight() }, 'fast' );
|
2012-06-11 06:54:41 +00:00
|
|
|
// Update UI
|
|
|
|
this.$spinner.remove();
|
|
|
|
this.$view.hide();
|
|
|
|
this.$spinner.hide();
|
2012-06-11 23:06:35 +00:00
|
|
|
this.$dialog = $( ve.init.ViewPageTarget.saveDialogTemplate );
|
2012-06-11 06:54:41 +00:00
|
|
|
// Add save and close buttons
|
|
|
|
this.$toolbar
|
|
|
|
.find( '.es-modes' )
|
|
|
|
.append(
|
|
|
|
$( '<div></div>' )
|
2012-06-11 23:06:35 +00:00
|
|
|
.addClass( 've-init-viewPageTarget-button ve-init-viewPageTarget-saveButton' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.append(
|
|
|
|
$( '<span></span>' )
|
|
|
|
.text( mw.msg( 'savearticle' ) )
|
|
|
|
)
|
2012-06-11 19:16:17 +00:00
|
|
|
.click( ve.proxy( function() { $(this).fadeIn( 'fast' ); }, this.$dialog ) )
|
2012-06-11 06:54:41 +00:00
|
|
|
);
|
|
|
|
// Set up save dialog
|
|
|
|
this.$dialog
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-title' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.text( mw.msg( 'tooltip-save' ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-closeButton' )
|
2012-06-11 19:16:17 +00:00
|
|
|
.click( ve.proxy( function() { $(this).fadeOut( 'fast' ); }, this.$dialog ) )
|
2012-06-11 06:54:41 +00:00
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-editSummary-label' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.text( mw.msg( 'summary' ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-minorEdit-label' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.text( mw.msg( 'minoredit' ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-watchList' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.prop( 'checked', ve.config.isPageWatched )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-watchList-label' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.text( mw.msg( 'watchthis' ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-saveButton' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.click( ve.proxy( this.onSaveDialogSaveButtonClick, this ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-saveButton-label' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.text( mw.msg( 'savearticle' ) )
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.find( '.ve-init-viewPageTarget-saveDialog-license' )
|
2012-06-11 06:54:41 +00:00
|
|
|
.html(
|
|
|
|
"By editing this page, you agree to irrevocably release your \
|
|
|
|
contributions under the CC-By-SA 3.0 License. If you don't want your \
|
|
|
|
writing to be editied mercilessly and redistrubuted at will, then \
|
|
|
|
don't submit it here.<br /><br />You are also confirming that you \
|
|
|
|
wrote this yourself, or copied it from a public domain or similar free \
|
|
|
|
resource. See Project:Copyright for full details of the licenses \
|
|
|
|
used on this site.\
|
|
|
|
<b>DO NOT SUBMIT COPYRIGHTED WORK WITHOUT PERMISSION!</b>"
|
|
|
|
)
|
|
|
|
.end()
|
2012-06-11 23:06:35 +00:00
|
|
|
.insertAfter( this.$toolbar.find( '.ve-init-viewPageTarget-saveButton' ) );
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.tearDownSurface = function( content ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
// Reset tabs
|
|
|
|
this.setSelectedTab( 'ca-view' );
|
|
|
|
// Update UI
|
2012-06-11 20:24:20 +00:00
|
|
|
this.$view.show().fadeTo( 'fast', 1 );
|
2012-06-11 06:54:41 +00:00
|
|
|
this.$surface.remove();
|
|
|
|
this.$toolbar.remove();
|
|
|
|
this.$spinner.remove();
|
2012-06-11 20:24:20 +00:00
|
|
|
this.$heading.animate( { 'margin-top': 0, 'opacity': 1 }, 'fast' );
|
2012-06-11 06:54:41 +00:00
|
|
|
// Destroy editor
|
|
|
|
this.surface = null;
|
|
|
|
};
|
|
|
|
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.setupTabs = function(){
|
2012-06-11 06:54:41 +00:00
|
|
|
// Only sysop users will have an edit tab in this namespace, so we might need to add one
|
|
|
|
if ( $( '#ca-edit' ).length === 0 ) {
|
|
|
|
// Add edit tab
|
|
|
|
mw.util.addPortletLink(
|
|
|
|
'p-views',
|
|
|
|
'#',
|
|
|
|
mw.msg( 'edit' ),
|
|
|
|
'ca-edit',
|
|
|
|
mw.msg( 'tooltip-ca-edit' ),
|
|
|
|
mw.msg( 'accesskey-ca-edit' ),
|
|
|
|
'#ca-history'
|
|
|
|
);
|
|
|
|
// If there isn't an edit tab, there's a view source tab we need to replace with edit source
|
|
|
|
var $viewSource = $( '#ca-viewsource' );
|
|
|
|
if ( $viewSource.length > 0 ) {
|
|
|
|
// "Move" the view source link to p-actions
|
|
|
|
mw.util.addPortletLink(
|
|
|
|
'p-cactions',
|
|
|
|
$viewSource.find( 'a' ).attr( 'href' ),
|
|
|
|
$viewSource.find( 'a' ).text(),
|
|
|
|
$viewSource.attr( 'id' )
|
|
|
|
);
|
|
|
|
// Remove the view original source link
|
|
|
|
$viewSource.remove();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Sysop users will need a new edit source tab since we are highjacking the edit tab
|
|
|
|
mw.util.addPortletLink(
|
|
|
|
'p-cactions',
|
|
|
|
mw.util.wikiGetlink() + '?action=edit',
|
|
|
|
'Edit Source', // TODO: i18n
|
|
|
|
'ca-editsource'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
$( '#ca-edit > span > a' ).click( ve.proxy( this.onEditTabClick, this ) );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows a loading spinner.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.showSpinner = function() {
|
2012-06-11 06:54:41 +00:00
|
|
|
this.$spinner = $( '<div></div>' )
|
2012-06-11 23:06:35 +00:00
|
|
|
.addClass( 've-init-viewPageTarget-loadingSpinner' )
|
2012-06-11 20:24:20 +00:00
|
|
|
.prependTo( this.$heading );
|
|
|
|
this.$heading.fadeTo( 'fast', 0.5 );
|
2012-06-11 06:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resets all tabs in the UI and selects a specific one.
|
|
|
|
*
|
|
|
|
* If no ID is given, or no ID matches the given ID, all tabs will be unselected.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {String} id HTML ID of tab to select
|
|
|
|
*/
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.ViewPageTarget.prototype.setSelectedTab = function( id ) {
|
2012-06-11 06:54:41 +00:00
|
|
|
$( '#p-views' ).find( 'li.selected' ).removeClass( 'selected' );
|
|
|
|
$( '#' + id ).addClass( 'selected' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.extendClass( ve.init.ViewPageTarget, ve.init.Target );
|
2012-06-11 06:54:41 +00:00
|
|
|
|
|
|
|
/* Initialization */
|
|
|
|
|
|
|
|
// TODO: Clean this stuff up
|
|
|
|
|
|
|
|
ve.config = mw.config.get( 'wgVisualEditor' );
|
2012-06-11 23:06:35 +00:00
|
|
|
ve.init.current = new ve.init.ViewPageTarget();
|