Client Side code

I am using Jquery as JS library for this project. One powerful feature of CRX is everything is stored in repository, Which is /etc/dvdretnal in our case.



Then they are included using /apps/dvdrental/global/include.jsp

See in the code how js and css included dynamically. You just have to drop js under /etc/dvdrental/js and css under /etc/dvdrental/css. See one section,

Node nodes =  (resourceResolver.resolve("/etc/dvdrental/css/")).adaptTo(Node.class);
INodeHelper nodeHelper = new NodeHelper();
Set<String> allnodes = null;
allnodes = nodeHelper.getAllNodes(nodes);
for(String node:allnodes){
%>
<link rel="stylesheet" href="<%=node %>" type="text/css">
<%} 
//Now add all java script

nodes =  (resourceResolver.resolve("/etc/dvdrental/js/")).adaptTo(Node.class);
allnodes = null;
allnodes = nodeHelper.getAllNodes(nodes);
for(String node:allnodes){
%>
<script language="javascript" type="text/javascript" src="<%=node %>"></script>
<%} %>


This approach might not be useful if you want to include only js file to a page. But this is just to show how powerful CRX can be.


Comments