silverstripe-framework/admin/client/dist/js/leaktools.js

67 lines
1.8 KiB
JavaScript
Raw Normal View History

(function (global, factory) {
2016-07-13 04:43:07 +02:00
if (typeof define === "function" && define.amd) {
define('ss.leaktools', ['jQuery'], factory);
} else if (typeof exports !== "undefined") {
factory(require('jQuery'));
} else {
var mod = {
exports: {}
};
factory(global.jQuery);
global.ssLeaktools = mod.exports;
}
})(this, function (_jQuery) {
2016-07-13 04:43:07 +02:00
'use strict';
2016-07-13 04:43:07 +02:00
var _jQuery2 = _interopRequireDefault(_jQuery);
2016-07-13 04:43:07 +02:00
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
2016-07-13 04:43:07 +02:00
var getHTML = function getHTML(el) {
var clone = el.cloneNode(true);
2016-07-13 04:43:07 +02:00
var div = (0, _jQuery2.default)('<div></div>');
div.append(clone);
2016-07-13 04:43:07 +02:00
return div.html();
};
2016-07-13 04:43:07 +02:00
_jQuery2.default.leaktools = {
2016-07-13 04:43:07 +02:00
logDuplicateElements: function logDuplicateElements() {
var els = (0, _jQuery2.default)('*');
var dirty = false;
2016-07-13 04:43:07 +02:00
els.each(function (i, a) {
els.not(a).each(function (j, b) {
if (getHTML(a) == getHTML(b)) {
dirty = true;
console.log(a, b);
}
});
});
2016-07-13 04:43:07 +02:00
if (!dirty) console.log('No duplicates found');
},
2016-07-13 04:43:07 +02:00
logUncleanedElements: function logUncleanedElements(clean) {
_jQuery2.default.each(_jQuery2.default.cache, function () {
var source = this.handle && this.handle.elem;
if (!source) return;
2016-07-13 04:43:07 +02:00
var parent = source;
while (parent && parent.nodeType == 1) {
parent = parent.parentNode;
}if (!parent) {
console.log('Unattached', source);
console.log(this.events);
if (clean) (0, _jQuery2.default)(source).unbind().remove();
} else if (parent !== document) console.log('Attached, but to', parent, 'not our document', source);
});
}
};
});