source: trunk/www/common/zoom.jsp @ 3041

Last change on this file since 3041 was 3041, checked in by Martin Svensson, 15 years ago

Misspelt style name

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 8.0 KB
Line 
1<%-- $Id: zoom.jsp 3041 2006-12-18 14:59:58Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  Open a larger window for editing text in a textarea.
25
26  @param title The title of the input field that is zoomed
27  @param form The name of the form where the zoomed input field is located
28  @param textarea The name of the textarea that is zoomed
29
30  @author Nicklas
31  @version 2.0
32--%>
33<%@ page session="false"
34  import="net.sf.basedb.util.Values"
35%>
36<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
37<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
38<%@ taglib prefix="m" uri="/WEB-INF/menu.tld" %>
39<%
40  String title = request.getParameter("title");
41  String form = request.getParameter("form");
42  String textarea = request.getParameter("textarea");
43  boolean disabled = Values.getBoolean(request.getParameter("disabled"));
44  String callback = request.getParameter("callback");
45%>
46<base:page type="popup" title="<%=title%>">
47<base:head scripts="menu.js" styles="menu.css,help.css">
48  <script language="JavaScript">
49  function getText()
50  {
51    var frm = document.forms["zoom"];
52    frm.zoom.value = window.opener.document.forms['<%=form%>'].elements['<%=textarea%>'].value;
53    frm.zoom.focus();
54  }
55  function setTextAndClose()
56  {
57    var value = document.forms["zoom"].zoom.value;
58    var element = window.opener.document.forms['<%=form%>'].elements['<%=textarea%>'];
59    element.value = value;
60    element.focus();
61    <%
62    if (callback != null)
63    {
64      %>
65      window.opener.<%=callback%>(value);
66      <%
67    }
68    %>
69    window.close();
70  }
71 
72  /*
73    Enclose the selected text with prefix and suffix. Code taken
74    from Trac: http://projects.edgewall.com/trac/
75  */
76  function encloseSelection(prefix, suffix)
77  {
78    var frm = document.forms['zoom'];
79    var textarea = frm.zoom;
80    textarea.focus();
81      var start, end, sel, scrollPos, subst;
82      if (typeof(document["selection"]) != "undefined")
83      {
84        sel = document.selection.createRange().text;
85      }
86      else if (typeof(textarea["setSelectionRange"]) != "undefined")
87      {
88        start = textarea.selectionStart;
89        end = textarea.selectionEnd;
90        scrollPos = textarea.scrollTop;
91        sel = textarea.value.substring(start, end);
92      }
93      if (sel.match(/ $/))
94      {
95        // exclude ending space char, if any
96          sel = sel.substring(0, sel.length - 1);
97          suffix = suffix + " ";
98      }
99      subst = prefix + sel + suffix;
100      if (typeof(document["selection"]) != "undefined")
101      {
102        var range = document.selection.createRange().text = subst;
103        textarea.caretPos -= suffix.length;
104      }
105      else if (typeof(textarea["setSelectionRange"]) != "undefined")
106      {
107        textarea.value = textarea.value.substring(0, start) + subst +
108                         textarea.value.substring(end);
109        if (sel)
110        {
111          textarea.setSelectionRange(start + subst.length, start + subst.length);
112        }
113        else
114        {
115          textarea.setSelectionRange(start + prefix.length, start + prefix.length);
116        }
117        textarea.scrollTop = scrollPos;
118      }
119  }
120  </script>
121</base:head>
122<base:body onload="getText()">
123  <m:menu
124    id="listtype"
125    style="display: none;">     
126  <m:menuitem 
127    title="Ordered list" 
128    onclick="encloseSelection('&lt;ol&gt&lt;li&gt;', '&lt;/li&gt;&lt;/ol&gt;')"
129    tooltip="Insert an ordered list"
130  />
131  <m:menuitem
132    title="Unordered list"
133    onclick="encloseSelection('&lt;ul&gt;&lt;li&gt;', '&lt;/li&gt;&lt;/ul&gt;')"
134    tooltip="Insert an unordered list"
135  />     
136  </m:menu>
137  <%
138  String tableInsert = "encloseSelection('&lt;table class=&quot;explanation&quot;&gt;', '&lt;/table&gt;')";
139  %>
140  <m:menu
141    id="tableitem"
142    style="display: none;">
143  <m:menuitem
144    title="Table"
145    onclick="<%=tableInsert%>"
146    tooltip="Insert a table"
147  />
148  <m:menuitem
149    title="Row"
150    onclick="encloseSelection('&lt;tr&gt;', '&lt;/tr&gt;')"
151    tooltip="Insert a row in a table"
152  />
153  <m:menuitem
154    title="Cell"
155    onclick="encloseSelection('&lt;td&gt;', '&lt;/td&gt;')"
156    tooltip="Insert a cell in a table row"
157  />
158  </m:menu>
159  <m:menu
160    id="textformats"
161    style="display: none;">
162  <m:menuitem
163    title="Important"
164    onclick="encloseSelection('&lt;imp&gt;', '&lt/imp&gt;')"
165    tooltip="Mark text as important"
166  />
167  <m:menuitem
168    title="User input"
169    onclick="encloseSelection('&lt;ui&gt;', '&lt/ui&gt;')"
170    tooltip="Mark text as user input."
171  />
172  <m:menuitem
173    title="Required"
174    onclick="encloseSelection('&lt;req&gt;', '&lt/req&gt;')"
175    tooltip="Mark text as required user input"
176  />
177  </m:menu>   
178  <form name="zoom" onsubmit="return false;">
179    <table align="center">
180    <tr>
181    <td>
182      <h3 class="docked"><%=title%> <base:help helpid="zoom.edit" /></h3>
183      <%
184      if (form.equals("help"))
185      {
186      %>
187        <tbl:toolbar clazz="editbar">                       
188          <tbl:button 
189            tooltip="Bold"
190            clazz="buttonclass"
191            image="text_bold.png"
192            onclick="encloseSelection('&lt;b&gt;', '&lt;/b&gt;')"
193          />
194          <tbl:button
195            tooltip="Italic"             
196            clazz="buttonclass"
197            image="text_italic.png"
198            onclick="encloseSelection('&lt;i&gt;', '&lt;/i&gt;')"
199          />
200          <tbl:button
201            tooltip="Underline"
202            clazz="buttonclass"
203            image="text_underline.png"
204            onclick="encloseSelection('&lt;u&gt;', '&lt;/u&gt;')"
205          />                     
206          <tbl:button
207            tooltip="Header 3"
208            clazz="buttonclass"
209            style="padding: 1px;"
210            image="text_h3.png"
211            onclick="encloseSelection('&lt;h3&gt;', '&lt;/h3&gt;')"
212          />
213          <tbl:button
214            tooltip="Header 4"
215            clazz="buttonclass"
216            style="padding: 1px;"
217            image="text_h4.png"
218            onclick="encloseSelection('&lt;h4&gt;', '&lt;/h4&gt;')"
219          />
220          <tbl:button
221            tooltip="Textstyle"
222            clazz="buttonclass"
223            image="text_style_edit.gif"
224            onclick="Menu.toggleTopMenu(document.getElementById('textformats'), event.clientX, event.clientY); event.cancelBubble = true;"
225          />           
226          <tbl:button
227            tooltip="Table"
228            clazz="buttonclass"
229            image="text_table.png"
230            onclick="Menu.toggleTopMenu(document.getElementById('tableitem'), event.clientX, event.clientY); event.cancelBubble = true;"
231          />
232          <tbl:button
233            tooltip="List"
234            clazz="buttonclass"
235            image="text_list.gif"
236            onclick="Menu.toggleTopMenu(document.getElementById('listtype'), event.clientX, event.clientY); event.cancelBubble = true;"
237          />
238          <tbl:button
239            tooltip="New line"
240            image="text_newline.gif" 
241            clazz="buttonclass"
242            onclick="encloseSelection('&lt;br&gt;', '')"
243          />
244          <tbl:button
245            tooltip="New paragraph"
246            clazz="buttonclass"
247            image="text_paragraph.gif"
248            onclick="encloseSelection('&lt;p&gt;', '&lt;/p&gt;')"
249          />           
250        </tbl:toolbar>
251        <%
252      }
253      %>
254      <textarea name="zoom" rows="30" cols="80" wrap="soft" 
255        <%=disabled ? "class=\"disabled\" disabled readonly" : ""%>></textarea>
256    </td>
257    </tr>
258    </table>
259 
260    <%
261    if (disabled)
262    {
263      %>
264      <table align="center">
265      <tr>
266        <td><base:button onclick="window.close()" title="Close" /></td>
267      </tr>
268      </table>
269      <%
270    }
271    else
272    {
273      %>
274      <table align="center">
275      <tr>
276        <td width="50%"><base:button onclick="setTextAndClose()" title="Ok" /></td>
277        <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
278      </tr>
279      </table>
280      <%
281    }
282    %>
283  </form>
284</base:body>
285</base:page>
Note: See TracBrowser for help on using the repository browser.