kindsoft / kindeditor

WYSIWYG HTML editor
http://kindeditor.net/
GNU Lesser General Public License v2.1
1.9k stars 606 forks source link

[PATCH included]: this.div.css("top", b) where b is non-integer is invalid - kindeditor sometimes does that #177

Open arekm opened 9 years ago

arekm commented 9 years ago

In kindeditor-min.js there is code:

            pos: function(a, b, c) {
                c = l(c, !0);
                if (a !== null && (a = a < 0 ? 0 : s(a), this.div.css("left", a), c)) this.x = a;
                if (b !== null && (b = b < 0 ? 0 : s(b), this.div.css("top", b), c)) this.y = b;
                return this
            },

sometimes "b" in "this.div.css("top", b)" ends up being non integer (for example I had values like 12.799999999...5).

If browser (google chrome) gets non-integer there it simply ignores it and "top" stays at 0px (looks like browsers do not like putting floats into attributes like top - it basically ignores it)

That float value is feed from autoPos: function

[...]
                x = R(e.x + (h.clientWidth - c) / 2),
                y = R(e.y + (h.clientHeight - d) / 2);
                o && A < 7 || P || (x -= e.x, y -= e.y);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - this causes the problem
                return this.pos(x, y)

so for example we have:

            y = R(e.y + (h.clientHeight - d) / 2);
            o && A < 7 || P || (x -= e.x, y -= e.y);

o == false, A == 537, P == false, e.x == 0, e.y == 955.2 return this.pos(x, y) y - gets values like 12.799999999...5

Seems that someone tried to avoid such problem by using R() (which is round()) earlier but forgot to do the same for quirk case.

The fix could be:

diff --git a/kindeditor.js b/kindeditor.js
index 2ea9152..c1a5da4 100644
--- a/kindeditor.js
+++ b/kindeditor.js
@@ -3426,8 +3426,8 @@ _extend(KWidget, {
                        y = _round(scrollPos.y + (docEl.clientHeight - h) / 2);
                }
                if (!(_IE && _V < 7 || _QUIRKS)) {
-                       x -= scrollPos.x;
-                       y -= scrollPos.y;
+                       x -= _round(scrollPos.x);
+                       y -= _round(scrollPos.y);
                }
                return self.pos(x, y);
        },

I got hit by this issue on forum.banggood.com (which uses kindeditor) when using google chrome with 125% zoom level set. 100% level is fine since it never causes non-integer scrollPos.Y.

arekm commented 9 years ago

And google chrome team information about this: http://blog.chromium.org/2014/10/chrome-39-beta-js-generators-animation.html

Other updates in this release
[...]
Scroll offsets (scrollTop, scrollLeft) now return high-precision fractional values in preparation for high-DPI support

and I guess that applies to scrollX and scrollY, too.