Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<link rel="stylesheet" href="//pulipulichen.github.io/blogger/posts/2016/12/semantic/semantic.min.css">
<link rel="stylesheet" href="http://fontawesome.io/assets/font-awesome/css/font-awesome.css">
<script src="//pulipulichen.github.io/blogger/posts/2016/12/semantic/semantic.min.js"></script>

<!-- ------------------------------------ -->

<form class="file-process-framework ui form dragandrophandler">

  <div class="ui two column doubling grid">
    <div class="column">
	<div class="ui segment">
	
    
<h1 class="ui horizontal divider header">
  Input
</h1>

    <div class="ui top attached tabular menu" style="display: none;">
      <div class="active item" data-tab="file">File</div>
    </div>

<!-- --------------------------------- -->

<!-- --------------------------------- -->

<div class="ui bottom attached tab active segment" data-tab="file">
  <div class="field">
      <label for="files">Please select a fods file: </label>
    </div>
    <div class="field">
      <input class="myfile" name="files[]" id="files" multiple="" type="file" />
      <div class="ui pointing inverted blue large basic label">
        <a href="http://blog.pulipuli.info/2016/12/utf-8notepad-how-to-convert-plain-text.html" target="notepad" style="display: block">How to Convert TXT file to UTF8 encoding?</a>
      </div>
    </div>

  
  <div class="inline field">
    <input type="checkbox" name="autodownload" id="autodownload" checked="checked" />
    <label for="autodownload">Download Processed File Automatically</label>
  </div>


</div> <!-- <div class="ui bottom attached tab segment" data-tab="file"> -->

    <!-- -------------------------------------- -->
    
  <div class="field">
    <div class="loading hide"><img src="//dl.dropboxusercontent.com/u/717137/2016/loading.gif" /></div>
  </div> <!-- <div class="field"> -->
  
		</div> <!-- <div class="ui segment"> -->
	</div> <!-- <div class="column"> -->
  <!-- -------------------------------------- -->
  
    <div class="column">
  <div class="ui segment display-result" style="">
  <!-- <div class="display-result"> -->
  
    <h2 class="ui horizontal divider header">
      Result
    </h2>
    <div class="field">
      <button type="button" class="fluid ui large right labeled icon green button download-file">
        <i class="right download icon"></i>
        DOWNLOAD
      </button>
    </div>

    <div class="field">
      <label for="filename">File Name: </label>
      <input type="text" onfocus="this.select()" id="filename" class="filename" style="width: calc(100% - 15em)" />
    </div>
    
    <div class="field">
      <label for="preview">
        Result Preview: 
        <div class="ui  pointing below  medium blue basic label encoding" style="margin-left: 1em">
          Get error encoding text? <a href="http://blog.pulipuli.info/2016/12/utf-8notepad-how-to-convert-plain-text.html" target="notepad" >Try to Convert TXT file to UTF8 encoding?</a>
        </div>
      </label>
        
      <textarea id="preview" class="preview" onfocus="this.select();"></textarea>
    </div>
  
  </div>
    </div> <!-- <div class="column"> -->
  </div> <!-- <div class="ui two column doubling grid"> -->
</form>
              
            
!

CSS

              
                body {
  padding: 1em !important; 
}
.file-process-framework .loading.hide {
  display:none;
}

.file-process-framework label,
.file-process-framework .download-file {
  display: block;
}

.file-process-framework .input-mode label {
  display: inline;
}

/*
.file-process-framework .download-file {
  font-size: 2em;
  width: 90%;
}
*/

.file-process-framework textarea.preview {
  display: block;
  width: 90%;
  height: calc(100vh - 200px);
}

@media (max-width:600px) {
  .display-result {display: none;}
  .column:not(:first-of-type) {display: none;}
  .header {display: none !important;}
  .column .ui.segment {
    padding: 0;
    border-width: 0 !important;
    margin: 0;
    box-shadow: none;
    position: static;
    background: none;
  }
  .column label, .column .label {display: none !important;}
  .inline.field {display: none;}
  #files {margin: 0;}
  .field {margin: 0 !important;}
  body {padding: 0 !important;}
}
              
            
!

JS

              
                var _process_file = function(_input, _callback) {
  
	var _result = _input;
	var _return = function () {
		if (typeof(_callback) === "function") {
			_callback(_result);
		}
	};
  
	var _end = "<office:scripts>";
	var _end_pos = _input.indexOf(_end);
	if (_end_pos === 1) {
		_return();
	}
	
	var _start = "</office:scripts>";
	var _start_pos = _input.indexOf(_start, _end_pos);
	if (_start_pos === 1) {
		_return();
	}
	
	var _part1 = _input.substr(0, _end_pos);
	var _part2 = _input.substring(_start_pos+_start.length, _input.length);
	_result = _part1 + _part2;
	
	_return();
        
};

var _output_filename_surffix="";


// -------------------------------------

var _load_file = function(evt) {
    //console.log(1);
    if(!window.FileReader) return; // Browser is not compatible

    var _panel = $(".file-process-framework");
    
    _panel.find(".loading").removeClass("hide");

    var reader = new FileReader();
    var _result;

    var _file_name = evt.target.files[0].name;
    
    reader.onload = function(evt) {
        if(evt.target.readyState != 2) return;
        if(evt.target.error) {
            alert('Error while reading file');
            return;
        }

        //filecontent = evt.target.result;

        //document.forms['myform'].elements['text'].value = evt.target.result;
        _result =  evt.target.result;

        _process_file(_result, function (_result) {
            _panel.find(".preview").val(_result);
            _panel.find(".filename").val(_file_name);
                        
            $(".file-process-framework .myfile").val("");
            $(".file-process-framework .loading").addClass("hide");
            _panel.find(".display-result").show();
            _panel.find(".display-result .encoding").show();

            var _auto_download = (_panel.find('[name="autodownload"]:checked').length === 1);
            if (_auto_download === true) {
                _panel.find(".download-file").click();
            }
            
            //_download_file(_result, _file_name, "txt");
        })
    };

    var _pos = _file_name.lastIndexOf(".");
    _file_name = _file_name.substr(0, _pos)
        + _output_filename_surffix
        + _file_name.substring(_pos, _file_name.length);

    //console.log(_file_name);

    reader.readAsText(evt.target.files[0]);
};

var _load_textarea = function(evt) {
    var _panel = $(".file-process-framework");
    
    // --------------------------

    var _result = _panel.find(".input-mode.textarea").val();
    if (_result.trim() === "") {
        return;
    }

    // ---------------------------
    
    _panel.find(".loading").removeClass("hide");

    // ---------------------------
    var d = new Date();
    var utc = d.getTime() - (d.getTimezoneOffset() * 60000);
  
    var local = new Date(utc);
    var _file_name = local.toJSON().slice(0,19).replace(/:/g, "-");
    _file_name = "output_" + _file_name + ".txt";

    // ---------------------------

    _process_file(_result, function (_result) {
        _panel.find(".preview").val(_result);
        _panel.find(".filename").val(_file_name);

        _panel.find(".loading").addClass("hide");
        _panel.find(".display-result").show();
        _panel.find(".display-result .encoding").hide();

        var _auto_download = (_panel.find('[name="autodownload"]:checked').length === 1);
        if (_auto_download === true) {
            _panel.find(".download-file").click();
        }
    });
};

var _download_file_button = function () {
    var _panel = $(".file-process-framework");
    
    var _file_name = _panel.find(".filename").val();
    var _data = _panel.find(".preview").val();
    
    _download_file(_data, _file_name, "txt");
};


var _download_file = function (data, filename, type) {
    var a = document.createElement("a"),
        file = new Blob([data], {type: type});
    if (window.navigator.msSaveOrOpenBlob) // IE10+
        window.navigator.msSaveOrOpenBlob(file, filename);
    else { // Others
        var url = URL.createObjectURL(file);
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        setTimeout(function() {
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);  
        }, 0); 
    }

}

// -----------------------------

var _handleFileUpload = function (_files, _obj) {
	//console.log(1);
    if(!window.FileReader) return; // Browser is not compatible

    var _panel = $(".file-process-framework");
    
    _panel.find(".loading").removeClass("hide");

	//console.log(_files[0]);
	
	var reader = new FileReader();
	
	var _result;

    var _file_name = _files[0].name;
    
    reader.onload = function(evt) {
        if(evt.target.readyState != 2) return;
        if(evt.target.error) {
            alert('Error while reading file');
            return;
        }

        //filecontent = evt.target.result;

        //document.forms['myform'].elements['text'].value = evt.target.result;
        _result =  evt.target.result;

        _process_file(_result, function (_result) {
            _panel.find(".preview").val(_result);
            _panel.find(".filename").val(_file_name);
                        
            $(".file-process-framework .myfile").val("");
            $(".file-process-framework .loading").addClass("hide");
            _panel.find(".display-result").show();
            _panel.find(".display-result .encoding").show();

            var _auto_download = (_panel.find('[name="autodownload"]:checked').length === 1);
            if (_auto_download === true) {
                _panel.find(".download-file").click();
            }
            
            //_download_file(_result, _file_name, "txt");
        })
    };

    var _pos = _file_name.lastIndexOf(".");
    _file_name = _file_name.substr(0, _pos)
        + _output_filename_surffix
        + _file_name.substring(_pos, _file_name.length);
	
	reader.readAsText(_files[0]);
};

$(function () {
	var obj = $("body");
	obj.on('dragenter', function (e) 
	{
		e.stopPropagation();
		e.preventDefault();
		$(this).css('border', '2px solid #0B85A1');
	});
	obj.on('dragover', function (e) 
	{
		 e.stopPropagation();
		 e.preventDefault();
	});
	obj.on('drop', function (e) 
	{
	 
		 $(this).css('border', '2px dotted #0B85A1');
		 e.preventDefault();
		 var files = e.originalEvent.dataTransfer.files;
	 
		 //We need to send dropped files to Server
		 _handleFileUpload(files,obj);
	});
});

// -----------------------------

$(function () {
  var _panel = $(".file-process-framework");
  _panel.find(".input-mode.textarea").click(_load_textarea).keyup(_load_textarea);
  _panel.find(".myfile").change(_load_file);
  _panel.find(".download-file").click(_download_file_button);
  
  $('.menu .item').tab();
});
              
            
!
999px

Console