-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheditor.js
144 lines (114 loc) · 3.95 KB
/
editor.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
var ssml = ssml || {};
function removethis(e){
$(e).parent().remove();
}
function insertbreak(e){
cls = e.innerText;
cls = cls.replace('s','');
var sel, range;
if (window.getSelection && (sel = window.getSelection()).rangeCount) {
range = sel.getRangeAt(0);
var icon = '<i class="far fa-clock" style="margin-left:2px" onclick="removethis(this)"></i>';
range.deleteContents();
range.collapse(true);
var span = document.createElement("span");
span.setAttribute('class', 'break-icon');
span.setAttribute('contenteditable', 'false');
span.setAttribute('value', cls);
span.innerHTML = icon;
range.insertNode(span);
// Move the caret immediately after the inserted span
range.setStartAfter(span);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
function converttotag(cls){
var sel, range;
if (window.getSelection && (sel = window.getSelection()).rangeCount) {
range = sel.getRangeAt(0);
var str = sel.toString();
var icon = '<i class="inside-icon far fa-times-circle" style="margin-left:2px" onclick="removethis(this)"></i>';
str = str + icon;
range.deleteContents();
range.collapse(true);
var span = document.createElement("span");
span.setAttribute('class', cls);
span.setAttribute('contenteditable', 'false');
span.innerHTML = str;
range.insertNode(span);
// Move the caret immediately after the inserted span
range.setStartAfter(span);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
ssml.actions = {
convertToSsml: function() {
var html = $(".editor").html();
var $newContent = $("<p/>");
/* Wrap text */
$newContent.append(html);
/* remove nbsp */
$newContent.html(function (i, html) {
return html.replace(/ /g, ' ');
});
/* remove icons */
$newContent.find("i").replaceWith(function(){
return '';
});
/* replace pause */
$newContent.find(".break-icon").replaceWith(function(){
console.log($(this).attr('value'));
return `<break time="${$(this).attr('value')}"/>`
});
/* replace linebreaks */
$newContent.find("p").each(function(){
if ($.trim($(this).text()) == ""){
$(this).remove();
}
});
/* replace br */
$newContent.find("br").replaceWith(function(){
return '';
})
/* replace strong */
$newContent.find(".emphasis").replaceWith(function(){
return '<emphasis level="strong">' + this.innerHTML + "</emphasis>";
})
/* replace slow */
$newContent.find(".slow").replaceWith(function(){
return '<prosody rate="slow">' + this.innerHTML + "</prosody>";
})
/* replace fast */
$newContent.find(".pitch-down").replaceWith(function(){
return '<prosody rate="fast">' + this.innerHTML + "</prosody>";
})
console.log( $newContent);
console.log("<speak>" + $newContent[0].innerHTML + "</speak>");
}
}
ssml.listners = {
actionbuttons: function() {
$(".action-button").on("click", function (event) {
event.preventDefault();
var action = $(this).data("action");
eval(action);
});
}
},
ssml.init = function () {
this.listners.actionbuttons();
document.execCommand("defaultParagraphSeparator", false, "p");
document.querySelector("div[contenteditable]").addEventListener("paste", function(e) {
e.preventDefault();
var text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
});
}
$(function () {
"use strict";
ssml.init();
});