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
Sven Franck
renderjs
Commits
384df48f
Commit
384df48f
authored
Feb 18, 2013
by
Ivan Tyagov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extend RouteGadget. Make use of new API in examples.
parent
09817dc3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
58 deletions
+70
-58
examples/route/gadget-color-picker.html
examples/route/gadget-color-picker.html
+27
-33
examples/route/require-renderjs_route.js
examples/route/require-renderjs_route.js
+16
-18
renderjs.js
renderjs.js
+27
-7
No files found.
examples/route/gadget-color-picker.html
View file @
384df48f
...
@@ -10,20 +10,16 @@
...
@@ -10,20 +10,16 @@
// dirty way to get which is actual gadget we are used for
// dirty way to get which is actual gadget we are used for
gadget_id
=
$
(
"
.body
"
).
parent
().
attr
(
"
id
"
)
gadget_id
=
$
(
"
.body
"
).
parent
().
attr
(
"
id
"
)
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
gadget_id
);
// define entry point which handles an url
gadget
.
render
=
function
(){
gadget
.
render
=
function
(){
var
body
=
$
(
"
.body
"
);
var
body
=
$
(
"
.body
"
),
handler_func
;
// Home route. Redirect to sub app /color/
body
.
route
(
"
add
"
,
""
,
1
)
.
done
(
function
()
{
// Default route. Redirect to color subapp
$
.
url
.
redirect
(
'
/color/
'
);
});
// /color app. Create subroutes and initialize DOM
// Default route. Redirect to color subapp
body
RenderJs
.
RouteGadget
.
add
(
""
,
.
route
(
"
add
"
,
"
/color<path:params>
"
,
1
)
function
()
{
$
.
url
.
redirect
(
'
/color/
'
);},
1
);
.
done
(
function
()
{
handler_func
=
function
()
{
var
i
,
j
,
k
,
increment
=
150
,
page
,
container
;
var
i
,
j
,
k
,
increment
=
150
,
page
,
container
;
// Container for the selected color
// Container for the selected color
page
=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
unknown
"
)
+
"
'>Wrong global route<a>
"
;
page
=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
unknown
"
)
+
"
'>Wrong global route<a>
"
;
...
@@ -45,29 +41,27 @@
...
@@ -45,29 +41,27 @@
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-one/
"
)
+
"
'>Gadget 1</a>
"
;
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-one/
"
)
+
"
'>Gadget 1</a>
"
;
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-two/
"
)
+
"
'>Gadget 2</a>
"
;
page
+=
"
<a href='
"
+
$
.
url
.
generateUrl
(
"
/gadget-two/
"
)
+
"
'>Gadget 2</a>
"
;
page
+=
"
<div class='container'></div>
"
;
page
+=
"
<div class='container'></div>
"
;
$
(
'
.body
'
)
.
html
(
page
);
body
.
html
(
page
);
// Create sub routed in the container
// Create sub routed in the container
container
=
$
(
this
).
find
(
"
div
"
);
RenderJs
.
RouteGadget
.
add
(
"
/color/
"
,
container
function
()
{
.
route
(
"
add
"
,
"
/color/
"
,
2
)
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);},
2
);
.
done
(
function
()
{
RenderJs
.
RouteGadget
.
add
(
"
/color/<int:red>/<int:green>/<int:blue>/
"
,
$
(
'
.select-color
'
).
text
(
"
Please select a color
"
);
function
(
red
,
green
,
blue
)
{
});
$
(
'
.select-color
'
).
html
(
container
"
<div style='background-color:rgb(
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
);'> <
\
/div>
"
+
.
route
(
"
add
"
,
"
/color/<int:red>/<int:green>/<int:blue>/
"
,
2
)
"
<p>Color (
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
) selected at
"
+
new
Date
()
+
"
<
\
/p>
"
);},
.
done
(
function
(
red
,
green
,
blue
)
{
2
);
$
(
'
.select-color
'
).
html
(
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
"
<div style='background-color:rgb(
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
);'> <
\
/div>
"
+
function
()
{
"
<p>Color (
"
+
red
+
"
,
"
+
green
+
"
,
"
+
blue
+
"
) selected at
"
+
new
Date
()
+
"
<
\
/p>
"
$
(
'
.select-color
'
).
html
(
"
Unknown color (
"
+
$
.
url
.
getPath
()
+
"
)
"
);},
);
2
);
});
};
container
.
route
(
"
go
"
,
$
.
url
.
getPath
(),
2
)
// /color app. Create subroutes and initialize DOM
.
fail
(
function
()
{
RenderJs
.
RouteGadget
.
add
(
"
/color<path:params>
"
,
handler_func
,
1
);
$
(
'
.select-color
'
).
html
(
"
Unknown color (
"
+
$
.
url
.
getPath
()
+
"
)
"
);
});
});
};
};
});
});
//]]>
//]]>
...
...
examples/route/require-renderjs_route.js
View file @
384df48f
...
@@ -18,34 +18,32 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
...
@@ -18,34 +18,32 @@ require([ "renderjs", "require-renderjs", "jquery", "route", "url" ], function(d
// XXX: try to encapsulate this in router gadget
// XXX: try to encapsulate this in router gadget
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
main-router
"
);
gadget
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
main-router
"
);
gadget
.
gadget_one
=
function
(){
gadget
.
gadget_one
=
function
(){
console
.
log
(
"
gadget-one
"
);
// 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
=
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
main-router
"
);
gadget
.
gadget_two
=
function
(){
gadget
.
gadget_two
=
function
(){
console
.
log
(
"
gadget-two
"
);
// we use interactionGadget which will call proper gadgets' function
// we use interactionGadget which will call proper gadgets' function
};
};
// XXX: fid why interaction gadget is not initialized proeprly yet
// XXX: fid why interaction gadget is not initialized properly yet
RenderJs
.
InteractionGadget
.
bind
(
$
(
"
#main-interactor
"
))
$
(
"
div[data-gadget-connection]
"
).
each
(
function
(
index
,
element
)
{
RenderJs
.
InteractionGadget
.
bind
(
$
(
element
));
});
var
body
=
$
(
"
body
"
);
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
$
.
url
.
onhashchange
(
function
()
{
$
.
url
.
onhashchange
(
function
()
{
body
RenderJs
.
RouteGadget
.
go
(
$
.
url
.
getPath
(),
.
route
(
"
go
"
,
$
.
url
.
getPath
())
function
()
{
.
fail
(
function
()
{
// Method to display error to the user
// Method to display error to the user
$
(
this
).
html
(
$
(
this
).
html
(
"
<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.
);
// Recreate the default one.
// All routes have been deleted by fail.
//initialize_route.apply(this, []);
// Recreate the default one.
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
//initialize_route.apply(this, []);
});
RenderJs
.
GadgetIndex
.
getGadgetById
(
"
gadget-color-picker
"
).
render
();
});
});
});
});
});
});
});
renderjs.js
View file @
384df48f
...
@@ -768,19 +768,39 @@ var RenderJs = (function () {
...
@@ -768,19 +768,39 @@ var RenderJs = (function () {
* Create routes between gadgets.
* Create routes between gadgets.
*/
*/
var
body
=
$
(
"
body
"
),
var
body
=
$
(
"
body
"
),
handler_func
,
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
)
{
// add route itself
handler_func
=
function
()
{
body
.
route
(
"
add
"
,
gadget_route
.
source
,
1
)
.
done
(
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
);
gadget
[
method_id
]();
gadget
[
method_id
]();
});
};
// add route itself
RenderJs
.
RouteGadget
.
add
(
gadget_route
.
source
,
handler_func
,
1
);
});
});
},
add
:
function
(
path
,
handler_func
,
priority
)
{
/*
* Add a route between path (hashable) and a handler function (part of Gadget's API).
*/
var
body
=
$
(
"
body
"
);
body
.
route
(
"
add
"
,
path
,
1
)
.
done
(
handler_func
);
},
go
:
function
(
path
,
handler_func
,
priority
)
{
/*
* Go a route.
*/
var
body
=
$
(
"
body
"
);
body
.
route
(
"
go
"
,
path
,
priority
)
.
fail
(
handler_func
);
}
}
};
};
}())
}())
...
...
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