MCPcopy Create free account
hub / github.com/TruthHun/BookStack / importFiles

Function importFiles

static/mergely/editor/editor.js:494–575  ·  view source on GitHub ↗
(ed)

Source from the content-addressed store, hash-verified

492 }
493
494 function importFiles(ed) {
495 // -------------
496 // file uploader - html5 file upload to browser
497 function file_load(target, side) {
498 var file = target.files[0];
499 var reader = new FileReader();
500 var $target = $(target);
501 function trigger(name, event) { $target.trigger(name, event); }
502 reader.onloadstart = function(evt) { trigger('start'); }
503 reader.onprogress = function(evt) { trigger('progress', evt); }
504 reader.onload = function(evt) { trigger('loaded', evt.target.result); }
505 reader.onerror = function (evt) {
506 alert(evt.target.error.name);
507 }
508 try {
509 reader.readAsText(file, 'UTF-8');
510 }
511 catch (e) {
512 console.error(e);
513 alert(e);
514 }
515 }
516 var file_data = {};
517 $('#file-lhs, #file-rhs').change(function (evt) {
518 var re = new RegExp('.*[\\\\/](.*)$');
519 var match = re.exec($(this).val());
520 var fname = match ? match[1] : 'unknown';
521
522 var progressbar = $('#' + evt.target.id + '-progress');
523
524 file_load(evt.target);
525 $(evt.target).bind('start', function(ev){
526 $(evt.target).css('display', 'none');
527 progressbar.css('display', 'inline-block');
528 });
529 $(evt.target).bind('progress', function(ev, progress){
530 var loaded = (progress.loaded / progress.total) * 100;
531 progressbar.find('> .progress-label').text(loaded + '%');
532 progressbar.progressbar('value', loaded);
533 });
534 $(evt.target).bind('loaded', function(ev, file){
535 progressbar.progressbar('value', 100);
536 progressbar.find('> .progress-label').text(fname);
537 file_data[evt.target.id] = file;
538 });
539 });
540
541 $('#file-lhs-progress').progressbar({value: 0});
542 $('#file-rhs-progress').progressbar({value: 0});
543 $('#dialog-upload .tabs').tabs();
544 function callbackName(data) {
545 console.log('callbackName', data);
546 }
547 $('#dialog-upload').dialog({
548 dialogClass: 'no-title',
549 resizable: false,
550 width: '450px',
551 modal: true,

Callers 1

handle_operationFunction · 0.70

Calls 4

textMethod · 0.80
file_loadFunction · 0.70
crossdomainGETFunction · 0.70
$Function · 0.50

Tested by

no test coverage detected