diff --git a/.gitignore b/.gitignore
index 67faecc..221a135 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,7 +12,6 @@ config/local.json
# Ignore natural lib
public/libs/natural/
-bower_components
.wav
audio_stimuli
diff --git a/bower_components/fielddb-glosser/.bower.json b/bower_components/fielddb-glosser/.bower.json
new file mode 100644
index 0000000..30e682b
--- /dev/null
+++ b/bower_components/fielddb-glosser/.bower.json
@@ -0,0 +1,39 @@
+{
+ "name": "fielddb-glosser",
+ "version": "3.12.15",
+ "authors": [
+ "info@fielddb.org"
+ ],
+ "description": "A semi-automatic IGT morpheme segmenter and glosser",
+ "main": "fielddb-glosser.js",
+ "keywords": [
+ "igt",
+ "leipzig",
+ "conventions",
+ "linguistics"
+ ],
+ "license": "Apache 2.0",
+ "homepage": "https://github.com/OpenSourceFieldlinguistics/FieldDB/issues/milestones?state=closed",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "client",
+ "test",
+ "tests",
+ "lib",
+ "dist",
+ "Gruntfile.js",
+ "package.json"
+ ],
+ "dependencies": {},
+ "_release": "3.12.15",
+ "_resolution": {
+ "type": "version",
+ "tag": "v3.12.15",
+ "commit": "1742d71f7c5366041fe78d1eaaba11916ad68781"
+ },
+ "_source": "https://github.com/OpenSourceFieldlinguistics/FieldDBGlosser.git",
+ "_target": "^3.12.15",
+ "_originalSource": "fielddb-glosser"
+}
\ No newline at end of file
diff --git a/bower_components/fielddb-glosser/LICENSE b/bower_components/fielddb-glosser/LICENSE
new file mode 100644
index 0000000..e06d208
--- /dev/null
+++ b/bower_components/fielddb-glosser/LICENSE
@@ -0,0 +1,202 @@
+Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "{}"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright {yyyy} {name of copyright owner}
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
diff --git a/bower_components/fielddb-glosser/README.md b/bower_components/fielddb-glosser/README.md
new file mode 100644
index 0000000..9de97b9
--- /dev/null
+++ b/bower_components/fielddb-glosser/README.md
@@ -0,0 +1,123 @@
+# FieldDBGlosser
+
+A semi-automatic IGT morpheme segmenter and glosser
+
+## Getting Started
+### On the server
+Install the module with: `npm install fielddb-glosser --save`
+
+```javascript
+var Glosser = require('FieldDBGlosser').Glosser;
+var glosser = new Glosser("yourdbidentifier");
+```
+
+### In the browser
+
+Install the module with: `bower install fielddb-glosser --save`
+
+Or, download the [production version][min] or the [development version][max].
+
+[min]: https://raw.github.com/OpenSourceFieldlinguistics/FieldDBGlosser/master/fielddb-glosser.min.js
+[max]: https://raw.github.com/OpenSourceFieldlinguistics/FieldDBGlosser/master/fielddb-glosser.js
+
+In your web page:
+
+```html
+
+
+```
+
+
+## Examples
+
+In the examples below, all fields are optional but the more information provided, the more context the glosser can take into account when returning guesses.
+
+
+To guess an utterance (citation line) from morphemes:
+
+```javascript
+glosser.guessUtteranceFromMorphemes({
+ utterance: "",
+ morphemes: "Kicha-nay-wa-n punqo-ta",
+ allomorphs: "",
+ gloss: "open-DES-1OM-3SG door-ACC",
+ translation: "I feel like opening the door."
+});
+```
+
+
+To guess a morpheme segmention from an utterance/orthography line:
+
+```javascript
+glosser.guessMorphemesFromUtterance({
+ utterance: "Kichanaywan punqota",
+ morphemes: "",
+ allomorphs: "",
+ gloss: "",
+ translation: "I feel like opening the door."
+});
+```
+
+
+To guess glosses from a morphemes/allomorphs line:
+
+```javascript
+glosser.guessGlossFromMorphemes({
+ utterance: "Kichanaywan punqota",
+ morphemes: "Kicha-nay-wa-n punqo-ta",
+ allomorphs: "",
+ gloss: "",
+ translation: "I feel like opening the door."
+});
+```
+
+To show a D3.js force directed graph of morphemes in the corpus:
+
+CSS:
+
+```css
+#corpus-precedence-rules-visualization {
+ background-color: #333;
+ text-align: center;
+}
+
+```
+
+Javascript:
+
+```javascript
+var doubleClickMorpheme = function(dataPoint){
+ console.log("Someone double clicked me ", dataPoint);
+};
+
+try {
+ glosser.visualizeMorphemesAsForceDirectedGraph(null, document.getElementById("corpus-precedence-rules-visualization"), "https://example.com/yourdbidentifier", doubleClickMorpheme);
+} catch(e) {
+ console.warn("There was a problem loading your corpus visualization.");
+}
+```
+
+
+### Sample glosser visualization client code
+
+For source code see [samples/vanilla](https://github.com/OpenSourceFieldlinguistics/FieldDBGlosser/tree/master/samples/vanilla)
+
+
+![lexicon_browser_dashboard](https://f.cloud.github.com/assets/196199/2366164/8555cb70-a6f3-11e3-93ec-140fcaad2294.png)
+
+
+## Contributing
+In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
+
+_Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!_
+
+## Release History
+
+* v1.82 Added more functions to the glosser so the client side apps dont have to invent the user experience. Previously the prototype app never overwrote a gloss or morpheme segemetnation if the user had already modified it. But the spread sheet app deleted the users chagnes which was very frustrating. By putting the functionailty in the glosser itself and moving it into a bower component there is a higher chance that this wont happen...
+* v1.16 Basic glosser which uses a map reduce of precedence rules to build a morphemes template, and D3.js visualization of morphemes
+
+## License
+Copyright (c) 2013 FieldDB Contributors
+Licensed under the Apache 2.0 license.
diff --git a/bower_components/fielddb-glosser/bower.json b/bower_components/fielddb-glosser/bower.json
new file mode 100644
index 0000000..ec4779a
--- /dev/null
+++ b/bower_components/fielddb-glosser/bower.json
@@ -0,0 +1,31 @@
+{
+ "name": "fielddb-glosser",
+ "version": "3.12.15",
+ "authors": [
+ "info@fielddb.org"
+ ],
+ "description": "A semi-automatic IGT morpheme segmenter and glosser",
+ "main": "fielddb-glosser.js",
+ "keywords": [
+ "igt",
+ "leipzig",
+ "conventions",
+ "linguistics"
+ ],
+ "license": "Apache 2.0",
+ "homepage": "https://github.com/OpenSourceFieldlinguistics/FieldDB/issues/milestones?state=closed",
+ "ignore": [
+ "**/.*",
+ "node_modules",
+ "bower_components",
+ "client",
+ "test",
+ "tests",
+ "lib",
+ "dist",
+ "Gruntfile.js",
+ "package.json"
+ ],
+ "dependencies": {
+ }
+}
diff --git a/bower_components/fielddb-glosser/fielddb-glosser.js b/bower_components/fielddb-glosser/fielddb-glosser.js
new file mode 100644
index 0000000..4b531f2
--- /dev/null
+++ b/bower_components/fielddb-glosser/fielddb-glosser.js
@@ -0,0 +1,41193 @@
+/*! fielddb-glosser - v2.2.0 - 2017-03-12
+* https://github.com/OpenSourceFieldlinguistics/FieldDB/issues/milestones?state=closed
+* Copyright (c) 2017 FieldDB Contributors; Licensed Apache 2.0 */
+
+(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o -1) {
+ return;
+ } else {
+ this.warnMessage = this.warnMessage + message;
+ }
+ console.warn("CORS-WARN: " + message);
+ if (b) {
+ console.log(b);
+ }
+ if (c) {
+ console.log(c);
+ }
+ // throw message;
+ },
+ bug: function(message) {
+ console.warn("CORS-BUG: " + message);
+ },
+ render: function() {
+ this.debug("Render requested for CORS, but it doesnt know how to render itself.");
+ },
+ clearCookies: function(hostname) {
+ this.warn("TODO clear cookies requested for " + hostname);
+ },
+ preprocess: function(options) {
+ this.debug("\n\n\npreprocess " + options.url + " " + options.complete);
+ options.complete = false;
+ options.percentComplete = 0;
+
+ // this.debugMode = true;
+ if (!options.method) {
+ options.method = options.type || "GET";
+ }
+ if (!options.url) {
+ this.bug("There was an error. Please report this.");
+ }
+ if (!options.data) {
+ options.data = "";
+ }
+ if (options.method === "GET" && options.data) {
+ options.dataToSend = JSON.stringify(options.data).replace(/,/g, "&").replace(/:/g, "=").replace(/"/g, "").replace(/[}{]/g, "");
+ options.url = options.url + "?" + options.dataToSend;
+ }
+ },
+ handleResponse: function(options, deferred) {
+ if (options.complete) {
+ // options = null;
+ return;
+ }
+ this.debug(options.url + " " + options.complete + ": handleResponse " + options.url);
+
+ var err,
+ status,
+ attr;
+
+ // this.debug("handleResponse", options);
+
+ var response = options.xhr.responseJSON || options.xhr.responseText || options.xhr.response;
+ // this.debug("Response from CORS request to " + options.url + ": " + response);
+
+ try {
+ response = JSON.parse(response);
+ } catch (e) {}
+ if (!response) {
+ response = {};
+ }
+ if (response.reason) {
+ response.message = response.reason;
+ delete response.reason;
+ }
+ status = response.status || options.xhr.status;
+
+ if (status < 400) {
+ this.debug("done " + options.url + " " + options.complete + "\n\n\n");
+ options.complete = true;
+ options.percentComplete = 100;
+ deferred.resolve(response);
+ return;
+ }
+
+ if (typeof response !== "object") {
+ response = {
+ message: response
+ };
+ }
+
+ err = new Error(response.userFriendlyErrors ? response.userFriendlyErrors[0] : response.message);
+ for (attr in response) {
+ if (response.hasOwnProperty(attr)) {
+ err[attr] = response[attr];
+ }
+ }
+ err.status = status;
+
+ this.handleError(options, err, deferred);
+ },
+ handleError: function(options, err, deferred) {
+ if (options.complete) {
+ // options = null;
+ return;
+ }
+ this.debug(options.url + " " + options.complete + ": handleError " + options.url);
+ var response;
+
+ // this.warn(options.url + " " + options.complete + ": was unsuccesful ");
+ this.debug(err.stack);
+
+ response = {
+ userFriendlyErrors: err.userFriendlyErrors || [err.message || "There was an error contacting URL from " + window.location.href + " the app will not function normally. Please report this."],
+ status: err.status || 610,
+ error: err
+ };
+
+ if (response.userFriendlyErrors[0] === "missing") {
+ response.userFriendlyErrors.unshift("The server replied that " + options.url + " is missing, please report this.");
+ } else if (response.userFriendlyErrors[0] === "no_db_file") {
+ response.userFriendlyErrors.unshift("That database doesn't exist. Are you sure this is the database you wanted to open: " + options.url);
+ }
+
+ if (response.status === 401) {
+ if (CORS.application && CORS.application.authentication && CORS.application.authentication.dispatchEvent) {
+ CORS.application.authentication.dispatchEvent("unauthorized");
+ }
+ }
+
+ // Tell the user if they are offline
+ if (response.status >= 500) {
+ try {
+ if (window && window.navigator && !window.navigator.onLine) {
+ response.userFriendlyErrors.unshift(CORS.OFFLINE.MESSAGE);
+ response.status = CORS.OFFLINE.CODE;
+ } else if (err && err.srcElement && err.srcElement.status !== undefined) {
+ response.status = err.srcElement.status;
+ }
+ } catch (e) {}
+ }
+
+ response.userFriendlyErrors[0] = response.userFriendlyErrors[0].replace("URL", options.url);
+ this.bug(response.userFriendlyErrors[0]);
+
+ response.details = options;
+ if (response.details && response.details.xhr) {
+ this.debug(options.url + " " + options.complete + ": cleaning up ", options.url);
+ options.status = options.status || options.xhr.status;
+ delete options.xhr;
+ }
+ this.debug(options.url + " " + options.complete + ": done " + options.url + "\n\n\n");
+ options.complete = true;
+ deferred.reject(response);
+ },
+ setHeader: function(xhr, key, value) {
+ xhr.setRequestHeader(key, value);
+ },
+ ontimeout: function(options, evt, deferred) {
+ var err = new Error(this.CLIENT_TIMEOUT.MESSAGE);
+ this.debug(options.url + " " + options.complete + ": timed out.");
+
+ err.status = this.CLIENT_TIMEOUT.CODE;
+ this.handleError(options, err, deferred);
+ },
+ onabort: function(options, evt, deferred) {
+ var err = new Error(this.CONNECTION_ABORTED.MESSAGE);
+ this.debug(options.url + " " + options.complete + ": was aborted.");
+
+ err.status = this.CONNECTION_ABORTED.CODE;
+ this.handleError(options, err, deferred);
+ },
+ onerror: function(options, evt, deferred) {
+ var err = new Error(this.CONNECTION_ERRORED.MESSAGE);
+ this.debug(options.url + " " + options.complete + ": errored.");
+
+ if (options.xhr && options.xhr.status) {
+ err.status = options.xhr.status;
+ } else if (options.status) {
+ err.status = options.status;
+ } else {
+ err.status = this.CONNECTION_ERRORED.CODE;
+ }
+
+ this.handleError(options, err, deferred);
+ },
+ onload: function(options, evt, deferred) {
+ this.handleResponse(options, deferred);
+ },
+ onprogress: function(options, evt) {
+ this.debug(options.url + " " + options.complete + ": onprogress " + options.url + " " + options.complete, evt);
+ if (evt.lengthComputable) {
+ var percentComplete = (evt.loaded / evt.total) * 100;
+ this.debug(options.url + " " + options.complete + ": percentComplete " + options.url, percentComplete);
+ console.log("Percent complete " + options.url + " : " + percentComplete);
+ if (!options.complete) {
+ options.percentComplete = percentComplete;
+ }
+ }
+ if (options.onprogress && typeof options.onprogress === "function") {
+ options.onprogress(evt);
+ }
+ }
+};
+
+/*
+ * Helper function which handles IE
+ */
+CORS.buildXhr = function(options) {
+ var xhr;
+ try {
+ xhr = new XMLHttpRequest();
+ } catch (e) {
+ this.warn("XMLHttpRequest is not defined, nothing will happen.", e);
+ return null;
+ }
+ if ("withCredentials" in xhr) {
+ // XHR for Chrome/Firefox/Opera/Safari.
+ try {
+ xhr.open(options.method, options.url, true);
+ } catch (exception) {
+ console.log(exception);
+ this.error = exception.message;
+ return null;
+ }
+ // https://mathiasbynens.be/notes/xhr-responsetype-json
+ // xhr.responseType = "json";
+ } else if (typeof XDomainRequest !== "undefined") {
+ // XDomainRequest for IE.
+ xhr = new XDomainRequest();
+ xhr.open(options.method, options.url);
+ } else {
+ // CORS not supported.
+ xhr = null;
+ }
+
+ if (!xhr) {
+ return;
+ }
+
+ this.setHeader(xhr, "Content-type", "application/json");
+ if (options.withCredentials !== false) {
+ xhr.withCredentials = true;
+ // Dont use CORS if its a file
+ if (options.url.lastIndexOf(".") > options.url.lastIndexOf("/") && options.url.substring(options.url.lastIndexOf(".")).indexOf("htm") !== 0) {
+ xhr.withCredentials = false;
+ }
+ }
+
+ if (options.timeout || this.timeout) {
+ xhr.timeout = options.timeout || this.timeout;
+ }
+
+ return xhr;
+};
+
+/*
+ * Functions for well formed CORS requests
+ */
+CORS.makeCORSRequest = function(options) {
+ var self = this,
+ deferred = Q.defer(),
+ data,
+ xhr;
+
+ if (!options || !options.url) {
+ Q.nextTick(function() {
+ deferred.reject({
+ status: 400,
+ details: options,
+ userFriendlyErrors: ["Url must be defined"]
+ });
+ });
+ return deferred.promise;
+ }
+
+ this.preprocess(options, deferred);
+
+ //forcing production server
+ options.url = options.url.replace("corpusdev", "corpus");
+
+ xhr = this.buildXhr(options);
+ if (!xhr) {
+ var message = this.error || "CORS not supported, your device will be unable to contact " + options.url;
+ this.bug(message);
+ Q.nextTick(function() {
+ deferred.reject({
+ status: 620,
+ details: options,
+ userFriendlyErrors: [message]
+ });
+ });
+ return deferred.promise;
+ }
+
+ // If it contains files, make it into a mulitpart upload
+ if (options && options.data && options.data.files) {
+ console.log("converting to formdata ", options.data);
+
+ data = new FormData();
+ for (var part in options.data) {
+ if (options.data.hasOwnProperty(part)) {
+ data.append(part, options.data[part]);
+ }
+ }
+ data = data;
+ this.setHeader(xhr, "Content-Type", "multipart/form-data");
+ } else {
+ if (options.data) {
+ data = JSON.stringify(options.data);
+ }
+ }
+
+ xhr.onprogress = function(evt) {
+ self.onprogress(options, evt, deferred);
+ };
+ xhr.onload = function(evt) {
+ self.onload(options, evt, deferred);
+ };
+ xhr.onerror = function(evt) {
+ self.onerror(options, evt, deferred);
+ };
+ xhr.onabort = function(evt) {
+ self.onabort(options, evt, deferred);
+ };
+ xhr.ontimeout = function(evt) {
+ self.ontimeout(options, evt, deferred);
+ };
+
+ options.xhr = xhr;
+ try {
+ if (data) {
+ self.debug(options.url + " " + options.complete + ": sending ", data);
+ xhr.send(data);
+ } else {
+ xhr.send();
+ }
+ } catch (e) {
+ self.warn("Caught an exception when calling send on xhr", e);
+ e.details = options;
+ deferred.reject(e);
+ }
+
+ return deferred.promise;
+};
+
+try {
+ exports.CORS = CORS;
+} catch (e) {}
+
+try {
+ if (!document) {}
+ // console.log(document);
+} catch (e) {
+ var CORSNode = require("./CORSNode").CORS;
+ console.warn("REST requests: enabled");
+ exports.CORS = CORSNode || CORS;
+}
+
+},{"./CORSNode":2,"q":3}],2:[function(require,module,exports){
+var Q = require("q");
+var http = require("http");
+var https = require("https");
+var url = require("url");
+
+var CORS = require("./CORS").CORS;
+
+/*
+ * Helper function which handles IE
+ */
+CORS.buildXhr = function() {};
+CORS.setHeader = function(xhr, key, value) {
+ xhr.setHeader(key, value);
+};
+
+var COOKIE_JAR = {};
+
+CORS.clearCookies = function(hostname) {
+ if (!hostname) {
+ return;
+ }
+
+ this.warn("clearing cookies on " + hostname);
+ delete COOKIE_JAR[hostname];
+};
+/*
+ * Functions for well formed CORS requests
+ */
+CORS.makeCORSRequest = function(options) {
+ var self = this,
+ deferred = Q.defer(),
+ data = "",
+ xhr;
+
+ if (!options || !options.url) {
+ Q.nextTick(function() {
+ deferred.reject({
+ status: 400,
+ details: options,
+ userFriendlyErrors: ["Url must be defined"]
+ });
+ });
+ return deferred.promise;
+ }
+
+ this.preprocess(options, deferred);
+
+ //forcing production server
+ // options.url = options.url.replace("corpusdev", "corpus");
+ var urlObject = url.parse(options.url);
+
+ var httpOrHttps = http;
+ if (urlObject.protocol === "https:") {
+ httpOrHttps = https;
+ urlObject.port = urlObject.port || 443;
+ }
+ delete urlObject.protocol;
+
+ urlObject.method = options.method || "GET";
+ xhr = httpOrHttps.request(urlObject, function(res) {
+ var output = "";
+ res.setEncoding("utf8");
+
+ self.debug(options.url + " " + options.complete + ": requesting ");
+
+ res.on("data", function(chunk) {
+ output += chunk;
+ self.debug(options.url + " " + options.complete + ": ondata ");
+ self.onprogress.apply(self, [options, {
+ lengthComputable: true,
+ loaded: output.length - chunk.length,
+ total: output.length
+ }, deferred]);
+ });
+
+ res.on("end", function() {
+ xhr.responseText = output;
+ xhr.status = res.statusCode;
+
+ // Save cookies
+ if (res.headers && res.headers["set-cookie"]) {
+ COOKIE_JAR[urlObject.host] = res.headers["set-cookie"];
+ self.debug(options.url + " " + options.complete + ": cookies", COOKIE_JAR);
+ }
+
+ // Remove cookies
+ self.debug(options.url + " " + options.complete + ": response headers " + options.url, res.headers);
+ if (options.method === "DELETE" && urlObject.path === "/_session") {
+ self.clearCookies(urlObject.host);
+ }
+
+ // Final progress event
+ self.onprogress.apply(self, [options, {
+ lengthComputable: true,
+ loaded: output.length,
+ total: output.length
+ }, deferred]);
+
+ self.onload.apply(self, [options, {}, deferred]);
+ });
+ });
+
+ // Include cookies
+ if (COOKIE_JAR[urlObject.host]) {
+ xhr.setHeader("Cookie", COOKIE_JAR[urlObject.host].join(";"));
+ }
+ self.debug(options.url + " " + options.complete + ": request cookies " + xhr.getHeader("cookie"));
+
+ xhr.setHeader("Content-type", "application/json");
+
+ xhr.setTimeout(options.timeout || this.timeout);
+
+ // If it contains files, make it into a mulitpart upload
+ if (options && options.data && options.data.files) {
+ // console.log("converting to formdata ", options.data);
+
+ // data = new FormData();
+ // for (var part in options.data) {
+ // if (options.data.hasOwnProperty(part)) {
+ // data.append(part, options.data[part]);
+ // }
+ // }
+ // data = data;
+ // xhr.setHeader("Content-Type", "multipart/form-data");
+ } else {
+ if (options.data) {
+ data = JSON.stringify(options.data);
+ }
+ }
+
+ xhr.on("error", function(err) {
+ self.onerror.apply(self, [options, err, deferred]);
+ });
+
+ xhr.on("timeout", function(err) {
+ self.ontimeout.apply(self, [options, err, deferred]);
+ xhr.abort();
+ });
+
+ options.xhr = xhr;
+ try {
+ if (data) {
+ self.debug(options.url + " " + options.complete + ": sending ", data);
+ xhr.write(data);
+ } else {
+ xhr.write("");
+ }
+ xhr.end();
+ } catch (e) {
+ self.warn("Caught an exception when calling send on xhr", e.stack);
+ e.details = options;
+ deferred.reject(e);
+ }
+
+ return deferred.promise;
+};
+
+if (exports) {
+ exports.CORS = CORS;
+}
+
+},{"./CORS":1,"http":94,"https":74,"q":3,"url":101}],3:[function(require,module,exports){
+(function (process){
+// vim:ts=4:sts=4:sw=4:
+/*!
+ *
+ * Copyright 2009-2012 Kris Kowal under the terms of the MIT
+ * license found at http://github.com/kriskowal/q/raw/master/LICENSE
+ *
+ * With parts by Tyler Close
+ * Copyright 2007-2009 Tyler Close under the terms of the MIT X license found
+ * at http://www.opensource.org/licenses/mit-license.html
+ * Forked at ref_send.js version: 2009-05-11
+ *
+ * With parts by Mark Miller
+ * Copyright (C) 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+(function (definition) {
+ "use strict";
+
+ // This file will function properly as a
+
+
+