mirror of
https://github.com/WhatCD/Gazelle.git
synced 2024-12-14 19:36:25 +00:00
6273679d49
fix typo I introduced in schedule.php Print to LAB_CHAN if sphinx connection fails nice bitcoin display Corrects [#] tag for Mono [hateradio] bitcoin donation Fix torrent unbookmarking upgraded sphinxapi.php to r2876 as the site is running r2902 Added options to block Tor, Opera Turbo and Opera Mini check for stale cache vanity house [clone00] bookmark almost anything [patapper] new torrent edit flags [rattvis] permissions stuff from patappatch c [BBCode] new [important] tag [DutchDude] Fixed images flowing past their boxes [hateradio] [BBCode] Tag for ordered lists. [hateradio] finally fixed that annoying textarea-resizing thing renamed temporary tables fixes http://what.cd/forums.php?action=viewthread&threadid=137432&page=1#post3408738 implements http://what.cd/forums.php?action=viewthread&threadid=122832 fixes http://what.cd/forums.php?action=viewthread&threadid=136553 fixes http://what.cd/forums.php?action=viewthread&threadid=112967 implements http://what.cd/forums.php?action=viewthread&threadid=110395
143 lines
4.1 KiB
JavaScript
143 lines
4.1 KiB
JavaScript
/*
|
|
TODO: Further optimize serialize function
|
|
|
|
UPDATE: We were forced to create an individual XHR for each request
|
|
to avoid race conditions on slower browsers where the request would
|
|
be overwritten before the callback triggered, and leave it hanging.
|
|
This only happened in FF3.0 that we tested.
|
|
|
|
Example usage 1:
|
|
ajax.handle = function () {
|
|
$('#preview' + postid).raw().innerHTML = ajax.response;
|
|
$('#editbox' + postid).hide();
|
|
}
|
|
ajax.post("ajax.php?action=preview","#form-id" + postid);
|
|
|
|
Example usage 2:
|
|
ajax.handle = function() {
|
|
$('#quickpost').raw().value = "[quote="+username+"]" + ajax.response + "[/quote]";
|
|
}
|
|
ajax.get("?action=get_post&post=" + postid);
|
|
|
|
*/
|
|
"use strict";
|
|
var json = {
|
|
encode: function (object) {
|
|
try {
|
|
return JSON.stringify(object);
|
|
} catch (err) {
|
|
return '';
|
|
}
|
|
},
|
|
decode: function (string) {
|
|
if (window.JSON && JSON.parse) {
|
|
return JSON.parse(string);
|
|
} else {
|
|
return eval("(" + string + ")");
|
|
//return (new Function("return " + data))();
|
|
}
|
|
}
|
|
};
|
|
|
|
var ajax = {
|
|
get: function (url, callback) {
|
|
var req = (typeof(window.ActiveXObject) === 'undefined') ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
|
|
if (callback !== undefined) {
|
|
req.onreadystatechange = function () {
|
|
if (req.readyState !== 4 || req.status !== 200) {
|
|
return;
|
|
}
|
|
callback(req.responseText);
|
|
};
|
|
}
|
|
req.open("GET", url, true);
|
|
req.send(null);
|
|
},
|
|
post: function (url, data, callback) {
|
|
var req = isset(window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
|
|
var params = ajax.serialize(data);
|
|
if (callback !== undefined) {
|
|
req.onreadystatechange = function () {
|
|
if (req.readyState !== 4 || req.status !== 200) {
|
|
return;
|
|
}
|
|
callback(req.responseText);
|
|
};
|
|
}
|
|
req.open('POST', url, true);
|
|
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
req.send(params);
|
|
},
|
|
serialize: function (data) {
|
|
var query = '',
|
|
elements;
|
|
if (is_array(data)) {
|
|
for (var key in data) {
|
|
query += key + '=' + encodeURIComponent(data[key]) + '&';
|
|
}
|
|
} else {
|
|
elements = document.getElementById(data).elements;
|
|
for (var i = 0, il = elements.length; i < il; i++) {
|
|
var element = elements[i];
|
|
if (!isset(element) || element.disabled || element.name === '') {
|
|
continue;
|
|
}
|
|
switch (element.type) {
|
|
case 'text':
|
|
case 'hidden':
|
|
case 'password':
|
|
case 'textarea':
|
|
case 'select-one':
|
|
query += element.name + '=' + encodeURIComponent(element.value) + '&';
|
|
break;
|
|
case 'select-multiple':
|
|
for (var j = 0, jl = element.options.length; j < jl; j++) {
|
|
var current = element.options[j];
|
|
if (current.selected) {
|
|
query += element.name + '=' + encodeURIComponent(current.value) + '&';
|
|
}
|
|
}
|
|
break;
|
|
case 'radio':
|
|
if (element.checked) {
|
|
query += element.name + '=' + encodeURIComponent(element.value) + '&';
|
|
}
|
|
break;
|
|
case 'checkbox':
|
|
if (element.checked) {
|
|
query += element.name + '=' + encodeURIComponent(element.value) + '&';
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return query.substr(0, query.length - 1);
|
|
}
|
|
};
|
|
//Bookmarks
|
|
function Bookmark(type, id, newName) {
|
|
var lnk = $('#bookmarklink_' + type + '_' + id).raw();
|
|
var oldName = lnk.innerHTML;
|
|
ajax.get("bookmarks.php?action=add&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
|
|
lnk.onclick = function() { Unbookmark(type, id, oldName); return false; };
|
|
lnk.innerHTML = newName;
|
|
});
|
|
}
|
|
|
|
function Unbookmark(type, id, newName) {
|
|
if(window.location.pathname.indexOf('bookmarks.php') != -1) {
|
|
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
|
|
$('#group_' + id).remove();
|
|
$('.groupid_' + id).remove();
|
|
$('.bookmark_' + id).remove();
|
|
});
|
|
} else {
|
|
var lnk = $('#bookmarklink_' + type + '_' + id).raw();
|
|
var oldName = lnk.innerHTML;
|
|
ajax.get("bookmarks.php?action=remove&type=" + type + "&auth=" + authkey + "&id=" + id, function() {
|
|
lnk.onclick = function() { Bookmark(type, id, oldName); return false; };
|
|
lnk.innerHTML = newName;
|
|
});
|
|
}
|
|
}
|