mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-26 15:28:37 -05:00
Remove "defunct" JS.
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
var aniqueue = [];
|
||||
var _frameRate = 15; /* ms */
|
||||
var _duration = 750; /* ms */
|
||||
|
||||
var _ani_speeds = {slow: 2* _duration,
|
||||
medium: _duration,
|
||||
fast: _duration/2,
|
||||
veryfast: _duration/4};
|
||||
|
||||
function __animate() {
|
||||
var a = aniqueue ? aniqueue[0] : [];
|
||||
var newqueue = [];
|
||||
for(var i = 0; i < a.length; i++) {
|
||||
var y = a[i]();
|
||||
if (y) newqueue.unshift(a[i]);
|
||||
}
|
||||
if(newqueue.length > 0) {
|
||||
aniqueue[0] = newqueue;
|
||||
}
|
||||
else {
|
||||
aniqueue = aniqueue.slice(1);
|
||||
}
|
||||
|
||||
if (!aniqueue.length && animator) {
|
||||
stop_animate();
|
||||
}
|
||||
}
|
||||
|
||||
var animator;
|
||||
|
||||
function add_to_aniframes(func, frame_indx) {
|
||||
frame_indx = frame_indx || 0;
|
||||
if((frame_indx >= 0 && aniqueue.length <= frame_indx) || aniqueue.length == 0) {
|
||||
aniqueue.push([]);
|
||||
frame_indx = Math.min(aniqueue.length-1, frame_indx);
|
||||
}
|
||||
aniqueue[frame_indx].unshift(func);
|
||||
if(! animator) {
|
||||
setTimeout(function() { start_animate(_frameRate); }, 30);
|
||||
}
|
||||
return frame_indx;
|
||||
}
|
||||
|
||||
function animate(func, goal, duration, frame_indx) {
|
||||
var d = null;
|
||||
var g = goal ? 1 : 0;
|
||||
if (_ani_speeds[duration])
|
||||
duration = _ani_speeds[duration];
|
||||
duration = duration || _duration;
|
||||
|
||||
add_to_aniframes(function() {
|
||||
d = d || new Date().getTime();
|
||||
var level = (new Date().getTime() - d)/duration;
|
||||
level = g ? level : 1 - level;
|
||||
level = Math.max(Math.min(level, 1), 0);
|
||||
try {
|
||||
func(level);
|
||||
return (level != g);
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}, frame_indx);
|
||||
}
|
||||
|
||||
function start_animate(interval) {
|
||||
if (!animator) {
|
||||
animator = setInterval(__animate, interval);
|
||||
}
|
||||
}
|
||||
|
||||
function stop_animate() {
|
||||
clearInterval(animator);
|
||||
animator = null;
|
||||
}
|
||||
@@ -1,209 +0,0 @@
|
||||
function helpon(link, what, newlabel) {
|
||||
var id = _id(link);
|
||||
show(what + id);
|
||||
var oldlabel = link.innerHTML;
|
||||
if(newlabel) {
|
||||
link.innerHTML = newlabel
|
||||
}
|
||||
link.onclick = function() {
|
||||
return helpoff(link, what, oldlabel);
|
||||
};
|
||||
link.blur();
|
||||
return false;
|
||||
}
|
||||
|
||||
function helpoff(link, what, newlabel) {
|
||||
var id = _id(link);
|
||||
hide(what+id);
|
||||
var oldlabel = link.innerHTML;
|
||||
if(newlabel) {
|
||||
link.innerHTML = newlabel
|
||||
}
|
||||
link.onclick = function() {
|
||||
return helpon(link, what, oldlabel);
|
||||
};
|
||||
link.blur();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function ReplyTemplate() { return $("samplecomment_"); }
|
||||
|
||||
function comment_reply(id) {
|
||||
id = id || '';
|
||||
var s = $("samplecomment_" + id);
|
||||
if (!s) {
|
||||
return re_id_node(ReplyTemplate().cloneNode(true), id);
|
||||
}
|
||||
return s;
|
||||
};
|
||||
|
||||
function _decode(text) {
|
||||
return decodeURIComponent(text.replace(/\+/g, " "));
|
||||
}
|
||||
|
||||
function Comment(id) {
|
||||
this.__init__(id);
|
||||
var edit_body = this.get("edit_body");
|
||||
if(edit_body) {
|
||||
this.text = decodeURIComponent(edit_body.innerHTML.replace(/\+/g, " "));
|
||||
}
|
||||
};
|
||||
|
||||
Comment.prototype = new Thing();
|
||||
|
||||
Comment.del = Thing.del;
|
||||
|
||||
Comment.prototype._edit = function(listing, where, text) {
|
||||
var edit_box = comment_reply(this._id);
|
||||
if (edit_box.parentNode != listing.listing) {
|
||||
if (edit_box.parentNode) {
|
||||
edit_box.parentNode.removeChild(edit_box);
|
||||
}
|
||||
listing.insert_node_before(edit_box, where);
|
||||
}
|
||||
else if (edit_box.parentNode.firstChild != edit_box) {
|
||||
var p = edit_box.parentNode;
|
||||
p.removeChild(edit_box);
|
||||
p.insertBefore(edit_box, p.firstChild);
|
||||
}
|
||||
var box = $("comment_reply_" + this._id);
|
||||
clearTitle(box);
|
||||
box.value = text;
|
||||
show(edit_box);
|
||||
return edit_box;
|
||||
};
|
||||
|
||||
Comment.prototype.edit = function() {
|
||||
this._edit(this.parent_listing(), this.row, this.text);
|
||||
$("commentform_" + this._id).replace.value = "yes";
|
||||
this.hide();
|
||||
};
|
||||
|
||||
Comment.prototype.reply = function() {
|
||||
this._edit(this.child_listing(), null, '');
|
||||
$("commentform_" + this._id).replace.value = "";
|
||||
$("comment_reply_" + this._id).focus();
|
||||
};
|
||||
|
||||
Comment.prototype.cancel = function() {
|
||||
var edit_box = comment_reply(this._id);
|
||||
hide(edit_box);
|
||||
this.show();
|
||||
};
|
||||
|
||||
Comment.comment = function(r) {
|
||||
var id = r.id;
|
||||
var parent_id = r.parent;
|
||||
new Comment(parent_id).cancel();
|
||||
new Listing(parent_id).push(unsafe(r.content));
|
||||
new Comment(r.id).show();
|
||||
vl[id] = r.vl;
|
||||
};
|
||||
|
||||
// Commenting on a link is handled by the Comment API so defer to it
|
||||
Link.comment = Comment.comment;
|
||||
|
||||
Comment.morechildren = function(r) {
|
||||
var c = new Thing(r.id);
|
||||
if(c.row) c.del();
|
||||
var parent = new Thing(r.parent).child_listing();
|
||||
parent.append(unsafe(r.content));
|
||||
|
||||
var c = new Comment(r.id);
|
||||
c.show(true);
|
||||
vl[r.id] = r.vl;
|
||||
};
|
||||
|
||||
Comment.editcomment = function(r) {
|
||||
var com = new Comment(r.id);
|
||||
com.get('body').innerHTML = unsafe(r.contentHTML);
|
||||
com.get('edit_body').innerHTML = unsafe(r.contentTxt);
|
||||
com.cancel();
|
||||
com.show();
|
||||
};
|
||||
|
||||
|
||||
Comment.prototype.collapse = function() {
|
||||
hide(this.get('child'));
|
||||
hide(this.get('display'));
|
||||
hide(this.get('arrows'));
|
||||
show(this.get('collapsed'));
|
||||
};
|
||||
|
||||
Comment.prototype.uncollapse = function() {
|
||||
show(this.get('child'));
|
||||
show(this.get('display'));
|
||||
show(this.get('arrows'));
|
||||
hide(this.get('collapsed'));
|
||||
};
|
||||
|
||||
|
||||
function morechildren(form, link_id, children, depth) {
|
||||
var id = _id(form);
|
||||
form.innerHTML = _global_loading_tag;
|
||||
form.style.color="red";
|
||||
redditRequest('morechildren', {link_id: link_id,
|
||||
children: children, depth: depth, id: id});
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function editcomment(id) {
|
||||
new Comment(id).edit();
|
||||
};
|
||||
|
||||
function cancelReply(canceler) {
|
||||
new Comment(_id(canceler)).cancel();
|
||||
};
|
||||
|
||||
|
||||
function reply(id) {
|
||||
if (logged) {
|
||||
var com = new Comment(id).reply();
|
||||
}
|
||||
else {
|
||||
showcover(true, 'reply_' + id);
|
||||
}
|
||||
};
|
||||
|
||||
function chkcomment(form) {
|
||||
if(form.replace.value) {
|
||||
return post_form(form, 'editcomment', null, null, true);
|
||||
}
|
||||
else {
|
||||
return post_form(form, 'comment', null, null, true);
|
||||
}
|
||||
};
|
||||
|
||||
function clearTitle(box) {
|
||||
if (box.rows && box.rows < 7 ||
|
||||
box.style.color == "gray" ||
|
||||
box.style.color == "#808080") {
|
||||
box.value = "";
|
||||
box.style.color = "black";
|
||||
if (box.rows) { box.rows = 7;}
|
||||
try{
|
||||
box.focus();
|
||||
}
|
||||
catch(e) {};
|
||||
}
|
||||
}
|
||||
|
||||
function hidecomment(id) {
|
||||
var com = new Comment(id);
|
||||
com.collapse();
|
||||
return false;
|
||||
}
|
||||
|
||||
function showcomment(id) {
|
||||
var com = new Comment(id);
|
||||
com.uncollapse();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Message = Comment;
|
||||
Message.message = Comment.comment;
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
//stuff that needs to be moved
|
||||
function rowon(el) {el.className = "menu collapse d";}
|
||||
function rowoff(el) {el.className = "menu collapse r";}
|
||||
|
||||
function helpon() {
|
||||
show("markhelp");
|
||||
$("marklink").href = "javascript: helpoff()";
|
||||
$("marklink").blur();
|
||||
rowon($("marktoggle"));
|
||||
}
|
||||
|
||||
function helpoff() {
|
||||
hide("markhelp");
|
||||
$("marklink").href = "javascript: helpon()";
|
||||
$("marklink").blur();
|
||||
rowoff($("marktoggle"));
|
||||
}
|
||||
|
||||
//function shareon() {
|
||||
// show("share");
|
||||
// $("sharelink").href = "javascript: shareoff()";
|
||||
// $("sharelink").blur();
|
||||
// rowon($("sharetoggle"));
|
||||
//}
|
||||
|
||||
//function shareoff() {
|
||||
// hide("share");
|
||||
// $("sharelink").href = "javascript: shareon()";
|
||||
// $("sharelink").blur();
|
||||
// rowoff($("sharetoggle"));
|
||||
//}
|
||||
|
||||
|
||||
function list_toggle_on(form, name, func) {
|
||||
id = _id(form);
|
||||
show(name + id);
|
||||
rowon($(name+"toggle_"+id));
|
||||
$(name+"link_"+id).onclick = function(event) { func(this); };
|
||||
$(name+"link_"+id).blur();
|
||||
}
|
||||
|
||||
function list_toggle_off(form, name, func) {
|
||||
id = _id(form);
|
||||
hide(name+id);
|
||||
rowoff($(name+"toggle_"+id));
|
||||
$(name+"link_"+id).onclick = function(event) { func(this); };
|
||||
$(name+"link_"+id).blur();
|
||||
}
|
||||
|
||||
|
||||
function contactson(form) {
|
||||
list_toggle_on(form, 'contacts_', contactsoff);
|
||||
}
|
||||
|
||||
function contactsoff(form) {
|
||||
list_toggle_off(form, 'contacts_', contactson);
|
||||
}
|
||||
|
||||
|
||||
var contable = new ConTable("contactlst",
|
||||
function (name, val) {new Ajax.Request('/ajax', {parameters: "action=ualias&name="+name+"&val="+val});},
|
||||
function (name) {new Ajax.Request('/ajax', {parameters: "action=ualias&name="+name})},
|
||||
function (name) {
|
||||
if ($("to").value.length > 0) $("to").value += ", " + name;
|
||||
else $("to").value = name;
|
||||
});
|
||||
|
||||
function makeedit(row) {
|
||||
var text = new Array("alias", "emails/aliases");
|
||||
for (var i = 1; i < 3; i++) {
|
||||
var c = row.cells[i];
|
||||
var empty = c.innerHTML;
|
||||
c.innerHTML = "<input type='text' "
|
||||
+ (empty.length > 0 ? "" : "style='color:gray' onfocus='clearTitle(this)'")
|
||||
+ " value='" + (empty || text[i-1]) + "'/>";
|
||||
}
|
||||
row.cells[3].innerHTML = "<a href='javascript:return true;' onclick='saverow(this); return false;'>save</a>";
|
||||
}
|
||||
|
||||
function makefinal(row) {
|
||||
for (var i = 1; i < 3; i++) {
|
||||
var c = row.cells[i];
|
||||
c.innerHTML = c.firstChild && c.firstChild.value || "";
|
||||
}
|
||||
row.cells[3].innerHTML = "<a href='javascript:return true;' onclick='editrow(this); return false'>edit</a>";
|
||||
}
|
||||
|
||||
function buildrow (row) {
|
||||
for (var i = 0; i < 5; i ++) row.insertCell(row.cells.length);
|
||||
row.cells[0].innerHTML = "<a style='font-size: normal; color: #336699' href='#' onclick='sendrow(this)'; return false'>add</a>";
|
||||
row.cells[4].innerHTML = "<a href='javascript:return true;' onclick='removerow(this); return false'>delete</a>";
|
||||
return row;
|
||||
}
|
||||
|
||||
function addrow() {contable.add();}
|
||||
function getrow(a) {return a.parentNode.parentNode;}
|
||||
function saverow(a) {contable.save(getrow(a));}
|
||||
function editrow(a) {contable.edit(getrow(a));}
|
||||
function removerow(a) {contable.remove(getrow(a));}
|
||||
function sendrow(a) {contable.send(getrow(a))};
|
||||
|
||||
function ConTable (id, onsave, onremove, onadd) {
|
||||
this.id = id;
|
||||
this.onsave = onsave || function () {};
|
||||
this.onremove = onremove || function () {};
|
||||
this.onadd = onadd || function () {};
|
||||
|
||||
this.table = function() {return $(this.id)};
|
||||
this.add = function () {
|
||||
var table = this.table();
|
||||
var row = table.insertRow(table.rows.length);
|
||||
makeedit(buildrow(row));
|
||||
};
|
||||
|
||||
|
||||
this.cellval = function (c) {return c.firstChild && c.firstChild.value
|
||||
|| c.firstChild && c.firstChild.nodeValue
|
||||
|| ""}
|
||||
|
||||
this.alias = function (row) {return this.cellval(row.cells[1])};
|
||||
this.val = function (row) {return this.cellval(row.cells[2])};
|
||||
|
||||
this.send = function (row) {this.onadd(this.alias(row))};
|
||||
this.edit = function (row) {makeedit(row)};
|
||||
this.save = function (row) {makefinal(row); this.onsave(this.alias(row), this.val(row))};
|
||||
this.remove = function (row) {var a = this.alias(row); this.table().deleteRow(row.rowIndex); this.onremove(a)};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
function frame_mod(id, uc) {
|
||||
if(!logged) {
|
||||
return frame_showlogin();
|
||||
}
|
||||
mod(id, uc);
|
||||
}
|
||||
|
||||
function frame_showlogin() {
|
||||
hide("left", "menu", "vertxt", "passwd2", "user", "passwd");
|
||||
$("logbtn").innerHTML = "login";
|
||||
$("logform").op.value = "login";
|
||||
show("frame_middle", "usrtxt", "passtxt", "rem", "remlbl");
|
||||
}
|
||||
|
||||
function cancel () {
|
||||
hide("frame_middle");
|
||||
show("frame_left", "menu");
|
||||
$("user").value = $("passwd").value = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
function kill(uh) {
|
||||
hide("main");
|
||||
show("killed");
|
||||
redditRequest('noframe');
|
||||
}
|
||||
|
||||
function unkill() {
|
||||
hide("killed");
|
||||
show("main");
|
||||
redditRequest('frame');
|
||||
}
|
||||
|
||||
|
||||
function swapel(e1, e2, e) {hide(e1); show(e2); $(e2).select(); }
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
if (!Object.prototype.toJSONString) {
|
||||
Array.prototype.toJSONString = function (w) {
|
||||
var a = [], // The array holding the partial texts.
|
||||
i, // Loop counter.
|
||||
l = this.length,
|
||||
v; // The value to be stringified.
|
||||
for (i = 0; i < l; i += 1) {
|
||||
v = this[i];
|
||||
switch (typeof v) {
|
||||
case 'object':
|
||||
if (v) {
|
||||
if (typeof v.toJSONString === 'function') {
|
||||
a.push(v.toJSONString(w));
|
||||
}
|
||||
} else {
|
||||
a.push('null');
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
a.push(v.toJSONString());
|
||||
}
|
||||
}
|
||||
return '[' + a.join(',') + ']';
|
||||
};
|
||||
Boolean.prototype.toJSONString = function () {
|
||||
return String(this);
|
||||
};
|
||||
Date.prototype.toJSONString = function () {
|
||||
function f(n) {
|
||||
return n < 10 ? '0' + n : n;
|
||||
}
|
||||
return '"' + this.getUTCFullYear() + '-' +
|
||||
f(this.getUTCMonth() + 1) + '-' +
|
||||
f(this.getUTCDate()) + 'T' +
|
||||
f(this.getUTCHours()) + ':' +
|
||||
f(this.getUTCMinutes()) + ':' +
|
||||
f(this.getUTCSeconds()) + 'Z"';
|
||||
};
|
||||
Number.prototype.toJSONString = function () {
|
||||
return isFinite(this) ? String(this) : 'null';
|
||||
};
|
||||
Object.prototype.toJSONString = function (w) {
|
||||
var a = [],
|
||||
k,
|
||||
i,
|
||||
v;
|
||||
if (w) {
|
||||
for (i = 0; i < w.length; i += 1) {
|
||||
k = w[i];
|
||||
if (typeof k === 'string') {
|
||||
v = this[k];
|
||||
switch (typeof v) {
|
||||
case 'object':
|
||||
if (v) {
|
||||
if (typeof v.toJSONString === 'function') {
|
||||
a.push(k.toJSONString() + ':' +
|
||||
v.toJSONString(w));
|
||||
}
|
||||
} else {
|
||||
a.push(k.toJSONString() + ':null');
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
a.push(k.toJSONString() + ':' + v.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (k in this) {
|
||||
if (typeof k === 'string' &&
|
||||
Object.prototype.hasOwnProperty.apply(this, [k])) {
|
||||
v = this[k];
|
||||
switch (typeof v) {
|
||||
case 'object':
|
||||
if (v) {
|
||||
if (typeof v.toJSONString === 'function') {
|
||||
a.push(k.toJSONString() + ':' +
|
||||
v.toJSONString());
|
||||
}
|
||||
} else {
|
||||
a.push(k.toJSONString() + ':null');
|
||||
}
|
||||
break;
|
||||
case 'string':
|
||||
case 'number':
|
||||
case 'boolean':
|
||||
a.push(k.toJSONString() + ':' + v.toJSONString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return '{' + a.join(',') + '}';
|
||||
};
|
||||
(function (s) {
|
||||
var m = {
|
||||
'\b': '\\b',
|
||||
'\t': '\\t',
|
||||
'\n': '\\n',
|
||||
'\f': '\\f',
|
||||
'\r': '\\r',
|
||||
'"' : '\\"',
|
||||
'\\': '\\\\'
|
||||
};
|
||||
s.parseJSON = function (filter) {
|
||||
var j;
|
||||
function walk(k, v) {
|
||||
var i;
|
||||
if (v && typeof v === 'object') {
|
||||
for (i in v) {
|
||||
if (Object.prototype.hasOwnProperty.apply(v, [i])) {
|
||||
v[i] = walk(i, v[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filter(k, v);
|
||||
}
|
||||
if (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(this.
|
||||
replace(/\\./g, '@').
|
||||
replace(/"[^"\\\n\r]*"/g, ''))) {
|
||||
j = eval('(' + this + ')');
|
||||
return typeof filter === 'function' ? walk('', j) : j;
|
||||
}
|
||||
throw new SyntaxError('parseJSON');
|
||||
};
|
||||
s.toJSONString = function () {
|
||||
if (/["\\\x00-\x1f]/.test(this)) {
|
||||
return '"' + this.replace(/[\x00-\x1f\\"]/g, function (a) {
|
||||
var c = m[a];
|
||||
if (c) {
|
||||
return c;
|
||||
}
|
||||
c = a.charCodeAt();
|
||||
return '\\u00' +
|
||||
Math.floor(c / 16).toString(16) +
|
||||
(c % 16).toString(16);
|
||||
}) + '"';
|
||||
}
|
||||
return '"' + this + '"';
|
||||
};
|
||||
})(String.prototype);
|
||||
}
|
||||
@@ -1,583 +0,0 @@
|
||||
function Thing(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
var reddit_thing_info = {fetch: []};
|
||||
Thing.prototype = {
|
||||
__init__: function(id) {
|
||||
this._id = id;
|
||||
this.row = this.$("thingrow");
|
||||
if (this.row) {
|
||||
/* initialize sizing info for animations if not already */
|
||||
if (!this.max_height()) {
|
||||
this.set_height("fit");
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_fade_and_hide: function(fraction) {
|
||||
fraction = Math.max(Math.min(fraction, 1), 0);
|
||||
var height_frac = Math.max(Math.min(2*fraction, 1), 0);
|
||||
var opac_frac = Math.max(Math.min(2 * fraction -1 , 1), 0);
|
||||
if(fraction == 0)
|
||||
this.hide();
|
||||
else if (this.row.style.display == 'none')
|
||||
this.show();
|
||||
this.set_opacity(opac_frac);
|
||||
this.set_height((height_frac == 1) ? 'fit' : (this.max_height() * height_frac));
|
||||
this.row.cur_hide = fraction;
|
||||
},
|
||||
|
||||
set_opacity : function(opac) {
|
||||
this.row.style.opacity = opac;
|
||||
var filt = "alpha(opacity=" + parseInt(opac*100) + ")";
|
||||
this.row.style.filter = filt;
|
||||
this.row.style.zoom = 1;
|
||||
},
|
||||
|
||||
get: function(name) {
|
||||
return $(name + '_' + this._id);
|
||||
},
|
||||
|
||||
$: function(name) {
|
||||
return $(name + '_' + this._id);
|
||||
},
|
||||
|
||||
_fade_step: function(frac, fading) {
|
||||
if(fading == this.row.fading) {
|
||||
var opac_frac = Math.max(Math.min(frac , 1), 0);
|
||||
this.set_opacity(opac_frac);
|
||||
}
|
||||
},
|
||||
|
||||
fade: function(duration, indx) {
|
||||
var t = this;
|
||||
this.row.fading = true;
|
||||
animate(function(x) { t._fade_step(x, true); }, 0, duration, indx);
|
||||
},
|
||||
|
||||
unfade: function(duration, indx) {
|
||||
var t = this;
|
||||
this.row.fading = false;
|
||||
animate(function(x) { t._fade_step(x, false); }, 1, duration, indx);
|
||||
},
|
||||
|
||||
_hide_step: function(fraction) {
|
||||
if(this.row.cur_hide == null)
|
||||
this.row.cur_hide = 1;
|
||||
if (this.row.hiding && fraction < this.row.cur_hide) {
|
||||
this._fade_and_hide(fraction);
|
||||
}
|
||||
},
|
||||
|
||||
_show_step: function(fraction) {
|
||||
if(this.row.cur_hide == null)
|
||||
this.row.cur_hide = 0;
|
||||
if (!this.row.hiding && fraction > this.row.cur_hide) {
|
||||
this._fade_and_hide(fraction);
|
||||
}
|
||||
},
|
||||
|
||||
hide: function(do_animate) {
|
||||
this.row.hidden = true;
|
||||
if(do_animate) {
|
||||
var t = this;
|
||||
this.row.hiding = true;
|
||||
animate(function(x) { t._hide_step(x); }, 0);
|
||||
}
|
||||
else {
|
||||
hide(this.row);
|
||||
if(this.__destroy && this.row && this.row.parentNode) {
|
||||
this.row.parentNode.removeChild(this.row);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
show: function(do_animate) {
|
||||
this.row.hidden = false;
|
||||
if(do_animate) {
|
||||
var t = this;
|
||||
this.row.hiding = false;
|
||||
animate(function(x) { t._show_step(x) }, 1);
|
||||
}
|
||||
else {
|
||||
show(this.row);
|
||||
}
|
||||
/* promoted magic */
|
||||
if(reddit_thing_info.fetch && reddit_thing_info.fetch.length != 0) {
|
||||
var f = reddit_thing_info.fetch;
|
||||
for(var i = 0; i < f.length; i++) {
|
||||
if (f[i] == this._id) {
|
||||
redditRequest("onload", {ids: f.join(",")},
|
||||
handleOnLoad, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(reddit_thing_info && reddit_thing_info[this._id]) {
|
||||
var img = this.$("promote_img");
|
||||
var img_src = unsafe(reddit_thing_info[this._id][0]);
|
||||
var new_url = unsafe(reddit_thing_info[this._id][1]);
|
||||
if (img && img.src != img_src) {
|
||||
img.src = img_src;
|
||||
this.$("title").href = new_url;
|
||||
if(this.$("thumbnail"))
|
||||
this.$("thumbnail").href = new_url;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
del: function(do_animate) {
|
||||
this.__destroy = true;
|
||||
this.hide(do_animate);
|
||||
},
|
||||
|
||||
child_listing: function() {
|
||||
var child = this.$("child");
|
||||
if (!Listing.exists(this._id)) {
|
||||
l = Listing.create(this._id);
|
||||
child.insertBefore(l.ajaxHook, child.firstChild);
|
||||
child.insertBefore(l.listing, child.firstChild);
|
||||
}
|
||||
return new Listing(this._id);
|
||||
},
|
||||
|
||||
is_visible: function() {
|
||||
if(this.row) {
|
||||
if(this.row.hidden == null)
|
||||
this.row.hidden = (this.row.style.display == 'none');
|
||||
return !this.row.hidden;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
compute_height:function() {
|
||||
var arrows = this.$("arrows");
|
||||
var entry = this.$("entry");
|
||||
var thumb = this.$("thumbnail");
|
||||
var num = this.$("num");
|
||||
return Math.max(arrows ? arrows.offsetHeight : 0,
|
||||
entry ? entry.offsetHeight : 0,
|
||||
thumb ? thumb.offsetHeight : 0,
|
||||
num ? num.offsetHeight : 0);
|
||||
},
|
||||
|
||||
parent_listing: function() {
|
||||
return Listing.attach(this.row.parentNode);
|
||||
},
|
||||
|
||||
max_height: function() {
|
||||
return this.row._height + this.row._top_pad + this.row._bot_pad;
|
||||
},
|
||||
|
||||
get_height: function() {
|
||||
return this.row.offsetHeight;
|
||||
},
|
||||
|
||||
set_height: function(h) {
|
||||
var entry = this.$('entry');
|
||||
var thumb = this.$('thumbnail');
|
||||
var arrows = this.$('arrows');
|
||||
var num = this.$('num');
|
||||
if(h == "fit" ||
|
||||
(this.max_height() && h >= this.max_height() *.90 )) {
|
||||
this.row.style.paddingTop = "";
|
||||
this.row.style.paddingBottom = "";
|
||||
h = "";
|
||||
}
|
||||
else if (h <= 0) {
|
||||
this.row.style.paddingTop = "0px";
|
||||
this.row.style.paddingBottom = "0px";
|
||||
h = "0px";
|
||||
}
|
||||
else {
|
||||
if(this.row._top_pad && h <= this.row._top_pad) {
|
||||
this.row.style.paddingTop = h + "px";
|
||||
this.row.style.paddingBottom = "0px";
|
||||
h = "0px";
|
||||
}
|
||||
else {
|
||||
var height;
|
||||
if (this.row.style.height) {
|
||||
height = parseInt(this.row.style.height);
|
||||
}
|
||||
else {
|
||||
height = this.compute_height();
|
||||
}
|
||||
var pad = this.row.offsetHeight - height;
|
||||
this.row.style.paddingTop = "";
|
||||
if(h < pad) {
|
||||
this.row.style.paddingBottom =
|
||||
Math.max(h - this.row._top_pad, 0) + "px";
|
||||
h = 0;
|
||||
}
|
||||
h += "px";
|
||||
}
|
||||
}
|
||||
entry.style.height = h;
|
||||
if(arrows) { arrows.style.height = h; }
|
||||
if(thumb) { thumb.style.height = h; }
|
||||
if(num) {
|
||||
if (h)
|
||||
num.style.marginTop = 0;
|
||||
else
|
||||
num.style.marginTop = "";
|
||||
num.style.height = h;
|
||||
|
||||
}
|
||||
this.row.style.height = h;
|
||||
|
||||
if(h == "" && this.is_visible()) {
|
||||
height = this.compute_height();
|
||||
top_pad = entry.offsetTop - this.row.offsetTop - 1;
|
||||
bot_pad = this.row.offsetHeight - height - top_pad -1;
|
||||
/* cache heights for later restoration */
|
||||
this.row._height = height;
|
||||
this.row._top_pad = top_pad;
|
||||
this.row._bot_pad = bot_pad;
|
||||
}
|
||||
|
||||
return this.row.offsetHeight;
|
||||
}
|
||||
};
|
||||
|
||||
Thing.del = function(r) {
|
||||
new Thing(r.id).del(true);
|
||||
};
|
||||
|
||||
function Listing(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
Listing.prototype = {
|
||||
__init__: function(id) {
|
||||
if(id) {
|
||||
id = "_" + id;
|
||||
}
|
||||
this.listing = $('siteTable' + id);
|
||||
this.ajax_hook = $('ajaxHook' + id);
|
||||
if(this.listing) {
|
||||
if(! this.listing.start_count) {
|
||||
this.listing.start_count = this.visible_count();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
insert_node_before: function(node, before_me, append_me) {
|
||||
before_me = before_me || this.listing.firstChild;
|
||||
if(!append_me && before_me) {
|
||||
this.listing.insertBefore(node, before_me);
|
||||
}
|
||||
else {
|
||||
this.listing.appendChild(node);
|
||||
}
|
||||
},
|
||||
|
||||
/* insert content via innerHTML and return Thing objects of
|
||||
* inserted things */
|
||||
insert: function(content, before_me, append_me) {
|
||||
var a = this.ajax_hook;
|
||||
a.innerHTML = content;
|
||||
var childs = a.childNodes;
|
||||
var things = [];
|
||||
for(var i = 0; i < childs.length; i++) {
|
||||
var id = _id(childs[i]);
|
||||
if(id) {
|
||||
var t = new Thing(id);
|
||||
t.set_height("fit");
|
||||
t.hide();
|
||||
things.unshift(t);
|
||||
}
|
||||
this.insert_node_before(childs[i], before_me, append_me);
|
||||
}
|
||||
/*a.innerHTML = '';*/
|
||||
return things;
|
||||
},
|
||||
|
||||
push: function(content) {
|
||||
return this.insert(content, this.listing.firstChild);
|
||||
},
|
||||
|
||||
append: function(content) {
|
||||
return this.insert(content, null, true);
|
||||
},
|
||||
|
||||
map: function(func) {
|
||||
if(this.listing) {
|
||||
var c = this.listing.childNodes;
|
||||
for(var i = 0; i < c.length; i++) {
|
||||
var id = _id(c[i]);
|
||||
if(id) {
|
||||
func(new Thing(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
select: function(func) {
|
||||
var agg = [];
|
||||
this.map(function(t) { if(func(t)) agg.unshift(t); });
|
||||
return agg;
|
||||
},
|
||||
|
||||
visible_count: function() {
|
||||
return this.select(function(t) {
|
||||
return t.is_visible();
|
||||
}).length;
|
||||
},
|
||||
|
||||
renumber: function(start_num) {
|
||||
var n = start_num;
|
||||
this.map(function(t) {
|
||||
var num = t.$('num');
|
||||
if(num.firstChild.innerHTML) {
|
||||
num = num.firstChild
|
||||
}
|
||||
if(num) {
|
||||
var current_num = parseInt(num.innerHTML);
|
||||
n = n || current_num;
|
||||
if(t.is_visible()) {
|
||||
num.innerHTML = (n++);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
reset_visible_count: function(n) {
|
||||
n = n || this.listing.start_count;
|
||||
this.map(function(t) {
|
||||
if(t.is_visible()) {
|
||||
if(--n < 0) {
|
||||
t.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.renumber();
|
||||
}
|
||||
};
|
||||
|
||||
Listing.exists = function(id) {
|
||||
return $('siteTable_' + id);
|
||||
};
|
||||
|
||||
Listing.attach = function(node) {
|
||||
var id = /siteTable_(.*)/.exec(node.id);
|
||||
if (id) {
|
||||
var listing = new Listing(id[1]);
|
||||
if (listing.listing) {
|
||||
return listing;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Listing.create = function(id) {
|
||||
var l = new Listing(id);
|
||||
if (!l.listing) {
|
||||
l.listing = document.createElement("div");
|
||||
l.listing.id = "siteTable_" + id;
|
||||
l.ajaxHook = document.createElement("div");
|
||||
l.ajaxHook.id = "ajaxHook_" + id;
|
||||
l.ajaxHook.className = "ajaxhook";
|
||||
};
|
||||
return l;
|
||||
};
|
||||
|
||||
function make_sr_list(sr_diffs) {
|
||||
var srs = [];
|
||||
for(var sr in sr_diffs) {
|
||||
if (!(sr in Object.prototype) && sr_diffs[sr] != null) {
|
||||
srs.unshift(sr + ":" + (sr_diffs[sr]?1:0));
|
||||
}
|
||||
}
|
||||
return srs.join(',');
|
||||
}
|
||||
|
||||
|
||||
Listing.fetch_more = function(sr_diffs, sr_needed, num_needed) {
|
||||
var args = update_get_params({srs: make_sr_list(sr_diffs)});
|
||||
/* assumes one listing per page, where is global */
|
||||
new Ajax.Request(where.path + ".json-html", { parameters: make_get_params(args),
|
||||
method: "get", onComplete: Listing_merge(sr_needed, num_needed) } );
|
||||
};
|
||||
|
||||
function _fire_and_hide(type) {
|
||||
return function(fullname) {
|
||||
redditRequest(type, {id: fullname, uh: modhash});
|
||||
new Link(fullname).hide(true);
|
||||
};
|
||||
}
|
||||
|
||||
Listing.unhide = _fire_and_hide('unhide');
|
||||
Listing.hide = _fire_and_hide('hide');
|
||||
Listing.report = _fire_and_hide('report');
|
||||
Listing.del = _fire_and_hide('del');
|
||||
|
||||
Listing.parse = function(r) {
|
||||
var links = [];
|
||||
var res_obj = parse_response(r);
|
||||
if(res_obj && res_obj.response) {
|
||||
var r = res_obj.response.object;
|
||||
for(var i = 0; i < r.length; i++) {
|
||||
if (r[i].kind == "Listing") {
|
||||
for(var j = 0; j < r[i].data.length; j++) {
|
||||
links.push(r[i].data[j].data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return links;
|
||||
};
|
||||
|
||||
function Listing_merge(sr_needed, num_needed) {
|
||||
return function (r) {
|
||||
/* assumes only one listing */
|
||||
var l = new Listing("");
|
||||
var links = Listing.parse(r);
|
||||
var things = [];
|
||||
var count = Math.max(l.listing.start_count, links.length);
|
||||
|
||||
for(var i = 0; i < links.length; i++) {
|
||||
var d = links[i];
|
||||
var t = new Thing(d.id);
|
||||
if(t.row) {
|
||||
if (! t.is_visible())
|
||||
things.unshift(t);
|
||||
}
|
||||
else {
|
||||
if (! num_needed && i < count) {
|
||||
t = l.insert(unsafe(d.content), l.listing.childNodes[i+1]);}
|
||||
else
|
||||
t = l.append(unsafe(d.content));
|
||||
if(d.sr == sr_needed ||
|
||||
(num_needed && i >= count - num_needed))
|
||||
things = things.concat(t);
|
||||
vl[d.id] = d.vl;
|
||||
sr[d.id] = d.sr;
|
||||
}
|
||||
}
|
||||
for(var i = 0; i < things.length; i++) {
|
||||
things[i].show(true);
|
||||
}
|
||||
add_to_aniframes(function() {
|
||||
l.reset_visible_count(count);
|
||||
}, 1);
|
||||
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
function Link(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
Link.prototype = new Thing();
|
||||
|
||||
Link.prototype.share = function() {
|
||||
var share = new ShareLink(this._id);
|
||||
share.attach(this.$("child"));
|
||||
};
|
||||
|
||||
function linkstatus(form) {
|
||||
var title = field(form.title);
|
||||
if(title) {
|
||||
return _global_submitting_tag;
|
||||
}
|
||||
return _global_fetching_tag;
|
||||
}
|
||||
|
||||
function setClick(a, css_class) {
|
||||
css_class = css_class || "title";
|
||||
var id = _id(a);
|
||||
if (id) {
|
||||
if(logged) {
|
||||
a.className = css_class + " loggedin click";
|
||||
}
|
||||
else {
|
||||
a.className = css_class + " click";
|
||||
}
|
||||
setClickCookie(id);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function setClickCookie(id) {
|
||||
var newcookie = readCookie("click") + id + ":";
|
||||
createCookie("click", newcookie);
|
||||
}
|
||||
|
||||
|
||||
function ThingForm(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
ThingForm.prototype = {
|
||||
__init__: function(id) {
|
||||
this._id = id;
|
||||
this.form = $(this.__name__ + "_" + id);
|
||||
if (!this.form) {
|
||||
var p = this.__prototype__();
|
||||
if (p) {
|
||||
this.form = re_id_node(p.cloneNode(true), id);
|
||||
}
|
||||
} else {
|
||||
show(this.form);
|
||||
}
|
||||
},
|
||||
|
||||
__name__ : "",
|
||||
|
||||
__prototype__: function() {
|
||||
return $(this.__name__ + '_');
|
||||
},
|
||||
|
||||
$: function(name) {
|
||||
return $(name + '_' + this._id);
|
||||
},
|
||||
|
||||
cancel: function() {
|
||||
hide(this.form);
|
||||
return false;
|
||||
},
|
||||
|
||||
ok: function() {
|
||||
return true;
|
||||
},
|
||||
|
||||
attach: function(where) {
|
||||
if (this.form.parentNode) {
|
||||
if(this.form.parentNode != where) {
|
||||
this.form.parentNode.removeChild(this.form);
|
||||
where.insertBefore(this.form, where.firstChild);
|
||||
}
|
||||
}
|
||||
where.insertBefore(this.form, where.firstChild);
|
||||
show(this.form);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
function ShareLink(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
ShareLink.prototype = new ThingForm();
|
||||
ShareLink.prototype.__name__ = "sharelink";
|
||||
|
||||
ShareLink.prototype.ok = function() {
|
||||
var p = this.__prototype__();
|
||||
var v = this.$("share_to").value.replace(/[\s,;]+/g, "\r\n");
|
||||
p.firstChild.share_to.value = v;
|
||||
p.firstChild.share_to.innerHTML = v;
|
||||
return true;
|
||||
};
|
||||
|
||||
function share(id) {
|
||||
if (logged) {
|
||||
new Link(id).share();
|
||||
}
|
||||
else {
|
||||
showcover(true, 'share_' + id);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,155 +0,0 @@
|
||||
function OrganicListing() {
|
||||
this.__init__('organic');
|
||||
this._links = organic_links;
|
||||
/* first time, init the position and figure out what is loaded */
|
||||
if(!this.listing._loaded) {
|
||||
this.listing._loaded = {};
|
||||
/* and which ones are present in the listing */
|
||||
var _this = this;
|
||||
this.map(function(t) {
|
||||
_this.listing._loaded[t._id] = t;
|
||||
if(t.is_visible()) {
|
||||
for(var i = 0; i < _this._links.length; i++) {
|
||||
if (t._id == _this._links[i]) {
|
||||
_this.listing.pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_this.listing.max_pos = _this.listing.pos;
|
||||
_this.listing.update_pos = true;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
OrganicListing.prototype = new Listing();
|
||||
|
||||
OrganicListing.prototype.current = function() {
|
||||
return this.listing._loaded[this._links[this.listing.pos]];
|
||||
};
|
||||
|
||||
OrganicListing.prototype.check_ahead = function(dir, num) {
|
||||
num = num || 10;
|
||||
dir = (dir > 0)? 1: -1;
|
||||
var pos = this.listing.pos;
|
||||
var len = this._links.length;
|
||||
var to_load = [];
|
||||
var streak = null;
|
||||
for(var i = 0; i < num; i++) {
|
||||
var j = ((i+1) * dir + pos + len) % len;
|
||||
if (!this.listing._loaded[this._links[j]]) {
|
||||
to_load.unshift(this._links[j]);
|
||||
if(streak == null) streak = true;
|
||||
}
|
||||
else if (streak) {
|
||||
streak = false;
|
||||
}
|
||||
}
|
||||
if( (streak && to_load.length > num/2) ||
|
||||
(!streak && to_load.length > 0) ) {
|
||||
to_load = to_load.join(',');
|
||||
var cur = this.current();
|
||||
redditRequest('fetch_links', {num_margin: cur.$("num") .style.width,
|
||||
mid_margin: cur.$("arrows").style.width,
|
||||
links: to_load}, null, true);
|
||||
}
|
||||
};
|
||||
|
||||
function _fire_and_shift(type) {
|
||||
return function(fullname) {
|
||||
redditRequest(type, {id: fullname, uh: modhash});
|
||||
get_organic(true);
|
||||
};
|
||||
}
|
||||
|
||||
function update_organic_pos(new_pos) {
|
||||
var c = readLCookie('reddit_first');
|
||||
if(c != '') {
|
||||
try {
|
||||
c = c.parseJSON();
|
||||
} catch(e) {
|
||||
c = '';
|
||||
}
|
||||
}
|
||||
|
||||
if(c == '') {
|
||||
c = {};
|
||||
}
|
||||
|
||||
if(c.organic_pos && c.organic_pos.length >= 2) {
|
||||
c.organic_pos[1] = new_pos;
|
||||
} else {
|
||||
c.organic_pos = ['none', new_pos];
|
||||
}
|
||||
|
||||
createLCookie('reddit_first', c.toJSONString());
|
||||
}
|
||||
|
||||
OrganicListing.unhide = _fire_and_shift('unhide');
|
||||
OrganicListing.hide = _fire_and_shift('hide');
|
||||
OrganicListing.report = _fire_and_shift('report');
|
||||
OrganicListing.del = _fire_and_shift('del');
|
||||
|
||||
|
||||
OrganicListing.populate = function(links) {
|
||||
var o = new OrganicListing();
|
||||
for(var i = 0; i < links.length; i++) {
|
||||
d = links[i].data;
|
||||
var t = o.insert(unsafe(d.content), o.listing.firstChild);
|
||||
if(t && t[0]) {
|
||||
vl[d.id] = d.vl;
|
||||
o.listing._loaded[d.id] = t[0];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
OrganicListing.prototype.change = function(dir) {
|
||||
dir = (dir > 0)? 1: -1;
|
||||
this.check_ahead(dir);
|
||||
var pos = this.listing.pos;
|
||||
var len = this._links.length;
|
||||
pos = (pos + dir + len) % len;
|
||||
|
||||
var n = this.listing._loaded[this._links[pos]];
|
||||
var c = this.current();
|
||||
if(n && c) {
|
||||
/* only update on "next" */
|
||||
if(dir > 0) {
|
||||
if(this.listing.max_pos == pos)
|
||||
this.listing.update_pos = true;
|
||||
else if (this.listing.update_pos) {
|
||||
update_organic_pos((pos+1)%len);
|
||||
this.listing.max_pos = pos;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.listing.update_pos = false;
|
||||
}
|
||||
|
||||
var _list = this.listing;
|
||||
_list.changing = true;
|
||||
_list.pos = pos;
|
||||
c.fade("veryfast");
|
||||
add_to_aniframes(function() {
|
||||
c.hide();
|
||||
n.show();
|
||||
n.set_opacity(0);
|
||||
}, 1);
|
||||
n.unfade("veryfast", 2);
|
||||
add_to_aniframes(function() {
|
||||
_list.changing = false;
|
||||
}, 3);
|
||||
}
|
||||
};
|
||||
|
||||
function get_organic(next) {
|
||||
var l = new OrganicListing();
|
||||
if(l.listing.changing)
|
||||
return false;
|
||||
else if(next)
|
||||
l.change(1);
|
||||
else
|
||||
l.change(-1);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,158 +0,0 @@
|
||||
var Prototype={
|
||||
Version:'1.3.1',
|
||||
emptyFunction:function(){}
|
||||
};
|
||||
var Class={
|
||||
create:function(){
|
||||
return function(){
|
||||
this.initialize.apply(this,arguments);
|
||||
}
|
||||
}
|
||||
};
|
||||
Object.extend=function(destination,source){
|
||||
for(property in source){
|
||||
destination[property]=source[property];
|
||||
}
|
||||
return destination;
|
||||
};
|
||||
Object.prototype.extend=function(object){
|
||||
return Object.extend.apply(this,[this,object]);
|
||||
};
|
||||
Function.prototype.bind=function(object){
|
||||
var __method=this;
|
||||
return function(){
|
||||
__method.apply(object,arguments);
|
||||
}
|
||||
};
|
||||
var Try={
|
||||
these:function(){
|
||||
var returnValue;
|
||||
for(var i=0;i<arguments.length;i++){
|
||||
var lambda=arguments[i];
|
||||
try{
|
||||
returnValue=lambda();
|
||||
break;
|
||||
}catch(e){}
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
};
|
||||
function $(){
|
||||
var elements=new Array();
|
||||
for(var i=0;i<arguments.length;i++){
|
||||
var element=arguments[i];
|
||||
if(typeof element=='string')
|
||||
element=document.getElementById(element);
|
||||
if(arguments.length==1)
|
||||
return element;
|
||||
elements.push(element);
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
if(!Array.prototype.push){
|
||||
Array.prototype.push=function(){
|
||||
var startLength=this.length;
|
||||
for(var i=0;i<arguments.length;i++)
|
||||
this[startLength+i]=arguments[i];
|
||||
return this.length;
|
||||
}
|
||||
}
|
||||
if(!Function.prototype.apply){
|
||||
Function.prototype.apply=function(object,parameters){
|
||||
var parameterStrings=new Array();
|
||||
if(!object)object=window;
|
||||
if(!parameters)parameters=new Array();
|
||||
for(var i=0;i<parameters.length;i++)
|
||||
parameterStrings[i]='parameters['+i+']';
|
||||
object.__apply__=this;
|
||||
var result=eval('object.__apply__('+
|
||||
parameterStrings.join(', ')+')');
|
||||
object.__apply__=null;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
var Ajax={
|
||||
getTransport:function(){
|
||||
return Try.these(
|
||||
function(){return new ActiveXObject('Msxml2.XMLHTTP')},
|
||||
function(){return new ActiveXObject('Microsoft.XMLHTTP')},
|
||||
function(){return new XMLHttpRequest()}
|
||||
)||false;
|
||||
}
|
||||
};
|
||||
Ajax.Base=function(){};
|
||||
Ajax.Base.prototype={
|
||||
setOptions:function(options){
|
||||
this.options={
|
||||
method:'post',
|
||||
asynchronous:true,
|
||||
parameters:''
|
||||
}.extend(options||{});
|
||||
},
|
||||
responseIsSuccess:function(){
|
||||
return this.transport.status==undefined
|
||||
||this.transport.status==0
|
||||
||(this.transport.status>=200&&this.transport.status<300);
|
||||
},
|
||||
responseIsFailure:function(){
|
||||
return!this.responseIsSuccess();
|
||||
}
|
||||
};
|
||||
Ajax.Request=Class.create();
|
||||
Ajax.Request.Events=
|
||||
['Uninitialized','Loading','Loaded','Interactive','Complete'];
|
||||
Ajax.Request.prototype=(new Ajax.Base()).extend({
|
||||
initialize:function(url,options){
|
||||
this.transport=Ajax.getTransport();
|
||||
this.setOptions(options);
|
||||
this.request(url);
|
||||
},
|
||||
request:function(url){
|
||||
var parameters=this.options.parameters||'';
|
||||
if(parameters.length>0)parameters+='&_=';
|
||||
try{
|
||||
if(this.options.method=='get')
|
||||
url+='?'+parameters;
|
||||
this.transport.open(this.options.method,url,
|
||||
this.options.asynchronous);
|
||||
if(this.options.asynchronous){
|
||||
this.transport.onreadystatechange=this.onStateChange.bind(this);
|
||||
setTimeout((function(){this.respondToReadyState(1)}).bind(this),10);
|
||||
}
|
||||
this.setRequestHeaders();
|
||||
var body=this.options.postBody?this.options.postBody:parameters;
|
||||
this.transport.send(this.options.method=='post'?body:null);
|
||||
}catch(e){
|
||||
}
|
||||
},
|
||||
setRequestHeaders:function(){
|
||||
var requestHeaders=
|
||||
['X-Requested-With','XMLHttpRequest',
|
||||
'X-Prototype-Version',Prototype.Version];
|
||||
if(this.options.method=='post'){
|
||||
requestHeaders.push('Content-type',
|
||||
'application/x-www-form-urlencoded');
|
||||
if(this.transport.overrideMimeType)
|
||||
requestHeaders.push('Connection','close');
|
||||
}
|
||||
if(this.options.requestHeaders)
|
||||
requestHeaders.push.apply(requestHeaders,this.options.requestHeaders);
|
||||
for(var i=0;i<requestHeaders.length;i+=2)
|
||||
this.transport.setRequestHeader(requestHeaders[i],requestHeaders[i+1]);
|
||||
},
|
||||
onStateChange:function(){
|
||||
var readyState=this.transport.readyState;
|
||||
if(readyState!=1)
|
||||
this.respondToReadyState(this.transport.readyState);
|
||||
},
|
||||
respondToReadyState:function(readyState){
|
||||
var event=Ajax.Request.Events[readyState];
|
||||
if(event=='Complete')
|
||||
(this.options['on'+this.transport.status]
|
||||
||this.options['on'+(this.responseIsSuccess()?'Success':'Failure')]
|
||||
||Prototype.emptyFunction)(this.transport);
|
||||
(this.options['on'+event]||Prototype.emptyFunction)(this.transport);
|
||||
if(event=='Complete')
|
||||
this.transport.onreadystatechange=Prototype.emptyFunction;
|
||||
}
|
||||
});
|
||||
@@ -1,377 +0,0 @@
|
||||
var style = 'reddit';
|
||||
var cur_menu = null; //track the current open menu
|
||||
var have_open = false;
|
||||
|
||||
function open_menu(menu) {
|
||||
var child = menu.nextSibling;
|
||||
if (child.className.indexOf("drop-choices") == -1) return;
|
||||
|
||||
show(child);
|
||||
child.style.top = (menu.offsetTop + menu.offsetHeight) + 'px';
|
||||
child.style.left = menu.offsetLeft + 'px';
|
||||
|
||||
menu.onclick = null;
|
||||
cur_menu = menu;
|
||||
have_open = true;
|
||||
}
|
||||
|
||||
function close_menus() {
|
||||
uls = document.getElementsByTagName('DIV');
|
||||
for (var i=0; i<uls.length; i++) {
|
||||
var ul = uls[i];
|
||||
var menu = ul.previousSibling;
|
||||
if (menu != cur_menu && ul.className.indexOf('drop-choices') > -1) {
|
||||
hide(ul);
|
||||
menu.onclick = function() {
|
||||
return open_menu(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* because body and the menu both fire the click event, cur_menu
|
||||
is only true for an instant when opening a menu */
|
||||
if (!cur_menu) {
|
||||
have_open = false;
|
||||
}
|
||||
cur_menu = null;
|
||||
}
|
||||
|
||||
function hover_open_menu(menu) {
|
||||
if (have_open) {
|
||||
open_menu(menu);
|
||||
close_menus();
|
||||
}
|
||||
}
|
||||
|
||||
var global_cookies_allowed = true;
|
||||
|
||||
function init() {
|
||||
/* temp strip off port for the ajax domain (which will need it to
|
||||
* make a request) */
|
||||
var i = ajax_domain.indexOf(':');
|
||||
var a = (i < 0) ? ajax_domain : ajax_domain.slice(0, i);
|
||||
/* permanently strip it off for the cur_domain which only sets cookies */
|
||||
i = cur_domain.indexOf(':');
|
||||
cur_domain = (i < 0) ? cur_domain : cur_domain.slice(0, i);
|
||||
|
||||
if(cur_domain != a) {
|
||||
global_cookies_allowed = false;
|
||||
}
|
||||
else if(cnameframe && !logged) {
|
||||
var m = Math.random() + '';
|
||||
createCookie('test', m);
|
||||
global_cookies_allowed = (readCookie('test') == m);
|
||||
}
|
||||
if (global_cookies_allowed) {
|
||||
updateClicks();
|
||||
/*updateMods();*/
|
||||
}
|
||||
stc = $("siteTable_comments");
|
||||
/* onload populates reddit_link_info, so checking its contents
|
||||
* ensures it doesn't get called on reload/refresh */
|
||||
if ( reddit_thing_info.fetch && reddit_thing_info.fetch.length != 0 )
|
||||
updateLinks(reddit_thing_info.fetch);
|
||||
update_reddit_count();
|
||||
}
|
||||
|
||||
function updateLinks(f) {
|
||||
for (var i = 0; i < f.length; i++) {
|
||||
var l = new Link(f[i]);
|
||||
if (l.row && l.row.style.display != "none")
|
||||
l.show();
|
||||
}
|
||||
}
|
||||
|
||||
function handleOnLoad(r) {
|
||||
r = parse_response(r);
|
||||
var f = reddit_thing_info.fetch;
|
||||
reddit_thing_info.fetch = [];
|
||||
|
||||
reddit_thing_info = (r && r.response) ? r.response.object : {};
|
||||
updateLinks(f);
|
||||
}
|
||||
|
||||
function deletetoggle(link, type) {
|
||||
var parent = link.parentNode;
|
||||
var form = parent.parentNode;
|
||||
link.blur();
|
||||
|
||||
var q = document.createElement('span');
|
||||
q.className = 'question';
|
||||
q.innerHTML = form.question.value;
|
||||
|
||||
var yes = document.createElement('a');
|
||||
yes.className = "yes";
|
||||
yes.innerHTML = form.yes.value;
|
||||
yes.href='javascript:void(0)';
|
||||
|
||||
var slash = document.createTextNode('/');
|
||||
|
||||
var no = document.createElement('a');
|
||||
no.className = "no";
|
||||
no.innerHTML = form.no.value;
|
||||
no.href='javascript:void(0)';
|
||||
|
||||
var oldtext = parent.innerHTML;
|
||||
no.onclick = function() {
|
||||
return untoggle(false, parent, oldtext, type)};
|
||||
|
||||
yes.onclick = function() {
|
||||
return untoggle(true, parent, oldtext, type)};
|
||||
|
||||
q.appendChild(yes);
|
||||
q.appendChild(slash);
|
||||
q.appendChild(no);
|
||||
|
||||
parent.innerHTML = '';
|
||||
parent.appendChild(q);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function untoggle(execute, parent, oldtext, type) {
|
||||
if(execute) {
|
||||
var form = parent.parentNode;
|
||||
var uh = modhash; //global
|
||||
parent.innerHTML = form.executed.value || oldtext;
|
||||
|
||||
if(type == 'del') {
|
||||
post_form(form, type, function() {return ""});
|
||||
}
|
||||
else if (typeof(type) == "string") {
|
||||
post_form(form, type, function() {return ""});
|
||||
}
|
||||
else if (typeof(type) == "function") {
|
||||
type(form.id.value, uh);
|
||||
}
|
||||
}
|
||||
else {
|
||||
parent.innerHTML = oldtext;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function chklogin(form) {
|
||||
if(global_cookies_allowed) {
|
||||
var op = field(form.op);
|
||||
var status = $("status_" + op);
|
||||
if (status) {
|
||||
status.innerHTML = _global_submitting_tag;
|
||||
};
|
||||
if (op == 'login' || op == 'login-main') {
|
||||
post_form(form, 'login');
|
||||
}
|
||||
else {
|
||||
post_form(form, 'register');
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function toggle(a_tag, op) {
|
||||
var form = a_tag.parentNode;
|
||||
post_form(form, op, function() {return ''});
|
||||
var action = form.action.value;
|
||||
var toggled = form.toggled_label.value;
|
||||
form.toggled_label.value = a_tag.innerHTML;
|
||||
a_tag.innerHTML = toggled;
|
||||
var toggled_action = form.toggled_action.value;
|
||||
form.toggled_action.value = form.action.value;
|
||||
form.action.value = toggled_action;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function resizeCookie(name, size) {
|
||||
var c = readCookie(name);
|
||||
if(c.length > size) {
|
||||
var i = size;
|
||||
while (i >= 0 && c[i--] != ';') { }
|
||||
createCookie(name, (i && c.slice(0, i+1)) || '');
|
||||
}
|
||||
}
|
||||
|
||||
/*function updateMods() {
|
||||
var mods = readCookie("mod");
|
||||
if (mods) {
|
||||
mods = mods.split(':');
|
||||
for (var i = 0; i < mods.length; i++) {
|
||||
var m = mods[i].split('=');
|
||||
setMod(m[0], m[1]);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
function updateClicks() {
|
||||
var clicks = readCookie("click");
|
||||
if (clicks) {
|
||||
clicks = clicks.split(':');
|
||||
for (var i = 0; i < clicks.length; i++) {
|
||||
setClick(clicks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showlang() {
|
||||
offset = window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
|
||||
|
||||
$('langcover').style.top = offset + 'px';
|
||||
$('langpopup').style.top = 40 + offset + 'px';
|
||||
show("langcover", "langpopup");
|
||||
return false;
|
||||
}
|
||||
|
||||
function showcover(warning, reason) {
|
||||
offset = window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop;
|
||||
if (warning) {
|
||||
show('cover_msg', 'cover_disclaim');
|
||||
}
|
||||
else {
|
||||
hide('cover_msg', 'cover_disclaim');
|
||||
}
|
||||
$('loginpopup').style.top = 40 + offset + 'px';
|
||||
|
||||
if (reason == 'sr_change_') {
|
||||
//depends on links.js and subreddit.js
|
||||
reason += make_sr_list(changed_srs);
|
||||
}
|
||||
|
||||
if (reason) {
|
||||
$('login_login').elements.reason.value = reason;
|
||||
$('login_reg').elements.reason.value = reason;
|
||||
}
|
||||
|
||||
new_captcha();
|
||||
show("cover", "loginpopup");
|
||||
return false;
|
||||
}
|
||||
|
||||
function hidecover(cover, loginpopup) {
|
||||
hide(cover, loginpopup);
|
||||
/* $('login_main_form').innerHTML = $('login_cover_form').innerHTML;
|
||||
$('login_cover_form').innerHTML = ''; */
|
||||
}
|
||||
|
||||
function check_some() {
|
||||
var have_checked = false;
|
||||
var elements = $("all-langs").form.elements;
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
el = elements[i];
|
||||
if (el.name.indexOf("lang-") != -1 && el.checked) {
|
||||
have_checked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (have_checked) {
|
||||
var some = $("some-langs");
|
||||
some.checked = "checked";
|
||||
}
|
||||
}
|
||||
|
||||
function clear_all() {
|
||||
var all = $("all-langs");
|
||||
if (!all.checked) return;
|
||||
var elements = all.form.elements;
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
el = elements[i];
|
||||
if (el.name.indexOf("lang-") != -1)
|
||||
el.checked = false;
|
||||
}
|
||||
}
|
||||
|
||||
function click(id) {
|
||||
setClick(id);
|
||||
setClickCookie(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function frame(a_tag, id) {
|
||||
click(id);
|
||||
a_tag.href = "/goto?id=" + id;
|
||||
return true;
|
||||
}
|
||||
|
||||
function set_sort(where, sort) {
|
||||
redditRequest('sort', {sort: sort,
|
||||
where: where});
|
||||
return true;
|
||||
}
|
||||
|
||||
function disable_ui(name) {
|
||||
var help = $(name + "-help");
|
||||
var gone = $(name + "-gone");
|
||||
help.parentNode.innerHTML = gone.innerHTML;
|
||||
redditRequest('disable_ui', {id: name});
|
||||
}
|
||||
|
||||
function update_reddit_count() {
|
||||
if (!cur_site || !logged) return;
|
||||
|
||||
var decay_factor = .9; //precentage to keep
|
||||
var decay_period = 86400; //num of seconds between updates
|
||||
var num_recent = 10; //num of recent reddits to report
|
||||
var num_count = 100; //num of reddits to actually count
|
||||
|
||||
var date_key = '_date';
|
||||
var cur_date = new Date();
|
||||
var count_cookie = 'reddit_counts';
|
||||
var recent_cookie = 'recent_reddits';
|
||||
var reddit_counts = readCookie(count_cookie);
|
||||
|
||||
//init the reddit_counts dict
|
||||
if (reddit_counts) reddit_counts = reddit_counts.parseJSON();
|
||||
else {
|
||||
reddit_counts = {};
|
||||
reddit_counts[date_key] = cur_date.toString();
|
||||
}
|
||||
|
||||
var last_reset = new Date(reddit_counts[date_key]);
|
||||
var decay = cur_date - last_reset > decay_period * 1000;
|
||||
var names = [];
|
||||
|
||||
//incrmenet the count on the current reddit
|
||||
reddit_counts[cur_site] = (reddit_counts[cur_site] || 0) + 1;
|
||||
|
||||
//collect the reddit names (for sorting) and decay the view counts
|
||||
//if necessary
|
||||
for (var sr_name in reddit_counts) {
|
||||
if (sr_name == date_key || Object.prototype[sr_name]) continue;
|
||||
|
||||
if (decay && sr_name != cur_site) {
|
||||
//compute the new count val
|
||||
var val = Math.floor(decay_factor * reddit_counts[sr_name]);
|
||||
if (val > 0) reddit_counts[sr_name] = val;
|
||||
else delete reddit_counts[sr_name];
|
||||
}
|
||||
|
||||
if (reddit_counts[sr_name]) names.push(sr_name);
|
||||
}
|
||||
|
||||
//sort the names by the view counts
|
||||
names.sort(function(n1, n2) {return reddit_counts[n2] - reddit_counts[n1];});
|
||||
|
||||
//update the last decay date
|
||||
if (decay) reddit_counts[date_key] = cur_date.toString();
|
||||
|
||||
//build the list of names to report as "recent"
|
||||
var recent_reddits = "";
|
||||
for (var i = 0; i < names.length; i++) {
|
||||
var sr_name = names[i];
|
||||
if (i < num_recent) {
|
||||
recent_reddits += names[i] + ',';
|
||||
} else if (i >= num_count && sr_name != cur_site) {
|
||||
delete reddit_counts[sr_name];
|
||||
}
|
||||
}
|
||||
|
||||
//set the two cookies: one for the counts, one for the final
|
||||
//recent list
|
||||
createCookie(count_cookie, reddit_counts.toJSONString());
|
||||
if (recent_reddits) {
|
||||
createCookie(recent_cookie, recent_reddits);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
function subscribe(button, id) {
|
||||
if (!logged) return showcover();
|
||||
|
||||
var add_class = "sr-toggle-button add";
|
||||
var remove_class = "sr-toggle-button remove";
|
||||
|
||||
if (button.className == add_class) {
|
||||
action = 'sub';
|
||||
button.className = remove_class;
|
||||
set_score(id, 1);
|
||||
}
|
||||
else {
|
||||
action = 'unsub';
|
||||
button.className = add_class;
|
||||
set_score(id, 0);
|
||||
}
|
||||
redditRequest_no_response('subscribe',
|
||||
{'sr': id, 'action': action, 'uh': modhash});
|
||||
}
|
||||
|
||||
function Subreddit(id) { }
|
||||
Subreddit.prototype = new Thing();
|
||||
|
||||
|
||||
function map_links_by_sr(srid, func) {
|
||||
var chx = $("sr_sel_chx_" + srid);
|
||||
var count = 0;
|
||||
if (chx) { chx = chx.checked; }
|
||||
for (var s in sr) {
|
||||
if (sr[s] == srid) {
|
||||
func(new Link(s), chx);
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
var changed_srs = {};
|
||||
function change_sr(srid) {
|
||||
var chx = $("sr_sel_chx_" + srid);
|
||||
var srs_list = [];
|
||||
if (changed_srs[srid] == null) {
|
||||
changed_srs[srid] = chx.checked;
|
||||
} else {
|
||||
changed_srs[srid] = null;
|
||||
}
|
||||
var show_save = false;
|
||||
for(var x in changed_srs) {
|
||||
if (!(x in Object.prototype) && changed_srs[x] != null) {
|
||||
show_save = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (show_save) {
|
||||
show('subscr_sub');
|
||||
} else {
|
||||
hide('subscr_sub');
|
||||
}
|
||||
|
||||
if(chx.checked) {
|
||||
show_by_srid(srid, changed_srs);
|
||||
}
|
||||
else {
|
||||
hide_by_srid(srid, changed_srs);
|
||||
}
|
||||
var box = $("sr_sel_" + srid);
|
||||
box.className = (chx.checked && 'selected') || "";
|
||||
return true;
|
||||
}
|
||||
|
||||
function hide_by_srid(srid, sr_deltas) {
|
||||
var l = new Listing('');
|
||||
var res = map_links_by_sr(srid,
|
||||
function(link, checked) {
|
||||
if (link.row.parentNode == l.listing) {
|
||||
link.hide(true);
|
||||
}
|
||||
});
|
||||
|
||||
/*Listing.fetch_more(sr_deltas, null, res);*/
|
||||
}
|
||||
|
||||
function show_by_srid(srid, sr_deltas) {
|
||||
var l = new Listing('');
|
||||
var res = map_links_by_sr(srid,
|
||||
function(link, checked) {
|
||||
if (link.row.parentNode == l.listing) {
|
||||
link.show(true);
|
||||
}
|
||||
});
|
||||
if(!res) {
|
||||
Listing.fetch_more(sr_deltas, srid);
|
||||
}
|
||||
add_to_aniframes(function() {
|
||||
new Listing('').reset_visible_count();
|
||||
}, 1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
|
||||
function UserTable(name) {
|
||||
this.table = $(name);
|
||||
this.header = $(name+"_header");
|
||||
};
|
||||
|
||||
|
||||
UserTable.prototype = {
|
||||
_del_row: function(name) {
|
||||
var row = this.table.rows.namedItem(name);
|
||||
if(row) {
|
||||
this.table.deleteRow(row.rowIndex);
|
||||
}
|
||||
},
|
||||
|
||||
_new_row: function(name, cellinnards, pos) {
|
||||
if(!pos) { pos = 0; }
|
||||
var row = this.table.insertRow(pos);
|
||||
hide(row);
|
||||
row.id = name;
|
||||
if(row) {
|
||||
for(var i = 0; i < cellinnards.length; i++) {
|
||||
var cell = row.insertCell(row.cells.length);
|
||||
cell.innerHTML = unsafe(cellinnards[i]);
|
||||
}
|
||||
}
|
||||
show(row);
|
||||
}
|
||||
};
|
||||
|
||||
UserTable.findTable = function(rowname) {
|
||||
var row = $(rowname);
|
||||
var ut = new UserTable(row.parentNode.parentNode.id);
|
||||
return ut;
|
||||
};
|
||||
|
||||
UserTable.getUser = function(name) {
|
||||
return name.split('_')[1];
|
||||
}
|
||||
|
||||
UserTable.add = function(r) {
|
||||
var table = new UserTable(r.id);
|
||||
table._new_row(r.name, r.cells);
|
||||
show(table.header);
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
UserTable.delRow = function(name) {
|
||||
var table = UserTable.findTable(name);
|
||||
table._del_row(name);
|
||||
if (table.table.rows.length == 0) {
|
||||
hide(table.header);
|
||||
}
|
||||
return table;
|
||||
};
|
||||
|
||||
|
||||
UserTable.del = function(type, container_name) {
|
||||
var f = function(name, uh) {
|
||||
var table = UserTable.delRow(name);
|
||||
redditRequest("friend", {name: UserTable.getUser(name),
|
||||
action: 'remove', container: container_name,
|
||||
type: type, uh: uh});
|
||||
};
|
||||
return f;
|
||||
};
|
||||
|
||||
class_dict["UserTable"] = UserTable;
|
||||
|
||||
@@ -1,607 +0,0 @@
|
||||
function unsafe(text) {
|
||||
text = text.replace?text:"";
|
||||
return text.replace(/>/g, ">").replace(/</g, "<").replace(/&/g, "&");
|
||||
}
|
||||
|
||||
|
||||
function hide () {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var e = $(arguments[i]);
|
||||
if (e) e.style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
function show () {
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
var e = $(arguments[i]);
|
||||
if (e) e.style.display = "";
|
||||
}
|
||||
}
|
||||
|
||||
Object.prototype.__iter__ = function(func) {
|
||||
var res = [];
|
||||
for(var o in this) {
|
||||
if(!(o in Object.prototype)) {
|
||||
res.unshift(func(o, this[o]));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
};
|
||||
|
||||
function make_get_params(obj) {
|
||||
return obj.__iter__(function(x, y) {
|
||||
return x + "=" + encodeURIComponent(y);
|
||||
}).join("&");
|
||||
}
|
||||
|
||||
function update_get_params(updates) {
|
||||
var getparams = {};
|
||||
where.params.__iter__(function(x, y) {
|
||||
getparams[x] = y;
|
||||
});
|
||||
if (updates)
|
||||
updates.__iter__(function(x, y) {
|
||||
getparams[x] = y;
|
||||
});
|
||||
return getparams;
|
||||
}
|
||||
|
||||
/* where is global */
|
||||
function relative_path(updates) {
|
||||
var getparams = update_get_params(updates);
|
||||
path = where.path;
|
||||
if(getparams) {
|
||||
path += "?" + make_get_params(getparams);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
function _id(obj) {
|
||||
if(obj && obj.id) {
|
||||
var id = obj.id;
|
||||
if(id.value) {id = id.value};
|
||||
id = id.split('_');
|
||||
if (id.length > 2) {
|
||||
id = id[id.length-2] + '_' + id[id.length-1];
|
||||
if(id == null) {return '';}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function buildParams(parameters) {
|
||||
if(parameters) {
|
||||
try {
|
||||
var p = new Array();
|
||||
for(var i = 0; i+1 < parameters.length; i += 2) {
|
||||
p.push(parameters[i] + '=' + encodeURIComponent(parameters[i+1]));
|
||||
}
|
||||
parameters = p.join('&');
|
||||
} catch(e) {
|
||||
parameters = '';
|
||||
alert(e);
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
var api_loc = '/api/';
|
||||
function redditRequest(op, parameters, worker_in, block) {
|
||||
var action = op;
|
||||
var worker = worker_in;
|
||||
if (!parameters) {
|
||||
parameters = {};
|
||||
}
|
||||
if (post_site) {
|
||||
parameters.r = post_site;
|
||||
}
|
||||
if (cnameframe) {
|
||||
parameters.cnameframe = 1;
|
||||
}
|
||||
op = api_loc + op;
|
||||
if(!worker) {
|
||||
worker = handleResponse(action);
|
||||
}
|
||||
else {
|
||||
worker = function(r) {
|
||||
remove_ajax_work(action);
|
||||
return worker_in(r);
|
||||
}
|
||||
}
|
||||
if(block == null || add_ajax_work(action)) {
|
||||
new Ajax.Request(op, {parameters: make_get_params(parameters),
|
||||
onComplete: worker});
|
||||
}
|
||||
}
|
||||
|
||||
var _ajax_work_queue = {};
|
||||
function add_ajax_work(op) {
|
||||
if(_ajax_work_queue[op]) {
|
||||
return false;
|
||||
}
|
||||
_ajax_work_queue[op] = true;
|
||||
return true;
|
||||
}
|
||||
function remove_ajax_work(op) {
|
||||
_ajax_work_queue[op] = false;
|
||||
}
|
||||
|
||||
function redditRequest_no_response(op, parameters) {
|
||||
redditRequest(op, parameters, function(r){});
|
||||
}
|
||||
|
||||
function get_class_from_id(id) {
|
||||
if(id) {
|
||||
id = id.split('_')[0];
|
||||
return class_dict[id];
|
||||
}
|
||||
}
|
||||
|
||||
function parse_response(r) {
|
||||
if(r.status == 500) return;
|
||||
return r.responseText.parseJSON();
|
||||
}
|
||||
|
||||
function tup(x) {
|
||||
if(! x.length ) { return [x] };
|
||||
return x;
|
||||
}
|
||||
|
||||
function applyStylesheet(cssText) {
|
||||
/* also referred to in the reddit.html template, for the name of the
|
||||
stylesheet set for this reddit. These must be in sync, because
|
||||
I'm over-writing it here */
|
||||
var sheet_title = 'applied_subreddit_stylesheet';
|
||||
|
||||
if(document.styleSheets[0].cssText) {
|
||||
/* of course IE has to do this differently from everyone else. */
|
||||
for(var x=0; x < document.styleSheets.length; x++) {
|
||||
if(document.styleSheets[x].title == sheet_title) {
|
||||
document.styleSheets[x].cssText = cssText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* for everyone else, we walk <head> for the <link> or <style>
|
||||
that has the old stylesheet, and delete it. Then we add a
|
||||
<style> with the new one */
|
||||
var headNode = document.getElementsByTagName("head")[0];
|
||||
var headNodes = headNode.childNodes;
|
||||
|
||||
for(var x=0; x < headNodes.length; x++) {
|
||||
var node = headNodes[x];
|
||||
|
||||
if(node.title == sheet_title) {
|
||||
headNode.removeChild(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var appliedCSSNode = document.createElement('style');
|
||||
appliedCSSNode.type = 'text/css';
|
||||
appliedCSSNode.rel = 'stylesheet';
|
||||
appliedCSSNode.media = 'screen';
|
||||
appliedCSSNode.title = sheet_title;
|
||||
|
||||
appliedCSSNode.textContent = cssText;
|
||||
|
||||
headNode.appendChild(appliedCSSNode);
|
||||
}
|
||||
}
|
||||
|
||||
function showDefaultStylesheet() {
|
||||
return toggleDefaultStylesheet(true);
|
||||
}
|
||||
function hideDefaultStylesheet() {
|
||||
return toggleDefaultStylesheet(false);
|
||||
}
|
||||
function toggleDefaultStylesheet(p_show) {
|
||||
var stylesheet_contents = $('stylesheet_contents').parentNode.parentNode;
|
||||
var default_stylesheet = $('default_stylesheet').parentNode.parentNode;
|
||||
|
||||
var show_button = $('show_default_stylesheet');
|
||||
var hide_button = $('hide_default_stylesheet');
|
||||
|
||||
if(p_show) {
|
||||
default_stylesheet.style.width = "50%";
|
||||
stylesheet_contents.style.width = "50%";
|
||||
show(default_stylesheet, hide_button);
|
||||
hide(show_button);
|
||||
} else {
|
||||
stylesheet_contents.style.width = "100%";
|
||||
default_stylesheet.style.width = "";
|
||||
show(show_button);
|
||||
hide(default_stylesheet, hide_button);
|
||||
}
|
||||
|
||||
return false; // don't post the form
|
||||
}
|
||||
|
||||
function gotoTextboxLine(textboxID, lineNo) {
|
||||
var textbox = $(textboxID);
|
||||
var text = textbox.value;
|
||||
|
||||
var newline = '\n';
|
||||
var newline_length = 1;
|
||||
var caret_pos = 0;
|
||||
|
||||
if ( text.indexOf('\r') > 0) {
|
||||
/* IE hack */
|
||||
newline = '\r';
|
||||
newline_length = 0;
|
||||
caret_pos = 1;
|
||||
}
|
||||
|
||||
var lines = textbox.value.split(newline);
|
||||
|
||||
for(var x=0; x<lineNo-1; x++) {
|
||||
caret_pos += lines[x].length + newline_length;
|
||||
}
|
||||
var end_pos = caret_pos;
|
||||
if (lineNo < lines.length) {
|
||||
end_pos += lines[lineNo-1].length + newline_length;
|
||||
}
|
||||
|
||||
|
||||
textbox.focus();
|
||||
if(textbox.createTextRange) { /* IE */
|
||||
var start = textbox.createTextRange();
|
||||
start.move('character', caret_pos);
|
||||
var end = textbox.createTextRange();
|
||||
end.move('character', end_pos);
|
||||
start.setEndPoint("StartToEnd", end);
|
||||
start.select();
|
||||
} else if (textbox.selectionStart) {
|
||||
textbox.setSelectionRange(caret_pos, end_pos);
|
||||
}
|
||||
|
||||
if(textbox.scrollHeight) {
|
||||
var avgLineHight = textbox.scrollHeight / lines.length;
|
||||
textbox.scrollTop = (lineNo-2) * avgLineHight;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function insertAtCursor(textbox, value) {
|
||||
textbox = $(textbox);
|
||||
var orig_pos = textbox.scrollTop;
|
||||
|
||||
if (document.selection) { /* IE */
|
||||
textbox.focus();
|
||||
var sel = document.selection.createRange();
|
||||
sel.text = value;
|
||||
}
|
||||
else if (textbox.selectionStart) {
|
||||
var prev_start = textbox.selectionStart;
|
||||
textbox.value =
|
||||
textbox.value.substring(0, textbox.selectionStart) +
|
||||
value +
|
||||
textbox.value.substring(textbox.selectionEnd, textbox.value.length);
|
||||
prev_start += value.length;
|
||||
textbox.setSelectionRange(prev_start, prev_start);
|
||||
} else {
|
||||
textbox.value += value;
|
||||
}
|
||||
|
||||
if(textbox.scrollHeight) {
|
||||
textbox.scrollTop = orig_pos;
|
||||
}
|
||||
|
||||
textbox.focus();
|
||||
}
|
||||
|
||||
|
||||
|
||||
function upload_image(form, status) {
|
||||
$('img-status').innerHTML = status;
|
||||
show('img-status');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
function completedUploadImage(status, img_src, name, errors) {
|
||||
show('img-status');
|
||||
$('img-status').innerHTML = status;
|
||||
for(var i = 0; i < errors.length; i++) {
|
||||
var e = $(errors[i][0]);
|
||||
if( errors[i][1]) {
|
||||
show(e);
|
||||
e.innerHTML = errors[i][1];
|
||||
}
|
||||
else {
|
||||
hide(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(img_src) {
|
||||
$('image-upload').reset();
|
||||
hide('submit-header-img');
|
||||
if (!name) {
|
||||
$('header-img').src = img_src;
|
||||
$('img-preview').src = img_src;
|
||||
show('delete-img');
|
||||
hide('submit-img');
|
||||
show('img-preview-container');
|
||||
} else {
|
||||
var img = $("img-preview_" + name);
|
||||
if(img) {
|
||||
/* Because IE isn't smart enought to eval "!img" */
|
||||
}
|
||||
else {
|
||||
var ul = $("image-preview-list");
|
||||
var li = $("img-prototype").cloneNode(true);
|
||||
li.id = "img-li_";
|
||||
ul.appendChild(li);
|
||||
re_id_node(li, ''+name);
|
||||
var name_b = $("img_name_" + name);
|
||||
if(name_b) {
|
||||
name_b.innerHTML = name;
|
||||
}
|
||||
var label = $("img_url_" + name);
|
||||
if(label) {
|
||||
label.innerHTML = "url(%%" + name + "%%)";
|
||||
}
|
||||
img = $("img-preview_" + name);
|
||||
|
||||
var sel_list = $('old-names');
|
||||
if (sel_list) {
|
||||
var opt = document.createElement('option');
|
||||
opt.innerHTML = name;
|
||||
sel_list.appendChild(opt);
|
||||
}
|
||||
}
|
||||
img.src = img_src;
|
||||
$("img-preview-a_" + name).href = img_src;
|
||||
show("img-li_" + name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function handleResponse(action) {
|
||||
var my_iter = function(x, func) {
|
||||
if(x) {
|
||||
var y = tup(x);
|
||||
for(var j = 0; j < y.length; j++) {
|
||||
func(y[j]);
|
||||
}
|
||||
}
|
||||
};
|
||||
var responseHandler = function(r) {
|
||||
remove_ajax_work(action);
|
||||
var res_obj = parse_response(r);
|
||||
if(!res_obj) {
|
||||
if($('status'))
|
||||
$('status').innerHTML = '';
|
||||
return;
|
||||
}
|
||||
// first thing to check is if a redirect has been requested
|
||||
if(res_obj.redirect) {
|
||||
window.location = unsafe(res_obj.redirect);
|
||||
return;
|
||||
}
|
||||
// next check for errors
|
||||
var error = res_obj.error;
|
||||
if(error && error.name) {
|
||||
var errid = error.name;
|
||||
if (error.id) { errid += "_" + error.id; }
|
||||
errid = $(errid);
|
||||
if (errid) {
|
||||
show(errid);
|
||||
$(errid).innerHTML = error.message;
|
||||
}
|
||||
}
|
||||
var r = res_obj.response;
|
||||
if(!r) return;
|
||||
var obj = r.object;
|
||||
if(obj) {
|
||||
my_iter(tup(obj),
|
||||
function(u) {
|
||||
if(u && u.kind && class_dict[u.kind]) {
|
||||
var func = (class_dict[u.kind][u.action] ||
|
||||
class_dict[u.kind][action]);
|
||||
if(func) {
|
||||
func(u.data);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// handle applied CSS
|
||||
if(r.call) {
|
||||
var calls = r.call;
|
||||
for(var i=0; i<calls.length; i++) {
|
||||
eval(calls[i]);
|
||||
}
|
||||
}
|
||||
// handle shifts of focus
|
||||
if (r.focus) {
|
||||
var f = $(r.focus);
|
||||
if(f) {f.focus();
|
||||
f.onfocus = null;}
|
||||
}
|
||||
if (r.blur) {
|
||||
var f = $(r.blur);
|
||||
if(f) {f.blur();
|
||||
f.onblur = null;}
|
||||
}
|
||||
if (r.captcha) {
|
||||
if (r.captcha.refresh) {
|
||||
var id = r.captcha.id;
|
||||
var captcha = $("capimage" + (id?('_'+id):''));
|
||||
var capiden = $("capiden" + (id?('_'+id):''));
|
||||
capiden.value = r.captcha.iden;
|
||||
captcha.src = ("/captcha/" + r.captcha.iden + ".png?" +
|
||||
Math.random())
|
||||
}
|
||||
}
|
||||
if (r.success) {
|
||||
fire_success();
|
||||
}
|
||||
my_iter(r.update,
|
||||
function(u) {
|
||||
var field = u.id && $(u.id);
|
||||
if(field) {
|
||||
for(var i in u) {
|
||||
if(typeof(u[i]) != "function" && u != 'name') {
|
||||
field[i] = unsafe(u[i]);
|
||||
}
|
||||
} }});
|
||||
my_iter(r.hide,
|
||||
function(h) {
|
||||
var field = h.name && $(h.name);
|
||||
if(field) { hide(field); }});
|
||||
my_iter(r.show,
|
||||
function(h) {
|
||||
var field = h.name && $(h.name);
|
||||
if(field) { show(field); }});
|
||||
};
|
||||
return responseHandler;
|
||||
}
|
||||
|
||||
function re_id_node(node, id) {
|
||||
function add_id(s) {
|
||||
if(id && s && typeof(s) == "string") {
|
||||
if(s.substr(s.length-1) != '_') s += '_';
|
||||
s += id;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
if(node.id && typeof(node.id) == "string") { node.id = add_id(node.id); }
|
||||
if(node.htmlFor) { add_id(node.htmlFor); }
|
||||
var children = node.childNodes;
|
||||
for(var i = 0; i < children.length; i++) {
|
||||
re_id_node(children[i], id);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
function Thing(id) {
|
||||
this.__init__(id);
|
||||
};
|
||||
|
||||
function field(form_field) {
|
||||
if (form_field == null || form_field.value == null ||
|
||||
((form_field.type == 'text' || form_field.type == 'textarea')
|
||||
&& form_field.style.color == "gray") ||
|
||||
(form_field.type == 'radio' && ! form_field.checked)) {
|
||||
return '';
|
||||
}
|
||||
else if (form_field.type == 'checkbox') {
|
||||
return form_field.checked?'on':'off';
|
||||
}
|
||||
return form_field.value;
|
||||
}
|
||||
|
||||
function change_w_callback(link, func) {
|
||||
var parent = link.parentNode;
|
||||
var form = parent.parentNode;
|
||||
var id = form.id.value;
|
||||
link.blur();
|
||||
var executed = document.createElement('span');
|
||||
executed.innerHTML = form.executed.value;
|
||||
parent.insertBefore(executed, link);
|
||||
hide(link);
|
||||
func(id);
|
||||
return false;
|
||||
}
|
||||
|
||||
function change_state(link, type) {
|
||||
change_w_callback(link, function(id) {
|
||||
redditRequest(type, {id: id, uh:modhash});
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function post_form(form, where, statusfunc, nametransformfunc, block) {
|
||||
var p = {uh: modhash};
|
||||
var id = _id(form);
|
||||
var status = $("status");
|
||||
|
||||
if(statusfunc == null) {
|
||||
statusfunc = function(x) { return _global_submitting_tag; };
|
||||
}
|
||||
if(nametransformfunc == null) {
|
||||
nametransformfunc = function(x) {return x;}
|
||||
}
|
||||
if(id) {
|
||||
status = $("status_" + id);
|
||||
p.id = id;
|
||||
}
|
||||
if(status) { status.innerHTML = statusfunc(form); }
|
||||
for(var i = 0; i < form.elements.length; i++) {
|
||||
if(! form.elements[i].id || !id ||
|
||||
_id(form.elements[i]) == id) {
|
||||
var f = field(form.elements[i]);
|
||||
if (f) {
|
||||
p[nametransformfunc(form.elements[i].name)] = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
redditRequest(where, p, null, block);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Used in submitted form rendering to allow for an empty field
|
||||
// when no JS is present, but some greyed text otherwise.
|
||||
function setMessage(field, msg) {
|
||||
if (! field.value || field.value == msg ) {
|
||||
field.value = msg;
|
||||
field.style.color = "gray";
|
||||
}
|
||||
else {
|
||||
field.onfocus = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function more(a_tag, new_label, div_on, div_off) {
|
||||
var old_label = a_tag.innerHTML;
|
||||
a_tag.innerHTML = new_label;
|
||||
var i;
|
||||
for(i = 0; i < div_on.length; i++) { show(div_on[i]); }
|
||||
for(i = 0; i < div_off.length; i++) { hide(div_off[i]); }
|
||||
a_tag.onclick = function() {
|
||||
return more(a_tag, old_label, div_off, div_on);
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
function new_captcha() {
|
||||
redditRequest("new_captcha");
|
||||
}
|
||||
|
||||
function view_embeded_media(id, media_link) {
|
||||
var eid = "embeded_media_" + id;
|
||||
var watchid = "view_embeded_media_span_watch_" + id;
|
||||
var closeid = "view_embeded_media_span_close_" + id;
|
||||
var watchspan = document.getElementById(watchid);
|
||||
var closespan = document.getElementById(closeid);
|
||||
var e = document.getElementById(eid);
|
||||
if (e.style.display == "none") {
|
||||
e.style.display = "block";
|
||||
e.innerHTML = media_link;
|
||||
watchspan.style.display = "none";
|
||||
closespan.style.display = "inline";
|
||||
} else {
|
||||
e.style.display = "none";
|
||||
watchspan.style.display = "inline";
|
||||
closespan.style.display = "none";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function show_hide_child(el, tagName, label) {
|
||||
code_block = el.parentNode.getElementsByTagName(tagName)[0];
|
||||
if (code_block.style.display == "none") {
|
||||
show(code_block);
|
||||
el.innerHTML = 'hide ' + label;
|
||||
} else if (code_block.style.display == "") {
|
||||
hide(code_block);
|
||||
el.innerHTML = 'view ' + label;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
var upm = "arrow upmod";
|
||||
var upr = "arrow up";
|
||||
var downm = "arrow downmod";
|
||||
var downr = "arrow down";
|
||||
|
||||
var upcls = [upr, upr, upm ];
|
||||
var downcls = [downm, downr, downr];
|
||||
var scorecls = ["score dislikes", "score", "score likes"];
|
||||
|
||||
|
||||
//cookie setting junk
|
||||
function cookieName(name) {
|
||||
return (logged || '') + "_" + name;
|
||||
}
|
||||
|
||||
function createLCookie(name,value,days) {
|
||||
var domain = "; domain=" + cur_domain;
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime()+(days*24*60*60*1000));
|
||||
var expires="; expires="+date.toGMTString();
|
||||
}
|
||||
else expires="";
|
||||
document.cookie=name+"="+ escape(value) +expires+domain+"; path=/";
|
||||
}
|
||||
|
||||
function createCookie(name, value, days) {
|
||||
return createLCookie(cookieName(name), value, days);
|
||||
}
|
||||
|
||||
function readLCookie(nameEQ) {
|
||||
nameEQ=nameEQ+'=';
|
||||
var ca=document.cookie.split(';');
|
||||
/* walk the list backwards so we always get the last cookie in the
|
||||
list */
|
||||
for(var i = ca.length-1; i >= 0; i--) {
|
||||
var c = ca[i];
|
||||
while(c.charAt(0)==' ') c=c.substring(1,c.length);
|
||||
if(c.indexOf(nameEQ)==0) {
|
||||
/* we can unescape even if it's not escaped */
|
||||
return unescape(c.substring(nameEQ.length,c.length));
|
||||
}
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
function readCookie(name) {
|
||||
var nameEQ=cookieName(name);
|
||||
return readLCookie(nameEQ);
|
||||
}
|
||||
|
||||
/*function setModCookie(id, c) {
|
||||
createCookie("mod", readCookie("mod") + id + "=" + c + ":");
|
||||
}*/
|
||||
|
||||
function set_score(id, dir)
|
||||
{
|
||||
var label = vl[id];
|
||||
var score = $("score_" + id);
|
||||
if(score) {
|
||||
score.className = scorecls[dir+1];
|
||||
score.innerHTML = label [dir+1];
|
||||
}
|
||||
}
|
||||
|
||||
function mod(id, uc, vh) {
|
||||
if (vh == null) vh = '';
|
||||
|
||||
//logged is global
|
||||
var up = $("up_" + id);
|
||||
var down = $("down_" + id);
|
||||
var dir = -1;
|
||||
|
||||
if (uc && up.className == upm || !uc && down.className == downm) {
|
||||
dir = 0;
|
||||
}
|
||||
else if (uc) {
|
||||
dir = 1;
|
||||
}
|
||||
|
||||
if (logged) {
|
||||
redditRequest_no_response('vote', {id: id, uh: modhash, dir: dir, vh: vh});
|
||||
}
|
||||
|
||||
up.className = upcls [dir+1];
|
||||
down.className = downcls [dir+1];
|
||||
set_score(id, dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user