1// Name: AjaxControlToolkit.RoundedCorners.RoundedCornersBehavior.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/// <reference path="../ExtenderBase/BaseScripts.js" /> 15/// <reference path="../Common/Common.js" /> 16 17 18Type.registerNamespace('AjaxControlToolkit'); 19 20AjaxControlToolkit.BoxCorners = function() { 21 /// <summary> 22 /// Corners of an element 23 /// </summary> 24 /// <field name="None" type="Number" integer="true" /> 25 /// <field name="TopLeft" type="Number" integer="true" /> 26 /// <field name="TopRight" type="Number" integer="true" /> 27 /// <field name="BottomRight" type="Number" integer="true" /> 28 /// <field name="BottomLeft" type="Number" integer="true" /> 29 /// <field name="Top" type="Number" integer="true" /> 30 /// <field name="Right" type="Number" integer="true" /> 31 /// <field name="Bottom" type="Number" integer="true" /> 32 /// <field name="Left" type="Number" integer="true" /> 33 /// <field name="All" type="Number" integer="true" /> 34 throw Error.invalidOperation(); 35} 36AjaxControlToolkit.BoxCorners.prototype = { 37 None : 0x00, 38 39 TopLeft : 0x01, 40 TopRight : 0x02, 41 BottomRight : 0x04, 42 BottomLeft : 0x08, 43 44 Top : 0x01 | 0x02, 45 Right : 0x02 | 0x04, 46 Bottom : 0x04 | 0x08, 47 Left : 0x08 | 0x01, 48 All : 0x01 | 0x02 | 0x04 | 0x08 49} 50AjaxControlToolkit.BoxCorners.registerEnum("AjaxControlToolkit.BoxCorners", true); 51 52 53AjaxControlToolkit.RoundedCornersBehavior = function(element) { 54 /// <summary> 55 /// The RoundedCornersBehavior rounds the corners of its target element 56 /// </summary> 57 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 58 /// DOM element associated with the behavior 59 /// </param> 60 AjaxControlToolkit.RoundedCornersBehavior.initializeBase(this, [element]); 61 62 this._corners = AjaxControlToolkit.BoxCorners.All; 63 this._radius = 5; 64 this._color = null; 65 this._parentDiv = null; 66 this._originalStyle = null; 67 this._borderColor = null; 68 this._isDirty = true; 69} 70AjaxControlToolkit.RoundedCornersBehavior.prototype = { 71 initialize: function() { 72 /// <summary> 73 /// Initialize the behavior 74 /// </summary> 75 AjaxControlToolkit.RoundedCornersBehavior.callBaseMethod(this, 'initialize'); 76 this.update(); 77 }, 78 79 dispose: function() { 80 /// <summary> 81 /// Dispose the behavior 82 /// </summary> 83 84 this.disposeParentDiv(); 85 AjaxControlToolkit.RoundedCornersBehavior.callBaseMethod(this, 'dispose'); 86 }, 87 88 update: function() { 89 /// <summary> 90 /// Create the surrounding div that will have rounded corners 91 /// </summary> 92 var e = this.get_element(); 93 94 if (!e || !this._isDirty || this.get_isUpdating()) return; 95 96 this.disposeParentDiv(); 97 98 var color = this.getBackgroundColor(); 99 var originalWidth = e.offsetWidth; 100 var newParent = e.cloneNode(false); 101 102 // move all children into the new div. 103 this.moveChildren(e, newParent); 104 105 // modify the target element to be transparent 106 // and set up the new parent 107 this._originalStyle = e.style.cssText; 108 e.style.backgroundColor = "transparent"; 109 e.style.verticalAlign = "top"; 110 e.style.padding = "0"; 111 e.style.overflow = ""; 112 e.style.className = ""; 113 // Don't assume there is a numerical value for height. A height of "auto" is possible. 114 if (e.style.height && e.style.height != "auto") { 115 // Increase the height to account for the rounded corners 116 e.style.height = parseInt($common.getCurrentStyle(e, 'height')) + (this._radius * 2) + "px"; 117 } else { 118 // Note: Do NOT use $common.getCurrentStyle in the check below 119 // because that breaks the work-around 120 if (!e.style.width && (0 < originalWidth)) { 121 // The following line works around a problem where IE renders the first 122 // rounded DIV about 6 pixels too high if e doesn't have a width or height 123 e.style.width = originalWidth + "px"; 124 } 125 } 126 127 // these are properties we don't want cloned down to the new parent 128 newParent.style.position = ""; 129 newParent.style.border = ""; 130 newParent.style.margin = ""; 131 newParent.style.width = "100%"; 132 newParent.id = ""; 133 newParent.removeAttribute("control"); 134 135 if (this._borderColor) { 136 newParent.style.borderTopStyle = "none"; 137 newParent.style.borderBottomStyle = "none"; 138 newParent.style.borderLeftStyle = "solid"; 139 newParent.style.borderRightStyle = "solid"; 140 newParent.style.borderLeftColor = this._borderColor; 141 newParent.style.borderRightColor = this._borderColor; 142 newParent.style.borderLeftWidth = "1px"; 143 newParent.style.borderRightWidth = "1px"; 144 if (this._radius == 0) { 145 newParent.style.borderTopStyle = "solid"; 146 newParent.style.borderBottomStyle = "solid"; 147 newParent.style.borderTopColor = this._borderColor; 148 newParent.style.borderBottomColor = this._borderColor; 149 newParent.style.borderTopWidth = "1px"; 150 newParent.style.borderBottomWidth = "1px"; 151 } 152 } else { 153 newParent.style.borderTopStyle = "none"; 154 newParent.style.borderBottomStyle = "none"; 155 newParent.style.borderLeftStyle = "none"; 156 newParent.style.borderRightStyle = "none"; 157 } 158 159 // build a set of steps on each end to fake the corners. 160 // ------- (step 0) 161 // -------- (step n-1) 162 // --------- (step n) 163 // XXXXXXXXX (inner div) 164 // XXXXXXXXX 165 // --------- (bottom step n) 166 // -------- (bottom step n-1) 167 // ------ (bottom step 0) 168 169 var lastDiv = null; 170 var radius = this._radius; 171 var lines = this._radius; 172 var lastDelta = 0; 173 174 for (var i = lines; i > 0; i--) { 175 176 // figure out how much we'll need to subtract from each item 177 var angle = Math.acos(i / radius);
178 var delta = radius - Math.round(Math.sin(angle) * radius); 179 180 // build a 1 pixel tall div 181 // that's delta pixels shorter on each end. 182 183 // add the top one 184 var newDiv = document.createElement("DIV"); 185 newDiv.__roundedDiv = true; 186 newDiv.style.backgroundColor = color; 187 newDiv.style.marginLeft = delta + "px"; 188 newDiv.style.marginRight = (delta - (this._borderColor ? 2 : 0)) + "px"; 189 newDiv.style.height = "1px"; 190 newDiv.style.fontSize = "1px"; // workaround for IE wierdness with 1px divs. 191 newDiv.style.overflow = "hidden"; 192 193 if (this._borderColor) { 194 newDiv.style.borderLeftStyle = "solid"; 195 newDiv.style.borderRightStyle = "solid"; 196 newDiv.style.borderLeftColor = this._borderColor; 197 newDiv.style.borderRightColor = this._borderColor; 198 199 var offset = Math.max(0, lastDelta - delta - 1); 200 newDiv.style.borderLeftWidth = (offset + 1) + "px"; 201 newDiv.style.borderRightWidth = (offset + 1) + "px"; 202 203 if (i == lines) { 204 newDiv.__roundedDivNoBorder = true; 205 newDiv.style.backgroundColor = this._borderColor; 206 } 207 } 208 209 e.insertBefore(newDiv, lastDiv); 210 211 var topDiv = newDiv; 212 213 // add the bottom one one 214 newDiv = newDiv.cloneNode(true); 215 newDiv.__roundedDiv = true; 216 217 e.insertBefore(newDiv, lastDiv); 218 219 var bottomDiv = newDiv; 220 221 lastDiv = newDiv; 222 lastDelta = delta; 223 224 if (!this.isCornerSet(AjaxControlToolkit.BoxCorners.TopLeft)) { 225 topDiv.style.marginLeft = "0"; 226 if (this._borderColor) { 227 topDiv.style.borderLeftWidth = "1px"; 228 } 229 } 230 if (!this.isCornerSet(AjaxControlToolkit.BoxCorners.TopRight)) { 231 topDiv.style.marginRight = "0"; 232 if (this._borderColor) { 233 topDiv.style.borderRightWidth = "1px"; 234 topDiv.style.marginRight = "-2px"; 235 } 236 } 237 if (!this.isCornerSet(AjaxControlToolkit.BoxCorners.BottomLeft)) { 238 bottomDiv.style.marginLeft = "0"; 239 if (this._borderColor) { 240 bottomDiv.style.borderLeftWidth = "1px"; 241 } 242 } 243 if (!this.isCornerSet(AjaxControlToolkit.BoxCorners.BottomRight)) { 244 bottomDiv.style.marginRight = "0"; 245 if (this._borderColor) { 246 bottomDiv.style.borderRightWidth = "1px"; 247 bottomDiv.style.marginRight = "-2px"; 248 } 249 } 250 } 251 252 // finally, add the newParent (which has all the original content) 253 // into the div. 254 e.insertBefore(newParent, lastDiv); 255 this._parentDiv = newParent; 256 this._isDirty = false; 257 }, 258 259 disposeParentDiv: function() { 260 /// <summary> 261 /// Dispose the surrounding div with rounded corners 262 /// </summary> 263 264 if (this._parentDiv) { 265 // clean up the divs we added. 266 var e = this.get_element(); 267 var children = e.childNodes; 268 for (var i = children.length - 1; i >= 0; i--) { 269 var child = children[i]; 270 if (child) { 271 if (child == this._parentDiv) { 272 this.moveChildren(child, e); 273 } 274 try { 275 e.removeChild(child); 276 } catch (e) { 277 // Safari likes to throw NOT_FOUND_ERR (DOMException 8) 278 // but it seems to work fine anyway. 279 } 280 } 281 } 282 283 // restore the original style 284 if (this._originalStyle) { 285 e.style.cssText = this._originalStyle; 286 this._originalStyle = null; 287 } 288 this._parentDiv = null; 289 } 290 }, 291
292 getBackgroundColor: function() { 293 /// <summary> 294 /// Get the background color of the target element 295 /// </summary> 296 if (this._color) { 297 return this._color; 298 } 299 return $common.getCurrentStyle(this.get_element(), 'backgroundColor'); 300 }, 301 302 moveChildren: function(src, dest) { 303 /// <summary> 304 /// Move the child nodes from one element to another 305 /// </summary> 306 /// <param name="src" type="Sys.UI.DomElement" domElement="true"> 307 /// DOM Element 308 /// </param> 309 /// <param name="dest" type="Sys.UI.DomElement" domElement="true"> 310 /// DOM Element 311 /// </param> 312 313 var moveCount = 0; 314 while (src.hasChildNodes()) { 315 var child = src.childNodes[0]; 316 child = src.removeChild(child); 317 dest.appendChild(child); 318 moveCount++; 319 } 320 return moveCount; 321 }, 322 323 isCornerSet: function(corner) { 324 /// <summary> 325 /// Check whether the a flag for this corner has been set 326 /// </summary> 327 /// <param name="corner" type="AjaxControlTooolkit.BoxCorners"> 328 /// Corner to check 329 /// </param> 330 /// <returns type="Boolean"> 331 /// True if it is included in the flags, false otherwise 332 /// </returns> 333 return (this._corners & corner) != AjaxControlToolkit.BoxCorners.None; 334 }, 335 336 setCorner: function(corner, value) { 337 /// <summary> 338 /// Set a corner as one that should be rounded 339 /// </summary> 340 /// <param name="corner" type="AjaxControlToolkit.BoxCorners"> 341 /// Corner to set 342 /// </param> 343 /// <param name="value" type="Boolean"> 344 /// True to set the value, False to clear it 345 /// </param> 346 if (value) { 347 this.set_Corners(this._corners | corner); 348 } else { 349 this.set_Corners(this._corners & ~corner); 350 } 351 }, 352 353 get_Color: function() { 354 /// <value type="String"> 355 /// The background color of the rounded area an corners. By default this picks up the background color of the panel that it is attached to. 356 /// </value> 357 return this._color; 358 }, 359 set_Color: function(value) { 360 if (value != this._color) { 361 this._color = value; 362 this._isDirty = true; 363 this.update(); 364 this.raisePropertyChanged('Color'); 365 } 366 }, 367 368 get_Radius: function() { 369 /// <value type="Number" integer="true"> 370 /// The radius of the corners (and height of the added area). Default is 5. 371 /// </value> 372 return this._radius; 373 }, 374 set_Radius: function(value) { 375 if (value != this._radius) { 376 this._radius = value; 377 this._isDirty = true; 378 this.update(); 379 this.raisePropertyChanged('Radius'); 380 } 381 }, 382 383 get_Corners: function() { 384 /// <value type="AjaxControlToolkit.BoxCorners"> 385 /// Corners that should be rounded 386 /// </value> 387 return this._corners; 388 }, 389 set_Corners: function(value) { 390 if (value != this._corners) { 391 this._corners = value; 392 this._isDirty = true; 393 this.update(); 394 this.raisePropertyChanged("Corners"); 395 } 396 }, 397 398 get_BorderColor: function() { 399 /// <value type="String"> 400 /// Color of the border (and hence the rounded corners) 401 /// </value> 402 return this._borderColor; 403 }, 404 set_BorderColor: function(value) { 405 if (value != this._borderColor) { 406 this._borderColor = value; 407 this._isDirty = true; 408 this.update(); 409 this.raisePropertyChanged("BorderColor"); 410 } 411 } 412} 413AjaxControlToolkit.RoundedCornersBehavior.registerClass('AjaxControlToolkit.RoundedCornersBehavior', AjaxControlToolkit.BehaviorBase);
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.