Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
renderjs
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
Boris Kocherov
renderjs
Commits
a86fa637
Commit
a86fa637
authored
Jun 25, 2013
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation
parent
55e79740
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
773 additions
and
751 deletions
+773
-751
renderjs.js
renderjs.js
+773
-751
No files found.
renderjs.js
View file @
a86fa637
/*! RenderJs v0.2 */
/*global console, require, $, localStorage, document, jIO */
/*jslint evil: true,
white: true
*/
/*jslint evil: true,
indent: 2, maxerr: 3
*/
"
use strict
"
;
/*
* RenderJs - Generic Gadget library renderer.
...
...
@@ -53,7 +53,7 @@ var RenderJs = (function () {
// a variable indicating if current gadget loading is over or not
var
is_ready
=
false
,
current_gadget
;
function
setSelfGadget
(
gadget
)
{
function
setSelfGadget
(
gadget
)
{
/*
* Only used internally to set current gadget being executed.
*/
...
...
@@ -70,7 +70,7 @@ var RenderJs = (function () {
RenderJs
.
bootstrap
(
$
(
'
body
'
));
}
var
root_gadget
=
RenderJs
.
GadgetIndex
.
getRootGadget
();
if
(
RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND
||
RENDERJS_ENABLE_IMPLICIT_ROUTE_CREATE
)
{
if
(
RENDERJS_ENABLE_IMPLICIT_INTERACTION_BIND
||
RENDERJS_ENABLE_IMPLICIT_ROUTE_CREATE
)
{
// We might have a page without gadgets.
// Be careful, right now we can be in this case because
// asynchronous gadget loading is not finished
...
...
@@ -85,7 +85,8 @@ var RenderJs = (function () {
// create all routes between gadgets
RenderJs
.
RouteGadget
.
init
();
}
});
}
);
}
}
},
...
...
@@ -100,7 +101,7 @@ var RenderJs = (function () {
is_gadget
=
root
.
attr
(
"
data-gadget
"
)
!==
undefined
;
// this will make RenderJs fire "ready" event when all gadgets are loaded.
RenderJs
.
setReady
(
false
);
if
(
is_gadget
&&
gadget_id
!==
undefined
)
{
if
(
is_gadget
&&
gadget_id
!==
undefined
)
{
// bootstart root gadget only if it is indeed a gadget
RenderJs
.
loadGadget
(
root
);
}
...
...
@@ -176,7 +177,7 @@ var RenderJs = (function () {
}
if
(
gadget_js
.
isReady
())
{
// avoid loading again gadget which was loaded before in same page
return
;
return
;
}
// update Gadget's instance with contents of "data-gadget-property"
...
...
@@ -241,8 +242,7 @@ var RenderJs = (function () {
}
});
}
}
else
{
}
else
{
// gadget is an inline (InteractorGadget or one using
// data-gadget-source / data-gadget-handler) so no need
// to load it from network
...
...
@@ -486,7 +486,12 @@ var RenderJs = (function () {
*/
var
tab_gadget
;
tab_gadget
=
RenderJs
.
addGadget
(
dom_id
,
gadget_id
,
gadget
,
gadget_data_handler
,
gadget_data_source
,
bootstrap
dom_id
,
gadget_id
,
gadget
,
gadget_data_handler
,
gadget_data_source
,
bootstrap
);
// we should unregister all gadgets part of this TabbularGadget
...
...
@@ -519,7 +524,8 @@ var RenderJs = (function () {
var
gadget_id_list
=
[];
$
.
each
(
dom
.
find
(
'
[data-gadget]
'
),
function
(
index
,
value
)
{
gadget_id_list
.
push
(
$
(
value
).
attr
(
"
id
"
));}
gadget_id_list
.
push
(
$
(
value
).
attr
(
"
id
"
));
}
);
return
gadget_id_list
;
},
...
...
@@ -609,14 +615,15 @@ var RenderJs = (function () {
function
updateGadgetIndexFromURL
(
url
)
{
// split to base and document url
var
url_list
=
url
.
split
(
'
/
'
),
document_url
=
url_list
[
url_list
.
length
-
1
],
document_url
=
url_list
[
url_list
.
length
-
1
],
d
=
url_list
.
splice
(
$
.
inArray
(
document_url
,
url_list
),
1
),
base_url
=
url_list
.
join
(
'
/
'
),
web_dav
=
jIO
.
newJio
({
"
type
"
:
"
dav
"
,
"
username
"
:
""
,
"
password
"
:
""
,
"
url
"
:
base_url
});
"
url
"
:
base_url
});
web_dav
.
get
(
document_url
,
function
(
err
,
response
)
{
RenderJs
.
Cache
.
set
(
url
,
response
);
...
...
@@ -629,7 +636,7 @@ var RenderJs = (function () {
* Update gadget index from all configured remote repositories.
*/
$
.
each
(
RenderJs
.
GadgetCatalog
.
getGadgetIndexUrlList
(),
function
(
index
,
value
)
{
function
(
index
,
value
)
{
updateGadgetIndexFromURL
(
value
);
});
},
...
...
@@ -660,11 +667,11 @@ var RenderJs = (function () {
// to find matching ones
var
gadget_list
=
[];
$
.
each
(
RenderJs
.
GadgetCatalog
.
getGadgetIndexUrlList
(),
function
(
index
,
url
)
{
function
(
index
,
url
)
{
// get repos from cache
var
cached_repo
=
RenderJs
.
Cache
.
get
(
url
);
$
.
each
(
cached_repo
.
gadget_list
,
function
(
index
,
gadget
)
{
function
(
index
,
gadget
)
{
if
(
$
.
inArray
(
service
,
gadget
.
service_list
)
>
-
1
)
{
// gadget provides a service, add to list
gadget_list
.
push
(
gadget
);
...
...
@@ -694,18 +701,18 @@ var RenderJs = (function () {
* Inspect DOM and initialize this gadget
*/
var
dom_list
,
gadget_id
;
if
(
force
===
1
)
{
if
(
force
===
1
)
{
// we explicitly want to re-init elements even if already this is done before
dom_list
=
$
(
"
div[data-gadget-connection]
"
);
}
else
{
}
else
{
// XXX: improve and save 'bound' on javascript representation of a gadget not DOM
dom_list
=
$
(
"
div[data-gadget-connection]
"
)
.
filter
(
function
()
{
return
$
(
this
).
data
(
"
bound
"
)
!==
true
;
})
.
data
(
'
bound
'
,
true
);
.
filter
(
function
()
{
return
$
(
this
).
data
(
"
bound
"
)
!==
true
;
})
.
data
(
'
bound
'
,
true
);
}
dom_list
.
each
(
function
(
index
,
element
)
{
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));});
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));
});
},
bind
:
function
(
gadget_dom
)
{
...
...
@@ -714,25 +721,33 @@ var RenderJs = (function () {
*/
var
gadget_id
,
gadget_connection_list
,
createMethodInteraction
=
function
(
original_source_method_id
,
source_gadget_id
,
source_method_id
,
destination_gadget_id
,
destination_method_id
)
{
original_source_method_id
,
source_gadget_id
,
source_method_id
,
destination_gadget_id
,
destination_method_id
)
{
var
interaction
=
function
()
{
// execute source method
RenderJs
.
GadgetIndex
.
getGadgetById
(
source_gadget_id
)[
original_source_method_id
].
source_gadget_id
)[
original_source_method_id
].
apply
(
null
,
arguments
);
// call trigger so bind can be asynchronously called
RenderJs
.
GadgetIndex
.
getGadgetById
(
destination_gadget_id
).
dom
.
trigger
(
source_method_id
);
destination_gadget_id
).
dom
.
trigger
(
source_method_id
);
};
return
interaction
;
},
createTriggerInteraction
=
function
(
destination_gadget_id
,
destination_method_id
)
{
destination_gadget_id
,
destination_method_id
)
{
var
interaction
=
function
()
{
RenderJs
.
GadgetIndex
.
getGadgetById
(
destination_gadget_id
)[
destination_method_id
].
destination_gadget_id
)[
destination_method_id
].
apply
(
null
,
arguments
);
};
return
interaction
;
...
...
@@ -741,9 +756,14 @@ var RenderJs = (function () {
gadget_connection_list
=
gadget_dom
.
attr
(
"
data-gadget-connection
"
);
gadget_connection_list
=
$
.
parseJSON
(
gadget_connection_list
);
$
.
each
(
gadget_connection_list
,
function
(
key
,
value
)
{
var
source
,
source_gadget_id
,
source_method_id
,
source_gadget
,
destination
,
destination_gadget_id
,
destination_method_id
,
destination_gadget
,
var
source
,
source_gadget_id
,
source_method_id
,
source_gadget
,
destination
,
destination_gadget_id
,
destination_method_id
,
destination_gadget
,
original_source_method_id
;
source
=
value
.
source
.
split
(
"
.
"
);
source_gadget_id
=
source
[
0
];
...
...
@@ -776,17 +796,18 @@ var RenderJs = (function () {
destination_gadget
.
dom
.
bind
(
source_method_id
,
createTriggerInteraction
(
destination_gadget_id
,
destination_method_id
destination_gadget_id
,
destination_method_id
)
);
}
else
{
}
else
{
// this is a custom event attached to HTML gadget
// representation
source_gadget
.
dom
.
bind
(
source_method_id
,
createTriggerInteraction
(
destination_gadget_id
,
destination_method_id
destination_gadget_id
,
destination_method_id
)
);
}
...
...
@@ -816,7 +837,8 @@ var RenderJs = (function () {
* Create routes between gadgets.
*/
var
body
=
$
(
"
body
"
),
handler_func
,
priority
,
handler_func
,
priority
,
gadget_route_list
=
gadget_dom
.
attr
(
"
data-gadget-route
"
);
gadget_route_list
=
$
.
parseJSON
(
gadget_route_list
);
$
.
each
(
gadget_route_list
,
function
(
key
,
gadget_route
)
{
...
...
@@ -881,7 +903,7 @@ var RenderJs = (function () {
};
}())
};
}());
}());
// Define Gadget prototype
RenderJs
.
Gadget
.
prototype
.
getId
=
function
()
{
...
...
@@ -915,7 +937,7 @@ RenderJs.Gadget.prototype.remove = function () {
RenderJs
.
GadgetIndex
.
unregisterGadget
(
this
);
// gadget might contain sub gadgets so before remove entire
// DOM we must unregister them from GadgetIndex
this
.
getDom
().
find
(
"
[data-gadget]
"
).
each
(
function
()
{
this
.
getDom
().
find
(
"
[data-gadget]
"
).
each
(
function
()
{
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
$
(
this
).
attr
(
"
id
"
));
RenderJs
.
GadgetIndex
.
unregisterGadget
(
gadget
);
});
...
...
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