1// Name: AjaxControlToolkit.Common.Common.debug.js 2// Assembly: AjaxControlToolkit 3// Version: 3.0.30930.28736 4// FileVersion: 3.0.30930.0 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 return Sys.UI.DomElement.getLocation(element); 156 }, 157 158 setLocation: function(element, point) { 159 /// <summary> 160 /// Sets the current location for an element. 161 /// </summary> 162 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 163 /// DOM element 164 /// </param> 165 /// <param name="point" type="Object"> 166 /// Point object (of the form {x,y}) 167 /// </param> 168 /// <remarks> 169 /// This method does not attempt to set the positioning mode of an element. 170 /// The position is relative from the elements nearest position:relative or 171 /// position:absolute element. 172 /// </remarks> 173 Sys.UI.DomElement.setLocation(element, point.x, point.y); 174 }, 175 176 getContentSize: function(element) { 177 /// <summary> 178 /// Gets the "content-box" size of an element. 179 /// </summary> 180 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 181 /// DOM element 182 /// </param> 183 /// <returns type="Object"> 184 /// Size of the element (in the form {width,height}) 185 /// </returns> 186 /// <remarks> 187 /// The "content-box" is the size of the content area *inside* of the borders and 188 /// padding of an element. The "content-box" size does not include the margins around 189 /// the element. 190 /// </remarks> 191 192 if (!element) { 193 throw Error.argumentNull('element'); 194 } 195 var size = this.getSize(element); 196 var borderBox = this.getBorderBox(element); 197 var paddingBox = this.getPaddingBox(element); 198 return { 199 width: size.width - borderBox.horizontal - paddingBox.horizontal, 200 height: size.height - borderBox.vertical - paddingBox.vertical 201 } 202 }, 203 204 getSize: function(element) { 205 /// <summary> 206 /// Gets the "border-box" size of an element. 207 /// </summary> 208 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 209 /// DOM element 210 /// </param> 211 /// <returns type="Object"> 212 /// Size of the element (in the form {width,height}) 213 /// </returns> 214 /// <remarks> 215 /// The "border-box" is the size of the content area *outside* of the borders and 216 /// padding of an element. The "border-box" size does not include the margins around 217 /// the element. 218 /// </remarks> 219 220 if (!element) { 221 throw Error.argumentNull('element'); 222 } 223 return { 224 width: element.offsetWidth, 225 height: element.offsetHeight 226 }; 227 }, 228 229 setContentSize: function(element, size) { 230 /// <summary> 231 /// Sets the "content-box" size of an element. 232 /// </summary> 233 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 234 /// DOM element 235 /// </param> 236 /// <param name="size" type="Object"> 237 /// Size of the element (in the form {width,height}) 238 /// </param> 239 /// <remarks> 240 /// The "content-box" is the size of the content area *inside* of the borders and 241 /// padding of an element. The "content-box" size does not include the margins around 242 /// the element. 243 /// </remarks> 244 245 if (!element) { 246 throw Error.argumentNull('element'); 247 } 248 if (!size) { 249 throw Error.argumentNull('size'); 250 } 251 // FF respects -moz-box-sizing css extension, so adjust the box size for the border-box 252 if (this.getCurrentStyle(element, 'MozBoxSizing') == 'border-box' || this.getCurrentStyle(element, 'BoxSizing') == 'border-box') { 253 var borderBox = this.getBorderBox(element); 254 var paddingBox = this.getPaddingBox(element); 255 size = { 256 width: size.width + borderBox.horizontal + paddingBox.horizontal, 257 height: size.height + borderBox.vertical + paddingBox.vertical 258 }; 259 } 260 element.style.width = size.width.toString() + 'px'; 261 element.style.height = size.height.toString() + 'px'; 262 }, 263 264 setSize: function(element, size) { 265 /// <summary> 266 /// Sets the "border-box" size of an element. 267 /// </summary> 268 /// <remarks> 269 /// The "border-box" is the size of the content area *outside* of the borders and 270 /// padding of an element. The "border-box" size does not include the margins around 271 /// the element. 272 /// </remarks> 273 /// <param name="element" type="Sys.UI.DomElement">DOM element</param> 274 /// <param name="size" type="Object">Size of the element (in the form {width,height})</param> 275 /// <returns /> 276 277 if (!element) { 278 throw Error.argumentNull('element'); 279 } 280 if (!size) { 281 throw Error.argumentNull('size'); 282 } 283 var borderBox = this.getBorderBox(element); 284 var paddingBox = this.getPaddingBox(element); 285 var contentSize = { 286 width: size.width - borderBox.horizontal - paddingBox.horizontal, 287 height: size.height - borderBox.vertical - paddingBox.vertical 288 }; 289 this.setContentSize(element, contentSize); 290 }, 291 292 getBounds: function(element) { 293 /// <summary>Gets the coordinates, width and height of an element.</summary> 294 /// <param name="element" domElement="true"/> 295 /// <returns type="Sys.UI.Bounds"> 296 /// A Bounds object with four fields, x, y, width and height, which contain the pixel coordinates, 297 /// width and height of the element. 298 /// </returns> 299 return Sys.UI.DomElement.getBounds(element); 300 }, 301 302 setBounds: function(element, bounds) { 303 /// <summary> 304 /// Sets the "border-box" bounds of an element 305 /// </summary> 306 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 307 /// DOM element 308 /// </param> 309 /// <param name="bounds" type="Object"> 310 /// Bounds of the element (of the form {x,y,width,height}) 311 /// </param> 312 /// <remarks> 313 /// The "border-box" is the size of the content area *outside* of the borders and 314 /// padding of an element. The "border-box" size does not include the margins around 315 /// the element. 316 /// </remarks> 317 318 if (!element) { 319 throw Error.argumentNull('element'); 320 } 321 if (!bounds) { 322 throw Error.argumentNull('bounds'); 323 } 324 this.setSize(element, bounds); 325 $common.setLocation(element, bounds); 326 }, 327 328 getClientBounds: function() { 329 /// <summary> 330 /// Gets the width and height of the browser client window (excluding scrollbars) 331 /// </summary> 332 /// <returns type="Sys.UI.Bounds"> 333 /// Browser's client width and height 334 /// </returns> 335 336 var clientWidth; 337 var clientHeight; 338 339 // getClientBounds must return dimensions excluding scrollbars, so cannot use window.innerWidth and window.innerHeight. 340 if (document.compatMode == "CSS1Compat") {
341 // Standards-compliant mode 342 clientWidth = document.documentElement.clientWidth; 343 clientHeight = document.documentElement.clientHeight; 344 } 345 else { 346 // Quirks mode 347 clientWidth = document.body.clientWidth; 348 clientHeight = document.body.clientHeight; 349 } 350 return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight); 351 }, 352 353 getMarginBox: function(element) { 354 /// <summary> 355 /// Gets the entire margin box sizes. 356 /// </summary> 357 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 358 /// DOM element 359 /// </param> 360 /// <returns type="Object"> 361 /// Element's margin box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 362 /// </returns> 363 364 if (!element) { 365 throw Error.argumentNull('element'); 366 } 367 var box = { 368 top: this.getMargin(element, AjaxControlToolkit.BoxSide.Top), 369 right: this.getMargin(element, AjaxControlToolkit.BoxSide.Right), 370 bottom: this.getMargin(element, AjaxControlToolkit.BoxSide.Bottom), 371 left: this.getMargin(element, AjaxControlToolkit.BoxSide.Left) 372 }; 373 box.horizontal = box.left + box.right; 374 box.vertical = box.top + box.bottom; 375 return box; 376 }, 377 378 getBorderBox: function(element) { 379 /// <summary> 380 /// Gets the entire border box sizes. 381 /// </summary> 382 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 383 /// DOM element 384 /// </param> 385 /// <returns type="Object"> 386 /// Element's border box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 387 /// </returns> 388 389 if (!element) { 390 throw Error.argumentNull('element'); 391 } 392 var box = { 393 top: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Top), 394 right: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Right), 395 bottom: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Bottom), 396 left: this.getBorderWidth(element, AjaxControlToolkit.BoxSide.Left) 397 }; 398 box.horizontal = box.left + box.right; 399 box.vertical = box.top + box.bottom; 400 return box; 401 }, 402 403 getPaddingBox: function(element) { 404 /// <summary> 405 /// Gets the entire padding box sizes. 406 /// </summary> 407 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 408 /// DOM element 409 /// </param> 410 /// <returns type="Object"> 411 /// Element's padding box sizes (of the form {top,left,bottom,right,horizontal,vertical}) 412 /// </returns> 413 414 if (!element) { 415 throw Error.argumentNull('element'); 416 } 417 var box = { 418 top: this.getPadding(element, AjaxControlToolkit.BoxSide.Top), 419 right: this.getPadding(element, AjaxControlToolkit.BoxSide.Right), 420 bottom: this.getPadding(element, AjaxControlToolkit.BoxSide.Bottom), 421 left: this.getPadding(element, AjaxControlToolkit.BoxSide.Left) 422 }; 423 box.horizontal = box.left + box.right; 424 box.vertical = box.top + box.bottom; 425 return box; 426 }, 427 428 isBorderVisible: function(element, boxSide) { 429 /// <summary> 430 /// Gets whether the current border style for an element on a specific boxSide is not 'none'. 431 /// </summary> 432 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 433 /// DOM element 434 /// </param> 435 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 436 /// Side of the element 437 /// </param> 438 /// <returns type="Boolean"> 439 /// Whether the current border style for an element on a specific boxSide is not 'none'. 440 /// </returns> 441 442 if (!element) { 443 throw Error.argumentNull('element'); 444 } 445 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 446 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 447 } 448 var styleName = this._borderStyleNames[boxSide]; 449 var styleValue = this.getCurrentStyle(element, styleName); 450 return styleValue != "none"; 451 }, 452 453 getMargin: function(element, boxSide) { 454 /// <summary> 455 /// Gets the margin thickness of an element on a specific boxSide. 456 /// </summary> 457 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 458 /// DOM element 459 /// </param> 460 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 461 /// Side of the element 462 /// </param> 463 /// <returns type="Number" integer="true"> 464 /// Margin thickness on the element's specified side 465 /// </returns> 466 467 if (!element) { 468 throw Error.argumentNull('element'); 469 } 470 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 471 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 472 } 473 var styleName = this._marginWidthNames[boxSide]; 474 var styleValue = this.getCurrentStyle(element, styleName); 475 try { return this.parsePadding(styleValue); } catch (ex) { return 0; } 476 }, 477 478 getBorderWidth: function(element, boxSide) { 479 /// <summary> 480 /// Gets the border thickness of an element on a specific boxSide. 481 /// </summary> 482 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 483 /// DOM element 484 /// </param> 485 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 486 /// Side of the element 487 /// </param> 488 /// <returns type="Number" integer="true"> 489 /// Border thickness on the element's specified side 490 /// </returns> 491 492 if (!element) { 493 throw Error.argumentNull('element'); 494 } 495 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 496 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 497 } 498 if (!this.isBorderVisible(element, boxSide)) { 499 return 0; 500 } 501 var styleName = this._borderWidthNames[boxSide]; 502 var styleValue = this.getCurrentStyle(element, styleName); 503 return this.parseBorderWidth(styleValue); 504 }, 505 506 getPadding: function(element, boxSide) { 507 /// <summary> 508 /// Gets the padding thickness of an element on a specific boxSide. 509 /// </summary> 510 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 511 /// DOM element 512 /// </param> 513 /// <param name="boxSide" type="AjaxControlToolkit.BoxSide"> 514 /// Side of the element 515 /// </param> 516 /// <returns type="Number" integer="true"> 517 /// Padding on the element's specified side 518 /// </returns> 519 520 if (!element) { 521 throw Error.argumentNull('element'); 522 } 523 if (boxSide < AjaxControlToolkit.BoxSide.Top || boxSide > AjaxControlToolkit.BoxSide.Left) { 524 throw Error.argumentOutOfRange(String.format(Sys.Res.enumInvalidValue, boxSide, 'AjaxControlToolkit.BoxSide')); 525 } 526 var styleName = this._paddingWidthNames[boxSide]; 527 var styleValue = this.getCurrentStyle(element, styleName); 528 return this.parsePadding(styleValue); 529 }, 530 531 parseBorderWidth: function(borderWidth) { 532 /// <summary> 533 /// Parses a border-width string into a pixel size 534 /// </summary> 535 /// <param name="borderWidth" type="String" mayBeNull="true"> 536 /// Type of border ('thin','medium','thick','inherit',px unit,null,'') 537 /// </param> 538 /// <returns type="Number" integer="true"> 539 /// Number of pixels in the border-width 540 /// </returns> 541 if (!this._borderThicknesses) { 542 543 // Populate the borderThicknesses lookup table 544 var borderThicknesses = {}; 545 var div0 = document.createElement('div'); 546 div0.style.visibility = 'hidden'; 547 div0.style.position = 'absolute'; 548 div0.style.fontSize = '1px'; 549 document.body.appendChild(div0) 550 var div1 = document.createElement('div'); 551 div1.style.height = '0px'; 552 div1.style.overflow = 'hidden'; 553 div0.appendChild(div1); 554 var base = div0.offsetHeight; 555 div1.style.borderTop = 'solid black'; 556 div1.style.borderTopWidth = 'thin'; 557 borderThicknesses['thin'] = div0.offsetHeight - base; 558 div1.style.borderTopWidth = 'medium'; 559 borderThicknesses['medium'] = div0.offsetHeight - base; 560 div1.style.borderTopWidth = 'thick'; 561 borderThicknesses['thick'] = div0.offsetHeight - base; 562 div0.removeChild(div1); 563 document.body.removeChild(div0); 564 this._borderThicknesses = borderThicknesses; 565 } 566 567 if (borderWidth) { 568 switch (borderWidth) { 569 case 'thin': 570 case 'medium': 571 case 'thick': 572 return this._borderThicknesses[borderWidth]; 573 case 'inherit': 574 return 0; 575 } 576 var unit = this.parseUnit(borderWidth);
577 Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidBorderWidthUnit, unit.type)); 578 return unit.size; 579 } 580 return 0; 581 }, 582 583 parsePadding: function(padding) { 584 /// <summary> 585 /// Parses a padding string into a pixel size 586 /// </summary> 587 /// <param name="padding" type="String" mayBeNull="true"> 588 /// Padding to parse ('inherit',px unit,null,'') 589 /// </param> 590 /// <returns type="Number" integer="true"> 591 /// Number of pixels in the padding 592 /// </returns> 593 594 if (padding) { 595 if (padding == 'inherit') { 596 return 0; 597 } 598 var unit = this.parseUnit(padding); 599 Sys.Debug.assert(unit.type == 'px', String.format(AjaxControlToolkit.Resources.Common_InvalidPaddingUnit, unit.type)); 600 return unit.size; 601 } 602 return 0; 603 }, 604 605 parseUnit: function(value) { 606 /// <summary> 607 /// Parses a unit string into a unit object 608 /// </summary> 609 /// <param name="value" type="String" mayBeNull="true"> 610 /// Value to parse (of the form px unit,% unit,em unit,...) 611 /// </param> 612 /// <returns type="Object"> 613 /// Parsed unit (of the form {size,type}) 614 /// </returns> 615 616 if (!value) { 617 throw Error.argumentNull('value'); 618 } 619 620 value = value.trim().toLowerCase(); 621 var l = value.length; 622 var s = -1; 623 for (var i = 0; i < l; i++) { 624 var ch = value.substr(i, 1); 625 if ((ch < '0' || ch > '9') && ch != '-' && ch != '.' && ch != ',') { 626 break; 627 } 628 s = i; 629 } 630 if (s == -1) { 631 throw Error.create(AjaxControlToolkit.Resources.Common_UnitHasNoDigits); 632 } 633 var type; 634 var size; 635 if (s < (l - 1)) { 636 type = value.substring(s + 1).trim(); 637 } else { 638 type = 'px'; 639 } 640 size = parseFloat(value.substr(0, s + 1)); 641 if (type == 'px') { 642 size = Math.floor(size); 643 } 644 return { 645 size: size, 646 type: type 647 }; 648 }, 649 650 getElementOpacity: function(element) { 651 /// <summary> 652 /// Get the element's opacity 653 /// </summary> 654 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 655 /// Element 656 /// </param> 657 /// <returns type="Number"> 658 /// Opacity of the element 659 /// </returns> 660 661 if (!element) { 662 throw Error.argumentNull('element'); 663 } 664 665 var hasOpacity = false; 666 var opacity; 667 668 if (element.filters) { 669 var filters = element.filters; 670 if (filters.length !== 0) { 671 var alphaFilter = filters['DXImageTransform.Microsoft.Alpha']; 672 if (alphaFilter) { 673 opacity = alphaFilter.opacity / 100.0; 674 hasOpacity = true; 675 } 676 } 677 } 678 else { 679 opacity = this.getCurrentStyle(element, 'opacity', 1); 680 hasOpacity = true; 681 } 682 683 if (hasOpacity === false) { 684 return 1.0; 685 } 686 return parseFloat(opacity); 687 }, 688 689 setElementOpacity: function(element, value) { 690 /// <summary> 691 /// Set the element's opacity 692 /// </summary> 693 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 694 /// Element 695 /// </param> 696 /// <param name="value" type="Number"> 697 /// Opacity of the element 698 /// </param> 699 700 if (!element) { 701 throw Error.argumentNull('element'); 702 } 703 704 if (element.filters) { 705 var filters = element.filters; 706 var createFilter = true; 707 if (filters.length !== 0) { 708 var alphaFilter = filters['DXImageTransform.Microsoft.Alpha']; 709 if (alphaFilter) { 710 createFilter = false; 711 alphaFilter.opacity = value * 100; 712 } 713 } 714 if (createFilter) { 715 element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (value * 100) + ')'; 716 } 717 } 718 else { 719 element.style.opacity = value; 720 } 721 }, 722 723 getVisible: function(element) { 724 /// <summary> 725 /// Check if an element is visible 726 /// </summary> 727 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 728 /// Element 729 /// </param> 730 /// <returns type="Boolean" mayBeNull="false"> 731 /// True if the element is visible, false otherwise 732 /// </returns> 733 734 // Note: reference to CommonToolkitScripts must be left intact (i.e. don't 735 // replace with 'this') because this function will be aliased 736 737 return (element && 738 ("none" != $common.getCurrentStyle(element, "display")) && 739 ("hidden" != $common.getCurrentStyle(element, "visibility"))); 740 }, 741 742 setVisible: function(element, value) { 743 /// <summary> 744 /// Check if an element is visible 745 /// </summary> 746 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 747 /// Element 748 /// </param> 749 /// <param name="value" type="Boolean" mayBeNull="false"> 750 /// True to make the element visible, false to hide it 751 /// </param> 752 753 // Note: reference to CommonToolkitScripts must be left intact (i.e. don't 754 // replace with 'this') because this function will be aliased 755 756 if (element && value != $common.getVisible(element)) { 757 if (value) { 758 if (element.style.removeAttribute) { 759 element.style.removeAttribute("display"); 760 } else { 761 element.style.removeProperty("display"); 762 } 763 } else { 764 element.style.display = 'none'; 765 } 766 element.style.visibility = value ? 'visible' : 'hidden'; 767 } 768 }, 769 770 resolveFunction: function(value) { 771 /// <summary>
772 /// Returns a function reference that corresponds to the provided value 773 /// </summary> 774 /// <param name="value" type="Object"> 775 /// The value can either be a Function, the name of a function (that can be found using window['name']), 776 /// or an expression that evaluates to a function. 777 /// </param> 778 /// <returns type="Function"> 779 /// Reference to the function, or null if not found 780 /// </returns> 781 782 if (value) { 783 if (value instanceof Function) { 784 return value; 785 } else if (String.isInstanceOfType(value) && value.length > 0) { 786 var func; 787 if ((func = window[value]) instanceof Function) { 788 return func; 789 } else if ((func = eval(value)) instanceof Function) { 790 return func; 791 } 792 } 793 } 794 return null; 795 }, 796 797 addCssClasses: function(element, classNames) { 798 /// <summary> 799 /// Adds multiple css classes to a DomElement 800 /// </summary> 801 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 802 /// <param name="classNames" type="Array">The class names to add</param> 803 804 for (var i = 0; i < classNames.length; i++) { 805 Sys.UI.DomElement.addCssClass(element, classNames[i]); 806 } 807 },
808 removeCssClasses: function(element, classNames) { 809 /// <summary> 810 /// Removes multiple css classes to a DomElement 811 /// </summary> 812 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 813 /// <param name="classNames" type="Array">The class names to remove</param> 814 815 for (var i = 0; i < classNames.length; i++) { 816 Sys.UI.DomElement.removeCssClass(element, classNames[i]); 817 } 818 }, 819 setStyle: function(element, style) { 820 /// <summary> 821 /// Sets the style of the element using the supplied style template object 822 /// </summary> 823 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 824 /// <param name="style" type="Object">The template</param> 825 826 $common.applyProperties(element.style, style); 827 }, 828 removeHandlers: function(element, events) { 829 /// <summary> 830 /// Removes a set of event handlers from an element 831 /// </summary> 832 /// <param name="element" type="Sys.UI.DomElement">The element to modify</param> 833 /// <param name="events" type="Object">The template object that contains event names and delegates</param> 834 /// <remarks> 835 /// This is NOT the same as $clearHandlers which removes all delegates from a DomElement. This rather removes select delegates 836 /// from a specified element and has a matching signature as $addHandlers 837 /// </remarks> 838 for (var name in events) { 839 $removeHandler(element, name, events[name]); 840 } 841 }, 842 843 overlaps: function(r1, r2) { 844 /// <summary> 845 /// Determine if two rectangles overlap 846 /// </summary> 847 /// <param name="r1" type="Object"> 848 /// Rectangle 849 /// </param> 850 /// <param name="r2" type="Object"> 851 /// Rectangle 852 /// </param> 853 /// <returns type="Boolean"> 854 /// True if the rectangles overlap, false otherwise 855 /// </returns> 856 857 return r1.x < (r2.x + r2.width) 858 && r2.x < (r1.x + r1.width) 859 && r1.y < (r2.y + r2.height) 860 && r2.y < (r1.y + r1.height); 861 }, 862 863 containsPoint: function(rect, x, y) { 864 /// <summary> 865 /// Tests whether a point (x,y) is contained within a rectangle 866 /// </summary> 867 /// <param name="rect" type="Object">The rectangle</param> 868 /// <param name="x" type="Number">The x coordinate of the point</param> 869 /// <param name="y" type="Number">The y coordinate of the point</param> 870 871 return x >= rect.x && x < (rect.x + rect.width) && y >= rect.y && y < (rect.y + rect.height); 872 }, 873 874 isKeyDigit: function(keyCode) { 875 /// <summary> 876 /// Gets whether the supplied key-code is a digit 877 /// </summary> 878 /// <param name="keyCode" type="Number" integer="true">The key code of the event (from Sys.UI.DomEvent)</param> 879 /// <returns type="Boolean" /> 880 881 return (0x30 <= keyCode && keyCode <= 0x39); 882 }, 883 884 isKeyNavigation: function(keyCode) { 885 /// <summary> 886 /// Gets whether the supplied key-code is a navigation key 887 /// </summary> 888 /// <param name="keyCode" type="Number" integer="true">The key code of the event (from Sys.UI.DomEvent)</param> 889 /// <returns type="Boolean" /> 890 891 return (Sys.UI.Key.left <= keyCode && keyCode <= Sys.UI.Key.down); 892 }, 893 894 padLeft: function(text, size, ch, truncate) { 895 /// <summary> 896 /// Pads the left hand side of the supplied text with the specified pad character up to the requested size 897 /// </summary> 898 /// <param name="text" type="String">The text to pad</param> 899 /// <param name="size" type="Number" integer="true" optional="true">The size to pad the text (default is 2)</param> 900 /// <param name="ch" type="String" optional="true">The single character to use as the pad character (default is ' ')</param> 901 /// <param name="truncate" type="Boolean" optional="true">Whether to truncate the text to size (default is false)</param> 902 903 return $common._pad(text, size || 2, ch || ' ', 'l', truncate || false); 904 }, 905 906 padRight: function(text, size, ch, truncate) { 907 /// <summary> 908 /// Pads the right hand side of the supplied text with the specified pad character up to the requested size 909 /// </summary>
910 /// <param name="text" type="String">The text to pad</param> 911 /// <param name="size" type="Number" integer="true" optional="true">The size to pad the text (default is 2)</param> 912 /// <param name="ch" type="String" optional="true">The single character to use as the pad character (default is ' ')</param> 913 /// <param name="truncate" type="Boolean" optional="true">Whether to truncate the text to size (default is false)</param> 914 915 return $common._pad(text, size || 2, ch || ' ', 'r', truncate || false); 916 }, 917 918 _pad: function(text, size, ch, side, truncate) { 919 /// <summary> 920 /// Pads supplied text with the specified pad character up to the requested size 921 /// </summary> 922 /// <param name="text" type="String">The text to pad</param> 923 /// <param name="size" type="Number" integer="true">The size to pad the text</param> 924 /// <param name="ch" type="String">The single character to use as the pad character</param> 925 /// <param name="side" type="String">Either 'l' or 'r' to siginfy whether to pad the Left or Right side respectively</param> 926 /// <param name="truncate" type="Boolean">Whether to truncate the text to size</param> 927 928 text = text.toString(); 929 var length = text.length; 930 var builder = new Sys.StringBuilder(); 931 if (side == 'r') { 932 builder.append(text); 933 } 934 while (length < size) { 935 builder.append(ch); 936 length++; 937 } 938 if (side == 'l') { 939 builder.append(text); 940 } 941 var result = builder.toString(); 942 if (truncate && result.length > size) { 943 if (side == 'l') { 944 result = result.substr(result.length - size, size); 945 } else { 946 result = result.substr(0, size); 947 } 948 } 949 return result; 950 }, 951 952 __DOMEvents: { 953 focusin: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focusin", true, false, window, 1); } }, 954 focusout: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focusout", true, false, window, 1); } }, 955 activate: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("activate", true, true, window, 1); } }, 956 focus: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("focus", false, false, window, 1); } }, 957 blur: { eventGroup: "UIEvents", init: function(e, p) { e.initUIEvent("blur", false, false, window, 1); } }, 958 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); } }, 959 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); } }, 960 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); } }, 961 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); } }, 962 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); } }, 963 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); } }, 964 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); } }, 965 load: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("load", false, false); } }, 966 unload: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("unload", false, false); } }, 967 select: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("select", true, false); } }, 968 change: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("change", true, false); } }, 969 submit: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("submit", true, true); } }, 970 reset: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("reset", true, false); } }, 971 resize: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("resize", true, false); } }, 972 scroll: { eventGroup: "HTMLEvents", init: function(e, p) { e.initEvent("scroll", true, false); } } 973 }, 974 975 tryFireRawEvent: function(element, rawEvent) { 976 /// <summary> 977 /// Attempts to fire a raw DOM event on an element 978 /// </summary> 979 /// <param name="element" type="Sys.UI.DomElement">The element to fire the event</param> 980 /// <param name="rawEvent" type="Object">The raw DOM event object to fire. Must not be Sys.UI.DomEvent</param> 981 /// <returns type="Boolean">True if the event was successfully fired, otherwise false</returns> 982 983 try { 984 if (element.fireEvent) { 985 element.fireEvent("on" + rawEvent.type, rawEvent); 986 return true; 987 } else if (element.dispatchEvent) { 988 element.dispatchEvent(rawEvent); 989 return true; 990 } 991 } catch (e) { 992 } 993 return false; 994 }, 995 996 tryFireEvent: function(element, eventName, properties) { 997 /// <summary> 998 /// Attempts to fire a DOM event on an element 999 /// </summary> 1000 /// <param name="element" type="Sys.UI.DomElement">The element to fire the event</param> 1001 /// <param name="eventName" type="String">The name of the event to fire (without an 'on' prefix)</param> 1002 /// <param name="properties" type="Object">Properties to add to the event</param> 1003 /// <returns type="Boolean">True if the event was successfully fired, otherwise false</returns> 1004 1005 try { 1006 if (document.createEventObject) { 1007 var e = document.createEventObject(); 1008 $common.applyProperties(e, properties || {}); 1009 element.fireEvent("on" + eventName, e); 1010 return true; 1011 } else if (document.createEvent) { 1012 var def = $common.__DOMEvents[eventName]; 1013 if (def) { 1014 var e = document.createEvent(def.eventGroup); 1015 def.init(e, properties || {}); 1016 element.dispatchEvent(e); 1017 return true; 1018 } 1019 } 1020 } catch (e) { 1021 } 1022 return false; 1023 }, 1024 1025 wrapElement: function(innerElement, newOuterElement, newInnerParentElement) { 1026 /// <summary> 1027 /// Wraps an inner element with a new outer element at the same DOM location as the inner element 1028 /// </summary> 1029 /// <param name="innerElement" type="Sys.UI.DomElement">The element to be wrapped</param> 1030 /// <param name="newOuterElement" type="Sys.UI.DomElement">The new parent for the element</param> 1031 /// <returns /> 1032 1033 var parent = innerElement.parentNode; 1034 parent.replaceChild(newOuterElement, innerElement); 1035 (newInnerParentElement || newOuterElement).appendChild(innerElement); 1036 }, 1037 1038 unwrapElement: function(innerElement, oldOuterElement) { 1039 /// <summary> 1040 /// Unwraps an inner element from an outer element at the same DOM location as the outer element 1041 /// </summary> 1042 /// <param name="innerElement" type="Sys.UI.DomElement">The element to be wrapped</param> 1043 /// <param name="newOuterElement" type="Sys.UI.DomElement">The new parent for the element</param> 1044 /// <returns /> 1045 1046 var parent = oldOuterElement.parentNode; 1047 if (parent != null) { 1048 $common.removeElement(innerElement); 1049 parent.replaceChild(innerElement, oldOuterElement); 1050 } 1051 }, 1052 1053 removeElement: function(element) { 1054 /// <summary> 1055 /// Removes an element from the DOM tree 1056 /// </summary> 1057 /// <param name="element" type="Sys.UI.DomElement">The element to be removed</param> 1058 /// <returns /> 1059 1060 var parent = element.parentNode; 1061 if (parent != null) { 1062 parent.removeChild(element); 1063 } 1064 }, 1065 1066 applyProperties: function(target, properties) { 1067 /// <summary> 1068 /// Quick utility method to copy properties from a template object to a target object 1069 /// </summary> 1070 /// <param name="target" type="Object">The object to apply to</param> 1071 /// <param name="properties" type="Object">The template to copy values from</param> 1072 1073 for (var p in properties) { 1074 var pv = properties[p]; 1075 if (pv != null && Object.getType(pv) === Object) { 1076 var tv = target[p]; 1077 $common.applyProperties(tv, pv); 1078 } else { 1079 target[p] = pv; 1080 } 1081 } 1082 }, 1083 1084 createElementFromTemplate: function(template, appendToParent, nameTable) { 1085 /// <summary> 1086 /// Creates an element for the current document based on a template object 1087 /// </summary> 1088 /// <param name="template" type="Object">The template from which to create the element</param> 1089 /// <param name="appendToParent" type="Sys.UI.DomElement" optional="true" mayBeNull="true">A DomElement under which to append this element</param> 1090 /// <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> 1091 /// <returns type="Sys.UI.DomElement" /> 1092 /// <remarks> 1093 /// This method is useful if you find yourself using the same or similar DomElement constructions throughout a class. You can even set the templates 1094 /// as static properties for a type to cut down on overhead. This method is often called with a JSON style template: 1095 /// <code> 1096 /// var elt = $common.createElementFromTemplate({ 1097 /// nodeName : "div", 1098 /// properties : { 1099 /// style : { 1100 /// height : "100px", 1101 /// width : "100px", 1102 /// backgroundColor : "white" 1103 /// }, 1104 /// expandoAttribute : "foo" 1105 /// }, 1106 /// events : { 1107 /// click : function() { alert("foo"); }, 1108 /// mouseover : function() { elt.backgroundColor = "silver"; }, 1109 /// mouseout : function() { elt.backgroundColor = "white"; } 1110 /// },
1111 /// cssClasses : [ "class0", "class1" ], 1112 /// visible : true, 1113 /// opacity : .5 1114 /// }, someParent); 1115 /// </code> 1116 /// </remarks> 1117 1118 // if we wish to override the name table we do so here 1119 if (typeof (template.nameTable) != 'undefined') { 1120 var newNameTable = template.nameTable; 1121 if (String.isInstanceOfType(newNameTable)) { 1122 newNameTable = nameTable[newNameTable]; 1123 } 1124 if (newNameTable != null) { 1125 nameTable = newNameTable; 1126 } 1127 } 1128 1129 // get a name for the element in the nameTable 1130 var elementName = null; 1131 if (typeof (template.name) !== 'undefined') { 1132 elementName = template.name; 1133 } 1134 1135 // create or acquire the element 1136 var elt = document.createElement(template.nodeName); 1137 1138 // if our element is named, add it to the name table 1139 if (typeof (template.name) !== 'undefined' && nameTable) { 1140 nameTable[template.name] = elt; 1141 } 1142 1143 // if we wish to supply a default parent we do so here 1144 if (typeof (template.parent) !== 'undefined' && appendToParent == null) { 1145 var newParent = template.parent; 1146 if (String.isInstanceOfType(newParent)) { 1147 newParent = nameTable[newParent]; 1148 } 1149 if (newParent != null) { 1150 appendToParent = newParent; 1151 } 1152 } 1153 1154 // properties are applied as expando values to the element 1155 if (typeof (template.properties) !== 'undefined' && template.properties != null) { 1156 $common.applyProperties(elt, template.properties); 1157 } 1158 1159 // css classes are added to the element's className property 1160 if (typeof (template.cssClasses) !== 'undefined' && template.cssClasses != null) { 1161 $common.addCssClasses(elt, template.cssClasses); 1162 } 1163 1164 // events are added to the dom element using $addHandlers 1165 if (typeof (template.events) !== 'undefined' && template.events != null) { 1166 $addHandlers(elt, template.events); 1167 } 1168 1169 // if the element is visible or not its visibility is set 1170 if (typeof (template.visible) !== 'undefined' && template.visible != null) { 1171 this.setVisible(elt, template.visible); 1172 } 1173 1174 // if we have an appendToParent we will now append to it 1175 if (appendToParent) { 1176 appendToParent.appendChild(elt); 1177 } 1178 1179 // if we have opacity, apply it 1180 if (typeof (template.opacity) !== 'undefined' && template.opacity != null) { 1181 $common.setElementOpacity(elt, template.opacity); 1182 } 1183 1184 // if we have child templates, process them 1185 if (typeof (template.children) !== 'undefined' && template.children != null) { 1186 for (var i = 0; i < template.children.length; i++) { 1187 var subtemplate = template.children[i]; 1188 $common.createElementFromTemplate(subtemplate, elt, nameTable); 1189 } 1190 } 1191 1192 // if we have a content presenter for the element get it (the element itself is the default presenter for content) 1193 var contentPresenter = elt; 1194 if (typeof (template.contentPresenter) !== 'undefined' && template.contentPresenter != null) { 1195 contentPresenter = nameTable[contentPresenter]; 1196 } 1197 1198 // if we have content, add it 1199 if (typeof (template.content) !== 'undefined' && template.content != null) { 1200 var content = template.content; 1201 if (String.isInstanceOfType(content)) { 1202 content = nameTable[content]; 1203 } 1204 if (content.parentNode) { 1205 $common.wrapElement(content, elt, contentPresenter); 1206 } else { 1207 contentPresenter.appendChild(content); 1208 } 1209 } 1210 1211 // return the created element 1212 return elt; 1213 }, 1214 1215 prepareHiddenElementForATDeviceUpdate: function() { 1216 /// <summary> 1217 /// JAWS, an Assistive Technology device responds to updates to form elements 1218 /// and refreshes its document buffer to what is showing live 1219 /// in the browser. To ensure that Toolkit controls that make XmlHttpRequests to 1220 /// retrieve content are useful to users with visual disabilities, we update a 1221 /// hidden form element to ensure that JAWS conveys what is in 1222 /// the browser. See this article for more details: 1223 /// http://juicystudio.com/article/improving-ajax-applications-for-jaws-users.php 1224 /// This method creates a hidden input on the screen for any page that uses a Toolkit 1225 /// control that will perform an XmlHttpRequest. 1226 /// </summary> 1227 var objHidden = document.getElementById('hiddenInputToUpdateATBuffer_C
1227ommonToolkitScripts'); 1228 if (!objHidden) { 1229 var objHidden = document.createElement('input'); 1230 objHidden.setAttribute('type', 'hidden'); 1231 objHidden.setAttribute('value', '1'); 1232 objHidden.setAttribute('id', 'hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1233 objHidden.setAttribute('name', 'hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1234 if (document.forms[0]) { 1235 document.forms[0].appendChild(objHidden); 1236 } 1237 } 1238 }, 1239 1240 updateFormToRefreshATDeviceBuffer: function() { 1241 /// <summary> 1242 /// Updates the hidden buffer to ensure that the latest document stream is picked up 1243 /// by the screen reader. 1244 /// </summary> 1245 var objHidden = document.getElementById('hiddenInputToUpdateATBuffer_CommonToolkitScripts'); 1246 1247 if (objHidden) { 1248 if (objHidden.getAttribute('value') == '1') { 1249 objHidden.setAttribute('value', '0'); 1250 } else { 1251 objHidden.setAttribute('value', '1'); 1252 } 1253 } 1254 }, 1255 1256 appendElementToFormOrBody: function(element) { 1257 /// <summary> 1258 /// Tries to append an element to the current form. If no form exists, the element will be appended to the body element. 1259 /// </summary> 1260 /// <param name="element" type="Object">The element to append.</param> 1261 if (document.forms && document.forms[0]) { 1262 document.forms[0].appendChild(element); 1263 } else { 1264 document.body.appendChild(element); 1265 } 1266 } 1267} 1268 1269// getLocation implementation from msajax 4 1270if (document.documentElement.getBoundingClientRect) { 1271 Sys.UI.DomElement.getLocation = function(element) { 1272 /// <summary>Gets the coordinates of a DOM element.</summary> 1273 /// <param name="element" domElement="true"/> 1274 /// <returns type="Sys.UI.Point"> 1275 /// A Point object with two fields, x and y, which contain the pixel coordinates of the element. 1276 /// </returns> 1277 // For a document element, body, or window, return zero. 1278 // In IE8, the boundingClientRect for body is influenced by the bounding rect of its content, and so may not be 0,0. 1279 // But for positioning purposes, elements positioned at 0,0 will be at the top even if the content has margins, etc, so 1280 // getlocation should return 0,0 for body. 1281 // In all browsers, detecting the body works by seeing if the element's parent ndoe is the element's own document's documentElement node. 1282 if (element.self || element.nodeType === 9 || // window? 1283 (element === document.documentElement) || // documentElement? 1284 (element.parentNode === element.ownerDocument.documentElement)) { // body? 1285 return new Sys.UI.Point(0, 0); 1286 } 1287 1288 // Here there is a small inconsistency with what other browsers would give for wrapping elements: 1289 // the bounding rect can be different from the first rectangle. getBoundingRect is used here 1290 // because it's more consistent and because clientRects need to be offset by the coordinates 1291 // of the frame in the parent window, which is not always accessible to script (if it's in a different 1292 // domain in particular). 1293 var clientRect = element.getBoundingClientRect(); 1294 if (!clientRect) { 1295 return new Sys.UI.Point(0,0); 1296 } 1297 // Firefox 3 can return decimals here, so round them. 1298 // This appears to be consistent with how the display engine actually places the element when there is a decimal. 1299 var ex, documentElement = element.ownerDocument.documentElement, 1300 offsetX = Math.round(clientRect.left) + documentElement.scrollLeft, 1301 offsetY = Math.round(clientRect.top) + documentElement.scrollTop; 1302 if (Sys.Browser.agent === Sys.Browser.InternetExplorer) { 1303 // When the window is an iframe, the frameborder needs to be added. This is only available from 1304 // script when the parent window is in the same domain as the frame, hence the try/catch. 1305 try { 1306 var f = element.ownerDocument.parentWindow.frameElement || null; 1307 if (f) { 1308 // frameBorder has a default of "1" so undefined must map to 0, and "0" and "no" to 2. 1309 var offset = (f.frameBorder === "0" || f.frameBorder === "no") ? 2 : 0; 1310 offsetX += offset; 1311 offsetY += offset; 1312 } 1313 } 1314 catch(ex) { 1315 } 1316 if (Sys.Browser.version === 7 && !document.documentMode) { 1317 // IE7 reapplies the page zoom level when using the returned coordinates. 1318 // therefore we must divide by the zoom level to compensate. This is not perfect, but close. 1319 // NOTE: IE8 with document.documentMode === 7 does
1319NOT emulate IE7 behavior, by design. 1320 // Also, this zoom detection does not work perfectly in IE8 compat mode, where we would want 1321 // it to be 100% always, so it is necessary that we ensure this only happens in ACTUAL IE7. 1322 // IE6 does not support zoom. 1323 var body = document.body, 1324 rect = body.getBoundingClientRect(), 1325 zoom = (rect.right-rect.left) / body.clientWidth; 1326 // zoom is not completely accurate, so snap to the previous 5% by multiplying by 100, rounding, 1327 // then subtracting zoom % 5, then dividing by 100 to get back to a multiplier. 1328 // It's not likely someone is zooming at 154%, for example, so that probably means it is actually 150%, whereas 1329 // 156% probably means 155% (the estimate tends to over-estimate). 1330 zoom = Math.round(zoom * 100); 1331 zoom = (zoom - zoom % 5) / 100; 1332 if (!isNaN(zoom) && (zoom !== 1)) { 1333 offsetX = Math.round(offsetX / zoom); 1334 offsetY = Math.round(offsetY / zoom); 1335 } 1336 } 1337 if ((document.documentMode || 0) < 8) { 1338 offsetX -= documentElement.clientLeft; 1339 offsetY -= documentElement.clientTop; 1340 } 1341 } 1342 return new Sys.UI.Point(offsetX, offsetY); 1343 } 1344} 1345else if (Sys.Browser.agent === Sys.Browser.Safari) { 1346 Sys.UI.DomElement.getLocation = function(element) { 1347 /// <summary>Gets the coordinates of a DOM element.</summary> 1348 /// <param name="element" domElement="true"/> 1349 /// <returns type="Sys.UI.Point"> 1350 /// A Point object with two fields, x and y, which contain the pixel coordinates of the element. 1351 /// </returns> 1352 // For a document element, return zero. 1353 if ((element.window && (element.window === element)) || element.nodeType === 9) return new Sys.UI.Point(0,0); 1354 1355 var offsetX = 0, offsetY = 0, 1356 parent, 1357 previous = null, 1358 previousStyle = null, 1359 currentStyle; 1360 for (parent = element; parent; previous = parent, previousStyle = currentStyle, parent = parent.offsetParent) { 1361 currentStyle = Sys.UI.DomElement._getCurrentStyle(parent); 1362 var tagName = parent.tagName ? parent.tagName.toUpperCase() : null; 1363 1364 if ((parent.offsetLeft || parent.offsetTop) && 1365 ((tagName !== "BODY") || (!previousStyle || previousStyle.position !== "absolute"))) { 1366 offsetX += parent.offsetLeft; 1367 offsetY += parent.offsetTop; 1368 } 1369 1370 if (previous && Sys.Browser.version >= 3) { 1371 offsetX += parseInt(currentStyle.borderLeftWidth); 1372 offsetY += parseInt(currentStyle.borderTopWidth); 1373 } 1374 } 1375 1376 currentStyle = Sys.UI.DomElement._getCurrentStyle(element); 1377 var elementPosition = currentStyle ? currentStyle.position : null; 1378 // If an element is absolutely positioned, its parent's scroll should not be subtracted 1379 if (!elementPosition || (elementPosition !== "absolute")) { 1380 for (parent = element.parentNode; parent; parent = parent.parentNode) { 1381 tagName = parent.tagName ? parent.tagName.toUpperCase() : null; 1382 1383 if ((tagName !== "BODY") && (tagName !== "HTML") && (parent.scrollLeft || parent.scrollTop)) { 1384 offsetX -= (parent.scrollLeft || 0); 1385 offsetY -= (parent.scrollTop || 0); 1386 } 1387 currentStyle = Sys.UI.DomElement._getCurrentStyle(parent); 1388 var parentPosition = currentStyle ? currentStyle.position : null; 1389 1390 if (parentPosition && (parentPosition === "absolute")) break; 1391 } 1392 } 1393 return new Sys.UI.Point(offsetX, offsetY); 1394 } 1395} 1396else { 1397 Sys.UI.DomElement.getLocation = function(element) { 1398 /// <summary>Gets the coordinates of a DOM element.</summary> 1399 /// <param name="element" domElement="true"/> 1400 /// <returns type="Sys.UI.Point"> 1401 /// A Point object with two fields, x and y, which contain the pixel coordinates of the element. 1402 /// </returns> 1403 // For a document element, return zero. 1404 if ((element.window && (element.window === element)) || element.nodeType === 9) return new Sys.UI.Point(0,0); 1405 1406 var offsetX = 0, offsetY = 0, 1407 parent, 1408 previous = null, 1409 previousStyle = null, 1410 currentStyle = null; 1411 for (parent = element; parent; previous = parent, previousStyle = currentStyle, parent = parent.offsetParent) { 1412 var tagName = parent.tagName ? parent.tagName.toUpperCase() : null; 1413 currentStyle = Sys.UI.DomElement._getCurrentStyle(parent); 1414 1415 if ((parent.offsetLeft || parent.offsetTop) && 1416 !((tagName === "BODY") && 1417 (!previousStyle || previousStyle.position !== "absolute"))) { 1418 1419 offsetX += parent.offsetLeft; 1420 offsetY += parent.offsetTop; 1421 } 1422 1423 if (previous !== null && currentStyle) { 1424 if ((tagName !== "TABLE") && (tagName !== "TD") && (tagName !== "HTML")) { 1425 offsetX += parseInt(currentStyle.borderLeftWidth) || 0; 1426 offsetY += parseInt(currentStyle.borderTopWidth) || 0; 1427 } 1428 if (tagName === "TABLE" && 1429 (currentStyle.position === "relative" || currentStyle.position === "absolute")) { 1430 offsetX += parseInt(currentStyle.marginLeft) || 0; 1431 offsetY += parseInt(currentStyle.marginTop) || 0; 1432 } 1433 } 1434 } 1435 1436 currentStyle = Sys.UI.DomElement._getCurrentStyle(element); 1437 var elementPosition = currentStyle ? currentStyle.position : null; 1438 // If an element is absolutely positioned, its parent's scroll should not be subtracted, except on Opera. 1439 if (!elementPosition || (elementPosition !== "absolute")) { 1440 for (parent = element.parentNode; parent; parent = parent.parentNode) { 1441 tagName = parent.tagName ? parent.tagName.toUpperCase() : null; 1442 1443 if ((tagName !== "BODY") && (tagName !== "HTML") && (parent.scrollLeft || parent.scrollTop)) { 1444 1445 offsetX -= (parent.scrollLeft || 0); 1446 offsetY -= (parent.scrollTop || 0); 1447 1448 currentStyle = Sys.UI.DomElement._getCurrentStyle(parent); 1449 if (currentStyle) { 1450 offsetX += parseInt(currentStyle.borderLeftWidth) || 0; 1451 offsetY += parseInt(currentStyle.borderTopWidth) || 0; 1452 } 1453 } 1454 } 1455 } 1456 return new Sys.UI.Point(offsetX, offsetY); 1457 } 1458} 1459 1460// Create the singleton instance of the CommonToolkitScripts 1461var CommonToolkitScripts = AjaxControlToolkit.CommonToolkitScripts = new AjaxControlToolkit._CommonToolkitScripts(); 1462var $common = CommonToolkitScripts; 1463 1464// Alias functions that were moved from BlockingScripts into Common
1465Sys.UI.DomElement.getVisible = $common.getVisible; 1466Sys.UI.DomElement.setVisible = $common.setVisible; 1467Sys.UI.Control.overlaps = $common.overlaps; 1468 1469AjaxControlToolkit._DomUtility = function() { 1470 /// <summary> 1471 /// Utility functions for manipulating the DOM 1472 /// </summary> 1473} 1474AjaxControlToolkit._DomUtility.prototype = { 1475 isDescendant : function(ancestor, descendant) { 1476 /// <summary> 1477 /// Whether the specified element is a descendant of the ancestor 1478 /// </summary> 1479 /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param> 1480 /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param> 1481 /// <returns type="Boolean" /> 1482 1483 for (var n = descendant.parentNode; n != null; n = n.parentNode) { 1484 if (n == ancestor) return true; 1485 } 1486 return false; 1487 }, 1488 isDescendantOrSelf : function(ancestor, descendant) { 1489 /// <summary> 1490 /// Whether the specified element is a descendant of the ancestor or the same as the ancestor 1491 /// </summary> 1492 /// <param name="ancestor" type="Sys.UI.DomElement">Ancestor node</param> 1493 /// <param name="descendant" type="Sys.UI.DomElement">Possible descendant node</param> 1494 /// <returns type="Boolean" /> 1495 1496 if (ancestor === descendant) 1497 return true; 1498 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1499 }, 1500 isAncestor : function(descendant, ancestor) { 1501 /// <summary> 1502 /// Whether the specified element is an ancestor of the descendant 1503 /// </summary> 1504 /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param> 1505 /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param> 1506 /// <returns type="Boolean" /> 1507 1508 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1509 }, 1510 isAncestorOrSelf : function(descendant, ancestor) { 1511 /// <summary> 1512 /// Whether the specified element is an ancestor of the descendant or the same as the descendant 1513 /// </summary> 1514 /// <param name="descendant" type="Sys.UI.DomElement">Descendant node</param> 1515 /// <param name="ancestor" type="Sys.UI.DomElement">Possible ancestor node</param> 1516 /// <returns type="Boolean" /> 1517 1518 if (descendant === ancestor) 1519 return true; 1520 1521 return AjaxControlToolkit.DomUtility.isDescendant(ancestor, descendant); 1522 }, 1523 isSibling : function(self, sibling) { 1524 /// <summary> 1525 /// Whether the specified element is a sibling of the self element 1526 /// </summary> 1527 /// <param name="self" type="Sys.UI.DomElement">Self node</param> 1528 /// <param name="sibling" type="Sys.UI.DomElement">Possible sibling node</param> 1529 /// <returns type="Boolean" /> 1530 1531 var parent = self.parentNode; 1532 for (var i = 0; i < parent.childNodes.length; i++) { 1533 if (parent.childNodes[i] == sibling) return true; 1534 } 1535 return false; 1536 } 1537} 1538AjaxControlToolkit._DomUtility.registerClass("AjaxControlToolkit._DomUtility"); 1539AjaxControlToolkit.DomUtility = new AjaxControlToolkit._DomUtility(); 1540 1541 1542AjaxControlToolkit.TextBoxWrapper = function(element) { 1543 /// <summary> 1544 /// Class that wraps a TextBox (INPUT type="text") to abstract-out the 1545 /// presence of a watermark (which may be visible to the user but which 1546 /// should never be read by script. 1547 /// </summary> 1548 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 1549 /// The DOM element the behavior is associated with 1550 /// </param> 1551 AjaxControlToolkit.TextBoxWrapper.initializeBase(this, [element]); 1552 this._current = element.value; 1553 this._watermark = null; 1554 this._isWatermarked = false; 1555} 1556 1557AjaxControlToolkit.TextBoxWrapper.prototype = { 1558 1559 dispose : function() { 1560 /// <summary> 1561 /// Dispose the behavior 1562 /// </summary>
1563 this.get_element().AjaxControlToolkitTextBoxWrapper = null; 1564 AjaxControlToolkit.TextBoxWrapper.callBaseMethod(this, 'dispose'); 1565 }, 1566 1567 get_Current : function() { 1568 /// <value type="String"> 1569 /// Current value actually in the TextBox (i.e., TextBox.value) 1570 /// </value> 1571 this._current = this.get_element().value; 1572 return this._current; 1573 }, 1574 set_Current : function(value) { 1575 this._current = value; 1576 this._updateElement(); 1577 }, 1578 1579 get_Value : function() { 1580 /// <value type="String"> 1581 /// Conceptual "value" of the TextBox - its contents if no watermark is present 1582 /// or "" if one is 1583 /// </value> 1584 if (this.get_IsWatermarked()) { 1585 return ""; 1586 } else { 1587 return this.get_Current(); 1588 } 1589 }, 1590 set_Value : function(text) { 1591 this.set_Current(text); 1592 if (!text || (0 == text.length)) { 1593 if (null != this._watermark) { 1594 this.set_IsWatermarked(true); 1595 } 1596 } else { 1597 this.set_IsWatermarked(false); 1598 } 1599 }, 1600 1601 get_Watermark : function() { 1602 /// <value type="String"> 1603 /// Text of the watermark for the TextBox 1604 /// </value> 1605 return this._watermark; 1606 }, 1607 set_Watermark : function(value) { 1608 this._watermark = value; 1609 this._updateElement(); 1610 }, 1611 1612 get_IsWatermarked : function() { 1613 /// <value type="Boolean"> 1614 /// true iff the TextBox is watermarked 1615 /// </value> 1616 return this._isWatermarked; 1617 }, 1618 set_IsWatermarked : function(isWatermarked) { 1619 if (this._isWatermarked != isWatermarked) { 1620 this._isWatermarked = isWatermarked; 1621 this._updateElement(); 1622 this._raiseWatermarkChanged(); 1623 } 1624 }, 1625 1626 _updateElement : function() { 1627 /// <summary> 1628 /// Updates the actual contents of the TextBox according to what should be there 1629 /// </summary> 1630 var element = this.get_element(); 1631 if (this._isWatermarked) { 1632 if (element.value != this._watermark) { 1633 element.value = this._watermark; 1634 } 1635 } else { 1636 if (element.value != this._current) { 1637 element.value = this._current; 1638 } 1639 } 1640 }, 1641 1642 add_WatermarkChanged : function(handler) { 1643 /// <summary> 1644 /// Adds a handler for the WatermarkChanged event 1645 /// </summary> 1646 /// <param name="handler" type="Function"> 1647 /// Handler 1648 /// </param> 1649 this.get_events().addHandler("WatermarkChanged", handler); 1650 }, 1651 remove_WatermarkChanged : function(handler) { 1652 /// <summary> 1653 /// Removes a handler for the WatermarkChanged event 1654 /// </summary> 1655 /// <param name="handler" type="Function"> 1656 /// Handler 1657 /// </param> 1658 this.get_events().removeHandler("WatermarkChanged", handler); 1659 }, 1660 _raiseWatermarkChanged : function() { 1661 /// <summary> 1662 /// Raises the WatermarkChanged event 1663 /// </summary> 1664 var onWatermarkChangedHandler = this.get_events().getHandler("WatermarkChanged"); 1665 if (onWatermarkChangedHandler) { 1666 onWatermarkChangedHandler(this, Sys.EventArgs.Empty); 1667 } 1668 } 1669} 1670AjaxControlToolkit.TextBoxWrapper.get_Wrapper = function(element) { 1671 /// <summary> 1672 /// Gets (creating one if necessary) the TextBoxWrapper for the specified TextBox 1673 /// </summary> 1674 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 1675 /// TextBox for which to get the wrapper 1676 /// </param> 1677 /// <returns type="AjaxControlToolkit.TextBoxWrapper"> 1678 /// TextBoxWrapper instance 1679 /// </returns> 1680 if (null == element.AjaxControlToolkitTextBoxWrapper) { 1681 element.AjaxControlToolkitTextBoxWrapper = new AjaxControlToolkit.TextBoxWrapper(element); 1682 } 1683 return element.AjaxControlToolkitTextBoxWrapper; 1684} 1685AjaxControlToolkit.TextBoxWrapper.registerClass('AjaxControlToolkit.TextBoxWrapper', Sys.UI.Behavior); 1686 1687AjaxControlToolkit.TextBoxWrapper.validatorGetValue = function(id) { 1688 /// <summary> 1689 /// Wrapper for ASP.NET's validatorGetValue to return the value from the wrapper if present 1690 /// </summary> 1691 /// <param name="id" type="String"> 1692 /// id of the element 1693 /// </param> 1694 /// <returns type="Object"> 1695 /// Value from the wrapper or result of original ValidatorGetValue 1696 /// </returns> 1697 var control = $get(id); 1698 if (control && control.AjaxControlToolkitTextBoxWrapper) { 1699 return control.AjaxControlToolkitTextBoxWrapper.get_Value(); 1700 } 1701 return AjaxControlToolkit.TextBoxWrapper._originalValidatorGetValue(id); 1702} 1703 1704// Wrap ASP.NET's ValidatorGetValue with AjaxControlToolkit.TextBoxWrapper.validatorGetValue 1705// to make validators work properly with watermarked TextBoxes 1706if (typeof(ValidatorGetValue) == 'function') { 1707 AjaxControlToolkit.TextBoxWrapper._originalValidatorGetValue = ValidatorGetValue; 1708 ValidatorGetValue = AjaxControlToolkit.TextBoxWrapper.validatorGetValue; 1709} 1710 1711 1712// Temporary fix null reference bug in Sys.CultureInfo._getAbbrMonthIndex 1713if (Sys.CultureInfo.prototype._getAbbrMonthIndex) { 1714 Sys.CultureInfo.prototype._getAbbrMonthIndex = function(value) { 1715 if (!this._upperAbbrMonths) { 1716 this._upperAbbrMonths = this._toUpperArray(this.dateTimeFormat.AbbreviatedMonthNames); 1717 } 1718 return Array.indexOf(this._upperAbbrMonths, this._toUpper(value)); 1719 } 1720 Sys.CultureInfo.CurrentCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex; 1721 Sys.CultureInfo.InvariantCulture._getAbbrMonthIndex = Sys.CultureInfo.prototype._getAbbrMonthIndex; 1722}
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.