feat(torrents): new directive for torrent overview picture reorganize

This commit is contained in:
OldHawk
2018-01-17 18:39:56 +08:00
parent aee57a00e3
commit 492ae70bc2
2 changed files with 31 additions and 9 deletions

View File

@@ -9,7 +9,6 @@
function torrentImageList($sce, $parse, $compile, $timeout) {
var directive = {
restrict: 'A',
replace: true,
priority: 10,
link: link
};
@@ -18,15 +17,36 @@
function link(scope, element, attrs) {
scope.$watch(attrs.torrentImageList, function (til) {
if (til) {
console.log(element[0]);
hideImage();
var targetNode = document.getElementById(attrs.torrentImageList);
var config = {childList: true};
var callback = function (mutationsList) {
for (var mutation of mutationsList) {
if (mutation.type === 'childList') {
hideImage();
}
}
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, config);
//observer.disconnect();
function hideImage() {
var imgs = element[0].querySelectorAll('img:not(.emoji)');
console.log(imgs);
angular.forEach(imgs, function (i) {
if (i.previousSibling && i.previousSibling.tagName.toUpperCase() === 'BR') {
i.previousSibling.remove();
}
if (i.parentElement.childElementCount === 1) {
angular.element(i.parentElement).css('display', 'none');
angular.element(i.parentElement).remove();
} else {
angular.element(i).css('display', 'none');
angular.element(i).remove();
}
});
}