Skip to content

Commit a63a0dd

Browse files
DVF-3265 fix IE 6-8 issues
1 parent 17ca5d3 commit a63a0dd

File tree

11 files changed

+52
-42
lines changed

11 files changed

+52
-42
lines changed

src/acgraph.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -536,21 +536,21 @@ acgraph.updateReferences = function() {
536536
if (!wrapperStage) continue;
537537

538538
// clip-path
539-
if (wrapper instanceof acgraph.vector.Element) {
539+
if (acgraph.utils.instanceOf(wrapper, acgraph.vector.Element)) {
540540
if (wrapperStage.isSuspended()) {
541541
wrapper.setDirtyState(acgraph.vector.Element.DirtyState.CLIP);
542542
} else if (!wrapper.hasDirtyState(acgraph.vector.Element.DirtyState.CLIP)) {
543-
renderer.setClip(wrapper);
543+
renderer.setClip(/** @type {!acgraph.vector.Element} */(wrapper));
544544
}
545545
}
546546

547547
// fill, stroke
548-
if (wrapper instanceof acgraph.vector.Shape) {
548+
if (acgraph.utils.instanceOf(wrapper, acgraph.vector.Shape)) {
549549
if (wrapperStage.isSuspended()) {
550550
wrapper.setDirtyState(acgraph.vector.Element.DirtyState.FILL | acgraph.vector.Element.DirtyState.STROKE);
551551
} else {
552-
if (!wrapper.hasDirtyState(acgraph.vector.Element.DirtyState.FILL)) renderer.applyFill(wrapper);
553-
if (!wrapper.hasDirtyState(acgraph.vector.Element.DirtyState.STROKE)) renderer.applyStroke(wrapper);
552+
if (!wrapper.hasDirtyState(acgraph.vector.Element.DirtyState.FILL)) renderer.applyFill(/** @type {!acgraph.vector.Shape} */(wrapper));
553+
if (!wrapper.hasDirtyState(acgraph.vector.Element.DirtyState.STROKE)) renderer.applyStroke(/** @type {!acgraph.vector.Shape} */(wrapper));
554554
}
555555
}
556556
}

src/utils/utils.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,13 @@ acgraph.utils.partialApplyingArgsToFunction = function(func, args, opt_obj) {
6767
};
6868

6969

70+
/**
71+
* Safe instanceof.
72+
* @param {*} object
73+
* @param {*} constructor
74+
* @return {boolean}
75+
*/
76+
acgraph.utils.instanceOf = function(object, constructor) {
77+
//Needs check object is defined for old IE lower 8.
78+
return !!object && object instanceof /** @type {Object} */(constructor);
79+
};

src/vector/Clip.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,27 @@ acgraph.vector.Clip.prototype.stage = function(opt_value) {
8989
*/
9090
acgraph.vector.Clip.prototype.shape = function(opt_leftOrShape, opt_top, opt_width, opt_height) {
9191
if (arguments.length) {
92-
if (opt_leftOrShape instanceof acgraph.vector.Shape) {
92+
if (acgraph.utils.instanceOf(opt_leftOrShape, acgraph.vector.Shape)) {
9393
if (this.shape_) {
94-
var sameType = this.shape_ instanceof acgraph.vector.Rect && opt_leftOrShape instanceof acgraph.vector.Rect ||
95-
this.shape_ instanceof acgraph.vector.Circle && opt_leftOrShape instanceof acgraph.vector.Circle ||
96-
this.shape_ instanceof acgraph.vector.Ellipse && opt_leftOrShape instanceof acgraph.vector.Ellipse ||
97-
this.shape_ instanceof acgraph.vector.Path && opt_leftOrShape instanceof acgraph.vector.Path;
94+
var sameType = acgraph.utils.instanceOf(this.shape_, acgraph.vector.Rect) && acgraph.utils.instanceOf(opt_leftOrShape, acgraph.vector.Rect) ||
95+
acgraph.utils.instanceOf(this.shape_, acgraph.vector.Circle) && acgraph.utils.instanceOf(opt_leftOrShape, acgraph.vector.Circle) ||
96+
acgraph.utils.instanceOf(this.shape_, acgraph.vector.Ellipse) && acgraph.utils.instanceOf(opt_leftOrShape, acgraph.vector.Ellipse) ||
97+
acgraph.utils.instanceOf(this.shape_, acgraph.vector.Path) && acgraph.utils.instanceOf(opt_leftOrShape, acgraph.vector.Path);
9898

9999
if (sameType) {
100100
this.shape_.deserialize(opt_leftOrShape.serialize());
101101
} else {
102102
this.shape_.parent(null);
103-
this.shape_ = opt_leftOrShape;
103+
this.shape_ = /** @type {acgraph.vector.Shape} */(opt_leftOrShape);
104104
this.shape_.parent(this);
105105
}
106106
} else {
107-
this.shape_ = opt_leftOrShape;
107+
this.shape_ = /** @type {acgraph.vector.Shape} */(opt_leftOrShape);
108108
this.shape_.parent(this);
109109
}
110110
} else {
111111
var left, top, width, height;
112-
if (opt_leftOrShape instanceof goog.math.Rect) {
112+
if (acgraph.utils.instanceOf(opt_leftOrShape, goog.math.Rect)) {
113113
left = opt_leftOrShape.left;
114114
top = opt_leftOrShape.top;
115115
width = opt_leftOrShape.width;
@@ -131,7 +131,7 @@ acgraph.vector.Clip.prototype.shape = function(opt_leftOrShape, opt_top, opt_wid
131131
height = goog.isDefAndNotNull(opt_height) ? opt_height : 0;
132132
}
133133
if (this.shape_) {
134-
if (this.shape_ instanceof acgraph.vector.Rect) {
134+
if (acgraph.utils.instanceOf(this.shape_, acgraph.vector.Rect)) {
135135
this.shape_.setX(left).setY(top).setWidth(width).setHeight(height);
136136
} else {
137137
this.shape_.parent(null);

src/vector/Element.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,8 +1475,8 @@ acgraph.vector.Element.prototype.clip = function(opt_value) {
14751475
if ((!this.clipElement_ && !clipShape) || (this.clipElement_ && this.clipElement_ === clipShape))
14761476
return this;
14771477

1478-
if (clipShape && !(clipShape instanceof acgraph.vector.Clip)) {
1479-
if (clipShape instanceof acgraph.vector.Shape && clipShape.hasParent() && clipShape.parent() instanceof acgraph.vector.Clip) {
1478+
if (clipShape && !(acgraph.utils.instanceOf(clipShape, acgraph.vector.Clip))) {
1479+
if (acgraph.utils.instanceOf(clipShape, acgraph.vector.Shape) && clipShape.hasParent() && acgraph.utils.instanceOf(clipShape.parent(), acgraph.vector.Clip)) {
14801480
if (this.clipElement_ && !this.clipElement_.isDisposed())
14811481
this.clipElement_.removeElement(this);
14821482

@@ -1491,7 +1491,7 @@ acgraph.vector.Element.prototype.clip = function(opt_value) {
14911491
}
14921492
}
14931493
} else {
1494-
this.clipElement_ = clipShape || null;
1494+
this.clipElement_ = (/** @type {acgraph.vector.Clip} */(clipShape)) || null;
14951495
}
14961496

14971497
this.clipChanged();
@@ -1678,7 +1678,7 @@ acgraph.vector.Element.prototype.drag = function(opt_value) {
16781678
if (goog.isDefAndNotNull(opt_value)) {
16791679
this.draggable_ = opt_value;
16801680
if (opt_value && !this.hasDirtyState(acgraph.vector.Element.DirtyState.DOM_MISSING)) {
1681-
var isLimited = opt_value instanceof goog.math.Rect;
1681+
var isLimited = acgraph.utils.instanceOf(opt_value, goog.math.Rect);
16821682
var limit = isLimited ? this.draggable_ : null;
16831683
if (!this.dragger_)
16841684
this.dragger_ = new acgraph.events.Dragger(this);

src/vector/LinearGradient.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ acgraph.vector.LinearGradient = function(keys, opt_opacity, opt_angle, opt_mode,
7070
* Gradient bounds. If set - gradient is in userSpaceOnUse mode (see opt_bounds description).
7171
* @type {goog.math.Rect}
7272
*/
73-
this.bounds = (opt_mode && (opt_mode instanceof goog.math.Rect)) ?
73+
this.bounds = (opt_mode && (acgraph.utils.instanceOf(opt_mode, goog.math.Rect))) ?
7474
/** @type {goog.math.Rect} */(opt_mode) : null;
7575
/**
7676
* Gradient transform.
@@ -109,8 +109,8 @@ acgraph.vector.LinearGradient.serialize = function(keys, opt_opacity, opt_angle,
109109
var saveAngle = !!opt_mode;
110110
/** @type {goog.math.Rect}*/
111111
var bounds = goog.isDefAndNotNull(opt_mode) ?
112-
opt_mode instanceof goog.math.Rect ?
113-
opt_mode :
112+
acgraph.utils.instanceOf(opt_mode, goog.math.Rect) ?
113+
/** @type {goog.math.Rect} */(opt_mode) :
114114
null :
115115
null;
116116

src/vector/Shape.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ acgraph.vector.Shape.prototype.serialize = function() {
218218

219219
if (this.fill_) {
220220
var fillData, tmpFill, tmpStroke;
221-
if (this.fill_ instanceof acgraph.vector.HatchFill) {
221+
if (acgraph.utils.instanceOf(this.fill_, acgraph.vector.HatchFill)) {
222222
fillData = {
223223
'type': 'hatchFill',
224224
'hatchType': this.fill_.type,
225225
'color': this.fill_.color,
226226
'thickness': this.fill_.thickness,
227227
'size': this.fill_.size
228228
};
229-
} else if (this.fill_ instanceof acgraph.vector.PatternFill) {
229+
} else if (acgraph.utils.instanceOf(this.fill_, acgraph.vector.PatternFill)) {
230230
fillData = this.fill_.serialize();
231231
} else if (goog.isObject(this.fill_) && ('keys' in this.fill_)) {
232232
if (('cx' in this.fill_) && ('cy' in this.fill_)) {

src/vector/Stage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2523,13 +2523,13 @@ acgraph.vector.Stage.prototype.removeAllListeners = function(opt_type) {
25232523
*/
25242524
acgraph.vector.Stage.prototype.handleMouseEvent_ = function(e) {
25252525
var event = new acgraph.events.BrowserEvent(e, this);
2526-
if (event['target'] instanceof acgraph.vector.Element) {
2526+
if (acgraph.utils.instanceOf(event['target'], acgraph.vector.Element)) {
25272527
var el = /** @type {acgraph.vector.Element} */(event['target']);
25282528
el.dispatchEvent(event);
25292529
var type = event['type'];
25302530
if (event.defaultPrevented) e.preventDefault();
25312531
// we do the binding and unbinding of event only if relatedTarget doesn't belong to the same stage
2532-
if (!(event['relatedTarget'] instanceof acgraph.vector.Element) ||
2532+
if (!(acgraph.utils.instanceOf(event['relatedTarget'], acgraph.vector.Element)) ||
25332533
(/** @type {acgraph.vector.Element} */(event['relatedTarget'])).getStage() != this) {
25342534
if (type == acgraph.events.EventType.MOUSEOVER) {
25352535
this.eventHandler_.listen(goog.dom.getDocument(), acgraph.events.EventType.MOUSEMOVE, this.handleMouseEvent_, false);

src/vector/svg/Renderer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,13 +1044,13 @@ acgraph.vector.svg.Renderer.prototype.applyFill = function(element) {
10441044
this.setAttribute_(element.domElement(), 'fill', pathPrefix + imageFill.id() + ')');
10451045
this.setAttribute_(element.domElement(), 'fill-opacity', goog.isDef(fill['opacity']) ? fill['opacity'] : 1);
10461046
}
1047-
} else if (fill instanceof acgraph.vector.HatchFill) {
1047+
} else if (acgraph.utils.instanceOf(fill, acgraph.vector.HatchFill)) {
10481048
var hatch = /** @type {acgraph.vector.HatchFill} */(fill);
10491049
hatch = defs.getHatchFill(hatch.type, hatch.color, hatch.thickness, hatch.size);
10501050
hatch.id(); // if the identifier of the fill is still empty, it will be generated
10511051
hatch.parent(element.getStage()).render();
10521052
this.setAttribute_(element.domElement(), 'fill', pathPrefix + hatch.id() + ')');
1053-
} else if (fill instanceof acgraph.vector.PatternFill) {
1053+
} else if (acgraph.utils.instanceOf(fill, acgraph.vector.PatternFill)) {
10541054
/** @type {acgraph.vector.PatternFill} */
10551055
var pattern = /** @type {acgraph.vector.PatternFill} */(fill);
10561056
pattern.id(); // if the identifier of the fill is still empty, it will be generated
@@ -1445,7 +1445,7 @@ acgraph.vector.svg.Renderer.prototype.setClip = function(element) {
14451445
var clipelement = /** @type {acgraph.vector.Clip} */ (element.clip());
14461446
if (clipelement) {
14471447
var clipId;
1448-
if (clipelement instanceof acgraph.vector.Clip)
1448+
if (acgraph.utils.instanceOf(clipelement, acgraph.vector.Clip))
14491449
clipId = /** @type {string} */ (clipelement.id());
14501450
if (!clipId)
14511451
clipId = this.createClip_(element, clipelement);

src/vector/vector.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ acgraph.vector.normalizeFill = function(opt_fillOrColorOrKeys, opt_opacityOrAngl
668668
};
669669
}
670670
} else if (goog.isObject(opt_fillOrColorOrKeys)) { // fill as an object
671-
if (opt_fillOrColorOrKeys instanceof acgraph.vector.PatternFill) {
671+
if (acgraph.utils.instanceOf(opt_fillOrColorOrKeys, acgraph.vector.PatternFill)) {
672672
newFill = opt_fillOrColorOrKeys;
673673
} else if (opt_fillOrColorOrKeys['type'] == 'pattern') {
674674
delete opt_fillOrColorOrKeys['id'];
@@ -753,7 +753,7 @@ acgraph.vector.normalizeFill = function(opt_fillOrColorOrKeys, opt_opacityOrAngl
753753
}
754754
var transform = opt_fillOrColorOrKeys['transform'];
755755
if (goog.isDefAndNotNull(transform)) {
756-
if (transform instanceof goog.math.AffineTransform) {
756+
if (acgraph.utils.instanceOf(transform, goog.math.AffineTransform)) {
757757
newFill['transform'] = transform;
758758
} else if (goog.isObject(transform)) {
759759
newFill['transform'] = new goog.math.AffineTransform();
@@ -839,7 +839,7 @@ acgraph.vector.normalizeStroke = function(opt_strokeOrFill, opt_thickness, opt_d
839839
// No pattern fill for stroke, unfortunately :D
840840
// Double typecast should be here, via ColoredFill,
841841
// but that's too much metadata, so let's go with this.
842-
newStroke = (tmp instanceof acgraph.vector.PatternFill) ? 'black' : /** @type {acgraph.vector.Stroke} */(tmp);
842+
newStroke = (acgraph.utils.instanceOf(tmp, acgraph.vector.PatternFill)) ? 'black' : /** @type {acgraph.vector.Stroke} */(tmp);
843843

844844
// If nothing else we can use normalized fill as a stroke,
845845
// ot is compatible. Otherwise we need to add properties.
@@ -891,7 +891,7 @@ acgraph.vector.normalizeHatchFill = function(opt_patternFillOrType, opt_color, o
891891
opt_color,
892892
goog.isDef(opt_thickness) ? parseFloat(opt_thickness) : undefined,
893893
goog.isDef(opt_size) ? parseFloat(opt_size) : undefined);
894-
} else if (opt_patternFillOrType instanceof acgraph.vector.PatternFill) {
894+
} else if (acgraph.utils.instanceOf(opt_patternFillOrType, acgraph.vector.PatternFill)) {
895895
newFill = opt_patternFillOrType;
896896
} else if (goog.isObject(opt_patternFillOrType)) {
897897
if (opt_patternFillOrType['type'] == 'pattern') {
@@ -909,7 +909,7 @@ acgraph.vector.normalizeHatchFill = function(opt_patternFillOrType, opt_color, o
909909
}
910910
} else
911911
newFill = null;
912-
return newFill;
912+
return /** @type {acgraph.vector.PatternFill|acgraph.vector.HatchFill} */(newFill);
913913
};
914914

915915

@@ -967,8 +967,8 @@ acgraph.vector.normalizePageSize = function(opt_paperSizeOrWidth, opt_landscapeO
967967
*/
968968
acgraph.vector.normalizeGradientMode = function(mode) {
969969
if (goog.isDefAndNotNull(mode)) { // mode is set
970-
if (mode instanceof goog.math.Rect)
971-
return mode;
970+
if (acgraph.utils.instanceOf(mode, goog.math.Rect))
971+
return /** @type {goog.math.Rect} */(mode);
972972
else if (goog.isObject(mode) && !isNaN(mode['left']) && !isNaN(mode['top']) && !isNaN(mode['width']) && !isNaN(mode['height']))
973973
return new goog.math.Rect(mode['left'], mode['top'], mode['width'], mode['height']);
974974
}

src/vector/vml/Defs.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ acgraph.vector.vml.Defs.prototype.serializeFill = function(fill) {
7979
var stringParam = '';
8080
if (goog.isString(fill)) {
8181
stringParam += fill + '1';
82-
} else if (fill instanceof acgraph.vector.RadialGradient) {
82+
} else if (acgraph.utils.instanceOf(fill, acgraph.vector.RadialGradient)) {
8383
/** @type {acgraph.vector.vml.RadialGradient} */
8484
var rg = /** @type {acgraph.vector.vml.RadialGradient} */(fill);
8585
stringParam = acgraph.vector.vml.RadialGradient.serialize(rg.keys, rg.cx, rg.cy, rg.size_x, rg.size_y, rg.opacity, rg.bounds);
86-
} else if (fill instanceof acgraph.vector.LinearGradient) {
86+
} else if (acgraph.utils.instanceOf(fill, acgraph.vector.LinearGradient)) {
8787
/** @type {acgraph.vector.LinearGradient} */
8888
var lg = /** @type {acgraph.vector.LinearGradient} */(fill);
8989
stringParam = acgraph.vector.LinearGradient.serialize(lg.keys, lg.opacity, lg.angle, lg.mode);

0 commit comments

Comments
 (0)