Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
jio
Commits
c1a8aff1
Commit
c1a8aff1
authored
Dec 05, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
html5.js not used by Firefox and Chrome anymore
parent
f544ed16
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
228 additions
and
223 deletions
+228
-223
test/html5.js
test/html5.js
+228
-223
No files found.
test/html5.js
View file @
c1a8aff1
/*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
*
* @return {String} Utf8 byte string
* @param {String} input String to convert
*/
* @return {String} Utf8 byte string
function
stringToUtf8ByteString
(
input
)
{
*/
/*jslint bitwise: true */
function
stringToUtf8ByteString
(
input
)
{
var
output
=
""
,
i
,
x
,
y
,
l
=
input
.
length
;
/*jslint bitwise: true */
var
output
=
""
,
i
,
x
,
y
,
l
=
input
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
/* Decode utf-16 surrogate pairs */
/* Decode utf-16 surrogate pairs */
x
=
input
.
charCodeAt
(
i
);
x
=
input
.
charCodeAt
(
i
);
y
=
i
+
1
<
l
?
input
.
charCodeAt
(
i
+
1
)
:
0
;
y
=
i
+
1
<
l
?
input
.
charCodeAt
(
i
+
1
)
:
0
;
if
(
0xD800
<=
x
&&
x
<=
0xDBFF
&&
0xDC00
<=
y
&&
y
<=
0xDFFF
)
{
if
(
0xD800
<=
x
&&
x
<=
0xDBFF
&&
0xDC00
<=
y
&&
y
<=
0xDFFF
)
{
x
=
0x10000
+
((
x
&
0x03FF
)
<<
10
)
+
(
y
&
0x03FF
);
x
=
0x10000
+
((
x
&
0x03FF
)
<<
10
)
+
(
y
&
0x03FF
);
i
+=
1
;
i
+=
1
;
}
}
/* Encode output as utf-8 */
/* Encode output as utf-8 */
if
(
x
<=
0x7F
)
{
if
(
x
<=
0x7F
)
{
output
+=
String
.
fromCharCode
(
x
);
output
+=
String
.
fromCharCode
(
x
);
}
else
if
(
x
<=
0x7FF
)
{
}
else
if
(
x
<=
0x7FF
)
{
output
+=
String
.
fromCharCode
(
output
+=
String
.
fromCharCode
(
0xC0
|
((
x
>>>
6
)
&
0x1F
),
0xC0
|
((
x
>>>
6
)
&
0x1F
),
0x80
|
(
x
&
0x3F
)
0x80
|
(
x
&
0x3F
)
);
);
}
else
if
(
x
<=
0xFFFF
)
{
}
else
if
(
x
<=
0xFFFF
)
{
output
+=
String
.
fromCharCode
(
output
+=
String
.
fromCharCode
(
0xE0
|
((
x
>>>
12
)
&
0x0F
),
0xE0
|
((
x
>>>
12
)
&
0x0F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
0x80
|
(
x
&
0x3F
)
);
);
}
else
if
(
x
<=
0x1FFFFF
)
{
}
else
if
(
x
<=
0x1FFFFF
)
{
output
+=
String
.
fromCharCode
(
output
+=
String
.
fromCharCode
(
0xF0
|
((
x
>>>
18
)
&
0x07
),
0xF0
|
((
x
>>>
18
)
&
0x07
),
0x80
|
((
x
>>>
12
)
&
0x3F
),
0x80
|
((
x
>>>
12
)
&
0x3F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
0x80
|
(
x
&
0x3F
)
);
);
}
}
}
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
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
x
=
input
.
charCodeAt
(
i
);
x
=
input
.
charCodeAt
(
i
);
if
((
x
&
0xF0
)
===
0xF0
)
{
if
((
x
&
0xF0
)
===
0xF0
)
{
i
+=
1
;
i
+=
1
;
x
=
((
x
&
0x07
)
<<
18
)
|
(
x
=
((
x
&
0x07
)
<<
18
)
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
12
:
0
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
12
:
0
);
);
i
+=
1
;
i
+=
1
;
x
=
x
|
(
x
=
x
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
);
);
i
+=
1
;
i
+=
1
;
x
=
x
|
(
x
=
x
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
);
if
(
0x10000
<=
x
&&
x
<=
0x10FFFF
)
{
output
+=
String
.
fromCharCode
(
(((
x
-
0x10000
)
>>>
10
)
&
0x03FF
)
|
0xD800
,
(
x
&
0x03FF
)
|
0xDC00
);
);
if
(
0x10000
<=
x
&&
x
<=
0x10FFFF
)
{
output
+=
String
.
fromCharCode
(
(((
x
-
0x10000
)
>>>
10
)
&
0x03FF
)
|
0xD800
,
(
x
&
0x03FF
)
|
0xDC00
);
}
else
{
output
+=
String
.
fromCharCode
(
x
);
}
}
else
if
((
x
&
0xE0
)
===
0xE0
)
{
i
+=
1
;
x
=
((
x
&
0x0F
)
<<
12
)
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
);
i
+=
1
;
output
+=
String
.
fromCharCode
(
x
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
));
}
else
if
((
x
&
0xC0
)
===
0xC0
)
{
i
+=
1
;
output
+=
String
.
fromCharCode
(((
x
&
0x1F
)
<<
6
)
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
));
}
else
{
}
else
{
output
+=
String
.
fromCharCode
(
x
);
output
+=
String
.
fromCharCode
(
x
);
}
}
}
else
if
((
x
&
0xE0
)
===
0xE0
)
{
i
+=
1
;
x
=
((
x
&
0x0F
)
<<
12
)
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
);
i
+=
1
;
output
+=
String
.
fromCharCode
(
x
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
));
}
else
if
((
x
&
0xC0
)
===
0xC0
)
{
i
+=
1
;
output
+=
String
.
fromCharCode
(((
x
&
0x1F
)
<<
6
)
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
));
}
else
{
output
+=
String
.
fromCharCode
(
x
);
}
}
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
))
{
throw
new
TypeError
(
"
The method parameter is missing or invalid.
"
);
throw
new
TypeError
(
"
The method parameter is missing or invalid.
"
);
}
if
(
properties
!==
undefined
&&
(
typeof
properties
!==
'
object
'
||
Object
.
getPrototypeOf
(
properties
||
[])
!==
Object
.
prototype
))
{
throw
new
TypeError
(
"
Value can't be converted to a dictionnary.
"
);
}
for
(
i
=
0
;
i
<
parts
.
length
;
i
+=
1
)
{
part
=
parts
[
i
];
if
(
part
instanceof
Blob
)
{
raw
+=
part
.
_data
;
}
else
if
(
part
)
{
raw
+=
stringToUtf8ByteString
(
part
.
toString
());
}
else
if
(
part
===
undefined
)
{
raw
+=
"
undefined
"
;
}
}
if
(
properties
!==
undefined
&&
(
typeof
properties
!==
'
object
'
||
Object
.
getPrototypeOf
(
properties
||
[])
!==
Object
.
prototype
))
{
throw
new
TypeError
(
"
Value can't be converted to a dictionnary.
"
);
}
for
(
i
=
0
;
i
<
parts
.
length
;
i
+=
1
)
{
part
=
parts
[
i
];
if
(
part
instanceof
Blob
)
{
raw
+=
part
.
_data
;
}
else
if
(
part
)
{
raw
+=
stringToUtf8ByteString
(
part
.
toString
());
}
else
if
(
part
===
undefined
)
{
raw
+=
"
undefined
"
;
}
}
Object
.
defineProperty
(
this
,
"
_data
"
,
{
"
configurable
"
:
true
,
"
enumerable
"
:
false
,
"
writable
"
:
true
,
"
value
"
:
raw
});
Object
.
defineProperty
(
this
,
"
size
"
,
{
"
configurable
"
:
false
,
"
enumerable
"
:
true
,
"
writable
"
:
false
,
"
value
"
:
raw
.
length
});
Object
.
defineProperty
(
this
,
"
type
"
,
{
"
configurable
"
:
false
,
"
enumerable
"
:
true
,
"
writable
"
:
false
,
"
value
"
:
type
});
}
}
Object
.
defineProperty
(
this
,
"
_data
"
,
{
Blob
.
prototype
.
type
=
""
;
"
configurable
"
:
true
,
Blob
.
prototype
.
size
=
0
;
"
enumerable
"
:
false
,
Blob
.
prototype
.
slice
=
function
(
start
,
end
,
contentType
)
{
"
writable
"
:
true
,
var
data
,
blob
,
i
,
fake_data
=
''
;
"
value
"
:
raw
data
=
this
.
_data
.
slice
(
start
,
end
);
});
for
(
i
=
0
;
i
<
data
.
length
;
i
+=
1
)
{
Object
.
defineProperty
(
this
,
"
size
"
,
{
fake_data
+=
'
a
'
;
"
configurable
"
:
false
,
}
"
enumerable
"
:
true
,
blob
=
new
Blob
([
fake_data
],
{
"
type
"
:
contentType
});
"
writable
"
:
false
,
blob
.
_data
=
data
;
"
value
"
:
raw
.
length
return
blob
;
});
};
Object
.
defineProperty
(
this
,
"
type
"
,
{
"
configurable
"
:
false
,
"
enumerable
"
:
true
,
"
writable
"
:
false
,
"
value
"
:
type
});
}
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
)
{
fake_data
+=
'
a
'
;
}
blob
=
new
Blob
([
fake_data
],
{
"
type
"
:
contentType
});
blob
.
_data
=
data
;
return
blob
;
};
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js
function
FileReader
()
{
return
;
}
FileReader
.
prototype
.
addEventListener
=
function
(
eventName
,
callback
)
{
////////////////////////////////////////////////////////////
// Check parameters
// https://github.com/TristanCavelier/notesntools/blob/\
if
(
typeof
callback
!==
"
function
"
)
{
// master/javascript/emitter.js
function
FileReader
()
{
return
;
return
;
}
}
// assign callback to event
FileReader
.
prototype
.
addEventListener
=
function
(
eventName
,
callback
)
{
this
.
_events
=
this
.
_events
||
{};
// Check parameters
this
.
_events
[
eventName
]
=
this
.
_events
[
eventName
]
||
[];
if
(
typeof
callback
!==
"
function
"
)
{
this
.
_events
[
eventName
].
push
(
callback
)
;
return
;
};
}
function
dispatchEvent
(
fr
,
eventName
)
{
// assign callback to event
var
args
,
i
,
funs
=
fr
.
_events
&&
fr
.
_events
[
eventName
]
&&
this
.
_events
=
this
.
_events
||
{};
fr
.
_events
[
eventName
].
slice
();
this
.
_events
[
eventName
]
=
this
.
_events
[
eventName
]
||
[];
this
.
_events
[
eventName
].
push
(
callback
);
};
// for html5 EventTarget compatibility
function
dispatchEvent
(
fr
,
eventName
)
{
if
(
fr
.
hasOwnProperty
(
'
on
'
+
eventName
)
&&
var
args
,
i
,
funs
=
fr
.
_events
&&
fr
.
_events
[
eventName
]
&&
typeof
fr
[
'
on
'
+
eventName
]
===
"
function
"
)
{
fr
.
_events
[
eventName
].
slice
();
funs
=
funs
||
[];
funs
.
before
=
fr
[
'
on
'
+
eventName
];
}
if
(
funs
)
{
args
=
[].
slice
.
call
(
arguments
,
2
);
// for html5 EventTarget compatibility
// for html5 EventTarget compatibility
if
(
funs
.
before
)
{
if
(
fr
.
hasOwnProperty
(
'
on
'
+
eventName
)
&&
// no try catch wraps listeners on EventTarget API
typeof
fr
[
'
on
'
+
eventName
]
===
"
function
"
)
{
funs
.
before
.
apply
(
fr
,
args
);
funs
=
funs
||
[];
funs
.
before
=
fr
[
'
on
'
+
eventName
];
}
}
// call funs
if
(
funs
)
{
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
args
=
[].
slice
.
call
(
arguments
,
2
);
funs
[
i
].
apply
(
fr
,
args
);
// for html5 EventTarget compatibility
if
(
funs
.
before
)
{
// no try catch wraps listeners on EventTarget API
funs
.
before
.
apply
(
fr
,
args
);
}
// call funs
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
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
)
{
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
if
(
funs
[
i
]
===
callback
)
{
if
(
funs
[
i
]
===
callback
)
{
funs
.
splice
(
i
,
1
);
funs
.
splice
(
i
,
1
);
break
;
break
;
}
}
}
}
}
}
};
};
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
"
,
{
"
loaded
"
:
blob
.
size
,
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
"
target
"
:
that
});
});
that
.
result
=
blob
.
_data
;
that
.
result
=
blob
.
_data
;
dispatchEvent
(
that
,
"
load
"
,
{
dispatchEvent
(
that
,
"
load
"
,
{
"
loaded
"
:
blob
.
size
,
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
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
"
,
{
"
loaded
"
:
blob
.
size
,
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
"
target
"
:
that
});
that
.
result
=
utf8ByteStringToString
(
blob
.
_data
);
dispatchEvent
(
that
,
"
load
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
});
});
});
that
.
result
=
utf8ByteStringToString
(
blob
.
_data
);
};
dispatchEvent
(
that
,
"
load
"
,
{
"
loaded
"
:
blob
.
size
,
////////////////////////////////////////////////////////////
"
total
"
:
blob
.
size
,
"
target
"
:
that
if
(
typeof
Blob
!==
'
function
'
||
typeof
FileReader
!==
'
function
'
||
});
(
/
\b
PhantomJS
\b
/i
).
test
(
navigator
.
userAgent
))
{
});
window
.
Blob
=
Blob
;
};
window
.
FileReader
=
FileReader
;
}
////////////////////////////////////////////////////////////
}());
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment