Commit c1a8aff1 authored by Tristan Cavelier's avatar Tristan Cavelier

html5.js not used by Firefox and Chrome anymore

parent f544ed16
/*jslint indent: 2, nomen: true, sloppy: true */ /*jslint indent: 2, nomen: true, sloppy: true */
/*global setTimeout */ /*global setTimeout, window, navigator */
//////////////////////////////////////////////////////////// (function () {
// https://github.com/TristanCavelier/notesntools/blob/\ ////////////////////////////////////////////////////////////
// master/javascript/stringToUtf8Bytes.js // https://github.com/TristanCavelier/notesntools/blob/\
/** // master/javascript/stringToUtf8Bytes.js
/**
* Converts a string into a Utf8 raw string (0 <= char <= 255) * Converts a string into a Utf8 raw string (0 <= char <= 255)
* *
* @param {String} input String to convert * @param {String} input String to convert
* @return {String} Utf8 byte string * @return {String} Utf8 byte string
*/ */
function stringToUtf8ByteString(input) { function stringToUtf8ByteString(input) {
/*jslint bitwise: true */ /*jslint bitwise: true */
var output = "", i, x, y, l = input.length; var output = "", i, x, y, l = input.length;
...@@ -47,15 +48,15 @@ function stringToUtf8ByteString(input) { ...@@ -47,15 +48,15 @@ function stringToUtf8ByteString(input) {
} }
} }
return output; return output;
} }
/** /**
* Converts a Utf8 raw string (0 <= char <= 255) into a real string * Converts a Utf8 raw string (0 <= char <= 255) into a real string
* *
* @param {String} input Utf8 encoded Bytes to convert * @param {String} input Utf8 encoded Bytes to convert
* @return {String} Real string * @return {String} Real string
*/ */
function utf8ByteStringToString(input) { function utf8ByteStringToString(input) {
/*jslint bitwise: true */ /*jslint bitwise: true */
var output = "", i, x, l = input.length; var output = "", i, x, l = input.length;
...@@ -101,15 +102,11 @@ function utf8ByteStringToString(input) { ...@@ -101,15 +102,11 @@ function utf8ByteStringToString(input) {
} }
} }
return output; return output;
} }
////////////////////////////////////////////////////////////
function ord(chr) { ////////////////////////////////////////////////////////////
return chr.charCodeAt(0);
}
function Blob(parts, properties) { function Blob(parts, properties) {
var i, part, raw = '', type; var i, part, raw = '', type;
type = (properties && properties.type && properties.type.toString()) || ""; type = (properties && properties.type && properties.type.toString()) || "";
if (!Array.isArray(parts)) { if (!Array.isArray(parts)) {
...@@ -148,10 +145,10 @@ function Blob(parts, properties) { ...@@ -148,10 +145,10 @@ function Blob(parts, properties) {
"writable": false, "writable": false,
"value": type "value": type
}); });
} }
Blob.prototype.type = ""; Blob.prototype.type = "";
Blob.prototype.size = 0; Blob.prototype.size = 0;
Blob.prototype.slice = function (start, end, contentType) { Blob.prototype.slice = function (start, end, contentType) {
var data, blob, i, fake_data = ''; var data, blob, i, fake_data = '';
data = this._data.slice(start, end); data = this._data.slice(start, end);
for (i = 0; i < data.length; i += 1) { for (i = 0; i < data.length; i += 1) {
...@@ -160,16 +157,16 @@ Blob.prototype.slice = function (start, end, contentType) { ...@@ -160,16 +157,16 @@ Blob.prototype.slice = function (start, end, contentType) {
blob = new Blob([fake_data], {"type": contentType}); blob = new Blob([fake_data], {"type": contentType});
blob._data = data; blob._data = data;
return blob; return blob;
}; };
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\ // https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js // master/javascript/emitter.js
function FileReader() { function FileReader() {
return; return;
} }
FileReader.prototype.addEventListener = function (eventName, callback) { FileReader.prototype.addEventListener = function (eventName, callback) {
// Check parameters // Check parameters
if (typeof callback !== "function") { if (typeof callback !== "function") {
return; return;
...@@ -179,9 +176,9 @@ FileReader.prototype.addEventListener = function (eventName, callback) { ...@@ -179,9 +176,9 @@ FileReader.prototype.addEventListener = function (eventName, callback) {
this._events = this._events || {}; this._events = this._events || {};
this._events[eventName] = this._events[eventName] || []; this._events[eventName] = this._events[eventName] || [];
this._events[eventName].push(callback); this._events[eventName].push(callback);
}; };
function dispatchEvent(fr, eventName) { function dispatchEvent(fr, eventName) {
var args, i, funs = fr._events && fr._events[eventName] && var args, i, funs = fr._events && fr._events[eventName] &&
fr._events[eventName].slice(); fr._events[eventName].slice();
...@@ -206,9 +203,9 @@ function dispatchEvent(fr, eventName) { ...@@ -206,9 +203,9 @@ function dispatchEvent(fr, eventName) {
funs[i].apply(fr, args); funs[i].apply(fr, args);
} }
} }
} }
FileReader.prototype.removeEventListener = function (eventName, callback) { FileReader.prototype.removeEventListener = function (eventName, callback) {
var i, funs = this._events && this._events[eventName]; var i, funs = this._events && this._events[eventName];
if (funs) { if (funs) {
...@@ -219,14 +216,14 @@ FileReader.prototype.removeEventListener = function (eventName, callback) { ...@@ -219,14 +216,14 @@ FileReader.prototype.removeEventListener = function (eventName, callback) {
} }
} }
} }
}; };
FileReader.prototype.abort = function () { FileReader.prototype.abort = function () {
this.dispatchEvent("abort", {"target": this}); this.dispatchEvent("abort", {"target": this});
delete this._events; delete this._events;
}; };
FileReader.prototype.readAsBinaryString = function (blob) { FileReader.prototype.readAsBinaryString = function (blob) {
var that = this; var that = this;
setTimeout(function () { setTimeout(function () {
dispatchEvent(that, "progress", { dispatchEvent(that, "progress", {
...@@ -241,9 +238,9 @@ FileReader.prototype.readAsBinaryString = function (blob) { ...@@ -241,9 +238,9 @@ FileReader.prototype.readAsBinaryString = function (blob) {
"target": that "target": that
}); });
}); });
}; };
FileReader.prototype.readAsText = function (blob) { FileReader.prototype.readAsText = function (blob) {
var that = this; var that = this;
setTimeout(function () { setTimeout(function () {
dispatchEvent(that, "progress", { dispatchEvent(that, "progress", {
...@@ -258,6 +255,14 @@ FileReader.prototype.readAsText = function (blob) { ...@@ -258,6 +255,14 @@ FileReader.prototype.readAsText = function (blob) {
"target": that "target": that
}); });
}); });
}; };
////////////////////////////////////////////////////////////
if (typeof Blob !== 'function' || typeof FileReader !== 'function' ||
(/\bPhantomJS\b/i).test(navigator.userAgent)) {
window.Blob = Blob;
window.FileReader = FileReader;
}
//////////////////////////////////////////////////////////// }());
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment