Project

General

Profile

1
 /*
2
  *   '$RCSfile$'
3
  *     Purpose: Default style sheet for KNB project web pages 
4
  *              Using this stylesheet rather than placing styles directly in 
5
  *              the KNB web documents allows us to globally change the 
6
  *              formatting styles of the entire site in one easy place.
7
  *   Copyright: 2000 Regents of the University of California and the
8
  *               National Center for Ecological Analysis and Synthesis
9
  *     Authors: Matt Jones
10
  *
11
  *    '$Author: leinfelder $'
12
  *      '$Date: 2011-01-07 10:33:05 -0800 (Fri, 07 Jan 2011) $'
13
  *  '$Revision: 5783 $'
14
  *
15
  * This program is free software; you can redistribute it and/or modify
16
  * it under the terms of the GNU General Public License as published by
17
  * the Free Software Foundation; either version 2 of the License, or
18
  * (at your option) any later version.
19
  *
20
  * This program is distributed in the hope that it will be useful,
21
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
  * GNU General Public License for more details.
24
  *
25
  * You should have received a copy of the GNU General Public License
26
  * along with this program; if not, write to the Free Software
27
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
  */
29

    
30

    
31
/**
32
 *  NOTE: THIS SCRIPT EXPECTS YOU ALREADY TO HAVE IMPORTED THE FOLLOWING 
33
 *  VARIABLES, WHICH ARE TYPICALLY DEFINED IN style/skins/qformat/qformat.js:
34
 *
35
 *   Location of the header that will be displayed at the top of the page
36
 *  HEADER_URL 
37
 *
38
 *   Location of the header that will be displayed at the top of the page
39
 *  LEFTCOL_URL 
40
 *
41
 *   Location of the header that will be displayed at the top of the page
42
 *  RIGHTCOL_URL 
43
 *
44
 *   Location of the header that will be displayed at the top of the page
45
 *  FOOTER_URL 
46
 *
47
 * header iframe class
48
 *  IFRAME_HEADER_CLASS
49
 *
50
 * left column iframe class
51
 *  IFRAME_LEFTCOL_CLASS
52
 *
53
 * right column iframe class
54
 *  IFRAME_RIGHTCOL_CLASS
55
 *
56
 * footer iframe class
57
 *  IFRAME_FOOTER_CLASS
58
 *
59
 * entire table class
60
 *  TEMPLATE_TABLE_CLASS
61
 *
62
 * header table-cell class. Note you should not set css "width" on this, since it 
63
 * includes a colspan
64
 *  TEMPLATE_HEADERROW_CLASS
65
 *
66
 * left column table-cell class. Note that restricting css "height" on this may 
67
 * affect visibility of the main content, since it's in the same table row 
68
 *  TEMPLATE_LEFTCOL_CLASS
69
 *
70
 * main central content table-cell class. Note that css attributes set here may 
71
 * apply to the content nested inside this cell
72
 *  TEMPLATE_CONTENTAREA_CLASS
73
 *
74
 * rigth column table-cell class. Note that restricting css "height" on this may 
75
 * affect visibility of the main content, since it's in the same table row 
76
 *  TEMPLATE_RIGHTCOL_CLASS
77
 *
78
 * footer table-cell class. Note you should not set "width" on this, since it 
79
 * includes a colspan
80
 *  TEMPLATE_FOOTERROW_CLASS
81
 */
82
 
83
function prependUrl(prefix, path) {
84

    
85
	var retUrl = path;
86
	if ( !_isBlank(path) ) {
87
		if ( !_isBlank(prefix) ) {
88
			//check if absolute
89
			if (path.indexOf("http") < 0) {
90
				//check if the server has been assumed with a leading "/"
91
				if (path.indexOf("/") != 0) {
92
					retUrl = prefix + "/" + path;
93
				}
94
			}
95
		}
96
	}
97
	return retUrl;
98
}
99

    
100

    
101
/**
102
 *  inserts the first half of the template table that surrounds the page's'
103
 *  content, including the the optional header and left column areas
104
 *  referenced by the HEADER_URL and LEFTCOL_URL settings
105
 */
106
function insertTemplateOpening(serverContextUrl) {
107

    
108
  //table opening tag
109
  document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" "
110
                                  +" class=\""+TEMPLATE_TABLE_CLASS+"\">");
111
  //first row is header
112
  document.write("<tr><td "+_getColSpanString()+" class=\""+TEMPLATE_HEADERROW_CLASS+"\">");
113

    
114
  //make any relative paths into absolute paths
115
  HEADER_URL = prependUrl(serverContextUrl, HEADER_URL);
116
	
117
  //content for the header (if any)
118
  _createIFrameWithURL(HEADER_URL, IFRAME_HEADER_CLASS);
119

    
120
  document.write("</td></tr><tr>");
121

    
122
  //content for the left column (if any)
123
  if (!_isBlank(LEFTCOL_URL)) {
124

    
125
    document.write("<td class=\""+TEMPLATE_LEFTCOL_CLASS+"\">");
126

    
127
	//make any relative paths into absolute paths
128
	LEFTCOL_URL = prependUrl(serverContextUrl, LEFTCOL_URL);
129
  
130
    _createIFrameWithURL(LEFTCOL_URL, IFRAME_LEFTCOL_CLASS);
131

    
132
    document.write("</td>");
133
  }
134

    
135
  //main content area
136
  document.write("<td class=\""+TEMPLATE_CONTENTAREA_CLASS+"\">");
137
}
138

    
139
/**
140
 *  inserts the last half of the template table that surrounds the page's'
141
 *  content, including the optional right column and footer areas
142
 *  referenced by the RIGHTCOL_URL and FOOTER_URL settings
143
 */
144
function insertTemplateClosing(serverContextUrl) {
145

    
146
  //right column
147
  document.write("</td>");
148

    
149
  //content for the right column (if any)
150
  if (!_isBlank(RIGHTCOL_URL)) {
151

    
152
    document.write("<td class=\""+TEMPLATE_RIGHTCOL_CLASS+"\">");
153

    
154
	//make any relative paths into absolute paths
155
	RIGHTCOL_URL = prependUrl(serverContextUrl, RIGHTCOL_URL);
156
	
157
    _createIFrameWithURL(RIGHTCOL_URL, IFRAME_RIGHTCOL_CLASS);
158

    
159
    document.write("</td>");
160
  }
161

    
162
  //last row is footer
163
  document.write("</tr><tr><td "+_getColSpanString()+" class=\""
164
                                              +TEMPLATE_FOOTERROW_CLASS+"\">");
165

    
166
  //make any relative paths into absolute paths
167
  FOOTER_URL = prependUrl(serverContextUrl, FOOTER_URL);
168
	
169
  //content for the footer (if any)
170
  _createIFrameWithURL(FOOTER_URL, IFRAME_FOOTER_CLASS);
171

    
172
  //close table
173
  document.write("</td></tr></table>");
174

    
175
}
176

    
177

    
178
/**
179
 *  inserts the header referenced by the SEARCHBOX_URL setting
180
 */
181
function insertSearchBox(serverContextUrl) { 
182

    
183
  if (!_isBlank(SEARCHBOX_URL)) {
184
  
185
	//make any relative paths into absolute paths
186
	SEARCHBOX_URL = prependUrl(serverContextUrl, SEARCHBOX_URL);
187

    
188
    _createIFrameWithURL(SEARCHBOX_URL, IFRAME_SEARCHBOX_CLASS);
189
  }
190

    
191
}
192

    
193

    
194
/**
195
 *  inserts the header referenced by the SEARCHBOX_URL setting
196
 */
197
function insertMap(serverContextUrl) { 
198

    
199
  if (!_isBlank(MAP_URL)) {
200
  	//make any relative paths into absolute paths
201
	MAP_URL = prependUrl(serverContextUrl, MAP_URL);
202

    
203
    _createIFrameWithURL(MAP_URL, IFRAME_MAP_CLASS);
204
  }
205

    
206
}
207

    
208
/**
209
 *  inserts the header referenced by the ADVANCED_SEARCHBOX_URL setting
210
 */
211
function insertAdvancedSearchBox(serverContextUrl) { 
212

    
213
  if (!_isBlank(ADVANCED_SEARCHBOX_URL)) {
214
	//make any relative paths into absolute paths
215
	ADVANCED_SEARCHBOX_URL = prependUrl(serverContextUrl, ADVANCED_SEARCHBOX_URL);
216
	
217
    _createIFrameWithURL(ADVANCED_SEARCHBOX_URL, IFRAME_ADVANCED_SEARCHBOX_CLASS);
218
  }
219

    
220
}
221

    
222
/**
223
 *  inserts the header referenced by the LOGINBOX_URL setting
224
 */
225
function insertLoginBox(serverContextUrl) { 
226

    
227
  if (!_isBlank(LOGINBOX_URL)) {
228
  
229
  	//make any relative paths into absolute paths
230
	LOGINBOX_URL = prependUrl(serverContextUrl, LOGINBOX_URL);
231

    
232
    _createIFrameWithURL(LOGINBOX_URL, IFRAME_LOGINBOX_CLASS);
233
  }
234

    
235
}
236

    
237

    
238
/**
239
 *  inserts an iframe into the document and assigns it the passed source URL
240
 *  and class attribute
241
 */
242
function _createIFrameWithURL(targetURL, cssClass) {
243

    
244

    
245
  if (_isBlank(targetURL)) {
246

    
247
    document.write("&nbsp;");
248

    
249
  } else {
250

    
251
    document.write("<iframe src=\""+targetURL+"\" class=\""+cssClass+"\" "
252
                  +" id=\"" + cssClass + "\""
253
                  +" name=\"" + cssClass + "\""
254
				  + "\" marginwidth=\"0\" scrolling=\"no\" "
255
                  +" marginheight=\"0\" marginwidth=\"0\" scrolling=\"no\" "
256
                  +" border=\"0\" frameborder=\"0\" framespacing=\"0\" "
257
                  +" hspace=\"0\" vspace=\"0\">Your browser does not support"
258
                  +" the iframe tag. <a href=\""+targetURL+"\" "
259
                  +"target=\"_blank\">This content</a>"
260
                  +" should have been displayed at this location</iframe>");
261
  }
262
}
263

    
264

    
265

    
266
function _isBlank(testString) {
267

    
268
  return (  !testString
269
          || testString==null
270
          || (testString.replace(/^\s*/, '').replace(/\s*$/,'')==""));
271
}
272

    
273

    
274
function _getColSpanString() {
275

    
276
  var colspan = 1;
277
  if (!_isBlank(LEFTCOL_URL))  colspan++;
278
  if (!_isBlank(RIGHTCOL_URL)) colspan++;
279
  if (colspan==1) return "";
280
  else return " colspan=\""+colspan+"\" ";
281
} 
282

    
283
function submitbrowseform(action,form_ref) {
284
  form_ref.action.value=action;
285
  form_ref.submit();
286
}
287

    
288
/**
289
* This uses jQuery to load access log information
290
**/
291
function loadStats(divId, docId, url, qformat) {
292
	var params = 
293
	{
294
		'action': "getlog",
295
		'docid': docId,
296
		'qformat': qformat
297
	};
298
	load(url, params, divId);
299
}
300
/**
301
* This uses jQuery to call any Metacat method with the given params
302
**/
303
function load(url, params, divId) {
304
	try {
305
		// call back function when loading finishes
306
		var callback = 
307
			function(response, status, xhr) {
308
				// error
309
				if (status == "error") {
310
					var msg = "Sorry but there was an error: ";
311
					$("#error").html(msg + xhr.status + " " + xhr.statusText);
312
				}
313
			};
314
		// replace div with content	
315
		if (divId) {
316
			$("#" + divId).load(
317
				url, 
318
				params,
319
				callback);
320
			} else {
321
				// just post without replacing content
322
				$.post(
323
				url, 
324
				params,
325
				callback);
326
			}	
327
		} catch (e) {
328
			// do nothing - jQuery was probably not included
329
		}
330
}
(5-5/33)