Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

By now we know which pages use scriptaculous. We'll keep them in mind to later come back and modify them.

jQuery libraries

DSpace already uses a copy of jQuery, but in a local form. The library function that uses it is:

...

Code Block
languagejava
collapsetrue
<%--

    The contents of this file are subject to the license and copyright
    detailed in the LICENSE and NOTICE files at the root of the source
    tree and available online at

    http://www.dspace.org/license/

--%>
<%--
  - HTML header for main home page
  --%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.dspace.org/dspace-tags.tld" prefix="dspace" %>

<%@ page contentType="text/html;charset=UTF-8" %>

<%@ page import="java.util.List"%>
<%@ page import="java.util.Enumeration"%>
<%@ page import="org.dspace.app.webui.util.JSPManager" %>
<%@ page import="org.dspace.app.webui.util.UIUtil" %>
<%@ page import="org.dspace.core.ConfigurationManager" %>
<%@ page import="org.dspace.app.util.Util" %>
<%@ page import="org.dspace.browse.BrowseIndex" %>
<%@ page import="org.dspace.browse.BrowseInfo" %>
<%@ page import="javax.servlet.jsp.jstl.core.*" %>
<%@ page import="javax.servlet.jsp.jstl.fmt.*" %>

<%
    String title = (String) request.getAttribute("dspace.layout.title");
    String navbar = (String) request.getAttribute("dspace.layout.navbar");
    boolean locbar = ((Boolean) request.getAttribute("dspace.layout.locbar")).booleanValue();

    String siteName = ConfigurationManager.getProperty("dspace.name");
    String scriptaculous = (String) request.getAttribute("dspace.layout.scriptaculous");    //Added code
    String jquery = (String) request.getAttribute("dspace.layout.jquery");                  //Added code

    String feedRef = (String)request.getAttribute("dspace.layout.feedref");
    boolean osLink = ConfigurationManager.getBooleanProperty("websvc.opensearch.autolink");
    String osCtx = ConfigurationManager.getProperty("websvc.opensearch.svccontext");
    String osName = ConfigurationManager.getProperty("websvc.opensearch.shortname");
    List parts = (List)request.getAttribute("dspace.layout.linkparts");
    String extraHeadData = (String)request.getAttribute("dspace.layout.head");
    String dsVersion = Util.getSourceVersion();
    String generator = dsVersion == null ? "DSpace" : "DSpace "+dsVersion;
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <title><%= siteName %>: <%= title %></title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta name="Generator" content="<%= generator %>" />
        <link rel="stylesheet" href="<%= request.getContextPath() %>/styles.css" type="text/css" />
        <link rel="stylesheet" href="<%= request.getContextPath() %>/print.css" media="print" type="text/css" />
        <link rel="shortcut icon" href="<%= request.getContextPath() %>/favicon.ico" type="image/x-icon"/>


<%
    if (!"NONE".equals(feedRef))
    {
        for (int i = 0; i < parts.size(); i+= 3)
        {
%>
        <link rel="alternate" type="application/<%= (String)parts.get(i) %>" title="<%= (String)parts.get(i+1) %>" href="<%= request.getContextPath() %>/feed/<%= (String)parts.get(i+2) %>/<%= feedRef %>"/>
<%
        }
    }

    if (osLink)
    {
%>
        <link rel="search" type="application/opensearchdescription+xml" href="<%= request.getContextPath() %>/<%= osCtx %>description.xml" title="<%= osName %>"/>
<%
    }

    if (extraHeadData != null)
        { %>
<%= extraHeadData %>
<%
        }

%>
    if (scriptaculous == null || scriptaculous.equals("on"))           //Added code starts here
       {
%>
    <script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/prototype.js"> </script>
    <script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/effects.js"> </script>
    <script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/builder.js"> </script>
    <script type="text/javascript" src="<%= request.getContextPath() %>/static/js/scriptaculous/controls.js"> </script>
<%      }
    if (jquery != null && jquery.equals("on"))
    {
%>
	<script src="<%= request.getContextPath() %>/static/js/jquery/jquery-1.7.2.min.js" type="text/javascript"></script>
<%
    }                                                                 //Added code ends here
%>

...

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.

Modifying *.jsp files

<script type="text/javascript" src="<%= request.getContextPath() %>/utils.js"></script>
<!-- remove following references to scriptaculous libraries -->
<script type="text/javascript" src="<%= request.getContextPath() %>/static/js/choice-support.js"> </script>
...

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.

Modifying *.jsp files

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 set focus on search textbox in JSPUI home page using jQuery .focus() function.  We'll modify this file:

No Format

[dspace-source]/dspace-jspui/dspace-jspui-webapp/src/main/webapp/home.jsp
Code Block
languagehtml/xml
titlehome.jsp
collapsetrue
<dspace:layout locbar="nolink" titlekey="jsp.home.title" feedData="<%= feedData %>" scriptaculous="off" jquery="on">
<script type="text/javascript">
$(document).ready(function() {
	$("#tquery").focus();
});
</script>

Then just run package and ant update DSpace 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 and enable jquery on edit-item-form.jsp layout tag.Now all we have to do is  change <dspace:layout> tag to include our new variables.