mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-18 17:51:29 +00:00
Control s and p now save and print on editor pages
This commit is contained in:
@@ -16,7 +16,6 @@ var SplitPane = require('naturalcrit/splitPane/splitPane.jsx');
|
|||||||
var Editor = require('../../editor/editor.jsx');
|
var Editor = require('../../editor/editor.jsx');
|
||||||
var BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
var BrewRenderer = require('../../brewRenderer/brewRenderer.jsx');
|
||||||
|
|
||||||
var HijackPrint = require('../hijackPrint.js');
|
|
||||||
var Markdown = require('naturalcrit/markdown.js');
|
var Markdown = require('naturalcrit/markdown.js');
|
||||||
|
|
||||||
|
|
||||||
@@ -65,11 +64,22 @@ var EditPage = React.createClass({
|
|||||||
htmlErrors : Markdown.validate(this.state.text)
|
htmlErrors : Markdown.validate(this.state.text)
|
||||||
})
|
})
|
||||||
|
|
||||||
document.onkeydown = HijackPrint(this.props.brew.shareId);
|
document.addEventListener('keydown', this.handleControlKeys);
|
||||||
},
|
},
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
window.onbeforeunload = 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(){
|
handleSplitMove : function(){
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
//TODO: Depricate
|
||||||
|
|
||||||
module.exports = function(shareId){
|
module.exports = function(shareId){
|
||||||
return function(event){
|
return function(event){
|
||||||
event = event || window.event;
|
event = event || window.event;
|
||||||
|
|||||||
@@ -35,7 +35,22 @@ const NewPage = React.createClass({
|
|||||||
text : storage
|
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(){
|
handleSplitMove : function(){
|
||||||
this.refs.editor.update();
|
this.refs.editor.update();
|
||||||
},
|
},
|
||||||
@@ -54,7 +69,7 @@ const NewPage = React.createClass({
|
|||||||
localStorage.setItem(KEY, text);
|
localStorage.setItem(KEY, text);
|
||||||
},
|
},
|
||||||
|
|
||||||
handleSave : function(){
|
save : function(){
|
||||||
this.setState({
|
this.setState({
|
||||||
isSaving : true
|
isSaving : true
|
||||||
});
|
});
|
||||||
@@ -85,19 +100,19 @@ const NewPage = React.createClass({
|
|||||||
save...
|
save...
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
}else{
|
}else{
|
||||||
return <Nav.item icon='fa-save' className='saveButton' onClick={this.handleSave}>
|
return <Nav.item icon='fa-save' className='saveButton' onClick={this.save}>
|
||||||
save
|
save
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handlePrintClick : function(){
|
print : function(){
|
||||||
localStorage.setItem('print', this.state.text);
|
localStorage.setItem('print', this.state.text);
|
||||||
window.open('/print?dialog=true&local=print','_blank');
|
window.open('/print?dialog=true&local=print','_blank');
|
||||||
},
|
},
|
||||||
|
|
||||||
renderLocalPrintButton : function(){
|
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
|
get PDF
|
||||||
</Nav.item>
|
</Nav.item>
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user