mirror of
https://github.com/documize/community.git
synced 2025-07-23 23:29:42 +02:00
Problem: when editing sections, last editing section received all keyboard shortcuts
Solution: implement per section keyboard shortcuts
This commit is contained in:
parent
dbba63c6cf
commit
af97efec83
6 changed files with 53 additions and 36 deletions
|
@ -22,18 +22,27 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
editMode: false,
|
||||
docName: '',
|
||||
docExcerpt: '',
|
||||
|
||||
hasNameError: computed.empty('docName'),
|
||||
hasExcerptError: computed.empty('docExcerpt'),
|
||||
|
||||
keyUp(e) {
|
||||
if (e.keyCode === 27) { // escape key
|
||||
this.send('onCancel');
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
toggleEdit() {
|
||||
this.set('docName', this.get('document.name'));
|
||||
this.set('docExcerpt', this.get('document.excerpt'));
|
||||
this.set('editMode', true);
|
||||
|
||||
Ember.run.schedule('afterRender', () => {
|
||||
$('#document-name').select();
|
||||
});
|
||||
},
|
||||
|
||||
onSaveDocument() {
|
||||
onSave() {
|
||||
if (this.get('hasNameError') || this.get('hasExcerptError')) {
|
||||
return;
|
||||
}
|
||||
|
@ -46,7 +55,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
this.set('editMode', false);
|
||||
},
|
||||
|
||||
cancel() {
|
||||
onCancel() {
|
||||
this.set('editMode', false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,12 @@ const {
|
|||
export default Ember.Component.extend({
|
||||
drop: null,
|
||||
busy: false,
|
||||
|
||||
mousetrap: null,
|
||||
hasNameError: computed.empty('page.title'),
|
||||
containerId: Ember.computed('page', function () {
|
||||
let page = this.get('page');
|
||||
return `base-editor-inline-container-${page.id}`;
|
||||
}),
|
||||
pageId: Ember.computed('page', function () {
|
||||
let page = this.get('page');
|
||||
return `page-editor-${page.id}`;
|
||||
|
@ -43,16 +47,20 @@ export default Ember.Component.extend({
|
|||
}),
|
||||
|
||||
didRender() {
|
||||
let self = this;
|
||||
Mousetrap.bind('esc', function () {
|
||||
self.send('onCancel');
|
||||
let msContainer = document.getElementById(this.get('containerId'));
|
||||
let mousetrap = new Mousetrap(msContainer);
|
||||
|
||||
mousetrap.bind('esc', () => {
|
||||
this.send('onCancel');
|
||||
return false;
|
||||
});
|
||||
Mousetrap.bind(['ctrl+s', 'command+s'], function () {
|
||||
self.send('onAction');
|
||||
mousetrap.bind(['ctrl+s', 'command+s'], () => {
|
||||
this.send('onAction');
|
||||
return false;
|
||||
});
|
||||
|
||||
this.set('mousetrap', mousetrap);
|
||||
|
||||
$('#' + this.get('pageId')).focus(function() {
|
||||
$(this).select();
|
||||
});
|
||||
|
@ -65,8 +73,11 @@ export default Ember.Component.extend({
|
|||
drop.destroy();
|
||||
}
|
||||
|
||||
Mousetrap.unbind('esc');
|
||||
Mousetrap.unbind(['ctrl+s', 'command+s']);
|
||||
let mousetrap = this.get('mousetrap');
|
||||
if (is.not.null(mousetrap)) {
|
||||
mousetrap.unbind('esc');
|
||||
mousetrap.unbind(['ctrl+s', 'command+s']);
|
||||
}
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
}
|
||||
|
||||
.round-button-mono {
|
||||
@extend .no-select;
|
||||
@include ease-in();
|
||||
display: inline-block;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
|
@ -52,9 +54,8 @@
|
|||
vertical-align: middle;
|
||||
border: 1px solid $color-stroke;
|
||||
text-align: center;
|
||||
@extend .no-select;
|
||||
@include ease-in();
|
||||
font-size: 1.2rem;
|
||||
background-color: transparent;
|
||||
|
||||
&:hover {
|
||||
@extend .z-depth-tiny;
|
||||
|
|
|
@ -4,20 +4,22 @@
|
|||
<div class="doc-excerpt">{{document.excerpt}}</div>
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="edit-document-heading">
|
||||
<div class="input-inline input-transparent edit-doc-title">
|
||||
{{focus-input id="document-name" type="text" value=docName class=(if hasNameError 'error-inline') placeholder="Name" autocomplete="off"}}
|
||||
</div>
|
||||
<div class="input-inline input-transparent edit-doc-excerpt">
|
||||
{{input id="document-excerpt" type="text" value=docExcerpt class=(if hasExcerptError 'error-inline') placeholder="Excerpt" autocomplete="off"}}
|
||||
</div>
|
||||
<div>
|
||||
<div class="round-button-mono" {{action 'onSaveDocument'}}>
|
||||
<i class="material-icons color-green">check</i>
|
||||
<form {{action "onSave" on="submit"}}>
|
||||
<div class="edit-document-heading">
|
||||
<div class="input-inline input-transparent edit-doc-title">
|
||||
{{focus-input id="document-name" type="text" value=docName class=(if hasNameError 'error-inline') placeholder="Name" autocomplete="off"}}
|
||||
</div>
|
||||
<div class="round-button-mono" {{action 'cancel'}}>
|
||||
<i class="material-icons color-gray">close</i>
|
||||
<div class="input-inline input-transparent edit-doc-excerpt">
|
||||
{{input id="document-excerpt" type="text" value=docExcerpt class=(if hasExcerptError 'error-inline') placeholder="Excerpt" autocomplete="off"}}
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="round-button-mono" {{action 'onSave'}}>
|
||||
<i class="material-icons color-green">check</i>
|
||||
</button>
|
||||
<div class="round-button-mono" {{action 'onCancel'}}>
|
||||
<i class="material-icons color-gray">close</i>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{{/unless}}
|
||||
|
|
|
@ -5,18 +5,12 @@
|
|||
</div>
|
||||
<div class="actions">
|
||||
{{#if showCancel}}
|
||||
<div class="flat-button" {{action 'onCancel'}}>
|
||||
cancel
|
||||
</div>
|
||||
<div class="flat-button" {{action 'onCancel'}}>cancel</div>
|
||||
{{/if}}
|
||||
{{#if hasSecondButton}}
|
||||
<div class="flat-button {{color2}}" {{action 'onAction2'}}>
|
||||
{{button2}}
|
||||
</div>
|
||||
<div class="flat-button {{color2}}" {{action 'onAction2'}}>{{button2}}</div>
|
||||
{{/if}}
|
||||
<div class="flat-button {{color}} dropdown-dialog-action-button" {{action 'onAction'}}>
|
||||
{{button}}
|
||||
</div>
|
||||
<div class="flat-button {{color}} dropdown-dialog-action-button" {{action 'onAction'}}>{{button}}</div>
|
||||
</div>
|
||||
<div class="clearfix"></div>
|
||||
</form>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div class="document-editor {{if blockMode 'document-editor-full'}}">
|
||||
<div id={{containerId}} class="document-editor {{if blockMode 'document-editor-full'}}">
|
||||
<div class="toolbar">
|
||||
<div class="buttons pull-right">
|
||||
{{#if busy}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue