mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Added accept button
Made close button not save
This commit is contained in:
parent
3076bf7e95
commit
a698c5dada
|
@ -17,16 +17,22 @@ es.Inspector = function( toolbar, context ) {
|
|||
this.toolbar = toolbar;
|
||||
this.context = context;
|
||||
this.$ = $( '<div class="es-inspector"></div>' );
|
||||
this.$closeButton = $( '<div class="es-inspector-closeButton"></div>' ).appendTo( this.$ );
|
||||
this.$closeButton = $( '<div class="es-inspector-button es-inspector-closeButton"></div>' )
|
||||
.appendTo( this.$ );
|
||||
this.$acceptButton = $( '<div class="es-inspector-button es-inspector-acceptButton"></div>' )
|
||||
.appendTo( this.$ );
|
||||
this.$form = $( '<form></form>' ).appendTo( this.$ );
|
||||
|
||||
// Events
|
||||
var _this = this;
|
||||
this.$closeButton.click( function() {
|
||||
_this.context.closeInspector();
|
||||
_this.context.closeInspector( false );
|
||||
} );
|
||||
this.$acceptButton.click( function() {
|
||||
_this.context.closeInspector( true );
|
||||
} );
|
||||
this.$form.submit( function( e ) {
|
||||
_this.context.closeInspector();
|
||||
_this.context.closeInspector( true );
|
||||
e.preventDefault();
|
||||
return false;
|
||||
} );
|
||||
|
@ -43,10 +49,10 @@ es.Inspector.prototype.open = function() {
|
|||
this.emit( 'open' );
|
||||
};
|
||||
|
||||
es.Inspector.prototype.close = function() {
|
||||
es.Inspector.prototype.close = function( accept ) {
|
||||
this.$.hide();
|
||||
if ( this.onClose ) {
|
||||
this.onClose();
|
||||
this.onClose( accept );
|
||||
}
|
||||
this.emit( 'close' );
|
||||
surfaceView.$input.focus();
|
||||
|
|
BIN
modules/es/images/accept.png
Normal file
BIN
modules/es/images/accept.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
@ -10,7 +10,8 @@ es.LinkInspector = function( toolbar, context ) {
|
|||
es.Inspector.call( this, toolbar, context );
|
||||
|
||||
// Properties
|
||||
this.$clearButton = $( '<div class="es-inspector-clearButton"></div>' ).prependTo( this.$ );
|
||||
this.$clearButton = $( '<div class="es-inspector-button es-inspector-clearButton"></div>' )
|
||||
.prependTo( this.$ );
|
||||
this.$.prepend( '<div class="es-inspector-title">Link inspector</div>' );
|
||||
this.$locationLabel = $( '<label>Page title</label>' ).appendTo( this.$form );
|
||||
this.$locationInput = $( '<input type="text">' ).appendTo( this.$form );
|
||||
|
@ -18,6 +19,9 @@ es.LinkInspector = function( toolbar, context ) {
|
|||
// Events
|
||||
var _this = this;
|
||||
this.$clearButton.click( function() {
|
||||
if ( $(this).is( '.es-inspector-button-disabled' ) ) {
|
||||
return;
|
||||
}
|
||||
var surfaceView = _this.context.getSurfaceView(),
|
||||
surfaceModel = surfaceView.getModel(),
|
||||
tx = surfaceModel.getDocument().prepareContentAnnotation(
|
||||
|
@ -28,7 +32,6 @@ es.LinkInspector = function( toolbar, context ) {
|
|||
surfaceModel.transact( tx );
|
||||
_this.$locationInput.val( '' );
|
||||
_this.context.closeInspector();
|
||||
return false;
|
||||
} );
|
||||
};
|
||||
|
||||
|
@ -48,15 +51,17 @@ es.LinkInspector.prototype.getTitleFromSelection = function() {
|
|||
return annotation.data.title;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return null;
|
||||
};
|
||||
|
||||
es.LinkInspector.prototype.onOpen = function() {
|
||||
var title = this.getTitleFromSelection();
|
||||
if ( title !== null ) {
|
||||
this.$locationInput.val( title );
|
||||
this.$clearButton.removeClass( 'es-inspector-button-disabled' );
|
||||
} else {
|
||||
this.$locationInput.val( '' );
|
||||
this.$clearButton.addClass( 'es-inspector-button-disabled' );
|
||||
}
|
||||
var _this = this;
|
||||
setTimeout( function() {
|
||||
|
@ -64,25 +69,27 @@ es.LinkInspector.prototype.onOpen = function() {
|
|||
}, 0 );
|
||||
};
|
||||
|
||||
es.LinkInspector.prototype.onClose = function() {
|
||||
var title = this.$locationInput.val();
|
||||
if ( title === this.getTitleFromSelection() || !title ) {
|
||||
return;
|
||||
es.LinkInspector.prototype.onClose = function( accept ) {
|
||||
if ( accept ) {
|
||||
var title = this.$locationInput.val();
|
||||
if ( title === this.getTitleFromSelection() || !title ) {
|
||||
return;
|
||||
}
|
||||
var surfaceView = this.context.getSurfaceView(),
|
||||
surfaceModel = surfaceView.getModel();
|
||||
var clear = surfaceModel.getDocument().prepareContentAnnotation(
|
||||
surfaceView.currentSelection,
|
||||
'clear',
|
||||
/link\/.*/
|
||||
);
|
||||
surfaceModel.transact( clear );
|
||||
var set = surfaceModel.getDocument().prepareContentAnnotation(
|
||||
surfaceView.currentSelection,
|
||||
'set',
|
||||
{ 'type': 'link/internal', 'data': { 'title': title } }
|
||||
);
|
||||
surfaceModel.transact( set );
|
||||
}
|
||||
var surfaceView = this.context.getSurfaceView(),
|
||||
surfaceModel = surfaceView.getModel();
|
||||
var clear = surfaceModel.getDocument().prepareContentAnnotation(
|
||||
surfaceView.currentSelection,
|
||||
'clear',
|
||||
/link\/.*/
|
||||
);
|
||||
surfaceModel.transact( clear );
|
||||
var set = surfaceModel.getDocument().prepareContentAnnotation(
|
||||
surfaceView.currentSelection,
|
||||
'set',
|
||||
{ 'type': 'link/internal', 'data': { 'title': title } }
|
||||
);
|
||||
surfaceModel.transact( set );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
|
|
@ -16,8 +16,7 @@
|
|||
z-index: 3;
|
||||
}
|
||||
|
||||
.es-inspector-closeButton,
|
||||
.es-inspector-clearButton {
|
||||
.es-inspector-button {
|
||||
position: absolute;
|
||||
top: 0.25em;
|
||||
width: 2em;
|
||||
|
@ -30,25 +29,31 @@
|
|||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.es-inspector-closeButton {
|
||||
right: 0.25em;
|
||||
background-image: url(../images/close.png);
|
||||
}
|
||||
|
||||
.es-inspector-clearButton {
|
||||
right: 2.25em;
|
||||
background-image: url(../images/clear.png);
|
||||
}
|
||||
|
||||
.es-inspector-closeButton:hover,
|
||||
.es-inspector-clearButton:hover {
|
||||
.es-inspector-button:hover {
|
||||
-moz-opacity: 1;
|
||||
filter:alpha(opacity=100);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.es-inspector-doneButton:hover {
|
||||
border-color: #dddddd;
|
||||
.es-inspector-button.es-inspector-button-disabled,
|
||||
.es-inspector-button.es-inspector-button-disabled:hover {
|
||||
-moz-opacity: 0.25;
|
||||
filter:alpha(opacity=25);
|
||||
opacity: 0.25;
|
||||
}
|
||||
.es-inspector-closeButton {
|
||||
right: 0.25em;
|
||||
background-image: url(../images/close.png);
|
||||
}
|
||||
|
||||
.es-inspector-acceptButton {
|
||||
right: 2.25em;
|
||||
background-image: url(../images/accept.png);
|
||||
}
|
||||
|
||||
.es-inspector-clearButton {
|
||||
right: 4.25em;
|
||||
background-image: url(../images/clear.png);
|
||||
}
|
||||
|
||||
.es-inspector form {
|
||||
|
|
|
@ -169,9 +169,9 @@ es.ContextView.prototype.openInspector = function( name ) {
|
|||
this.inspector = name;
|
||||
};
|
||||
|
||||
es.ContextView.prototype.closeInspector = function() {
|
||||
es.ContextView.prototype.closeInspector = function( accept ) {
|
||||
if ( this.inspector ) {
|
||||
this.inspectors[this.inspector].close();
|
||||
this.inspectors[this.inspector].close( accept );
|
||||
this.$inspectors.hide();
|
||||
this.inspector = null;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue