export file with correct file extension, if possible

This commit is contained in:
ansuz 2016-07-25 11:26:42 +02:00
parent 5e71a5473c
commit efd190beca
2 changed files with 51 additions and 32 deletions

View File

@ -102,19 +102,6 @@ define([
editor.setOption('readOnly', !bool); editor.setOption('readOnly', !bool);
}; };
var exportText = module.exportText = function () {
var text = editor.getValue();
Cryptpad.prompt(Messages.exportPrompt,
document.title, function (filename) {
if (filename === null) { return; }
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 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 toolbarList; // List of users still connected to the channel (server IDs)
var addToUserList = function(data) { var addToUserList = function(data) {
@ -246,6 +233,22 @@ define([
} }
}; };
var exportText = module.exportText = function () {
var text = editor.getValue();
var ext = Modes.extensionOf(module.highlightMode);
var title = Cryptpad.fixFileName(suggestName()) + ext;
Cryptpad.prompt(Messages.exportPrompt, title, function (filename) {
if (filename === null) { return; }
var blob = new Blob([text], {
type: 'text/plain;charset=utf-8'
});
saveAs(blob, filename);
});
};
var onInit = config.onInit = function (info) { var onInit = config.onInit = function (info) {
//Cryptpad.warn("Initializing realtime session..."); //Cryptpad.warn("Initializing realtime session...");
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox'); var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
@ -279,7 +282,7 @@ define([
var mode = mime && mime.mode || null; var mode = mime && mime.mode || null;
if (Modes.some(function (o) { return o.mode === mode; })) { if (Modes.list.some(function (o) { return o.mode === mode; })) {
setMode(mode); setMode(mode);
$bar.find('#language-mode').val(mode); $bar.find('#language-mode').val(mode);
} else { } else {
@ -337,7 +340,7 @@ define([
/* Let the user select different syntax highlighting modes */ /* Let the user select different syntax highlighting modes */
var syntaxDropdown = '<select title="syntax highlighting" id="language-mode">\n' + var syntaxDropdown = '<select title="syntax highlighting" id="language-mode">\n' +
Modes.map(function (o) { Modes.list.map(function (o) {
var selected = o.mode === lastLanguage? ' selected="selected"' : ''; var selected = o.mode === lastLanguage? ' selected="selected"' : '';
return '<option value="' + o.mode + '"'+selected+'>' + o.language + '</option>'; return '<option value="' + o.mode + '"'+selected+'>' + o.language + '</option>';
}).join('\n') + }).join('\n') +

View File

@ -1,10 +1,13 @@
define(function () { define(function () {
return [ var Modes = {};
"apl apl",
// mode language (extension)
var list = Modes.list = [
"apl apl .apl",
"asciiarmor asciiarmor", "asciiarmor asciiarmor",
"asn.1 asn.1", "asn.1 asn.1",
"asterisk asterisk", "asterisk asterisk",
"brainfuck brainfuck", "brainfuck brainfuck .b",
"clike clike", "clike clike",
"clojure clojure", "clojure clojure",
"cmake cmake", "cmake cmake",
@ -12,7 +15,7 @@ define(function () {
"coffeescript coffeescript", "coffeescript coffeescript",
"commonlisp commonlisp", "commonlisp commonlisp",
"crystal crystal", "crystal crystal",
"css css", "css css .css",
"cypher cypher", "cypher cypher",
"d d", "d d",
"dart dart", "dart dart",
@ -24,36 +27,36 @@ define(function () {
"ebnf ebnf", "ebnf ebnf",
"ecl ecl", "ecl ecl",
"eiffel eiffel", "eiffel eiffel",
"elm elm", "elm elm .elm",
"erlang erlang", "erlang erlang",
"factor factor", "factor factor",
"fcl fcl", "fcl fcl",
"forth forth", "forth forth",
"fortran fortran", "fortran fortran",
"gas gas", "gas gas",
"gfm gfm", "gfm gfm .md",
"gherkin gherkin", "gherkin gherkin",
"go go", "go go",
"groovy groovy", "groovy groovy",
"haml haml", "haml haml",
"handlebars handlebars", "handlebars handlebars",
"haskell haskell", "haskell haskell .hs",
"haskell-literate haskell-literate", "haskell-literate haskell-literate",
"haxe haxe", "haxe haxe",
"htmlembedded htmlembedded", "htmlembedded htmlembedded",
"htmlmixed htmlmixed", "htmlmixed htmlmixed .html",
"http http", "http http",
"idl idl", "idl idl",
"index.html index.html", "index.html index.html",
"jade jade", "jade jade",
"javascript javascript", "javascript javascript .js",
"jinja2 jinja2", "jinja2 jinja2",
"jsx jsx", "jsx jsx .jsx",
"julia julia", "julia julia",
"livescript livescript", "livescript livescript",
"loadmode.js loadmode.js", "loadmode.js loadmode.js",
"lua lua", "lua lua",
"markdown markdown", "markdown markdown .md",
"mathematica mathematica", "mathematica mathematica",
"meta.js meta.js", "meta.js meta.js",
"mirc mirc", "mirc mirc",
@ -74,7 +77,7 @@ define(function () {
"properties properties", "properties properties",
"protobuf protobuf", "protobuf protobuf",
"puppet puppet", "puppet puppet",
"python python", "python python .py",
"q q", "q q",
"r r", "r r",
"rpm rpm", "rpm rpm",
@ -82,8 +85,8 @@ define(function () {
"ruby ruby", "ruby ruby",
"rust rust", "rust rust",
"sass sass", "sass sass",
"scheme scheme", "scheme scheme .scm",
"shell shell", "shell shell .sh",
"sieve sieve", "sieve sieve",
"slim slim", "slim slim",
"smalltalk smalltalk", "smalltalk smalltalk",
@ -97,7 +100,7 @@ define(function () {
"stylus stylus", "stylus stylus",
"swift swift", "swift swift",
"tcl tcl", "tcl tcl",
"text text", "text text .txt",
"textile textile", "textile textile",
"tiddlywiki tiddlywiki", "tiddlywiki tiddlywiki",
"tiki tiki", "tiki tiki",
@ -117,14 +120,27 @@ define(function () {
"xml xml", "xml xml",
//"xwiki xwiki21", //"xwiki xwiki21",
"xquery xquery", "xquery xquery",
"yaml yaml", "yaml yaml .yaml",
"yaml-frontmatter yaml-frontmatter", "yaml-frontmatter yaml-frontmatter",
"z80 z80" "z80 z80"
].map(function (line) { ].map(function (line) {
var kv = line.split(/\s/); var kv = line.split(/\s/);
return { return {
language: kv[0].replace(/_/g, ' '), language: kv[0].replace(/_/g, ' '),
mode: kv[1] mode: kv[1],
ext: kv[2],
}; };
}); });
var extensionOf = Modes.extensionOf = function (mode) {
var ext = '';
list.some(function (o) {
if (o.mode !== mode) { return; }
ext = o.ext || '';
return true;
});
return ext;
};
return Modes;
}); });