-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
95 lines (80 loc) · 2.31 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function commande(nom, argument){
if (typeof argument === 'undefined') {
argument = '';
}
document.execCommand(nom, false, argument);
}
function rafraichit(){
var valeur = $('.editeur').html();
$('.htmlview').text(valeur);
}
$(document).ready(function(){
$('button').click(function(){
var id = $(this).attr('id');
switch(id){
case "createLink":
argument = prompt("Insert link");
commande(id, argument);
break;
case "insertImage":
argument = prompt("Insert image");
commande(id, argument);
break;
case "forecolor":
argument = prompt("name the color of text");
commande(id, argument);
break;
case "backcolor":
argument = prompt("name the color of background");
commande(id, argument);
break;
case "fontsize":
argument = prompt("Enter the text font size");
commande(id, argument);
break;
case "fontName":
argument = prompt("name the font style");
commande(id, argument);
break;
case "insertText":
argument = prompt("write the text");
commande(id, argument);
break;
default:
commande(id);
break;
}
rafraichit();
});
$('.editeur').keyup(function(){
rafraichit();
});
});
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
document.getElementById("save").addEventListener("click", function(){
var text = document.getElementById("editeur").value;
var filename = document.getElementById("textfeild").value;
download(filename+".txt", text);
}, false);
var doc = new jsPDF();
var specialElementHandlers = {
'#editor': function (element, renderer) {
return true;
}
};
$('#cmd').click(function () {
doc.fromHTML($('#editeur').html(), 15, 15, {
'width': 170,
'elementHandlers': specialElementHandlers
});
var filename = document.getElementById("textfeild").value;
doc.save(filename +".pdf");
});