Skip to content

fix destroy() memory leak #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 61 additions & 17 deletions src/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,32 +65,76 @@ if (!String.prototype.resolve)
return value;
}
};

var _templateCache = {};
var getTemplate = function(template){
if (!_templateCache.hasOwnProperty(template)){
var str = template.split(/{([^{}]+)}/g);

for (var i = 0; i < str.length; i++){
var s = str[i];
var hasStart = (s.charAt(0) === "}");
var hasEnd = (s.charAt(s.length - 1) === "{");
if (hasStart)
{
s = s.substr(1);
}
if (hasEnd)
{
s = s.substr(0, s.length - 1);
}

if (hasStart || hasEnd)
{
str[i] = s; //plain old html
} else {
str[i] = {
token: str[i],
key: s.split(".")
};
}
}
_templateCache[template] = str;
}
return _templateCache[template];
};

String.prototype.resolve = function (substitutes, prefixes)
{
var result = this;
$.each(substitutes, function (key, value)
{
if (value != null && typeof value !== "function")
{
if (typeof value === "object")
var str = getTemplate(this);
var result = "";
for (var i = 0; i < str.length; i++){
if (typeof str[i] === "object"){
var key = str[i].key;
var v = "";
// now we have a variable to be substitued
if (substitutes.hasOwnProperty(key[0]))
{
var keys = (prefixes) ? $.extend([], prefixes) : [];
keys.push(key);
result = result.resolve(value, keys) + "";
v = substitutes[key[0]];
}
else
{
if (formatter && formatter[key] && typeof formatter[key] === "function")
{
value = formatter[key](value);
continue;
}

for (var k = 1; k < key.length; k++){
if (v.hasOwnProperty(key[k])){
v = v[key[k]];
} else {
v = null;
break;
}
key = (prefixes) ? prefixes.join(".") + "." + key : key;
var pattern = new RegExp("\\{\\{" + key + "\\}\\}", "gm");
result = result.replace(pattern, (value.replace) ? value.replace(/\$/gi, "&#36;") : value);
}
var formatter_key = key[key.length-1];
if (formatter && formatter[formatter_key] && typeof formatter[formatter_key] === "function"){
result += formatter[formatter_key](v);
} else {
result += v;
}
} else {
result += str[i]; // plain old html
}
});
}
return result;
};
}
Expand Down Expand Up @@ -167,4 +211,4 @@ if (!Array.prototype.propValues)
}
return result;
};
}
}
5 changes: 3 additions & 2 deletions src/internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ function renderColumnSelection(actions)
that.element.find("tbody").empty(); // Fixes an column visualization bug
renderTableHeader.call(that);
loadData.call(that);
that.element.trigger("columnToggle" + namespace, column);
}
});
dropDown.find(getCssSelector(css.dropDownMenuItems)).append(item);
Expand Down Expand Up @@ -873,7 +874,7 @@ function replacePlaceHolder(placeholder, element)
placeholder.each(function (index, item)
{
// todo: check how append is implemented. Perhaps cloning here is superfluous.
$(item).before(element.clone(true)).remove();
$(item).before(element).remove();
});
}

Expand Down Expand Up @@ -945,4 +946,4 @@ function sortRows()
this.rows.sort(sort);
}
}
}
}