Added webapp for afsk control
App sends out commands via the user’s audio port to the Arduino code
This commit is contained in:
parent
451f7d0bd1
commit
ecec37e898
|
@ -0,0 +1 @@
|
|||
html{overflow:hidden}body{background:#282828;font-family:'Helvetica Neue',Tahoma,Geneva,sans-serif;overflow:hidden;padding-top:20px}*{-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.cmd{border:1px solid;color:#282828;margin-bottom:8px;padding:10px;text-align:center;font-size:18px;font-weight:200;letter-spacing:1px;cursor:pointer;border-radius:5px}.cmd:active{background:#282828 !important;letter-spacing:8px}.cmd.forward{background:#3bb29d}.cmd.forward:active{border-color:#3bb29d;color:#3bb29d}.cmd.backward{background:#df4949}.cmd.backward:active{border-color:#df4949;color:#df4949}.cmd.delay{background:#d2d2d2}.cmd.delay:active{border-color:#d2d2d2;color:#d2d2d2}.cmd.run{background:#efc94c}.cmd.run:active{border-color:#efc94c;color:#efc94c}.cmd.loop{background:#30505c}.cmd.loop:active{border-color:#30505c;color:#30505c}.cmd.loop.on{background:#e27a3f}.cmd.loop.on:active{border-color:#e27a3f;color:#e27a3f}.cmd.seq{border:0;padding:0;height:135px}.cmd.seq div{display:block;height:44px;float:none}.cmd.seq .for,.cmd.seq .back,.cmd.seq .pause{border:1px solid #000;border-radius:5px;height:37px;width:35px;text-align:right;letter-spacing:normal !important;line-height:59px;font-size:12px !important;padding-left:1px;padding-right:1px;margin-right:5px;color:#282828;float:left}.cmd.seq .for.highlight,.cmd.seq .back.highlight,.cmd.seq .pause.highlight{border:1px solid #efc94c;background:#453d00;color:#453d00}.cmd.seq .for.highlight.set,.cmd.seq .back.highlight.set,.cmd.seq .pause.highlight.set{background:#efc94c;color:#282828}.cmd.seq .for{border-color:#3bb29d}.cmd.seq .for.set{background:#3bb29d}.cmd.seq .back{border-color:#df4949}.cmd.seq .back.set{background:#df4949}.cmd.seq .pause{border-color:#d2d2d2}.cmd.seq .pause.set{background:#d2d2d2}#monitor{position:fixed;bottom:8px;text-align:center;left:0;right:0;color:white;font-family:monospace;font-size:24px}
|
|
@ -0,0 +1,177 @@
|
|||
@bg: rgb(40, 40, 40);
|
||||
|
||||
html{
|
||||
overflow: hidden;
|
||||
}
|
||||
body{
|
||||
background: @bg;
|
||||
font-family: 'Helvetica Neue', Tahoma, Geneva, sans-serif;
|
||||
overflow: hidden;
|
||||
padding-top: 20px;
|
||||
}
|
||||
*{
|
||||
-webkit-touch-callout: none;
|
||||
-webkit-user-select: none;
|
||||
-khtml-user-select: none;
|
||||
-moz-user-select: none;
|
||||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/*
|
||||
@forward: #6EE862;
|
||||
@backward: #E87562;
|
||||
@delay: rgb(210, 210, 210);
|
||||
@run: #FFE11F;
|
||||
@loop: #F41FFF;
|
||||
@pause: rgb(210, 210, 210);
|
||||
*/
|
||||
@pause: rgb(210, 210, 210);
|
||||
|
||||
@dark_highlight: rgb(170, 140, 150);
|
||||
@dark: @bg + @bg;
|
||||
@br: 5px;
|
||||
|
||||
|
||||
/*
|
||||
KULER - Max
|
||||
*/
|
||||
@forward: rgb(59, 178, 157);
|
||||
@backward: rgb(223, 73, 73);
|
||||
@delay: @pause;
|
||||
@run: rgb(239, 201, 76);
|
||||
@loop: rgb(48, 80, 92);
|
||||
@loop_on: rgb(226, 122, 63);
|
||||
|
||||
.cmd{
|
||||
border: 1px solid;
|
||||
color: @bg;
|
||||
margin-bottom: 8px;
|
||||
padding: 10px;
|
||||
text-align: center;
|
||||
font-size: 18px;
|
||||
font-weight: 200;
|
||||
letter-spacing: 1px;
|
||||
cursor: pointer;
|
||||
border-radius: @br;
|
||||
&:active{
|
||||
background: @bg !important;
|
||||
letter-spacing: 8px;
|
||||
}
|
||||
&.forward{
|
||||
background: @forward;
|
||||
&:active{
|
||||
border-color: @forward;
|
||||
color: @forward;
|
||||
}
|
||||
}
|
||||
&.backward{
|
||||
background: @backward;
|
||||
&:active{
|
||||
border-color: @backward;
|
||||
color: @backward;
|
||||
}
|
||||
}
|
||||
&.delay{
|
||||
background: @delay;
|
||||
&:active{
|
||||
border-color: @delay;
|
||||
color: @delay;
|
||||
}
|
||||
}
|
||||
&.run{
|
||||
background: @run;
|
||||
&:active{
|
||||
border-color: @run;
|
||||
color: @run;
|
||||
}
|
||||
}
|
||||
&.loop{
|
||||
background: @loop;
|
||||
&:active{
|
||||
border-color: @loop;
|
||||
color: @loop;
|
||||
}
|
||||
&.on{
|
||||
background: @loop_on;
|
||||
&:active{
|
||||
border-color: @loop_on;
|
||||
color: @loop_on;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.seq{
|
||||
border: 0;
|
||||
padding: 0;
|
||||
height: 135px;
|
||||
div{
|
||||
display: block;
|
||||
height: 44px;
|
||||
float: none;
|
||||
}
|
||||
.for,
|
||||
.back,
|
||||
.pause{
|
||||
border: 1px solid #000;
|
||||
border-radius: @br;
|
||||
height: 37px;
|
||||
width: 35px;
|
||||
text-align: right;
|
||||
letter-spacing: normal !important;
|
||||
line-height: 59px;
|
||||
font-size: 12px !important;
|
||||
padding-left: 1px;
|
||||
padding-right: 1px;
|
||||
margin-right: 5px;
|
||||
color: @bg;
|
||||
float: left;
|
||||
|
||||
&.highlight{
|
||||
border: 1px solid @run;
|
||||
background: @run - @dark_highlight;
|
||||
color: @run - @dark_highlight;
|
||||
&.set{
|
||||
background: @run;
|
||||
color: @bg;
|
||||
}
|
||||
}
|
||||
}
|
||||
.for{
|
||||
border-color: @forward;
|
||||
//&:active,
|
||||
//&:hover,
|
||||
&.set{
|
||||
background: @forward;
|
||||
}
|
||||
}
|
||||
.back{
|
||||
border-color: @backward;
|
||||
//&:active,
|
||||
//&:hover,
|
||||
&.set{
|
||||
background: @backward;
|
||||
}
|
||||
}
|
||||
.pause{
|
||||
border-color: @pause;
|
||||
//&:active,
|
||||
//&:hover,
|
||||
&.set{
|
||||
background: @pause;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#monitor{
|
||||
position: fixed;
|
||||
bottom: 8px;
|
||||
text-align: center;
|
||||
left: 0;
|
||||
right: 0;
|
||||
color: white;
|
||||
font-family: monospace;
|
||||
font-size: 24px;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
|
||||
<link rel="apple-touch-icon" href="ios-icon.png" />
|
||||
<meta name="apple-mobile-web-app-title" content="intval" />
|
||||
<meta name="format-detection" content="telephone=no" />
|
||||
<title>INTVAL ctrl</title>
|
||||
<link href="css/intval.css" rel="stylesheet" />
|
||||
<script type="text/javascript" src="js/base64-binary.js"></script>
|
||||
<script type="text/javascript" src="js/fsk.js"></script>
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
|
||||
<script type="text/javascript" src="js/fastclick.js"></script>
|
||||
<script type="text/javascript" src="js/intval.js"></script>
|
||||
</head>
|
||||
<body onload="ctrl.onload();">
|
||||
<div class="cmd forward" title="f" onclick="ctrl.sendCmd(this);">+1</div>
|
||||
<div class="cmd backward" title="b" onclick="ctrl.sendCmd(this);">-1</div>
|
||||
<div class="cmd seq" title="Sequence" id="seq" style="width: 10000px;">
|
||||
<div class="row_f">
|
||||
<div class="for" title="f" onclick="ctrl.set(this);">0</div>
|
||||
</div>
|
||||
<div class="row_B">
|
||||
<div class="back" title="b" onclick="ctrl.set(this);">0</div>
|
||||
</div>
|
||||
<div class="row_x">
|
||||
<div class="pause" title="x" onclick="ctrl.set(this);">0</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cmd delay" onclick="ctrl.changeDelay();">DELAY <span id="delayVal">1</span><span> sec</span></div>
|
||||
<div class="cmd loop off" title="Loop" onclick="ctrl.setLoop();">LOOP off</div>
|
||||
<div class="cmd run" title="Run" onclick="ctrl.run.start();">RUN</div>
|
||||
<div id="monitor" onclick="ctrl.setPos();">0</div>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
After Width: | Height: | Size: 643 B |
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
Copyright (c) 2011, Daniel Guerrero
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL DANIEL GUERRERO BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Uses the new array typed in javascript to binary base64 encode/decode
|
||||
* at the moment just decodes a binary base64 encoded
|
||||
* into either an ArrayBuffer (decodeArrayBuffer)
|
||||
* or into an Uint8Array (decode)
|
||||
*
|
||||
* References:
|
||||
* https://developer.mozilla.org/en/JavaScript_typed_arrays/ArrayBuffer
|
||||
* https://developer.mozilla.org/en/JavaScript_typed_arrays/Uint8Array
|
||||
*/
|
||||
|
||||
var Base64Binary = {
|
||||
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
||||
|
||||
/* will return a Uint8Array type */
|
||||
decodeArrayBuffer: function(input) {
|
||||
var bytes = (input.length/4) * 3;
|
||||
var ab = new ArrayBuffer(bytes);
|
||||
this.decode(input, ab);
|
||||
|
||||
return ab;
|
||||
},
|
||||
|
||||
decode: function(input, arrayBuffer) {
|
||||
//get last chars to see if are valid
|
||||
var lkey1 = this._keyStr.indexOf(input.charAt(input.length-1));
|
||||
var lkey2 = this._keyStr.indexOf(input.charAt(input.length-2));
|
||||
|
||||
var bytes = (input.length/4) * 3;
|
||||
if (lkey1 == 64) bytes--; //padding chars, so skip
|
||||
if (lkey2 == 64) bytes--; //padding chars, so skip
|
||||
|
||||
var uarray;
|
||||
var chr1, chr2, chr3;
|
||||
var enc1, enc2, enc3, enc4;
|
||||
var i = 0;
|
||||
var j = 0;
|
||||
|
||||
if (arrayBuffer)
|
||||
uarray = new Uint8Array(arrayBuffer);
|
||||
else
|
||||
uarray = new Uint8Array(bytes);
|
||||
|
||||
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
|
||||
|
||||
for (i=0; i<bytes; i+=3) {
|
||||
//get the 3 octects in 4 ascii chars
|
||||
enc1 = this._keyStr.indexOf(input.charAt(j++));
|
||||
enc2 = this._keyStr.indexOf(input.charAt(j++));
|
||||
enc3 = this._keyStr.indexOf(input.charAt(j++));
|
||||
enc4 = this._keyStr.indexOf(input.charAt(j++));
|
||||
|
||||
chr1 = (enc1 << 2) | (enc2 >> 4);
|
||||
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
||||
chr3 = ((enc3 & 3) << 6) | enc4;
|
||||
|
||||
uarray[i] = chr1;
|
||||
if (enc3 != 64) uarray[i+1] = chr2;
|
||||
if (enc4 != 64) uarray[i+2] = chr3;
|
||||
}
|
||||
|
||||
return uarray;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,828 @@
|
|||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @preserve FastClick: polyfill to remove click delays on browsers with touch UIs.
|
||||
*
|
||||
* @codingstandard ftlabs-jsv2
|
||||
* @copyright The Financial Times Limited [All Rights Reserved]
|
||||
* @license MIT License (see LICENSE.txt)
|
||||
*/
|
||||
|
||||
/*jslint browser:true, node:true*/
|
||||
/*global define, Event, Node*/
|
||||
|
||||
|
||||
/**
|
||||
* Instantiate fast-clicking listeners on the specified layer.
|
||||
*
|
||||
* @constructor
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
function FastClick(layer, options) {
|
||||
var oldOnClick;
|
||||
|
||||
options = options || {};
|
||||
|
||||
/**
|
||||
* Whether a click is currently being tracked.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
this.trackingClick = false;
|
||||
|
||||
|
||||
/**
|
||||
* Timestamp for when click tracking started.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The element being tracked for a click.
|
||||
*
|
||||
* @type EventTarget
|
||||
*/
|
||||
this.targetElement = null;
|
||||
|
||||
|
||||
/**
|
||||
* X-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartX = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Y-coordinate of touch start event.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchStartY = 0;
|
||||
|
||||
|
||||
/**
|
||||
* ID of the last touch, retrieved from Touch.identifier.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.lastTouchIdentifier = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Touchmove boundary, beyond which a click will be cancelled.
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.touchBoundary = options.touchBoundary || 10;
|
||||
|
||||
|
||||
/**
|
||||
* The FastClick layer.
|
||||
*
|
||||
* @type Element
|
||||
*/
|
||||
this.layer = layer;
|
||||
|
||||
/**
|
||||
* The minimum time between tap(touchstart and touchend) events
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapDelay = options.tapDelay || 200;
|
||||
|
||||
/**
|
||||
* The maximum time for a tap
|
||||
*
|
||||
* @type number
|
||||
*/
|
||||
this.tapTimeout = options.tapTimeout || 700;
|
||||
|
||||
if (FastClick.notNeeded(layer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Some old versions of Android don't have Function.prototype.bind
|
||||
function bind(method, context) {
|
||||
return function() { return method.apply(context, arguments); };
|
||||
}
|
||||
|
||||
|
||||
var methods = ['onMouse', 'onClick', 'onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'];
|
||||
var context = this;
|
||||
for (var i = 0, l = methods.length; i < l; i++) {
|
||||
context[methods[i]] = bind(context[methods[i]], context);
|
||||
}
|
||||
|
||||
// Set up event handlers as required
|
||||
if (deviceIsAndroid) {
|
||||
layer.addEventListener('mouseover', this.onMouse, true);
|
||||
layer.addEventListener('mousedown', this.onMouse, true);
|
||||
layer.addEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.addEventListener('click', this.onClick, true);
|
||||
layer.addEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.addEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.addEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.addEventListener('touchcancel', this.onTouchCancel, false);
|
||||
|
||||
// Hack is required for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
// which is how FastClick normally stops click events bubbling to callbacks registered on the FastClick
|
||||
// layer when they are cancelled.
|
||||
if (!Event.prototype.stopImmediatePropagation) {
|
||||
layer.removeEventListener = function(type, callback, capture) {
|
||||
var rmv = Node.prototype.removeEventListener;
|
||||
if (type === 'click') {
|
||||
rmv.call(layer, type, callback.hijacked || callback, capture);
|
||||
} else {
|
||||
rmv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
|
||||
layer.addEventListener = function(type, callback, capture) {
|
||||
var adv = Node.prototype.addEventListener;
|
||||
if (type === 'click') {
|
||||
adv.call(layer, type, callback.hijacked || (callback.hijacked = function(event) {
|
||||
if (!event.propagationStopped) {
|
||||
callback(event);
|
||||
}
|
||||
}), capture);
|
||||
} else {
|
||||
adv.call(layer, type, callback, capture);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// If a handler is already declared in the element's onclick attribute, it will be fired before
|
||||
// FastClick's onClick handler. Fix this by pulling out the user-defined handler function and
|
||||
// adding it as listener.
|
||||
if (typeof layer.onclick === 'function') {
|
||||
|
||||
// Android browser on at least 3.2 requires a new reference to the function in layer.onclick
|
||||
// - the old one won't work if passed to addEventListener directly.
|
||||
oldOnClick = layer.onclick;
|
||||
layer.addEventListener('click', function(event) {
|
||||
oldOnClick(event);
|
||||
}, false);
|
||||
layer.onclick = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Windows Phone 8.1 fakes user agent string to look like Android and iPhone.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsWindowsPhone = navigator.userAgent.indexOf("Windows Phone") >= 0;
|
||||
|
||||
/**
|
||||
* Android requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsAndroid = navigator.userAgent.indexOf('Android') > 0 && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS = /iP(ad|hone|od)/.test(navigator.userAgent) && !deviceIsWindowsPhone;
|
||||
|
||||
|
||||
/**
|
||||
* iOS 4 requires an exception for select elements.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOS4 = deviceIsIOS && (/OS 4_\d(_\d)?/).test(navigator.userAgent);
|
||||
|
||||
|
||||
/**
|
||||
* iOS 6.0(+?) requires the target element to be manually derived
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsIOSWithBadTarget = deviceIsIOS && (/OS ([6-9]|\d{2})_\d/).test(navigator.userAgent);
|
||||
|
||||
/**
|
||||
* BlackBerry requires exceptions.
|
||||
*
|
||||
* @type boolean
|
||||
*/
|
||||
var deviceIsBlackBerry10 = navigator.userAgent.indexOf('BB10') > 0;
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a native click.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element needs a native click
|
||||
*/
|
||||
FastClick.prototype.needsClick = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
|
||||
// Don't send a synthetic click to disabled inputs (issue #62)
|
||||
case 'button':
|
||||
case 'select':
|
||||
case 'textarea':
|
||||
if (target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'input':
|
||||
|
||||
// File inputs need real clicks on iOS 6 due to a browser bug (issue #68)
|
||||
if ((deviceIsIOS && target.type === 'file') || target.disabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'label':
|
||||
case 'iframe': // iOS8 homescreen apps can prevent events bubbling into frames
|
||||
case 'video':
|
||||
return true;
|
||||
}
|
||||
|
||||
return (/\bneedsclick\b/).test(target.className);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether a given element requires a call to focus to simulate click into element.
|
||||
*
|
||||
* @param {EventTarget|Element} target Target DOM element
|
||||
* @returns {boolean} Returns true if the element requires a call to focus to simulate native click.
|
||||
*/
|
||||
FastClick.prototype.needsFocus = function(target) {
|
||||
switch (target.nodeName.toLowerCase()) {
|
||||
case 'textarea':
|
||||
return true;
|
||||
case 'select':
|
||||
return !deviceIsAndroid;
|
||||
case 'input':
|
||||
switch (target.type) {
|
||||
case 'button':
|
||||
case 'checkbox':
|
||||
case 'file':
|
||||
case 'image':
|
||||
case 'radio':
|
||||
case 'submit':
|
||||
return false;
|
||||
}
|
||||
|
||||
// No point in attempting to focus disabled inputs
|
||||
return !target.disabled && !target.readOnly;
|
||||
default:
|
||||
return (/\bneedsfocus\b/).test(target.className);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send a click event to the specified element.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
* @param {Event} event
|
||||
*/
|
||||
FastClick.prototype.sendClick = function(targetElement, event) {
|
||||
var clickEvent, touch;
|
||||
|
||||
// On some Android devices activeElement needs to be blurred otherwise the synthetic click will have no effect (#24)
|
||||
if (document.activeElement && document.activeElement !== targetElement) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// Synthesise a click event, with an extra attribute so it can be tracked
|
||||
clickEvent = document.createEvent('MouseEvents');
|
||||
clickEvent.initMouseEvent(this.determineEventType(targetElement), true, true, window, 1, touch.screenX, touch.screenY, touch.clientX, touch.clientY, false, false, false, false, 0, null);
|
||||
clickEvent.forwardedTouchEvent = true;
|
||||
targetElement.dispatchEvent(clickEvent);
|
||||
};
|
||||
|
||||
FastClick.prototype.determineEventType = function(targetElement) {
|
||||
|
||||
//Issue #159: Android Chrome Select Box does not open with a synthetic click event
|
||||
if (deviceIsAndroid && targetElement.tagName.toLowerCase() === 'select') {
|
||||
return 'mousedown';
|
||||
}
|
||||
|
||||
return 'click';
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.focus = function(targetElement) {
|
||||
var length;
|
||||
|
||||
// Issue #160: on iOS 7, some input elements (e.g. date datetime month) throw a vague TypeError on setSelectionRange. These elements don't have an integer value for the selectionStart and selectionEnd properties, but unfortunately that can't be used for detection because accessing the properties also throws a TypeError. Just check the type instead. Filed as Apple bug #15122724.
|
||||
if (deviceIsIOS && targetElement.setSelectionRange && targetElement.type.indexOf('date') !== 0 && targetElement.type !== 'time' && targetElement.type !== 'month') {
|
||||
length = targetElement.value.length;
|
||||
targetElement.setSelectionRange(length, length);
|
||||
} else {
|
||||
targetElement.focus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether the given target element is a child of a scrollable layer and if so, set a flag on it.
|
||||
*
|
||||
* @param {EventTarget|Element} targetElement
|
||||
*/
|
||||
FastClick.prototype.updateScrollParent = function(targetElement) {
|
||||
var scrollParent, parentElement;
|
||||
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
|
||||
// Attempt to discover whether the target element is contained within a scrollable layer. Re-check if the
|
||||
// target element was moved to another parent.
|
||||
if (!scrollParent || !scrollParent.contains(targetElement)) {
|
||||
parentElement = targetElement;
|
||||
do {
|
||||
if (parentElement.scrollHeight > parentElement.offsetHeight) {
|
||||
scrollParent = parentElement;
|
||||
targetElement.fastClickScrollParent = parentElement;
|
||||
break;
|
||||
}
|
||||
|
||||
parentElement = parentElement.parentElement;
|
||||
} while (parentElement);
|
||||
}
|
||||
|
||||
// Always update the scroll top tracker if possible.
|
||||
if (scrollParent) {
|
||||
scrollParent.fastClickLastScrollTop = scrollParent.scrollTop;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @param {EventTarget} targetElement
|
||||
* @returns {Element|EventTarget}
|
||||
*/
|
||||
FastClick.prototype.getTargetElementFromEventTarget = function(eventTarget) {
|
||||
|
||||
// On some older browsers (notably Safari on iOS 4.1 - see issue #56) the event target may be a text node.
|
||||
if (eventTarget.nodeType === Node.TEXT_NODE) {
|
||||
return eventTarget.parentNode;
|
||||
}
|
||||
|
||||
return eventTarget;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch start, record the position and scroll offset.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchStart = function(event) {
|
||||
var targetElement, touch, selection;
|
||||
|
||||
// Ignore multiple touches, otherwise pinch-to-zoom is prevented if both fingers are on the FastClick element (issue #111).
|
||||
if (event.targetTouches.length > 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
targetElement = this.getTargetElementFromEventTarget(event.target);
|
||||
touch = event.targetTouches[0];
|
||||
|
||||
if (deviceIsIOS) {
|
||||
|
||||
// Only trusted events will deselect text on iOS (issue #49)
|
||||
selection = window.getSelection();
|
||||
if (selection.rangeCount && !selection.isCollapsed) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!deviceIsIOS4) {
|
||||
|
||||
// Weird things happen on iOS when an alert or confirm dialog is opened from a click event callback (issue #23):
|
||||
// when the user next taps anywhere else on the page, new touchstart and touchend events are dispatched
|
||||
// with the same identifier as the touch event that previously triggered the click that triggered the alert.
|
||||
// Sadly, there is an issue on iOS 4 that causes some normal touch events to have the same identifier as an
|
||||
// immediately preceeding touch event (issue #52), so this fix is unavailable on that platform.
|
||||
// Issue 120: touch.identifier is 0 when Chrome dev tools 'Emulate touch events' is set with an iOS device UA string,
|
||||
// which causes all touch events to be ignored. As this block only applies to iOS, and iOS identifiers are always long,
|
||||
// random integers, it's safe to to continue if the identifier is 0 here.
|
||||
if (touch.identifier && touch.identifier === this.lastTouchIdentifier) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
|
||||
this.lastTouchIdentifier = touch.identifier;
|
||||
|
||||
// If the target element is a child of a scrollable layer (using -webkit-overflow-scrolling: touch) and:
|
||||
// 1) the user does a fling scroll on the scrollable layer
|
||||
// 2) the user stops the fling scroll with another tap
|
||||
// then the event.target of the last 'touchend' event will be the element that was under the user's finger
|
||||
// when the fling scroll was started, causing FastClick to send a click event to that layer - unless a check
|
||||
// is made to ensure that a parent layer was not scrolled before sending a synthetic click (issue #42).
|
||||
this.updateScrollParent(targetElement);
|
||||
}
|
||||
}
|
||||
|
||||
this.trackingClick = true;
|
||||
this.trackingClickStart = event.timeStamp;
|
||||
this.targetElement = targetElement;
|
||||
|
||||
this.touchStartX = touch.pageX;
|
||||
this.touchStartY = touch.pageY;
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Based on a touchmove event object, check whether the touch has moved past a boundary since it started.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.touchHasMoved = function(event) {
|
||||
var touch = event.changedTouches[0], boundary = this.touchBoundary;
|
||||
|
||||
if (Math.abs(touch.pageX - this.touchStartX) > boundary || Math.abs(touch.pageY - this.touchStartY) > boundary) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Update the last position.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchMove = function(event) {
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the touch has moved, cancel the click tracking
|
||||
if (this.targetElement !== this.getTargetElementFromEventTarget(event.target) || this.touchHasMoved(event)) {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Attempt to find the labelled control for the given label element.
|
||||
*
|
||||
* @param {EventTarget|HTMLLabelElement} labelElement
|
||||
* @returns {Element|null}
|
||||
*/
|
||||
FastClick.prototype.findControl = function(labelElement) {
|
||||
|
||||
// Fast path for newer browsers supporting the HTML5 control attribute
|
||||
if (labelElement.control !== undefined) {
|
||||
return labelElement.control;
|
||||
}
|
||||
|
||||
// All browsers under test that support touch events also support the HTML5 htmlFor attribute
|
||||
if (labelElement.htmlFor) {
|
||||
return document.getElementById(labelElement.htmlFor);
|
||||
}
|
||||
|
||||
// If no for attribute exists, attempt to retrieve the first labellable descendant element
|
||||
// the list of which is defined here: http://www.w3.org/TR/html5/forms.html#category-label
|
||||
return labelElement.querySelector('button, input:not([type=hidden]), keygen, meter, output, progress, select, textarea');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch end, determine whether to send a click event at once.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onTouchEnd = function(event) {
|
||||
var forElement, trackingClickStart, targetTagName, scrollParent, touch, targetElement = this.targetElement;
|
||||
|
||||
if (!this.trackingClick) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent phantom clicks on fast double-tap (issue #36)
|
||||
if ((event.timeStamp - this.lastClickTime) < this.tapDelay) {
|
||||
this.cancelNextClick = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((event.timeStamp - this.trackingClickStart) > this.tapTimeout) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset to prevent wrong click cancel on input (issue #156).
|
||||
this.cancelNextClick = false;
|
||||
|
||||
this.lastClickTime = event.timeStamp;
|
||||
|
||||
trackingClickStart = this.trackingClickStart;
|
||||
this.trackingClick = false;
|
||||
this.trackingClickStart = 0;
|
||||
|
||||
// On some iOS devices, the targetElement supplied with the event is invalid if the layer
|
||||
// is performing a transition or scroll, and has to be re-detected manually. Note that
|
||||
// for this to function correctly, it must be called *after* the event target is checked!
|
||||
// See issue #57; also filed as rdar://13048589 .
|
||||
if (deviceIsIOSWithBadTarget) {
|
||||
touch = event.changedTouches[0];
|
||||
|
||||
// In certain cases arguments of elementFromPoint can be negative, so prevent setting targetElement to null
|
||||
targetElement = document.elementFromPoint(touch.pageX - window.pageXOffset, touch.pageY - window.pageYOffset) || targetElement;
|
||||
targetElement.fastClickScrollParent = this.targetElement.fastClickScrollParent;
|
||||
}
|
||||
|
||||
targetTagName = targetElement.tagName.toLowerCase();
|
||||
if (targetTagName === 'label') {
|
||||
forElement = this.findControl(targetElement);
|
||||
if (forElement) {
|
||||
this.focus(targetElement);
|
||||
if (deviceIsAndroid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
targetElement = forElement;
|
||||
}
|
||||
} else if (this.needsFocus(targetElement)) {
|
||||
|
||||
// Case 1: If the touch started a while ago (best guess is 100ms based on tests for issue #36) then focus will be triggered anyway. Return early and unset the target element reference so that the subsequent click will be allowed through.
|
||||
// Case 2: Without this exception for input elements tapped when the document is contained in an iframe, then any inputted text won't be visible even though the value attribute is updated as the user types (issue #37).
|
||||
if ((event.timeStamp - trackingClickStart) > 100 || (deviceIsIOS && window.top !== window && targetTagName === 'input')) {
|
||||
this.targetElement = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
this.focus(targetElement);
|
||||
this.sendClick(targetElement, event);
|
||||
|
||||
// Select elements need the event to go through on iOS 4, otherwise the selector menu won't open.
|
||||
// Also this breaks opening selects when VoiceOver is active on iOS6, iOS7 (and possibly others)
|
||||
if (!deviceIsIOS || targetTagName !== 'select') {
|
||||
this.targetElement = null;
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (deviceIsIOS && !deviceIsIOS4) {
|
||||
|
||||
// Don't send a synthetic click event if the target element is contained within a parent layer that was scrolled
|
||||
// and this tap is being used to stop the scrolling (usually initiated by a fling - issue #42).
|
||||
scrollParent = targetElement.fastClickScrollParent;
|
||||
if (scrollParent && scrollParent.fastClickLastScrollTop !== scrollParent.scrollTop) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent the actual click from going though - unless the target node is marked as requiring
|
||||
// real clicks or if it is in the whitelist in which case only non-programmatic clicks are permitted.
|
||||
if (!this.needsClick(targetElement)) {
|
||||
event.preventDefault();
|
||||
this.sendClick(targetElement, event);
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On touch cancel, stop tracking the click.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.onTouchCancel = function() {
|
||||
this.trackingClick = false;
|
||||
this.targetElement = null;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Determine mouse events which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onMouse = function(event) {
|
||||
|
||||
// If a target element was never set (because a touch event was never fired) allow the event
|
||||
if (!this.targetElement) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.forwardedTouchEvent) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Programmatically generated events targeting a specific element should be permitted
|
||||
if (!event.cancelable) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Derive and check the target element to see whether the mouse event needs to be permitted;
|
||||
// unless explicitly enabled, prevent non-touch click events from triggering actions,
|
||||
// to prevent ghost/doubleclicks.
|
||||
if (!this.needsClick(this.targetElement) || this.cancelNextClick) {
|
||||
|
||||
// Prevent any user-added listeners declared on FastClick element from being fired.
|
||||
if (event.stopImmediatePropagation) {
|
||||
event.stopImmediatePropagation();
|
||||
} else {
|
||||
|
||||
// Part of the hack for browsers that don't support Event#stopImmediatePropagation (e.g. Android 2)
|
||||
event.propagationStopped = true;
|
||||
}
|
||||
|
||||
// Cancel the event
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the mouse event is permitted, return true for the action to go through.
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* On actual clicks, determine whether this is a touch-generated click, a click action occurring
|
||||
* naturally after a delay after a touch (which needs to be cancelled to avoid duplication), or
|
||||
* an actual click which should be permitted.
|
||||
*
|
||||
* @param {Event} event
|
||||
* @returns {boolean}
|
||||
*/
|
||||
FastClick.prototype.onClick = function(event) {
|
||||
var permitted;
|
||||
|
||||
// It's possible for another FastClick-like library delivered with third-party code to fire a click event before FastClick does (issue #44). In that case, set the click-tracking flag back to false and return early. This will cause onTouchEnd to return early.
|
||||
if (this.trackingClick) {
|
||||
this.targetElement = null;
|
||||
this.trackingClick = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Very odd behaviour on iOS (issue #18): if a submit element is present inside a form and the user hits enter in the iOS simulator or clicks the Go button on the pop-up OS keyboard the a kind of 'fake' click event will be triggered with the submit-type input element as the target.
|
||||
if (event.target.type === 'submit' && event.detail === 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
permitted = this.onMouse(event);
|
||||
|
||||
// Only unset targetElement if the click is not permitted. This will ensure that the check for !targetElement in onMouse fails and the browser's click doesn't go through.
|
||||
if (!permitted) {
|
||||
this.targetElement = null;
|
||||
}
|
||||
|
||||
// If clicks are permitted, return true for the action to go through.
|
||||
return permitted;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Remove all FastClick's event listeners.
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
FastClick.prototype.destroy = function() {
|
||||
var layer = this.layer;
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
layer.removeEventListener('mouseover', this.onMouse, true);
|
||||
layer.removeEventListener('mousedown', this.onMouse, true);
|
||||
layer.removeEventListener('mouseup', this.onMouse, true);
|
||||
}
|
||||
|
||||
layer.removeEventListener('click', this.onClick, true);
|
||||
layer.removeEventListener('touchstart', this.onTouchStart, false);
|
||||
layer.removeEventListener('touchmove', this.onTouchMove, false);
|
||||
layer.removeEventListener('touchend', this.onTouchEnd, false);
|
||||
layer.removeEventListener('touchcancel', this.onTouchCancel, false);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Check whether FastClick is needed.
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
*/
|
||||
FastClick.notNeeded = function(layer) {
|
||||
var metaViewport;
|
||||
var chromeVersion;
|
||||
var blackberryVersion;
|
||||
|
||||
// Devices that don't support touch don't need FastClick
|
||||
if (typeof window.ontouchstart === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Chrome version - zero for other browsers
|
||||
chromeVersion = +(/Chrome\/([0-9]+)/.exec(navigator.userAgent) || [,0])[1];
|
||||
|
||||
if (chromeVersion) {
|
||||
|
||||
if (deviceIsAndroid) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// Chrome on Android with user-scalable="no" doesn't need FastClick (issue #89)
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// Chrome 32 and above with width=device-width or less don't need FastClick
|
||||
if (chromeVersion > 31 && document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Chrome desktop doesn't need FastClick (issue #15)
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (deviceIsBlackBerry10) {
|
||||
blackberryVersion = navigator.userAgent.match(/Version\/([0-9]*)\.([0-9]*)/);
|
||||
|
||||
// BlackBerry 10.3+ does not require Fastclick library.
|
||||
// https://github.com/ftlabs/fastclick/issues/251
|
||||
if (blackberryVersion[1] >= 10 && blackberryVersion[2] >= 3) {
|
||||
metaViewport = document.querySelector('meta[name=viewport]');
|
||||
|
||||
if (metaViewport) {
|
||||
// user-scalable=no eliminates click delay.
|
||||
if (metaViewport.content.indexOf('user-scalable=no') !== -1) {
|
||||
return true;
|
||||
}
|
||||
// width=device-width (or less than device-width) eliminates click delay.
|
||||
if (document.documentElement.scrollWidth <= window.outerWidth) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// IE10 with -ms-touch-action: none, which disables double-tap-to-zoom (issue #97)
|
||||
if (layer.style.msTouchAction === 'none') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// IE11: prefixed -ms-touch-action is no longer supported and it's recomended to use non-prefixed version
|
||||
// http://msdn.microsoft.com/en-us/library/windows/apps/Hh767313.aspx
|
||||
if (layer.style.touchAction === 'none') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Factory method for creating a FastClick object
|
||||
*
|
||||
* @param {Element} layer The layer to listen on
|
||||
* @param {Object} [options={}] The options to override the defaults
|
||||
*/
|
||||
FastClick.attach = function(layer, options) {
|
||||
return new FastClick(layer, options);
|
||||
};
|
||||
|
||||
|
||||
if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
|
||||
|
||||
// AMD. Register as an anonymous module.
|
||||
define(function() {
|
||||
return FastClick;
|
||||
});
|
||||
} else if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = FastClick.attach;
|
||||
module.exports.FastClick = FastClick;
|
||||
} else {
|
||||
window.FastClick = FastClick;
|
||||
}
|
||||
}());
|
|
@ -0,0 +1,103 @@
|
|||
var dataURI, audio, myAudioContext, mySource, myBuffer;
|
||||
|
||||
if ('AudioContext' in window) {
|
||||
myAudioContext = new AudioContext();
|
||||
} else if ('webkitAudioContext' in window) {
|
||||
myAudioContext = new webkitAudioContext();
|
||||
} else {
|
||||
alert('Your browser does not support yet Web Audio API');
|
||||
}
|
||||
|
||||
var chr8 = function () {
|
||||
return Array.prototype.map.call(arguments, function(a){
|
||||
return String.fromCharCode(a&0xff)
|
||||
}).join('');
|
||||
}
|
||||
var chr16 = function () {
|
||||
return Array.prototype.map.call(arguments, function(a){
|
||||
return String.fromCharCode(a&0xff, (a>>8)&0xff)
|
||||
}).join('');
|
||||
}
|
||||
var chr32 = function () {
|
||||
return Array.prototype.map.call(arguments, function(a){
|
||||
return String.fromCharCode(a&0xff, (a>>8)&0xff,(a>>16)&0xff, (a>>24)&0xff);
|
||||
}).join('');
|
||||
}
|
||||
var toUTF8 = function (str) {
|
||||
var utf8 = [];
|
||||
for (var i = 0; i < str.length; i++) {
|
||||
var c = str.charCodeAt(i);
|
||||
if (c <= 0x7f)
|
||||
utf8.push(c);
|
||||
else if (c <= 0x7ff) {
|
||||
utf8.push(0xc0 | (c >>> 6));
|
||||
utf8.push(0x80 | (c & 0x3f));
|
||||
} else if (c <= 0xffff) {
|
||||
utf8.push(0xe0 | (c >>> 12));
|
||||
utf8.push(0x80 | ((c >>> 6) & 0x3f));
|
||||
utf8.push(0x80 | (c & 0x3f));
|
||||
} else {
|
||||
var j = 4;
|
||||
while (c >>> (6*j)) j++;
|
||||
utf8.push(((0xff00 >>> j) & 0xff) | (c >>> (6*--j)));
|
||||
while (j--)
|
||||
utf8[idx++] = 0x80 | ((c >>> (6*j)) & 0x3f);
|
||||
}
|
||||
}
|
||||
return utf8;
|
||||
}
|
||||
|
||||
var fsk = {};
|
||||
|
||||
fsk.generate = function (str) {
|
||||
if (str.length === 0) return;
|
||||
var utf8 = toUTF8(str);
|
||||
//console.log(utf8);
|
||||
|
||||
var sampleRate = 29400;
|
||||
var baud = 1225;
|
||||
var freqHigh = 7350;
|
||||
var freqLow = 4900;
|
||||
var spb = sampleRate/baud; // 24 samples per bit
|
||||
var preCarrierBits = Math.ceil(sampleRate*40/1000/spb); // 49 bits
|
||||
var postCarrierBits = Math.ceil(sampleRate*5/1000/spb); // 6.125 bits => 7 bits
|
||||
var size = (preCarrierBits + postCarrierBits + 10 * utf8.length) * spb;
|
||||
|
||||
var data = "RIFF" + chr32(size + 36) + "WAVE" +
|
||||
"fmt " + chr32(16, 0x00010001, sampleRate, sampleRate, 0x00080001) +
|
||||
"data" + chr32(size);
|
||||
|
||||
var pushData = function (freq, samples) {
|
||||
for (var i = 0; i < samples; i++) {
|
||||
var v = 128 + 127 * Math.sin((2 * Math.PI) * (i / sampleRate) * freq);
|
||||
data += chr8(v);
|
||||
}
|
||||
}
|
||||
pushData(freqHigh, preCarrierBits * spb);
|
||||
for (var x in utf8) {
|
||||
var c = (utf8[x] << 1) | 0x200;
|
||||
for (var i = 0; i < 10; i++, c >>>= 1)
|
||||
pushData((c&1) ? freqHigh : freqLow, spb);
|
||||
}
|
||||
pushData(freqHigh, postCarrierBits * spb);
|
||||
|
||||
//if (size+44 != data.length) alert("wrong size: " + size+44 + " != " + data.length);
|
||||
|
||||
dataURI = escape(btoa(data));
|
||||
|
||||
var arrayBuff = Base64Binary.decodeArrayBuffer(dataURI);
|
||||
myAudioContext.decodeAudioData(arrayBuff, function (audioData) {
|
||||
myBuffer = audioData;
|
||||
});
|
||||
}
|
||||
|
||||
fsk.play = function () {
|
||||
mySource = myAudioContext.createBufferSource();
|
||||
mySource.buffer = myBuffer;
|
||||
mySource.connect(myAudioContext.destination);
|
||||
if ('AudioContext' in window) {
|
||||
mySource.start(0);
|
||||
} else if ('webkitAudioContext' in window) {
|
||||
mySource.noteOn(0);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,257 @@
|
|||
//var $ = function (name) {
|
||||
//return document.getElementById(name);
|
||||
//} replaced by real jquery
|
||||
|
||||
|
||||
var ctrl = {};
|
||||
ctrl.seq = [];
|
||||
ctrl.pos = 0;
|
||||
ctrl.loop = false;
|
||||
|
||||
ctrl.delay = {
|
||||
f : 500,
|
||||
B : 700,
|
||||
x : 1000
|
||||
};
|
||||
|
||||
ctrl.play = function (val) {
|
||||
fsk.generate(val);
|
||||
setTimeout(function () {
|
||||
fsk.play();
|
||||
ctrl.posCmd(val);
|
||||
}, 10);
|
||||
};
|
||||
|
||||
ctrl.sendCmd = function (elem) {
|
||||
'use strict';
|
||||
var val = elem.title;
|
||||
console.log('Send command: ' + val);
|
||||
ctrl.play(val);
|
||||
};
|
||||
|
||||
ctrl.local = function (key, value) {
|
||||
var has = function () {
|
||||
try {
|
||||
return 'localStorage' in window && window.localStorage !== null;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
if (value === undefined) {
|
||||
if (has()) {
|
||||
var val = window.localStorage[key];
|
||||
if (val !== undefined) {
|
||||
val = JSON.parse(val);
|
||||
}
|
||||
return val;
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
} else {
|
||||
if (has()) {
|
||||
window.localStorage[key] = JSON.stringify(value);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.run = {};
|
||||
ctrl.run.i = 0;
|
||||
ctrl.run.next = function () {
|
||||
if ( ctrl.seq[ctrl.run.i] !== null
|
||||
&& ctrl.seq[ctrl.run.i] !== undefined) {
|
||||
console.log(ctrl.seq[ctrl.run.i]);
|
||||
ctrl.highlight(ctrl.run.i);
|
||||
if (ctrl.seq[ctrl.run.i] !== 'x') {
|
||||
ctrl.play(ctrl.seq[ctrl.run.i]);
|
||||
}
|
||||
setTimeout(function () {
|
||||
ctrl.run.i++;
|
||||
ctrl.run.next();
|
||||
}, ctrl.delay[ctrl.seq[ctrl.run.i]]);
|
||||
} else if (ctrl.run.i < ctrl.seq.length) {
|
||||
ctrl.run.i++;
|
||||
ctrl.run.next();
|
||||
} else {
|
||||
console.log('End sequence');
|
||||
ctrl.highlight(false);
|
||||
}
|
||||
};
|
||||
ctrl.run.start = function () {
|
||||
console.log('Started running sequence');
|
||||
ctrl.run.i = 0;
|
||||
ctrl.run.next();
|
||||
};
|
||||
ctrl.run.end = function () {
|
||||
console.log('Finished running sequence');
|
||||
ctrl.highlight(false);
|
||||
if (ctrl.loop) {
|
||||
ctrl.run.start();
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.highlight = function (i) {
|
||||
$('.seq > div > div').removeClass('highlight');
|
||||
if (i !== undefined && i !== false) {
|
||||
//console.log(i);
|
||||
$('.seq .row_f > div').eq(i).addClass('highlight');
|
||||
$('.seq .row_B > div').eq(i).addClass('highlight');
|
||||
$('.seq .row_x > div').eq(i).addClass('highlight');
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.setLoop = function () {
|
||||
if (ctrl.loop) {
|
||||
ctrl.loop = false;
|
||||
$('.loop').text('LOOP off');
|
||||
$('.loop').removeClass('on').addClass('off');
|
||||
ctrl.local('loop', {set: false});
|
||||
} else {
|
||||
ctrl.loop = true;
|
||||
$('.loop').text('LOOP on');
|
||||
$('.loop').removeClass('off').addClass('on')
|
||||
ctrl.local('loop', {set: true});
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.changeDelay = function (saved) {
|
||||
var delay;
|
||||
if (saved === undefined) {
|
||||
delay = prompt('Delay', ctrl.delay.x /1000);
|
||||
} else {
|
||||
delay = saved / 1000;
|
||||
}
|
||||
if (delay !== null) {
|
||||
delay = parseInt(delay) * 1000;
|
||||
ctrl.delay.x = delay;
|
||||
$('#delayVal').text(delay / 1000);
|
||||
ctrl.local('delay', delay);
|
||||
}
|
||||
};
|
||||
|
||||
//counter management
|
||||
ctrl.posCmd = function (val) {
|
||||
if (val === 'f') {
|
||||
ctrl.pos++;
|
||||
} else if (val === 'b') {
|
||||
ctrl.pos--;
|
||||
}
|
||||
ctrl.local('pos', ctrl.pos);
|
||||
$('#monitor').text(ctrl.pos);
|
||||
};
|
||||
|
||||
ctrl.setPos = function (pos) {
|
||||
if (pos === undefined) {
|
||||
ctrl.pos = parseInt(prompt('Frame position'));
|
||||
} else {
|
||||
ctrl.pos = parseInt(pos);
|
||||
}
|
||||
ctrl.local('pos', ctrl.pos);
|
||||
$('#monitor').text(ctrl.pos);
|
||||
};
|
||||
|
||||
ctrl.set = function (t) {
|
||||
var pos = parseInt(t.innerHTML);
|
||||
|
||||
if (ctrl.hasClass(t, 'set')) {
|
||||
ctrl.removeClass(t, 'set');
|
||||
ctrl.seq[pos] = null;
|
||||
} else {
|
||||
var which = t.className;
|
||||
var rows = $('#seq')[0].children;
|
||||
for (var i = 0; i < rows.length; i++) {
|
||||
var cell = rows[i].children[pos];
|
||||
if (cell.className.indexOf(which) === -1) {
|
||||
ctrl.removeClass(cell, 'set');
|
||||
}
|
||||
}
|
||||
ctrl.addClass(t, 'set');
|
||||
ctrl.seq[pos] = t.title;
|
||||
}
|
||||
ctrl.local('seq', ctrl.seq);
|
||||
};
|
||||
|
||||
ctrl.layout = function () {
|
||||
var layout = $('#seq')[0],
|
||||
row = layout.children,
|
||||
cell = null,
|
||||
w = $(window).width(),
|
||||
btn = $('.seq > div > div').eq(0).width() + 4,
|
||||
num = Math.floor((w - 16) / btn) - 1;
|
||||
for (var i = 0; i < row.length; i++) {
|
||||
if (ctrl.seq[0] !== undefined && ctrl.seq[0] !== null) {
|
||||
if (row[i].children[0].title === ctrl.seq[0]) {
|
||||
ctrl.addClass(row[i].children[0], 'set');
|
||||
}
|
||||
}
|
||||
for (var x = 0; x < num; x++) {
|
||||
cell = null;
|
||||
cell = row[i].children[0].cloneNode(true);
|
||||
cell.innerHTML = parseInt(cell.innerHTML) + x + 1;
|
||||
ctrl.removeClass(cell, 'set');
|
||||
if (ctrl.seq !== [] && ctrl.seq[x+1] !== undefined && ctrl.seq[x+1] !== null) {
|
||||
if (cell.title === ctrl.seq[x+1]) {
|
||||
ctrl.addClass(cell, 'set');
|
||||
}
|
||||
}
|
||||
row[i].appendChild(cell);
|
||||
}
|
||||
}
|
||||
if (ctrl.seq === []) {
|
||||
for (var y = 0; y < num; y++) {
|
||||
ctrl.seq.push(null);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.onload = function () {
|
||||
var delay = ctrl.local('delay');
|
||||
console.log(delay);
|
||||
if (delay !== undefined && delay !== false) {
|
||||
ctrl.changeDelay(delay);
|
||||
}
|
||||
var pos = ctrl.local('pos');
|
||||
console.log(pos);
|
||||
if (pos !== undefined && pos !== false) {
|
||||
ctrl.setPos(pos);
|
||||
}
|
||||
var loop = ctrl.local('loop');
|
||||
console.log(loop);
|
||||
if (loop !== undefined && loop !== false) {
|
||||
if (loop.set === true) {
|
||||
ctrl.setLoop(); //toggles to true
|
||||
}
|
||||
}
|
||||
var seq = ctrl.local('seq');
|
||||
console.log(seq);
|
||||
if (seq !== undefined && seq !== false) {
|
||||
ctrl.seq = seq;
|
||||
}
|
||||
ctrl.layout();
|
||||
//FastClick.attach(document.body);
|
||||
};
|
||||
|
||||
ctrl.hasClass = function (t, className) {
|
||||
if (t.className.indexOf(className) === -1) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
ctrl.addClass = function (t, className) {
|
||||
|
||||
t.className += ' ' + className;
|
||||
};
|
||||
|
||||
ctrl.removeClass = function (t, className) {
|
||||
t.className = t.className.replace(className + ' ', '');
|
||||
t.className = t.className.replace(' ' + className, '');
|
||||
};
|
||||
|
||||
Array.prototype.clone = function () {
|
||||
|
||||
return this.slice(0);
|
||||
};
|
Loading…
Reference in New Issue