Changeset 3919
- Timestamp:
- Oct 28, 2010, 11:01:38 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/servlet/www/static/js/script.js
r3905 r3919 1 /* 2 * Add var TOGGLE = 0; to a global script 3 */ 4 1 // Add var TOGGLE = 0; to a global script 5 2 var CONTEXT = "/proteios/app?action="; 6 3 7 function empty() { return true; } 4 function empty() 5 { 6 return true; 7 } 8 8 9 function rightGo(action) 9 10 { 10 11 12 13 14 15 16 17 11 if(parent.right) 12 { 13 parent.right.location = CONTEXT + action; 14 } 15 else 16 { 17 goToLocation(CONTEXT + action); 18 } 18 19 } 19 20 20 21 function popupGo(action) 21 22 { 22 23 window.open(CONTEXT + action ,'popup','width=500,height=500'); 23 24 } 24 25 25 26 function goToLocation(location) 26 27 { 27 if(TOGGLE == 0) 28 { 29 window.location = location; 30 } 31 TOGGLE = 0; 32 } 33 34 35 function getScrollXY() { 36 var scrOfX = 0, scrOfY = 0; 37 if( typeof( window.pageYOffset ) == 'number' ) { 38 //Netscape compliant 39 scrOfY = window.pageYOffset; 40 scrOfX = window.pageXOffset; 41 } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { 42 //DOM compliant 43 scrOfY = document.body.scrollTop; 44 scrOfX = document.body.scrollLeft; 45 } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { 46 //IE6 standards compliant mode 47 scrOfY = document.documentElement.scrollTop; 48 scrOfX = document.documentElement.scrollLeft; 49 } 50 return [ scrOfX, scrOfY ]; 51 } 52 53 function getXYSize() { 54 var myWidth = 0, myHeight = 0; 55 if( typeof( window.innerWidth ) == 'number' ) { 56 //Non-IE 57 myWidth = window.innerWidth; 58 myHeight = window.innerHeight; 59 } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { 60 //IE 6+ in 'standards compliant mode' 61 myWidth = document.documentElement.clientWidth; 62 myHeight = document.documentElement.clientHeight; 63 } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 64 //IE 4 compatible 65 myWidth = document.body.clientWidth; 66 myHeight = document.body.clientHeight; 67 } 68 return [ myWidth, myHeight ]; 69 } 70 28 if(TOGGLE == 0) 29 { 30 window.location = location; 31 } 32 TOGGLE = 0; 33 } 34 35 function getScrollXY() 36 { 37 var scrOfX = 0, scrOfY = 0; 38 if( typeof( window.pageYOffset ) == 'number' ) 39 { 40 //Netscape compliant 41 scrOfY = window.pageYOffset; 42 scrOfX = window.pageXOffset; 43 } 44 else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 45 { 46 //DOM compliant 47 scrOfY = document.body.scrollTop; 48 scrOfX = document.body.scrollLeft; 49 } 50 else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 51 { 52 //IE6 standards compliant mode 53 scrOfY = document.documentElement.scrollTop; 54 scrOfX = document.documentElement.scrollLeft; 55 } 56 return [ scrOfX, scrOfY ]; 57 } 58 59 function getXYSize() 60 { 61 var myWidth = 0, myHeight = 0; 62 if( typeof( window.innerWidth ) == 'number' ) { 63 // Non-IE 64 myWidth = window.innerWidth; 65 myHeight = window.innerHeight; 66 } 67 else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 68 { 69 // IE 6+ in 'standards compliant mode' 70 myWidth = document.documentElement.clientWidth; 71 myHeight = document.documentElement.clientHeight; 72 } 73 else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 74 { 75 // IE 4 compatible 76 myWidth = document.body.clientWidth; 77 myHeight = document.body.clientHeight; 78 } 79 return [ myWidth, myHeight ]; 80 } 81 82 // Returns node by the given id, or null if it does not exist 71 83 function getElement(id) 72 84 { 73 var div; 74 if(document.all) 75 { 76 div = document.all[id]; 77 } 78 else 79 { 80 div = document.getElementById(id); 81 } 82 return div; 85 return document.all ? document.all[id] : document.getElementById(id); 83 86 } 84 87 85 88 function submitForm(formId) 86 89 { 87 getElement(formId).submit(); 88 } 89 90 getElement(formId).submit(); 91 } 90 92 91 93 function addHiliteEvents(item) 92 94 { 93 item.onmouseover = function() { this.className = "hover " + this.className;} 94 item.onmouseout = function() { this.className = this.className.slice(6);} 95 } 96 95 item.onmouseover = function() 96 { 97 this.className = "hover " + this.className; 98 }; 99 item.onmouseout = function() 100 { 101 this.className = this.className.slice(6); 102 }; 103 } 97 104 98 105 function submitFormAs(formId, action) 99 106 { 100 101 102 103 104 105 106 } 107 108 / * Toggles visibility of a div */107 if(TOGGLE == 0) 108 { 109 getElement(formId + "action").value = action; 110 getElement(formId).submit(); 111 } 112 TOGGLE = 0; 113 } 114 115 // Toggles visibility of a div 109 116 function toggle(id) 110 117 { 111 var div = getElement(id); 112 if(div.style.display == "block") 113 { 118 var div = getElement(id); 119 if(div.style.display == "block") 120 { 121 div.style.display = "none"; 122 } 123 else 124 { 125 div.style.display = "block"; 126 } 127 } 128 129 // Toggles visibility of a fieldset 130 function toggleFieldset(id) 131 { 132 var node = getElement(id); 133 var icon = getElement("btn" + id); 134 if(node.style.display == "block") 135 { 136 node.style.display = "none"; 137 icon.src = "static/img/plus.gif"; 138 } 139 else 140 { 141 node.style.display = "block"; 142 icon.src = "static/img/minus.gif"; 143 } 144 } 145 146 var visiblePopup = 0; 147 // popup, toggles the visibility and positions a div so it's visible 148 function popup(id) 149 { 150 var div = getElement(id); 151 var xy = getScrollXY(); 152 var newTop = (xy[1]+50) + "px"; 153 div.style.top = newTop; 154 toggle(id); 155 visiblePopup=id; 156 } 157 158 // TODO there might be a situation where more popups have been shown, this method should close them all 159 function closeAllVisiblePopups() 160 { 161 hide(visiblePopup); 162 } 163 164 // Sets display:none for the given elementId 165 function hide(id) 166 { 167 var div = getElement(id); 114 168 div.style.display = "none"; 115 } 116 else 117 { 169 } 170 171 function closePopup(id) 172 { 173 hide(id); 174 } 175 176 // Sets display:block for the given elementId 177 function show(id) 178 { 179 var div = getElement(id); 118 180 div.style.display = "block"; 119 } 120 } 121 122 /* Toggles visibility of a fieldset */ 123 function toggleFieldset(id) 124 { 125 var node = getElement(id); 126 var icon = getElement("btn" + id); 127 if(node.style.display == "block") 128 { 129 node.style.display = "none"; 130 icon.src = "static/img/plus.gif"; 131 } 132 else 133 { 134 node.style.display = "block"; 135 icon.src = "static/img/minus.gif"; 136 } 137 } 138 139 var visiblePopup = 0; 140 /* popup, toggles the visibility and positions a div so it's visible */ 141 function popup(id) 142 { 143 var div = getElement(id); 144 var xy = getScrollXY(); 145 var newTop = (xy[1]+50) + "px"; 146 div.style.top = newTop; 147 toggle(id); 148 visiblePopup=id; 149 } 150 151 /* TODO there might be a situation where more popups have been shown, this method should close them all */ 152 function closeAllVisiblePopups() 153 { 154 hide(visiblePopup); 155 } 156 157 /* Sets display:none for the given elementId */ 158 function hide(id) 159 { 160 var div = getElement(id); 161 div.style.display = "none"; 162 } 163 164 function closePopup(id) 165 { 166 hide(id); 167 } 168 169 170 /* Sets display:block for the given elementId */ 171 function show(id) 172 { 173 var div = getElement(id); 174 div.style.display = "block"; 175 } 176 181 } 177 182 178 183 var LASTTABID = 0; 179 184 function showTab(id) 180 185 { 181 var prefix = "contentOf"; 182 if(LASTTABID != 0) 183 { 184 var last = getElement(LASTTABID); 185 last.className = "tab"; 186 hide(prefix + LASTTABID); 187 } 188 show(prefix + id); 189 var tab = getElement(id); 190 tab.className = "hover tab here"; 191 LASTTABID = id; 192 } 193 194 195 /* Initiates a table with correct class and eventhandlers*/ 186 var prefix = "contentOf"; 187 if(LASTTABID != 0) 188 { 189 var last = getElement(LASTTABID); 190 last.className = "tab"; 191 hide(prefix + LASTTABID); 192 } 193 show(prefix + id); 194 var tab = getElement(id); 195 tab.className = "hover tab here"; 196 LASTTABID = id; 197 } 198 199 // Initiates a table with correct class and eventhandlers 196 200 function initTable(id) 197 201 { 198 var table = getElement(id); 199 var tableRows = table.rows; 200 for(var i = 0; i<tableRows.length;i++) 201 { 202 var row = tableRows[i]; 203 addHiliteEvents(row); 204 } 205 } 206 207 208 /* Binds hover events to all LI elements */ 202 var table = getElement(id); 203 if(table != null) 204 { 205 var tableRows = table.rows; 206 for(var i = 0; i<tableRows.length;i++) 207 { 208 var row = tableRows[i]; 209 addHiliteEvents(row); 210 } 211 } 212 } 213 214 // Binds hover events to all LI elements 209 215 function initUl(id) { 210 var ul = getElement(id); 211 var elements = ul.getElementsByTagName("LI"); 212 for(var i = 0; i< elements.length-1;i++) 213 { 214 if(elements[i].nodeName == "LI") 215 { 216 var li = elements[i]; 217 addHiliteEvents(li); 218 } 219 } 220 } 221 216 var ul = getElement(id); 217 var elements = ul.getElementsByTagName("LI"); 218 for(var i = 0; i< elements.length-1;i++) 219 { 220 if(elements[i].nodeName == "LI") 221 { 222 var li = elements[i]; 223 addHiliteEvents(li); 224 } 225 } 226 } 222 227 223 228 function setNameField(select) 224 229 { 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 230 var form = select.form; 231 var option = select.options[select.selectedIndex]; 232 var value = option.text; 233 var elements = form.getElementsByTagName("input"); 234 for(var i = 0; i < elements.length;i++) 235 { 236 var input = elements[i]; 237 if(input.id == "annotationName") 238 { 239 if(option.value == "0") 240 { 241 input.value = ""; 242 input.disabled = !(input.disabled); 243 } 244 else 245 { 246 input.value = option.text; 247 input.disabled = "disabled"; 248 } 249 } 250 } 246 251 } 247 252 248 253 function checkAllRowsInTable(formId) 249 254 { 250 251 252 253 254 255 256 257 258 259 255 var form = getElement(formId); 256 var elements = form.getElementsByTagName("input"); 257 for(var i = 0; i < elements.length;i++) 258 { 259 var input = elements[i]; 260 if(input.id == "itemId") 261 { 262 input.checked = !input.checked; 263 } 264 } 260 265 } 261 266 262 267 /* 263 268 Add a field to a form. If it already exists the value is changed. 264 269 */ 265 270 function addField(formId, name, value) 266 271 { 267 268 269 for(var i = 0; i < form.elements.length; i++)270 {271 var e = form.elements[i];272 if(e.name == name)273 {274 field = e;275 break;276 }277 }278 279 280 /* Create new element */281 282 283 284 285 272 var field = null; 273 var form = getElement(formId); 274 for(var i = 0; i < form.elements.length; i++) 275 { 276 var e = form.elements[i]; 277 if(e.name == name) 278 { 279 field = e; 280 break; 281 } 282 } 283 if(field == null) 284 { 285 // Create new element 286 field = document.createElement("input"); 287 field.type = "hidden"; 288 field.name = name; 289 form.appendChild(field); 290 } 286 291 field.value = value; 287 292 } … … 289 294 function addShadeUnshade(obj) 290 295 { 291 obj.shade = function() { 292 this.className = "shade " + this.className; 293 } 294 295 obj.unshade = function() { 296 this.className = this.className.slice(6); 297 } 298 } 299 300 /* http://blog.firetree.net/2005/07/04/javascript-find-position/ */ 301 function findPosX(obj) 302 { 296 obj.shade = function() 297 { 298 this.className = "shade " + this.className; 299 }; 300 301 obj.unshade = function() 302 { 303 this.className = this.className.slice(6); 304 }; 305 } 306 307 // http://blog.firetree.net/2005/07/04/javascript-find-position/ 308 function findPosX(obj) 309 { 303 310 var curleft = 0; 304 311 if(obj.offsetParent) 305 while(1) 306 { 307 curleft += obj.offsetLeft; 308 if(!obj.offsetParent) 312 while(1) 313 { 314 curleft += obj.offsetLeft; 315 if(!obj.offsetParent) 316 { 309 317 break; 310 obj = obj.offsetParent; 311 } 318 } 319 obj = obj.offsetParent; 320 } 312 321 else if(obj.x) 322 { 313 323 curleft += obj.x; 324 } 325 314 326 return curleft; 315 316 317 318 327 } 328 329 function findPosY(obj) 330 { 319 331 var curtop = 0; 320 332 if(obj.offsetParent) 321 while(1) 322 { 323 curtop += obj.offsetTop; 324 if(!obj.offsetParent) 333 while(1) 334 { 335 curtop += obj.offsetTop; 336 if(!obj.offsetParent) 337 { 325 338 break; 326 obj = obj.offsetParent; 327 } 339 } 340 obj = obj.offsetParent; 341 } 328 342 else if(obj.y) 343 { 329 344 curtop += obj.y; 345 } 346 330 347 return curtop; 331 } 332 333 334 /* http://bytes.com/forum/thread763579.html */ 335 function resize_all_iframes() 336 { 348 } 349 350 // http://bytes.com/forum/thread763579.html 351 function resize_all_iframes() 352 { 337 353 var f_list = document.getElementsByTagName("IFRAME"); 338 354 if(f_list.length > 0) 339 355 { 340 for (var i = 0, f; f = f_list[i]; i++)341 {342 resize_iframe(f.id);343 }344 } 345 346 347 /* http://guymal.com/mycode/100_percent_iframe/ */356 for (var i = 0, f; f = f_list[i]; i++) 357 { 358 resize_iframe(f.id); 359 } 360 } 361 } 362 363 // http://guymal.com/mycode/100_percent_iframe/ 348 364 function resize_iframe(frameId) 349 365 { 350 366 351 352 353 354 355 356 //resize the iframe according to the size of the357 //window (all these should be on the same line)358 359 360 361 } 362 363 / * http://www.dynamicdrive.com/dynamicindex5/texttool.htm */367 var height=window.innerWidth;//Firefox 368 if (document.body.clientHeight) 369 { 370 height=document.body.clientHeight;//IE 371 } 372 // resize the iframe according to the size of the 373 // window (all these should be on the same line) 374 var iframe = getElement(frameId); 375 var y = findPosY(iframe); 376 iframe.style.height=parseInt(height-y-8)+"px"; 377 } 378 379 // http://www.dynamicdrive.com/dynamicindex5/texttool.htm 364 380 function showtip(current,e,text) 365 381 { 366 if (document.all || document.getElementById)367 {368 thetitle = text.split('<br>');369 if (thetitle.length > 1)370 {371 thetitles = '';372 for (i=0; i < thetitle.length; i++)373 {374 thetitles += thetitle[i];375 }376 current.title = thetitles;377 }378 else379 {380 current.title = text;381 }382 }383 else if (document.layers)384 {385 document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>');386 document.tooltip.document.close();387 document.tooltip.left = e.pageX + 5;388 document.tooltip.top = e.pageY + 5;389 document.tooltip.visibility = "show";390 }382 if (document.all || document.getElementById) 383 { 384 thetitle = text.split('<br>'); 385 if (thetitle.length > 1) 386 { 387 thetitles = ''; 388 for (i=0; i < thetitle.length; i++) 389 { 390 thetitles += thetitle[i]; 391 } 392 current.title = thetitles; 393 } 394 else 395 { 396 current.title = text; 397 } 398 } 399 else if (document.layers) 400 { 401 document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>'); 402 document.tooltip.document.close(); 403 document.tooltip.left = e.pageX + 5; 404 document.tooltip.top = e.pageY + 5; 405 document.tooltip.visibility = "show"; 406 } 391 407 } 392 408 393 409 function hidetip() 394 410 { 395 if (document.layers) 396 { 397 document.tooltip.visibility = "hidden"; 398 } 399 } 400 401 // this will resize all iframes every 402 // time you change the size of the window. 411 if (document.layers) 412 { 413 document.tooltip.visibility = "hidden"; 414 } 415 } 416 417 // this will resize all iframes every time you change the size of the window. 403 418 window.onresize=resize_all_iframes; 404 419 405 406 420 var body; 407 window.onload =function() { 408 body = getElement("rightFrameBody"); 409 addShadeUnshade(body); 410 var elements = document.getElementsByTagName("LI"); 411 for(var i = 0; i < elements.length;i++) 412 { 413 addHiliteEvents(elements[i]); 414 } 415 } 416 417 418 419 421 window.onload =function() 422 { 423 body = getElement("rightFrameBody"); 424 addShadeUnshade(body); 425 var elements = document.getElementsByTagName("LI"); 426 for(var i = 0; i < elements.length;i++) 427 { 428 addHiliteEvents(elements[i]); 429 } 430 }; 431
Note: See TracChangeset
for help on using the changeset viewer.