correctly destroy element when route is being changed

This commit is contained in:
Bernhard Posselt 2014-09-18 10:14:46 +02:00
Родитель 66abbda557
Коммит 4fe70c8f1b
5 изменённых файлов: 31 добавлений и 19 удалений

Просмотреть файл

@ -13,6 +13,7 @@ owncloud-news (3.001)
* **Bugfix**: Import feeds from a very large OPML file in chunks to prevent server slowdown
* **Bugfix**: Folder names are not uppercased anymore due to possible naming conflicts caused by folders being created through the API
* **Bugfix**: Loading icon is now displayed until all feeds and folders are loaded
* **Enhancement**: Correctly float heise.de info box
* **Enhancement**: Allow to turn off marking read when scrolling
* **Enhancement**: Allow to order by oldest first
* **Enhancement**: Add clientside routing

Просмотреть файл

@ -36,7 +36,7 @@ class XPathArticleEnhancer implements ArticleEnhancer {
* @internal param \OCA\News\ArticleEnhancer\a $SimplePieFileFactory factory for getting a simple pie file instance
* @internal param int $maximumTimeout maximum timeout in seconds, defaults to 10 sec
*/
public function __construct(SimplePieAPIFactory $fileFactory,
public function __construct(SimplePieAPIFactory $fileFactory,
array $regexXPathPair, Config $config){
$this->regexXPathPair = $regexXPathPair;
$this->fileFactory = $fileFactory;
@ -54,7 +54,7 @@ class XPathArticleEnhancer implements ArticleEnhancer {
if(preg_match($regex, $item->getUrl())) {
$file = $this->getFile($item->getUrl());
// convert encoding by detecting charset from header
/** @noinspection PhpUndefinedFieldInspection */
$contentType = $file->headers['content-type'];
@ -72,11 +72,11 @@ class XPathArticleEnhancer implements ArticleEnhancer {
$xpath = new \DOMXpath($dom);
$xpathResult = $xpath->evaluate($search);
// in case it wasnt a text query assume its a single
// in case it wasnt a text query assume its a single
if(!is_string($xpathResult)) {
$xpathResult = $this->domToString($xpathResult);
}
// convert all relative to absolute URLs
$xpathResult = $this->substituteRelativeLinks($xpathResult, $item->getUrl());
@ -93,8 +93,8 @@ class XPathArticleEnhancer implements ArticleEnhancer {
private function getFile($url) {
if(trim($this->config->getProxyHost()) === '') {
return $this->fileFactory->getFile(
$url,
$this->maximumTimeout,
$url,
$this->maximumTimeout,
5,
null,
"Mozilla/5.0 AppleWebKit",
@ -105,8 +105,8 @@ class XPathArticleEnhancer implements ArticleEnhancer {
);
} else {
return $this->fileFactory->getFile(
$url,
$this->maximumTimeout,
$url,
$this->maximumTimeout,
5,
null,
"Mozilla/5.0 AppleWebKit",
@ -135,19 +135,20 @@ class XPathArticleEnhancer implements ArticleEnhancer {
return $xmlString;
}
// remove <!DOCTYPE
$dom->removeChild($dom->firstChild);
// remove <html></html>
// remove <!DOCTYPE
$dom->removeChild($dom->firstChild);
// remove <html></html>
$dom->replaceChild($dom->firstChild->firstChild, $dom->firstChild);
$substitution = ["href", "src"];
foreach ($substitution as $attribute) {
$xpath = new \DOMXpath($dom);
$xpathResult = $xpath->query(
"//*[@" . $attribute . " " .
"and not(contains(@" . $attribute . ", '://')) " .
"and not(starts-with(@" . $attribute . ", 'mailto:'))]");
"and not(contains(@" . $attribute . ", '://')) " .
"and not(starts-with(@" . $attribute . ", 'mailto:')) " .
"and not(starts-with(@" . $attribute . ", '//'))]");
foreach ($xpathResult as $linkNode) {
$urlElement = $linkNode->attributes->getNamedItem($attribute);
$abs = $this->relativeToAbsoluteUrl( $urlElement->nodeValue, $absoluteUrl );

Просмотреть файл

@ -2211,19 +2211,24 @@ app.directive('newsTimeout', ["$timeout", "$rootScope", function ($timeout, $roo
'newsTimeout': '&'
},
link: function (scope, element) {
var destroyed = false;
var seconds = 7;
var timer = $timeout(scope.newsTimeout, seconds * 1000);
// remove timeout if element is being removed by
// for instance clicking on the x button
scope.$on('$destroy', function () {
element.on('$destroy', function () {
$timeout.cancel(timer);
});
// also delete the entry if undo is ignored and the url
// is changed
$rootScope.$on('$locationChangeStart', function () {
element.remove();
if (!destroyed) {
destroyed = true;
element.remove();
scope.newsTimeout();
}
});
}
};

2
js/build/app.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -16,19 +16,24 @@ app.directive('newsTimeout', function ($timeout, $rootScope) {
'newsTimeout': '&'
},
link: function (scope, element) {
var destroyed = false;
var seconds = 7;
var timer = $timeout(scope.newsTimeout, seconds * 1000);
// remove timeout if element is being removed by
// for instance clicking on the x button
scope.$on('$destroy', function () {
element.on('$destroy', function () {
$timeout.cancel(timer);
});
// also delete the entry if undo is ignored and the url
// is changed
$rootScope.$on('$locationChangeStart', function () {
element.remove();
if (!destroyed) {
destroyed = true;
element.remove();
scope.newsTimeout();
}
});
}
};