Added accept button

Made close button not save
This commit is contained in:
Trevor Parscal 2011-12-09 23:04:55 +00:00
parent 3076bf7e95
commit a698c5dada
6 changed files with 62 additions and 44 deletions

View file

@ -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();

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

View file

@ -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 */

View file

@ -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 {

View file

@ -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;
}