(Jump to other KnowledgeBases)
DSpace Resources
DSpace Website
DSpace Documentation
DSpace Wiki
DSpace Demo Site
Contribute to KnowledgBase
In this manual we'll setup and enable jQuery javascript libraries instead of default scriptaculous ones, they both have great effects and functionalities so we can choose the one that best fits our interest, or knowledge.
Note: We'll add jqueryui (jquery user interface) libraries too. With them will be easy to generate visual effects or use widgets like calendars, progressbars ...
Using simple on/off switches defined in <dspace:layout> element we'll allow DSpace .jsp pages to load or not this script files. Example:
<dspace:layout titlekey="jsp.search.results.title" navbar="off" locbar="off" scriptaculous="off" jquery="on">
<dspace:layout titlekey="jsp.search.results.title" navbar="off" locbar="off" scriptaculous="on" jquery="off">
<dspace:layout titlekey="jsp.search.results.title" navbar="off" locbar="off" scriptaculous="off" jquery="off">
First we'll take a look to the current use of script libraries in DSpace and later we'll start modifying source files.
DSpace JSPUI interface bundles scriptaculous javascript libraries in every page head section. We can check that looking at source code of DSpace home page, we'll see this few lines:
<script type="text/javascript" src="/jspui/static/js/scriptaculous/prototype.js"> </script> <script type="text/javascript" src="/jspui/static/js/scriptaculous/effects.js"> </script> <script type="text/javascript" src="/jspui/static/js/scriptaculous/builder.js"> </script> <script type="text/javascript" src="/jspui/static/js/scriptaculous/controls.js"> </script>
Doing a litle browsing we can check that this libraries (prototype) are used in a library function:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/static/js/choice-support.js
This function is called on the following java server pages:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/submit/edit-metadata.jsp
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp//tools/edit-item-form.jsp
By now we know which pages use scriptaculous, , let's see jQuery.
DSpace already uses a copy of jQuery, but in a local form. The library function that uses it is:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/dspace-admin/js/bitstream-ordering.js
This function is called on the following java server page:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/tools/edit-item-form.jsp
And jQuery library file can be located on:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/dspace-admin/js/jquery-1.4.2.min.js
Now that every script file and script file caller is located we'll start to code.
In this examples we'll overwrite existing source code files, if you feel comfortable working with JSPUI modules can move this modifications to "dspace/modules/jspui" folder.
We'll create a folder to accommodate jQuery and jQuery-UI script files in
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/static/js/jqueryui/
First we must download jquery and jquery-ui script libraries from jQuery UI webpage, we'll download it's full version so we can use more functionalities on future modifications. All files are zipped inside a structure like this:
We'll use only js and css folders for our purposes. I'll describe selected folders content:
Filename changes
Newer versions of jqueryui can contain different filenames that the ones provided in this manual, take care that your downloaded files match the references on your .jsp file
We'll create a new folder inside dspace-source/dspace-jspui/dspace-jspui-webapp/src/main/webapp/static/js/jqueryui and copy all previously described files inside it..Structure will look like this:* dspace-source/dspace-jspui/dspace-jspui-webapp/src/main/webapp/static/js/jqueryui/jquery-1.7.2.min.js
We must define inside dspace tag library descriptor a pair of variables that will be used in LayoutTag class file: scriptaculous and jquery.
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/WEB-INF/dspace-tags.tld
Then we must add the private variables and it's getter and setters:
[dspace-source]/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/jsptag/LayoutTag.java
Once our variables are declared in our layout tag, we'll use them in header-default.jsp file. The one that renders header section of every page displayed by DSpace.
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/layout/header-default.jsp
With this code all .jsp pages that use <dspace:layout> (majority in DSpace) will load only scriptaculous libraries. In other words will behave as previous modifications.
Now all we have to do is change <dspace:layout> tag with our new variables where we want to load jQuery libraries. To test that everything is working properly we'll try to set focus on search textbox in JSPUI home page using jQuery .focus() function. We'll modify this file:
[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/home.jsp
Then just run package and ant update to watch your function in action.
Note: If you want to work with only one version of jQuery you must delete jquery-1.4.2.min.js file, enable jquery on edit-item-form.jsp layout tag and delete jquery-1.4.2 library reference.
The advantage of using variables is that our pages will load only necessary script libraries and it makes easier to update library versions site-wide. And you can change jQuery for any other script library of you choice or add more libraries.