mirror of
https://github.com/kkhattabi213/apm.emtusahuelva.es.git
synced 2026-03-31 15:06:24 +02:00
Subida inicial APM EMTUSA
This commit is contained in:
680
js/annyang.min.js
vendored
Normal file
680
js/annyang.min.js
vendored
Normal file
@@ -0,0 +1,680 @@
|
||||
//! annyang
|
||||
//! version : 2.6.0
|
||||
//! author : Tal Ater @TalAter
|
||||
//! license : MIT
|
||||
//! https://www.TalAter.com/annyang/
|
||||
(function (root, factory) {
|
||||
"use strict";
|
||||
if (typeof define === 'function' && define.amd) { // AMD + global
|
||||
define([], function () {
|
||||
return (root.annyang = factory(root));
|
||||
});
|
||||
} else if (typeof module === 'object' && module.exports) { // CommonJS
|
||||
module.exports = factory(root);
|
||||
} else { // Browser globals
|
||||
root.annyang = factory(root);
|
||||
}
|
||||
}(typeof window !== 'undefined' ? window : this, function (root, undefined) {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* # Quick Tutorial, Intro and Demos
|
||||
*
|
||||
* The quickest way to get started is to visit the [annyang homepage](https://www.talater.com/annyang/).
|
||||
*
|
||||
* For a more in-depth look at annyang, read on.
|
||||
*
|
||||
* # API Reference
|
||||
*/
|
||||
|
||||
var annyang;
|
||||
|
||||
// Get the SpeechRecognition object, while handling browser prefixes
|
||||
var SpeechRecognition = root.SpeechRecognition ||
|
||||
root.webkitSpeechRecognition ||
|
||||
root.mozSpeechRecognition ||
|
||||
root.msSpeechRecognition ||
|
||||
root.oSpeechRecognition;
|
||||
|
||||
// Check browser support
|
||||
// This is done as early as possible, to make it as fast as possible for unsupported browsers
|
||||
if (!SpeechRecognition) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var commandsList = [];
|
||||
var recognition;
|
||||
var callbacks = { start: [], error: [], end: [], soundstart: [], result: [], resultMatch: [], resultNoMatch: [], errorNetwork: [], errorPermissionBlocked: [], errorPermissionDenied: [] };
|
||||
var autoRestart;
|
||||
var lastStartedAt = 0;
|
||||
var autoRestartCount = 0;
|
||||
var debugState = false;
|
||||
var debugStyle = 'font-weight: bold; color: #00f;';
|
||||
var pauseListening = false;
|
||||
var isListening = false;
|
||||
|
||||
// The command matching code is a modified version of Backbone.Router by Jeremy Ashkenas, under the MIT license.
|
||||
var optionalParam = /\s*\((.*?)\)\s*/g;
|
||||
var optionalRegex = /(\(\?:[^)]+\))\?/g;
|
||||
var namedParam = /(\(\?)?:\w+/g;
|
||||
var splatParam = /\*\w+/g;
|
||||
var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#]/g;
|
||||
var commandToRegExp = function(command) {
|
||||
command = command.replace(escapeRegExp, '\\$&')
|
||||
.replace(optionalParam, '(?:$1)?')
|
||||
.replace(namedParam, function(match, optional) {
|
||||
return optional ? match : '([^\\s]+)';
|
||||
})
|
||||
.replace(splatParam, '(.*?)')
|
||||
.replace(optionalRegex, '\\s*$1?\\s*');
|
||||
return new RegExp('^' + command + '$', 'i');
|
||||
};
|
||||
|
||||
// This method receives an array of callbacks to iterate over, and invokes each of them
|
||||
var invokeCallbacks = function(callbacks, ...args) {
|
||||
callbacks.forEach(function(callback) {
|
||||
callback.callback.apply(callback.context, args);
|
||||
});
|
||||
};
|
||||
|
||||
var isInitialized = function() {
|
||||
return recognition !== undefined;
|
||||
};
|
||||
|
||||
// method for logging in developer console when debug mode is on
|
||||
var logMessage = function(text, extraParameters) {
|
||||
if (text.indexOf('%c') === -1 && !extraParameters) {
|
||||
console.log(text);
|
||||
} else {
|
||||
console.log(text, extraParameters || debugStyle);
|
||||
}
|
||||
};
|
||||
|
||||
var initIfNeeded = function() {
|
||||
if (!isInitialized()) {
|
||||
annyang.init({}, false);
|
||||
}
|
||||
};
|
||||
|
||||
var registerCommand = function(command, callback, originalPhrase) {
|
||||
commandsList.push({ command, callback, originalPhrase });
|
||||
if (debugState) {
|
||||
logMessage('Command successfully loaded: %c'+originalPhrase, debugStyle);
|
||||
}
|
||||
};
|
||||
|
||||
var parseResults = function(results) {
|
||||
invokeCallbacks(callbacks.result, results);
|
||||
var commandText;
|
||||
// go over each of the 5 results and alternative results received (we've set maxAlternatives to 5 above)
|
||||
for (let i = 0; i<results.length; i++) {
|
||||
// the text recognized
|
||||
commandText = results[i].trim();
|
||||
if (debugState) {
|
||||
logMessage('Speech recognized: %c'+commandText, debugStyle);
|
||||
}
|
||||
|
||||
// try and match recognized text to one of the commands on the list
|
||||
for (let j = 0, l = commandsList.length; j < l; j++) {
|
||||
var currentCommand = commandsList[j];
|
||||
var result = currentCommand.command.exec(commandText);
|
||||
if (result) {
|
||||
var parameters = result.slice(1);
|
||||
if (debugState) {
|
||||
logMessage('command matched: %c'+currentCommand.originalPhrase, debugStyle);
|
||||
if (parameters.length) {
|
||||
logMessage('with parameters', parameters);
|
||||
}
|
||||
}
|
||||
// execute the matched command
|
||||
currentCommand.callback.apply(this, parameters);
|
||||
invokeCallbacks(callbacks.resultMatch, commandText, currentCommand.originalPhrase, results);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
invokeCallbacks(callbacks.resultNoMatch, results);
|
||||
};
|
||||
|
||||
annyang = {
|
||||
|
||||
/**
|
||||
* Initialize annyang with a list of commands to recognize.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* var commands = {'hello :name': helloFunction};
|
||||
* var commands2 = {'hi': helloFunction};
|
||||
*
|
||||
* // initialize annyang, overwriting any previously added commands
|
||||
* annyang.init(commands, true);
|
||||
* // adds an additional command without removing the previous commands
|
||||
* annyang.init(commands2, false);
|
||||
* ````
|
||||
* As of v1.1.0 it is no longer required to call init(). Just start() listening whenever you want, and addCommands() whenever, and as often as you like.
|
||||
*
|
||||
* @param {Object} commands - Commands that annyang should listen to
|
||||
* @param {boolean} [resetCommands=true] - Remove all commands before initializing?
|
||||
* @method init
|
||||
* @deprecated
|
||||
* @see [Commands Object](#commands-object)
|
||||
*/
|
||||
init: function(commands, resetCommands = true) {
|
||||
// Abort previous instances of recognition already running
|
||||
if (recognition && recognition.abort) {
|
||||
recognition.abort();
|
||||
}
|
||||
|
||||
// initiate SpeechRecognition
|
||||
recognition = new SpeechRecognition();
|
||||
|
||||
// Set the max number of alternative transcripts to try and match with a command
|
||||
recognition.maxAlternatives = 5;
|
||||
|
||||
// In HTTPS, turn off continuous mode for faster results.
|
||||
// In HTTP, turn on continuous mode for much slower results, but no repeating security notices
|
||||
recognition.continuous = root.location.protocol === 'http:';
|
||||
|
||||
// Sets the language to the default 'en-US'. This can be changed with annyang.setLanguage()
|
||||
recognition.lang = 'en-US';
|
||||
|
||||
recognition.onstart = function() {
|
||||
isListening = true;
|
||||
invokeCallbacks(callbacks.start);
|
||||
};
|
||||
|
||||
recognition.onsoundstart = function() {
|
||||
invokeCallbacks(callbacks.soundstart);
|
||||
};
|
||||
|
||||
recognition.onerror = function(event) {
|
||||
invokeCallbacks(callbacks.error, event);
|
||||
switch (event.error) {
|
||||
case 'network':
|
||||
invokeCallbacks(callbacks.errorNetwork, event);
|
||||
break;
|
||||
case 'not-allowed':
|
||||
case 'service-not-allowed':
|
||||
// if permission to use the mic is denied, turn off auto-restart
|
||||
autoRestart = false;
|
||||
// determine if permission was denied by user or automatically.
|
||||
if (new Date().getTime()-lastStartedAt < 200) {
|
||||
invokeCallbacks(callbacks.errorPermissionBlocked, event);
|
||||
} else {
|
||||
invokeCallbacks(callbacks.errorPermissionDenied, event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onend = function() {
|
||||
isListening = false;
|
||||
invokeCallbacks(callbacks.end);
|
||||
// annyang will auto restart if it is closed automatically and not by user action.
|
||||
if (autoRestart) {
|
||||
// play nicely with the browser, and never restart annyang automatically more than once per second
|
||||
var timeSinceLastStart = new Date().getTime()-lastStartedAt;
|
||||
autoRestartCount += 1;
|
||||
if (autoRestartCount % 10 === 0) {
|
||||
if (debugState) {
|
||||
logMessage('Speech Recognition is repeatedly stopping and starting. See http://is.gd/annyang_restarts for tips.');
|
||||
}
|
||||
}
|
||||
if (timeSinceLastStart < 1000) {
|
||||
setTimeout(function() {
|
||||
annyang.start({ paused: pauseListening });
|
||||
}, 1000-timeSinceLastStart);
|
||||
} else {
|
||||
annyang.start({ paused: pauseListening });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
recognition.onresult = function(event) {
|
||||
if(pauseListening) {
|
||||
if (debugState) {
|
||||
logMessage('Speech heard, but annyang is paused');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Map the results to an array
|
||||
var SpeechRecognitionResult = event.results[event.resultIndex];
|
||||
var results = [];
|
||||
for (let k = 0; k<SpeechRecognitionResult.length; k++) {
|
||||
results[k] = SpeechRecognitionResult[k].transcript;
|
||||
}
|
||||
|
||||
parseResults(results);
|
||||
};
|
||||
|
||||
// build commands list
|
||||
if (resetCommands) {
|
||||
commandsList = [];
|
||||
}
|
||||
if (commands.length) {
|
||||
this.addCommands(commands);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Start listening.
|
||||
* It's a good idea to call this after adding some commands first, but not mandatory.
|
||||
*
|
||||
* Receives an optional options object which supports the following options:
|
||||
*
|
||||
* - `autoRestart` (boolean, default: true) Should annyang restart itself if it is closed indirectly, because of silence or window conflicts?
|
||||
* - `continuous` (boolean) Allow forcing continuous mode on or off. Annyang is pretty smart about this, so only set this if you know what you're doing.
|
||||
* - `paused` (boolean, default: true) Start annyang in paused mode.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* // Start listening, don't restart automatically
|
||||
* annyang.start({ autoRestart: false });
|
||||
* // Start listening, don't restart automatically, stop recognition after first phrase recognized
|
||||
* annyang.start({ autoRestart: false, continuous: false });
|
||||
* ````
|
||||
* @param {Object} [options] - Optional options.
|
||||
* @method start
|
||||
*/
|
||||
start: function(options) {
|
||||
initIfNeeded();
|
||||
options = options || {};
|
||||
if (options.paused !== undefined) {
|
||||
pauseListening = !!options.paused;
|
||||
} else {
|
||||
pauseListening = false;
|
||||
}
|
||||
if (options.autoRestart !== undefined) {
|
||||
autoRestart = !!options.autoRestart;
|
||||
} else {
|
||||
autoRestart = true;
|
||||
}
|
||||
if (options.continuous !== undefined) {
|
||||
recognition.continuous = !!options.continuous;
|
||||
}
|
||||
|
||||
lastStartedAt = new Date().getTime();
|
||||
try {
|
||||
recognition.start();
|
||||
} catch(e) {
|
||||
if (debugState) {
|
||||
logMessage(e.message);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Stop listening, and turn off mic.
|
||||
*
|
||||
* Alternatively, to only temporarily pause annyang responding to commands without stopping the SpeechRecognition engine or closing the mic, use pause() instead.
|
||||
* @see [pause()](#pause)
|
||||
*
|
||||
* @method abort
|
||||
*/
|
||||
abort: function() {
|
||||
autoRestart = false;
|
||||
autoRestartCount = 0;
|
||||
if (isInitialized()) {
|
||||
recognition.abort();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Pause listening. annyang will stop responding to commands (until the resume or start methods are called), without turning off the browser's SpeechRecognition engine or the mic.
|
||||
*
|
||||
* Alternatively, to stop the SpeechRecognition engine and close the mic, use abort() instead.
|
||||
* @see [abort()](#abort)
|
||||
*
|
||||
* @method pause
|
||||
*/
|
||||
pause: function() {
|
||||
pauseListening = true;
|
||||
},
|
||||
|
||||
/**
|
||||
* Resumes listening and restores command callback execution when a result matches.
|
||||
* If SpeechRecognition was aborted (stopped), start it.
|
||||
*
|
||||
* @method resume
|
||||
*/
|
||||
resume: function() {
|
||||
annyang.start();
|
||||
},
|
||||
|
||||
/**
|
||||
* Turn on output of debug messages to the console. Ugly, but super-handy!
|
||||
*
|
||||
* @param {boolean} [newState=true] - Turn on/off debug messages
|
||||
* @method debug
|
||||
*/
|
||||
debug: function(newState = true) {
|
||||
debugState = !!newState;
|
||||
},
|
||||
|
||||
/**
|
||||
* Set the language the user will speak in. If this method is not called, defaults to 'en-US'.
|
||||
*
|
||||
* @param {String} language - The language (locale)
|
||||
* @method setLanguage
|
||||
* @see [Languages](https://github.com/TalAter/annyang/blob/master/docs/FAQ.md#what-languages-are-supported)
|
||||
*/
|
||||
setLanguage: function(language) {
|
||||
initIfNeeded();
|
||||
recognition.lang = language;
|
||||
},
|
||||
|
||||
/**
|
||||
* Add commands that annyang will respond to. Similar in syntax to init(), but doesn't remove existing commands.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* var commands = {'hello :name': helloFunction, 'howdy': helloFunction};
|
||||
* var commands2 = {'hi': helloFunction};
|
||||
*
|
||||
* annyang.addCommands(commands);
|
||||
* annyang.addCommands(commands2);
|
||||
* // annyang will now listen to all three commands
|
||||
* ````
|
||||
*
|
||||
* @param {Object} commands - Commands that annyang should listen to
|
||||
* @method addCommands
|
||||
* @see [Commands Object](#commands-object)
|
||||
*/
|
||||
addCommands: function(commands) {
|
||||
var cb;
|
||||
|
||||
initIfNeeded();
|
||||
|
||||
for (let phrase in commands) {
|
||||
if (commands.hasOwnProperty(phrase)) {
|
||||
cb = root[commands[phrase]] || commands[phrase];
|
||||
if (typeof cb === 'function') {
|
||||
// convert command to regex then register the command
|
||||
registerCommand(commandToRegExp(phrase), cb, phrase);
|
||||
} else if (typeof cb === 'object' && cb.regexp instanceof RegExp) {
|
||||
// register the command
|
||||
registerCommand(new RegExp(cb.regexp.source, 'i'), cb.callback, phrase);
|
||||
} else {
|
||||
if (debugState) {
|
||||
logMessage('Can not register command: %c'+phrase, debugStyle);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove existing commands. Called with a single phrase, array of phrases, or methodically. Pass no params to remove all commands.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* var commands = {'hello': helloFunction, 'howdy': helloFunction, 'hi': helloFunction};
|
||||
*
|
||||
* // Remove all existing commands
|
||||
* annyang.removeCommands();
|
||||
*
|
||||
* // Add some commands
|
||||
* annyang.addCommands(commands);
|
||||
*
|
||||
* // Don't respond to hello
|
||||
* annyang.removeCommands('hello');
|
||||
*
|
||||
* // Don't respond to howdy or hi
|
||||
* annyang.removeCommands(['howdy', 'hi']);
|
||||
* ````
|
||||
* @param {String|Array|Undefined} [commandsToRemove] - Commands to remove
|
||||
* @method removeCommands
|
||||
*/
|
||||
removeCommands: function(commandsToRemove) {
|
||||
if (commandsToRemove === undefined) {
|
||||
commandsList = [];
|
||||
} else {
|
||||
commandsToRemove = Array.isArray(commandsToRemove) ? commandsToRemove : [commandsToRemove];
|
||||
commandsList = commandsList.filter(command => {
|
||||
for (let i = 0; i<commandsToRemove.length; i++) {
|
||||
if (commandsToRemove[i] === command.originalPhrase) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Add a callback function to be called in case one of the following events happens:
|
||||
*
|
||||
* * `start` - Fired as soon as the browser's Speech Recognition engine starts listening
|
||||
* * `soundstart` - Fired as soon as any sound (possibly speech) has been detected.
|
||||
* This will fire once per Speech Recognition starting. See https://is.gd/annyang_sound_start
|
||||
* * `error` - Fired when the browser's Speech Recogntion engine returns an error, this generic error callback will be followed by more accurate error callbacks (both will fire if both are defined)
|
||||
* Callback function will be called with the error event as the first argument
|
||||
* * `errorNetwork` - Fired when Speech Recognition fails because of a network error
|
||||
* Callback function will be called with the error event as the first argument
|
||||
* * `errorPermissionBlocked` - Fired when the browser blocks the permission request to use Speech Recognition.
|
||||
* Callback function will be called with the error event as the first argument
|
||||
* * `errorPermissionDenied` - Fired when the user blocks the permission request to use Speech Recognition.
|
||||
* Callback function will be called with the error event as the first argument
|
||||
* * `end` - Fired when the browser's Speech Recognition engine stops
|
||||
* * `result` - Fired as soon as some speech was identified. This generic callback will be followed by either the `resultMatch` or `resultNoMatch` callbacks.
|
||||
* Callback functions for to this event will be called with an array of possible phrases the user said as the first argument
|
||||
* * `resultMatch` - Fired when annyang was able to match between what the user said and a registered command
|
||||
* Callback functions for this event will be called with three arguments in the following order:
|
||||
* * The phrase the user said that matched a command
|
||||
* * The command that was matched
|
||||
* * An array of possible alternative phrases the user might have said
|
||||
* * `resultNoMatch` - Fired when what the user said didn't match any of the registered commands.
|
||||
* Callback functions for this event will be called with an array of possible phrases the user might've said as the first argument
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* annyang.addCallback('error', function() {
|
||||
* $('.myErrorText').text('There was an error!');
|
||||
* });
|
||||
*
|
||||
* annyang.addCallback('resultMatch', function(userSaid, commandText, phrases) {
|
||||
* console.log(userSaid); // sample output: 'hello'
|
||||
* console.log(commandText); // sample output: 'hello (there)'
|
||||
* console.log(phrases); // sample output: ['hello', 'halo', 'yellow', 'polo', 'hello kitty']
|
||||
* });
|
||||
*
|
||||
* // pass local context to a global function called notConnected
|
||||
* annyang.addCallback('errorNetwork', notConnected, this);
|
||||
* ````
|
||||
* @param {String} type - Name of event that will trigger this callback
|
||||
* @param {Function} callback - The function to call when event is triggered
|
||||
* @param {Object} [context] - Optional context for the callback function
|
||||
* @method addCallback
|
||||
*/
|
||||
addCallback: function(type, callback, context) {
|
||||
var cb = root[callback] || callback;
|
||||
if (typeof cb === 'function' && callbacks[type] !== undefined) {
|
||||
callbacks[type].push({callback: cb, context: context || this});
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Remove callbacks from events.
|
||||
*
|
||||
* - Pass an event name and a callback command to remove that callback command from that event type.
|
||||
* - Pass just an event name to remove all callback commands from that event type.
|
||||
* - Pass undefined as event name and a callback command to remove that callback command from all event types.
|
||||
* - Pass no params to remove all callback commands from all event types.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* annyang.addCallback('start', myFunction1);
|
||||
* annyang.addCallback('start', myFunction2);
|
||||
* annyang.addCallback('end', myFunction1);
|
||||
* annyang.addCallback('end', myFunction2);
|
||||
*
|
||||
* // Remove all callbacks from all events:
|
||||
* annyang.removeCallback();
|
||||
*
|
||||
* // Remove all callbacks attached to end event:
|
||||
* annyang.removeCallback('end');
|
||||
*
|
||||
* // Remove myFunction2 from being called on start:
|
||||
* annyang.removeCallback('start', myFunction2);
|
||||
*
|
||||
* // Remove myFunction1 from being called on all events:
|
||||
* annyang.removeCallback(undefined, myFunction1);
|
||||
* ````
|
||||
*
|
||||
* @param type Name of event type to remove callback from
|
||||
* @param callback The callback function to remove
|
||||
* @returns undefined
|
||||
* @method removeCallback
|
||||
*/
|
||||
removeCallback: function(type, callback) {
|
||||
var compareWithCallbackParameter = function(cb) {
|
||||
return cb.callback !== callback;
|
||||
};
|
||||
// Go over each callback type in callbacks store object
|
||||
for (let callbackType in callbacks) {
|
||||
if (callbacks.hasOwnProperty(callbackType)) {
|
||||
// if this is the type user asked to delete, or he asked to delete all, go ahead.
|
||||
if (type === undefined || type === callbackType) {
|
||||
// If user asked to delete all callbacks in this type or all types
|
||||
if (callback === undefined) {
|
||||
callbacks[callbackType] = [];
|
||||
} else {
|
||||
// Remove all matching callbacks
|
||||
callbacks[callbackType] = callbacks[callbackType].filter(compareWithCallbackParameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true if speech recognition is currently on.
|
||||
* Returns false if speech recognition is off or annyang is paused.
|
||||
*
|
||||
* @return boolean true = SpeechRecognition is on and annyang is listening
|
||||
* @method isListening
|
||||
*/
|
||||
isListening: function() {
|
||||
return isListening && !pauseListening;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the instance of the browser's SpeechRecognition object used by annyang.
|
||||
* Useful in case you want direct access to the browser's Speech Recognition engine.
|
||||
*
|
||||
* @returns SpeechRecognition The browser's Speech Recognizer currently used by annyang
|
||||
* @method getSpeechRecognizer
|
||||
*/
|
||||
getSpeechRecognizer: function() {
|
||||
return recognition;
|
||||
},
|
||||
|
||||
/**
|
||||
* Simulate speech being recognized. This will trigger the same events and behavior as when the Speech Recognition
|
||||
* detects speech.
|
||||
*
|
||||
* Can accept either a string containing a single sentence, or an array containing multiple sentences to be checked
|
||||
* in order until one of them matches a command (similar to the way Speech Recognition Alternatives are parsed)
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* annyang.trigger('Time for some thrilling heroics');
|
||||
* annyang.trigger(
|
||||
* ['Time for some thrilling heroics', 'Time for some thrilling aerobics']
|
||||
* );
|
||||
* ````
|
||||
*
|
||||
* @param string|array sentences A sentence as a string or an array of strings of possible sentences
|
||||
* @returns undefined
|
||||
* @method trigger
|
||||
*/
|
||||
trigger: function(sentences) {
|
||||
if(!annyang.isListening()) {
|
||||
if (debugState) {
|
||||
if (!isListening) {
|
||||
logMessage('Cannot trigger while annyang is aborted');
|
||||
} else {
|
||||
logMessage('Speech heard, but annyang is paused');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(sentences)) {
|
||||
sentences = [sentences];
|
||||
}
|
||||
|
||||
parseResults(sentences);
|
||||
}
|
||||
};
|
||||
|
||||
return annyang;
|
||||
|
||||
}));
|
||||
|
||||
/**
|
||||
* # Good to Know
|
||||
*
|
||||
* ## Commands Object
|
||||
*
|
||||
* Both the [init()]() and addCommands() methods receive a `commands` object.
|
||||
*
|
||||
* annyang understands commands with `named variables`, `splats`, and `optional words`.
|
||||
*
|
||||
* * Use `named variables` for one word arguments in your command.
|
||||
* * Use `splats` to capture multi-word text at the end of your command (greedy).
|
||||
* * Use `optional words` or phrases to define a part of the command as optional.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````html
|
||||
* <script>
|
||||
* var commands = {
|
||||
* // annyang will capture anything after a splat (*) and pass it to the function.
|
||||
* // e.g. saying "Show me Batman and Robin" will call showFlickr('Batman and Robin');
|
||||
* 'show me *tag': showFlickr,
|
||||
*
|
||||
* // A named variable is a one word variable, that can fit anywhere in your command.
|
||||
* // e.g. saying "calculate October stats" will call calculateStats('October');
|
||||
* 'calculate :month stats': calculateStats,
|
||||
*
|
||||
* // By defining a part of the following command as optional, annyang will respond
|
||||
* // to both: "say hello to my little friend" as well as "say hello friend"
|
||||
* 'say hello (to my little) friend': greeting
|
||||
* };
|
||||
*
|
||||
* var showFlickr = function(tag) {
|
||||
* var url = 'http://api.flickr.com/services/rest/?tags='+tag;
|
||||
* $.getJSON(url);
|
||||
* }
|
||||
*
|
||||
* var calculateStats = function(month) {
|
||||
* $('#stats').text('Statistics for '+month);
|
||||
* }
|
||||
*
|
||||
* var greeting = function() {
|
||||
* $('#greeting').text('Hello!');
|
||||
* }
|
||||
* </script>
|
||||
* ````
|
||||
*
|
||||
* ### Using Regular Expressions in commands
|
||||
* For advanced commands, you can pass a regular expression object, instead of
|
||||
* a simple string command.
|
||||
*
|
||||
* This is done by passing an object containing two properties: `regexp`, and
|
||||
* `callback` instead of the function.
|
||||
*
|
||||
* #### Examples:
|
||||
* ````javascript
|
||||
* var calculateFunction = function(month) { console.log(month); }
|
||||
* var commands = {
|
||||
* // This example will accept any word as the "month"
|
||||
* 'calculate :month stats': calculateFunction,
|
||||
* // This example will only accept months which are at the start of a quarter
|
||||
* 'calculate :quarter stats': {'regexp': /^calculate (January|April|July|October) stats$/, 'callback': calculateFunction}
|
||||
* }
|
||||
````
|
||||
*
|
||||
*/
|
||||
2
js/getmdl-select.min.js
vendored
Normal file
2
js/getmdl-select.min.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
"use strict";!function(){function e(){getmdlSelect.init(".getmdl-select")}window.addEventListener?window.addEventListener("load",e,!1):window.attachEvent&&window.attachEvent("onload",e)}();var getmdlSelect={_defaultValue:{width:300},_addEventListeners:function(e){var t=e.querySelector("input"),n=e.querySelector('input[type="hidden"]'),l=e.querySelectorAll("li"),a=e.querySelector(".mdl-js-menu"),o=e.querySelector(".mdl-icon-toggle__label"),i="",c="",s="",u=!1,d=function(o){var i=o.textContent.trim();if(t.value=i,l.forEach(function(e){e.classList.remove("selected")}),o.classList.add("selected"),e.MaterialTextfield.change(i),setTimeout(function(){e.MaterialTextfield.updateClasses_()},250),n.value=o.dataset.val||"",c=t.value,s=n.value,"createEvent"in document){var u=document.createEvent("HTMLEvents");u.initEvent("change",!1,!0),a.MaterialMenu.hide(),t.dispatchEvent(u)}else t.fireEvent("onchange")},r=function(){u=!1,t.value=c,n.value=s,e.querySelector(".mdl-menu__container").classList.contains("is-visible")||e.classList.remove("is-focused");var l=document.querySelectorAll(".getmdl-select .mdl-js-menu");[].forEach.call(l,function(e){e.MaterialMenu.hide()});var o=new Event("closeSelect");a.dispatchEvent(o)};document.body.addEventListener("click",r,!1),e.onkeydown=function(l){9==l.keyCode&&(t.value=c,n.value=s,a.MaterialMenu.hide(),e.classList.remove("is-focused"))},t.onfocus=function(e){a.MaterialMenu.show(),a.focus(),u=!0},t.onblur=function(e){e.stopPropagation()},t.onclick=function(t){t.stopPropagation(),a.classList.contains("is-visible")?(a.MaterialMenu.hide(),u=!1):(a.MaterialMenu.show(),r(),e.classList.add("is-focused"),u=!0)},t.onkeydown=function(l){27==l.keyCode&&(t.value=c,n.value=s,a.MaterialMenu.hide(),e.MaterialTextfield.onBlur_(),""!==i&&(e.querySelector(".mdl-textfield__label").textContent=i,i=""))},a.addEventListener("closeSelect",function(l){t.value=c,n.value=s,e.classList.remove("is-focused"),""!==i&&(e.querySelector(".mdl-textfield__label").textContent=i,i="")}),a.onkeydown=function(l){27==l.keyCode&&(t.value=c,n.value=s,e.classList.remove("is-focused"),""!==i&&(e.querySelector(".mdl-textfield__label").textContent=i,i=""))},o&&(o.onclick=function(l){l.stopPropagation(),u?(a.MaterialMenu.hide(),u=!1,e.classList.remove("is-focused"),e.MaterialTextfield.onBlur_(),t.value=c,n.value=s):(r(),e.MaterialTextfield.onFocus_(),t.focus(),a.MaterialMenu.show(),u=!0)}),[].forEach.call(l,function(n){n.onfocus=function(){e.classList.add("is-focused");var l=n.textContent.trim();t.value=l,e.classList.contains("mdl-textfield--floating-label")||""!=i||(i=e.querySelector(".mdl-textfield__label").textContent.trim(),e.querySelector(".mdl-textfield__label").textContent="")},n.onclick=function(){d(n)},n.dataset.selected&&d(n)})},init:function(e){var t=document.querySelectorAll(e);[].forEach.call(t,function(e){getmdlSelect._addEventListeners(e),componentHandler.upgradeElement(e),componentHandler.upgradeElement(e.querySelector("ul"))})}};
|
||||
//# sourceMappingURL=getmdl-select.min.js.map
|
||||
6227
js/index.js
Normal file
6227
js/index.js
Normal file
File diff suppressed because it is too large
Load Diff
4
js/jquery-1.11.1.min.js
vendored
Normal file
4
js/jquery-1.11.1.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
114
js/jquery.cookie.js
Normal file
114
js/jquery.cookie.js
Normal file
@@ -0,0 +1,114 @@
|
||||
/*!
|
||||
* jQuery Cookie Plugin v1.4.1
|
||||
* https://github.com/carhartl/jquery-cookie
|
||||
*
|
||||
* Copyright 2006, 2014 Klaus Hartl
|
||||
* Released under the MIT license
|
||||
*/
|
||||
(function (factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD (Register as an anonymous module)
|
||||
define(['jquery'], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node/CommonJS
|
||||
module.exports = factory(require('jquery'));
|
||||
} else {
|
||||
// Browser globals
|
||||
factory(jQuery);
|
||||
}
|
||||
}(function ($) {
|
||||
|
||||
var pluses = /\+/g;
|
||||
|
||||
function encode(s) {
|
||||
return config.raw ? s : encodeURIComponent(s);
|
||||
}
|
||||
|
||||
function decode(s) {
|
||||
return config.raw ? s : decodeURIComponent(s);
|
||||
}
|
||||
|
||||
function stringifyCookieValue(value) {
|
||||
return encode(config.json ? JSON.stringify(value) : String(value));
|
||||
}
|
||||
|
||||
function parseCookieValue(s) {
|
||||
if (s.indexOf('"') === 0) {
|
||||
// This is a quoted cookie as according to RFC2068, unescape...
|
||||
s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
|
||||
}
|
||||
|
||||
try {
|
||||
// Replace server-side written pluses with spaces.
|
||||
// If we can't decode the cookie, ignore it, it's unusable.
|
||||
// If we can't parse the cookie, ignore it, it's unusable.
|
||||
s = decodeURIComponent(s.replace(pluses, ' '));
|
||||
return config.json ? JSON.parse(s) : s;
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
function read(s, converter) {
|
||||
var value = config.raw ? s : parseCookieValue(s);
|
||||
return $.isFunction(converter) ? converter(value) : value;
|
||||
}
|
||||
|
||||
var config = $.cookie = function (key, value, options) {
|
||||
|
||||
// Write
|
||||
|
||||
if (arguments.length > 1 && !$.isFunction(value)) {
|
||||
options = $.extend({}, config.defaults, options);
|
||||
|
||||
if (typeof options.expires === 'number') {
|
||||
var days = options.expires, t = options.expires = new Date();
|
||||
t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
|
||||
}
|
||||
|
||||
return (document.cookie = [
|
||||
encode(key), '=', stringifyCookieValue(value),
|
||||
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
|
||||
options.path ? '; path=' + options.path : '',
|
||||
options.domain ? '; domain=' + options.domain : '',
|
||||
options.secure ? '; secure' : ''
|
||||
].join(''));
|
||||
}
|
||||
|
||||
// Read
|
||||
|
||||
var result = key ? undefined : {},
|
||||
// To prevent the for loop in the first place assign an empty array
|
||||
// in case there are no cookies at all. Also prevents odd result when
|
||||
// calling $.cookie().
|
||||
cookies = document.cookie ? document.cookie.split('; ') : [],
|
||||
i = 0,
|
||||
l = cookies.length;
|
||||
|
||||
for (; i < l; i++) {
|
||||
var parts = cookies[i].split('='),
|
||||
name = decode(parts.shift()),
|
||||
cookie = parts.join('=');
|
||||
|
||||
if (key === name) {
|
||||
// If second argument (value) is a function it's a converter...
|
||||
result = read(cookie, value);
|
||||
break;
|
||||
}
|
||||
|
||||
// Prevent storing a cookie that we couldn't decode.
|
||||
if (!key && (cookie = read(cookie)) !== undefined) {
|
||||
result[name] = cookie;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
config.defaults = {};
|
||||
|
||||
$.removeCookie = function (key, options) {
|
||||
// Must not alter options, thus extending a fresh object...
|
||||
$.cookie(key, '', $.extend({}, options, { expires: -1 }));
|
||||
return !$.cookie(key);
|
||||
};
|
||||
|
||||
}));
|
||||
10
js/jquery.mobile-1.4.5.min.js
vendored
Normal file
10
js/jquery.mobile-1.4.5.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2
js/jquery.storageapi.min.js
vendored
Normal file
2
js/jquery.storageapi.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
11
js/jquery.ui.touch-punch.min.js
vendored
Normal file
11
js/jquery.ui.touch-punch.min.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
/*!
|
||||
* jQuery UI Touch Punch 0.2.3
|
||||
*
|
||||
* Copyright 2011–2014, Dave Furfero
|
||||
* Dual licensed under the MIT or GPL Version 2 licenses.
|
||||
*
|
||||
* Depends:
|
||||
* jquery.ui.widget.js
|
||||
* jquery.ui.mouse.js
|
||||
*/
|
||||
!function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
|
||||
519
js/json2.js
Normal file
519
js/json2.js
Normal file
@@ -0,0 +1,519 @@
|
||||
/*
|
||||
json2.js
|
||||
2015-05-03
|
||||
|
||||
Public Domain.
|
||||
|
||||
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
|
||||
|
||||
See http://www.JSON.org/js.html
|
||||
|
||||
|
||||
This code should be minified before deployment.
|
||||
See http://javascript.crockford.com/jsmin.html
|
||||
|
||||
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
|
||||
NOT CONTROL.
|
||||
|
||||
|
||||
This file creates a global JSON object containing two methods: stringify
|
||||
and parse. This file is provides the ES5 JSON capability to ES3 systems.
|
||||
If a project might run on IE8 or earlier, then this file should be included.
|
||||
This file does nothing on ES5 systems.
|
||||
|
||||
JSON.stringify(value, replacer, space)
|
||||
value any JavaScript value, usually an object or array.
|
||||
|
||||
replacer an optional parameter that determines how object
|
||||
values are stringified for objects. It can be a
|
||||
function or an array of strings.
|
||||
|
||||
space an optional parameter that specifies the indentation
|
||||
of nested structures. If it is omitted, the text will
|
||||
be packed without extra whitespace. If it is a number,
|
||||
it will specify the number of spaces to indent at each
|
||||
level. If it is a string (such as '\t' or ' '),
|
||||
it contains the characters used to indent at each level.
|
||||
|
||||
This method produces a JSON text from a JavaScript value.
|
||||
|
||||
When an object value is found, if the object contains a toJSON
|
||||
method, its toJSON method will be called and the result will be
|
||||
stringified. A toJSON method does not serialize: it returns the
|
||||
value represented by the name/value pair that should be serialized,
|
||||
or undefined if nothing should be serialized. The toJSON method
|
||||
will be passed the key associated with the value, and this will be
|
||||
bound to the value
|
||||
|
||||
For example, this would serialize Dates as ISO strings.
|
||||
|
||||
Date.prototype.toJSON = function (key) {
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10
|
||||
? '0' + n
|
||||
: n;
|
||||
}
|
||||
|
||||
return this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z';
|
||||
};
|
||||
|
||||
You can provide an optional replacer method. It will be passed the
|
||||
key and value of each member, with this bound to the containing
|
||||
object. The value that is returned from your method will be
|
||||
serialized. If your method returns undefined, then the member will
|
||||
be excluded from the serialization.
|
||||
|
||||
If the replacer parameter is an array of strings, then it will be
|
||||
used to select the members to be serialized. It filters the results
|
||||
such that only members with keys listed in the replacer array are
|
||||
stringified.
|
||||
|
||||
Values that do not have JSON representations, such as undefined or
|
||||
functions, will not be serialized. Such values in objects will be
|
||||
dropped; in arrays they will be replaced with null. You can use
|
||||
a replacer function to replace those with JSON values.
|
||||
JSON.stringify(undefined) returns undefined.
|
||||
|
||||
The optional space parameter produces a stringification of the
|
||||
value that is filled with line breaks and indentation to make it
|
||||
easier to read.
|
||||
|
||||
If the space parameter is a non-empty string, then that string will
|
||||
be used for indentation. If the space parameter is a number, then
|
||||
the indentation will be that many spaces.
|
||||
|
||||
Example:
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}]);
|
||||
// text is '["e",{"pluribus":"unum"}]'
|
||||
|
||||
|
||||
text = JSON.stringify(['e', {pluribus: 'unum'}], null, '\t');
|
||||
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
|
||||
|
||||
text = JSON.stringify([new Date()], function (key, value) {
|
||||
return this[key] instanceof Date
|
||||
? 'Date(' + this[key] + ')'
|
||||
: value;
|
||||
});
|
||||
// text is '["Date(---current time---)"]'
|
||||
|
||||
|
||||
JSON.parse(text, reviver)
|
||||
This method parses a JSON text to produce an object or array.
|
||||
It can throw a SyntaxError exception.
|
||||
|
||||
The optional reviver parameter is a function that can filter and
|
||||
transform the results. It receives each of the keys and values,
|
||||
and its return value is used instead of the original value.
|
||||
If it returns what it received, then the structure is not modified.
|
||||
If it returns undefined then the member is deleted.
|
||||
|
||||
Example:
|
||||
|
||||
// Parse the text. Values that look like ISO date strings will
|
||||
// be converted to Date objects.
|
||||
|
||||
myData = JSON.parse(text, function (key, value) {
|
||||
var a;
|
||||
if (typeof value === 'string') {
|
||||
a =
|
||||
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
|
||||
if (a) {
|
||||
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
|
||||
+a[5], +a[6]));
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
myData = JSON.parse('["Date(09/09/2001)"]', function (key, value) {
|
||||
var d;
|
||||
if (typeof value === 'string' &&
|
||||
value.slice(0, 5) === 'Date(' &&
|
||||
value.slice(-1) === ')') {
|
||||
d = new Date(value.slice(5, -1));
|
||||
if (d) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
|
||||
This is a reference implementation. You are free to copy, modify, or
|
||||
redistribute.
|
||||
*/
|
||||
|
||||
/*jslint
|
||||
eval, for, this
|
||||
*/
|
||||
|
||||
/*property
|
||||
JSON, apply, call, charCodeAt, getUTCDate, getUTCFullYear, getUTCHours,
|
||||
getUTCMinutes, getUTCMonth, getUTCSeconds, hasOwnProperty, join,
|
||||
lastIndex, length, parse, prototype, push, replace, slice, stringify,
|
||||
test, toJSON, toString, valueOf
|
||||
*/
|
||||
|
||||
|
||||
// Create a JSON object only if one does not already exist. We create the
|
||||
// methods in a closure to avoid creating global variables.
|
||||
|
||||
if (typeof JSON !== 'object') {
|
||||
JSON = {};
|
||||
}
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var rx_one = /^[\],:{}\s]*$/,
|
||||
rx_two = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,
|
||||
rx_three = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,
|
||||
rx_four = /(?:^|:|,)(?:\s*\[)+/g,
|
||||
rx_escapable = /[\\\"\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
|
||||
rx_dangerous = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
|
||||
|
||||
function f(n) {
|
||||
// Format integers to have at least two digits.
|
||||
return n < 10
|
||||
? '0' + n
|
||||
: n;
|
||||
}
|
||||
|
||||
function this_value() {
|
||||
return this.valueOf();
|
||||
}
|
||||
|
||||
if (typeof Date.prototype.toJSON !== 'function') {
|
||||
|
||||
Date.prototype.toJSON = function () {
|
||||
|
||||
return isFinite(this.valueOf())
|
||||
? this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z'
|
||||
: null;
|
||||
};
|
||||
|
||||
Boolean.prototype.toJSON = this_value;
|
||||
Number.prototype.toJSON = this_value;
|
||||
String.prototype.toJSON = this_value;
|
||||
}
|
||||
|
||||
var gap,
|
||||
indent,
|
||||
meta,
|
||||
rep;
|
||||
|
||||
|
||||
function quote(string) {
|
||||
|
||||
// If the string contains no control characters, no quote characters, and no
|
||||
// backslash characters, then we can safely slap some quotes around it.
|
||||
// Otherwise we must also replace the offending characters with safe escape
|
||||
// sequences.
|
||||
|
||||
rx_escapable.lastIndex = 0;
|
||||
return rx_escapable.test(string)
|
||||
? '"' + string.replace(rx_escapable, function (a) {
|
||||
var c = meta[a];
|
||||
return typeof c === 'string'
|
||||
? c
|
||||
: '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
}) + '"'
|
||||
: '"' + string + '"';
|
||||
}
|
||||
|
||||
|
||||
function str(key, holder) {
|
||||
|
||||
// Produce a string from holder[key].
|
||||
|
||||
var i, // The loop counter.
|
||||
k, // The member key.
|
||||
v, // The member value.
|
||||
length,
|
||||
mind = gap,
|
||||
partial,
|
||||
value = holder[key];
|
||||
|
||||
// If the value has a toJSON method, call it to obtain a replacement value.
|
||||
|
||||
if (value && typeof value === 'object' &&
|
||||
typeof value.toJSON === 'function') {
|
||||
value = value.toJSON(key);
|
||||
}
|
||||
|
||||
// If we were called with a replacer function, then call the replacer to
|
||||
// obtain a replacement value.
|
||||
|
||||
if (typeof rep === 'function') {
|
||||
value = rep.call(holder, key, value);
|
||||
}
|
||||
|
||||
// What happens next depends on the value's type.
|
||||
|
||||
switch (typeof value) {
|
||||
case 'string':
|
||||
return quote(value);
|
||||
|
||||
case 'number':
|
||||
|
||||
// JSON numbers must be finite. Encode non-finite numbers as null.
|
||||
|
||||
return isFinite(value)
|
||||
? String(value)
|
||||
: 'null';
|
||||
|
||||
case 'boolean':
|
||||
case 'null':
|
||||
|
||||
// If the value is a boolean or null, convert it to a string. Note:
|
||||
// typeof null does not produce 'null'. The case is included here in
|
||||
// the remote chance that this gets fixed someday.
|
||||
|
||||
return String(value);
|
||||
|
||||
// If the type is 'object', we might be dealing with an object or an array or
|
||||
// null.
|
||||
|
||||
case 'object':
|
||||
|
||||
// Due to a specification blunder in ECMAScript, typeof null is 'object',
|
||||
// so watch out for that case.
|
||||
|
||||
if (!value) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
// Make an array to hold the partial results of stringifying this object value.
|
||||
|
||||
gap += indent;
|
||||
partial = [];
|
||||
|
||||
// Is the value an array?
|
||||
|
||||
if (Object.prototype.toString.apply(value) === '[object Array]') {
|
||||
|
||||
// The value is an array. Stringify every element. Use null as a placeholder
|
||||
// for non-JSON values.
|
||||
|
||||
length = value.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
partial[i] = str(i, value) || 'null';
|
||||
}
|
||||
|
||||
// Join all of the elements together, separated with commas, and wrap them in
|
||||
// brackets.
|
||||
|
||||
v = partial.length === 0
|
||||
? '[]'
|
||||
: gap
|
||||
? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']'
|
||||
: '[' + partial.join(',') + ']';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
|
||||
// If the replacer is an array, use it to select the members to be stringified.
|
||||
|
||||
if (rep && typeof rep === 'object') {
|
||||
length = rep.length;
|
||||
for (i = 0; i < length; i += 1) {
|
||||
if (typeof rep[i] === 'string') {
|
||||
k = rep[i];
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (
|
||||
gap
|
||||
? ': '
|
||||
: ':'
|
||||
) + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
// Otherwise, iterate through all of the keys in the object.
|
||||
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = str(k, value);
|
||||
if (v) {
|
||||
partial.push(quote(k) + (
|
||||
gap
|
||||
? ': '
|
||||
: ':'
|
||||
) + v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Join all of the member texts together, separated with commas,
|
||||
// and wrap them in braces.
|
||||
|
||||
v = partial.length === 0
|
||||
? '{}'
|
||||
: gap
|
||||
? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}'
|
||||
: '{' + partial.join(',') + '}';
|
||||
gap = mind;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
// If the JSON object does not yet have a stringify method, give it one.
|
||||
|
||||
if (typeof JSON.stringify !== 'function') {
|
||||
meta = { // table of character substitutions
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"': '\\"',
|
||||
'\\': '\\\\'
|
||||
};
|
||||
JSON.stringify = function (value, replacer, space) {
|
||||
|
||||
// The stringify method takes a value and an optional replacer, and an optional
|
||||
// space parameter, and returns a JSON text. The replacer can be a function
|
||||
// that can replace values, or an array of strings that will select the keys.
|
||||
// A default replacer method can be provided. Use of the space parameter can
|
||||
// produce text that is more easily readable.
|
||||
|
||||
var i;
|
||||
gap = '';
|
||||
indent = '';
|
||||
|
||||
// If the space parameter is a number, make an indent string containing that
|
||||
// many spaces.
|
||||
|
||||
if (typeof space === 'number') {
|
||||
for (i = 0; i < space; i += 1) {
|
||||
indent += ' ';
|
||||
}
|
||||
|
||||
// If the space parameter is a string, it will be used as the indent string.
|
||||
|
||||
} else if (typeof space === 'string') {
|
||||
indent = space;
|
||||
}
|
||||
|
||||
// If there is a replacer, it must be a function or an array.
|
||||
// Otherwise, throw an error.
|
||||
|
||||
rep = replacer;
|
||||
if (replacer && typeof replacer !== 'function' &&
|
||||
(typeof replacer !== 'object' ||
|
||||
typeof replacer.length !== 'number')) {
|
||||
throw new Error('JSON.stringify');
|
||||
}
|
||||
|
||||
// Make a fake root object containing our value under the key of ''.
|
||||
// Return the result of stringifying the value.
|
||||
|
||||
return str('', {'': value});
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// If the JSON object does not yet have a parse method, give it one.
|
||||
|
||||
if (typeof JSON.parse !== 'function') {
|
||||
JSON.parse = function (text, reviver) {
|
||||
|
||||
// The parse method takes a text and an optional reviver function, and returns
|
||||
// a JavaScript value if the text is a valid JSON text.
|
||||
|
||||
var j;
|
||||
|
||||
function walk(holder, key) {
|
||||
|
||||
// The walk method is used to recursively walk the resulting structure so
|
||||
// that modifications can be made.
|
||||
|
||||
var k, v, value = holder[key];
|
||||
if (value && typeof value === 'object') {
|
||||
for (k in value) {
|
||||
if (Object.prototype.hasOwnProperty.call(value, k)) {
|
||||
v = walk(value, k);
|
||||
if (v !== undefined) {
|
||||
value[k] = v;
|
||||
} else {
|
||||
delete value[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return reviver.call(holder, key, value);
|
||||
}
|
||||
|
||||
|
||||
// Parsing happens in four stages. In the first stage, we replace certain
|
||||
// Unicode characters with escape sequences. JavaScript handles many characters
|
||||
// incorrectly, either silently deleting them, or treating them as line endings.
|
||||
|
||||
text = String(text);
|
||||
rx_dangerous.lastIndex = 0;
|
||||
if (rx_dangerous.test(text)) {
|
||||
text = text.replace(rx_dangerous, function (a) {
|
||||
return '\\u' +
|
||||
('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
}
|
||||
|
||||
// In the second stage, we run the text against regular expressions that look
|
||||
// for non-JSON patterns. We are especially concerned with '()' and 'new'
|
||||
// because they can cause invocation, and '=' because it can cause mutation.
|
||||
// But just to be safe, we want to reject all unexpected forms.
|
||||
|
||||
// We split the second stage into 4 regexp operations in order to work around
|
||||
// crippling inefficiencies in IE's and Safari's regexp engines. First we
|
||||
// replace the JSON backslash pairs with '@' (a non-JSON character). Second, we
|
||||
// replace all simple value tokens with ']' characters. Third, we delete all
|
||||
// open brackets that follow a colon or comma or that begin the text. Finally,
|
||||
// we look to see that the remaining characters are only whitespace or ']' or
|
||||
// ',' or ':' or '{' or '}'. If that is so, then the text is safe for eval.
|
||||
|
||||
if (
|
||||
rx_one.test(
|
||||
text
|
||||
.replace(rx_two, '@')
|
||||
.replace(rx_three, ']')
|
||||
.replace(rx_four, '')
|
||||
)
|
||||
) {
|
||||
|
||||
// In the third stage we use the eval function to compile the text into a
|
||||
// JavaScript structure. The '{' operator is subject to a syntactic ambiguity
|
||||
// in JavaScript: it can begin a block or an object literal. We wrap the text
|
||||
// in parens to eliminate the ambiguity.
|
||||
|
||||
j = eval('(' + text + ')');
|
||||
|
||||
// In the optional fourth stage, we recursively walk the new structure, passing
|
||||
// each name/value pair to a reviver function for possible transformation.
|
||||
|
||||
return typeof reviver === 'function'
|
||||
? walk({'': j}, '')
|
||||
: j;
|
||||
}
|
||||
|
||||
// If the text is not JSON parseable, then a SyntaxError is thrown.
|
||||
|
||||
throw new SyntaxError('JSON.parse');
|
||||
};
|
||||
}
|
||||
}());
|
||||
10
js/jszip-utils.min.js
vendored
Normal file
10
js/jszip-utils.min.js
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
/*!
|
||||
|
||||
JSZipUtils - A collection of cross-browser utilities to go along with JSZip.
|
||||
<http://stuk.github.io/jszip-utils>
|
||||
|
||||
(c) 2014 Stuart Knightley, David Duponchel
|
||||
Dual licenced under the MIT license or GPLv3. See https://raw.github.com/Stuk/jszip-utils/master/LICENSE.markdown.
|
||||
|
||||
*/
|
||||
!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.JSZipUtils=a():"undefined"!=typeof global?global.JSZipUtils=a():"undefined"!=typeof self&&(self.JSZipUtils=a())}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(){try{return new window.XMLHttpRequest}catch(a){}}function d(){try{return new window.ActiveXObject("Microsoft.XMLHTTP")}catch(a){}}var e={};e._getBinaryFromXHR=function(a){return a.response||a.responseText};var f=window.ActiveXObject?function(){return c()||d()}:c;e.getBinaryContent=function(a,b){try{var c=f();c.open("GET",a,!0),"responseType"in c&&(c.responseType="arraybuffer"),c.overrideMimeType&&c.overrideMimeType("text/plain; charset=x-user-defined"),c.onreadystatechange=function(){var d,f;if(4===c.readyState)if(200===c.status||0===c.status){d=null,f=null;try{d=e._getBinaryFromXHR(c)}catch(g){f=new Error(g)}b(f,d)}else b(new Error("Ajax error for "+a+" : "+this.status+" "+this.statusText),null)},c.send()}catch(d){b(new Error(d),null)}},b.exports=e},{}]},{},[1])(1)});
|
||||
15
js/jszip.min.js
vendored
Normal file
15
js/jszip.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
5
js/leaflet.js
Normal file
5
js/leaflet.js
Normal file
File diff suppressed because one or more lines are too long
4
js/osrm.js
Normal file
4
js/osrm.js
Normal file
File diff suppressed because one or more lines are too long
1
js/sweetalert2.min.js
vendored
Normal file
1
js/sweetalert2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user