From a82362cda2f348a066075c9ab7887eec1df815e3 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 2 Sep 2016 09:01:34 +0200 Subject: [PATCH] filereader for stikkedizr --- htdocs/themes/stikkedizr/js/stikked.js | 57 +++++++++++++++++++ .../stikkedizr/views/defaults/footer.php | 1 + htdocs/themes/stikkedizr/views/view/view.php | 2 +- .../stikkedizr/views/view/view_footer.php | 1 + 4 files changed, 60 insertions(+), 1 deletion(-) diff --git a/htdocs/themes/stikkedizr/js/stikked.js b/htdocs/themes/stikkedizr/js/stikked.js index 2ae0a04..5b9b317 100644 --- a/htdocs/themes/stikkedizr/js/stikked.js +++ b/htdocs/themes/stikkedizr/js/stikked.js @@ -202,12 +202,69 @@ ST.crypto_generate_key = function(len) { return key; } +ST.filereader = function() { + $("#code").fileReaderJS({ + // CSS Class to add to the drop element when a drag is active + dragClass: "drag", + + // A string to match MIME types, for instance + accept: false, + + // An object specifying how to read certain MIME types + // For example: { + // 'image/*': 'DataURL', + // 'data/*': 'ArrayBuffer', + // 'text/*' : 'Text' + // } + readAsMap: {}, + + // How to read any files not specified by readAsMap + readAsDefault: 'DataURL', + on: { + beforestart: function(e, file) { + // return false if you want to skip this file + }, + loadstart: function(e, file) { /* Native ProgressEvent */ }, + progress: function(e, file) { /* Native ProgressEvent */ }, + load: function(e, file) { /* Native ProgressEvent */ }, + error: function(e, file) { /* Native ProgressEvent */ }, + loadend: function(e, file) { + try { + var words = CryptoJS.enc.Base64.parse(e.target.result.split(',')[1]); + var utf8 = CryptoJS.enc.Utf8.stringify(words); + $('#code').val(utf8); + } catch (err) { + console.error(err); + console.info('event: ', e); + console.info('file: ', file); + }; + }, + abort: function(e, file) { /* Native ProgressEvent */ }, + skip: function(e, file) { + // Called when a file is skipped. This happens when: + // 1) A file doesn't match the accept option + // 2) false is returned in the beforestart callback + }, + groupstart: function(group) { + // Called when a 'group' (a single drop / copy / select that may + // contain multiple files) is receieved. + // You can ignore this event if you don't care about groups + }, + groupend: function(group) { + // Called when a 'group' is finished. + // You can ignore this event if you don't care about groups + } + } + }); +} + ST.init = function() { ST.expand(); ST.show_embed(); ST.spamadmin(); ST.line_highlighter(); ST.crypto(); + ST.filereader(); }; $(document).ready(function() { diff --git a/htdocs/themes/stikkedizr/views/defaults/footer.php b/htdocs/themes/stikkedizr/views/defaults/footer.php index de178d4..31c8380 100644 --- a/htdocs/themes/stikkedizr/views/defaults/footer.php +++ b/htdocs/themes/stikkedizr/views/defaults/footer.php @@ -15,6 +15,7 @@ $this->carabiner->js('jquery.js'); $this->carabiner->js('jquery.timers.js'); $this->carabiner->js('crypto-js/rollups/aes.js'); $this->carabiner->js('lz-string-1.3.3-min.js'); +$this->carabiner->js('filereader.js'); $this->carabiner->js('stikked.js'); $this->carabiner->js('codemirror/codemirror.js'); $this->carabiner->js('codemirror_exec.js'); diff --git a/htdocs/themes/stikkedizr/views/view/view.php b/htdocs/themes/stikkedizr/views/view/view.php index 87c86a0..3feb83f 100644 --- a/htdocs/themes/stikkedizr/views/view/view.php +++ b/htdocs/themes/stikkedizr/views/view/view.php @@ -54,7 +54,7 @@ if(isset($insert)){
-
+
diff --git a/htdocs/themes/stikkedizr/views/view/view_footer.php b/htdocs/themes/stikkedizr/views/view/view_footer.php index 00b034b..e2cac07 100644 --- a/htdocs/themes/stikkedizr/views/view/view_footer.php +++ b/htdocs/themes/stikkedizr/views/view/view_footer.php @@ -10,6 +10,7 @@ $this->carabiner->js('jquery.js'); $this->carabiner->js('jquery.timers.js'); $this->carabiner->js('crypto-js/rollups/aes.js'); $this->carabiner->js('lz-string-1.3.3-min.js'); +$this->carabiner->js('filereader.js'); $this->carabiner->js('stikked.js'); $this->carabiner->js('codemirror/codemirror.js'); $this->carabiner->js('codemirror_exec.js');