1// Name: AjaxControlToolkit.Common.Common.debug.js 2// Assembly: AjaxControlToolkit 3// Version: 3.0.30512.20315 4// FileVersion: 3.0.30512.1 5// (c) Copyright Microsoft Corporation. 6// This source is subject to the Microsoft Public License. 7// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL. 8// All other rights reserved. 9 10 11/// <reference name="MicrosoftAjax.debug.js" /> 12/// <reference name="MicrosoftAjaxTimer.debug.js" /> 13/// <reference name="MicrosoftAjaxWebForms.debug.js" /> 14 15 16// Add common toolkit scripts here. To consume the scripts on a control add 17// 18// [RequiredScript(typeof(CommonToolkitScripts))] 19// public class SomeExtender : ... 20// 21// to the controls extender class declaration. 22 23 24Type.registerNamespace('AjaxControlToolkit'); 25 26 27AjaxControlToolkit.BoxSide = function() { 28 /// <summary> 29 /// The BoxSide enumeration describes the sides of a DOM element 30 /// </summary> 31 /// <field name="Top" type="Number" integer="true" static="true" /> 32 /// <field name="Right" type="Number" integer="true" static="true" /> 33 /// <field name="Bottom" type="Number" integer="true" static="true" /> 34 /// <field name="Left" type="Number" integer="true" static="true" /> 35} 36AjaxControlToolkit.BoxSide.prototype = { 37 Top : 0, 38 Right : 1, 39 Bottom : 2, 40 Left : 3 41} 42AjaxControlToolkit.BoxSide.registerEnum("AjaxControlToolkit.BoxSide", false); 43 44 45AjaxControlToolkit._CommonToolkitScripts = function() { 46 /// <summary> 47 /// The _CommonToolkitScripts class contains functionality utilized across a number 48 /// of controls (but not universally) 49 /// </summary> 50 /// <remarks> 51 /// You should not create new instances of _CommonToolkitScripts. Instead you should use the shared instance CommonToolkitScripts (or AjaxControlToolkit.CommonToolkitScripts). 52 /// </remarks> 53} 54AjaxControlToolkit._CommonToolkitScripts.prototype = { 55 // The order of these lookup tables is directly linked to the BoxSide enum defined above 56 _borderStyleNames: ["borderTopStyle", "borderRightStyle", "borderBottomStyle", "borderLeftStyle"], 57 _borderWidthNames: ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"], 58 _paddingWidthNames: ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"], 59 _marginWidthNames: ["marginTop", "marginRight", "marginBottom", "marginLeft"], 60 61 getCurrentStyle: function(element, attribute, defaultValue) { 62 /// <summary> 63 /// CommonToolkitScripts.getCurrentStyle is used to compute the value of a style attribute on an 64 /// element that is currently being displayed. This is especially useful for scenarios where 65 /// several CSS classes and style attributes are merged, or when you need information about the 66 /// size of an element (such as its padding or margins) that is not exposed in any other fashion. 67 /// </summary> 68 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 69 /// Live DOM element to check style of 70 /// </param> 71 /// <param name="attribute" type="String"> 72 /// The style attribute's name is expected to be in a camel-cased form that you would use when 73 /// accessing a JavaScript property instead of the hyphenated form you would use in a CSS 74 /// stylesheet (i.e. it should be "backgroundColor" and not "background-color"). 75 /// </param> 76 /// <param name="defaultValue" type="Object" mayBeNull="true" optional="true"> 77 /// In the event of a problem (i.e. a null element or an attribute that cannot be found) we 78 /// return this object (or null if none if not specified). 79 /// </param> 80 /// <returns type="Object"> 81 /// Current style of the element's attribute 82 /// </returns> 83 84 var currentValue = null; 85 if (element) { 86 if (element.currentStyle) { 87 currentValue = element.currentStyle[attribute]; 88 } else if (document.defaultView && document.defaultView.getComputedStyle) { 89 var style = document.defaultView.getComputedStyle(element, null); 90 if (style) { 91 currentValue = style[attribute]; 92 } 93 } 94 95 if (!currentValue && element.style.getPropertyValue) { 96 currentValue = element.style.getPropertyValue(attribute); 97 } 98 else if (!currentValue && element.style.getAttribute) { 99 currentValue = element.style.getAttribute(attribute); 100 } 101 } 102 103 if ((!currentValue || currentValue == "" || typeof (currentValue) === 'undefined')) { 104 if (typeof (defaultValue) != 'undefined') { 105 currentValue = defaultValue; 106 } 107 else { 108 currentValue = null; 109 } 110 } 111 return currentValue; 112 }, 113
114 getInheritedBackgroundColor: function(element) { 115 /// <summary> 116 /// CommonToolkitScripts.getInheritedBackgroundColor provides the ability to get the displayed 117 /// background-color of an element. In most cases calling CommonToolkitScripts.getCurrentStyle 118 /// won't do the job because it will return "transparent" unless the element has been given a 119 /// specific background color. This function will walk up the element's parents until it finds 120 /// a non-transparent color. If we get all the way to the top of the document or have any other 121 /// problem finding a color, we will return the default value '#FFFFFF'. This function is 122 /// especially important when we're using opacity in IE (because ClearType will make text look 123 /// horrendous if you fade it with a transparent background color). 124 /// </summary> 125 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 126 /// Live DOM element to get the background color of 127 /// </param> 128 /// <returns type="String"> 129 /// Background color of the element 130 /// </returns> 131 132 if (!element) return '#FFFFFF'; 133 var background = this.getCurrentStyle(element, 'backgroundColor'); 134 try { 135 while (!background || background == '' || background == 'transparent' || background == 'rgba(0, 0, 0, 0)') { 136 element = element.parentNode; 137 if (!element) { 138 background = '#FFFFFF'; 139 } else { 140 background = this.getCurrentStyle(element, 'backgroundColor'); 141 } 142 } 143 } catch (ex) { 144 background = '#FFFFFF'; 145 } 146 return background; 147 }, 148 149 getLocation: function(element) { 150 /// <summary>Gets the coordinates of a DOM element.</summary> 151 /// <param name="element" domElement="true"/> 152 /// <returns type="Sys.UI.Point"> 153 /// A Point object with two fields, x and y, which contain the pixel coordinates of the element. 154 /// </returns> 155 156 // workaround for an issue in getLocation where it will compute the location of the document element. 157 // this will return an offset if scrolled. 158 // 159 if (element === document.documentElement) { 160 return new Sys.UI.Point(0, 0); 161 } 162 163 // Workaround for IE6 bug in getLocation (also required patching getBounds - remove that fix when this is removed) 164 if (Sys.Browser.agent == Sys.Browser.InternetExplorer && Sys.Browser.version < 7) { 165 if (element.window === element || element.nodeType === 9 || !element.getClientRects || !element.getBoundingClientRect) return new Sys.UI.Point(0, 0); 166 167 // Get the first bounding rectangle in screen coordinates 168 var screenRects = element.getClientRects(); 169 if (!screenRects || !screenRects.length) { 170 return new Sys.UI.Point(0, 0); 171 } 172 var first = screenRects[0]; 173 174 // Delta between client coords and screen coords 175 var dLeft = 0; 176 var dTop = 0; 177 178 var inFrame = false; 179 try { 180 inFrame = element.ownerDocument.parentWindow.frameElement; 181 } catch (ex) { 182 // If accessing the frameElement fails, a frame is probably in a different 183 // domain than its parent - and we still want to do the calculation below 184 inFrame = true; 185 } 186 187 // If we're in a frame, get client coordinates too so we can compute the delta 188 if (inFrame) { 189 // Get the bounding rectangle in client coords 190 var clientRect = element.getBoundingClientRect(); 191 if (!clientRect) { 192 return new Sys.UI.Point(0, 0); 193 } 194 195 // Find the minima in screen coords 196 var minLeft = first.left; 197 var minTop = first.top; 198 for (var i = 1; i < screenRects.length; i++) { 199 var r = screenRects[i]; 200 if (r.left < minLeft) { 201 minLeft = r.left; 202 } 203 if (r.top < minTop) { 204 minTop = r.top; 205 } 206 } 207 208 // Compute the delta between screen and client coords 209 dLeft = minLeft - clientRect.left; 210 dTop = minTop - clientRect.top; 211 } 212 213 // Subtract 2px, the border of the viewport (It can be changed in IE6 by applying a border style to the HTML element, 214 // but this is not supported by ASP.NET AJAX, and it cannot be changed in IE7.), and also subtract the delta between 215 // screen coords and client coords 216 var ownerDocument = element.document.documentElement; 217 return new Sys.UI.Point(first.left - 2 - dLeft + ownerDocument.scrollLeft, first.top - 2 - dTop + ownerDocument.scrollTop); 218 } 219 220 return Sys.UI.DomElement.getLocation(element); 221 }, 222
223 setLocation: function(element, point) { 224 /// <summary> 225 /// Sets the current location for an element. 226 /// </summary> 227 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 228 /// DOM element 229 /// </param> 230 /// <param name="point" type="Object"> 231 /// Point object (of the form {x,y}) 232 /// </param> 233 /// <remarks> 234 /// This method does not attempt to set the positioning mode of an element. 235 /// The position is relative from the elements nearest position:relative or 236 /// position:absolute element. 237 /// </remarks> 238 Sys.UI.DomElement.setLocation(element, point.x, point.y); 239 }, 240 241 getContentSize: function(element) { 242 /// <summary> 243 /// Gets the "content-box" size of an element. 244 /// </summary> 245 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 246 /// DOM element 247 /// </param> 248 /// <returns type="Object"> 249 /// Size of the element (in the form {width,height}) 250 /// </returns> 251 /// <remarks> 252 /// The "content-box" is the size of the content area *inside* of the borders and 253 /// padding of an element. The "content-box" size does not include the margins around 254 /// the element. 255 /// </remarks> 256 257 if (!element) { 258 throw Error.argumentNull('element'); 259 } 260 var size = this.getSize(element); 261 var borderBox = this.getBorderBox(element); 262 var paddingBox = this.getPaddingBox(element); 263 return { 264 width: size.width - borderBox.horizontal - paddingBox.horizontal, 265 height: size.height - borderBox.vertical - paddingBox.vertical 266 } 267 }, 268 269 getSize: function(element) { 270 /// <summary> 271 /// Gets the "border-box" size of an element. 272 /// </summary> 273 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 274 /// DOM element 275 /// </param> 276 /// <returns type="Object"> 277 /// Size of the element (in the form {width,height}) 278 /// </returns> 279 /// <remarks> 280 /// The "border-box" is the size of the content area *outside* of the borders and 281 /// padding of an element. The "border-box" size does not include the margins around 282 /// the element. 283 /// </remarks> 284 285 if (!element) { 286 throw Error.argumentNull('element'); 287 } 288 return { 289 width: element.offsetWidth, 290 height: element.offsetHeight 291 }; 292 }, 293 294 setContentSize: function(element, size) { 295 /// <summary> 296 /// Sets the "content-box" size of an element. 297 /// </summary> 298 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 299 /// DOM element 300 /// </param> 301 /// <param name="size" type="Object"> 302 /// Size of the element (in the form {width,height}) 303 /// </param> 304 /// <remarks> 305 /// The "content-box" is the size of the content area *inside* of the borders and 306 /// padding of an element. The "content-box" size does not include the margins around 307 /// the element. 308 /// </remarks> 309 310 if (!element) { 311 throw Error.argumentNull('element'); 312 } 313 if (!size) { 314 throw Error.argumentNull('size'); 315 } 316 // FF respects -moz-box-sizing css extension, so adjust the box size for the border-box 317 if (this.getCurrentStyle(element, 'MozBoxSizing') == 'border-box' || this.getCurrentStyle(element, 'BoxSizing') == 'border-box') { 318 var borderBox = this.getBorderBox(element); 319 var paddingBox = this.getPaddingBox(element); 320 size = { 321 width: size.width + borderBox.horizontal + paddingBox.horizontal, 322 height: size.height + borderBox.vertical + paddingBox.vertical 323 }; 324 } 325 element.style.width = size.width.toString() + 'px'; 326 element.style.height = size.height.toString() + 'px'; 327 }, 328 329 setSize: function(element, size) { 330 /// <summary> 331 /// Sets the "border-box" size of an element. 332 /// </summary> 333 /// <remarks> 334 /// The "border-box" is the size of the content area *outside* of the borders and 335 /// padding of an element. The "border-box" size does not include the margins around 336 /// the element. 337 /// </remarks> 338 /// <param name="element" type="Sys.UI.DomElement">DOM element</param> 339 /// <param name="size" type="Object">Size of the element (in the form {width,height})</param> 340 /// <returns /> 341 342 if (!element) { 343 throw Error.argumentNull('element'); 344 } 345 if (!size) { 346 throw Error.argumentNull('size'); 347 } 348 var borderBox = this.getBorderBox(element); 349 var paddingBox = this.getPaddingBox(element); 350 var contentSize = { 351 width: size.width - borderBox.horizontal - paddingBox.horizontal, 352 height: size.height - borderBox.vertical - paddingBox.vertical 353 }; 354 this.setContentSize(element, contentSize); 355 }, 356 357 getBounds: function(element) { 358 /// <summary>Gets the coordinates, width and height of an element.</summary> 359 /// <param name="element" domElement="true"/> 360 /// <returns type="Sys.UI.Bounds"> 361 /// A Bounds object with four fields, x, y, width and height, which contain the pixel coordinates, 362 /// width and height of the element. 363 /// </returns> 364 /// <remarks> 365 /// Use the CommonToolkitScripts version of getLocation to handle the workaround for IE6. We can 366 /// remove the below implementation and just call Sys.UI.DomElement.getBounds when the other bug 367 /// is fixed. 368 /// </remarks> 369 370 var offset = $common.getLocation(element); 371 return new Sys.UI.Bounds(offset.x, offset.y, element.offsetWidth || 0, element.offsetHeight || 0
371); 372 }, 373 374 setBounds: function(element, bounds) { 375 /// <summary> 376 /// Sets the "border-box" bounds of an element 377 /// </summary> 378 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 379 /// DOM element 380 /// </param> 381 /// <param name="bounds" type="Object"> 382 /// Bounds of the element (of the form {x,y,width,height}) 383 /// </param> 384 /// <remarks> 385 /// The "border-box" is the size of the content area *outside* of the borders and 386 /// padding of an element. The "border-box" size does not include the margins around 387 /// the element. 388 /// </remarks> 389 390 if (!element) { 391 throw Error.argumentNull('element'); 392 } 393 if (!bounds) { 394 throw Error.argumentNull('bounds'); 395 } 396 this.setSize(element, bounds); 397 $common.setLocation(element, bounds); 398 }, 399 400 getClientBounds: function() { 401 /// <summary> 402 /// Gets the width and height of the browser client window (excluding scrollbars) 403 /// </summary> 404 /// <returns type="Sys.UI.Bounds"> 405 /// Browser's client width and height 406 /// </returns> 407 408 var clientWidth; 409 var clientHeight; 410 411 // getClientBounds must return dimensions excluding scrollbars, so cannot use window.innerWidth and window.innerHeight. 412 if (document.compatMode == "CSS1Compat") { 413 // Standards-compliant mode 414 clientWidth = document.documentElement.clientWidth; 415 clientHeight = document.documentElement.clientHeight; 416 } 417 else { 418 // Quirks mode 419 clientWidth = document.body.clientWidth; 420 clientHeight = document.body.clientHeight; 421 } 422 return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight); 423 }, 424 425 getMarginBox: function(element) { 426 /// <summary> 427 /// Gets the entire margin box sizes. 428 /// </summary> 429 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 430 /// DOM element 431 /// </param> 432 /// <returns type="Object"> 433 /// Element's margin box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 434 /// </returns> 435 436 if (!element) { 437 throw Error.argumentNull('element'); 438 } 439 var box = { 440 top: this.getMargin(element, AjaxControlToolkit.BoxSide.Top), 441 right: this.getMargin(element, AjaxControlToolkit.BoxSide.Right), 442 bottom: this.getMargin(element, AjaxControlToolkit.BoxSide.Bottom), 443 left: this.getMargin(element, AjaxControlToolkit.BoxSide.Left) 444 }; 445 box.horizontal = box.left + box.right; 446 box.vertical = box.top + box.bottom; 447 return box; 448 }, 449 450 getBorderBox: function(element) { 451 /// <summary> 452 /// Gets the entire border box sizes. 453 /// </summary> 454 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 455 /// DOM element 456 /// </param> 457 /// <returns type="Object"> 458 /// Element's border box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 459 /// </returns> 460 461 if (!element) { 462 throw Error.argumentNull('element'); 463 } 464 var box = { 465 top: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Top), 466 right: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Right), 467 bottom: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Bottom), 468 left: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Left) 469 }; 470 box.horizontal = box.left + box.right; 471 box.vertical = box.top + box.bottom; 472 return box; 473 }, 474 475 getPaddingBox: function(element) { 476 /// <summary> 477 /// Gets the entire padding box sizes. 478 /// </summary> 479 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 480 /// DOM element 481 /// </param> 482 /// <returns type="Object"> 483 /// Element's padding box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 484 /// </returns> 485 486 if (!element) { 487 throw Error.argumentNull('element'); 488 } 489 var box = { 490 top: this.getPadding(element, AjaxControlToolkit.BoxSide.Top), 491 right: this.getPadding(element, AjaxControlToolkit.BoxSide.Right), 492 bottom: this.getPadding(element, AjaxControlToolkit.BoxSide.Bottom), 493 left: this.getPadding(element, AjaxControlToolkit.BoxSide.Left) 494 }; 495 box.horizontal = box.left + box.right; 496 box.vertical = box.top + box.bottom; 497 return box; 498 }, 499 500 isBorderVisible: function(element, boxSide) { 501 /// <summary> 502 /// Gets whether the current border style for an element on a specific boxSide is not 'none'. 503 /// </summary> 504 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 505 /// DOM element 506 /// </param> 507 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 508 /// Side of the element 509 /// </param> 510 /// <returns type="Boolean"> 511 /// Whether the current border style for an element on a specific boxSide is not 'none'. 512 /// </returns> 513 514 if (!element) { 515 throw Error.argumentNull('element'); 516 } 517 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 518 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 519 } 520 var styleName = this._borderStyleNames[boxSide]; 521 var styleValue = this.getCurrentStyle(element, styleName); 522 return styleValue != "none"; 523 }, 524 525 getMargin: function(element, boxSide) { 526 /// <summary> 527 /// Gets the margin thickness of an element on a specific boxSide. 528 /// </summary> 529 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 530 /// DOM element 531 /// </param> 532 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 533 /// Side of the element 534 /// </param> 535 /// <returns type="Number" integer="true"> 536 /// Margin thickness on the element's specified side 537 /// </returns> 538 539 if (!element) { 540 throw Error.argumentNull('element'); 541 } 542 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 543 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 544 } 545 var styleName = this._marginWidthNames[boxSide]; 546 var styleValue = this.getCurrentStyle(element, styleName); 547 try { return this.parsePadding(styleValue); } catch (ex) { return 0; } 548 }, 549 550 getBorderWidth: function(element, boxSide) { 551 /// <summary> 552 /// Gets the border thickness of an element on a specific boxSide. 553 /// </summary> 554 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 555 /// DOM element 556 /// </param> 557 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 558 /// Side of the element 559 /// </param> 560 /// <returns type="Number" integer="true"> 561 /// Border thickness on the element's specified side 562 /// </returns> 563 564 if (!element) { 565 throw Error.argumentNull('element'); 566 } 567 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 568 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 569 } 570 if (!this.isBorderVisible(element, boxSide)) { 571 return 0; 572 } 573 var styleName = this._borderWidthNames[boxSide]; 574 var styleValue = this.getCurrentStyle(element, styleName); 575 return this.parseBorderWidth(styleValue); 576 }, 577 578 getPadding: function(element, boxSide) { 579 /// <summary> 580 /// Gets the padding thickness of an element on a specific boxSide. 581 /// </summary> 582 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 583 /// DOM element 584 /// </param> 585 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 586 /// Side of the element 587 /// </param> 588 /// <returns type="Number" integer="true"> 589 /// Padding on the element's specified side 590 /// </returns> 591 592 if (!element) { 593 throw Error.argumentNull('element'); 594 } 595 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 596 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 597 } 598 var styleName = this._paddingWidthNames[boxSide]; 599 var styleValue = this.getCurrentStyle(element, styleName); 600 return this.parsePadding(styleValue); 601 }, 602 603 parseBorderWidth: function(borderWidth) { 604 /// <summary> 605 /// Parses a border-width string into a pixel size 606 /// </summary> 607 /// <param name="borderWidth" type="String" mayBeNull="true"> 608 /// Type of border ('thin','medium','thick','inherit',px unit,null,'') 609 /// </param> 610 /// <returns type="Number" integer="true"> 611 /// Number of pixels in the border-width 612 /// </returns> 613 if (!this._borderThicknesses) { 614 615 // Populate the borderThicknesses lookup table 616 var borderThicknesses = {}; 617 var div0 = document.createElement('div'); 618 div0.style.visibility = 'hidden'; 619 div0.style.position = 'absolute'; 620 div0.style.fontSize = '1px'; 621 document.body.appendChild(div0) 622 var div1 = document.createElement('div'); 623 div1.style.height = '0px'; 624 div1.style.overflow = 'hidden'; 625 div0.appendChild(div1); 626 var base = div0.offsetHeight; 627 div1.style.borderTop = 'solid black'; 628 div1.style.borderTopWidth = 'thin'; 629 borderThicknesses['thin'] = div0.offsetHeight - base; 630 div1.style.borderTopWidth = 'medium'; 631 borderThicknesses['medium'] = div0.offsetHeight - base; 632 div1.style.borderTopWidth = 'thick'; 633 borderThicknesses['thick'] = div0.offsetHeight - base; 634 div0.removeChild(div1); 635 document.body.removeChild(div0); 636 this._borderThicknesses = borderThicknesses; 637 } 638 639 if (borderWidth) { 640 switch (borderWidth) { 641 case 'thin': 642 case 'medium': 643 case 'thick': 644 return this._borderThicknesses[borderWidth]; 645 case 'inherit': 646 return 0; 647 } 648 var unit = this.parseUnit(borderWidth);
649 Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidBorderWidthUnit, unit.type)); 650 return unit.size; 651 } 652 return 0; 653 }, 654 655 parsePadding: function(padding) { 656 /// <summary> 657 /// Parses a padding string into a pixel size 658 /// </summary> 659 /// <param name="padding" type="String" mayBeNull="true"> 660 /// Padding to parse ('inherit',px unit,null,'') 661 /// </param> 662 /// <returns type="Number" integer="true"> 663 /// Number of pixels in the padding 664 /// </returns> 665 666 if (padding) { 667 if (padding == 'inherit') { 668 return 0; 669 } 670 var unit = this.parseUnit(padding); 671 Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidPaddingUnit, unit.type)); 672 return unit.size; 673 } 674 return 0; 675 }, 676 677 parseUnit: function(value) { 678 /// <summary> 679 /// Parses a unit string into a unit object 680 /// </summary> 681 /// <param name="value" type="String" mayBeNull="true"> 682 /// Value to parse (of the form px unit,% unit,em unit,...) 683 /// </param> 684 /// <returns type="Object"> 685 /// Parsed unit (of the form {size,type}) 686 /// </returns> 687 688 if (!value) { 689 throw Error.argumentNull('value'); 690 } 691 692 value = value.trim().toLowerCase(); 693 var l = value.length; 694 var s = -1; 695 for (var i = 0; i < l; i++) { 696 var ch = value.substr(i, 1); 697 if ((ch < '0' || ch > '9') && ch != '-' && ch != '.' && ch != ',') { 698 break; 699 } 700 s = i; 701 } 702 if (s == -1) { 703 throw Error.create(AjaxControlToolkit.Resources.Common_UnitHasNoDigits); 704 } 705 var type; 706 var size; 707 if (s < (l - 1)) { 708 type = value.substring(s + 1).trim(); 709 } else { 710 type = 'px'; 711 } 712 size = parseFloat(value.substr(0, s + 1)); 713 if (type == 'px') { 714 size = Math.floor(size); 715 } 716 return { 717 size: size, 718 type: type 719 }; 720 }, 721 722 getElementOpacity: function(element) { 723 /// <summary> 724 /// Get the element's opacity 725 /// </summary> 726 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 727 /// Element 728 /// </param> 729 /// <returns type="Number"> 730 /// Opacity of the element 731 /// </returns> 732 733 if (!element) { 734 throw Error.argumentNull('element'); 735 } 736 737 var hasOpacity = false; 738 var opacity; 739 740 if (element.filters) { 741 var filters = element.filters; 742 if (filters.length !== 0) { 743 var alphaFilter = filters['DXImageTransform.Microsoft.Alpha']; 744 if (alphaFilter) { 745 opacity = alphaFilter.opacity / 100.0; 746 hasOpacity = true; 747 } 748 } 749 } 750 else { 751 opacity = this.getCurrentStyle(element, 'opacity', 1); 752 hasOpacity = true; 753 } 754 755 if (hasOpacity === false) { 756 return 1.0; 757 } 758 return parseFloat(opacity); 759 }, 760 761 setElementOpacity: function(element, value) { 762 /// <summary> 763 /// Set the element's opacity 764 /// </summary> 765 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 766 /// Element 767 /// </param> 768 /// <param name="value" type="Number"> 769 /// Opacity of the element 770 /// </param> 771 772 if (!element) { 773 throw Error.argumentNull('element'); 774 } 775 776 if (element.filters) { 777 var filters = element.filters; 778 var createFilter = true; 779 if (filters.length !== 0) { 780 var alphaFilter = filters['DXImageTransform.Microsoft.Alpha']; 781 if (alphaFilter) { 782 createFilter = false; 783 alphaFilter.opacity = value * 100; 784 } 785 } 786 if (createFilter) { 787 element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (value * 100) + ')'; 788 } 789 } 790 else { 791 element.style.opacity = value; 792 } 793 }, 794 795 getVisible: function(element) { 796 /// <summary> 797 /// Check if an element is visible 798 /// </summary> 799 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 800 /// Element 801 /// </param> 802 /// <returns type="Boolean" mayBeNull="false"> 803 /// True if the element is visible, false otherwise 804 /// </returns> 805 806 // Note: reference to CommonToolkitScripts must be left intact (i.e. don't 807 // replace with 'this') because this function will be aliased 808 809 return (element && 810 ("none" != $common.getCurrentStyle(element, "display")) && 811 ("hidden" != $common.getCurrentStyle(element, "visibility"))); 812 }, 813 814 setVisible: function(element, value) { 815 /// <summary> 816 /// Check if an element is visible 817 /// </summary> 818 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 819 /// Element 820 /// </param> 821 /// <param name="value" type="Boolean" mayBeNull="false"> 822 /// True to make the element visible, false to hide it 823 /// </param> 824 825 // Note: reference to CommonToolkitScripts must be left intact (i.e. don't 826 // replace with 'this') because this function will be aliased 827 828 if (element && value != $common.getVisible(element)) { 829 if (value) { 830 if (element.style.removeAttribute) { 831 element.style.removeAttribute("display"); 832 } else { 833 element.style.removeProperty("display"); 834 } 835 } else { 836 element.style.display = 'none'; 837 } 838 element.style.visibility = value ? 'visible' : 'hidden'; 839 } 840 }, 841 842 resolveFunction: function(value) { 843 /// <summary>
844 /// Returns a function reference that corresponds to the provided value 845 /// </summary> 846 /// <param name="value" type="Object"> 847 /// The value can either be a Function, the name of a function (that can be found using window['name']), 848 /// or an expression that evaluates to a function. 849 /// </param> 850 /// <returns type="Function"> 851 /// Reference to the function, or null if not found 852 /// </returns> 853 854 if (value) { 855 if (value instanceof Function) { 856 return value; 857 } else if (String.isInstanceOfType(value) && value.length > 0) { 858 var func; 859 if ((func = window[value]) instanceof Function) { 860 return func; 861 } else if ((func = eval(value)) instanceof Function) { 862 return func; 863 } 864 } 865 } 866 return null; 867 }, 868 869 addCssClasses: function(element, classNames) { 870 /// <summary> 871 /// Adds multiple css classes to a DomElement 872 /// </summary> 873 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 874 /// <param name="classNames" type="Array">The class names to add</param> 875 876 for (var i = 0; i < classNames.length; i++) { 877 Sys.UI.DomElement.addCssClass(element, classNames[i]); 878 } 879 },
880 removeCssClasses: function(element, classNames) { 881 /// <summary> 882 /// Removes multiple css classes to a DomElement 883 /// </summary> 884 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 885 /// <param name="classNames" type="Array">The class names to remove</param> 886 887 for (var i = 0; i < classNames.length; i++) { 888 Sys.UI.DomElement.removeCssClass(element, classNames[i]); 889 } 890 }, 891 setStyle: function(element, style) { 892 /// <summary> 893 /// Sets the style of the element using the supplied style template object 894 /// </summary> 895 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 896 /// <param name="style" type="Object">The template</param> 897 898 $common.applyProperties(element.style, style); 899 }, 900 removeHandlers: function(element, events) { 901 /// <summary> 902 /// Removes a set of event handlers from an element 903 /// </summary> 904 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 905 /// <param name="events" type="Object">The template object that contains event names and delegates</param> 906 /// <remarks> 907 /// This is NOT the same as $clearHandlers which removes all delegates from a DomElement. This rather removes select delegates 908 /// from a specified element and has a matching signature as $addHandlers 909 /// </remarks> 910 for (var name in events) { 911 $removeHandler(element, name, events[name]); 912 } 913 }, 914 915 overlaps: function(r1, r2) { 916 /// <summary> 917 /// Determine if two rectangles overlap 918 /// </summary> 919 /// <param name="r1" type="Object"> 920 /// Rectangle 921 /// </param> 922 /// <param name="r2" type="Object"> 923 /// Rectangle 924 /// </param> 925 /// <returns type="Boolean"> 926 /// True if the rectangles overlap, false otherwise 927 /// </returns> 928 929 return r1.x < (r2.x + r2.width) 930 && r2.x < (r1.x + r1.width) 931 && r1.y < (r2.y + r2.height) 932 && r2.y < (r1.y + r1.height); 933 }, 934 935 containsPoint: function(rect, x, y) { 936 /// <summary> 937 /// Tests whether a point (x,y) is contained within a rectangle 938 /// </summary> 939 /// <param name="rect" type="Object">The rectangle</param> 940 /// <param name="x" type="Number">The x coordinate of the point</param> 941 /// <param name="y" type="Number">The y coordinate of the point</param> 942 943 return x >= rect.x && x < (rect.x + rect.width) && y >= rect.y && y < (rect.y + rect.height); 944 }, 945 946 isKeyDigit: function(keyCode) { 947 /// <summary> 948 /// Gets whether the supplied key-code is a digit 949 /// </summary> 950 /// <param name="keyCode" type="Number" integer="true">The key code of the event (from Sys.UI.DomEvent)</param> 951 /// <returns type="Boolean" /> 952 953 return (0x30 <= keyCode && keyCode <= 0x39); 954 }, 955 956 isKeyNavigation: function(keyCode) { 957 /// <summary> 958 /// Gets whether the supplied key-code is a navigation key 959 /// </summary> 960 /// <param name="keyCode" type="Number" integer="true">The key code of the event (from Sys.UI.DomEvent)</param> 961 /// <returns type="Boolean" /> 962 963 return (Sys.UI.Key.left <= keyCode && keyCode <= Sys.UI.Key.down); 964 }, 965 966 padLeft: function(text, size, ch, truncate) { 967 /// <summary> 968 /// Pads the left hand side of the supplied text with the specified pad character up to the requested size 969 /// </summary> 970 /// <param name="text" type="String">The text to pad</param> 971 /// <param name="size" type="Number" integer="true" optional="true">The size to pad the text (default is 2)</param> 972 /// <param name="ch" type="String" optional="true">The single character to use as the pad character (default is ' ')</param> 973 /// <param name="truncate" type="Boolean" optional="true">Whether to truncate the text to size (default is false)</param> 974 975 return $common._pad(text, size || 2, ch || ' ', 'l', truncate || false); 976 }, 977 978 padRight: function(text, size, ch, truncate) { 979 /// <summary> 980 /// Pads the right hand side of the supplied text with the specified pad character up to the requested size 981 /// </summary>
982 /// <param name="text" type="String">The text to pad</param> 983 /// <param name="size" type="Number" integer="true" optional="true">The size to pad the text (default is 2)</param> 984 /// <param name="ch" type="String" optional="true">The single character to use as the pad character (default is ' ')</param> 985 /// <param name="truncate" type="Boolean" optional="true">Whether to truncate the text to size (default is false)</param> 986 987 return $common._pad(text, size || 2, ch || ' ', 'r', truncate || false); 988 }, 989 990 _pad: function(text, size, ch, side, truncate) { 991 /// <summary> 992 /// Pads supplied text with the specified pad character up to the requested size 993 /// </summary> 994 /// <param name="text" type="String">The text to pad</param> 995 /// <param name="size" type="Number" integer="true">The size to pad the text</param> 996 /// <param name="ch" type="String">The single character to use as the pad character</param> 997 /// <param name="side" type="String">Either 'l' or 'r' to siginfy whether to pad the Left or Right side respectively</param> 998 /// <param name="truncate" type="Boolean">Whether to truncate the text to size</param> 999 1000 text = text.toString(); 1001 var length = text.length; 1002 var builder = new Sys.StringBuilder(); 1003 if (side == 'r') { 1004 builder.append(text); 1005 } 1006 while (length < size) { 1007 builder.append(ch); 1008 length++; 1009 } 1010 if (side == 'l') { 1011 builder.append(text); 1012 } 1013 var result = builder.toString(); 1014 if (truncate && result.length > size) { 1015 if (side == 'l') { 1016 result = result.substr(result.length - size, size); 1017 } else { 1018 result = result.substr(0, size); 1019 } 1020 } 1021 return result; 1022 }, 1023 1024 __DOMEvents: { 1025 focusin: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focusin", true, false, window, 1); } }, 1026 focusout: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focusout", true, false, window, 1); } }, 1027 activate: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("activate", true, true, window, 1); } }, 1028 focus: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focus", false, false, window, 1); } }, 1029 blur: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("blur", false, false, window, 1); } }, 1030 click: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("click", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1031 dblclick: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("click", true, true, window, 2, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1032 mousedown: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("mousedown", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1033 mouseup: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("mouseup", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1034 mouseover: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("mouseover", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1035 mousemove: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("mousemove", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1036 mouseout: { eventGroup: "MouseEvents", init: function(e, p) { e.initMouseEvent("mousemove", true, true, window, 1, p.screenX || 0, p.screenY || 0, p.clientX || 0, p.clientY || 0, p.ctrlKey || false, p.altKey || false, p.shiftKey || false, p.metaKey || false, p.button || 0, p.relatedTarget || null); } }, 1037 load: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("load", false, false); } }, 1038 unload: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("unload", false, false); } }, 1039 select: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("select", true, false); } }, 1040 change: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("change", true, false); } }, 1041 submit: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("submit", true, true); } }, 1042 reset: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("reset", true, false); } }, 1043 resize: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("resize", true, false); } }, 1044 scroll: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("scroll", true, false); } } 1045 }, 1046 1047 tryFireRawEvent: function(element, rawEvent) { 1048 /// <summary> 1049 /// Attempts to fire a raw DOM event on an element 1050 /// </summary> 1051 /// <param name="element" type="Sys.UI.DomElement">The element to fire the event</param> 1052 /// <param name="rawEvent" type="Object">The raw DOM event object to fire. Must not be Sys.UI.DomEvent</param> 1053 /// <returns type="Boolean">True if the event was successfully fired, otherwise false</returns> 1054 1055 try { 1056 if (element.fireEvent) { 1057 element.fireEvent("on" + rawEvent.type, rawEvent); 1058 return true; 1059 } else if (element.dispatchEvent) { 1060 element.dispatchEvent(rawEvent); 1061 return true; 1062 } 1063 } catch (e) { 1064 } 1065 return false; 1066 }, 1067 1068 tryFireEvent: function(element, eventName, properties) { 1069 /// <summary> 1070 /// Attempts to fire a DOM event on an element 1071 /// </summary> 1072 /// <param name="element" type="Sys.UI.DomElement">The element to fire the event</param> 1073 /// <param name="eventName" type="String">The name of the event to fire (without an 'on' prefix)</param> 1074 /// <param name="properties" type="Object">Properties to add to the event</param> 1075 /// <returns type="Boolean">True if the event was successfully fired, otherwise false</returns> 1076 1077 try { 1078 if (document.createEventObject) { 1079 var e = document.createEventObject(); 1080 $common.applyProperties(e, properties || {}); 1081 element.fireEvent("on" + eventName, e); 1082 return true; 1083 } else if (document.createEvent) { 1084 var def = $common.__DOMEvents[eventName]; 1085 if (def) { 1086 var e = document.createEvent(def.eventGroup); 1087 def.init(e, properties || {}); 1088 element.dispatchEvent(e); 1089 return true; 1090 } 1091 } 1092 } catch (e) { 1093 } 1094 return false; 1095 }, 1096 1097 wrapElement: function(innerElement, newOuterElement, newInnerParentElement) { 1098 /// <summary> 1099 /// Wraps an inner element with a new outer element at the same DOM location as the inner element 1100 /// </summary> 1101 /// <param name="innerElement" type="Sys.UI.DomElement">The element to be wrapped</param> 1102 /// <param name="newOuterElement" type="Sys.UI.DomElement">The new parent for the element</param> 1103 /// <returns /> 1104 1105 var parent = innerElement.parentNode; 1106 parent.replaceChild(newOuterElement, innerElement); 1107 (newInnerParentElement || newOuterElement).appendChild(innerElement); 1108 }, 1109 1110 unwrapElement: function(innerElement, oldOuterElement) { 1111 /// <summary> 1112 /// Unwraps an inner element from an outer element at the same DOM location as the outer element 1113 /// </summary> 1114 /// <param name="innerElement" type="Sys.UI.DomElement">The element to be wrapped</param> 1115 /// <param name="newOuterElement" type="Sys.UI.DomElement">The new parent for the element</param> 1116 /// <returns /> 1117 1118 var parent = oldOuterElement.parentNode; 1119 if (parent != null) { 1120 $common.removeElement(innerElement); 1121 parent.replaceChild(innerElement, oldOuterElement); 1122 } 1123 }, 1124 1125 removeElement: function(element) { 1126 /// <summary> 1127 /// Removes an element from the DOM tree 1128 /// </summary> 1129 /// <param name="element" type="Sys.UI.DomElement">The element to be removed</param> 1130 /// <returns /> 1131 1132 var parent = element.parentNode; 1133 if (parent != null) { 1134 parent.removeChild(element); 1135 } 1136 }, 1137 1138 applyProperties: function(target, properties) { 1139 /// <summary> 1140 /// Quick utility method to copy properties from a template object to a target object 1141 /// </summary> 1142 /// <param name="target" type="Object">The object to apply to</param> 1143 /// <param name="properties" type="Object">The template to copy values from</param> 1144 1145 for (var p in properties) { 1146 var pv = properties[p]; 1147 if (pv != null && Object.getType(pv) === Object) { 1148 var tv = target[p]; 1149 $common.applyProperties(tv, pv); 1150 } else { 1151 target[p] = pv; 1152 } 1153 } 1154 }, 1155 1156 createElementFromTemplate: function(template, appendToParent, nameTable) { 1157 /// <summary> 1158 /// Creates an element for the current document based on a template object 1159 /// </summary> 1160 /// <param name="template" type="Object">The template from which to create the element</param> 1161 /// <param name="appendToParent" type="Sys.UI.DomElement" optional="true" mayBeNull="true">A DomElement under which to append this element</param> 1162 /// <param name="nameTable" type="Object" optional="true" mayBeNull="true">An object to use as the storage for the element using template.name as the key</param> 1163 /// <returns type="Sys.UI.DomElement" /> 1164 /// <remarks> 1165 /// This method is useful if you find yourself using the same or similar DomElement constructions throughout a class. You can even set the templates 1166 /// as static properties for a type to cut down on overhead. This method is often called with a JSON style template: 1167 /// <code> 1168 /// var elt = $common.createElementFromTemplate({ 1169 /// nodeName : "div", 1170 /// properties : { 1171 /// style : { 1172 /// height : "100px", 1173 /// width : "100px", 1174 /// backgroundColor : "white" 1175 /// }, 1176 /// expandoAttribute : "foo" 1177 /// }, 1178 /// events : { 1179 /// click : function() { alert("foo"); }, 1180 /// mouseover : function() { elt.backgroundColor = "silver"; }, 1181 /// mouseout : function() { elt.backgroundColor = "white"; } 1182 /// },
1183 /// cssClasses : [ "class0", "class1" ], 1184 /// visible : true, 1185 /// opacity : .5 1186 /// }, someParent); 1187 /// </code> 1188 /// </remarks> 1189 1190 // if we wish to override the name table we do so here 1191 if (typeof (template.nameTable) != 'undefined') { 1192 var newNameTable = template.nameTable; 1193 if (String.isInstanceOfType(newNameTable)) { 1194 newNameTable = nameTable[newNameTable]; 1195 } 1196 if (newNameTable != null) { 1197 nameTable = newNameTable; 1198 } 1199 } 1200 1201 // get a name for the element in the nameTable 1202 var elementName = null; 1203 if (typeof (template.name) !== 'undefined') { 1204 elementName = template.name; 1205 } 1206 1207 // create or acquire the element 1208 var elt = document.createElement(template.nodeName); 1209 1210 // if our element is named, add it to the name table 1211 if (typeof (template.name) !== 'undefined' && nameTable) { 1212 nameTable[template.name] = elt; 1213 } 1214 1215 // if we wish to supply a default parent we do so here 1216 if (typeof (template.parent) !== 'undefined' && appendToParent == null) { 1217 var newParent = template.parent; 1218 if (String.isInstanceOfType(newParent)) { 1219 newParent = nameTable[newParent]; 1220 } 1221 if (newParent != null) { 1222 appendToParent = newParent; 1223 } 1224 } 1225 1226 // properties are applied as expando values to the element 1227 if (typeof (template.properties) !== 'undefined' && template.properties != null) { 1228 $common.applyProperties(elt, template.properties); 1229 } 1230 1231 // css classes are added to the element's className property 1232 if (typeof (template.cssClasses) !== 'undefined' && template.cssClasses != null) { 1233 $common.addCssClasses(elt, template.cssClasses); 1234 } 1235 1236 // events are added to the dom element using $addHandlers 1237 if (typeof (template.events) !== 'undefined' && template.events != null) { 1238 $addHandlers(elt, template.events); 1239 } 1240 1241 // if the element is visible or not its visibility is set 1242 if (typeof (template.visible) !== 'undefined' && template.visible != null) { 1243 this.setVisible(elt, template.visible); 1244 } 1245 1246 // if we have an appendToParent we will now append to it 1247 if (appendToParent) { 1248 appendToParent.appendChild(elt); 1249 } 1250 1251 // if we have opacity, apply it 1252 if (typeof (template.opacity) !== 'undefined' && template.opacity != null) { 1253 $common.setElementOpacity(elt, template.opacity); 1254 } 1255 1256 // if we have child templates, process them 1257 if (typeof (template.children) !== 'undefined' && template.children != null) { 1258 for (var i = 0; i < template.children.length; i++) { 1259 var subtemplate = template.children[i]; 1260 $common.createElementFromTemplate(subtemplate, elt, nameTable); 1261 } 1262 } 1263 1264 // if we have a content presenter for the element get it (the element itself is the default presenter for content) 1265 var contentPresenter = elt; 1266 if (typeof (template.contentPresenter) !== 'undefined' && template.contentPresenter != null) { 1267 contentPresenter = nameTable[contentPresenter]; 1268 } 1269 1270 // if we have content, add it 1271 if (typeof (template.content) !== 'undefined' && template.content != null) { 1272 var content = template.content; 1273 if (String.isInstanceOfType(content)) { 1274 content = nameTable[content]; 1275 } 1276 if (content.parentNode) { 1277 $common.wrapElement(content, elt, contentPresenter); 1278 } else { 1279 contentPresenter.appendChild(content); 1280 } 1281 } 1282 1283 // return the created element 1284 return elt; 1285 }, 1286 1287 prepareHiddenElementForATDeviceUpdate: function() { 1288 /// <summary> 1289 /// JAWS, an Assistive Technology device responds to updates to form elements 1290 /// and refreshes its document buffer to what is showing live 1291 /// in the browser. To ensure that Toolkit controls that make XmlHttpRequests to 1292 /// retrieve content are useful to users with visual disabilities, we update a 1293 /// hidden form element to ensure that JAWS conveys what is in 1294 /// the browser. See this article for more details: 1295 /// http://juicystudio.com/article/improving-ajax-applications-for-jaws-users.php 1296 /// This method creates a hidden input on the screen for any page that uses a Toolkit 1297 /// control that will perform an XmlHttpRequest. 1298 /// </summary> 1299 var objHidden = document.getElementById('hiddenInputToUpdateATBuffer_C
1299ommonToolkitScripts'); 1300 if (!objHidden) { 1301 var objHidden = document.createElement('input'); 1302 objHidden.setAttribute('type', 'hidden'); 1303 objHidden.setAttribute('value', '1'); 1304 objHidden.setAttribute('id', 'hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1305 objHidden.setAttribute('name', 'hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1306 if (document.forms[0]) { 1307 document.forms[0].appendChild(objHidden); 1308 } 1309 } 1310 }, 1311 1312 updateFormToRefreshATDeviceBuffer: function() { 1313 /// <summary> 1314 /// Updates the hidden buffer to ensure that the latest document stream is picked up 1315 /// by the screen reader. 1316 /// </summary> 1317 var objHidden = document.getElementById('hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1318 1319 if (objHidden) { 1320 if (objHidden.getAttribute('value') == '1') { 1321 objHidden.setAttribute('value', '0'); 1322 } else { 1323 objHidden.setAttribute('value', '1'); 1324 } 1325 } 1326 } 1327} 1328 1329// Create the singleton instance of the CommonToolkitScripts 1330var CommonToolkitScripts = AjaxControlToolkit.CommonToolkitScripts = new AjaxControlToolkit._CommonToolkitScripts(); 1331var $common = CommonToolkitScripts; 1332 1333// Alias functions that were moved from BlockingScripts into Common 1334Sys.UI.DomElement.getVisible = $common.getVisible; 1335Sys.UI.DomElement.setVisible = $common.setVisible; 1336Sys.UI.Control.overlaps = $common.overlaps; 1337 1338AjaxControlToolkit._DomUtility = function() { 1339 /// <summary> 1340 /// Utility functions for manipulating the DOM 1341 /// </summary> 1342} 1343AjaxControlToolkit._DomUtility.prototype = { 1344 isDescendant : function(ancestor, descendant) { 1345 /// <summary> 1346 /// Whether the specified element is a descendant of the ancestor 1347 /// </summary> 1348 /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param> 1349 /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param> 1350 /// <returns type="Boolean" /> 1351 1352 for (var n = descendant.parentNode; n != null; n = n.parentNode) { 1353 if (n == ancestor) return true; 1354 } 1355 return false; 1356 }, 1357 isDescendantOrSelf : function(ancestor, descendant) { 1358 /// <summary> 1359 /// Whether the specified element is a descendant of the ancestor or the same as the ancestor 1360 /// </summary> 1361 /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param> 1362 /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param> 1363 /// <returns type="Boolean" /> 1364 1365 if (ancestor === descendant) 1366 return true; 1367 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1368 }, 1369 isAncestor : function(descendant, ancestor) { 1370 /// <summary> 1371 /// Whether the specified element is an ancestor of the descendant 1372 /// </summary> 1373 /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param> 1374 /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param> 1375 /// <returns type="Boolean" /> 1376 1377 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1378 }, 1379 isAncestorOrSelf : function(descendant, ancestor) { 1380 /// <summary> 1381 /// Whether the specified element is an ancestor of the descendant or the same as the descendant 1382 /// </summary> 1383 /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param> 1384 /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param> 1385 /// <returns type="Boolean" /> 1386 1387 if (descendant === ancestor) 1388 return true; 1389 1390 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1391 }, 1392 isSibling : function(self, sibling) { 1393 /// <summary> 1394 /// Whether the specified element is a sibling of the self element 1395 /// </summary> 1396 /// <param name="self" type="Sys.UI.DomElement">Self node</param> 1397 /// <param name="sibling" type="Sys.UI.DomElement">Possible sibling node</param> 1398 /// <returns type="Boolean" /> 1399 1400 var parent = self.parentNode; 1401 for (var i = 0; i < parent.childNodes.length; i++) { 1402 if (parent.childNodes[i] == sibling) return true; 1403 } 1404 return false; 1405 } 1406} 1407AjaxControlToolkit._DomUtility.registerClass("AjaxControlToolkit._DomUtility"); 1408AjaxControlToolkit.DomUtility = new AjaxControlToolkit._DomUtility(); 1409 1410 1411AjaxControlToolkit.TextBoxWrapper = function(element) { 1412 /// <summary> 1413 /// Class that wraps a TextBox (INPUT type="text") to abstract-out the 1414 /// presence of a watermark (which may be visible to the user but which 1415 /// should never be read by script. 1416 /// </summary> 1417 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 1418 /// The DOM element the behavior is associated with 1419 /// </param> 1420 AjaxControlToolkit.TextBoxWrapper.initializeBase(this, [element]);
1421 this._current = element.value; 1422 this._watermark = null; 1423 this._isWatermarked = false; 1424} 1425 1426AjaxControlToolkit.TextBoxWrapper.prototype = { 1427 1428 dispose : function() { 1429 /// <summary> 1430 /// Dispose the behavior 1431 /// </summary> 1432 this.get_element().AjaxControlToolkitTextBoxWrapper = null; 1433 AjaxControlToolkit.TextBoxWrapper.callBaseMethod(this, 'dispose'); 1434 }, 1435 1436 get_Current : function() { 1437 /// <value type="String"> 1438 /// Current value actually in the TextBox (i.e., TextBox.value) 1439 /// </value> 1440 this._current = this.get_element().value; 1441 return this._current; 1442 }, 1443 set_Current : function(value) { 1444 this._current = value; 1445 this._updateElement(); 1446 }, 1447 1448 get_Value : function() { 1449 /// <value type="String"> 1450 /// Conceptual "value" of the TextBox - its contents if no watermark is present 1451 /// or "" if one is 1452 /// </value> 1453 if (this.get_IsWatermarked()) { 1454 return ""; 1455 } else { 1456 return this.get_Current(); 1457 } 1458 }, 1459 set_Value : function(text) { 1460 this.set_Current(text); 1461 if (!text || (0 == text.length)) { 1462 if (null != this._watermark) { 1463 this.set_IsWatermarked(true); 1464 } 1465 } else { 1466 this.set_IsWatermarked(false); 1467 } 1468 }, 1469 1470 get_Watermark : function() { 1471 /// <value type="String"> 1472 /// Text of the watermark for the TextBox 1473 /// </value> 1474 return this._watermark; 1475 }, 1476 set_Watermark : function(value) { 1477 this._watermark = value; 1478 this._updateElement(); 1479 }, 1480 1481 get_IsWatermarked : function() { 1482 /// <value type="Boolean"> 1483 /// true iff the TextBox is watermarked 1484 /// </value> 1485 return this._isWatermarked; 1486 }, 1487 set_IsWatermarked : function(isWatermarked) { 1488 if (this._isWatermarked != isWatermarked) { 1489 this._isWatermarked = isWatermarked; 1490 this._updateElement(); 1491 this._raiseWatermarkChanged(); 1492 } 1493 }, 1494 1495 _updateElement : function() { 1496 /// <summary> 1497 /// Updates the actual contents of the TextBox according to what should be there 1498 /// </summary> 1499 var element = this.get_element(); 1500 if (this._isWatermarked) { 1501 if (element.value != this._watermark) { 1502 element.value = this._watermark; 1503 } 1504 } else { 1505 if (element.value != this._current) { 1506 element.value = this._current; 1507 } 1508 } 1509 }, 1510 1511 add_WatermarkChanged : function(handler) { 1512 /// <summary> 1513 /// Adds a handler for the WatermarkChanged event 1514 /// </summary> 1515 /// <param name="handler" type="Function"> 1516 /// Handler 1517 /// </param> 1518 this.get_events().addHandler("WatermarkChanged", handler); 1519 }, 1520 remove_WatermarkChanged : function(handler) { 1521 /// <summary> 1522 /// Removes a handler for the WatermarkChanged event 1523 /// </summary> 1524 /// <param name="handler" type="Function"> 1525 /// Handler 1526 /// </param> 1527 this.get_events().removeHandler("WatermarkChanged", handler); 1528 }, 1529 _raiseWatermarkChanged : function() { 1530 /// <summary> 1531 /// Raises the WatermarkChanged event 1532 /// </summary> 1533 var onWatermarkChangedHandler = this.get_events().getHandler("WatermarkChanged"); 1534 if (onWatermarkChangedHandler) { 1535 onWatermarkChangedHandler(this, Sys.EventArgs.Empty); 1536 } 1537 } 1538} 1539AjaxControlToolkit.TextBoxWrapper.get_Wrapper = function(element) { 1540 /// <summary> 1541 /// Gets (creating one if necessary) the TextBoxWrapper for the specified TextBox 1542 /// </summary> 1543 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 1544 /// TextBox for which to get the wrapper 1545 /// </param> 1546 /// <returns type="AjaxControlToolkit.TextBoxWrapper"> 1547 /// TextBoxWrapper instance 1548 /// </returns> 1549 if (null == element.AjaxControlToolkitTextBoxWrapper) { 1550 element.AjaxControlToolkitTextBoxWrapper = new AjaxControlToolkit.TextBoxWrapper(element); 1551 } 1552 return element.AjaxControlToolkitTextBoxWrapper; 1553} 1554AjaxControlToolkit.TextBoxWrapper.registerClass('AjaxControlToolkit.TextBoxWrapper', Sys.UI.Behavior); 1555 1556AjaxControlToolkit.TextBoxWrapper.validatorGetValue = function(id) { 1557 /// <summary> 1558 /// Wrapper for ASP.NET's validatorGetValue to return the value from the wrapper if present 1559 /// </summary> 1560 /// <param name="id" type="String"> 1561 /// id of the element 1562 /// </param> 1563 /// <returns type="Object"> 1564 /// Value from the wrapper or result of original ValidatorGetValue 1565 /// </returns> 1566 var control = $get(id); 1567 if (control && control.AjaxControlToolkitTextBoxWrapper) { 1568 return control.AjaxControlToolkitTextBoxWrapper.get_Value(); 1569 } 1570 return AjaxControlToolkit.TextBoxWrapper._originalValidatorGetValue(id); 1571} 1572 1573// Wrap ASP.NET's ValidatorGetValue with AjaxControlToolkit.TextBoxWrapper.validatorGetValue 1574// to make validators work properly with watermarked TextBoxes 1575if (typeof(ValidatorGetValue) == 'function') { 1576 AjaxControlToolkit.TextBoxWrapper._originalValidatorGetValue = ValidatorGetValue; 1577 ValidatorGetValue = AjaxControlToolkit.TextBoxWrapper.validatorGetValue; 1578} 1579 1580 1581// Temporary fix null reference bug in Sys.CultureInfo._getAbbrMonthIndex 1582if (Sys.CultureInfo.prototype._getAbbrMonthIndex) { 1583 try { 1584 Sys.CultureInfo.prototype._getAbbrMonthIndex(''); 1585 } catch(ex) { 1586 Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) { 1587 if (!this._upperAbbrMonths) { 1588 this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames); 1589 } 1590 return Array.indexOf(this._upperAbbrMonths, this._toUpper(value)); 1591 } 1592 Sys.CultureInfo.CurrentCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex; 1593 Sys.CultureInfo.InvariantCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex; 1594 } 1595}
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.