1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/copyleft/gpl.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
49 Returns DOM node or array of nodes (if more then one argument passed).
50 If argument is node object allready then do nothing.
51 // Stolen from Prototype
54 var elements = new Array();
56 for (var i = 0; i < arguments.length; i++) {
57 var element = arguments[i];
58 if (typeof element == 'string')
59 element = document.getElementById(element);
61 if (arguments.length == 1)
64 elements.push(element);
72 function show(id) { delClass( id, 'hidden' ) }
73 function hide(id) { addClass( id, 'hidden' ) }
75 function hideshow(id) { return toggleVisibility( id ) }
76 function toggleVisibility(id) {
79 if ( e.className.match( /\bhidden\b/ ) )
87 function setVisibility(id, visibility) {
88 if ( visibility ) show(id);
92 function switchVisibility(id1, id2) {
93 // Show both and then hide the one we want
102 function addClass(id, value) {
104 if ( e.className.match( new RegExp('\b'+ value +'\b') ) )
106 e.className += e.className? ' '+value : value;
109 function delClass(id, value) {
111 e.className = e.className.replace( new RegExp('\\s?\\b'+ value +'\\b', 'g'), '' );
116 function rollup(id) {
118 var e2 = e.parentNode;
120 if (e.className.match(/\bhidden\b/)) {
121 set_rollup_state(e,e2,'shown');
122 createCookie(id,1,365);
125 set_rollup_state(e,e2,'hidden');
126 createCookie(id,0,365);
131 function set_rollup_state(e,e2,state) {
133 if (state == 'shown') {
135 delClass( e2, 'rolled-up' );
137 else if (state == 'hidden') {
139 addClass( e2, 'rolled-up' );
145 /* onload handlers */
147 var onLoadStack = new Array();
148 var onLoadLastStack = new Array();
149 var onLoadExecuted = 0;
151 function onLoadHook(commandStr) {
152 if(typeof(commandStr) == "string") {
153 onLoadStack[ onLoadStack.length ] = commandStr;
159 // some things *really* need to be done after everything else
160 function onLoadLastHook(commandStr) {
161 if(typeof(commandStr) == "string"){
162 onLoadLastStack[onLoadLastStack.length] = commandStr;
168 function doOnLoadHooks() {
169 if(onLoadExecuted) return;
172 for ( i in onLoadStack ) {
173 eval( onLoadStack[i] );
175 for ( i in onLoadLastStack ) {
176 eval( onLoadLastStack[i] );
181 window.onload = doOnLoadHooks;
183 /* calendar functions */
185 function openCalWindow(field) {
186 var objWindow = window.open('<%$RT::WebPath%>/Helpers/CalPopup.html?field='+field,
188 'height=235,width=285,scrollbars=1');
192 function createCalendarLink(input) {
195 var link = document.createElement('a');
196 link.setAttribute('href', '#');
198 clickevent = function clickevent(e) { openCalWindow(input); return false; };
199 if (! addEvent(link, "click", clickevent)) {
203 var text = document.createTextNode('<% loc("Choose a date") %>');
204 link.appendChild(text);
206 var space = document.createTextNode(' ');
208 e.parentNode.insertBefore(link, e.nextSibling);
209 e.parentNode.insertBefore(space, e.nextSibling);
218 function focusElementById(id) {
223 function updateParentField(field, value) {
225 window.opener.$(field).value = value;
230 function addEvent(obj, sType, fn) {
231 if (obj.addEventListener) {
232 obj.addEventListener(sType, fn, false);
233 } else if (obj.attachEvent) {
234 var r = obj.attachEvent("on"+sType, fn);
241 function setCheckbox(form, name, val) {
242 var myfield = form.getElementsByTagName('input');
243 for ( var i = 0; i < myfield.length; i++ ) {
244 if ( name && myfield[i].name != name ) continue;
245 if ( myfield[i].type != 'checkbox' ) continue;
247 myfield[i].checked = val;