Skip to content

Commit 92e2e32

Browse files
committed
prevent redefine properties
1 parent 1fc7d18 commit 92e2e32

2 files changed

Lines changed: 26 additions & 19 deletions

File tree

js/utils.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,42 @@ export function genId() {
88
}
99

1010
export function addDocumentObjectHelpers() {
11-
Object.defineProperty(Element.prototype, 'documentOffsetTop', {
12-
get: function () {
11+
if (!Element.prototype.hasOwnProperty('documentOffsetTop')) {
12+
Object.defineProperty(Element.prototype, 'documentOffsetTop', {
13+
get: function () {
1314
return this.offsetTop + ( this.offsetParent ? this.offsetParent.documentOffsetTop : 0 );
14-
}
15-
});
16-
17-
Object.defineProperty(Element.prototype, 'documentOffsetLeft', {
15+
}
16+
});
17+
}
18+
if (!Element.prototype.hasOwnProperty('documentOffsetLeft')) {
19+
Object.defineProperty(Element.prototype, 'documentOffsetLeft', {
1820
get: function () {
19-
return this.offsetLeft + ( this.offsetParent ? this.offsetParent.documentOffsetLeft : 0 );
21+
return this.offsetLeft + ( this.offsetParent ? this.offsetParent.documentOffsetLeft : 0 );
2022
}
21-
});
23+
});
24+
}
2225

23-
Object.defineProperty(Element.prototype, 'documentClientWidth', {
26+
if (!Element.prototype.hasOwnProperty('documentClientWidth')) {
27+
Object.defineProperty(Element.prototype, 'documentClientWidth', {
2428
get: function () {
25-
return this.getBoundingClientRect().width;
29+
return this.getBoundingClientRect().width;
2630
}
27-
});
31+
});
32+
}
2833

29-
Object.defineProperty(Element.prototype, 'documentClientHeight', {
34+
if (!Element.prototype.hasOwnProperty('documentClientHeight')) {
35+
Object.defineProperty(Element.prototype, 'documentClientHeight', {
3036
get: function () {
31-
return this.getBoundingClientRect().height;
37+
return this.getBoundingClientRect().height;
3238
}
33-
});
39+
});
40+
}
3441

35-
String.prototype.ptroTrim = function()
36-
{
42+
if (!String.prototype.hasOwnProperty('ptroTrim')) {
43+
String.prototype.ptroTrim = function () {
3744
return String(this).replace(/^\s+|\s+$/g, '');
38-
};
39-
45+
};
46+
}
4047
}
4148

4249
export function clearSelection() {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "painterro",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Embуedded html image editor",
55
"main": "build/painterro.commonjs2.js",
66
"scripts": {

0 commit comments

Comments
 (0)