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 */
/*global setTimeout */
/*global setTimeout
, window, navigator
*/
////////////////////////////////////////////////////////////
// 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
)
{
/*jslint bitwise: true */
var
output
=
""
,
i
,
x
,
y
,
l
=
input
.
length
;
(
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
)
{
/*jslint bitwise: true */
var
output
=
""
,
i
,
x
,
y
,
l
=
input
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
/* Decode utf-16 surrogate pairs */
x
=
input
.
charCodeAt
(
i
);
y
=
i
+
1
<
l
?
input
.
charCodeAt
(
i
+
1
)
:
0
;
if
(
0xD800
<=
x
&&
x
<=
0xDBFF
&&
0xDC00
<=
y
&&
y
<=
0xDFFF
)
{
x
=
0x10000
+
((
x
&
0x03FF
)
<<
10
)
+
(
y
&
0x03FF
);
i
+=
1
;
}
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
/* Decode utf-16 surrogate pairs */
x
=
input
.
charCodeAt
(
i
);
y
=
i
+
1
<
l
?
input
.
charCodeAt
(
i
+
1
)
:
0
;
if
(
0xD800
<=
x
&&
x
<=
0xDBFF
&&
0xDC00
<=
y
&&
y
<=
0xDFFF
)
{
x
=
0x10000
+
((
x
&
0x03FF
)
<<
10
)
+
(
y
&
0x03FF
);
i
+=
1
;
}
/* Encode output as utf-8 */
if
(
x
<=
0x7F
)
{
output
+=
String
.
fromCharCode
(
x
);
}
else
if
(
x
<=
0x7FF
)
{
output
+=
String
.
fromCharCode
(
0xC0
|
((
x
>>>
6
)
&
0x1F
),
0x80
|
(
x
&
0x3F
)
);
}
else
if
(
x
<=
0xFFFF
)
{
output
+=
String
.
fromCharCode
(
0xE0
|
((
x
>>>
12
)
&
0x0F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
);
}
else
if
(
x
<=
0x1FFFFF
)
{
output
+=
String
.
fromCharCode
(
0xF0
|
((
x
>>>
18
)
&
0x07
),
0x80
|
((
x
>>>
12
)
&
0x3F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
);
/* Encode output as utf-8 */
if
(
x
<=
0x7F
)
{
output
+=
String
.
fromCharCode
(
x
);
}
else
if
(
x
<=
0x7FF
)
{
output
+=
String
.
fromCharCode
(
0xC0
|
((
x
>>>
6
)
&
0x1F
),
0x80
|
(
x
&
0x3F
)
);
}
else
if
(
x
<=
0xFFFF
)
{
output
+=
String
.
fromCharCode
(
0xE0
|
((
x
>>>
12
)
&
0x0F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
);
}
else
if
(
x
<=
0x1FFFFF
)
{
output
+=
String
.
fromCharCode
(
0xF0
|
((
x
>>>
18
)
&
0x07
),
0x80
|
((
x
>>>
12
)
&
0x3F
),
0x80
|
((
x
>>>
6
)
&
0x3F
),
0x80
|
(
x
&
0x3F
)
);
}
}
return
output
;
}
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
)
{
/*jslint bitwise: true */
var
output
=
""
,
i
,
x
,
l
=
input
.
length
;
/**
* 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
)
{
/*jslint bitwise: true */
var
output
=
""
,
i
,
x
,
l
=
input
.
length
;
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
x
=
input
.
charCodeAt
(
i
);
if
((
x
&
0xF0
)
===
0xF0
)
{
i
+=
1
;
x
=
((
x
&
0x07
)
<<
18
)
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
12
:
0
);
i
+=
1
;
x
=
x
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
);
i
+=
1
;
x
=
x
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
);
if
(
0x10000
<=
x
&&
x
<=
0x10FFFF
)
{
output
+=
String
.
fromCharCode
(
(((
x
-
0x10000
)
>>>
10
)
&
0x03FF
)
|
0xD800
,
(
x
&
0x03FF
)
|
0xDC00
for
(
i
=
0
;
i
<
l
;
i
+=
1
)
{
x
=
input
.
charCodeAt
(
i
);
if
((
x
&
0xF0
)
===
0xF0
)
{
i
+=
1
;
x
=
((
x
&
0x07
)
<<
18
)
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
12
:
0
);
i
+=
1
;
x
=
x
|
(
i
<
l
?
(
input
.
charCodeAt
(
i
)
&
0x3F
)
<<
6
:
0
);
i
+=
1
;
x
=
x
|
(
i
<
l
?
input
.
charCodeAt
(
i
)
&
0x3F
:
0
);
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
{
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
)
{
var
i
,
part
,
raw
=
''
,
type
;
type
=
(
properties
&&
properties
.
type
&&
properties
.
type
.
toString
())
||
""
;
if
(
!
Array
.
isArray
(
parts
))
{
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
"
;
function
Blob
(
parts
,
properties
)
{
var
i
,
part
,
raw
=
''
,
type
;
type
=
(
properties
&&
properties
.
type
&&
properties
.
type
.
toString
())
||
""
;
if
(
!
Array
.
isArray
(
parts
))
{
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
"
;
}
}
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
"
,
{
"
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
});
}
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
;
}
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
;
};
FileReader
.
prototype
.
addEventListener
=
function
(
eventName
,
callback
)
{
// Check parameters
if
(
typeof
callback
!==
"
function
"
)
{
////////////////////////////////////////////////////////////
// https://github.com/TristanCavelier/notesntools/blob/\
// master/javascript/emitter.js
function
FileReader
()
{
return
;
}
// assign callback to event
this
.
_events
=
this
.
_events
||
{};
this
.
_events
[
eventName
]
=
this
.
_events
[
eventName
]
||
[];
this
.
_events
[
eventName
].
push
(
callback
)
;
};
FileReader
.
prototype
.
addEventListener
=
function
(
eventName
,
callback
)
{
// Check parameters
if
(
typeof
callback
!==
"
function
"
)
{
return
;
}
function
dispatchEvent
(
fr
,
eventName
)
{
var
args
,
i
,
funs
=
fr
.
_events
&&
fr
.
_events
[
eventName
]
&&
fr
.
_events
[
eventName
].
slice
();
// assign callback to event
this
.
_events
=
this
.
_events
||
{};
this
.
_events
[
eventName
]
=
this
.
_events
[
eventName
]
||
[];
this
.
_events
[
eventName
].
push
(
callback
);
};
// for html5 EventTarget compatibility
if
(
fr
.
hasOwnProperty
(
'
on
'
+
eventName
)
&&
typeof
fr
[
'
on
'
+
eventName
]
===
"
function
"
)
{
funs
=
funs
||
[];
funs
.
before
=
fr
[
'
on
'
+
eventName
];
}
if
(
funs
)
{
args
=
[].
slice
.
call
(
arguments
,
2
);
function
dispatchEvent
(
fr
,
eventName
)
{
var
args
,
i
,
funs
=
fr
.
_events
&&
fr
.
_events
[
eventName
]
&&
fr
.
_events
[
eventName
].
slice
();
// for html5 EventTarget compatibility
if
(
funs
.
before
)
{
// no try catch wraps listeners on EventTarget API
funs
.
before
.
apply
(
fr
,
args
);
if
(
fr
.
hasOwnProperty
(
'
on
'
+
eventName
)
&&
typeof
fr
[
'
on
'
+
eventName
]
===
"
function
"
)
{
funs
=
funs
||
[];
funs
.
before
=
fr
[
'
on
'
+
eventName
];
}
// call funs
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
funs
[
i
].
apply
(
fr
,
args
);
if
(
funs
)
{
args
=
[].
slice
.
call
(
arguments
,
2
);
// 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
)
{
var
i
,
funs
=
this
.
_events
&&
this
.
_events
[
eventName
];
FileReader
.
prototype
.
removeEventListener
=
function
(
eventName
,
callback
)
{
var
i
,
funs
=
this
.
_events
&&
this
.
_events
[
eventName
];
if
(
funs
)
{
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
if
(
funs
[
i
]
===
callback
)
{
funs
.
splice
(
i
,
1
);
break
;
if
(
funs
)
{
for
(
i
=
0
;
i
<
funs
.
length
;
i
+=
1
)
{
if
(
funs
[
i
]
===
callback
)
{
funs
.
splice
(
i
,
1
);
break
;
}
}
}
}
};
};
FileReader
.
prototype
.
abort
=
function
()
{
this
.
dispatchEvent
(
"
abort
"
,
{
"
target
"
:
this
});
delete
this
.
_events
;
};
FileReader
.
prototype
.
abort
=
function
()
{
this
.
dispatchEvent
(
"
abort
"
,
{
"
target
"
:
this
});
delete
this
.
_events
;
};
FileReader
.
prototype
.
readAsBinaryString
=
function
(
blob
)
{
var
that
=
this
;
setTimeout
(
function
()
{
dispatchEvent
(
that
,
"
progress
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
});
that
.
result
=
blob
.
_data
;
dispatchEvent
(
that
,
"
load
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
FileReader
.
prototype
.
readAsBinaryString
=
function
(
blob
)
{
var
that
=
this
;
setTimeout
(
function
()
{
dispatchEvent
(
that
,
"
progress
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
});
that
.
result
=
blob
.
_data
;
dispatchEvent
(
that
,
"
load
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
});
});
});
};
};
FileReader
.
prototype
.
readAsText
=
function
(
blob
)
{
var
that
=
this
;
setTimeout
(
function
()
{
dispatchEvent
(
that
,
"
progress
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
target
"
:
that
FileReader
.
prototype
.
readAsText
=
function
(
blob
)
{
var
that
=
this
;
setTimeout
(
function
()
{
dispatchEvent
(
that
,
"
progress
"
,
{
"
loaded
"
:
blob
.
size
,
"
total
"
:
blob
.
size
,
"
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