1/* 2 * The contents of this file are subject to the license and copyright 3 * detailed in the LICENSE and NOTICE files at the root of the source 4 * tree and available online at 5 * 6 * http://www.dspace.org/license/ 7 */ 8/* 9 * Utility Javascript methods for DSpace 10 */ 11 12// Popup window - here so it can be referred to by several methods 13var popupWindow; 14 15// ========================================================= 16// Methods for e-person popup window 17// ========================================================= 18 19// Add to list of e-people on this page -- invoked by eperson popup window 20function addEPerson(id, email, name) 21{ 22 var newplace = window.document.epersongroup.eperson_id.options.length; 23 24 if (newplace > 0 && window.document.epersongroup.eperson_id.options[0].value == "") 25 { 26 newplace = 0; 27 } 28 29 // First we check to see if e-person is already there 30 for (var i = 0; i < window.document.epersongroup.eperson_id.options.length; i++) 31 { 32 if (window.document.epersongroup.eperson_id.options[i].value == id) 33 { 34 newplace = -1; 35 } 36 } 37 38 if (newplace > -1) 39 { 40 window.document.epersongroup.eperson_id.options[newplace] = new Option(name + " (" + email + ")", id); 41 } 42} 43 44// Add to list of groups on this page -- invoked by eperson popup window 45function addGroup(id, name) 46{ 47 var newplace = window.document.epersongroup.group_ids.options.length; 48 49 if (newplace > 0 && window.document.epersongroup.group_ids.options[0].value == "") 50 { 51 newplace = 0; 52 } 53 54 // First we check to see if group is already there 55 for (var i = 0; i < window.document.epersongroup.group_ids.options.length; i++) 56 { 57 // is it in the list already 58 if (window.document.epersongroup.group_ids.options[i].value == id) 59 { 60 newplace = -1; 61 } 62 63 // are we trying to add the new group to the new group on an Edit Group page (recursive) 64 if (window.document.epersongroup.group_id) 65 { 66 if (window.document.epersongroup.group_id.value == id) 67 { 68 newplace = -1; 69 } 70 } 71 } 72 73 if (newplace > -1) 74 { 75 window.document.epersongroup.group_ids.options[newplace] = new Option(name + " (" + id + ")", id); 76 } 77} 78 79// This needs to be invoked in the 'onClick' javascript event for buttons 80// on pages with a dspace:selecteperson element in them 81function finishEPerson() 82{ 83 selectAll(window.document.epersongroup.eperson_id); 84 85 if (popupWindow != null) 86 { 87 popupWindow.close(); 88 } 89} 90 91// This needs to be invoked in the 'onClick' javascript event for buttons 92// on pages with a dspace:selecteperson element in them 93function finishGroups() 94{ 95 selectAll(window.document.epersongroup.group_ids); 96 97 if (popupWindow != null) 98 { 99 popupWindow.close(); 100 } 101} 102 103// ========================================================= 104// Miscellaneous utility methods 105// ========================================================= 106 107// Open a popup window (or bring to front if already open) 108function popup_window(winURL, winName) 109{ 110 var props = 'scrollBars=yes,resizable=yes,toolbar=no,menubar=no,location=no,directories=no,width=640,height=480'; 111 popupWindow = window.open(winURL, winName, props); 112 popupWindow.focus(); 113} 114 115 116// Select all options in a <SELECT> list 117function selectAll(sourceList) 118{ 119 for(var i = 0; i < sourceList.options.length; i++) 120 { 121 if ((sourceList.options[i] != null) && (sourceList.options[i].value != "")) 122 sourceList.options[i].selected = true; 123 } 124 return true; 125} 126 127// Deletes the selected options from supplied <SELECT> list 128function removeSelected(sourceList) 129{ 130 var maxCnt = sourceList.options.length; 131 for(var i = maxCnt - 1; i >= 0; i--) 132 { 133 if ((sourceList.options[i] != null) && (sourceList.options[i].selected == true)) 134 { 135 sourceList.options[i] = null; 136 } 137 } 138} 139 140 141// Disables accidentally submitting a form when the "Enter" key is pressed. 142// Just add "onkeydown='return disableEnterKey(event);'" to form. 143function disableEnterKey(e) 144{ 145 var key; 146 147 if(window.event) 148 key = window.event.keyCode; //Internet Explorer 149 else 150 key = e.which; //Firefox & Netscape 151 152 if(key == 13) //if "Enter" pressed, then disable! 153 return false;
154 else 155 return true; 156} 157 158 159//****************************************************** 160// Functions used by controlled vocabulary add-on 161// There might be overlaping with existing functions 162//****************************************************** 163 164function expandCollapse(node, contextPath) { 165 node = node.parentNode; 166 var childNode = (node.getElementsByTagName("ul"))[0]; 167 168 if(!childNode) return false; 169 170 var image = node.getElementsByTagName("img")[0]; 171 172 if(childNode.style.display != "block") { 173 childNode.style.display = "block"; 174 image.src = contextPath + "/image/controlledvocabulary/m.gif"; 175 image.alt = "Collapse search term category"; 176 } else { 177 childNode.style.display = "none"; 178 image.src = contextPath + "/image/controlledvocabulary/p.gif"; 179 image.alt = "Expand search term category"; 180 } 181 182 return false; 183} 184 185 186function getAnchorText(ahref) { 187 if(isMicrosoft()) return ahref.childNodes.item(0).nodeValue; 188 else return ahref.text; 189} 190 191function getTextValue(node) { 192 if(node.nodeName == "A") { 193 return getAnchorText(node); 194 } else { 195 return ""; 196 } 197 198} 199 200 201function getParentTextNode(node) { 202 var parentNode = node.parentNode.parentNode.parentNode; 203 var children = parentNode.childNodes; 204 var textNode; 205 for(var i=0; i< children.length; i++) { 206 var child = children.item(i); 207 if(child.className == "value") { 208 return child; 209 } 210 } 211 return null; 212} 213 214function ec(node, contextPath) { 215 expandCollapse(node, contextPath); 216 return false; 217} 218 219 220function i(node) { 221 return sendBackToParentWindow(node); 222} 223 224 225function getChildrenByTagName(rootNode, tagName) { 226 var children = rootNode.childNodes; 227 var result = new Array(0); 228 if(children == null) return result; 229 for(var i=0; i<children.length; i++) { 230 if(children[i].tagName == tagName) { 231 var elementArray = new Array(1); 232 elementArray[0] = children[i]; 233 result = result.concat(elementArray); 234 } 235 } 236 return result; 237} 238 239function popUp(URL) { 240 var page; 241 page = window.open(URL, 'controlledvocabulary', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=650,height=450'); 242} 243 244 245function isNetscape(v) { 246 return isBrowser("Netscape", v); 247} 248 249function isMicrosoft(v) { 250 return isBrowser("Microsoft", v); 251} 252 253function isMicrosoft() { 254 return isBrowser("Microsoft", 0); 255} 256 257 258function isBrowser(b,v) { 259 browserOk = false; 260 versionOk = false; 261 262 browserOk = (navigator.appName.indexOf(b) != -1); 263 if (v == 0) versionOk = true; 264 else versionOk = (v <= parseInt(navigator.appVersion)); 265 return browserOk && versionOk; 266} 267 268 269
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.