1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-15 23:05:57 +00:00

Control s and p now save and print on editor pages

This commit is contained in:
Scott Tolksdorf
2016-11-14 22:40:37 -05:00
parent 8b3f9ac76a
commit 2f2a1c5146
3 changed files with 34 additions and 7 deletions

View File

@@ -16,7 +16,6 @@ var SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
var Editor = require('../../editor/editor.jsx');
var BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
var HijackPrint = require('../hijackPrint.js');
var Markdown = require('naturalcrit/markdown.js');
@@ -65,11 +64,22 @@ var EditPage = React.createClass({
htmlErrors : Markdown.validate(this.state.text)
})
document.onkeydown = HijackPrint(this.props.brew.shareId);
document.addEventListener('keydown', this.handleControlKeys);
},
componentWillUnmount: function() {
window.onbeforeunload = function(){};
document.onkeydown = function(){};
document.removeEventListener('keydown', this.handleControlKeys);
},
handleControlKeys : function(e){
if(!(e.ctrlKey || e.metaKey)) return;
e.stopPropagation();
e.preventDefault();
const S_KEY = 83;
const P_KEY = 80;
if(e.keyCode == S_KEY) this.save();
if(e.keyCode == P_KEY) window.open(`/print/${this.props.brew.shareId}?dialog=true`, '_blank').focus();
},
handleSplitMove : function(){

View File

@@ -1,3 +1,5 @@
//TODO: Depricate
module.exports = function(shareId){
return function(event){
event = event || window.event;

View File

@@ -35,7 +35,22 @@ const NewPage = React.createClass({
text : storage
})
}
document.addEventListener('keydown', this.handleControlKeys);
},
componentWillUnmount: function() {
document.removeEventListener('keydown', this.handleControlKeys);
},
handleControlKeys : function(e){
if(!(e.ctrlKey || e.metaKey)) return;
e.stopPropagation();
e.preventDefault();
const S_KEY = 83;
const P_KEY = 80;
if(e.keyCode == S_KEY) this.save();
if(e.keyCode == P_KEY) this.print();
},
handleSplitMove : function(){
this.refs.editor.update();
},
@@ -54,7 +69,7 @@ const NewPage = React.createClass({
localStorage.setItem(KEY, text);
},
handleSave : function(){
save : function(){
this.setState({
isSaving : true
});
@@ -85,19 +100,19 @@ const NewPage = React.createClass({
save...
</Nav.item>
}else{
return <Nav.item icon='fa-save' className='saveButton' onClick={this.handleSave}>
return <Nav.item icon='fa-save' className='saveButton' onClick={this.save}>
save
</Nav.item>
}
},
handlePrintClick : function(){
print : function(){
localStorage.setItem('print', this.state.text);
window.open('/print?dialog=true&local=print','_blank');
},
renderLocalPrintButton : function(){
return <Nav.item color='purple' icon='fa-file-pdf-o' onClick={this.handlePrintClick}>
return <Nav.item color='purple' icon='fa-file-pdf-o' onClick={this.print}>
get PDF
</Nav.item>
},