Skip to content

Commit

Permalink
Merge pull request #21 from neizerth/master
Browse files Browse the repository at this point in the history
update
  • Loading branch information
amosyagina authored Aug 13, 2018
2 parents 90f4d58 + b467529 commit 78527cb
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions file-api/text-editor/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,17 @@ class TextEditor {
registerEvents() {
const save = throttle( this.save.bind( this ), 1000 );
this.contentContainer.addEventListener( 'input', save );
this.container.addEventListener( 'dragover', this.showHint.bind( this ));
this.container.addEventListener( 'drop', this.loadFile.bind( this ));
}
loadFile( e ) {
e.preventDefault();
const [ file ] = e.dataTransfer.files,
{ type, name } = file;
if ( type !== 'text/plain' ) {
return;
}
this.readFile( file )
.then( e => this.load( e.target.result ));
this.setFilename( name );
this.hideHint();
}
readFile( file ) {
const reader = new FileReader,
promise = new Promise( resolve =>
reader.addEventListener( 'load', resolve ));
reader.readAsText(file);
return promise;
}
setFilename( filename ) {
this.filenameContainer.textContent = filename;
}
showHint( e ) {
e.preventDefault();
this.hintContainer.classList.add( 'text-editor__hint_visible' );
}
hideHint() {
this.hintContainer.classList.remove( 'text-editor__hint_visible' );
}
load( value ) {
this.contentContainer.value = value || '';
Expand Down

0 comments on commit 78527cb

Please sign in to comment.