Commit 5f407404 authored by S Anand's avatar S Anand
Browse files

Create scaffolding

parent 498381d5
Pipeline #57576 failed with stage
in 1 minute and 15 seconds
import { speechplayer } from './src/speechplayer.js'
if (typeof jQuery != 'undefined') {
jQuery.extend(jQuery.fn, {
speechplayer: speechplayer
})
}
......@@ -6,6 +6,7 @@ export { datafilter } from './index-datafilter.js'
export { sanddance } from './src/sanddance.js'
import './index-highlight.js'
import './index-template.js'
import './index-speechplayer.js'
import './index-formhandler.js'
import './index-dropdown.js'
import './index-event.js'
......
......@@ -53,6 +53,11 @@ export default [
plugins: [uglify()],
output: { file: "dist/template.min.js", format: "umd", name: "g1" }
},
{
input: "index-speechplayer",
plugins: [uglify()],
output: { file: "dist/speechplayer.min.js", format: "umd", name: "g1" }
},
{
input: "index-event",
plugins: [uglify()],
......@@ -65,11 +70,12 @@ export default [
},
{
input: "index-mapviewer",
plugins: [resolve(),
commonjs(),
babel(babelrc({ config: babelConfig, exclude: 'node_modules/**' })),
process.env.npm_lifecycle_event == 'dev'? '': uglify()
],
plugins: [
resolve(),
commonjs(),
babel(babelrc({ config: babelConfig, exclude: 'node_modules/**' })),
process.env.npm_lifecycle_event == 'dev'? '': uglify()
],
output: {
file: "dist/mapviewer.min.js", format: "umd", name: "g1", globals: {
leaflet: 'L',
......@@ -91,13 +97,15 @@ export default [
},
{
input: "index-dropdown",
plugins: [resolve(),
commonjs(),
htmlparts('src/dropdown.template.html')],
plugins: [
resolve(),
commonjs(),
htmlparts('src/dropdown.template.html')
],
output: {
file: "dist/dropdown.min.js",
format: "umd",
name: "g1"
}
file: "dist/dropdown.min.js",
format: "umd",
name: "g1"
}
}
]
export function speechplayer(options) {
options = options || {}
var synth = window.speechSynthesis
if (!synth)
throw new Error('SpeechSynthesis not supported on this browser')
// playlist is a list of {text: ..., node: ...}. node: is optional
var playlist = []
var speech = {}
speech.text = function(text) {
playlist.splice(0, playlist.length)
// Add text as an array
if (Array.isArray(text))
text.forEach(function(item) {
playlist.push({text: item})
})
else
playlist.push({text: text})
return speech
}
speech.node = function(selector) {
playlist.splice(0, playlist.length)
var nodes = Array.prototype.slice.call(document.querySelectorAll(selector))
nodes.forEach(function(node) {
playlist.push({text: node.textContent, node: node})
})
return speech
}
speech.playlist = playlist
speech.play = function() {
// TODO
}
return speech
}
<!DOCTYPE html>
<html>
<head>
<title>speechplayer tests</title>
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../dist/speechplayer.min.js"></script>
<script src="tape.js"></script>
</head>
<body>
<script>
tape.onFinish(function () { window.renderComplete = true })
</script>
<div class="player">
<div class="play">&#x25B6;</div>
</div>
<div class="test-node">
This is a single sentence that will be played.
</div>
<script>
var speech = $('.player').speechplayer()
tape('speech stores text as a single array element', function (t) {
var text = 'Set the text to be played explicitly.'
speech.text(text)
t.equal(speech.playlist.length, 1)
t.equal(speech.playlist[0].text, text)
t.end()
})
tape('speech stores text as multiple array element', function (t) {
speech.text(['One', 'Two', 'Three'])
t.equal(speech.playlist.length, 3)
t.equal(speech.playlist[0].text, 'One')
t.equal(speech.playlist[1].text, 'Two')
t.equal(speech.playlist[2].text, 'Three')
t.end()
})
tape('speech stores single node content ', function (t) {
speech.node('.test-node')
var node = document.querySelector('.test-node')
t.equal(speech.playlist.length, 1)
t.equal(speech.playlist[0].text, node.textContent)
t.equal(speech.playlist[0].node, node)
t.end()
})
</script>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment