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 */
/*global setTimeout */
/*global setTimeout, window, navigator */
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/stringToUtf8Bytes.js
/**
(function () {
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/stringToUtf8Bytes.js
/**
* Converts a string into a Utf8 raw string (0 <= char <= 255)
*
* @param {String} input String to convert
* @return {String} Utf8 byte string
*/
function stringToUtf8ByteString(input) {
function stringToUtf8ByteString(input) {
/*jslint bitwise: true */
var output = "", i, x, y, l = input.length;
......@@ -47,15 +48,15 @@ function stringToUtf8ByteString(input) {
}
}
return output;
}
}
/**
/**
* Converts a Utf8 raw string (0 <= char <= 255) into a real string
*
* @param {String} input Utf8 encoded Bytes to convert
* @return {String} Real string
*/
function utf8ByteStringToString(input) {
function utf8ByteStringToString(input) {
/*jslint bitwise: true */
var output = "", i, x, l = input.length;
......@@ -101,15 +102,11 @@ function utf8ByteStringToString(input) {
}
}
return output;
}
////////////////////////////////////////////////////////////
}
function ord(chr) {
return chr.charCodeAt(0);
}
////////////////////////////////////////////////////////////
function Blob(parts, properties) {
function Blob(parts, properties) {
var i, part, raw = '', type;
type = (properties && properties.type && properties.type.toString()) || "";
if (!Array.isArray(parts)) {
......@@ -148,10 +145,10 @@ function Blob(parts, properties) {
"writable": false,
"value": type
});
}
Blob.prototype.type = "";
Blob.prototype.size = 0;
Blob.prototype.slice = function (start, end, contentType) {
}
Blob.prototype.type = "";
Blob.prototype.size = 0;
Blob.prototype.slice = function (start, end, contentType) {
var data, blob, i, fake_data = '';
data = this._data.slice(start, end);
for (i = 0; i < data.length; i += 1) {
......@@ -160,16 +157,16 @@ Blob.prototype.slice = function (start, end, contentType) {
blob = new Blob([fake_data], {"type": contentType});
blob._data = data;
return blob;
};
};
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js
function FileReader() {
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js
function FileReader() {
return;
}
}
FileReader.prototype.addEventListener = function (eventName, callback) {
FileReader.prototype.addEventListener = function (eventName, callback) {
// Check parameters
if (typeof callback !== "function") {
return;
......@@ -179,9 +176,9 @@ FileReader.prototype.addEventListener = function (eventName, callback) {
this._events = this._events || {};
this._events[eventName] = this._events[eventName] || [];
this._events[eventName].push(callback);
};
};
function dispatchEvent(fr, eventName) {
function dispatchEvent(fr, eventName) {
var args, i, funs = fr._events && fr._events[eventName] &&
fr._events[eventName].slice();
......@@ -206,9 +203,9 @@ function dispatchEvent(fr, eventName) {
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];
if (funs) {
......@@ -219,14 +216,14 @@ FileReader.prototype.removeEventListener = function (eventName, callback) {
}
}
}
};
};
FileReader.prototype.abort = function () {
FileReader.prototype.abort = function () {
this.dispatchEvent("abort", {"target": this});
delete this._events;
};
};
FileReader.prototype.readAsBinaryString = function (blob) {
FileReader.prototype.readAsBinaryString = function (blob) {
var that = this;
setTimeout(function () {
dispatchEvent(that, "progress", {
......@@ -241,9 +238,9 @@ FileReader.prototype.readAsBinaryString = function (blob) {
"target": that
});
});
};
};
FileReader.prototype.readAsText = function (blob) {
FileReader.prototype.readAsText = function (blob) {
var that = this;
setTimeout(function () {
dispatchEvent(that, "progress", {
......@@ -258,6 +255,14 @@ FileReader.prototype.readAsText = function (blob) {
"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