Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / drawing / stencil / Image.js

History | View | Annotate | Download (2.09 KB)

1 9 andrej.cim
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6
7
8
if(!dojo._hasResource["dojox.drawing.stencil.Image"]){
9
dojo._hasResource["dojox.drawing.stencil.Image"]=true;
10
dojo.provide("dojox.drawing.stencil.Image");
11
dojox.drawing.stencil.Image=dojox.drawing.util.oo.declare(dojox.drawing.stencil._Base,function(_1){
12
},{type:"dojox.drawing.stencil.Image",anchorType:"group",baseRender:true,dataToPoints:function(o){
13
o=o||this.data;
14
this.points=[{x:o.x,y:o.y},{x:o.x+o.width,y:o.y},{x:o.x+o.width,y:o.y+o.height},{x:o.x,y:o.y+o.height}];
15
return this.points;
16
},pointsToData:function(p){
17
p=p||this.points;
18
var s=p[0];
19
var e=p[2];
20
this.data={x:s.x,y:s.y,width:e.x-s.x,height:e.y-s.y,src:this.src||this.data.src};
21
return this.data;
22
},_createHilite:function(){
23
this.remove(this.hit);
24
this.hit=this.container.createRect(this.data).setStroke(this.style.current).setFill(this.style.current.fill);
25
this._setNodeAtts(this.hit);
26
},_create:function(_2,d,_3){
27
this.remove(this[_2]);
28
var s=this.container.getParent();
29
this[_2]=s.createImage(d);
30
this.container.add(this[_2]);
31
this._setNodeAtts(this[_2]);
32
},render:function(_4){
33
if(this.data.width=="auto"||isNaN(this.data.width)){
34
this.getImageSize(true);
35
console.warn("Image size not provided. Acquiring...");
36
return;
37
}
38
this.onBeforeRender(this);
39
this.renderHit&&this._createHilite();
40
this._create("shape",this.data,this.style.current);
41
},getImageSize:function(_5){
42
if(this._gettingSize){
43
return;
44
}
45
this._gettingSize=true;
46
var _6=dojo.create("img",{src:this.data.src},dojo.body());
47
var _7=dojo.connect(_6,"error",this,function(){
48
dojo.disconnect(c);
49
dojo.disconnect(_7);
50
console.error("Error loading image:",this.data.src);
51
console.warn("Error image:",this.data);
52
});
53
var c=dojo.connect(_6,"load",this,function(){
54
var _8=dojo.marginBox(_6);
55
this.setData({x:this.data.x,y:this.data.y,src:this.data.src,width:_8.w,height:_8.h});
56
dojo.disconnect(c);
57
dojo.destroy(_6);
58
_5&&this.render(true);
59
});
60
}});
61
dojox.drawing.register({name:"dojox.drawing.stencil.Image"},"stencil");
62
}