Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
03d57c2a
Commit
03d57c2a
authored
Jun 22, 2011
by
François Billioud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add timing methods in tools.js
parent
5367e7fe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
4 deletions
+86
-4
UNGProject/js/tools.js
UNGProject/js/tools.js
+86
-4
No files found.
UNGProject/js/tools.js
View file @
03d57c2a
...
@@ -33,12 +33,94 @@ UngObject.prototype.inherits = function(superClass) {
...
@@ -33,12 +33,94 @@ UngObject.prototype.inherits = function(superClass) {
*/
*/
currentTime
=
function
()
{
return
(
new
Date
()).
toUTCString
();}
currentTime
=
function
()
{
return
(
new
Date
()).
toUTCString
();}
// save
saveXHR
=
function
(
address
)
{
//create request
var
xhr
=
null
;
try
{
xhr
=
new
XMLHttpRequest
();
}
catch
(
e
)
{
try
{
xhr
=
new
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);}
catch
(
e2
)
{
try
{
xhr
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);}
catch
(
e
)
{
alert
(
"
Please install a more recent browser
"
)}
}
}
//xhr.open("PUT", keyToUrl(key, wallet), true, wallet.userAddress, wallet.davToken);
//HACK:
xhr
.
open
(
"
PUT
"
,
address
,
true
);
xhr
.
setRequestHeader
(
"
Authorization
"
,
"
Basic
"
+
"
nom:test
"
);
//END HACK.
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
if
(
xhr
.
status
!=
200
&&
xhr
.
status
!=
201
&&
xhr
.
status
!=
204
)
{
alert
(
"
error: got status
"
+
xhr
.
status
+
"
when doing basic auth PUT on url
"
+
Base64
.
encode
(
"
nom:test
"
)
+
"
"
+
xhr
.
statusText
);
}
}
}
xhr
.
withCredentials
=
"
true
"
;
xhr
.
send
(
JSON
.
stringify
(
getCurrentDocument
()));
}
// load
loadXHR
=
function
(
address
)
{
//create request
var
xhr
=
null
;
try
{
xhr
=
new
XMLHttpRequest
();
}
catch
(
e
)
{
try
{
xhr
=
new
ActiveXObject
(
"
Msxml2.XMLHTTP
"
);}
catch
(
e2
)
{
try
{
xhr
=
new
ActiveXObject
(
"
Microsoft.XMLHTTP
"
);}
catch
(
e
)
{}
}
}
xhr
.
open
(
"
GET
"
,
address
,
true
);
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
4
)
{
var
cDoc
=
getCurrentDocument
();
if
(
xhr
.
status
==
200
)
{
cDoc
.
load
(
JSON
.
parse
(
xhr
.
responseText
));
}
else
{
alert
(
"
error: got status
"
+
xhr
.
status
+
"
when doing basic auth GET on url
"
+
"
nom:test
"
+
"
"
+
xhr
.
statusText
);
}
cDoc
.
setAsCurrentDocument
();
}
}
xhr
.
send
();
}
/*
/*
* wait an event before execute an action
* wait an event before execute an action
*/
*/
waitBeforeExecution
=
function
(
event
,
func
)
{
tryUntilSucceed
=
function
(
func
)
{
var
waitBefore
=
function
()
{
var
nb
=
2
;
//avoid to test too much times
if
(
event
)
{
func
.
call
();}
else
{
setTimeout
(
waitBefore
,
1000
)}
var
retry
=
function
()
{
try
{
return
func
.
call
();}
catch
(
e
)
{
if
(
nb
<
100
)
{
setTimeout
(
retry
,
nb
*
100
);
alert
(
e
);}}
nb
*=
nb
;
}
}
setTimeout
(
waitBefore
,
1000
);
retry
(
);
}
}
requireBeforeSucceed
=
function
(
required
,
func
)
{
var
test
=
function
()
{
try
{
return
required
.
call
();}
catch
(
e
)
{
return
null
;}
}
if
(
test
())
{
tryUntilSucceed
(
func
);}
else
{
setTimeout
(
test
,
100
);};
}
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