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
e4793d89
Commit
e4793d89
authored
Sep 01, 2011
by
François Billioud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change the way dependencies are loaded
parent
eb08ca0a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
79 deletions
+72
-79
UNGProject/unhosted/jio.js
UNGProject/unhosted/jio.js
+72
-79
No files found.
UNGProject/unhosted/jio.js
View file @
e4793d89
...
...
@@ -7,13 +7,13 @@
/**
* load dependencies
*/
var
ready
=
includeJS
([
//files to load
"
unhosted/sjcl.js
"
,
"
unhosted/jquery.js
"
,
"
unhosted/base64.js
"
],
[
//element to check before being ready
$
],
script
);
// function to execute then
var
dependenceLoaded
=
includeJS
([
//files to load
"
/
unhosted/sjcl.js
"
,
"
/
unhosted/jquery.js
"
,
"
/
unhosted/base64.js
"
],
function
()
{
// return true only if dependencies are loaded
return
$
!==
undefined
&&
sjcl
!==
undefined
&&
Base64
!==
undefined
;
// check jQuery, sjcl & Base64
});
function
script
()
{
...
...
@@ -744,6 +744,8 @@
}
}
/*************************************************************************
*************************** other functions *****************************/
...
...
@@ -775,10 +777,11 @@
function
createStorage
(
data
,
applicant
)
{
switch
(
data
.
type
)
{
case
"
dav
"
:
return
new
JIO
.
DAVStorage
(
data
,
applicant
);
break
;
case
"
local
"
:
return
new
JIO
.
LocalStorage
(
data
,
applicant
);
break
;
case
"
index
"
:
return
new
JIO
.
IndexedStorage
(
data
,
applicant
);
break
;
case
"
multiple
"
:
return
new
JIO
.
MultipleStorage
(
data
,
applicant
);
break
;
case
"
replicate
"
:
return
new
JIO
.
ReplicateStorage
(
data
,
applicant
);
break
;
case
"
encrypte
"
:
return
new
JIO
.
CryptedStorage
(
data
,
applicant
);
break
;
case
"
encrypt
"
:
return
new
JIO
.
CryptedStorage
(
data
,
applicant
);
break
;
//etc
default
:
var
waitedNode
=
null
;
//create a custom storage from a js file
$
.
ajax
({
...
...
@@ -794,25 +797,6 @@
}
}
/**
* delegate a function to a non-object element, or to each element of an array of non-object elements
* this function is used to delete a file or a list of files for example
* @param element : a non-object element, or an array of non-object elements
* @param f : function to apply
*/
function
oneOrEach
(
element
,
f
)
{
typeof
element
!=
"
object
"
?
f
(
element
)
:
$
.
each
(
element
,
function
(
index
,
fileName
)
{
f
(
fileName
);})
}
/**
* return a shallow copy of the object parameter
* @param object : the object to copy
* @return a shallow copy of the object
*/
function
copy
(
object
)
{
$
.
extend
({},
object
);
}
window
.
JIO
=
JIO
;
//the name to use for the framework. Ex : JIO.initialize(...), JIO.loadDocument...
}
...
...
@@ -823,16 +807,14 @@
/**
* include js files
* @param url : path or array of paths of the js file(s)
* @param
flag
: (optional) array of elements allowing to know if dependencies are ready
* @param
ready
: (optional) array of elements allowing to know if dependencies are ready
* @param instruction : (optional) instruction to execute when dependencies are loaded
* @return
a ready function which returns true only if the dependencies are ready
* @return
the ready function
* @example : includeJS("jquery.js",[$]);
*/
function
includeJS
(
url
,
flag
,
instruction
)
{
typeof
url
!=
"
object
"
?
includeElement
(
url
)
:
onEach
(
url
);
var
ready
=
function
()
{
return
oneOrEach
(
flag
.
slice
(),
function
(
element
){
return
typeof
element
!=
"
undefined
"
});
}
function
includeJS
(
url
,
ready
,
instruction
)
{
//path = findURL("jio.js");
typeof
url
!=
"
object
"
?
includeElement
(
url
)
:
onEach
(
url
,
includeElement
);
if
(
instruction
)
{
(
function
waitUntilLoaded
()
{
!
ready
()
?
setTimeout
(
waitUntilLoaded
,
50
)
:
instruction
();})()
}
...
...
@@ -841,15 +823,26 @@
function
includeElement
(
element
)
{
//include a js file
var
head
=
window
.
document
.
getElementsByTagName
(
'
head
'
)[
0
];
var
script
=
window
.
document
.
createElement
(
'
script
'
);
script
.
setAttribute
(
'
src
'
,
url
);
script
.
setAttribute
(
'
src
'
,
element
);
script
.
setAttribute
(
'
type
'
,
'
text/javascript
'
);
head
.
appendChild
(
script
);
}
function
onEach
(
array
,
f
)
{
var
head
=
array
.
pop
();
if
(
array
.
length
==
0
)
{
return
true
}
return
f
(
head
)
&&
oneOrEach
(
array
);
if
(
head
===
undefined
)
{
return
true
}
var
rep1
=
f
(
head
);
var
rep2
=
onEach
(
array
,
f
);
return
rep1
&&
rep2
;
}
function
findURL
(
fileName
)
{
var
elements
=
window
.
document
.
getElementsByName
(
"
script
"
);
var
jioRegExp
=
new
RegExp
(
"
^((.*)/)?
"
+
fileName
+
"
$
"
);
for
(
var
e
in
elements
)
{
if
(
jioRegExp
.
test
(
e
.
src
))
{
return
e
.
src
.
replace
(
jioRegExp
,
"
$1
"
)}
}
return
""
;
}
}
...
...
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