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
Labels
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
renderjs
Commits
e417ed3b
Commit
e417ed3b
authored
Feb 19, 2013
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make gadget independant from each other. Use global RouteGadget to route
between different applications.
parent
036c479f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
39 deletions
+32
-39
examples/route/gadget-color-picker.html
examples/route/gadget-color-picker.html
+22
-30
examples/route/gadget-three.html
examples/route/gadget-three.html
+0
-3
examples/route/index.html
examples/route/index.html
+5
-0
examples/route/require-renderjs_route.js
examples/route/require-renderjs_route.js
+4
-6
renderjs.js
renderjs.js
+1
-0
No files found.
examples/route/gadget-color-picker.html
View file @
e417ed3b
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
</ul>
</ul>
<div
class=
"select-color"
style=
"display: block;"
>
Unknown color (/color/)
</div>
<div
class=
"select-color"
style=
"display: block;"
>
Unknown color (/color/)
</div>
<a
href=
"#/gadget-one/"
>
Gadget 1
</a>
<a
href=
"#/gadget-two/"
>
Gadget 2
</a>
<div
class=
"container"
></div>
<div
class=
"container"
></div>
</div>
</div>
...
@@ -29,37 +28,30 @@
...
@@ -29,37 +28,30 @@
//
<!
[
CDATA
[
//
<!
[
CDATA
[
$
(
document
).
ready
(
function
()
{
$
(
document
).
ready
(
function
()
{
gadget
=
RenderJs
.
getSelfGadget
();
gadget
=
RenderJs
.
getSelfGadget
();
// define entry point which handles an url
gadget
.
render
=
function
(){
var
handler_func
;
gadget
.
redirect
=
function
()
{
// Default route. Redirect to color subapp
// Default route. Redirect to color subapp
RenderJs
.
RouteGadget
.
add
(
""
,
$
.
url
.
redirect
(
'
/color/
'
);
function
()
{
$
.
url
.
redirect
(
'
/color/
'
);},
};
1
);
gadget
.
initRoutes
=
function
()
{
handler_func
=
function
()
{
// Create sub routed in the container
// XXX: it uses low level API
// Create sub routed in the container
RenderJs
.
RouteGadget
.
add
(
"
/color/
"
,
RenderJs
.
RouteGadget
.
add
(
"
/color/
"
,
function
()
{
function
()
{
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);},
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);},
2
);
2
);
RenderJs
.
RouteGadget
.
add
(
"
/color/<int:red>/<int:green>/<int:blue>/
"
,
RenderJs
.
RouteGadget
.
add
(
"
/color/<int:red>/<int:green>/<int:blue>/
"
,
function
(
red
,
green
,
blue
)
{
function
(
red
,
green
,
blue
)
{
$
(
'
.select-color
'
).
html
(
$
(
'
.select-color
'
).
html
(
"
<div style='background-color:rgb(
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
);'> <
\
/div>
"
+
"
<div style='background-color:rgb(
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
);'> <
\
/div>
"
+
"
<p>Color (
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
) selected at
"
+
new
Date
()
+
"
<
\
/p>
"
);},
"
<p>Color (
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
) selected at
"
+
new
Date
()
+
"
<
\
/p>
"
);},
2
);
2
);
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
function
()
{
function
()
{
$
(
'
.select-color
'
).
html
(
"
Unknown color (
"
+
$
.
url
.
getPath
()
+
"
)
"
);},
$
(
'
.select-color
'
).
html
(
"
Unknown color (
"
+
$
.
url
.
getPath
()
+
"
)
"
);},
2
);
2
);
};
};
// /color app. Create subroutes and initialize DOM
RenderJs
.
RouteGadget
.
add
(
"
/color<path:params>
"
,
handler_func
,
1
);
};
});
});
//]]>
//]]>
</script>
</script>
...
...
examples/route/gadget-three.html
View file @
e417ed3b
...
@@ -11,10 +11,7 @@
...
@@ -11,10 +11,7 @@
$
(
gadget
.
getDom
()).
find
(
"
.gadget-id-viewer
"
).
html
(
"
This is
"
+
gadget
.
getId
())
$
(
gadget
.
getDom
()).
find
(
"
.gadget-id-viewer
"
).
html
(
"
This is
"
+
gadget
.
getId
())
gadget
.
render
=
function
(
gadget_id
){
gadget
.
render
=
function
(
gadget_id
){
// XXX: find cooler way to get this gadget_id rather from url .. (closures?)
//gadget_id = window.location.toString().split("#")[1].replace("/", "").replace("/", "");
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
console
.
log
(
gadget
);
$
(
gadget
.
getDom
().
find
(
"
.gadget-id-viewer
"
)).
toggle
();
$
(
gadget
.
getDom
().
find
(
"
.gadget-id-viewer
"
)).
toggle
();
};
};
});
});
...
...
examples/route/index.html
View file @
e417ed3b
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
<div
data-gadget=
""
<div
data-gadget=
""
id=
"main-router"
id=
"main-router"
data-gadget-route=
"[
data-gadget-route=
"[
{"source": "", "destination": "gadget-color-picker.redirect"},
{"source": "/color<path:params>", "destination": "gadget-color-picker.initRoutes"},
{"source": "/gadget-one/", "destination": "main-router.gadget_one"},
{"source": "/gadget-one/", "destination": "main-router.gadget_one"},
{"source": "/gadget-two/", "destination": "main-router.gadget_two"}]"
>
{"source": "/gadget-two/", "destination": "main-router.gadget_two"}]"
>
</div>
</div>
...
@@ -22,6 +24,9 @@
...
@@ -22,6 +24,9 @@
<div
id=
"gadget-color-picker"
<div
id=
"gadget-color-picker"
data-gadget=
"gadget-color-picker.html"
></div>
data-gadget=
"gadget-color-picker.html"
></div>
<a
href=
"#/gadget-one/"
>
Gadget 1
</a>
<a
href=
"#/gadget-two/"
>
Gadget 2
</a>
<div
id=
"gadget-one"
<div
id=
"gadget-one"
data-gadget=
"gadget-one.html"
></div>
data-gadget=
"gadget-one.html"
></div>
...
...
examples/route/require-renderjs_route.js
View file @
e417ed3b
...
@@ -20,8 +20,6 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
...
@@ -20,8 +20,6 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
gadget
.
gadget_one
=
function
(){
gadget
.
gadget_one
=
function
(){
// we use interactionGadget which will call proper gadgets' function
// we use interactionGadget which will call proper gadgets' function
};
};
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
main-router
"
);
gadget
.
gadget_two
=
function
(){
gadget
.
gadget_two
=
function
(){
// we use interactionGadget which will call proper gadgets' function
// we use interactionGadget which will call proper gadgets' function
};
};
...
@@ -31,7 +29,6 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
...
@@ -31,7 +29,6 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));
});
});
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
$
.
url
.
onhashchange
(
function
()
{
$
.
url
.
onhashchange
(
function
()
{
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
function
()
{
function
()
{
...
@@ -40,9 +37,10 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
...
@@ -40,9 +37,10 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
"
<p>Oups, seems the route '<b>
"
+
$
.
url
.
getPath
()
+
"
<
\
/b>' doesn't exist!<
\
/p>
"
+
"
<p>Oups, seems the route '<b>
"
+
$
.
url
.
getPath
()
+
"
<
\
/b>' doesn't exist!<
\
/p>
"
+
"
<a href='
"
+
$
.
url
.
generateUrl
(
""
)
+
"
'>Go back to home<
\
/a>
"
);
"
<a href='
"
+
$
.
url
.
generateUrl
(
""
)
+
"
'>Go back to home<
\
/a>
"
);
// All routes have been deleted by fail.
// All routes have been deleted by fail.
// Recreate the default one.
// XXX: Recreate the default routes using RouteGadget
//initialize_route.apply(this, []);
$
(
"
div[data-gadget-route]
"
).
each
(
function
(
index
,
element
)
{
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
RenderJs
.
RouteGadget
.
route
(
$
(
element
));
});
});
});
});
});
});
});
...
...
renderjs.js
View file @
e417ed3b
...
@@ -794,6 +794,7 @@ var RenderJs = (function () {
...
@@ -794,6 +794,7 @@ var RenderJs = (function () {
var
gadget_id
=
gadget_route
.
destination
.
split
(
'
.
'
)[
0
],
var
gadget_id
=
gadget_route
.
destination
.
split
(
'
.
'
)[
0
],
method_id
=
gadget_route
.
destination
.
split
(
'
.
'
)[
1
],
method_id
=
gadget_route
.
destination
.
split
(
'
.
'
)[
1
],
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
// XXX: pass passed to us arguments + gadget_id
gadget
[
method_id
](
gadget_id
=
gadget_id
);
gadget
[
method_id
](
gadget_id
=
gadget_id
);
};
};
// add route itself
// add route itself
...
...
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