FeedOnFeeds/fof.js

404 lines
8.9 KiB
JavaScript
Raw Normal View History

2007-06-08 08:21:15 +04:00
var curWidth = 0;
var curPos = 0;
var drag = false;
2007-01-02 04:41:22 +03:00
var what;
var when;
var firstItem;
var item;
var itemElement;
function keyboard(e)
{
2007-06-08 08:21:15 +04:00
if (!e) e = window.event;
if (e.keyCode) keycode=e.keyCode;
else keycode=e.which;
2007-01-02 04:41:22 +03:00
if(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) return true;
2007-06-08 08:21:15 +04:00
key = String.fromCharCode(keycode);
if(key == "n")
{
if(itemElement)
{
Element.removeClassName(itemElement, 'selected');
next = itemElement.nextSibling;
if(next.id)
{
itemElement = next;
}
else
{
item = firstItem;
itemElement = $(item);
}
item = itemElement.id;
itemElement = $(item);
Element.addClassName(itemElement, 'selected');
y = itemElement.y ? itemElement.y : itemElement.offsetTop;
window.scrollTo(0, y);
// what a hack
siblings = $A(itemElement.parentNode.childNodes)
n = siblings.length;
n -= 7;
i = siblings.indexOf(itemElement);
i -= 5;
document.title = "Feed on Feeds - " + i + " of " + n;
2007-06-08 08:21:15 +04:00
return false;
}
else
{
item = firstItem;
itemElement = $(item);
Element.addClassName(itemElement, 'selected');
y = itemElement.y ? itemElement.y : itemElement.offsetTop;
window.scrollTo(0, y);
siblings = $A(itemElement.parentNode.childNodes)
n = siblings.length;
n -= 7;
i = siblings.indexOf(itemElement);
i -= 5;
document.title = "Feed on Feeds - " + i + " of " + n;
2007-06-08 08:21:15 +04:00
return false;
}
}
return true;
2007-01-02 04:41:22 +03:00
}
function startResize(e)
{
2007-06-08 08:21:15 +04:00
if (!e) e = window.event;
Event.stop(e);
drag = true;
curPos=e.clientX;
curWidth=$('sidebar').offsetWidth;
2007-01-02 04:41:22 +03:00
return false;
}
function dragResize(e)
{
2007-06-08 08:21:15 +04:00
if (!e) e = window.event;
if(drag)
{
Event.stop(e);
newPos=e.clientX;
var x=newPos-curPos;
var w=curWidth+x;
newWidth=(w<5?5:w);
$('handle').style.left=newWidth+'px';
2007-01-02 04:41:22 +03:00
2007-06-08 08:21:15 +04:00
return false;
2007-01-02 04:41:22 +03:00
}
}
function completeDrag(e)
{
2007-06-08 08:21:15 +04:00
if (!e) e = window.event;
2007-01-02 04:41:22 +03:00
2007-06-08 08:21:15 +04:00
if(drag)
{
Event.stop(e);
drag = false;
newPos=e.clientX;
var x=newPos-curPos;
var w=curWidth+x;
newWidth=(w<5?5:w);
$('sidebar').style.width=newWidth+'px';
$('handle').style.left=newWidth+'px';
$('items').style.marginLeft=(newWidth+20)+'px';
if(isIE)
{
tables = $$('#sidebar table');
for(i=0;i<tables.length;i++){
tables[i].style.width=(newWidth-20)+'px';
}
}
var today = new Date();
var expire = new Date();
expire.setTime(today.getTime() + 3600000*24*100);
document.cookie = "fof_sidebar_width="+newWidth+ "; expires="+expire.toGMTString()+";";
2007-06-08 08:21:15 +04:00
return false;
}
2007-01-02 04:41:22 +03:00
}
function hide_all()
{
2007-06-08 08:21:15 +04:00
items = document.getElementsByClassName("item", "items");
items.each( function(e) { e.className = "item hidden"; });
2007-01-02 04:41:22 +03:00
}
function show_all()
{
2007-06-08 08:21:15 +04:00
items = document.getElementsByClassName("item", "items");
items.each( function(e) { e.className = "item shown"; });
2007-01-02 04:41:22 +03:00
}
function hide_body(id)
{
2007-06-08 08:21:15 +04:00
$('i' + id).className = 'item hidden';
2007-01-02 04:41:22 +03:00
}
function show_body(id)
{
2007-06-08 08:21:15 +04:00
$('i' + id).className = 'item shown';
2007-01-02 04:41:22 +03:00
}
function flag_upto(id)
{
2007-06-08 08:21:15 +04:00
elements = $A(Form.getInputs('itemform', 'checkbox'));
for(i=0; i<elements.length; i++)
{
elements[i].checked = true;
if(elements[i].name == id)
{
break;
}
}
2007-01-02 04:41:22 +03:00
}
function toggle_highlight()
{
2007-06-08 08:21:15 +04:00
if(document.body.className == '')
{
document.body.className = 'highlight-on';
}
else
{
document.body.className = '';
}
2007-01-02 04:41:22 +03:00
}
function flag_all()
{
2007-06-08 08:21:15 +04:00
elements = $A(Form.getInputs('itemform', 'checkbox'));
elements.each( function(e) { e.checked = true; });
2007-01-02 04:41:22 +03:00
}
function toggle_all()
{
2007-06-08 08:21:15 +04:00
elements = $A(Form.getInputs('itemform', 'checkbox'));
elements.each( function(e) { e.checked = !e.checked; });
2007-01-02 04:41:22 +03:00
}
function unflag_all()
{
2007-06-08 08:21:15 +04:00
elements = $A(Form.getInputs('itemform', 'checkbox'));
elements.each( function(e) { e.checked = false; });
2007-01-02 04:41:22 +03:00
}
function mark_read()
{
2007-06-08 08:21:15 +04:00
document.items['action'].value = 'read';
document.items['return'].value = escape(location);
document.items.submit();
2007-01-02 04:41:22 +03:00
}
function mark_unread()
{
2007-06-08 08:21:15 +04:00
document.items['action'].value = 'unread';
document.items['return'].value = escape(location);
document.items.submit();
2007-01-02 04:41:22 +03:00
}
2007-04-12 05:41:46 +04:00
function mark_feed_read(id)
{
2007-06-08 08:21:15 +04:00
throb();
var url = "view-action.php";
var params = "feed=" + id;
var complete = function () { refreshlist(); };
var options = { method: 'post', parameters: params, onComplete: complete };
new Ajax.Request(url, options);
return false;
2007-04-12 05:41:46 +04:00
}
2007-01-02 04:41:22 +03:00
function add_tag(id, tag)
{
2007-06-08 08:21:15 +04:00
throb();
var url = "add-tag.php";
var params = "tag=" + tag + "&item=" + id;
var complete = function () { refreshlist(); refreshitem(id); };
var options = { method: 'get', parameters: params, onComplete: complete };
new Ajax.Request(url, options);
return false;
2007-01-02 04:41:22 +03:00
}
function remove_tag(id, tag)
{
2007-06-08 08:21:15 +04:00
throb();
var url = "add-tag.php";
var params = "remove=true&tag=" + tag + "&item=" + id;
var complete = function () { refreshlist(); refreshitem(id); };
var options = { method: 'get', parameters: params, onComplete: complete };
new Ajax.Request(url, options);
return false;
2007-01-02 04:41:22 +03:00
}
function delete_tag(tag)
{
throb();
var url = "view-action.php";
var params = "deltag=" + tag;
var complete = function () { refreshlist(); };
var options = { method: 'get', parameters: params, onComplete: complete };
new Ajax.Request(url, options);
return false;
}
2007-01-02 04:41:22 +03:00
function toggle_favorite(id)
{
2007-06-08 08:21:15 +04:00
throb();
2007-01-02 04:41:22 +03:00
image = $('fav' + id);
2007-06-08 08:21:15 +04:00
var url = "add-tag.php?tag=star";
var params = "&item=" + id;
var complete = function () { refreshlist(); refreshitem(id); };
var options = { method: 'get', parameters: params, onComplete: complete };
2007-01-02 04:41:22 +03:00
if(image.star)
{
2007-06-08 08:21:15 +04:00
params += "&remove=true";
var complete = function() { image.src='image/star-off.gif'; image.star = false; refreshlist(); };
2007-01-02 04:41:22 +03:00
}
else
{
2007-06-08 08:21:15 +04:00
var complete = function() { image.src='image/star-on.gif'; image.star = true; refreshlist(); };
2007-01-02 04:41:22 +03:00
}
2007-06-08 08:21:15 +04:00
var options = { method: 'get', parameters: params, onComplete: complete };
new Ajax.Request(url, options);
2007-01-02 04:41:22 +03:00
return false;
}
function refreshitem(id)
{
2007-06-08 08:21:15 +04:00
throb();
var url = 'item.php';
var params = 'id=' + id;
new Ajax.Updater($("i"+id), url, {method: 'get', parameters: params });
2007-01-02 04:41:22 +03:00
}
function refreshlist()
{
2007-06-08 08:21:15 +04:00
throb();
var url = 'sidebar.php';
var params = "what=" + what + "&when=" + when;
2007-06-12 07:20:19 +04:00
new Ajax.Updater($('sidebar'), url, {method: 'get', parameters: params, evalScripts: true });
2007-01-02 04:41:22 +03:00
}
function throb()
{
2007-06-08 08:21:15 +04:00
Element.show('throbber');
2007-01-02 04:41:22 +03:00
}
2007-06-08 08:21:15 +04:00
// this fancy bit of computer science from Aristotle Pagaltzis @ http://plasmasturm.org/log/311/
function iterate( iterable ) {
var i = -1;
var getter = function() { return i < 0 ? null : i < iterable.length ? iterable[ i ] : null; };
return function() { return ++i < iterable.length ? getter : null };
}
function continueupdate()
{
if(feed = feedi())
{
f = feed();
new Insertion.Bottom($('items'), 'Updating ' + f['title'] + "... ");
2007-06-09 09:43:38 +04:00
$('items').childElements().last().scrollTo();
new Ajax.Updater('items', 'update-single.php', {
method: 'get',
parameters: 'feed=' + f['id'],
insertion: Insertion.Bottom,
onComplete: continueupdate
});
}
else
{
new Insertion.Bottom($('items'), '<br>Update complete!');
refreshlist();
}
}
2007-06-09 09:43:38 +04:00
function continueadd()
{
if(feed = feedi())
{
f = feed();
new Insertion.Bottom($('items'), 'Adding ' + f['url'] + "... ");
$('items').childElements().last().scrollTo();
new Ajax.Updater('items', 'add-single.php', {
method: 'get',
parameters: 'url=' + encodeURIComponent(f['url']),
insertion: Insertion.Bottom,
onComplete: continueadd
});
}
else
{
new Insertion.Bottom($('items'), '<br>Done!');
refreshlist();
}
}
function ajaxupdate()
{
throb();
feedi = iterate(feedslist);
continueupdate();
}
2007-06-09 09:43:38 +04:00
function ajaxadd()
{
throb();
feedi = iterate(feedslist);
continueadd();
}