1// Name: DropShadow.DropShadowBehavior.debug.js 2// Assembly: AjaxControlToolkit 3// Version: 4.1.7.1213 4// FileVersion: 4.1.7.1213 5// (c) 2010 CodePlex Foundation 6 7 8/// <reference name="MicrosoftAjax.debug.js" /> 9/// <reference path="../ExtenderBase/BaseScripts.js" /> 10/// <reference path="../Common/Common.js" /> 11/// <reference path="../RoundedCorners/RoundedCornersBehavior.js" /> 12/// <reference path="../Compat/Timer/Timer.js" /> 13 14(function () { 15 var scriptName = "ExtendedDropShadow"; 16 var e = null; 17 18 function execute() { 19 20 Type.registerNamespace('Sys.Extended.UI'); 21 22 Sys.Extended.UI.DropShadowBehavior = function (element) { 23 /// <summary> 24 /// The DropShadowBehavior is used to attach a drop shadow to the element 25 /// </summary> 26 /// <param name="element" type="Sys.UI.DomElement" domElement="true"> 27 /// DOM Element the behavior is associated with 28 /// </param> 29 Sys.Extended.UI.DropShadowBehavior.initializeBase(this, [element]); 30 31 this._opacity = 1.0; 32 this._width = 5; 33 34 this._shadowDiv = null; 35 36 this._trackPosition = null; 37 this._trackPositionDelay = 50; 38 this._timer = null; 39 this._tickHandler = null; 40 this._roundedBehavior = null; 41 this._shadowRoundedBehavior = null; 42 43 this._rounded = false; 44 this._radius = 5; 45 46 this._lastX = null; 47 this._lastY = null; 48 this._lastW = null; 49 this._lastH = null; 50 } 51 Sys.Extended.UI.DropShadowBehavior.prototype = { 52 initialize: function () { 53 /// <summary> 54 /// Initialize the behavior 55 /// </summary> 56 Sys.Extended.UI.DropShadowBehavior.callBaseMethod(this, 'initialize'); 57 58 e = this.get_element(); 59 60 if ($common.getCurrentStyle(e, 'position', e.style.position) != "absolute") { 61 e.style.position = "relative"; 62 } 63 64 if (this._rounded) { 65 this.setupRounded(); 66 } 67 68 if (this._trackPosition) { 69 this.startTimer(); 70 } 71 72 this.setShadow(); 73 }, 74 75 dispose: function () { 76 /// <summary> 77 /// Dispose the behavior 78 /// </summary> 79 80 this.stopTimer(); 81 this.disposeShadowDiv(); 82 Sys.Extended.UI.DropShadowBehavior.callBaseMethod(this, 'dispose'); 83 84 }, 85 86 buildShadowDiv: function () { 87 /// <summary> 88 /// Create the div that we'll use as the shadow 89 /// </summary> 90 91 e = this.get_element(); 92 93 if (!this.get_isInitialized() || !e || !this._width) return; 94 95 if (e.style.boxShadow == undefined && e.style.MozBoxShadow == undefined && e.style.WebkitBoxShadow == undefined) { 96 97 var div = document.createElement("DIV"); 98 div.style.backgroundColor = "black"; 99 div.style.position = "absolute"; 100 101 if (e.id) { 102 div.id = e.id + "_DropShadow"; 103 } 104 105 this._shadowDiv = div; 106 107 e.parentNode.appendChild(div); 108 109 if (this._rounded) { 110 this._shadowDiv.style.height = Math.max(0, e.offsetHeight - (2 * this._radius)) + "px"; 111 if (!this._shadowRoundedBehavior) { 112 this._shadowRoundedBehavior = $create(Sys.Extended.UI.RoundedCornersBehavior, { "Radius": this._radius }, null, null, this._shadowDiv); 113 } else { 114 this._shadowRoundedBehavior.set_Radius(this._radius); 115 } 116 } else if (this._shadowRoundedBehavior) { 117 this._shadowRoundedBehavior.set_Radius(0); 118 } 119 120 if (this._opacity != 1.0) { 121 this.setupOpacity(); 122 } 123 124 this.setShadow(false, true); 125 this.updateZIndex(); 126 } 127 128 }, 129 130 disposeShadowDiv: function () { 131 /// <summary> 132 /// Dispose of the div we use as the shadow 133 /// </summary> 134 135 if (this._shadowDiv) { 136 if (this._shadowDiv.parentNode) { 137 this._shadowDiv.parentNode.removeChild(this._shadowDiv); 138 } 139 this._shadowDiv = null; 140 } 141 142 if (this._shadowRoundedBehavior) { 143 this._shadowRoundedBehavior.dispose(); 144 this._shadowRoundedBehavior = null; 145 } 146 }, 147 148 onTimerTick: function () { 149 /// <summary> 150 /// Timer's tick handler that is used to position the shadow when its target moves 151 /// </summary> 152 this.setShadow(); 153 }, 154 155 startTimer: function () { 156 /// <summary> 157 /// Start the timer (and hence start tracking the bounds of the target element) 158 /// </summary> 159 160 if (!this._timer) { 161 if (!this._tickHandler) { 162 this._tickHandler = Function.createDelegate(this, this.onTimerTick); 163 } 164 this._timer = new Sys.Timer(); 165 this._timer.set_interval(this._trackPositionDelay); 166 this._timer.add_tick(this._tickHandler); 167 this._timer.set_enabled(true); 168 } 169 }, 170 171 stopTimer: function () { 172 /// <summary> 173 /// Stop the timer (and hence stop tracking the bounds of the target element) 174 /// </summary> 175 176 if (this._timer) { 177 this._timer.remove_tick(this._tickHandler); 178 this._timer.set_enabled(false); 179 this._timer.dispose(); 180 this._timer = null; 181 } 182 }, 183 184 setShadow: function (force, norecurse) { 185 /// <summary> 186 /// This function does the heavy lifting of positioning and sizing the shadow. 187 /// It caches values to avoid extra work - it's called on a timer so we need to 188 /// keep it light weight. 189 /// </summary> 190 /// <param name="force" type="Boolean"> 191 /// Whether to force the bounds change 192 /// </param> 193 /// <param name="norecurse" type="Boolean"> 194 /// Whether to recurse if we need to recreate the shadow div 195 /// </param> 196
197 e = this.get_element(); 198 199 if (!this.get_isInitialized() || !e || (!this._width && !force)) return; 200 201 if (e.style.boxShadow == undefined && e.style.MozBoxShadow == undefined && e.style.WebkitBoxShadow == undefined) { 202 203 var existingShadow = this._shadowDiv; 204 if (!existingShadow) { 205 this.buildShadowDiv(); 206 } 207 208 var location = { x: e.offsetLeft, y: e.offsetTop }; 209 210 if (force || this._lastX != location.x || this._lastY != location.y || !existingShadow) { 211 this._lastX = location.x; 212 this._lastY = location.y; 213 214 var w = this.get_Width(); 215 216 location.x += w; 217 location.y += w; 218 219 $common.setLocation(this._shadowDiv, location); 220 } 221 222 var h = e.offsetHeight; 223 var w = e.offsetWidth; 224 225 if (force || h != this._lastH || w != this._lastW || !existingShadow) { 226 this._lastW = w; 227 this._lastH = h; 228 if (!this._rounded || !existingShadow || norecurse) { 229 this._shadowDiv.style.width = w + "px"; 230 this._shadowDiv.style.height = h + "px"; 231 } else { 232 this.disposeShadowDiv(); 233 this.setShadow(); 234 } 235 } 236 237 if (this._shadowDiv) { 238 this._shadowDiv.style.visibility = $common.getCurrentStyle(e, 'visibility'); 239 } 240 } 241 else { 242 243 var boxShadowVals; 244 245 if (this._opacity == ".25") 246 boxShadowVals = this._width + "px " + this._width + "px " + this._width + "px " + "#D3D3D3"; 247 else if (this._opacity == ".5") 248 boxShadowVals = this._width + "px " + this._width + "px " + this._width + "px " + "#778899"; 249 else if (this._opacity == ".75") 250 boxShadowVals = this._width + "px " + this._width + "px " + this._width + "px " + "#808080"; 251 else 252 boxShadowVals = this._width + "px " + this._width + "px " + this._width + "px " + "#000"; 253 254 if (e.style.boxShadow != undefined) { 255 e.style.boxShadow = boxShadowVals; 256 } 257 else if (e.style.MozBoxShadow != undefined) { 258 e.style.MozBoxShadow = boxShadowVals; 259 } 260 else if (e.style.WebkitBoxShadow != undefined) { 261 e.style.WebkitBoxShadow = boxShadowVals; 262 } 263 } 264 }, 265 266 setupOpacity: function () { 267 /// <summary> 268 /// Set the opacity of the shadow div 269 /// </summary> 270 if (this.get_isInitialized() && this._shadowDiv) { 271 $common.setElementOpacity(this._shadowDiv, this._opacity); 272 } 273 274 }, 275 276 setupRounded: function () { 277 /// <summary> 278 /// Demand create and initialize the RoundedCornersBehavior 279 /// </summary> 280 281 if (!this._roundedBehavior && this._rounded) { 282 this._roundedBehavior = $create(Sys.Extended.UI.RoundedCornersBehavior, null, null, null, this.get_element()); 283 } 284 if (this._roundedBehavior) { 285 this._roundedBehavior.set_Radius(this._rounded ? this._radius : 0); 286 } 287 }, 288 289 updateZIndex: function () { 290 /// <summary> 291 /// Update the z-Index so the shadow div remains behind the target element 292 /// </summary> 293 294 if (!this._shadowDiv) return; 295
296 var e = this.get_element(); 297 var targetZIndex = e.style.zIndex; 298 var shadowZIndex = this._shadowDiv.style.zIndex; 299 300 if (shadowZIndex && targetZIndex && targetZIndex > shadowZIndex) { 301 return; 302 } else { 303 targetZIndex = Math.max(2, targetZIndex); 304 shadowZIndex = targetZIndex - 1; 305 } 306 e.style.zIndex = targetZIndex; 307 this._shadowDiv.style.zIndex = shadowZIndex; 308 }, 309 310 updateRoundedCorners: function () { 311 /// <summary> 312 /// Update the RoundedCorndersBehavior and recreate the shadow div so its corners are rounded as well 313 /// </summary> 314 if (this.get_isInitialized()) { 315 this.setupRounded(); 316 this.disposeShadowDiv(); 317 this.setShadow(); 318 } 319 }, 320 321 get_Opacity: function () { 322 /// <value type="Number"> 323 /// The opacity of the drop shadow, from 0 (fully transparent) to 1.0 (fully opaque). The default value is .5. 324 /// </value> 325 return this._opacity; 326 }, 327 set_Opacity: function (value) { 328 if (this._opacity != value) { 329 this._opacity = value; 330 331 this.setShadow(); 332 this.setupOpacity(); 333 334 this.raisePropertyChanged('Opacity'); 335 } 336 }, 337 338 get_Rounded: function () { 339 /// <value type="Boolean"> 340 /// Whether or not the corners of the target and drop shadow should be rounded 341 /// </value> 342 return this._rounded; 343 }, 344 set_Rounded: function (value) { 345 346 if (value != this._rounded) { 347 this._rounded = value; 348 349 this.updateRoundedCorners(); 350 this.raisePropertyChanged('Rounded'); 351 } 352 }, 353 354 get_Radius: function () { 355 /// <value type="Number" integer="true"> 356 /// Radius, in pixels, of the rounded corners 357 /// </value> 358 return this._radius; 359 }, 360 set_Radius: function (value) { 361 if (value != this._radius) { 362 this._radius = value; 363 364 this.updateRoundedCorners(); 365 this.raisePropertyChanged('Radius'); 366 } 367 }, 368 369 get_Width: function () { 370 /// <value type="Number" integer="true"> 371 /// Width in pixels of the drop shadow. The default value is 5 pixels. 372 /// </value> 373 return this._width; 374 }, 375 set_Width: function (value) { 376 377 if (value != this._width) { 378 this._width = value; 379 380 if (this._shadowDiv) { 381 $common.setVisible(this._shadowDiv, value > 0); 382 } 383 384 this.setShadow(true); 385 this.raisePropertyChanged('Width'); 386 } 387 }, 388 389 get_TrackPositionDelay: function () { 390 /// <value type="Number"> 391 /// Length of the timer interval used when tracking the position of the target 392 /// </value> 393 return this._trackPositionDelay; 394 }, 395 set_TrackPositionDelay: function (value) { 396 if (value != this._trackPositionDelay) { 397 this._trackPositionDelay = value; 398 399 if (!e) 400 e = this.get_element(); 401 402 if (e.style.boxShadow == undefined && e.style.MozBoxShadow == undefined && e.style.WebkitBoxShadow == undefined) { 403 if (this._trackPosition) { 404 this.stopTimer(); 405 this.startTimer(); 406 } 407 this.raisePropertyChanged('TrackPositionDelay'); 408 } 409 } 410 }, 411 412 get_TrackPosition: function () { 413 /// <value type="Boolean"> 414 /// Whether the drop shadow should track the position of the panel it is attached to. Use this if the panel is absolutely positioned or will otherwise move. 415 /// </value> 416 return this._trackPosition; 417 }, 418 419 set_TrackPosition: function (value) { 420 if (value != this._trackPosition) { 421 this._trackPosition = value; 422 423 if (!e)
424 e = this.get_element(); 425 426 if (e.style.boxShadow == undefined && e.style.MozBoxShadow == undefined && e.style.WebkitBoxShadow == undefined) { 427 if (this.get_element()) { 428 if (value) { 429 this.startTimer(); 430 } else { 431 this.stopTimer(); 432 } 433 } 434 this.raisePropertyChanged('TrackPosition'); 435 } 436 } 437 } 438 } 439 Sys.Extended.UI.DropShadowBehavior.registerClass('Sys.Extended.UI.DropShadowBehavior', Sys.Extended.UI.BehaviorBase); 440 Sys.registerComponent(Sys.Extended.UI.DropShadowBehavior, { name: "dropShadow" }); 441 442 } // execute 443 444 if (window.Sys && Sys.loader) { 445 Sys.loader.registerScript(scriptName, ["ExtendedBase", "ExtendedCommon", "ExtendedTimer", "ExtendedRoundedCorners"], execute); 446 } 447 else { 448 execute(); 449 } 450 451})();
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.