Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл - board.js (Старый размер - 30296 | Новый - 0):
- 0. - var Board = {
- 1. - createTopic: function(oid, hash) {
- 2. - var title = trim(val('bnt_title')), post = trim(val('bnt_text')), question, answers = [];
- 3. - var chosen = cur.boardNewMedia.chosenMedias || {}, media = [], types = [];
- 4. - for (var i = 0, l = chosen.length; i < l; ++i) {
- 5. - var m = chosen[i];
- 6. - if (m) {
- 7. - types.push(m[0]);
- 8. - media.push(m[1]);
- 9. - }
- 10. - }
- 11. - if (!title) return elfocus('bnt_title');
- 12. - if (!post && !media.length) return elfocus('bnt_text');
- 13. - if (cur.pollPreview) {
- 14. - question = trim(val('bnt_poll_question'));
- 15. - if (!question) {
- 16. - return elfocus('bnt_poll_question');
- 17. - }
- 18. - for (var el = ge('bnt_poll_answers').firstChild; el; el = el.nextSibling) {
- 19. - if (!isVisible(el)) break;
- 20. - var answer = trim(val(el));
- 21. - if (answer) {
- 22. - answers.push(answer);
- 23. - }
- 24. - }
- 25. - if (!answers.length) {
- 26. - return elfocus(ge('bnt_poll_answers').firstChild);
- 27. - }
- 28. - }
- 29. -
- 30. - globalHistoryDestroy('board' + (-oid));
- 31. - ajax.post('al_board.php', {
- 32. - act: 'do_create',
- 33. - oid: oid,
- 34. - hash: hash,
- 35. - title: title,
- 36. - post: post,
- 37. - media_types: types,
- 38. - media: media,
- 39. - question: question,
- 40. - from_group: isChecked('bnt_from_group'),
- 41. - answers: answers
- 42. - }, {
- 43. - showProgress: lockButton.pbind(ge('bnt_subm')),
- 44. - hideProgress: unlockButton.pbind(ge('bnt_subm'))
- 45. - });
- 46. - },
- 47. - attachPoll: function() {
- 48. - var prev = ge('bnt_media_preview');
- 49. - cur.pollPreview = prev.parentNode.insertBefore(ce('div', {id: 'bnt_poll', innerHTML: '\
- 50. - <div class="bnt_header">' + getLang('voting_topic') + '</div>\
- 51. - <input type="text" class="text" id="bnt_poll_question" />\
- 52. - <nobr class="no_select fl_r" onselectstart="return false;" ondblclick="return false;">\
- 53. - <a id="bnt_poll_add" onclick="Board.incPoll(\'bnt\')">' + getLang('voting_variants_add') + '</a><span class="sdivide">|</span><a id="bnt_poll_delete" class="bnt_disabled" onclick="Board.decPoll(\'bnt\')">' + getLang('voting_variants_del') + '</a>\
- 54. - </nobr>\
- 55. - <div class="bnt_header">' + getLang('voting_variants') + '</div>\
- 56. - <div id="bnt_poll_answers"></div>\
- 57. - '}, {display: 'none'}), prev);
- 58. - Board.initAddPoll('bnt');
- 59. - slideDown(cur.pollPreview, 200, function() {
- 60. - show('bnt_cancel_poll');
- 61. - elfocus('bnt_poll_question');
- 62. - });
- 63. - },
- 64. - initAddPoll: function(prefix) {
- 65. - var html = [];
- 66. - for (var i = 0; i < 20; ++i) {
- 67. - html.push('<input type="text" class="text ' + prefix + '_poll_answer" style="' + (i > 1 ? 'display: none' : '') + '" />');
- 68. - }
- 69. - ge(prefix + '_poll_answers').innerHTML = html.join('');
- 70. - },
- 71. - cancelPoll: function() {
- 72. - hide('bnt_cancel_poll');
- 73. - slideUp(cur.pollPreview, 200, function() {
- 74. - re(cur.pollPreview);
- 75. - cur.pollPreview = false;
- 76. - show('bnt_attach');
- 77. - });
- 78. - },
- 79. - incPoll: function(prefix) {
- 80. - var answers = ge(prefix + '_poll_answers');
- 81. - for (var el = answers.firstChild; el; el = el.nextSibling) {
- 82. - if (!isVisible(el)) {
- 83. - break;
- 84. - }
- 85. - }
- 86. - if (el) {
- 87. - ge(prefix + '_poll_delete').className = '';
- 88. - show(el);
- 89. - }
- 90. - if (!el || !el.nextSibling) {
- 91. - ge(prefix + '_poll_add').className = prefix + '_disabled';
- 92. - }
- 93. - },
- 94. - decPoll: function(prefix) {
- 95. - var answers = ge(prefix + '_poll_answers'), first = answers.firstChild;
- 96. - for (var el = answers.lastChild; el; el = el.previousSibling) {
- 97. - if (isVisible(el)) {
- 98. - break;
- 99. - }
- 100. - }
- 101. - if (el) {
- 102. - if (el == first || el == first.nextSibling) {
- 103. - el = false;
- 104. - }
- 105. - if (el) {
- 106. - ge(prefix + '_poll_add').className = '';
- 107. - hide(el);
- 108. - }
- 109. - }
- 110. - if (!el || !el.previousSibling || el.previousSibling == first.nextSibling) {
- 111. - ge(prefix + '_poll_delete').className = prefix + '_disabled';
- 112. - }
- 113. - },
- 114. -
- 115. - scrollResize: function() {
- 116. - if (browser.mobile || cur.pvShown) return;
- 117. -
- 118. - var docEl = document.documentElement;
- 119. - var ch = window.innerHeight || docEl.clientHeight || bodyNode.clientHeight;
- 120. - var st = scrollGetY();
- 121. - var lnk = ge('blst_load_more');
- 122. -
- 123. - if (!isVisible(lnk)) return;
- 124. - if (st + ch > lnk.offsetTop) {
- 125. - Board.load();
- 126. - }
- 127. - },
- 128. - initScroll: function() {
- 129. - cur.module = 'board';
- 130. -
- 131. - Board.scrollnode = browser.msie6 ? pageNode : window;
- 132. -
- 133. - addEvent(Board.scrollnode, 'scroll', Board.scrollResize);
- 134. - addEvent(window, 'resize', Board.scrollResize);
- 135. - removeEvent(window, 'load', Board.initScroll);
- 136. - cur.destroy.push(Board.deinitScroll);
- 137. - },
- 138. - deinitScroll: function() {
- 139. - removeEvent(Board.scrollnode, 'scroll', Board.scrollResize);
- 140. - removeEvent(window, 'resize', Board.scrollResize);
- 141. - },
- 142. - loaded: function(off, rows) {
- 143. - cur.offset = off;
- 144. -
- 145. - var cont = ge('blst_cont'), d = ce('div', {innerHTML: rows});
- 146. - while (d.firstChild) {
- 147. - cont.appendChild(d.firstChild);
- 148. - }
- 149. -
- 150. - if (off >= cur.count || !rows) {
- 151. - hide('blst_load_more');
- 152. - return;
- 153. - }
- 154. - cur.loading = 1;
- 155. - var params = cur.query ? {act: 'search', q: cur.query} : {order: cur.order};
- 156. - ajax.post('/board' + cur.gid, extend(params, {offset: cur.offset, part: 1}), {cache: 1, onDone: function() {
- 157. - if (cur.loading == 2) {
- 158. - Board.loaded.apply(window, arguments);
- 159. - } else {
- 160. - cur.loading = false;
- 161. - }
- 162. - }, onFail: function() {
- 163. - cur.loading = 0;
- 164. - return true;
- 165. - }});
- 166. - },
- 167. - load: function() {
- 168. - if (!isVisible('blst_load_more') || isVisible('blst_more_progress')) return;
- 169. - if (cur.loading) {
- 170. - cur.loading = 2;
- 171. - return;
- 172. - }
- 173. -
- 174. - var params = cur.query ? {act: 'search', q: cur.query} : {order: cur.order};
- 175. - ajax.post('/board' + cur.gid, extend(params, {offset: cur.offset, part: 1}), {onDone: Board.loaded, onFail: function() {
- 176. - cur.loading = 0;
- 177. - return true;
- 178. - }, showProgress: function() {
- 179. - show('blst_more_progress');
- 180. - hide(ge('blst_load_more').firstChild);
- 181. - }, hideProgress: function() {
- 182. - show(ge('blst_load_more').firstChild);
- 183. - hide('blst_more_progress');
- 184. - }, cache: 1});
- 185. - },
- 186. -
- 187. - topicFieldUpdated: function() {
- 188. - var newt = val(cur.addField), newh = getSize(cur.addBlock)[1];
- 189. - var ch = (cur.addBlockHeight != newh), ct = (cur.addText != newt);
- 190. - if (ch) {
- 191. - cur.addBlockHeight = newh;
- 192. - cur.addBlockWrap.style.height = newh + 'px';
- 193. - }
- 194. - if (ct) {
- 195. - cur.addText = newt;
- 196. - }
- 197. - if (ch || ct) {
- 198. - Board.topicOnScroll(false, false, true);
- 199. - }
- 200. - },
- 201. - topicOnProgress: function() {
- 202. - Board.topicFieldUpdated();
- 203. - },
- 204. - topicCheckAttach: function() {
- 205. - var img = geByClass1('photo', cur.addAttach);
- 206. - if (!img) return;
- 207. - if (img.width && img.height) {
- 208. - Board.topicFieldUpdated();
- 209. - } else {
- 210. - img.onload = Board.topicCheckAttach;
- 211. - }
- 212. - },
- 213. - topicAttachAdded: function() {
- 214. - Board.topicFieldUpdated();
- 215. - Board.topicCheckAttach();
- 216. - },
- 217. - topicAttachWillAdd: function() {
- 218. - setTimeout(Board.topicAttachAdded, 10);
- 219. - setTimeout(Board.topicAttachAdded, 100);
- 220. - setTimeout(Board.topicAttachAdded, 1000);
- 221. - },
- 222. - repliesCount: function() {
- 223. - var m = cur.addText.match(/\[post\d+\|[^\]]+\]/g), res = 0;
- 224. - for (var i in (m || {})) ++res;
- 225. - return res;
- 226. - },
- 227. - replyPost: function(post, mid) {
- 228. - if (browser.mobile) return elfocus(cur.addField);
- 229. - cur.addForce = true;
- 230. - Board.topicOnScroll(false, false, true);
- 231. - var count = Board.repliesCount();
- 232. - if (count >= 10) {
- 233. - return setTimeout(elfocus.pbind(cur.addField), 0);
- 234. - }
- 235. - var insert = replaceEntities(cur.names[mid].replace('{post_id}', 'post' + post)), pos;
- 236. - if (document.selection) {
- 237. - var range = document.selection.createRange();
- 238. - if (range.parentElement() == cur.addField) {
- 239. - range.text = insert + (range.text || '');
- 240. - pos = -1;
- 241. - range.select();
- 242. - } else {
- 243. - val(cur.addField, cur.addText + insert);
- 244. - pos = cur.addText.length + insert.length;
- 245. - }
- 246. - } else {
- 247. - pos = cur.addField.selectionEnd + insert.length;
- 248. - cur.addField.blur();
- 249. - val(cur.addField, cur.addText.substr(0, cur.addField.selectionStart) + insert + cur.addText.substr(cur.addField.selectionStart));
- 250. - }
- 251. - if (pos >= 0) {
- 252. - elfocus(cur.addField, pos, pos);
- 253. - }
- 254. - cur.addText = val(cur.addField);
- 255. - },
- 256. - privacyChanged: function(key) {
- 257. - if (key == 'voting_action') {
- 258. - Board.votingAction(key);
- 259. - } else if (key == 'topic_action') {
- 260. - Board.topicAction(key);
- 261. - }
- 262. - },
- 263. - topicAction: function(key) {
- 264. - ge('privacy_edit_topic_action').innerHTML = getLang('global_edit');
- 265. - var act = cur.privacy[key][0];
- 266. - cur.privacy[key] = [0, 0, []];
- 267. - if (act == 'edit') {
- 268. - showFastBox(getLang('board_edit_topic'), '\
- 269. - <div class="bte_label fl_l">' + getLang('board_new_topic_title') + '</div>\
- 270. - <div class="bte_labeled fl_l">\
- 271. - <input id="bte_title" class="text" type="text" onchange="curBox().changed = true;" onkeypress="if (event.keyCode == 10 || event.keyCode == 13) Board.saveTopic()" />\
- 272. - </div><br class="clear">\
- 273. - ', getLang('global_save'), Board.saveTopic, getLang('global_cancel'));
- 274. - val('bte_title', winToUtf(val('bt_title')));
- 275. - elfocus('bte_title');
- 276. - } else if (act == 'voting') {
- 277. - showBox('al_board.php', {act: 'create_voting', topic: cur.topic});
- 278. - } else if (act == 'delete') {
- 279. - showFastBox(getLang('board_edit_topic'), '<div>' + getLang('board_sure_delete_topic') + '</div>', getLang('global_delete'), Board.deleteTopic, getLang('global_cancel'));
- 280. - } else if (act == 'open' || act == 'close') {
- 281. - ajax.post('al_board.php', {act: (act == 'open') ? 'open_topic' : 'close_topic', topic: cur.topic, hash: cur.hash, offset: nav.objLoc.offset}, {
- 282. - showProgress: function() {
- 283. - hide('privacy_edit_topic_action');
- 284. - show('edit_topic_prg');
- 285. - },
- 286. - hideProgress: function() {
- 287. - hide('edit_topic_prg');
- 288. - show('privacy_edit_topic_action');
- 289. - }
- 290. - });
- 291. - } else if (act == 'fix' || act == 'unfix') {
- 292. - var t = cur.topic;
- 293. - ajax.post('al_board.php', {act: (act == 'fix') ? 'fix_topic' : 'unfix_topic', topic: t, hash: cur.hash}, {
- 294. - onDone: function(text, priv) {
- 295. - if (cur.topic !== t) return;
- 296. - cur.privacy.topic_action_types = priv;
- 297. - var msg = ge('bt_msg');
- 298. - if (!msg) {
- 299. - msg = ge('content').insertBefore(ce('div', {id: 'bt_msg', className: 'msg'}), ge('bt_title').parentNode.nextSibling);
- 300. - re('bv_msg');
- 301. - }
- 302. - msg.innerHTML = text;
- 303. - msg.style.backgroundColor = '#F4EBBD';
- 304. - animate(msg, {backgroundColor: '#F9F6E7'}, 2000);
- 305. - },
- 306. - showProgress: function() {
- 307. - hide('privacy_edit_topic_action');
- 308. - show('edit_topic_prg');
- 309. - },
- 310. - hideProgress: function() {
- 311. - hide('edit_topic_prg');
- 312. - show('privacy_edit_topic_action');
- 313. - }
- 314. - });
- 315. - }
- 316. - },
- 317. - saveTopic: function() {
- 318. - var newtitle = trim(val('bte_title'));
- 319. - if (!newtitle) {
- 320. - return elfocus('bte_title');
- 321. - }
- 322. - ajax.post('al_board.php', {act: 'save_topic', topic: cur.topic, hash: cur.hash, title: newtitle}, {onDone: function(text) {
- 323. - ge('bt_title').innerHTML = text;
- 324. - curBox().hide();
- 325. - }, progress: curBox().progress});
- 326. - },
- 327. - deleteTopic: function() {
- 328. - ajax.post('al_board.php', {act: 'delete_topic', topic: cur.topic, hash: cur.hash}, {progress: curBox().progress});
- 329. - },
- 330. - initTopic: function(opts, preload) {
- 331. - extend(cur, {
- 332. - module: 'board',
- 333. -
- 334. - docked: false,
- 335. - topic: opts.topic,
- 336. - owner: opts.owner,
- 337. - hash: opts.hash,
- 338. - postLimit: opts.limit,
- 339. - postTo: 'board' + (-opts.owner),
- 340. -
- 341. - names: opts.names,
- 342. - mediaTypes: opts.media,
- 343. -
- 344. - addField: ge('ba_text'),
- 345. - addBlock: ge('ba_post'),
- 346. - addAttach: ge('ba_media_preview'),
- 347. - addBlockWrap: ge('ba_post_wrap'),
- 348. -
- 349. - pgStart: opts.start,
- 350. - pgOffset: opts.offset,
- 351. - pgCount: opts.count,
- 352. - pgPerPage: opts.perpage,
- 353. - pgCont: ge('bt_rows'),
- 354. - pgMore: ge('bt_load_more'),
- 355. - pgPages: ge('bt_pages'),
- 356. - pgMorePrg: ge('bt_more_progress'),
- 357. - pgPreload: preload,
- 358. - pgUrl: opts.url,
- 359. - pgHref: opts.url + '?offset=',
- 360. -
- 361. - pgPostProcess: Board.loadedPosts,
- 362. - pgOnScroll: Board.topicOnScroll,
- 363. - pgNoArrowNav: Board.noArrowNav,
- 364. -
- 365. - onPrivacyChanged: Board.privacyChanged,
- 366. - updates: opts.updates,
- 367. - topicMyReplied: false,
- 368. - topicMyDeleted: {}
- 369. - });
- 370. - cur.privacy = extend(cur.privacy || {}, opts.privacy);
- 371. - Board.initUpdates();
- 372. -
- 373. - if (cur.addField) {
- 374. - cur.boardAddMedia = initAddMedia(ge('ba_add_media').firstChild, 'ba_media_preview', cur.mediaTypes, {
- 375. - limit: 10,
- 376. - editable: 1,
- 377. - sortable: 1,
- 378. - teWidth: 280,
- 379. - teHeight: 200
- 380. - });
- 381. - cur.boardAddMedia.onChange = Board.topicAttachWillAdd;
- 382. - cur.boardAddMedia.onProgress = Board.topicOnProgress;
- 383. - placeholderSetup(cur.addField);
- 384. - autosizeSetup(cur.addField, {minHeight: 42, maxHeight: 160});
- 385. - addEvent(cur.addField, 'change keydown keyup paste', Board.topicFieldUpdated);
- 386. - Board.topicFieldUpdated();
- 387. - }
- 388. -
- 389. - Board.topicOnScroll(false, false, true);
- 390. -
- 391. - Pagination.init(opts.bottom);
- 392. - cur.destroy.push(Pagination.deinit);
- 393. - cur.destroy.push(removeEvent.pbind(window, 'keydown', Board.handleEditEsc));
- 394. - },
- 395. - initUpdates: function () {
- 396. - if (!cur.updates || !window.Notifier) {
- 397. - return
- 398. - }
- 399. - Board.checkUpdates();
- 400. - cur.updates.unread = 0;
- 401. - cur.updates.interval = setInterval(Board.checkUpdates, 20000);
- 402. - cur.destroy.push(function () {
- 403. - clearInterval(cur.updates.interval);
- 404. - });
- 405. -
- 406. - if (!isArray(cur.onUnidle)) {
- 407. - cur.onUnidle = [];
- 408. - }
- 409. - cur.onUnidle.push(function () {
- 410. - Board.updateTitle(true);
- 411. - });
- 412. - },
- 413. - checkUpdates: function () {
- 414. - if (!cur.updates || !cur.updates.queue) {
- 415. - return;
- 416. - }
- 417. - Notifier.addKey(cur.updates.queue, Board.checkedUpdates);
- 418. - },
- 419. - getAbsDate: function (ts) {
- 420. - var date = new Date(ts || vkNow()),
- 421. - hours = date.getHours(),
- 422. - minutes = date.getMinutes(),
- 423. - ampm = '', numhours;
- 424. - if (cur.updates.time_system) {
- 425. - ampm = cur.updates.time_system[hours > 11 ? 1 : 0];
- 426. - hours = (hours % 12) || 12;
- 427. - }
- 428. - numhours = hours > 9 ? hours : ('0' + hours);
- 429. - minutes = minutes > 9 ? minutes : ('0' + minutes);
- 430. - return cur.updates.date_format.replace('{am_pm}', ampm).replace('{hour}', hours).replace('{num_hour}', numhours).replace('{minute}', minutes);
- 431. - },
- 432. - checkedUpdates: function (key, data) {
- 433. - if (!cur.updates || !cur.updates.queue || cur.updates.queue.key != key) {
- 434. - return;
- 435. - }
- 436. - if (data.failed) {
- 437. - cur.updates.queue = false;
- 438. - return;
- 439. - }
- 440. - cur.updates.queue.ts = data.ts;
- 441. - if (!isArray(data.events) || !data.events.length) {
- 442. - return;
- 443. - }
- 444. - // debugLog('board updated', data);
- 445. - var count = false;
- 446. - each(data.events, function () {
- 447. - var ev = this.split('<!>'), evVer = ev[0], evType = ev[1],
- 448. - topicId = ev[2], postId = ev[4], el = ge('post' + postId);
- 449. -
- 450. - if (evVer != cur.updates.qversion) {
- 451. - location.reload();
- 452. - return false;
- 453. - }
- 454. - if (ev[3] > -1) count = ev[3];
- 455. - // debugLog(ev, count, evType);
- 456. - switch (evType) {
- 457. - case 'new_post':
- 458. - if (cur.topicMyReplied || el || cur.pgOffset < cur.pgCount) break;
- 459. -
- 460. - var data = {
- 461. - actions: '',
- 462. - owner_id: cur.owner,
- 463. - topic_raw: cur.topic,
- 464. - post_raw: postId,
- 465. - post_id: ev[5],
- 466. - post_uid: ev[6],
- 467. - name: ev[7],
- 468. - photo: ev[8],
- 469. - link: ev[9],
- 470. - text: ev[10],
- 471. - media: ev[11],
- 472. - date: Board.getAbsDate(),
- 473. - online: ''
- 474. - }, skin = cur.updates.skin, actions = '';
- 475. - if (vk.id) {
- 476. - if (vk.id == data.post_uid || cur.updates.admin_level > 0) {
- 477. - if (vk.id == data.post_uid || cur.updates.admin_level > 1) {
- 478. - actions += skin.sep + skin.act_edit;
- 479. - }
- 480. - actions += skin.sep + skin.act_delete;
- 481. - } else if (vk.id != data.post_uid) {
- 482. - actions += skin.sep + skin.act_report;
- 483. - }
- 484. - if (vk.id != data.post_uid) {
- 485. - actions += skin.sep + skin.act_reply;
- 486. - }
- 487. - }
- 488. - data.actions = actions;
- 489. - cur.names[data.post_uid] = ev[12];
- 490. -
- 491. - var newEl = se(rs(skin.post, data));
- 492. - // debugLog(skin, data, actions);
- 493. - ge('bt_rows').appendChild(newEl);
- 494. - setStyle(newEl, {backgroundColor: '#FEFAE4'});
- 495. - animate(newEl, {backgroundColor: '#FFF'}, 6000);
- 496. -
- 497. - cur.pgOffset++;
- 498. - cur.pgCount++;
- 499. - if (window.curNotifier && curNotifier.idle_manager && curNotifier.idle_manager.is_idle) {
- 500. - cur.updates.unread++;
- 501. - }
- 502. - break;
- 503. -
- 504. - case 'del_post':
- 505. - if (cur.topicMyDeleted[ev[4]] || !el) break;
- 506. - hide(el);
- 507. - cur.pgOffset--;
- 508. - cur.pgCount--;
- 509. - break;
- 510. -
- 511. - case 'res_post':
- 512. - if (isVisible(el)) break;
- 513. - show(el);
- 514. - cur.pgOffset++;
- 515. - cur.pgCount++;
- 516. - break;
- 517. - }
- 518. - });
- 519. - if (count !== false) {
- 520. - val('bt_summary', count ? getLang('board_msgs_in_topic', count) : getLang('board_no_msgs_in_topic'));
- 521. - Pagination.pageReady(false);
- 522. - Board.topicOnScroll(false, false, true);
- 523. - Board.updateTitle();
- 524. - }
- 525. - },
- 526. - updateTitle: function (unidle) {
- 527. - if (!cur.updates) {
- 528. - return;
- 529. - }
- 530. - if (unidle) {
- 531. - cur.updates.unread = 0;
- 532. - }
- 533. - document.title = replaceEntities((cur.updates.unread ? '('+ cur.updates.unread + ') ' : '') + cur.updates.skin.title);
- 534. - },
- 535. - cancelAddPost: function(clear) {
- 536. - cur.addForce = false;
- 537. - hide('ba_cancel');
- 538. - cur.addBlock.className = '';
- 539. - cur.boardAddMedia.menu.updateFixed(false);
- 540. - if (browser.msie6) {
- 541. - cur.addBlockWrap.appendChild(cur.addBlock);
- 542. - }
- 543. - cur.docked = false;
- 544. - if (clear === true) {
- 545. - val(cur.addField, '');
- 546. - cur.boardAddMedia.unchooseMedia();
- 547. - hide('bp_warn');
- 548. - cur.addField.autosize.update();
- 549. - Board.topicFieldUpdated();
- 550. - }
- 551. - },
- 552. - topicResetStyle: function() {
- 553. - cur.addBlock.style.left = '';
- 554. - },
- 555. - topicOnScroll: function(e, st, pp) {
- 556. - if (st === false || st === undefined) {
- 557. - st = scrollGetY();
- 558. - }
- 559. - if (!cur.addField) return;
- 560. - if (pp === true) {
- 561. - cur.addBlockTop = getXY(cur.addBlockWrap)[1];
- 562. - if (browser.msie6) cur.addBlockTop += st;
- 563. - }
- 564. - var needDock = (cur.addText || cur.addForce || cur.boardAddMedia.chosenMedia) && (st + lastWindowHeight < cur.addBlockTop + cur.addBlockHeight);
- 565. - if (needDock && !cur.docked) {
- 566. - cur.addBlock.className = 'fixed';
- 567. - if (browser.msie6) {
- 568. - bodyNode.appendChild(cur.addBlock);
- 569. - e = {type: 'resize'};
- 570. - } else {
- 571. - cur.boardAddMedia.menu.updateFixed(true);
- 572. - }
- 573. - cur.docked = true;
- 574. - show('ba_cancel');
- 575. - cur.addForce = true;
- 576. - } else if (!needDock && cur.docked) {
- 577. - Board.cancelAddPost();
- 578. - }
- 579. - if (cur.docked && e && e.type == 'resize') {
- 580. - if (browser.msie6) {
- 581. - cur.addBlock.style.left = getXY(ge('content'))[0] + 'px';
- 582. - } else {
- 583. - cur.addBlock.style.left = (ge('page_layout').offsetLeft + ge('content').offsetLeft) + 'px';
- 584. - setTimeout(Board.topicResetStyle, 0);
- 585. - }
- 586. - }
- 587. - },
- 588. - loadedPosts: function(count, from, rows, offset, pages, preload, names) {
- 589. - Board.topicOnScroll(false, false, true);
- 590. - ge('bt_summary').innerHTML = count ? getLang('board_msgs_in_topic', count) : getLang('board_no_msgs_in_topic');
- 591. - if (preload) { // got new page
- 592. - Board.cancelEditPost();
- 593. - } else {
- 594. - names = offset;
- 595. - }
- 596. - extend(cur.names, names);
- 597. - },
- 598. - noArrowNav: function() {
- 599. - return cur.__focused || cur.bEditingPost;
- 600. - },
- 601. - scrollToEnd: function() {
- 602. - var st = cur.addBlockTop + cur.addBlockHeight + 20 - lastWindowHeight;
- 603. - if (scrollGetY() < st) {
- 604. - Pagination.setScroll(st);
- 605. - }
- 606. - },
- 607. - sendPost: function() {
- 608. - var prg = ge('ba_progress');
- 609. - if (isVisible(prg)) return;
- 610. -
- 611. - var value = trim(val(cur.addField)),
- 612. - addmedia = cur.boardAddMedia || {},
- 613. - media = addmedia.chosenMedia || {},
- 614. - medias = cur.boardAddMedia ? addmedia.getMedias() : [],
- 615. - params = {
- 616. - act: 'post_comment',
- 617. - topic: cur.topic,
- 618. - hash: cur.hash,
- 619. - comment: value,
- 620. - last: last,
- 621. - from_group: isChecked('ba_from_group')
- 622. - }, attachI = 0;
- 623. -
- 624. - if (isArray(media) && media.length) {
- 625. - medias.push(clone(media));
- 626. - }
- 627. -
- 628. - if (medias.length) {
- 629. - each(medias, function(k, v) {
- 630. - if (!v) return;
- 631. - ++attachI;
- 632. - params['attach' + attachI + '_type'] = this[0];
- 633. - params['attach' + attachI] = this[1];
- 634. - });
- 635. - }
- 636. - if (!attachI && !value) {
- 637. - return elfocus(cur.addField);
- 638. - }
- 639. -
- 640. - cur.topicMyReplied = true;
- 641. - var last = ((cur.pgCont.childNodes[cur.pgNodesCount - 1].id || '').match(/\d+$/) || [0])[0];
- 642. - ajax.post('al_board.php', params, {onDone: function(count, from, rows, offset, pages, preload) {
- 643. - cur.topicMyReplied = false;
- 644. - re('b_no_content');
- 645. - Pagination.loaded.apply(window, arguments);
- 646. - Board.cancelAddPost(true);
- 647. - setTimeout(Board.scrollToEnd, 0);
- 648. - if (pages && offset) {
- 649. - nav.setLoc(extend(nav.objLoc, {offset: offset}));
- 650. - }
- 651. - }, progress: prg});
- 652. - },
- 653. - deleteReportPost: function(post, act) {
- 654. - post = cur.owner + '_' + post;
- 655. - var prg = geByClass1('bp_progress', ge('post' + post));
- 656. - if (isVisible(prg)) return;
- 657. -
- 658. - cur.topicMyDeleted[post] = 1;
- 659. - ajax.post('al_board.php', {act: act, post: post, hash: cur.hash}, {onDone: function(text, deleted) {
- 660. - var info = ge('post' + post).firstChild.nextSibling;
- 661. - if (info) {
- 662. - info.firstChild.rows[0].cells[0].innerHTML = text;
- 663. - } else {
- 664. - info = ge('post' + post).appendChild(ce('div', {className: 'bp_deleted', innerHTML: '\
- 665. - <table cellspacing="0" cellpadding="0" style="width: 100%"><tr><td class="bp_deleted_td">\
- 666. - ' + text + '\
- 667. - </td></tr></table>'}));
- 668. - hide(info.previousSibling);
- 669. - }
- 670. -
- 671. - if (deleted) {
- 672. - Pagination.recache(-1);
- 673. - Board.loadedPosts(cur.pgCount);
- 674. - }
- 675. - }, progress: prg});
- 676. - },
- 677. - deletePost: function(post) {
- 678. - Board.deleteReportPost(post, 'delete_comment');
- 679. - },
- 680. - reportPost: function(post) {
- 681. - Board.deleteReportPost(post, 'spam_comment');
- 682. - },
- 683. - restorePost: function(post) {
- 684. - post = cur.owner + '_' + post;
- 685. - cur.topicMyDeleted[post] = 0;
- 686. - ajax.post('al_board.php', {act: 'restore_comment', post: post, hash: cur.hash}, {onDone: function() {
- 687. - var info = ge('post' + post).firstChild.nextSibling;
- 688. - if (info) {
- 689. - show(info.previousSibling);
- 690. - re(info);
- 691. -
- 692. - Pagination.recache(1);
- 693. - Board.loadedPosts(cur.pgCount);
- 694. - }
- 695. - }});
- 696. - },
- 697. - editPost: function(post) {
- 698. - if (cur.bEditingPost) {
- 699. - return ge('bpe_text') ? elfocus('bpe_text') : false;
- 700. - }
- 701. - post = cur.owner + '_' + post;
- 702. - cur.bEditingPost = post;
- 703. -
- 704. - var postNode = ge('post' + post), dataNode = ge('bp_data' + post);
- 705. - var bottom = geByClass1('bp_bottom', postNode), prg = geByClass1('bp_progress', bottom);
- 706. - ajax.post('al_board.php', {act: 'edit_comment', post: post}, {onDone: function(text, media, add) {
- 707. - addEvent(window, 'keydown', Board.handleEditEsc);
- 708. - var textField = dataNode.parentNode.insertBefore(ce('div', {className: 'bpe_wrap', innerHTML: '\
- 709. - <textarea id="bpe_text" onkeyup="checkTextLength(cur.postLimit, this, \'bpe_warn\')" onkeypress="onCtrlEnter(event, Board.savePost)">' + text + '</textarea>\
- 710. - <div id="bpe_warn"></div>\
- 711. - <div id="bpe_media_preview" class="clear_fix media_preview"></div>\
- 712. - ' + (add ? '<div class="wpe_auth">' + add + '</div>' : '') + '\
- 713. - <div class="bpe_buttons">\
- 714. - <div id="bpe_add_media" class="fl_r"><span class="add_media_lnk">' + getLang('board_add_attach') + '</span></div>\
- 715. - <div class="button_blue fl_l">\
- 716. - <button onclick="Board.savePost()">' + getLang('global_save') + '</button>\
- 717. - </div>\
- 718. - <div class="button_cancel bpe_cancel fl_l">\
- 719. - <div class="button" onclick="Board.cancelEditPost()">' + getLang('global_cancel') + '</div>\
- 720. - </div>\
- 721. - <div class="progress fl_l" id="bpe_progress"></div>\
- 722. - </div>'}), dataNode).firstChild;
- 723. - autosizeSetup(textField, {minHeight: 17, delta: 0});
- 724. - setTimeout(function() {
- 725. - show(textField.parentNode);
- 726. - elfocus(textField);
- 727. - hide(dataNode, bottom);
- 728. - cur.boardEditMedia = initAddMedia(ge('bpe_add_media').firstChild, 'bpe_media_preview', cur.mediaTypes, {limit: 10, editable: 1, sortable: 1, teWidth: 280, teHeight: 200});
- 729. - if (media && media.length) {
- 730. - for (var i = 0, l = (media || []).length; i < l; ++i) {
- 731. - cur.boardEditMedia.chooseMedia.apply(window, media[i]);
- 732. - }
- 733. - }
- 734. - }, 0);
- 735. - }, onFail: function() {
- 736. - cur.bEditingPost = false;
- 737. - }, progress: prg});
- 738. - },
- 739. - cancelEditPost: function(nt, nm, ne) {
- 740. - var post = cur.bEditingPost, prg = ge('bpe_progress');
- 741. - if (!post || isVisible(prg)) return;
- 742. -
- 743. - cur.bEditingPost = false;
- 744. - if (!prg) return;
- 745. -
- 746. - removeEvent(window, 'keydown', Board.handleEditEsc);
- 747. - cleanElems(ge('bpe_add_media').firstChild);
- 748. -
- 749. - var postNode = ge('post' + post), dataNode = ge('bp_data' + post);
- 750. - var textNode = dataNode.firstChild, mediaNode = textNode.nextSibling;
- 751. - var bottom = geByClass1('bp_bottom', postNode);
- 752. -
- 753. - if (nt !== undefined) {
- 754. - val(textNode, nt);
- 755. - (nt ? show : hide)(textNode);
- 756. - }
- 757. - if (nm !== undefined) {
- 758. - if (mediaNode && !nm) {
- 759. - re(mediaNode);
- 760. - } else if (nm) {
- 761. - if (!mediaNode) {
- 762. - mediaNode = dataNode.appendChild(ce('div'));
- 763. - }
- 764. - dataNode.replaceChild(ce('div', {innerHTML: nm}).firstChild, mediaNode);
- 765. - }
- 766. - }
- 767. - if (ne !== undefined) {
- 768. - var ed = geByClass1('bp_edited_by', postNode);
- 769. - val(ed, ne);
- 770. - (ne ? show : hide)(ed);
- 771. - }
- 772. - show(bottom, dataNode);
- 773. - re(ge('bpe_text').parentNode);
- 774. - },
- 775. - handleEditEsc: function(e) {
- 776. - if (e.keyCode == KEY.ESC) {
- 777. - Board.cancelEditPost();
- 778. - }
- 779. - },
- 780. - savePost: function() {
- 781. - var post = cur.bEditingPost, prg = ge('bpe_progress');
- 782. - if (!post || !prg || isVisible(prg)) return;
- 783. -
- 784. - var newtext = trim(val('bpe_text')),
- 785. - addmedia = cur.boardEditMedia || {},
- 786. - media = addmedia.chosenMedia || {},
- 787. - medias = cur.boardEditMedia ? addmedia.getMedias() : [],
- 788. - params = {
- 789. - act: 'save_comment',
- 790. - post: post,
- 791. - hash: cur.hash,
- 792. - comment: newtext
- 793. - }, attachI = 0;
- 794. -
- 795. - if (isArray(media) && media.length) {
- 796. - medias.push(clone(media));
- 797. - }
- 798. -
- 799. - if (medias.length) {
- 800. - each(medias, function(k, v) {
- 801. - if (!v) return;
- 802. - ++attachI;
- 803. - params['attach' + attachI + '_type'] = this[0];
- 804. - params['attach' + attachI] = this[1];
- 805. - });
- 806. - }
- 807. - if (!attachI && !newtext) {
- 808. - return elfocus('bpe_text');
- 809. - }
- 810. -
- 811. - ajax.post('al_board.php', params, {
- 812. - onDone: Board.cancelEditPost,
- 813. - progress: prg
- 814. - });
- 815. - },
- 816. -
- 817. - votingUpdate: function(html, js) {
- 818. - if (curBox()) {
- 819. - curBox().hide();
- 820. - }
- 821. -
- 822. - var wrap = ge('bv_wrap');
- 823. - wrap.innerHTML = html;
- 824. - if (js) eval(js);
- 825. - if (!/^board\d+([\?#]|$)/.test(_tbLink.loc || '')) {
- 826. - globalHistoryDestroy(_tbLink.loc);
- 827. - }
- 828. - if (html) {
- 829. - delete(cur.privacy.topic_action_types.voting);
- 830. - } else {
- 831. - var newTypes = {edit: cur.privacy.topic_action_types.edit, voting: getLang('board_create_voting')};
- 832. - for (var i in cur.privacy.topic_action_types) {
- 833. - newTypes[i] = cur.privacy.topic_action_types[i];
- 834. - }
- 835. - cur.privacy.topic_action_types = newTypes;
- 836. - }
- 837. - },
- 838. - vote: function(el, oid, vid, option) {
- 839. - var pr = hasClass(el.firstChild, 'progress') ? el.firstChild : el.insertBefore(ce('span', {className: 'fl_r progress'}), el.firstChild);
- 840. - ajax.post('al_voting.php', {
- 841. - act: 'vote',
- 842. - option_id: option,
- 843. - owner_id: oid,
- 844. - voting_id: vid,
- 845. - context: 'topic',
- 846. - hash: cur.polls[vid].hash
- 847. - }, {onDone: Board.votingUpdate, progress: pr});
- 848. - },
- 849. - votingAction: function(key) {
- 850. - ge('privacy_edit_voting_action').innerHTML = getLang('voting_settings');
- 851. - var act = intval(cur.privacy[key][0]);
- 852. - cur.privacy[key] = [0, 0, []];
- 853. - Board.votingActionPerform(act);
- 854. - },
- 855. - votingActionPerform: function(act, sure) {
- 856. - if (act == 105) {
- 857. - if (sure) {
- 858. - curBox().hide();
- 859. - } else {
- 860. - return showFastBox(getLang('global_warning'), getLang('voting_sure_del_quiz'), getLang('global_delete'), Board.votingActionPerform.pbind(act, true), getLang('global_cancel'));
- 861. - }
- 862. - }
- 863. - var state = 0;
- 864. - switch (act) {
- 865. - case 101: act = 'openclose'; state = 0; break;
- 866. - case 102: act = 'openclose'; state = 1; break;
- 867. - case 103: act = 'tomain'; state = 0; break;
- 868. - case 104: act = 'tomain'; state = 1; break;
- 869. - case 105: act = 'delete'; state = 0; break;
- 870. - }
- 871. - ajax.post('al_voting.php', {
- 872. - act: act,
- 873. - owner_id: cur._voting.oid,
- 874. - voting_id: cur._voting.vid,
- 875. - state: state,
- 876. - context: 'topic',
- 877. - hash: cur._voting.hash
- 878. - }, {onDone: Board.votingUpdate, showProgress: function() {
- 879. - hide('privacy_edit_voting_action');
- 880. - show('bv_progress');
- 881. - }, onHideProgress: function() {
- 882. - hide('bv_progress');
- 883. - show('privacy_edit_voting_action');
- 884. - }});
- 885. - },
- 886. -
- 887. - mentionOver: function(el) {
- 888. - var post = ((el.getAttribute('mention') || '').match(/^bp(-?\d+_\d+)$/) || {})[1];
- 889. - if (!post) {
- 890. - mentionOver(el);
- 891. - return;
- 892. - }
- 893. - showTooltip(el, {
- 894. - url: 'al_board.php',
- 895. - params: {act: 'post_tt', post: post},
- 896. - slide: 15,
- 897. - shift: [78, -3, 0],
- 898. - ajaxdt: 100,
- 899. - showdt: 400,
- 900. - hidedt: 200,
- 901. - className: 'rich board_tt'
- 902. - });
- 903. - },
- 904. - docTooltip: function(el, post, doc) {
- 905. - showTooltip(el, {
- 906. - url: 'al_board.php',
- 907. - params: {act: 'doc_tt', post: post, doc: doc},
- 908. - slide: 15,
- 909. - shift: [78, -3, 0],
- 910. - ajaxdt: 100,
- 911. - showdt: 400,
- 912. - hidedt: 200,
- 913. - className: 'rich board_tt'
- 914. - });
- 915. - },
- 916. -
- 917. - searchGo: function(el, ev) {
- 918. - return nav.go(el, ev, {params: {q: nav.objLoc.q}});
- 919. - }
- 920. -
- 921. - }
- 922. -
- 923. - try{stManager.done('board.js');}catch(e){}
- ------
Advertisement
Add Comment
Please, Sign In to add comment