Skip to content

Commit

Permalink
Use wtLayout instead of jQuery.data
Browse files Browse the repository at this point in the history
jQuery.data (jQuery 1.x) prevents leaks *only* when also using jQuery's
own remove(), html(), etc. functions.

jQuery.data (jQuery 1.x) actually *causes* leaks on modern browsers,
when jQuery's methods are not used, like when calling Node.removeChild()
directly.

Circular references between DOM elements and JS objects are not an issue
with more recent browsers.

(Alternative could be to use ECMAScript 6 WeakMap, which is not
supported by IE)
  • Loading branch information
RockinRoel committed Mar 19, 2019
1 parent 919b736 commit 3b7a736
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
12 changes: 6 additions & 6 deletions src/js/StdGridLayoutImpl2.js
Expand Up @@ -109,7 +109,7 @@ WT_DECLARE_WT_MEMBER
resizeHandles: []
}];

jQuery.data(document.getElementById(id), 'layout', this);
document.getElementById(id).wtLayout = this;

function getItem(id) {
var i, il;
Expand Down Expand Up @@ -781,7 +781,7 @@ WT_DECLARE_WT_MEMBER
var piw = WT.$(parentItemWidget.id);
if (piw) {
if (parentItemWidget != piw) {
parent = jQuery.data(piw.parentNode, 'layout');
parent = piw.parentNode.wtLayout;
if (!parent) {
/* The parent item widget is no longer in the DOM. Need a test
* case for that. */
Expand Down Expand Up @@ -1592,7 +1592,7 @@ WT_DECLARE_WT_MEMBER
parentWithWtPS = false;

if (!topLevel) {
parent = jQuery.data(document.getElementById(parentId), 'layout');
parent = document.getElementById(parentId).wtLayout;
parentItemWidget = widget;
parentMargin[HORIZONTAL] = boxMargin(parentItemWidget, HORIZONTAL);
parentMargin[VERTICAL] = boxMargin(parentItemWidget, VERTICAL);
Expand All @@ -1615,7 +1615,7 @@ WT_DECLARE_WT_MEMBER
if (p.wtGetPS)
parentWithWtPS = true;

var l = jQuery.data(p.parentNode, 'layout');
var l = p.parentNode.wtLayout;
if (l) {
parentItemWidget = p;
parent = l;
Expand Down Expand Up @@ -1698,7 +1698,7 @@ WT_DECLARE_APP_MEMBER

this.find = function(id) {
var el = document.getElementById(id);
return el ? jQuery.data(el, 'layout') : null;
return el ? el.wtLayout : null;
};

this.setDirty = function(id) {
Expand All @@ -1717,7 +1717,7 @@ WT_DECLARE_APP_MEMBER
var item = el;
el = el.parentNode;
while (el && el != document.body) {
var layout = jQuery.data(el, 'layout');
var layout = el.wtLayout;
if (layout)
layout.setElDirty(item);
item = el;
Expand Down
22 changes: 11 additions & 11 deletions src/js/StdGridLayoutImpl2.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/js/WDialog.js
Expand Up @@ -106,7 +106,7 @@ WT_DECLARE_WT_MEMBER
if (pctMaxWidth !== 0) {
var ws = WT.windowSize();

var layout = jQuery.data(layoutContainer.firstChild, 'layout');
var layout = layoutContainer.firstChild.wtLayout;
if (layout && layout.setMaxSize) {
layout.setMaxSize(ws.x * pctMaxWidth / 100,
ws.y * pctMaxHeight / 100);
Expand Down Expand Up @@ -263,7 +263,7 @@ WT_DECLARE_WT_MEMBER
resizeBusy = !done;
wtResize(el, w, h, true);

var layout = jQuery.data(layoutContainer.firstChild, 'layout');
var layout = layoutContainer.firstChild.wtLayout;
if (layout && layout.setMaxSize)
layout.setMaxSize(0, 0);

Expand Down
6 changes: 3 additions & 3 deletions src/js/WDialog.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b7a736

Please sign in to comment.