mirror of
https://github.com/Mabbs/mabbs.github.io
synced 2025-08-09 02:12:03 +00:00
Update file rss-feed-preview.js
This commit is contained in:
parent
5300870620
commit
be9602047b
@ -66,17 +66,17 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkFeed(url, callback) {
|
function checkFeed(url, onSuccess, onError) {
|
||||||
$.ajax({
|
return $.ajax({
|
||||||
url: CORS_PROXY + url,
|
url: CORS_PROXY + url,
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
dataType: 'text',
|
dataType: 'text',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
var items = parseRSS(data);
|
var items = parseRSS(data);
|
||||||
callback(items);
|
onSuccess(items);
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function () {
|
||||||
callback(null);
|
onError();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -130,17 +130,20 @@
|
|||||||
var cache = {};
|
var cache = {};
|
||||||
var currentLink = null;
|
var currentLink = null;
|
||||||
var timeout = null;
|
var timeout = null;
|
||||||
|
var currentRequest = null;
|
||||||
|
var currentRequestId = 0;
|
||||||
|
$('main table tbody').on('mouseenter mousemove mouseleave', 'tr td a', function (e) {
|
||||||
|
|
||||||
$('main table tbody tr td a').each(function () {
|
if (e.type === 'mouseenter') {
|
||||||
var $link = $(this);
|
var $link = $(this);
|
||||||
|
|
||||||
$link.on('mouseenter', function (e) {
|
|
||||||
currentLink = this;
|
|
||||||
var siteName = $link.text();
|
var siteName = $link.text();
|
||||||
var url = $link.attr('data-feed');
|
var url = $link.attr('data-feed');
|
||||||
if (!url)
|
if (!url)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
currentLink = $link[0];
|
||||||
|
var requestId = ++currentRequestId;
|
||||||
|
|
||||||
$previewEl.html('<p>Checking for RSS/Atom feed...</p>').show();
|
$previewEl.html('<p>Checking for RSS/Atom feed...</p>').show();
|
||||||
positionPreview(e);
|
positionPreview(e);
|
||||||
|
|
||||||
@ -148,38 +151,51 @@
|
|||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(function () {
|
timeout = setTimeout(function () {
|
||||||
if (cache[url]) {
|
if (cache[url]) {
|
||||||
renderFeedItems(cache[url], siteName);
|
if (currentLink === $link[0] && requestId === currentRequestId) {
|
||||||
positionPreview(e);
|
renderFeedItems(cache[url], siteName);
|
||||||
|
positionPreview(e);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url) {
|
currentRequest = checkFeed(
|
||||||
checkFeed(url, function (items) {
|
url,
|
||||||
if (currentLink === $link[0] && items) {
|
function (items) {
|
||||||
|
if (requestId !== currentRequestId || currentLink !== $link[0])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (items && items.length) {
|
||||||
cache[url] = items;
|
cache[url] = items;
|
||||||
renderFeedItems(items, siteName);
|
renderFeedItems(items, siteName);
|
||||||
positionPreview(e);
|
|
||||||
} else {
|
} else {
|
||||||
$previewEl.hide();
|
$previewEl.html('<p>No feed items found.</p>');
|
||||||
}
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
$previewEl.hide();
|
|
||||||
}
|
|
||||||
}, 300);
|
|
||||||
});
|
|
||||||
|
|
||||||
$link.on('mousemove', function (e) {
|
positionPreview(e);
|
||||||
|
},
|
||||||
|
function () {
|
||||||
|
if (requestId !== currentRequestId || currentLink !== $link[0])
|
||||||
|
return;
|
||||||
|
$previewEl.html('<p>Failed to load feed.</p>');
|
||||||
|
positionPreview(e);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}, 300);
|
||||||
|
} else if (e.type === 'mousemove') {
|
||||||
if ($previewEl.is(':visible'))
|
if ($previewEl.is(':visible'))
|
||||||
positionPreview(e);
|
positionPreview(e);
|
||||||
});
|
} else if (e.type === 'mouseleave') {
|
||||||
|
|
||||||
$link.on('mouseleave', function () {
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = null;
|
timeout = null;
|
||||||
currentLink = null;
|
currentLink = null;
|
||||||
|
|
||||||
|
if (currentRequest) {
|
||||||
|
currentRequest.abort();
|
||||||
|
currentRequest = null;
|
||||||
|
}
|
||||||
|
|
||||||
$previewEl.hide();
|
$previewEl.hide();
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('click', function (e) {
|
$(document).on('click', function (e) {
|
||||||
@ -189,6 +205,7 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
if (document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||||
init();
|
init();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user