mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
crash fix for notifications, removed exec_body_script, closes #1058
This commit is contained in:
@@ -97,7 +97,7 @@ var ajaxify = {};
|
|||||||
|
|
||||||
templates.flush();
|
templates.flush();
|
||||||
templates.load_template(function () {
|
templates.load_template(function () {
|
||||||
exec_body_scripts(content);
|
|
||||||
require(['forum/' + tpl_url], function(script) {
|
require(['forum/' + tpl_url], function(script) {
|
||||||
if (script && script.init) {
|
if (script && script.init) {
|
||||||
script.init();
|
script.init();
|
||||||
@@ -172,56 +172,4 @@ var ajaxify = {};
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function exec_body_scripts(body_el) {
|
|
||||||
// modified from http://stackoverflow.com/questions/2592092/executing-script-elements-inserted-with-innerhtml
|
|
||||||
|
|
||||||
function nodeName(elem, name) {
|
|
||||||
return elem.nodeName && elem.nodeName.toUpperCase() === name.toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
function evalScript(elem) {
|
|
||||||
var data = (elem.text || elem.textContent || elem.innerHTML || ""),
|
|
||||||
head = document.getElementsByTagName("head")[0] ||
|
|
||||||
document.documentElement,
|
|
||||||
script = document.createElement("script");
|
|
||||||
|
|
||||||
script.type = "text/javascript";
|
|
||||||
try {
|
|
||||||
script.appendChild(document.createTextNode(data));
|
|
||||||
} catch (e) {
|
|
||||||
script.text = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (elem.src) {
|
|
||||||
script.src = elem.src;
|
|
||||||
}
|
|
||||||
|
|
||||||
head.insertBefore(script, head.firstChild);
|
|
||||||
//TODO: remove from head before inserting?, doing this breaks scripts in safari so commented out for now
|
|
||||||
//head.removeChild(script);
|
|
||||||
}
|
|
||||||
|
|
||||||
var scripts = [],
|
|
||||||
script,
|
|
||||||
children_nodes = $(body_el).find('script'),
|
|
||||||
child,
|
|
||||||
i;
|
|
||||||
|
|
||||||
for (i = 0; children_nodes[i]; i++) {
|
|
||||||
child = children_nodes[i];
|
|
||||||
if (nodeName(child, "script") &&
|
|
||||||
(!child.type || child.type.toLowerCase() === "text/javascript")) {
|
|
||||||
scripts.push(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; scripts[i]; i++) {
|
|
||||||
script = scripts[i];
|
|
||||||
if (script.parentNode) {
|
|
||||||
script.parentNode.removeChild(script);
|
|
||||||
}
|
|
||||||
evalScript(scripts[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}(jQuery));
|
}(jQuery));
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ var async = require('async'),
|
|||||||
if (nids && nids.length > 0) {
|
if (nids && nids.length > 0) {
|
||||||
async.each(nids, function(nid, next) {
|
async.each(nids, function(nid, next) {
|
||||||
Notifications.get(nid, uid, function(nid_info) {
|
Notifications.get(nid, uid, function(nid_info) {
|
||||||
if (nid_info.uniqueId === uniqueId) {
|
if (nid_info && nid_info.uniqueId === uniqueId) {
|
||||||
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nid);
|
db.sortedSetRemove('uid:' + uid + ':notifications:unread', nid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user