| 1 |
dojo.provide("dojox.mobile.app.ImageView"); |
| 2 |
dojo.experimental("dojox.mobile.app.ImageView"); |
| 3 |
dojo.require("dojox.mobile.app._Widget"); |
| 4 |
|
| 5 |
dojo.require("dojo.fx.easing"); |
| 6 |
|
| 7 |
dojo.declare("dojox.mobile.app.ImageView", dojox.mobile.app._Widget, { |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
zoom: 1, |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
zoomCenterX: 0, |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
zoomCenterY: 0, |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
maxZoom: 5, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
autoZoomLevel: 3, |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
disableAutoZoom: false, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
disableSwipe: false, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
autoZoomEvent: null, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
_leftImg: null, |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
_centerImg: null, |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
_rightImg: null, |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
_leftSmallImg: null, |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
_centerSmallImg: null, |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
_rightSmallImg: null, |
| 66 |
|
| 67 |
constructor: function(){ |
| 68 |
|
| 69 |
this.panX = 0; |
| 70 |
this.panY = 0; |
| 71 |
|
| 72 |
this.handleLoad = dojo.hitch(this, this.handleLoad); |
| 73 |
this._updateAnimatedZoom = dojo.hitch(this, this._updateAnimatedZoom); |
| 74 |
this._updateAnimatedPan = dojo.hitch(this, this._updateAnimatedPan); |
| 75 |
this._onAnimPanEnd = dojo.hitch(this, this._onAnimPanEnd); |
| 76 |
}, |
| 77 |
|
| 78 |
buildRendering: function(){ |
| 79 |
this.inherited(arguments); |
| 80 |
|
| 81 |
this.canvas = dojo.create("canvas", {}, this.domNode); |
| 82 |
|
| 83 |
dojo.addClass(this.domNode, "mblImageView"); |
| 84 |
}, |
| 85 |
|
| 86 |
postCreate: function(){ |
| 87 |
this.inherited(arguments); |
| 88 |
|
| 89 |
this.size = dojo.marginBox(this.domNode); |
| 90 |
|
| 91 |
dojo.style(this.canvas, { |
| 92 |
width: this.size.w + "px", |
| 93 |
height: this.size.h + "px" |
| 94 |
}); |
| 95 |
this.canvas.height = this.size.h; |
| 96 |
this.canvas.width = this.size.w; |
| 97 |
|
| 98 |
var _this = this; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
this.connect(this.domNode, "onmousedown", function(event){ |
| 103 |
if(_this.isAnimating()){ |
| 104 |
return; |
| 105 |
} |
| 106 |
if(_this.panX){ |
| 107 |
_this.handleDragEnd(); |
| 108 |
} |
| 109 |
|
| 110 |
_this.downX = event.targetTouches ? event.targetTouches[0].clientX : event.clientX; |
| 111 |
_this.downY = event.targetTouches ? event.targetTouches[0].clientY : event.clientY; |
| 112 |
}); |
| 113 |
|
| 114 |
|
| 115 |
this.connect(this.domNode, "onmousemove", function(event){ |
| 116 |
if(_this.isAnimating()){ |
| 117 |
return; |
| 118 |
} |
| 119 |
if((!_this.downX && _this.downX !== 0) || (!_this.downY && _this.downY !== 0)){ |
| 120 |
|
| 121 |
return; |
| 122 |
} |
| 123 |
|
| 124 |
if((!_this.disableSwipe && _this.zoom == 1) |
| 125 |
|| (!_this.disableAutoZoom && _this.zoom != 1)){ |
| 126 |
var x = event.targetTouches ? |
| 127 |
event.targetTouches[0].clientX : event.pageX; |
| 128 |
var y = event.targetTouches ? |
| 129 |
event.targetTouches[0].clientY : event.pageY; |
| 130 |
|
| 131 |
_this.panX = x - _this.downX; |
| 132 |
_this.panY = y - _this.downY; |
| 133 |
|
| 134 |
if(_this.zoom == 1){ |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
if(Math.abs(_this.panX) > 10){ |
| 139 |
_this.render(); |
| 140 |
} |
| 141 |
}else{ |
| 142 |
|
| 143 |
|
| 144 |
if(Math.abs(_this.panX) > 10 || Math.abs(_this.panY) > 10){ |
| 145 |
_this.render(); |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
}); |
| 150 |
|
| 151 |
this.connect(this.domNode, "onmouseout", function(event){ |
| 152 |
if(!_this.isAnimating() && _this.panX){ |
| 153 |
_this.handleDragEnd(); |
| 154 |
} |
| 155 |
}); |
| 156 |
|
| 157 |
this.connect(this.domNode, "onmouseover", function(event){ |
| 158 |
_this.downX = _this.downY = null; |
| 159 |
}); |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
this.connect(this.domNode, "onclick", function(event){ |
| 164 |
if(_this.isAnimating()){ |
| 165 |
return; |
| 166 |
} |
| 167 |
if(_this.downX == null || _this.downY == null){ |
| 168 |
return; |
| 169 |
} |
| 170 |
|
| 171 |
var x = (event.targetTouches ? |
| 172 |
event.targetTouches[0].clientX : event.pageX); |
| 173 |
var y = (event.targetTouches ? |
| 174 |
event.targetTouches[0].clientY : event.pageY); |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
if(Math.abs(_this.panX) > 14 || Math.abs(_this.panY) > 14){ |
| 179 |
_this.downX = _this.downY = null; |
| 180 |
_this.handleDragEnd(); |
| 181 |
return; |
| 182 |
} |
| 183 |
_this.downX = _this.downY = null; |
| 184 |
|
| 185 |
if(!_this.disableAutoZoom){ |
| 186 |
|
| 187 |
if(!_this._centerImg || !_this._centerImg._loaded){ |
| 188 |
|
| 189 |
return; |
| 190 |
} |
| 191 |
if(_this.zoom != 1){ |
| 192 |
_this.set("animatedZoom", 1); |
| 193 |
return; |
| 194 |
} |
| 195 |
|
| 196 |
var pos = dojo._abs(_this.domNode); |
| 197 |
|
| 198 |
|
| 199 |
var xRatio = _this.size.w / _this._centerImg.width; |
| 200 |
var yRatio = _this.size.h / _this._centerImg.height; |
| 201 |
|
| 202 |
|
| 203 |
_this.zoomTo( |
| 204 |
((x - pos.x) / xRatio) - _this.panX, |
| 205 |
((y - pos.y) / yRatio) - _this.panY, |
| 206 |
_this.autoZoomLevel); |
| 207 |
} |
| 208 |
}); |
| 209 |
|
| 210 |
|
| 211 |
dojo.connect(this.domNode, "flick", this, "handleFlick"); |
| 212 |
}, |
| 213 |
|
| 214 |
isAnimating: function(){ |
| 215 |
|
| 216 |
|
| 217 |
return this._anim && this._anim.status() == "playing"; |
| 218 |
}, |
| 219 |
|
| 220 |
handleDragEnd: function(){ |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
this.downX = this.downY = null; |
| 226 |
console.log("handleDragEnd"); |
| 227 |
|
| 228 |
if(this.zoom == 1){ |
| 229 |
if(!this.panX){ |
| 230 |
return; |
| 231 |
} |
| 232 |
|
| 233 |
var leftLoaded = (this._leftImg && this._leftImg._loaded) |
| 234 |
|| (this._leftSmallImg && this._leftSmallImg._loaded); |
| 235 |
var rightLoaded = (this._rightImg && this._rightImg._loaded) |
| 236 |
|| (this._rightSmallImg && this._rightSmallImg._loaded); |
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
var doMove = |
| 241 |
!(Math.abs(this.panX) < this._centerImg._baseWidth / 2) && |
| 242 |
( |
| 243 |
(this.panX > 0 && leftLoaded ? 1 : 0) || |
| 244 |
(this.panX < 0 && rightLoaded ? 1 : 0) |
| 245 |
); |
| 246 |
|
| 247 |
|
| 248 |
if(!doMove){ |
| 249 |
|
| 250 |
|
| 251 |
this._animPanTo(0, dojo.fx.easing.expoOut, 700); |
| 252 |
}else{ |
| 253 |
|
| 254 |
this.moveTo(this.panX); |
| 255 |
} |
| 256 |
}else{ |
| 257 |
if(!this.panX && !this.panY){ |
| 258 |
return; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
this.zoomCenterX -= (this.panX / this.zoom); |
| 263 |
this.zoomCenterY -= (this.panY / this.zoom); |
| 264 |
|
| 265 |
this.panX = this.panY = 0; |
| 266 |
} |
| 267 |
|
| 268 |
}, |
| 269 |
|
| 270 |
handleFlick: function(event){ |
| 271 |
|
| 272 |
|
| 273 |
if(this.zoom == 1 && event.duration < 500){ |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
if(event.direction == "ltr"){ |
| 279 |
this.moveTo(1); |
| 280 |
}else if(event.direction == "rtl"){ |
| 281 |
this.moveTo(-1); |
| 282 |
} |
| 283 |
|
| 284 |
this.downX = this.downY = null; |
| 285 |
} |
| 286 |
}, |
| 287 |
|
| 288 |
moveTo: function(direction){ |
| 289 |
direction = direction > 0 ? 1 : -1; |
| 290 |
var toImg; |
| 291 |
|
| 292 |
if(direction < 1){ |
| 293 |
if(this._rightImg && this._rightImg._loaded){ |
| 294 |
toImg = this._rightImg; |
| 295 |
}else if(this._rightSmallImg && this._rightSmallImg._loaded){ |
| 296 |
toImg = this._rightSmallImg; |
| 297 |
} |
| 298 |
}else{ |
| 299 |
if(this._leftImg && this._leftImg._loaded){ |
| 300 |
toImg = this._leftImg; |
| 301 |
}else if(this._leftSmallImg && this._leftSmallImg._loaded){ |
| 302 |
toImg = this._leftSmallImg; |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
this._moveDir = direction; |
| 307 |
var _this = this; |
| 308 |
|
| 309 |
if(toImg && toImg._loaded){ |
| 310 |
|
| 311 |
this._animPanTo(this.size.w * direction, null, 500, function(){ |
| 312 |
_this.panX = 0; |
| 313 |
_this.panY = 0; |
| 314 |
|
| 315 |
if(direction < 0){ |
| 316 |
|
| 317 |
_this._switchImage("left", "right"); |
| 318 |
}else{ |
| 319 |
|
| 320 |
_this._switchImage("right", "left"); |
| 321 |
} |
| 322 |
|
| 323 |
_this.render(); |
| 324 |
_this.onChange(direction * -1); |
| 325 |
}); |
| 326 |
|
| 327 |
}else{ |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
console.log("moveTo image not loaded!", toImg); |
| 333 |
|
| 334 |
this._animPanTo(0, dojo.fx.easing.expoOut, 700); |
| 335 |
} |
| 336 |
}, |
| 337 |
|
| 338 |
_switchImage: function(toImg, fromImg){ |
| 339 |
var toSmallImgName = "_" + toImg + "SmallImg"; |
| 340 |
var toImgName = "_" + toImg + "Img"; |
| 341 |
|
| 342 |
var fromSmallImgName = "_" + fromImg + "SmallImg"; |
| 343 |
var fromImgName = "_" + fromImg + "Img"; |
| 344 |
|
| 345 |
this[toImgName] = this._centerImg; |
| 346 |
this[toSmallImgName] = this._centerSmallImg; |
| 347 |
|
| 348 |
this[toImgName]._type = toImg; |
| 349 |
|
| 350 |
if(this[toSmallImgName]){ |
| 351 |
this[toSmallImgName]._type = toImg; |
| 352 |
} |
| 353 |
|
| 354 |
this._centerImg = this[fromImgName]; |
| 355 |
this._centerSmallImg = this[fromSmallImgName]; |
| 356 |
this._centerImg._type = "center"; |
| 357 |
|
| 358 |
if(this._centerSmallImg){ |
| 359 |
this._centerSmallImg._type = "center"; |
| 360 |
} |
| 361 |
this[fromImgName] = this[fromSmallImgName] = null; |
| 362 |
}, |
| 363 |
|
| 364 |
_animPanTo: function(to, easing, duration, callback){ |
| 365 |
this._animCallback = callback; |
| 366 |
this._anim = new dojo.Animation({ |
| 367 |
curve: [this.panX, to], |
| 368 |
onAnimate: this._updateAnimatedPan, |
| 369 |
duration: duration || 500, |
| 370 |
easing: easing, |
| 371 |
onEnd: this._onAnimPanEnd |
| 372 |
}); |
| 373 |
|
| 374 |
this._anim.play(); |
| 375 |
return this._anim; |
| 376 |
}, |
| 377 |
|
| 378 |
onChange: function(direction){ |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
}, |
| 383 |
|
| 384 |
_updateAnimatedPan: function(amount){ |
| 385 |
this.panX = amount; |
| 386 |
this.render(); |
| 387 |
}, |
| 388 |
|
| 389 |
_onAnimPanEnd: function(){ |
| 390 |
this.panX = this.panY = 0; |
| 391 |
|
| 392 |
if(this._animCallback){ |
| 393 |
this._animCallback(); |
| 394 |
} |
| 395 |
}, |
| 396 |
|
| 397 |
zoomTo: function(centerX, centerY, zoom){ |
| 398 |
this.set("zoomCenterX", centerX); |
| 399 |
this.set("zoomCenterY", centerY); |
| 400 |
|
| 401 |
this.set("animatedZoom", zoom); |
| 402 |
}, |
| 403 |
|
| 404 |
render: function(){ |
| 405 |
var cxt = this.canvas.getContext('2d'); |
| 406 |
|
| 407 |
cxt.clearRect(0, 0, this.canvas.width, this.canvas.height); |
| 408 |
|
| 409 |
|
| 410 |
this._renderImg( |
| 411 |
this._centerSmallImg, |
| 412 |
this._centerImg, |
| 413 |
this.zoom == 1 ? (this.panX < 0 ? 1 : this.panX > 0 ? -1 : 0) : 0); |
| 414 |
|
| 415 |
if(this.zoom == 1 && this.panX != 0){ |
| 416 |
if(this.panX > 0){ |
| 417 |
|
| 418 |
this._renderImg(this._leftSmallImg, this._leftImg, 1); |
| 419 |
}else{ |
| 420 |
|
| 421 |
this._renderImg(this._rightSmallImg, this._rightImg, -1); |
| 422 |
} |
| 423 |
} |
| 424 |
}, |
| 425 |
|
| 426 |
_renderImg: function(smallImg, largeImg, panDir){ |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
var img = (largeImg && largeImg._loaded) ? largeImg : smallImg; |
| 433 |
|
| 434 |
if(!img || !img._loaded){ |
| 435 |
|
| 436 |
return; |
| 437 |
} |
| 438 |
var cxt = this.canvas.getContext('2d'); |
| 439 |
|
| 440 |
var baseWidth = img._baseWidth; |
| 441 |
var baseHeight = img._baseHeight; |
| 442 |
|
| 443 |
|
| 444 |
var desiredWidth = baseWidth * this.zoom; |
| 445 |
var desiredHeight = baseHeight * this.zoom; |
| 446 |
|
| 447 |
|
| 448 |
var destWidth = Math.min(this.size.w, desiredWidth); |
| 449 |
var destHeight = Math.min(this.size.h, desiredHeight); |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
var sourceWidth = this.dispWidth = img.width * (destWidth / desiredWidth); |
| 454 |
var sourceHeight = this.dispHeight = img.height * (destHeight / desiredHeight); |
| 455 |
|
| 456 |
var zoomCenterX = this.zoomCenterX - (this.panX / this.zoom); |
| 457 |
var zoomCenterY = this.zoomCenterY - (this.panY / this.zoom); |
| 458 |
|
| 459 |
|
| 460 |
var centerX = Math.floor(Math.max(sourceWidth / 2, |
| 461 |
Math.min(img.width - sourceWidth / 2, zoomCenterX))); |
| 462 |
var centerY = Math.floor(Math.max(sourceHeight / 2, |
| 463 |
Math.min(img.height - sourceHeight / 2, zoomCenterY))); |
| 464 |
|
| 465 |
|
| 466 |
var sourceX = Math.max(0, |
| 467 |
Math.round((img.width - sourceWidth)/2 + (centerX - img._centerX)) ); |
| 468 |
var sourceY = Math.max(0, |
| 469 |
Math.round((img.height - sourceHeight) / 2 + (centerY - img._centerY)) |
| 470 |
); |
| 471 |
|
| 472 |
var destX = Math.round(Math.max(0, this.canvas.width - destWidth)/2); |
| 473 |
var destY = Math.round(Math.max(0, this.canvas.height - destHeight)/2); |
| 474 |
|
| 475 |
var oldDestWidth = destWidth; |
| 476 |
var oldSourceWidth = sourceWidth; |
| 477 |
|
| 478 |
if(this.zoom == 1 && panDir && this.panX){ |
| 479 |
|
| 480 |
if(this.panX < 0){ |
| 481 |
if(panDir > 0){ |
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
destWidth -= Math.abs(this.panX); |
| 486 |
destX = 0; |
| 487 |
}else if(panDir < 0){ |
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
destWidth = Math.max(1, Math.abs(this.panX) - 5); |
| 493 |
destX = this.size.w - destWidth; |
| 494 |
} |
| 495 |
}else{ |
| 496 |
if(panDir > 0){ |
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
destWidth = Math.max(1, Math.abs(this.panX) - 5); |
| 502 |
destX = 0; |
| 503 |
}else if(panDir < 0){ |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
destWidth -= Math.abs(this.panX); |
| 508 |
destX = this.size.w - destWidth; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
sourceWidth = Math.max(1, |
| 513 |
Math.floor(sourceWidth * (destWidth / oldDestWidth))); |
| 514 |
|
| 515 |
if(panDir > 0){ |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
sourceX = (sourceX + oldSourceWidth) - (sourceWidth); |
| 520 |
} |
| 521 |
sourceX = Math.floor(sourceX); |
| 522 |
} |
| 523 |
|
| 524 |
try{ |
| 525 |
|
| 526 |
|
| 527 |
cxt.drawImage( |
| 528 |
img, |
| 529 |
Math.max(0, sourceX), |
| 530 |
sourceY, |
| 531 |
Math.min(oldSourceWidth, sourceWidth), |
| 532 |
sourceHeight, |
| 533 |
destX, |
| 534 |
destY, |
| 535 |
Math.min(oldDestWidth, destWidth), |
| 536 |
destHeight |
| 537 |
); |
| 538 |
}catch(e){ |
| 539 |
console.log("Caught Error",e, |
| 540 |
|
| 541 |
"type=", img._type, |
| 542 |
"oldDestWidth = ", oldDestWidth, |
| 543 |
"destWidth", destWidth, |
| 544 |
"destX", destX |
| 545 |
, "oldSourceWidth=",oldSourceWidth, |
| 546 |
"sourceWidth=", sourceWidth, |
| 547 |
"sourceX = " + sourceX |
| 548 |
); |
| 549 |
} |
| 550 |
}, |
| 551 |
|
| 552 |
_setZoomAttr: function(amount){ |
| 553 |
this.zoom = Math.min(this.maxZoom, Math.max(1, amount)); |
| 554 |
|
| 555 |
if(this.zoom == 1 |
| 556 |
&& this._centerImg |
| 557 |
&& this._centerImg._loaded){ |
| 558 |
|
| 559 |
if(!this.isAnimating()){ |
| 560 |
this.zoomCenterX = this._centerImg.width / 2; |
| 561 |
this.zoomCenterY = this._centerImg.height / 2; |
| 562 |
} |
| 563 |
this.panX = this.panY = 0; |
| 564 |
} |
| 565 |
|
| 566 |
this.render(); |
| 567 |
}, |
| 568 |
|
| 569 |
_setZoomCenterXAttr: function(value){ |
| 570 |
if(value != this.zoomCenterX){ |
| 571 |
if(this._centerImg && this._centerImg._loaded){ |
| 572 |
value = Math.min(this._centerImg.width, value); |
| 573 |
} |
| 574 |
this.zoomCenterX = Math.max(0, Math.round(value)); |
| 575 |
} |
| 576 |
}, |
| 577 |
|
| 578 |
_setZoomCenterYAttr: function(value){ |
| 579 |
if(value != this.zoomCenterY){ |
| 580 |
if(this._centerImg && this._centerImg._loaded){ |
| 581 |
value = Math.min(this._centerImg.height, value); |
| 582 |
} |
| 583 |
this.zoomCenterY = Math.max(0, Math.round(value)); |
| 584 |
} |
| 585 |
}, |
| 586 |
|
| 587 |
_setZoomCenterAttr: function(value){ |
| 588 |
if(value.x != this.zoomCenterX || value.y != this.zoomCenterY){ |
| 589 |
this.set("zoomCenterX", value.x); |
| 590 |
this.set("zoomCenterY", value.y); |
| 591 |
this.render(); |
| 592 |
} |
| 593 |
}, |
| 594 |
|
| 595 |
_setAnimatedZoomAttr: function(amount){ |
| 596 |
if(this._anim && this._anim.status() == "playing"){ |
| 597 |
return; |
| 598 |
} |
| 599 |
|
| 600 |
this._anim = new dojo.Animation({ |
| 601 |
curve: [this.zoom, amount], |
| 602 |
onAnimate: this._updateAnimatedZoom, |
| 603 |
onEnd: this._onAnimEnd |
| 604 |
}); |
| 605 |
|
| 606 |
this._anim.play(); |
| 607 |
}, |
| 608 |
|
| 609 |
_updateAnimatedZoom: function(amount){ |
| 610 |
this._setZoomAttr(amount); |
| 611 |
}, |
| 612 |
|
| 613 |
_setCenterUrlAttr: function(urlOrObj){ |
| 614 |
this._setImage("center", urlOrObj); |
| 615 |
}, |
| 616 |
_setLeftUrlAttr: function(urlOrObj){ |
| 617 |
this._setImage("left", urlOrObj); |
| 618 |
}, |
| 619 |
_setRightUrlAttr: function(urlOrObj){ |
| 620 |
this._setImage("right", urlOrObj); |
| 621 |
}, |
| 622 |
|
| 623 |
_setImage: function(name, urlOrObj){ |
| 624 |
var smallUrl = null; |
| 625 |
|
| 626 |
var largeUrl = null; |
| 627 |
|
| 628 |
if(dojo.isString(urlOrObj)){ |
| 629 |
|
| 630 |
largeUrl = urlOrObj; |
| 631 |
}else{ |
| 632 |
largeUrl = urlOrObj.large; |
| 633 |
smallUrl = urlOrObj.small; |
| 634 |
} |
| 635 |
|
| 636 |
if(this["_" + name + "Img"] && this["_" + name + "Img"]._src == largeUrl){ |
| 637 |
|
| 638 |
return; |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
var largeImg = this["_" + name + "Img"] = new Image(); |
| 643 |
largeImg._type = name; |
| 644 |
largeImg._loaded = false; |
| 645 |
largeImg._src = largeUrl; |
| 646 |
largeImg._conn = dojo.connect(largeImg, "onload", this.handleLoad); |
| 647 |
|
| 648 |
if(smallUrl){ |
| 649 |
|
| 650 |
|
| 651 |
var smallImg = this["_" + name + "SmallImg"] = new Image(); |
| 652 |
smallImg._type = name; |
| 653 |
smallImg._loaded = false; |
| 654 |
smallImg._conn = dojo.connect(smallImg, "onload", this.handleLoad); |
| 655 |
smallImg._isSmall = true; |
| 656 |
smallImg._src = smallUrl; |
| 657 |
smallImg.src = smallUrl; |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
largeImg.src = largeUrl; |
| 663 |
}, |
| 664 |
|
| 665 |
handleLoad: function(evt){ |
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
var img = evt.target; |
| 671 |
img._loaded = true; |
| 672 |
|
| 673 |
dojo.disconnect(img._conn); |
| 674 |
|
| 675 |
var type = img._type; |
| 676 |
|
| 677 |
switch(type){ |
| 678 |
case "center": |
| 679 |
this.zoomCenterX = img.width / 2; |
| 680 |
this.zoomCenterY = img.height / 2; |
| 681 |
break; |
| 682 |
} |
| 683 |
|
| 684 |
var height = img.height; |
| 685 |
var width = img.width; |
| 686 |
|
| 687 |
if(width / this.size.w < height / this.size.h){ |
| 688 |
|
| 689 |
img._baseHeight = this.canvas.height; |
| 690 |
img._baseWidth = width / (height / this.size.h); |
| 691 |
}else{ |
| 692 |
|
| 693 |
img._baseWidth = this.canvas.width; |
| 694 |
img._baseHeight = height / (width / this.size.w); |
| 695 |
} |
| 696 |
img._centerX = width / 2; |
| 697 |
img._centerY = height / 2; |
| 698 |
|
| 699 |
this.render(); |
| 700 |
|
| 701 |
this.onLoad(img._type, img._src, img._isSmall); |
| 702 |
}, |
| 703 |
|
| 704 |
onLoad: function(type, url, isSmall){ |
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
} |
| 716 |
}); |