| 1 |
define(["dojo/_base/kernel", "dojo/_base/query" ,"dojo/_base/lang", "dojo/_base/declare", "dojo/_base/sniff", |
| 2 |
"dojo/dom-construct", "dojo/dom-class", "dojo/dom-geometry", "dojo/_base/fx", "dojo/fx", "dijit/_Widget", |
| 3 |
"dojo/NodeList-fx"], |
| 4 |
function(kernel, query, lang, declare, has, domConstruct, domClass, domGeom, baseFx, coreFx, Widget, NodeListFx){ |
| 5 |
|
| 6 |
kernel.experimental("dojox.fx.Shadow"); |
| 7 |
|
| 8 |
return declare("dojox.fx.Shadow", Widget,{ |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
shadowPng: kernel.moduleUrl("dojox.fx", "resources/shadow"), |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
shadowThickness: 7, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
shadowOffset: 3, |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
opacity: 0.75, |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
animate: false, |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
node: null, |
| 41 |
|
| 42 |
startup: function(){ |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
this.inherited(arguments); |
| 47 |
this.node.style.position = "relative"; |
| 48 |
|
| 49 |
|
| 50 |
this.pieces={}; |
| 51 |
var x1 = -1 * this.shadowThickness; |
| 52 |
var y0 = this.shadowOffset; |
| 53 |
var y1 = this.shadowOffset + this.shadowThickness; |
| 54 |
this._makePiece("tl", "top", y0, "left", x1); |
| 55 |
this._makePiece("l", "top", y1, "left", x1, "scale"); |
| 56 |
this._makePiece("tr", "top", y0, "left", 0); |
| 57 |
this._makePiece("r", "top", y1, "left", 0, "scale"); |
| 58 |
this._makePiece("bl", "top", 0, "left", x1); |
| 59 |
this._makePiece("b", "top", 0, "left", 0, "crop"); |
| 60 |
this._makePiece("br", "top", 0, "left", 0); |
| 61 |
|
| 62 |
this.nodeList = query(".shadowPiece",this.node); |
| 63 |
|
| 64 |
this.setOpacity(this.opacity); |
| 65 |
this.resize(); |
| 66 |
}, |
| 67 |
|
| 68 |
_makePiece: function(name, vertAttach, vertCoord, horzAttach, horzCoord, sizing){ |
| 69 |
|
| 70 |
|
| 71 |
var img; |
| 72 |
var url = this.shadowPng + name.toUpperCase() + ".png"; |
| 73 |
if(has("ie") < 7){ |
| 74 |
img = domConstruct.create("div"); |
| 75 |
img.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+url+"'"+ |
| 76 |
(sizing?", sizingMethod='"+sizing+"'":"") + ")"; |
| 77 |
}else{ |
| 78 |
img = domConstruct.create("img", { src:url }); |
| 79 |
} |
| 80 |
|
| 81 |
img.style.position="absolute"; |
| 82 |
img.style[vertAttach]=vertCoord+"px"; |
| 83 |
img.style[horzAttach]=horzCoord+"px"; |
| 84 |
img.style.width=this.shadowThickness+"px"; |
| 85 |
img.style.height=this.shadowThickness+"px"; |
| 86 |
domClass.add(img,"shadowPiece"); |
| 87 |
this.pieces[name]=img; |
| 88 |
this.node.appendChild(img); |
| 89 |
|
| 90 |
}, |
| 91 |
|
| 92 |
setOpacity: function(n,animArgs){ |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
if(has("ie")){ return; } |
| 99 |
if(!animArgs){ animArgs = {}; } |
| 100 |
if(this.animate){ |
| 101 |
var _anims = []; |
| 102 |
this.nodeList.forEach(function(node){ |
| 103 |
_anims.push(baseFx._fade(lang.mixin(animArgs,{ node: node, end: n }))); |
| 104 |
}); |
| 105 |
coreFx.combine(_anims).play(); |
| 106 |
}else{ |
| 107 |
this.nodeList.style("opacity",n); |
| 108 |
} |
| 109 |
|
| 110 |
}, |
| 111 |
|
| 112 |
setDisabled: function(disabled){ |
| 113 |
|
| 114 |
|
| 115 |
if(disabled){ |
| 116 |
if(this.disabled){ return; } |
| 117 |
if(this.animate){ this.nodeList.fadeOut().play(); |
| 118 |
}else{ this.nodeList.style("visibility","hidden"); } |
| 119 |
this.disabled = true; |
| 120 |
}else{ |
| 121 |
if(!this.disabled){ return; } |
| 122 |
if(this.animate){ this.nodeList.fadeIn().play(); |
| 123 |
}else{ this.nodeList.style("visibility","visible"); } |
| 124 |
this.disabled = false; |
| 125 |
} |
| 126 |
}, |
| 127 |
|
| 128 |
resize: function(args){ |
| 129 |
|
| 130 |
|
| 131 |
var x; var y; |
| 132 |
if(args){ x = args.x; y = args.y; |
| 133 |
}else{ |
| 134 |
var co = domGeom.position(this.node); |
| 135 |
x = co.w; y = co.h; |
| 136 |
} |
| 137 |
var sideHeight = y - (this.shadowOffset+this.shadowThickness); |
| 138 |
if (sideHeight < 0) { sideHeight = 0; } |
| 139 |
if (y < 1) { y = 1; } |
| 140 |
if (x < 1) { x = 1; } |
| 141 |
with(this.pieces){ |
| 142 |
l.style.height = sideHeight+"px"; |
| 143 |
r.style.height = sideHeight+"px"; |
| 144 |
b.style.width = x+"px"; |
| 145 |
bl.style.top = y+"px"; |
| 146 |
b.style.top = y+"px"; |
| 147 |
br.style.top = y+"px"; |
| 148 |
tr.style.left = x+"px"; |
| 149 |
r.style.left = x+"px"; |
| 150 |
br.style.left = x+"px"; |
| 151 |
} |
| 152 |
} |
| 153 |
}); |
| 154 |
}); |