', {
'class': 'cp-modal-close fa fa-times',
'title': Messages.filePicker_close
- }).click(function () {
- $blockContainer.hide();
- }).appendTo($block);
+ }).click(hide).appendTo($block);
+ $body.click(hide);
+ $block.click(function (e) {
+ e.stopPropagation();
+ });
$body.keydown(function (e) {
- if (e.which === 27) { $blockContainer.hide(); }
+ if (e.which === 27) {
+ hide();
+ }
});
return $blockContainer;
};
diff --git a/www/common/sframe-channel.js b/www/common/sframe-channel.js
index 6bfffb028..fc9bcd0dd 100644
--- a/www/common/sframe-channel.js
+++ b/www/common/sframe-channel.js
@@ -109,8 +109,9 @@ define([
window.addEventListener('message', function (msg) {
var data = JSON.parse(msg.data);
if (ow !== msg.source) {
- console.log("DROP Message from unexpected source");
- console.log(msg);
+ return;
+ //console.log("DROP Message from unexpected source");
+ //console.log(msg);
} else if (!otherWindow) {
otherWindow = ow;
ow.postMessage(JSON.stringify({ txid: data.txid }), '*');
diff --git a/www/common/sframe-common-interface.js b/www/common/sframe-common-interface.js
index 57fb3c6d1..5885e2f93 100644
--- a/www/common/sframe-common-interface.js
+++ b/www/common/sframe-common-interface.js
@@ -261,18 +261,40 @@ define([
return $userAdmin;
};
+ // createFileDialog can only be used in filepicker due to access rights restrictions
UI.createFileDialog = function (cfg) {
var common = cfg.common;
+ var sframeChan = common.getSframeChannel();
+ var updateContainer;
+ var hideFileDialog = function () {
+ sframeChan.event('EV_FILE_PICKER_CLOSE');
+ };
+ // Create modal
var $blockContainer = Cryptpad.createModal({
id: 'fileDialog',
- $body: cfg.$body
- });
+ $body: cfg.$body,
+ onClose: hideFileDialog
+ }).show();
+ // Set the fixed content
var $block = $blockContainer.find('.cp-modal');
var $description = $('').text(Messages.filePicker_description);
$block.append($description);
var $filter = $('
', {'class': 'cp-modal-form'}).appendTo($block);
+ var to;
+ $('', {
+ type: 'text',
+ 'class': 'filter',
+ 'placeholder': Messages.filePicker_filter
+ }).appendTo($filter).on('keypress', function () {
+ if (to) { window.clearTimeout(to); }
+ to = window.setTimeout(updateContainer, 300);
+ });
+ $filter.append(common.createButton('upload', false, cfg.data, function () {
+ hideFileDialog();
+ }));
var $container = $('', {'class': 'fileContainer'}).appendTo($block);
- var updateContainer = function () {
+ // Update the files list when needed
+ updateContainer = function () {
$container.html('');
var filter = $filter.find('.filter').val().trim();
var todo = function (err, list) {
@@ -291,28 +313,27 @@ define([
$span.append(name);
$span.click(function () {
if (typeof cfg.onSelect === "function") { cfg.onSelect(data.href); }
- $blockContainer.hide();
+ hideFileDialog();
});
});
};
common.getFilesList(todo);
};
- var to;
- $('', {
- type: 'text',
- 'class': 'filter',
- 'placeholder': Messages.filePicker_filter
- }).appendTo($filter).on('keypress', function () {
- if (to) { window.clearTimeout(to); }
- to = window.setTimeout(updateContainer, 300);
- });
- //$filter.append(' '+Messages.or+' ');
- /*var data = {FM: cfg.data.FM};
- $filter.append(common.createButton('upload', false, data, function () {
- $blockContainer.hide();
- }));*/
updateContainer();
- $blockContainer.show();
+ sframeChan.on('EV_FILE_PICKER_REFRESH', updateContainer);
+ };
+
+
+ UI.initFilePicker = function (common, cfg) {
+ var onSelect = cfg.onSelect || $.noop;
+ var sframeChan = common.getSframeChannel();
+ sframeChan.on("EV_FILE_PICKED", function (data) {
+ onSelect(data);
+ });
+ };
+ UI.openFilePicker = function (common) {
+ var sframeChan = common.getSframeChannel();
+ sframeChan.event("EV_FILE_PICKER_OPEN");
};
return UI;
diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js
index c819b3c30..e56142ae1 100644
--- a/www/common/sframe-common-outer.js
+++ b/www/common/sframe-common-outer.js
@@ -14,6 +14,7 @@ define([
var Crypto;
var Cryptget;
var sframeChan;
+ var FilePicker;
nThen(function (waitFor) {
// Load #2, the loading screen is up so grab whatever you need...
@@ -23,11 +24,14 @@ define([
'/bower_components/chainpad-crypto/crypto.js',
'/common/cryptget.js',
'/common/sframe-channel.js',
- ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel) {
+ '/filepicker/main.js',
+ ], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, SFrameChannel,
+ _FilePicker) {
CpNfOuter = _CpNfOuter;
Cryptpad = _Cryptpad;
Crypto = _Crypto;
Cryptget = _Cryptget;
+ FilePicker = _FilePicker;
SFrameChannel.create($('#sbox-iframe')[0].contentWindow, waitFor(function (sfc) {
sframeChan = sfc;
}));
@@ -215,7 +219,7 @@ define([
});
- sframeChan.on('Q_UPLOAD_FILE', function (data, cb) {
+ var onFileUpload = function (sframeChan, data, cb) {
var sendEvent = function (data) {
sframeChan.event("EV_FILE_UPLOAD_STATE", data);
};
@@ -245,6 +249,31 @@ define([
data.blob = Crypto.Nacl.util.decodeBase64(data.blob);
Cryptpad.uploadFileSecure(data, data.noStore, Cryptpad, updateProgress, onComplete, onError, onPending);
cb();
+ };
+ sframeChan.on('Q_UPLOAD_FILE', function (data, cb) {
+ onFileUpload(sframeChan, data, cb);
+ });
+
+ var FP = {};
+ var initFilePicker = function () {
+ var config = {};
+ config.onFilePicked = function (data) {
+ sframeChan.event('EV_FILE_PICKED', data);
+ };
+ config.onClose = function () {
+ FP.$iframe.hide();
+ };
+ config.onFileUpload = onFileUpload;
+ if (!FP.$iframe) {
+ FP.$iframe = $('