Guest User

Untitled

a guest
Jul 21st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.34 KB | None | 0 0
  1. var TW = Class.create();
  2.  
  3. TW.prototype = {
  4. initialize: function () {
  5. this._waiting = new Array();
  6. this._forumNewsSeen = new Array();
  7. this._forumNewsSeen[0] = 0;
  8. this._forumNewsId = 0;
  9. },
  10.  
  11. setWaiting: function (id, len) {
  12. this._waiting[id] = 1;
  13. if (len) window.setTimeout(this.clearWaiting.bind(this, id), len);
  14. },
  15.  
  16. clearWaiting: function (id) {
  17. this._waiting[id] = 0;
  18. },
  19.  
  20. isWaiting: function (id) {
  21. return this._waiting[id];
  22. },
  23.  
  24. keepWaiting: function (fn) {
  25. window.setTimeout(fn, 500);
  26. },
  27.  
  28. // Ajax stuff
  29. Ajax: Object.extend(new Object(), {
  30.  
  31. checkMessageBox: function (t) {
  32. if (t.action && t.action == 'msgbox') {
  33. twmsgbox.show(t.title, t.msg);
  34. return true;
  35. }
  36. return false;
  37. },
  38.  
  39. postComment: function () {
  40. var c = $F('newscomment');
  41. if (c.length == 0) {
  42. twmsgbox.show("No Comment", "You did not enter a comment");
  43. return;
  44. }
  45.  
  46. $('commentbtn').disabled = true;
  47.  
  48. var qid = $F('quoteid');
  49. var nid = $F('newsid');
  50. var pg = $F('page');
  51.  
  52. var query = $H({
  53. quoteid: qid,
  54. newsid: nid,
  55. comment: c,
  56. page: pg,
  57. action: 'addcomment'
  58. });
  59.  
  60. new Ajax.Request(baseurl + '/ajax/news.php', {
  61. method: 'post',
  62. parameters: query,
  63. onSuccess: this.donePostComment.bindAsEventListener(this),
  64. onFail: function () {
  65. twmsgbox.show("Failed Posting", "The post failed");
  66. $('commentbtn').disabled = false;
  67. }
  68. });
  69. },
  70.  
  71. donePostComment: function (r) {
  72. t = r.responseText.parseJSON();
  73. //if (t.action && t.action == 'msgbox') {
  74. //twmsgbox.show(t.title, t.msg);
  75. // return;
  76. //}
  77. if (this.checkMessageBox(t)) {
  78. return;
  79. }
  80.  
  81. if (t.newurl) {
  82. window.location = t.newurl;
  83. return;
  84. }
  85.  
  86. $('comcon').innerHTML = t.html;
  87. $('post' + t.postid).scrollIntoView();
  88.  
  89. },
  90.  
  91. deleteComment: function (pid) {
  92. var query = $H({
  93. postid: pid,
  94. action: 'deletecomment'
  95. });
  96. this.deleteid = pid;
  97.  
  98. new Ajax.Request(baseurl + '/ajax/news.php', {
  99. method: 'post',
  100. parameters: query,
  101. onSuccess: this.doneDeleteComment.bindAsEventListener(this),
  102. onFail: function () {
  103. twmsgbox.show("Failed", "Delete Action Failed");
  104. }
  105. });
  106.  
  107. },
  108.  
  109. doneDeleteComment: function (r) {
  110. t = r.responseText.parseJSON();
  111. if (t.type == "ok") {
  112. if ($('cbody' + this.deleteid)) {
  113. Effect.BlindUp('cbody' + this.deleteid);
  114. }
  115. }
  116.  
  117. twmsgbox.show(t.title, t.msg);
  118. },
  119.  
  120. showBumpers: function (nid, pg, fr) {
  121. var query = $H({
  122. newsid: nid,
  123. page: pg,
  124. friends: fr,
  125. action: 'showbumpers2'
  126. });
  127.  
  128. new Ajax.Request(baseurl + '/ajax/news.php', {
  129. method: 'post',
  130. parameters: query,
  131. onSuccess: this.doneShowBumpers.bindAsEventListener(this),
  132. onFail: function () {
  133. twmsgbox.show("Failed", "Failed to go to page " + pg);
  134. }
  135. });
  136.  
  137. },
  138.  
  139. doneShowBumpers: function (r) {
  140. var t = r.responseText.parseJSON();
  141. if (this.checkMessageBox(t)) {
  142. return;
  143. }
  144.  
  145. $('bumperslist').innerHTML = t.bumperslist;
  146. $('bumppagenav').innerHTML = t.pagenav;
  147. },
  148.  
  149. voteQuoteUp: function (id) {
  150. new Effect.Fade($('quote' + id));
  151.  
  152. var query = $H({
  153. quoteid: id,
  154. action: 'voteup'
  155. });
  156.  
  157. new Ajax.Request(baseurl + '/ajax/quotes.php', {
  158. method: 'post',
  159. parameters: query,
  160. onSuccess: this.doneQuoteVote.bindAsEventListener(this),
  161. onFail: function () {
  162. twmsgbox.show("Failed", "Your vote failed. You Suck");
  163. }
  164. });
  165.  
  166. },
  167.  
  168. voteQuoteDown: function (id) {
  169. new Effect.Fade($('quote' + id));
  170.  
  171. var query = $H({
  172. quoteid: id,
  173. action: 'votedown'
  174. });
  175.  
  176. new Ajax.Request(baseurl + '/ajax/quotes.php', {
  177. method: 'post',
  178. parameters: query,
  179. onSuccess: this.doneQuoteVote.bindAsEventListener(this),
  180. onFail: function () {
  181. twmsgbox.show("Failed", "Your vote failed. You Suck");
  182. }
  183. });
  184. },
  185.  
  186. doneQuoteVote: function (r) {
  187. var t = r.responseText.parseJSON();
  188. if (this.checkMessageBox(t)) {
  189. return;
  190. }
  191.  
  192. new Insertion.Bottom('quotelist', t.newquote);
  193. $('userquotecount').innerHTML = t.usercount;
  194. new Effect.Appear($('quote' + t.quoteid));
  195. },
  196.  
  197. getNewQuotes: function () {
  198. var divs = $('quotelist').descendants();
  199. var x;
  200. //for (x=0; x < divs.length; x++) {
  201. // new Effect.Fade(divs[x]);
  202. //}
  203. $('quotelist').innerHTML = '';
  204.  
  205. var query = $H({
  206. action: 'getnewquotes'
  207. });
  208. new Ajax.Request(baseurl + '/ajax/quotes.php', {
  209. method: 'post',
  210. parameters: query,
  211. onSuccess: this.doneGetNewQuotes.bindAsEventListener(this),
  212. onFail: function () {
  213. twmsgbox.show("Failed", "You suck at getting new quotes");
  214. }
  215. });
  216.  
  217. },
  218.  
  219. doneGetNewQuotes: function (r) {
  220. var t = r.responseText.parseJSON();
  221. if (this.checkMessageBox(t)) {
  222. return;
  223. }
  224.  
  225. new Insertion.Bottom('quotelist', t.newquote);
  226.  
  227. var divs = $('quotelist').descendants();
  228. var x;
  229. for (x = 0; x < divs.length; x++) {
  230. new Effect.Appear(divs[x]);
  231. }
  232.  
  233. },
  234.  
  235. submitQuote: function () {
  236. var query = $H({
  237. action: 'submitquote',
  238. quote: $('newquote').value
  239. });
  240. new Ajax.Request(baseurl + '/ajax/quotes.php', {
  241. method: 'post',
  242. parameters: query,
  243. onSuccess: this.doneSubmitQuote.bindAsEventListener(this),
  244. onFail: function () {
  245. twmsgbox.show("Failed", "Your submission failed. You Suck");
  246. }
  247. });
  248.  
  249. },
  250.  
  251. doneSubmitQuote: function (r) {
  252. var t = r.responseText.parseJSON();
  253. if (this.checkMessageBox(t)) {
  254. if (t.msg.match('submitted')) {
  255. $('newquote').value = "";
  256. }
  257.  
  258. return;
  259. }
  260.  
  261. },
  262.  
  263. getRSSNews: function (id) {
  264. var query = $H({
  265. action: 'getrssnews',
  266. rssnewsid: id
  267. });
  268. new Ajax.Request(baseurl + '/ajax/admin_news.php', {
  269. method: 'post',
  270. parameters: query,
  271. onSuccess: this.doneGetRSSNews.bindAsEventListener(this),
  272. onFail: function () {
  273. twmsgbox.show("Failed", "Your submission failed. You Suck");
  274. }
  275. });
  276.  
  277. },
  278.  
  279. doneGetRSSNews: function (r) {
  280. var t = r.responseText.parseJSON();
  281. if (this.checkMessageBox(t)) {
  282. return;
  283. }
  284.  
  285. $('rsstitle').value = t.title;
  286. $('rsshref').value = t.href;
  287. $('rssview').href = t.href;
  288. $('rssbody').value = t.summary;
  289. }
  290.  
  291. }),
  292.  
  293.  
  294. // Forums stuff
  295. Forums: Object.extend(new Object(), {
  296.  
  297.  
  298. // Forum news stuff
  299. News: Object.extend(new Object(), {
  300. _seen: Array(0),
  301. _newsid: 0,
  302. _news: '',
  303. _delay: 5000,
  304.  
  305.  
  306. startNews: function (news) {
  307. this._news = news;
  308.  
  309. this._upcoming = 0;
  310. this._promoted = 0;
  311.  
  312. window.setTimeout(this.continueNews.bind(this), this._delay);
  313. },
  314.  
  315. continueNews: function () {
  316. var un = $('forumnews').getElementsByTagName('div');
  317. var pn = $('forumnewspromoted').getElementsByTagName('div');
  318.  
  319.  
  320. if (un[2] && this._upcoming < this._news.upcoming.length) Effect.Fade(un[2].id);
  321. if (pn[2] && this._promoted < this._news.promoted.length) Effect.Fade(pn[2].id);
  322.  
  323. window.setTimeout(this.showNews.bind(this), 1000);
  324.  
  325. },
  326.  
  327. showNews: function () {
  328. var un = $('forumnews').getElementsByTagName('div');
  329. var pn = $('forumnewspromoted').getElementsByTagName('div');
  330.  
  331. var run_again = 0;
  332.  
  333. if (this._upcoming < this._news.upcoming.length) {
  334. new Insertion.Top('forumnews', this._news.upcoming[this._upcoming].html);
  335. Effect.Appear('news' + this._news.upcoming[this._upcoming].id);
  336. this._upcoming++;
  337. run_again = 1;
  338. }
  339.  
  340.  
  341. if (this._promoted < this._news.promoted.length) {
  342. new Insertion.Top('forumnewspromoted', this._news.promoted[this._promoted].html);
  343. Effect.Appear('news' + this._news.promoted[this._promoted].id);
  344. this._promoted++;
  345. run_again = 1;
  346. }
  347.  
  348. if (run_again) {
  349. window.setTimeout(this.continueNews.bind(this), this._delay);
  350. }
  351. }
  352.  
  353.  
  354. })
  355. // End forum news
  356. })
  357. // End forum
  358. }
  359.  
  360. var $TW = new TW();
  361.  
  362. Effect.FadeKeepSpace = function (element) {
  363. var oldOpacity = Element.getInlineOpacity(element);
  364. var options = Object.extend({
  365. from: Element.getOpacity(element) || 1.0,
  366. to: 0.0,
  367. afterFinishInternal: function (effect) {
  368. with(Element) {
  369. if (effect.options.to != 0) return;
  370. blank(effect.element);
  371. setStyle(effect.element, {
  372. opacity: oldOpacity
  373. });
  374. }
  375. }
  376. },
  377. arguments[1] || {});
  378. return new Effect.Opacity(element, options);
  379. }
  380.  
  381. Effect.AppearKeepSpace = function (element) {
  382. var options = Object.extend({
  383. from: (Element.getStyle(element, 'visibility') == 'hidden' ? 0.0 : Element.getOpacity(element) || 0.0),
  384. to: 1.0,
  385. beforeSetup: function (effect) {
  386. with(Element) {
  387. setOpacity(effect.element, effect.options.from);
  388. unblank(effect.element);
  389. }
  390. }
  391. },
  392. arguments[1] || {});
  393. return new Effect.Opacity(element, options);
  394. }
  395.  
  396. Object.extend(Element, {
  397. blank: function () {
  398. for (var i = 0; i < arguments.length; i++) {
  399. var element = $(arguments[i]);
  400. element.style.visibility = 'hidden';
  401. }
  402. },
  403. unblank: function () {
  404. for (var i = 0; i < arguments.length; i++) {
  405. var element = $(arguments[i]);
  406. element.style.visibility = 'visible';
  407. }
  408. }
  409. });
  410.  
  411.  
  412. String.prototype.parseJSON = function () {
  413. try {
  414. return ! (/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
  415. this.replace(/"(\\.|[^"\\])*"/g, ''))) && eval('(' + this + ')');
  416. } catch(e) {
  417. return false;
  418. }
  419. };
Add Comment
Please, Sign In to add comment