[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 // 2 // Created on: <14-Jul-2004 14:18:58 dl> 3 // 4 // SOFTWARE NAME: eZ publish 5 // SOFTWARE RELEASE: 3.9.0 6 // BUILD VERSION: 17785 7 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 8 // SOFTWARE LICENSE: GNU General Public License v2.0 9 // NOTICE: > 10 // This program is free software; you can redistribute it and/or 11 // modify it under the terms of version 2.0 of the GNU General 12 // Public License as published by the Free Software Foundation. 13 // 14 // This program is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 // GNU General Public License for more details. 18 // 19 // You should have received a copy of version 2.0 of the GNU General 20 // Public License along with this program; if not, write to the Free 21 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 22 // MA 02110-1301, USA. 23 // 24 // 25 26 /*! \file ezjslibdomsupport.js 27 */ 28 29 /*! 30 \brief 31 32 Functions which works with HTMLElements: 33 ezjslib_findHTMLChildTextNode, 34 ezjslib_setTextToHTMLChildTextNode, 35 ezjslib_removeHTMLChildTextNode, 36 ezjslib_createHTMLChildTextNode, 37 ezjslib_setHTMLNodeClassStyle, 38 ezjslib_appendHTMLNodeClassStyle, 39 ezjslib_getHTMLNodeById, 40 ezjslib_getHTMLChildNodeByTag, 41 ezjslib_getHTMLChildNodeByProperty, 42 ezjslib_getStyleObject. 43 */ 44 45 /*! 46 Finds the text of \a node 47 */ 48 function ezjslib_findHTMLChildTextNode( node ) 49 { 50 return ezjslib_findHTMLChildNodeByType( node, 3 ); 51 } 52 53 /*! 54 Finds the image of \a node 55 */ 56 function ezjslib_findHTMLChildImageNode( node ) 57 { 58 return ezjslib_findHTMLChildNodeByType( node, 1 ); 59 } 60 61 /*! 62 Finds child node of \a node by \a type 63 */ 64 function ezjslib_findHTMLChildNodeByType( node, type ) 65 { 66 if( node ) 67 { 68 for ( var i = 0; i < node.childNodes.length; i++ ) 69 { 70 if ( node.childNodes[i].nodeType == type ) 71 { 72 return node.childNodes[i]; 73 } 74 } 75 } 76 77 return null; 78 } 79 80 /*! 81 Finds the text of \a node and replaces it with \a text 82 */ 83 function ezjslib_setTextToHTMLChildTextNode( node, text ) 84 { 85 var textNode = ezjslib_findHTMLChildTextNode( node ); 86 if( textNode != null ) 87 { 88 textNode.data = text; 89 } 90 } 91 92 /*! 93 */ 94 function ezjslib_setImageSourceToHTMLChildImageNode( node, imageSource ) 95 { 96 var imageNode = ezjslib_findHTMLChildImageNode( node ); 97 if( imageNode != null ) 98 { 99 imageNode.src = imageSource; 100 } 101 } 102 103 /*! 104 Finds text of \a node and removes it 105 */ 106 function ezjslib_removeHTMLChildTextNode( node ) 107 { 108 ezjslib_removeHTMLChildNodeByType( node, 3 ); 109 } 110 111 /*! 112 Finds image of \a node and removes it 113 */ 114 function ezjslib_removeHTMLChildImageNode( node ) 115 { 116 ezjslib_removeHTMLChildNodeByType( node, 1 ); 117 } 118 119 /*! 120 Finds a child of \a node by \a type and removes it 121 */ 122 function ezjslib_removeHTMLChildNodeByType( node, type ) 123 { 124 var textNode = ezjslib_findHTMLChildNodeByType( node, type ); 125 if( textNode != null ) 126 { 127 node.removeChild( textNode ); 128 } 129 } 130 131 /*! 132 Creates and appends child text node with text \a text to node \a node 133 */ 134 function ezjslib_createHTMLChildTextNode( node, text ) 135 { 136 if ( node != null ) 137 { 138 var textNode = document.createTextNode( text ); 139 node.appendChild( textNode ); 140 } 141 } 142 143 /*! 144 */ 145 function ezjslib_createHTMLChildImageNode( node, imageSource, imageWidth, imageHeight ) 146 { 147 if ( node != null ) 148 { 149 var imageNode = document.createElement( 'img' ); 150 imageNode.src = imageSource; 151 if ( imageWidth ) 152 imageNode.width = imageWidth; 153 if ( imageHeight ) 154 imageNode.height = imageHeight; 155 156 node.appendChild( imageNode ); 157 } 158 } 159 160 /*! 161 \return HTMLElement with id \a node_id 162 */ 163 function ezjslib_getHTMLNodeById( node_id ) 164 { 165 return document.getElementById( node_id ); 166 } 167 168 /*! 169 \return a FIRST child HTMLElement of \a node with tag \a tag 170 */ 171 function ezjslib_getHTMLChildNodeByTag( node, tag ) 172 { 173 for ( var i = 0; i < node.childNodes.length; ++i ) 174 { 175 var child = node.childNodes[i]; 176 177 if ( child["tagName"] && child.tagName.toLowerCase() == tag ) 178 { 179 return child; 180 } 181 } 182 183 return null; 184 } 185 186 /*! 187 \return a FIRST child HTMLElement of \a node with property name 188 \a attrName and property value \a attrValue 189 */ 190 function ezjslib_getHTMLChildNodeByProperty( node, propName, propValue ) 191 { 192 if( node ) 193 { 194 for ( var i = 0; i < node.childNodes.length; ++i ) 195 { 196 var child = node.childNodes[i]; 197 var value = child[propName]; 198 199 if ( value && value == propValue ) 200 { 201 return child; 202 } 203 } 204 } 205 206 return null; 207 } 208 209 /*! 210 Sets 'className' property of node \a node to value \a styleClassName 211 */ 212 function ezjslib_setHTMLNodeClassStyle( node, styleClassName ) 213 { 214 if ( node && styleClassName ) 215 { 216 node['className'] = styleClassName; 217 } 218 } 219 220 /*! 221 Appends to 'className' property of node \a node the value \a styleClassName 222 */ 223 function ezjslib_appendHTMLNodeClassStyle( node, styleClassName ) 224 { 225 if ( node && styleClassName ) 226 { 227 if ( node['className'] == '' ) 228 node['className'] = styleClassName; 229 else 230 node['className'] = node['className'] + ' ' + styleClassName; 231 } 232 } 233 234 /*! 235 Get the style object for the element with id objID 236 */ 237 function ezjslib_getStyleObject( objID ) 238 { 239 if( document.getElementById && document.getElementById( objID ) ) // DOM 240 { 241 return document.getElementById( objID ).style; 242 } 243 else if ( document.all && document.all( objID ) ) // IE 244 { 245 return document.all( objID ).style; 246 } 247 else if ( document.layers && document.layers[objID] ) 248 { 249 return false; // Netscape 4.x Not currently supported. 250 } 251 else 252 { 253 return false; 254 } 255 } 256 257 /*! 258 Get the properties of the visible screen. Returns an object containing 259 .ScrollX - The amount of pixels the page has been scrolled vertically 260 .ScrollY - The amount of pixels the page has been scrolled horizontally 261 .Height - The height of the browser window 262 .Width - The width of the browser window. 263 */ 264 function ezjslib_getScreenProperties() 265 { 266 // client width and height 267 result = new Array(); 268 result.ScrollX = 0; 269 result.ScrollY = 0; 270 result.Height = 0; 271 result.Width = 0; 272 273 if( typeof( window.innerWidth ) == 'number' ) 274 { 275 // all but IE 276 result.Width = window.innerWidth; 277 result.Height = window.innerHeight; 278 } 279 else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 280 { 281 // IE 6 282 result.Width = document.documentElement.clientWidth; 283 result.Height = document.documentElement.clientHeight; 284 } 285 else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 286 { 287 // IE 4 288 result.Width = document.body.clientWidth; 289 result.Height = document.body.clientHeight; 290 } 291 292 // offsets 293 if( typeof( window.pageYOffset ) == 'number' ) 294 { 295 // Netscape compliant 296 result.ScrollY = window.pageYOffset; 297 result.ScrollX = window.pageXOffset; 298 } 299 else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 300 { 301 // DOM 302 result.ScrollY = document.body.scrollTop; 303 result.ScrollX = document.body.scrollLeft; 304 } 305 else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 306 { 307 // IE6 308 result.ScrollY = document.documentElement.scrollTop; 309 result.ScrollX = document.documentElement.scrollLeft; 310 } 311 312 return result; 313 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |