abcjs 6.0.0-beta.7 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/tests.yml +29 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/CONTRIBUTING.md +1 -0
- package/LICENSE.md +1 -1
- package/README.md +92 -3
- package/RELEASE.md +957 -1
- package/abcjs-audio.css +14 -5
- package/dist/.gitignore +1 -2
- package/dist/abcjs-basic-min.js +3 -0
- package/dist/abcjs-basic-min.js.LICENSE +23 -0
- package/dist/abcjs-basic.js +28231 -0
- package/dist/abcjs-basic.js.map +1 -0
- package/dist/abcjs-plugin-min.js +3 -0
- package/dist/abcjs-plugin-min.js.LICENSE +23 -0
- package/dist/report-basic.html +37 -0
- package/dist/report-before-glyph-compress.html +37 -0
- package/dist/report-brown-ts-target-es5.html +37 -0
- package/dist/report-dev-orig-no-babel.html +37 -0
- package/dist/report-synth.html +37 -0
- package/docker-build.sh +1 -0
- package/glyphs.json +1 -0
- package/index.js +27 -2
- package/{static-wrappers/license.js → license.js} +1 -1
- package/package.json +26 -29
- package/{src/plugin/abc_plugin.js → plugin.js} +31 -19
- package/src/api/abc_animation.js +1 -17
- package/src/api/abc_tablatures.js +144 -0
- package/src/api/abc_timing_callbacks.js +234 -116
- package/src/api/abc_tunebook.js +18 -67
- package/src/api/abc_tunebook_svg.js +38 -46
- package/src/data/abc_tune.js +232 -972
- package/src/data/deline-tune.js +199 -0
- package/src/edit/abc_editarea.js +112 -0
- package/src/edit/abc_editor.js +95 -221
- package/src/midi/abc_midi_create.js +48 -50
- package/src/parse/abc_common.js +0 -14
- package/src/parse/abc_parse.js +167 -1321
- package/src/parse/abc_parse_book.js +62 -0
- package/src/parse/abc_parse_directive.js +164 -41
- package/src/parse/abc_parse_header.js +116 -145
- package/src/parse/abc_parse_key_voice.js +26 -20
- package/src/parse/abc_parse_music.js +1337 -0
- package/src/parse/abc_tokenizer.js +21 -15
- package/src/parse/abc_transpose.js +3 -15
- package/src/parse/tune-builder.js +896 -0
- package/src/parse/wrap_lines.js +205 -453
- package/src/synth/abc_midi_flattener.js +1292 -0
- package/src/{midi → synth}/abc_midi_renderer.js +44 -17
- package/src/synth/abc_midi_sequencer.js +648 -0
- package/src/synth/active-audio-context.js +3 -14
- package/src/synth/cents-to-factor.js +10 -0
- package/src/synth/create-note-map.js +21 -32
- package/src/synth/create-synth-control.js +20 -103
- package/src/synth/create-synth.js +185 -77
- package/src/synth/download-buffer.js +7 -21
- package/src/synth/get-midi-file.js +13 -20
- package/src/synth/images/{loading.svg → loading.svg.js} +4 -0
- package/src/synth/images/loop.svg.js +65 -0
- package/src/synth/images/pause.svg.js +10 -0
- package/src/synth/images/play.svg.js +9 -0
- package/src/synth/images/{reset.svg → reset.svg.js} +5 -1
- package/src/synth/instrument-index-to-name.js +1 -16
- package/src/synth/load-note.js +37 -76
- package/src/synth/pitch-to-note-name.js +0 -15
- package/src/synth/pitches-to-perc.js +64 -0
- package/src/synth/place-note.js +78 -68
- package/src/synth/play-event.js +17 -18
- package/src/synth/register-audio-context.js +11 -23
- package/src/synth/sounds-cache.js +0 -15
- package/src/synth/supports-audio.js +9 -23
- package/src/synth/synth-controller.js +80 -49
- package/src/synth/synth-sequence.js +20 -34
- package/src/tablatures/instruments/guitar/guitar-fonts.js +19 -0
- package/src/tablatures/instruments/guitar/guitar-patterns.js +23 -0
- package/src/tablatures/instruments/guitar/tab-guitar.js +50 -0
- package/src/tablatures/instruments/string-patterns.js +277 -0
- package/src/tablatures/instruments/string-tablature.js +56 -0
- package/src/tablatures/instruments/tab-note.js +282 -0
- package/src/tablatures/instruments/tab-notes.js +41 -0
- package/src/tablatures/instruments/violin/tab-violin.js +47 -0
- package/src/tablatures/instruments/violin/violin-fonts.js +19 -0
- package/src/tablatures/instruments/violin/violin-patterns.js +23 -0
- package/src/tablatures/tab-absolute-elements.js +310 -0
- package/src/tablatures/tab-common.js +29 -0
- package/src/tablatures/tab-renderer.js +243 -0
- package/src/tablatures/transposer.js +110 -0
- package/src/test/abc_midi_lint.js +5 -22
- package/src/test/abc_midi_sequencer_lint.js +11 -14
- package/src/test/abc_parser_lint.js +136 -32
- package/src/test/abc_vertical_lint.js +94 -32
- package/src/test/rendering-lint.js +38 -5
- package/src/write/abc_absolute_element.js +112 -120
- package/src/write/abc_abstract_engraver.js +102 -253
- package/src/write/abc_beam_element.js +30 -290
- package/src/write/abc_brace_element.js +12 -121
- package/src/write/abc_create_clef.js +21 -32
- package/src/write/abc_create_key_signature.js +8 -26
- package/src/write/abc_create_note_head.js +107 -0
- package/src/write/abc_create_time_signature.js +2 -21
- package/src/write/abc_crescendo_element.js +3 -50
- package/src/write/abc_decoration.js +7 -30
- package/src/write/abc_dynamic_decoration.js +3 -37
- package/src/write/abc_ending_element.js +1 -57
- package/src/write/abc_engraver_controller.js +111 -234
- package/src/write/abc_glyphs.js +9 -19
- package/src/write/abc_relative_element.js +57 -97
- package/src/write/abc_renderer.js +10 -832
- package/src/write/abc_spacing.js +0 -15
- package/src/write/abc_staff_group_element.js +14 -349
- package/src/write/abc_tempo_element.js +9 -117
- package/src/write/abc_tie_element.js +5 -68
- package/src/write/abc_triplet_element.js +6 -124
- package/src/write/abc_voice_element.js +7 -222
- package/src/write/add-chord.js +103 -0
- package/src/write/add-text-if.js +33 -0
- package/src/write/bottom-text.js +79 -0
- package/src/write/calcHeight.js +17 -0
- package/src/write/classes.js +100 -0
- package/src/write/draw/absolute.js +68 -0
- package/src/write/draw/beam.js +56 -0
- package/src/write/draw/brace.js +106 -0
- package/src/write/draw/crescendo.js +38 -0
- package/src/write/draw/debug-box.js +8 -0
- package/src/write/draw/draw.js +56 -0
- package/src/write/draw/dynamics.js +20 -0
- package/src/write/draw/ending.js +46 -0
- package/src/write/draw/group-elements.js +66 -0
- package/src/write/draw/horizontal-line.js +25 -0
- package/src/write/draw/non-music.js +50 -0
- package/src/write/draw/print-line.js +24 -0
- package/src/write/draw/print-path.js +7 -0
- package/src/write/draw/print-stem.js +30 -0
- package/src/write/draw/print-symbol.js +59 -0
- package/src/write/draw/print-vertical-line.js +18 -0
- package/src/write/draw/relative.js +77 -0
- package/src/write/draw/round-number.js +5 -0
- package/src/write/draw/selectables.js +59 -0
- package/src/write/draw/separator.js +16 -0
- package/src/write/draw/set-paper-size.js +45 -0
- package/src/write/{sprintf.js → draw/sprintf.js} +0 -0
- package/src/write/draw/staff-group.js +226 -0
- package/src/write/draw/staff-line.js +9 -0
- package/src/write/draw/staff.js +33 -0
- package/src/write/draw/tab-line.js +40 -0
- package/src/write/draw/tempo.js +45 -0
- package/src/write/draw/text.js +71 -0
- package/src/write/draw/tie.js +97 -0
- package/src/write/draw/triplet.js +46 -0
- package/src/write/draw/voice.js +102 -0
- package/src/write/format-jazz-chord.js +15 -0
- package/src/write/free-text.js +41 -0
- package/src/write/get-font-and-attr.js +37 -0
- package/src/write/get-text-size.js +56 -0
- package/src/write/highlight.js +11 -0
- package/src/write/layout/VoiceElements.js +121 -0
- package/src/write/layout/beam.js +213 -0
- package/src/write/layout/get-left-edge-of-staff.js +56 -0
- package/src/write/layout/getBarYAt.js +6 -0
- package/src/write/layout/layout.js +94 -0
- package/src/write/layout/setUpperAndLowerElements.js +232 -0
- package/src/write/layout/staffGroup.js +146 -0
- package/src/write/layout/triplet.js +75 -0
- package/src/write/layout/voice.js +137 -0
- package/src/write/selection.js +188 -70
- package/src/write/separator.js +10 -0
- package/src/write/set-class.js +21 -0
- package/src/write/subtitle.js +12 -0
- package/src/write/svg.js +95 -43
- package/src/write/top-text.js +54 -0
- package/src/write/unhighlight.js +11 -0
- package/temp.txt +17 -0
- package/test.js +27 -64
- package/types/index.d.ts +1095 -0
- package/version.js +1 -1
- package/.babelrc +0 -5
- package/.eslintrc +0 -3
- package/.gitmodules +0 -3
- package/abcjs-midi.css +0 -166
- package/build-utils/loadPresets.js +0 -14
- package/build-utils/presets/webpack.analyze.js +0 -6
- package/build-utils/presets/webpack.optimize.js +0 -30
- package/build-utils/webpack.development.js +0 -14
- package/build-utils/webpack.production.js +0 -35
- package/deploy-docs.sh +0 -25
- package/docs/README.md +0 -33
- package/fix-versions.sh +0 -23
- package/mei.js +0 -43
- package/midi.js +0 -62
- package/src/api/abc_tunebook_midi.js +0 -116
- package/src/midi/abc_midi_controls.js +0 -701
- package/src/midi/abc_midi_flattener.js +0 -1119
- package/src/midi/abc_midi_js_preparer.js +0 -243
- package/src/midi/abc_midi_sequencer.js +0 -401
- package/src/midi/abc_midi_ui_generator.js +0 -86
- package/src/plugin/abc_plugin_midi.js +0 -220
- package/src/synth/images/loop.svg +0 -61
- package/src/synth/images/pause.svg +0 -6
- package/src/synth/images/play.svg +0 -5
- package/src/transform/abc2abc_write.js +0 -395
- package/static-wrappers/basic.js +0 -2
- package/static-wrappers/midi.js +0 -2
- package/static-wrappers/plugin-midi.js +0 -6
- package/static-wrappers/plugin.js +0 -6
- package/webpack.config.js +0 -29
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
function delineTune(inputLines, options) {
|
|
2
|
+
if (!options) options = {};
|
|
3
|
+
var lineBreaks = !!options.lineBreaks;
|
|
4
|
+
var outputLines = [];
|
|
5
|
+
var inMusicLine = false;
|
|
6
|
+
var currentMeter = [];
|
|
7
|
+
var currentKey = [];
|
|
8
|
+
var currentClef = [];
|
|
9
|
+
var currentVocalFont = [];
|
|
10
|
+
var currentGChordFont = [];
|
|
11
|
+
var currentTripletFont = [];
|
|
12
|
+
var currentAnnotationFont = [];
|
|
13
|
+
for (var i = 0; i < inputLines.length; i++) {
|
|
14
|
+
var inputLine = inputLines[i];
|
|
15
|
+
if (inputLine.staff) {
|
|
16
|
+
if (inMusicLine && !inputLine.vskip) {
|
|
17
|
+
var outputLine = outputLines[outputLines.length-1];
|
|
18
|
+
//findMismatchKeys(inputLine, outputLine, ["staff", "staffGroup"], "line", i)
|
|
19
|
+
for (var s = 0; s < outputLine.staff.length; s++) {
|
|
20
|
+
var inputStaff = inputLine.staff[s];
|
|
21
|
+
var outputStaff = outputLine.staff[s];
|
|
22
|
+
if (inputStaff) {
|
|
23
|
+
if (!objEqual(inputStaff.meter, currentMeter[s])) {
|
|
24
|
+
// The meter changed for this line, otherwise it wouldn't have been set
|
|
25
|
+
addMeterToVoices(inputStaff.meter, inputStaff.voices)
|
|
26
|
+
currentMeter[s] = inputStaff.meter;
|
|
27
|
+
delete inputStaff.meter;
|
|
28
|
+
}
|
|
29
|
+
if (!objEqual(inputStaff.key, currentKey[s])) {
|
|
30
|
+
addKeyToVoices(inputStaff.key, inputStaff.voices);
|
|
31
|
+
currentKey[s] = inputStaff.key;
|
|
32
|
+
delete inputStaff.key;
|
|
33
|
+
}
|
|
34
|
+
if (inputStaff.title)
|
|
35
|
+
outputStaff.abbrevTitle = inputStaff.title;
|
|
36
|
+
if (!objEqual(inputStaff.clef, currentClef[s])) {
|
|
37
|
+
addClefToVoices(inputStaff.clef, inputStaff.voices);
|
|
38
|
+
currentClef[s] = inputStaff.clef;
|
|
39
|
+
delete inputStaff.clef;
|
|
40
|
+
}
|
|
41
|
+
if (!objEqual(inputStaff.vocalfont, currentVocalFont[s])) {
|
|
42
|
+
addFontToVoices(inputStaff.vocalfont, inputStaff.voices, 'vocalfont')
|
|
43
|
+
currentVocalFont[s] = inputStaff.vocalfont;
|
|
44
|
+
delete inputStaff.vocalfont;
|
|
45
|
+
}
|
|
46
|
+
if (!objEqual(inputStaff.gchordfont, currentGChordFont[s])) {
|
|
47
|
+
addFontToVoices(inputStaff.gchordfont, inputStaff.voices, 'gchordfont')
|
|
48
|
+
currentGChordFont[s] = inputStaff.gchordfont;
|
|
49
|
+
delete inputStaff.gchordfont;
|
|
50
|
+
}
|
|
51
|
+
if (!objEqual(inputStaff.tripletfont, currentTripletFont[s])) {
|
|
52
|
+
addFontToVoices(inputStaff.tripletfont, inputStaff.voices, 'tripletfont')
|
|
53
|
+
currentTripletFont[s] = inputStaff.tripletfont;
|
|
54
|
+
delete inputStaff.tripletfont;
|
|
55
|
+
}
|
|
56
|
+
if (!objEqual(inputStaff.annotationfont, currentAnnotationFont[s])) {
|
|
57
|
+
addFontToVoices(inputStaff.annotationfont, inputStaff.voices, 'annotationfont')
|
|
58
|
+
currentAnnotationFont[s] = inputStaff.annotationfont;
|
|
59
|
+
delete inputStaff.annotationfont;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//findMismatchKeys(inputStaff, outputStaff, ["voices", "title", "abbrevTitle", "barNumber", "meter", "key", "clef", "vocalfont", "gchordfont", "tripletfont", "annotationfont"], "staff", i + ' ' + s)
|
|
63
|
+
if (inputStaff) {
|
|
64
|
+
for (var v = 0; v < outputStaff.voices.length; v++) {
|
|
65
|
+
var outputVoice = outputStaff.voices[v];
|
|
66
|
+
var inputVoice = inputStaff.voices[v];
|
|
67
|
+
if (lineBreaks)
|
|
68
|
+
outputVoice.push({el_type: "break"});
|
|
69
|
+
if (inputVoice)
|
|
70
|
+
outputStaff.voices[v] = outputVoice.concat(inputVoice)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
for (var ii = 0; ii < inputLine.staff.length; ii++) {
|
|
76
|
+
currentKey[ii] = inputLine.staff[ii].key;
|
|
77
|
+
currentMeter[ii] = inputLine.staff[ii].meter;
|
|
78
|
+
currentClef[ii] = inputLine.staff[ii].clef;
|
|
79
|
+
}
|
|
80
|
+
// copy this because we are going to change it and we don't want to change the original.
|
|
81
|
+
outputLines.push(cloneLine(inputLine));
|
|
82
|
+
}
|
|
83
|
+
inMusicLine = true;
|
|
84
|
+
} else {
|
|
85
|
+
inMusicLine = false;
|
|
86
|
+
outputLines.push(inputLine);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return outputLines;
|
|
90
|
+
}
|
|
91
|
+
// function findMismatchKeys(input, output, ignore, context, context2) {
|
|
92
|
+
// if (!input) {
|
|
93
|
+
// return;
|
|
94
|
+
// }
|
|
95
|
+
// var outputKeys = Object.keys(output);
|
|
96
|
+
// var inputKeys = Object.keys(input);
|
|
97
|
+
// for (var ii = 0; ii < ignore.length; ii++) {
|
|
98
|
+
// if (outputKeys.indexOf(ignore[ii]) >= 0) {
|
|
99
|
+
// outputKeys.splice(outputKeys.indexOf(ignore[ii]), 1);
|
|
100
|
+
// }
|
|
101
|
+
// if (inputKeys.indexOf(ignore[ii]) >= 0) {
|
|
102
|
+
// inputKeys.splice(inputKeys.indexOf(ignore[ii]), 1);
|
|
103
|
+
// }
|
|
104
|
+
// }
|
|
105
|
+
// if (inputKeys.join(",") !== outputKeys.join(",")) {
|
|
106
|
+
// console.log("keys mismatch "+context + ' ' + context2, input, output);
|
|
107
|
+
// }
|
|
108
|
+
// for (var k = 0; k < inputKeys.length; k++) {
|
|
109
|
+
// var key = inputKeys[k];
|
|
110
|
+
// if (ignore.indexOf(key) < 0) {
|
|
111
|
+
// var inputValue = JSON.stringify(input[key], replacer);
|
|
112
|
+
// var outputValue = JSON.stringify(output[key], replacer);
|
|
113
|
+
// if (inputValue !== outputValue)
|
|
114
|
+
// console.log("value mismatch "+context + ' ' + context2 + ' ' + key, inputValue, outputValue)
|
|
115
|
+
// }
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
118
|
+
function replacer(key, value) {
|
|
119
|
+
// Filtering out properties
|
|
120
|
+
if (key === 'abselem') {
|
|
121
|
+
return 'abselem';
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function addMeterToVoices(meter, voices) {
|
|
127
|
+
meter.el_type = "meter";
|
|
128
|
+
meter.startChar = -1;
|
|
129
|
+
meter.endChar = -1;
|
|
130
|
+
for (var i = 0; i < voices.length; i++) {
|
|
131
|
+
voices[i].unshift(meter);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function addKeyToVoices(key, voices) {
|
|
136
|
+
key.el_type = "key";
|
|
137
|
+
key.startChar = -1;
|
|
138
|
+
key.endChar = -1;
|
|
139
|
+
for (var i = 0; i < voices.length; i++) {
|
|
140
|
+
voices[i].unshift(key);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function addClefToVoices(clef, voices) {
|
|
145
|
+
clef.el_type = "clef";
|
|
146
|
+
clef.startChar = -1;
|
|
147
|
+
clef.endChar = -1;
|
|
148
|
+
for (var i = 0; i < voices.length; i++) {
|
|
149
|
+
voices[i].unshift(clef);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function addFontToVoices(font, voices, type) {
|
|
154
|
+
font.el_type = "font";
|
|
155
|
+
font.type = type;
|
|
156
|
+
font.startChar = -1;
|
|
157
|
+
font.endChar = -1;
|
|
158
|
+
for (var i = 0; i < voices.length; i++) {
|
|
159
|
+
voices[i].unshift(font);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function objEqual(input, output) {
|
|
164
|
+
if (!input)
|
|
165
|
+
return true; // the default is whatever the old output is.
|
|
166
|
+
var inputValue = JSON.stringify(input, replacer);
|
|
167
|
+
var outputValue = JSON.stringify(output, replacer);
|
|
168
|
+
return inputValue === outputValue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function cloneLine(line) {
|
|
172
|
+
var output = {};
|
|
173
|
+
var keys = Object.keys(line);
|
|
174
|
+
for (var i = 0; i < keys.length; i++) {
|
|
175
|
+
if (keys[i] !== "staff")
|
|
176
|
+
output[keys[i]] = line[keys[i]];
|
|
177
|
+
else {
|
|
178
|
+
output.staff = [];
|
|
179
|
+
for (var j = 0; j < line.staff.length; j++) {
|
|
180
|
+
var staff = {};
|
|
181
|
+
var keys2 = Object.keys(line.staff[j]);
|
|
182
|
+
for (var k = 0; k < keys2.length; k++) {
|
|
183
|
+
if (keys2[k] !== "voices")
|
|
184
|
+
staff[keys2[k]] = line.staff[j][keys2[k]];
|
|
185
|
+
else {
|
|
186
|
+
staff.voices = [];
|
|
187
|
+
for (var v = 0; v < line.staff[j].voices.length; v++) {
|
|
188
|
+
staff.voices.push([].concat(line.staff[j].voices[v]));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
output.staff.push(staff)
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return output;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
module.exports = delineTune;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// abc_editor.js
|
|
2
|
+
|
|
3
|
+
// window.ABCJS.Editor is the interface class for the area that contains the ABC text. It is responsible for
|
|
4
|
+
// holding the text of the tune and calling the parser and the rendering engines.
|
|
5
|
+
//
|
|
6
|
+
// EditArea is an example of using a textarea as the control that is shown to the user. As long as
|
|
7
|
+
// the same interface is used, window.ABCJS.Editor can use a different type of object.
|
|
8
|
+
//
|
|
9
|
+
// EditArea:
|
|
10
|
+
// - constructor(textareaid)
|
|
11
|
+
// This contains the id of a textarea control that will be used.
|
|
12
|
+
// - addSelectionListener(listener)
|
|
13
|
+
// A callback class that contains the entry point fireSelectionChanged()
|
|
14
|
+
// - addChangeListener(listener)
|
|
15
|
+
// A callback class that contains the entry point fireChanged()
|
|
16
|
+
// - getSelection()
|
|
17
|
+
// returns the object { start: , end: } with the current selection in characters
|
|
18
|
+
// - setSelection(start, end)
|
|
19
|
+
// start and end are the character positions that should be selected.
|
|
20
|
+
// - getString()
|
|
21
|
+
// returns the ABC text that is currently displayed.
|
|
22
|
+
// - setString(str)
|
|
23
|
+
// sets the ABC text that is currently displayed, and resets the initialText variable
|
|
24
|
+
// - getElem()
|
|
25
|
+
// returns the textarea element
|
|
26
|
+
// - string initialText
|
|
27
|
+
// Contains the starting text. This can be compared against the current text to see if anything changed.
|
|
28
|
+
//
|
|
29
|
+
|
|
30
|
+
// Polyfill for CustomEvent for old IE versions
|
|
31
|
+
try {
|
|
32
|
+
if (typeof window.CustomEvent !== "function") {
|
|
33
|
+
var CustomEvent = function (event, params) {
|
|
34
|
+
params = params || {bubbles: false, cancelable: false, detail: undefined};
|
|
35
|
+
var evt = document.createEvent('CustomEvent');
|
|
36
|
+
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
|
|
37
|
+
return evt;
|
|
38
|
+
};
|
|
39
|
+
CustomEvent.prototype = window.Event.prototype;
|
|
40
|
+
window.CustomEvent = CustomEvent;
|
|
41
|
+
}
|
|
42
|
+
} catch (e) {
|
|
43
|
+
// if we aren't in a browser, this code will crash, but it is not needed then either.
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var EditArea = function(textareaid) {
|
|
47
|
+
this.textarea = document.getElementById(textareaid);
|
|
48
|
+
this.initialText = this.textarea.value;
|
|
49
|
+
this.isDragging = false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
EditArea.prototype.addSelectionListener = function(listener) {
|
|
53
|
+
this.textarea.onmousemove = function(ev) {
|
|
54
|
+
if (this.isDragging)
|
|
55
|
+
listener.fireSelectionChanged();
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
EditArea.prototype.addChangeListener = function(listener) {
|
|
60
|
+
this.changelistener = listener;
|
|
61
|
+
this.textarea.onkeyup = function() {
|
|
62
|
+
listener.fireChanged();
|
|
63
|
+
};
|
|
64
|
+
this.textarea.onmousedown = function() {
|
|
65
|
+
this.isDragging = true;
|
|
66
|
+
listener.fireSelectionChanged();
|
|
67
|
+
};
|
|
68
|
+
this.textarea.onmouseup = function() {
|
|
69
|
+
this.isDragging = false;
|
|
70
|
+
listener.fireChanged();
|
|
71
|
+
};
|
|
72
|
+
this.textarea.onchange = function() {
|
|
73
|
+
listener.fireChanged();
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
//TODO won't work under IE?
|
|
78
|
+
EditArea.prototype.getSelection = function() {
|
|
79
|
+
return {start: this.textarea.selectionStart, end: this.textarea.selectionEnd};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
EditArea.prototype.setSelection = function(start, end) {
|
|
83
|
+
if(this.textarea.setSelectionRange)
|
|
84
|
+
this.textarea.setSelectionRange(start, end);
|
|
85
|
+
else if(this.textarea.createTextRange) {
|
|
86
|
+
// For IE8
|
|
87
|
+
var e = this.textarea.createTextRange();
|
|
88
|
+
e.collapse(true);
|
|
89
|
+
e.moveEnd('character', end);
|
|
90
|
+
e.moveStart('character', start);
|
|
91
|
+
e.select();
|
|
92
|
+
}
|
|
93
|
+
this.textarea.focus();
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
EditArea.prototype.getString = function() {
|
|
97
|
+
return this.textarea.value;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
EditArea.prototype.setString = function(str) {
|
|
101
|
+
this.textarea.value = str;
|
|
102
|
+
this.initialText = this.getString();
|
|
103
|
+
if (this.changelistener) {
|
|
104
|
+
this.changelistener.fireChanged();
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
EditArea.prototype.getElem = function() {
|
|
109
|
+
return this.textarea;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
module.exports = EditArea;
|