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