add file export for codepad

addresses #24
pull/1/head
ansuz 9 years ago
parent 920dbeabd1
commit c3d2568d3c

@ -8,10 +8,12 @@ define([
'/common/toolbar.js',
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.min.js',
'/customize/pad.js'
], function (Config, /*RTCode,*/ Messages, Crypto, Realtime, TextPatcher, Toolbar, JSONSortify, JsonOT) {
var $ = window.jQuery;
var saveAs = window.saveAs;
var module = window.APP = {};
var ifrw = module.ifrw = $('#pad-iframe')[0].contentWindow;
var stringify = function (obj) {
@ -57,6 +59,15 @@ define([
editor.setOption('readOnly', !bool);
};
var exportText = module.exportText = function () {
var text = editor.getValue();
var filename = window.prompt("What would you like to name your file?");
if (filename) {
var blob = new Blob([text], {type: "text/plain;charset=utf-8"});
saveAs(blob, filename);
}
};
var userList = {}; // List of pretty name of all users (mapped with their server ID)
var toolbarList; // List of users still connected to the channel (server IDs)
var addToUserList = function(data) {
@ -134,10 +145,13 @@ define([
toolbarList = info.userList;
var config = {
userData: userList,
changeNameID: 'cryptpad-changeName'
changeNameID: 'cryptpad-changeName',
saveContentID: 'cryptpad-saveContent',
};
toolbar = info.realtime.toolbar = Toolbar.create($bar, info.myID, info.realtime, info.getLag, info.userList, config);
createChangeName('cryptpad-changeName', $bar);
$bar.find('#cryptpad-saveContent').click(exportText);
window.location.hash = info.channel + key;
};

@ -14,6 +14,8 @@ define([
/** Id of the div containing the lag info. */
var LAG_ELEM_CLS = 'rtwysiwyg-lag';
var SAVE_ELEMENT_CLS = 'cryptpad-saveContent';
/** The toolbar class which contains the user list, debug link and lag. */
var TOOLBAR_CLS = 'rtwysiwyg-toolbar';
@ -96,6 +98,7 @@ define([
'.' + DEBUG_LINK_CLS + ':link:hover { color:blue; }',
'.gwt-TabPanelBottom { border-top: 0 none; }',
'.' + TOOLBAR_CLS + ' button { box-sizing: border-box; height: 101%; background-color: inherit; border: 1px solid #A6A6A6; border-radius: 5px; margin-right: 5px;}',
'.' + TOOLBAR_CLS + ' ' + SAVE_ELEMENT_CLS + '{ float: right; margin-right: 5px; }',
'</style>'
].join('\n'));
@ -178,6 +181,11 @@ define([
return $container.find('#'+id)[0];
};
var createSaveElement = function (id, $container) {
$container.append('<button class="'+ SAVE_ELEMENT_CLS + '" id="' + id + '">SAVE</button>');
return $container.find('#'+id)[0];
};
var checkLag = function (getLag, lagElement) {
if(typeof getLag !== "function") { return; }
var lag = getLag();
@ -230,6 +238,8 @@ define([
var lagElement = createLagElement(toolbar.find('.rtwysiwyg-toolbar-rightside'));
var userData = config.userData;
var changeNameID = config.changeNameID;
var saveContentID = config.saveContentID;
var saveElement;
// Check if the user is allowed to change his name
if(changeNameID) {
@ -237,6 +247,10 @@ define([
userListElement = createChangeName($container, userListElement, changeNameID);
}
if (saveContentID) {
saveElement = createSaveElement(saveContentID, toolbar.find('.rtwysiwyg-toolbar-rightside'));
}
rememberPad();
var connected = false;

Loading…
Cancel
Save