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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Klaus Wölfel
renderjs
Commits
3c081ec2
Commit
3c081ec2
authored
Feb 18, 2013
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use RouteGadget API to clean up.
Extend RouteGadget API to test multiple routers per page.
parent
384df48f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
39 deletions
+72
-39
examples/route/gadget-color-picker.html
examples/route/gadget-color-picker.html
+25
-27
examples/route/require-renderjs_route.js
examples/route/require-renderjs_route.js
+1
-1
test/renderjs_test.js
test/renderjs_test.js
+31
-8
test/route/gadget-one.html
test/route/gadget-one.html
+7
-1
test/route/index.html
test/route/index.html
+8
-2
No files found.
examples/route/gadget-color-picker.html
View file @
3c081ec2
...
...
@@ -2,7 +2,26 @@
<head></head>
<body>
<h2>
Color picker
</h2>
<div
class=
"body"
></div>
<div
class=
"body"
>
<a
href=
"#unknown"
>
Wrong global route
</a>
<ul
style=
"list-style: none;"
>
<li><a
href=
"#/color/0/0/0/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(0,0,0);"
>
</a></li>
<li><a
href=
"#/color/0/0/150/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(0,0,150);"
>
</a></li>
<li><a
href=
"#/color/0/150/0/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(0,150,0);"
>
</a></li>
<li><a
href=
"#/color/0/150/150/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(0,150,150);"
>
</a></li>
<li><a
href=
"#/color/150/0/0/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(150,0,0);"
>
</a></li>
<li><a
href=
"#/color/150/0/150/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(150,0,150);"
>
</a></li>
<li><a
href=
"#/color/150/150/0/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(150,150,0);"
>
</a></li>
<li><a
href=
"#/color/150/150/150/"
style=
"text-decoration: none; display: block; width: 2em; background-color:rgb(150,150,150);"
>
</a></li>
<li
style=
"text-align: center;"
><a
href=
"#/color/X/X/X"
style=
"text-decoration: none; display: block; width: 2em;"
>
XXX
</a></li>
</ul>
<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>
<script
type=
"text/javascript"
language=
"javascript"
>
//
<!
[
CDATA
[
...
...
@@ -13,40 +32,20 @@
// define entry point which handles an url
gadget
.
render
=
function
(){
var
body
=
$
(
"
.body
"
),
handler_func
;
var
handler_func
;
// Default route. Redirect to color subapp
RenderJs
.
RouteGadget
.
add
(
""
,
function
()
{
$
.
url
.
redirect
(
'
/color/
'
);},
1
);
function
()
{
$
.
url
.
redirect
(
'
/color/
'
);},
1
);
handler_func
=
function
()
{
var
i
,
j
,
k
,
increment
=
150
,
page
,
container
;
// Container for the selected color
page
=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
unknown
"
)
+
"
'>Wrong global route<a>
"
;
page
+=
"
<ul style='list-style: none;'>
"
;
for
(
i
=
0
;
i
<
256
;
i
+=
increment
)
{
for
(
j
=
0
;
j
<
256
;
j
+=
increment
)
{
for
(
k
=
0
;
k
<
256
;
k
+=
increment
)
{
page
+=
"
<li><a style='text-decoration: none; display: block; width: 2em;
"
+
"
background-color:rgb(
"
+
i
+
"
,
"
+
j
+
"
,
"
+
k
+
"
);'
"
+
"
href='
"
+
$
.
url
.
generateUrl
(
"
/color/
"
+
i
+
"
/
"
+
j
+
"
/
"
+
k
+
"
/
"
)
+
"
'
"
+
"
> <
\
/a><
\
/li>
"
;
}
}
}
page
+=
"
<li style='text-align: center;'><a style='text-decoration: none; display: block; width: 2em;' href='
"
+
$
.
url
.
generateUrl
(
"
/color/X/X/X
"
)
+
"
'>XXX<a><
\
/li>
"
;
page
+=
"
<
\
/ul>
"
;
page
+=
"
<div style='display: block;' class='select-color'><
\
/div>
"
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-one/
"
)
+
"
'>Gadget 1</a>
"
;
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-two/
"
)
+
"
'>Gadget 2</a>
"
;
page
+=
"
<div class='container'></div>
"
;
body
.
html
(
page
);
// Create sub routed in the container
RenderJs
.
RouteGadget
.
add
(
"
/color/
"
,
function
()
{
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);},
2
);
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);},
2
);
RenderJs
.
RouteGadget
.
add
(
"
/color/<int:red>/<int:green>/<int:blue>/
"
,
function
(
red
,
green
,
blue
)
{
$
(
'
.select-color
'
).
html
(
...
...
@@ -61,7 +60,6 @@
// /color app. Create subroutes and initialize DOM
RenderJs
.
RouteGadget
.
add
(
"
/color<path:params>
"
,
handler_func
,
1
);
};
});
//]]>
...
...
examples/route/require-renderjs_route.js
View file @
3c081ec2
...
...
@@ -26,7 +26,7 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
// we use interactionGadget which will call proper gadgets' function
};
//
XXX: fid why interaction gadget is not initialized properly yet
//
we have to re-bind interaction gadget as main-route API implemantation changed
$
(
"
div[data-gadget-connection]
"
).
each
(
function
(
index
,
element
)
{
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));
});
...
...
test/renderjs_test.js
View file @
3c081ec2
...
...
@@ -245,25 +245,48 @@ function setupRenderJSTest(){
RenderJs
.
bindReady
(
function
()
{
start
();
// initialize route gadget as it's loaded asynchronously
RenderJs
.
RouteGadget
.
route
(
$
(
"
#main-router
"
));
$
(
"
div[data-gadget-route]
"
).
each
(
function
(
index
,
element
)
{
RenderJs
.
RouteGadget
.
route
(
$
(
element
));
});
// listen to event and do actual routing
$
.
url
.
onhashchange
(
function
()
{
var
body
=
$
(
"
body
"
);
body
.
route
(
"
go
"
,
$
.
url
.
getPath
())
.
fail
(
function
()
{
alert
(
"
no route
"
);
});
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
function
()
{
console
.
log
(
"
no route
"
);});
});
$
.
url
.
go
(
'
/gadget-one/
'
);
// give some time so .render finishes, most likely we need some event like .bindReady
// to indicate that respective .render method finishes in generic RenderJs ?
stop
();
setTimeout
(
function
()
{
start
();
// respective gadget .render method must be called and global var changed
equal
(
1
,
route_changed
);
equal
(
'
/gadget-one/
'
,
window
.
location
.
toString
().
split
(
'
#
'
)[
1
]);
start
();
$
.
url
.
go
(
'
/gadget-two/
'
);
stop
();
setTimeout
(
function
()
{
// respective gadget .render method must be called and global var changed
equal
(
2
,
route_changed
);
equal
(
'
/gadget-two/
'
,
window
.
location
.
toString
().
split
(
'
#
'
)[
1
]);
start
();
$
.
url
.
go
(
'
/gadget-three/
'
);
stop
();
setTimeout
(
function
()
{
// respective gadget .render method must be called and global var changed
equal
(
3
,
route_changed
);
equal
(
'
/gadget-three/
'
,
window
.
location
.
toString
().
split
(
'
#
'
)[
1
]);
start
();
},
1000
);
},
1000
);
},
1000
);
});
});
...
...
test/route/gadget-one.html
View file @
3c081ec2
...
...
@@ -5,9 +5,15 @@
//
<!
[
CDATA
[
$
(
document
).
ready
(
function
()
{
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-one
"
);
gadget
.
gadget_one
=
function
(){
gadget
.
gadget_one
=
function
()
{
route_changed
=
1
;
// so we can test this method was actually called from qunit
};
gadget
.
gadget_two
=
function
()
{
route_changed
=
2
;
// so we can test this method was actually called from qunit
};
gadget
.
gadget_three
=
function
()
{
route_changed
=
3
;
// so we can test this method was actually called from qunit
};
});
//]]>
</script>
...
...
test/route/index.html
View file @
3c081ec2
...
...
@@ -4,14 +4,20 @@
<title></title>
<meta
name=
"viewport"
content=
"width=device-width, height=device-height, initial-scale=1"
/>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
</head>
<body>
<div
data-gadget=
""
id=
"main-router"
data-gadget-route=
"[
{"source": "/gadget-one/", "destination": "gadget-one.gadget_one"}]"
>
{"source": "/gadget-one/", "destination": "gadget-one.gadget_one"},
{"source": "/gadget-two/", "destination": "gadget-one.gadget_two"}]"
>
</div>
<div
data-gadget=
""
id=
"suplimentary-router"
data-gadget-route=
"[
{"source": "/gadget-three/", "destination": "gadget-one.gadget_three"}]"
>
</div>
<div
id=
"gadget-one"
...
...
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