PageRenderTime 59ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/public/scripts/main.js

https://github.com/xgenvn/jupo
JavaScript | 2398 lines | 2244 code | 104 blank | 50 comment | 42 complexity | 8d523cf56534ba96b96188f9e553aa2b MD5 | raw file
Possible License(s): AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. $(window).unload(function() {
  2. if (get_cookie('channel_id') != null && window.location.href.indexOf('/post/') == -1) {
  3. update_status('offline', false);
  4. }
  5. });
  6. $(document).ready(function(e) {
  7. if ( typeof $.global === 'undefined') {
  8. $.global = {};
  9. $.global.clear_autosave = {};
  10. $.global.preload = {};
  11. }
  12. // restore chat windows
  13. if (localStorage.getItem('chats') != undefined) {
  14. chat_ids = localStorage['chats'].split(',');
  15. console.log(chat_ids);
  16. for (var i = 0; i < chat_ids.length; i++) {
  17. var chat_id = chat_ids[i];
  18. if (chat_id != '' && chat_id.split('-')[1] != undefined && isNaN(chat_id.split('-')[1]) == false) {
  19. start_chat(chat_id);
  20. }
  21. }
  22. }
  23. $.global.title = 'Jupo';
  24. $.global.history = [];
  25. sessionStorage.clear();
  26. if ($('#header-container').length > 0) {
  27. init_avatar_uploader();
  28. }
  29. refresh('#body');
  30. if (window.location.href.indexOf('#comment-') != -1) {
  31. var comment_id = window.location.href.split('#')[1]
  32. var comment = $('#' + comment_id)
  33. if (comment.length > 0) {
  34. comment.addClass('animate flash');
  35. offset_top = comment.offset().top - 45;
  36. $('html,body').animate({
  37. scrollTop: offset_top
  38. }, 'fast');
  39. }
  40. }
  41. $('.online-now .online-count').html($('#friends-online li.status.online').length + $('#friends-online li.status.away').length);
  42. // nginx push
  43. var channel_id;
  44. channel_id = get_cookie('channel_id');
  45. if (channel_id != null) {
  46. stream();
  47. start_pingpong();
  48. update_status('online');
  49. }
  50. // replace system tooltip with tipsy
  51. $('.likes, .viewers, .quick-stats, .see-changes, .reply-to').tipsy({
  52. gravity: 's',
  53. live: true
  54. });
  55. $('#friends-online .status a').tipsy({
  56. gravity: 's',
  57. delayIn: 500,
  58. html: true,
  59. live: true
  60. });
  61. // show default image until the image is loaded by the browser
  62. // $('img.small-avatar, img.medium-avatar').after(function () {
  63. // return '<img class="default-avatar ' + this.className + '"/>'
  64. // })
  65. // .hide()
  66. // .one('load', function() {
  67. // $(this).show().next().remove();
  68. // });
  69. $('body').attr('class', 'animate fadeIn');
  70. var message = get_parameter_by_name('message');
  71. if (message != "") {
  72. $('div#message').html(message).show(0).delay(15000).hide(0);
  73. }
  74. // check user timezone
  75. var timezone = jstz.determine_timezone();
  76. var offset = timezone.offset();
  77. var sign = offset[0];
  78. var parts = offset.substring(1).split(':');
  79. var utcoffset = sign + (parts[0] * 3600 + parts[1] * 60);
  80. set_cookie('utcoffset', utcoffset);
  81. // Auto load more posts
  82. $(window).scroll(function() {
  83. if ($('div#overlay').is(':visible') == false && $(window).scrollTop() + $(window).height() > get_doc_height() - 250) {
  84. console.log('scroll end');
  85. if ($.global.loading != true) {
  86. $('a.next').trigger('click');
  87. }
  88. }
  89. });
  90. // Archive posts
  91. $("#body, #overlay").on('click', "a.archive", function(e) {
  92. // Hide menu
  93. $('a.dropdown-menu-icon.active').parent().removeClass('active');
  94. $('a.dropdown-menu-icon.active').next('ul').hide();
  95. $('a.dropdown-menu-icon.active').removeClass('active');
  96. var href = $(this).attr("href");
  97. feed = $(this).parents('li.feed');
  98. message = '<div class="undo">' + 'This post has been archived. </strong>' + '<a class="undo" href="' + href.replace('/archive', '/unarchive') + '">Undo</a>' + '</div>';
  99. feed.animate({
  100. opacity: 0
  101. }, 0, function(e) {
  102. $('section', feed).hide();
  103. $('> a', feed).hide();
  104. $('> i', feed).hide();
  105. feed.append(message);
  106. feed.animate({
  107. opacity: 1
  108. }, 100);
  109. });
  110. $.ajax({
  111. type: "POST",
  112. headers: {
  113. 'X-CSRFToken': get_cookie('_csrf_token')
  114. },
  115. url: $(this).attr("href"),
  116. success: function(id) {
  117. return false;
  118. }
  119. });
  120. return false;
  121. });
  122. // Confirm remove items
  123. $("#body, #overlay").on('click', "a.remove", function(e) {
  124. // show_loading();
  125. // Hide menu
  126. $('a.dropdown-menu-icon.active').parent().removeClass('active');
  127. $('a.dropdown-menu-icon.active').next('ul').hide();
  128. $('a.dropdown-menu-icon.active').removeClass('active');
  129. var href = $(this).attr("href");
  130. var feed = $(this).parents('li.feed');
  131. message = '<div class="undo">' + 'This post has been removed. </strong>' + '<a class="undo" href="' + href.replace('remove', 'undo_remove') + '">Undo</a>' + '</div>';
  132. feed.animate({
  133. opacity: 0
  134. }, 0, function(e) {
  135. $('section', feed).hide();
  136. $('> a', feed).hide();
  137. $('> i', feed).hide();
  138. feed.append(message);
  139. feed.animate({
  140. opacity: 1
  141. }, 100);
  142. });
  143. $.ajax({
  144. type: "POST",
  145. headers: {
  146. 'X-CSRFToken': get_cookie('_csrf_token')
  147. },
  148. url: $(this).attr("href"),
  149. success: function(id) {
  150. // hide_loading();
  151. return false;
  152. }
  153. });
  154. console.log('asdf')
  155. return false;
  156. });
  157. $('body').on('click', 'a.scroll', function(e) {
  158. id = $(this).attr('href');
  159. if ($(id).length == 0) {
  160. open_in_overlay_mode('#!/feed/' + id.split('-')[1]);
  161. } else {
  162. $('html,body').animate({scrollTop: $(id).offset().top},'fast');
  163. }
  164. // $('.notice-item-close', $(this).parents('div.notice-wrap')).trigger('click');
  165. })
  166. $('#body, #overlay').on('click', 'a.undo', function(e) {
  167. // Hide menu
  168. $('a.dropdown-menu-icon.active').parent().removeClass('active');
  169. $('a.dropdown-menu-icon.active').next('ul').hide();
  170. $('a.dropdown-menu-icon.active').removeClass('active');
  171. feed = $(this).parents('li.feed');
  172. href = $(this).attr("href");
  173. $('.undo', feed).remove();
  174. $('section footer', feed).show();
  175. $('section', feed).show();
  176. $('> a', feed).show();
  177. $('> i', feed).show();
  178. try {
  179. $('input[name="to"]', feed).tokenInput('clear');
  180. $('input[name="viewers"]', feed).tokenInput('clear');
  181. } catch(err) {
  182. }
  183. if (href != undefined) {
  184. $.ajax({
  185. type: "POST",
  186. headers: {
  187. 'X-CSRFToken': get_cookie('_csrf_token')
  188. },
  189. url: $(this).attr("href"),
  190. success: function(id) {
  191. console.log('Undo: ' + id);
  192. return false;
  193. }
  194. });
  195. }
  196. return false;
  197. })
  198. $('#body, #overlay').on('click', 'a.forward', function(e) {
  199. // Hide menu
  200. $('a.dropdown-menu-icon.active').parent().removeClass('active');
  201. $('a.dropdown-menu-icon.active').next('ul').hide();
  202. $('a.dropdown-menu-icon.active').removeClass('active');
  203. feed = $(this).parents('li.feed section');
  204. href = $(this).attr("href");
  205. if (!$('footer.undo', feed).is(":visible")) {
  206. show_loading();
  207. $.ajax({
  208. type: "GET",
  209. url: $(this).attr("href"),
  210. success: function(html) {
  211. hide_loading();
  212. $('footer', feed).hide();
  213. feed.append(html);
  214. $('form.viewers input[id^="token-input-"]', feed).focus()
  215. return false;
  216. }
  217. });
  218. }
  219. return false;
  220. });
  221. $('#body, #overlay').on('submit', 'form.viewers', function(e) {
  222. show_loading();
  223. feed = $(this).parents('li.feed');
  224. feed_id = feed.attr('id');
  225. $.ajax({
  226. type: "POST",
  227. url: $(this).attr('action'),
  228. data: $(this).serializeArray(),
  229. success: function(html) {
  230. hide_loading();
  231. feed.replaceWith(html);
  232. refresh('#' + feed_id);
  233. return false;
  234. }
  235. });
  236. return false;
  237. })
  238. // $("a[rel=gallery], a.popup").fancybox({
  239. // mouseWheel: false,
  240. // loop: false,
  241. // closeBtn: false,
  242. // arrows: false,
  243. // closeClick: true,
  244. // });
  245. // Update online status based on mouse move
  246. // var mouse_move_timeout = null;
  247. // var move_count = 0;
  248. // $("html").mousemove(function() {
  249. // move_count += 1;
  250. //
  251. // if(move_count == 10) {
  252. // move_count = 0;
  253. // clearTimeout(mouse_move_timeout);
  254. // update_status('online');
  255. // mouse_move_timeout = setTimeout("update_status('away')", 30000);
  256. // }
  257. //
  258. // });
  259. /**
  260. * Mark as Read
  261. */
  262. var mark_as_read_timer = null;
  263. $("#body, #overlay").on('mouseenter', 'li.unread > section', function() {
  264. post_id = $(this).parent().attr('id');
  265. // li.feed
  266. mark_as_read_timer = setTimeout(function() {
  267. mark_as_read(post_id);
  268. }, 50);
  269. })
  270. $('#body').on('mouseleave', 'li.unread > section', function() {
  271. id = $(this).parent().attr('id');
  272. if (mark_as_read_timer) {
  273. clearTimeout(mark_as_read_timer)
  274. }
  275. });
  276. $('#body, #overlay').on('click', 'a.dropdown-menu-icon', function() {
  277. $('div#filters > ul').hide();
  278. if (!$(this).next('ul').is(':visible')) {
  279. // remove current active
  280. $('div.dropdown-menu.active ul').hide();
  281. $('div.dropdown-menu.active').removeClass('active');
  282. $('a.dropdown-menu-icon.active').removeClass('active');
  283. }
  284. $(this).parent().toggleClass('active');
  285. $(this).toggleClass('active');
  286. $(this).next('ul').toggle();
  287. return false;
  288. })
  289. $('#body, #overlay, #popup').on('click', 'form.new footer a', function() {
  290. var id = $(this).attr('id');
  291. var form = $(this).parents('form');
  292. // deactive all actived
  293. $('tr.toggle:not(#' + id + ')', form).hide();
  294. $('footer a:not(#' + id + ')', form).removeClass('active');
  295. $(this).toggleClass('active');
  296. $('tr#' + id, form).toggle();
  297. if (id == 'send-to' && $('tr#send-to', form).is(':visible')) {
  298. $('tr#send-to .token-input-list input[type="text"]').focus();
  299. }
  300. });
  301. /* Drop down menu */
  302. $('header nav a.user"').click(function() {
  303. var dm = $(this).next('ul.dropdown-menu');
  304. if (dm.hasClass('hidden')) {
  305. $('header nav ul.dropdown-menu').addClass('hidden');
  306. dm.removeClass('hidden');
  307. $('header nav .dropdown-menu-active').removeClass('dropdown-menu-active');
  308. $(this).addClass('dropdown-menu-active');
  309. } else {
  310. dm.addClass('hidden');
  311. $(this).removeClass('dropdown-menu-active');
  312. }
  313. return false;
  314. });
  315. $('header nav a.view-notifications').click(function() {
  316. var dm = $(this).next('ul.dropdown-menu');
  317. if (dm.hasClass('hidden')) {
  318. $('header nav ul.dropdown-menu').addClass('hidden');
  319. $('header nav ul.notifications').removeClass('hidden');
  320. $('header nav .dropdown-menu-active').removeClass('dropdown-menu-active');
  321. $(this).addClass('dropdown-menu-active');
  322. $('header nav ul.notifications .updating').show();
  323. $.ajax({
  324. type: "OPTIONS",
  325. cache: false,
  326. url: '/notifications',
  327. dataType: "json",
  328. success: function(resp) {
  329. $('header nav ul.notifications .updating').fadeOut();
  330. var item = $('#unread-notification-counter');
  331. value = resp.unread_notifications_count;
  332. item.html(value);
  333. var title = document.title;
  334. var pattern = /^\(.*?\) /gi;
  335. var count = title.match(pattern);
  336. if (value != 0) {
  337. $('#unread-notification-counter').removeClass('grey');
  338. if (count == null) {
  339. document.title = '(' + $('#unread-notification-counter').html() + ') ' + title;
  340. } else {
  341. document.title = title.replace(count, '(' + $('#unread-notification-counter').html() + ') ');
  342. }
  343. } else {
  344. $('#unread-notification-counter').addClass('grey');
  345. if (count != null) {
  346. document.title = title.replace(count, '');
  347. }
  348. }
  349. $('header nav ul.notifications ul').html(resp.body);
  350. refresh('header nav ul.notifications ul');
  351. }
  352. });
  353. } else {
  354. dm.addClass('hidden');
  355. $(this).removeClass('dropdown-menu-active');
  356. }
  357. return false;
  358. })
  359. /* End dropdown menu */
  360. // $('#scroll-to-top').scroll_to_top({
  361. // 'min': 400,
  362. // 'fadeSpeed': 500,
  363. // });
  364. // Refresh page after press Back button on browser
  365. $(window).bind('popstate', function(event) {
  366. // if the event has our history data on it, load the page fragment with
  367. // AJAX
  368. console.log(event);
  369. var state = event.originalEvent.state;
  370. if (state) {
  371. console.log(state);
  372. data = sessionStorage[state.path];
  373. if (state.path.indexOf('#!') != -1) {
  374. open_in_overlay_mode(state.path, data);
  375. } else {
  376. open_in_async_mode(state.path, state.rel, data);
  377. }
  378. }
  379. });
  380. $('#body, #overlay').on('click', 'a.rename', function() {
  381. filename = $(this).data('name');
  382. file_id = $(this).attr('data-id');
  383. href = $(this).attr('href');
  384. var new_name = prompt('Enter a new name for "' + filename + '"');
  385. if (!new_name) {
  386. return false;
  387. }
  388. show_loading();
  389. $.ajax({
  390. type: "POST",
  391. headers: {
  392. 'X-CSRFToken': get_cookie('_csrf_token')
  393. },
  394. data: {
  395. name: new_name
  396. },
  397. url: href,
  398. success: function(resp) {
  399. hide_loading();
  400. console.log(file_id);
  401. $('#body li#' + file_id).replaceWith(resp);
  402. $('#overlay li#' + file_id).replaceWith(resp);
  403. }
  404. });
  405. return false;
  406. })
  407. $('#body, #overlay, #popup').on('click', 'a.toggle', function() {
  408. var new_class = $(this).data('class');
  409. var new_href = $(this).data('href');
  410. var new_name = $(this).data('name');
  411. var new_title = $(this).data('title');
  412. var href = $(this).attr('href');
  413. if (new_class != undefined) {
  414. $(this).data('class', $(this).attr('class'));
  415. }
  416. $(this).data('name', $(this).html());
  417. $(this).data('href', href);
  418. $(this).data('title', $(this).attr('title'));
  419. if (new_class != undefined) {
  420. $(this).attr('class', new_class.replace('toggle', '') + ' toggle');
  421. }
  422. $(this).html(new_name);
  423. $(this).attr('href', new_href);
  424. $(this).attr('title', new_title);
  425. if (href.indexOf('/pin') != -1) {
  426. $(this).parents('section').parents('li').addClass('pinned');
  427. } else if (href.indexOf('/unpin') != -1) {
  428. $(this).parents('section').parents('li').removeClass('pinned');
  429. }
  430. if (href.indexOf('/like') != -1) {
  431. likes = $(this).next('span.likes');
  432. counter_id = '#' + likes.children('span.counter').attr('id');
  433. incr(counter_id, 1);
  434. if ($(counter_id).html() != '0') {
  435. likes.removeClass('hidden');
  436. } else {
  437. likes.addClass('hidden');
  438. }
  439. } else if (href.indexOf('/unlike') != -1) {
  440. likes = $(this).next('span.likes');
  441. counter_id = '#' + likes.children('span.counter').attr('id');
  442. incr(counter_id, -1);
  443. if ($(counter_id).html() != '0') {
  444. likes.removeClass('hidden');
  445. } else {
  446. likes.addClass('hidden');
  447. }
  448. }
  449. if (href != '#') {
  450. $.ajax({
  451. type: "POST",
  452. headers: {
  453. 'X-CSRFToken': get_cookie('_csrf_token')
  454. },
  455. url: href,
  456. success: function(resp) {
  457. return false;
  458. }
  459. });
  460. }
  461. return false;
  462. });
  463. $('#body, #overlay').on("click", 'a.next', function() {
  464. $('span.loading', this).css('display', 'inline-block');
  465. $('span.text', this).html('Loading...');
  466. var more_button = $(this).parents('li');
  467. console.log('more button clicked');
  468. $.global.loading = true;
  469. $.ajax({
  470. type: "OPTIONS",
  471. cache: false,
  472. url: $(this).attr('href'),
  473. dataType: "html",
  474. success: function(html) {
  475. $.global.loading = false;
  476. more_button.replaceWith(html);
  477. refresh('#body');
  478. refresh('#overlay');
  479. }
  480. });
  481. return false;
  482. });
  483. // $('#popup').on('click', 'a.add-member', function() {
  484. // var element = $(this);
  485. // var href = $(this).attr('href');
  486. // $.ajax({
  487. // type: "POST",
  488. // headers: {
  489. // 'X-CSRFToken': get_cookie('_csrf_token')
  490. // },
  491. // url: href,
  492. // success: function(resp) {
  493. // console.log('Added');
  494. // }
  495. // });
  496. // href = href.replace('/remove_member', '/add_member');
  497. // element.replaceWith('<a href="' + href + '" class="button remove-member">Remove from Group</a>');
  498. // return false;
  499. // });
  500. $('#popup').on('click', 'a.invite', function() {
  501. var element = $(this);
  502. var href = $(this).attr('href');
  503. $.ajax({
  504. type: "POST",
  505. headers: {
  506. 'X-CSRFToken': get_cookie('_csrf_token')
  507. },
  508. url: href,
  509. success: function(resp) {
  510. console.log('Invited');
  511. }
  512. });
  513. element.replaceWith('<a href="#" class="button"> ✔ Sent</a>');
  514. return false;
  515. });
  516. $('#body, #overlay, #popup').on('click', 'a.follow', function() {
  517. var element = $(this);
  518. var href = $(this).attr('href');
  519. $.ajax({
  520. type: "POST",
  521. headers: {
  522. 'X-CSRFToken': get_cookie('_csrf_token')
  523. },
  524. url: href,
  525. success: function(resp) {
  526. console.log('Followed');
  527. }
  528. });
  529. href = href.replace('/follow', '/unfollow');
  530. if (window.location.href.indexOf('/group/') != -1) {
  531. element.replaceWith('<a href="' + href + '" class="button unfollow">Unfollow</a>');
  532. }
  533. else { // user page
  534. if ($(this).parents('#right-sidebar').length > 0) {
  535. element.replaceWith('<a href="' + href + '" class="unfollow">- Remove Contact</a>');
  536. } else {
  537. element.replaceWith('<a href="' + href + '" class="button unfollow">Remove from Contacts</a>');
  538. }
  539. }
  540. return false;
  541. });
  542. $('#body, #overlay, #popup').on('click', 'a.unfollow', function() {
  543. var element = $(this);
  544. var href = $(this).attr('href');
  545. $.ajax({
  546. type: "POST",
  547. headers: {
  548. 'X-CSRFToken': get_cookie('_csrf_token')
  549. },
  550. url: href,
  551. success: function(resp) {
  552. console.log('Unfollowed');
  553. }
  554. });
  555. href = href.replace('/unfollow', '/follow');
  556. if (window.location.href.indexOf('/group/') != -1) {
  557. element.replaceWith('<a href="' + href + '" class="button follow">Follow</a>');
  558. } else {
  559. if ($(this).parents('#right-sidebar').length > 0) {
  560. element.replaceWith('<a href="' + href + '" class="follow">+ Add Contact</a>');
  561. } else {
  562. element.replaceWith('<a href="' + href + '" class="button follow">Add to Contacts</a>');
  563. }
  564. }
  565. return false;
  566. });
  567. $('div#body').on('click', 'a.unread-posts', function() {
  568. $('ul#stream > li.hidden').removeClass('hidden').fadeIn();
  569. $('div#unread-messages').hide();
  570. $('div#unread-messages span#unread').html('0');
  571. return false;
  572. })
  573. $('#overlay').on("submit", 'form#profile-update', function() {
  574. $.ajax({
  575. type: "POST",
  576. cache: false,
  577. url: $(this).attr('action'),
  578. data: $(this).serializeArray(),
  579. success: function(resp) {
  580. if (resp == "Error") {
  581. show_error()
  582. } else {
  583. window.location.href = window.location.pathname;
  584. }
  585. return false;
  586. }
  587. });
  588. return false;
  589. });
  590. $('#popup').on("submit", 'form.new-group', function() {
  591. $.ajax({
  592. type: "POST",
  593. cache: false,
  594. url: $(this).attr('action'),
  595. data: $(this).serializeArray(),
  596. success: function(group_id) {
  597. open_in_async_mode('/group/' + group_id, null, null, function() {
  598. open_in_popup_mode('/search?query=&type=people&ref=group-' + group_id);
  599. });
  600. return false;
  601. }
  602. });
  603. return false;
  604. });
  605. $('#body, #overlay, #popup').on("submit", 'form.new:not(.overlay)', function() {
  606. button = $('input[type="submit"]', this);
  607. button.val('Posting...');
  608. var form = $(this);
  609. show_loading();
  610. $('span.empty').remove();
  611. if ($('textarea.mention', form).length != 0) {
  612. $('textarea.mention', form).mentionsInput('val', function(text) {
  613. $('form.new textarea.marked-up').val(text);
  614. });
  615. }
  616. // clear autosave form
  617. if (window.location.href.indexOf('#!') != -1) {
  618. url = window.location.hash;
  619. } else {
  620. url = window.location.href;
  621. }
  622. $.global.clear_autosave[url] = $(this).attr('id');
  623. // clear preload
  624. $.global.preload = null;
  625. $('textarea.mention', form).val('').focus();
  626. // Reset autocomplete
  627. $('textarea.mention', form).mentionsInput('reset');
  628. // $('input.autocomplete').tokenInput('clear');
  629. // Unfocus input autocomplete
  630. $('input.autocomplete', form).blur();
  631. // Reset attachments container
  632. $('div#attachments', form).empty();
  633. $("textarea", form).css('height', '');
  634. $.ajax({
  635. type: "POST",
  636. cache: false,
  637. headers: {
  638. 'X-CSRFToken': get_cookie('_csrf_token')
  639. },
  640. url: $(this).attr('action'),
  641. data: $(this).serializeArray(),
  642. error: function(jqXHR, textStatus, errorThrown) {
  643. show_error();
  644. },
  645. success: function(resp) {
  646. button.val('Share');
  647. hide_loading();
  648. feed_id = $(resp).attr('id');
  649. if ($('#popup').is(':visible')) {
  650. open_in_async_mode('/feed/' + feed_id.split('-')[1]);
  651. } else {
  652. if ($('#' + feed_id).length == 0) {
  653. $('ul#stream').prepend(resp);
  654. }
  655. feed_id = $('ul#stream li.feed').attr('id');
  656. refresh('ul#stream #' + feed_id);
  657. }
  658. }
  659. });
  660. return false;
  661. });
  662. $('#body, #overlay').on('click', 'a.update-comment', function() {
  663. // Hủy bỏ tất cả các comment đang edit
  664. $('li.comment div.update-comment').addClass('hidden');
  665. $('li.comment div.message').removeClass('hidden')
  666. $('li.comment div.footer').removeClass('hidden');
  667. $('li.comment a.update-comment.hidden').removeClass('hidden');
  668. $('li.comment div.update-comment textarea.mention').mentionsInput("reset");
  669. //
  670. $(this).addClass('hidden');
  671. comment_id = $(this).parents('li.comment').attr('id');
  672. update_form = $('#' + comment_id + ' div.update-comment')
  673. if (update_form.is(':visible')) {
  674. update_form.addClass('hidden');
  675. $('#' + comment_id + ' div.message').removeClass('hidden')
  676. $('#' + comment_id + ' div.footer').removeClass('hidden');
  677. }
  678. else {
  679. update_form.removeClass('hidden');
  680. $('#' + comment_id + ' div.message').addClass('hidden')
  681. $('#' + comment_id + ' div.footer').addClass('hidden');
  682. text = $('.raw-message', update_form).text();
  683. setTimeout(function() {
  684. $('textarea.mention', update_form).val(text);
  685. $('textarea.mention', update_form).mentionsInput("update");
  686. $('textarea.mention', update_form).focus();
  687. }, 10)
  688. }
  689. })
  690. $('#body, #overlay').on('submit', 'div.update-comment form', function() {
  691. var comment_id = $(this).parents('li.comment').attr('id');
  692. $('textarea.mention', this).mentionsInput('val', function(text) {
  693. $('#' + comment_id + ' form.update-comment textarea.marked-up').val(text);
  694. });
  695. var textarea = $('textarea.mention', this);
  696. textarea.attr('readonly', 'readonly');
  697. $.ajax({
  698. type: "POST",
  699. headers: {
  700. 'X-CSRFToken': get_cookie('_csrf_token')
  701. },
  702. url: $(this).attr('action'),
  703. data: $(this).serializeArray(),
  704. error: function(jqXHR, textStatus, errorThrown) {
  705. textarea.attr("readonly", false);
  706. textarea.attr('background', '#fff');
  707. },
  708. success: function(text) {
  709. textarea.attr("readonly", false);
  710. $('#' + comment_id + ' div.message .text').html(text);
  711. $('#' + comment_id + ' div.update-comment .raw-comment').html(text);
  712. $('#' + comment_id + ' div.update-comment').addClass('hidden');
  713. $('#' + comment_id + ' a.update-comment').removeClass('hidden');
  714. $('#' + comment_id + ' div.message').removeClass('hidden')
  715. $('#' + comment_id + ' div.footer').removeClass('hidden')
  716. }
  717. })
  718. return false;
  719. })
  720. $('#body, #overlay').on('keydown', 'form.new-comment textarea, form.update-comment textarea', function(e) {
  721. if (e.keyCode == 13) { // Enter
  722. if (e.ctrlKey || e.shiftKey) {
  723. var val = this.value;
  724. if (typeof this.selectionStart == "number" && typeof this.selectionEnd == "number") {
  725. var start = this.selectionStart;
  726. this.value = val.slice(0, start) + "\n" + val.slice(this.selectionEnd);
  727. this.selectionStart = this.selectionEnd = start + 1;
  728. } else if (document.selection && document.selection.createRange) {
  729. this.focus();
  730. var range = document.selection.createRange();
  731. range.text = "\r\n";
  732. range.collapse(false);
  733. range.select();
  734. }
  735. $(this).trigger('change'); // update textarea height
  736. }
  737. else {
  738. new_comment_form = $(this).parents('form');
  739. var ts = Math.round((new Date()).getTime() / 1000);
  740. if (new_comment_form.data('last_submited') === undefined ||
  741. ts - new_comment_form.data('last_submited') > 1) {
  742. new_comment_form.data('last_submited', ts);
  743. new_comment_form.trigger('submit');
  744. }
  745. }
  746. return false;
  747. }
  748. else if (e.keyCode == 27) { // ESC
  749. var comment_id = $(this).parents('li.comment').attr('id');
  750. if ($('#' + comment_id + ' div.update-comment').length > 0) {
  751. $('#' + comment_id + ' div.update-comment').addClass('hidden');
  752. $('#' + comment_id + ' a.update-comment').removeClass('hidden');
  753. $('#' + comment_id + ' div.message').removeClass('hidden')
  754. $('#' + comment_id + ' div.footer').removeClass('hidden')
  755. }
  756. }
  757. });
  758. $("#body, #overlay").on("submit", 'form.new-comment', function() {
  759. var submit_button = $('input[type="submit"]', this);
  760. var submit_button_text = submit_button.val();
  761. submit_button.val('...');
  762. submit_button.attr('disabled', 'disabled');
  763. var textarea = $('textarea.mention', this);
  764. textarea.attr('readonly', 'readonly');
  765. comments_list_id = $(this).parents('ul.comments').attr('id');
  766. var feed_id = $(this).parents('li.feed').attr('id');
  767. $.global.disable_realtime_update = feed_id;
  768. console.log('disable realtime update: ' + feed_id);
  769. $('textarea.mention', this).mentionsInput('val', function(text) {
  770. $('#' + feed_id + ' form.new-comment textarea.marked-up').val(text);
  771. });
  772. // clear autosave form
  773. if (window.location.href.indexOf('#!') != -1) {
  774. url = window.location.hash;
  775. } else {
  776. url = window.location.href;
  777. }
  778. $.global.clear_autosave[url] = $(this).attr('id');
  779. // clear preload
  780. $.global.preload = null;
  781. $.ajax({
  782. type: "POST",
  783. headers: {
  784. 'X-CSRFToken': get_cookie('_csrf_token')
  785. },
  786. url: $(this).attr('action'),
  787. data: $(this).serializeArray(),
  788. error: function(jqXHR, textStatus, errorThrown) {
  789. show_error();
  790. submit_button.val(submit_button_text);
  791. submit_button.attr('disabled', false);
  792. textarea.attr("readonly", false);
  793. },
  794. success: function(resp) {
  795. // var offset_top = null;
  796. // var last_comment = $('#' + feed_id + ' li.comment:last');
  797. //
  798. // if (last_comment.length == 0) {
  799. // if ($('#' + feed_id).length != 0) {
  800. // offset_top = $('#' + feed_id).offset().top
  801. // }
  802. //
  803. // } else {
  804. // offset_top = last_comment.offset().top
  805. // }
  806. //
  807. // if (offset_top != null) {
  808. // $('body').scrollTop(offset_top - 250);
  809. // }
  810. submit_button.val(submit_button_text);
  811. submit_button.attr('disabled', false);
  812. textarea.attr("readonly", false);
  813. textarea.css('height', '');
  814. textarea.mentionsInput('reset');
  815. // remove read-receipts
  816. // $('#body #' + feed_id + ' a.quick-stats .receipt-icon').remove();
  817. // $('#body #' + feed_id + ' a.quick-stats .read-receipts-count').remove();
  818. // $('#body #' + feed_id + ' li.read-receipts').html('<i class="receipt-icon"></i> Seen by no one.');
  819. // $('#overlay #' + feed_id + ' a.quick-stats .receipt-icon').remove();
  820. // $('#overlay #' + feed_id + ' a.quick-stats .read-receipts-count').remove();
  821. // $('#overlay #' + feed_id + ' li.read-receipts').html('<i class="receipt-icon"></i> Seen by no one.');
  822. // Clear and reset comment box
  823. $('#' + comments_list_id + " form.new-comment input[name='reply_to']").val('');
  824. $('#' + comments_list_id + " form.new-comment textarea.mention").val('').focus();
  825. // $('#' + comments_list_id + " form.new-comment textarea.mention").css('height', '26px');
  826. // reset textarea height
  827. $('#' + comments_list_id + ' form.new-comment div.attachments').empty();
  828. $('#' + comments_list_id + ' form.new-comment input[name="attachments"]').val('');
  829. var comment = $(resp);
  830. if ($('#' + comment.attr('id')).length == 0) {
  831. $('#' + comments_list_id + ' div.comments-list').append(resp);
  832. incr('#body #' + feed_id + ' .quick-stats .comment-count', 1);
  833. incr('#body #' + feed_id + ' .comments-list .comment-count', 1);
  834. incr('#overlay #' + feed_id + ' .quick-stats .comment-count', 1);
  835. incr('#overlay #' + feed_id + ' .comments-list .comment-count', 1);
  836. refresh('#' + comments_list_id);
  837. }
  838. }
  839. })
  840. return false;
  841. });
  842. $("#body, #overlay").on("click", 'a.toggle-comments', function(e) {
  843. comments = $('ul.comments', $(this).parents('footer'));
  844. comments.toggle();
  845. return false;
  846. });
  847. $("#body, #overlay").on("click", 'a.reply', function(e) {
  848. console.log('a.reply clicked');
  849. // Phải dùng attr(data-) vì comment_id là số quá to, .data() nó parse ra số -> sai mất
  850. comment_id = $(this).attr('data-comment-id')
  851. username = $(this).data('owner-name');
  852. user_id = $(this).attr('data-owner-id');
  853. if (user_id) {
  854. comments_list = $(this).parents('ul.comments:first');
  855. } else {
  856. comments_list = $('ul.comments', $(this).parents('footer'));
  857. }
  858. if (!comments_list.is(":visible")) {
  859. comments_list.toggle();
  860. }
  861. mention_textarea = $('li.new-comment textarea.mention', comments_list)
  862. mention_textarea.mentionsInput('reset');
  863. $('li.write-a-comment', comments_list).remove();
  864. $('li.new-comment', comments_list).show();
  865. mention_textarea.focus();
  866. if (username) {
  867. var marked_up_text = '@[' + username + '](user:' + user_id + ')'
  868. mention_textarea.val(marked_up_text);
  869. mention_textarea.mentionsInput("update");
  870. $('li.new-comment input[name="reply_to"]', comments_list).val(comment_id);
  871. mention_textarea.val(mention_textarea.val() + ': ');
  872. } else {
  873. mention_textarea.caretToEnd();
  874. }
  875. // $('li.new-comment textarea', comments_list).elastic();
  876. // mention_textarea.css('height', '26px');
  877. preload_autocomplete();
  878. return false;
  879. });
  880. $('#body, #overlay').on('click', 'li.comment a.see-changes', function() {
  881. comment_id = $(this).parents('li.comment').attr('id');
  882. $('#' + comment_id + ' .text').toggleClass('hidden');
  883. $('div.tipsy').remove();
  884. })
  885. $('#body, #overlay').on('click', 'a.remove-comment', function() {
  886. var r = confirm("Delete this comment?");
  887. if (r == true) {
  888. comment_id = $(this).parents('li').attr('id');
  889. $('#body #' + comment_id).fadeOut().remove();
  890. $('#overlay #' + comment_id).fadeOut().remove();
  891. $.ajax({
  892. type: "POST",
  893. headers: {
  894. 'X-CSRFToken': get_cookie('_csrf_token')
  895. },
  896. url: $(this).attr('href')
  897. })
  898. }
  899. return false;
  900. })
  901. $("#body, #overlay").on("click", 'a.mark', function(e) {
  902. // $.global.mouse_inside_overlay = false;
  903. $('html').trigger('click');
  904. count = $(this).data('count');
  905. counter_id = $(this).data('counter-id');
  906. if (count) {
  907. count = parseInt(count);
  908. } else {
  909. count = 0;
  910. }
  911. var feed_id = $(this).parents('section').parents('li').attr('id');
  912. $('#body #' + feed_id).fadeOut().remove();
  913. $('#overlay #' + feed_id).fadeOut().remove();
  914. incr('#' + counter_id, count);
  915. // Send request to server (in background)
  916. var href = $(this).attr('href');
  917. $.ajax({
  918. type: "POST",
  919. headers: {
  920. 'X-CSRFToken': get_cookie('_csrf_token')
  921. },
  922. url: href
  923. })
  924. return false;
  925. });
  926. $("nav").on("click", 'a.notification', function(e) {
  927. try {
  928. href = $(this).attr('href').split('#!')[1];
  929. redirect_to = href.split('?')[1].split('=')[1];
  930. $(this).removeClass('unread');
  931. } catch (err) {// mark all as read: close overlay and reset counter
  932. $.ajax({
  933. type: "GET",
  934. url: $(this).attr('href')
  935. })
  936. $('#unread-notification-counter').html('0');
  937. $('#unread-notification-counter').addClass('grey');
  938. $('ul.notifications a.unread').removeClass('unread');
  939. var title = document.title;
  940. var pattern = /^\(.*?\) /gi;
  941. var count = title.match(pattern);
  942. document.title = title.replace(count, '');
  943. // $.global.mouse_inside_overlay = false;
  944. // $('header nav ul.dropdown-menu').addClass('hidden');
  945. // $('header nav .dropdown-menu-active').removeClass('dropdown-menu-active');
  946. return false;
  947. }
  948. open_in_async_mode(redirect_to);
  949. $.ajax({
  950. type: "POST",
  951. headers: {
  952. 'X-CSRFToken': get_cookie('_csrf_token')
  953. },
  954. url: href,
  955. success: function(count) {
  956. $('#unread-notification-counter').html(count);
  957. title = document.title;
  958. var pattern = /^\(.*?\) /gi;
  959. var counter = title.match(pattern);
  960. if (count == '0') {
  961. $('#unread-notification-counter').addClass('grey');
  962. document.title = title.replace(counter, '');
  963. } else {
  964. document.title = title.replace(counter, '(' + count + ') ');
  965. }
  966. }
  967. })
  968. return false;
  969. });
  970. $("#body, #overlay").on("click", 'a.remove-attachment', function() {
  971. console.log('remove-attachment clicked');
  972. form = $(this).parents('form');
  973. $.ajax({
  974. type: "POST",
  975. headers: {
  976. 'X-CSRFToken': get_cookie('_csrf_token')
  977. },
  978. url: $(this).attr("data-href"),
  979. success: function(id) {
  980. $('#attachment-' + id).remove();
  981. var files = $('input[name="attachments"]', form).val();
  982. files = files.replace(id + ',', '');
  983. $('input[name="attachments"]', form).val(files);
  984. }
  985. });
  986. return false;
  987. });
  988. /* ========================= End Message Actions ====================== */
  989. /**
  990. * Expand menu (left sidebar)
  991. */
  992. $("div#global").on("click", 'a.async', function() {
  993. if ($(this).hasClass('active') && $("#overlay").is(":visible")) {
  994. close_overlay();
  995. return false;
  996. }
  997. $('#left-sidebar li a.active').removeClass('active');
  998. $(this).addClass('active');
  999. $('.count', $(this)).fadeOut().remove();
  1000. var href = $(this).attr('href');
  1001. var rel = $(this).attr('rel');
  1002. open_in_async_mode(href, rel);
  1003. // Hide left sidebar (if is openned)
  1004. $('#global, #main').removeClass('global-default-styles');
  1005. $('#left-sidebar').removeClass('left-sidebar-default-styles');
  1006. return false;
  1007. });
  1008. // $('textarea.mention').keyup(function(e) {
  1009. // if (e.keyCode == 27) {
  1010. // // ESC close mentions autocomplete list
  1011. // $('div.mentions-autocomplete-list').empty().hide();
  1012. //
  1013. //
  1014. // }
  1015. // });
  1016. // ============ Search box =============
  1017. $('form#search-box').on('click', '.reset', function() {
  1018. $(this).fadeOut(100);
  1019. $('form#search-box input').val('');
  1020. $('form#search-box input').focus();
  1021. $('form#search-box ul.dropdown-menu').hide();
  1022. return false;
  1023. });
  1024. $('form#search-box input').focus(function(e) {
  1025. show_searchbox_dropdown($(this).val());
  1026. $(this).addClass('highlight');
  1027. $("form#search-box i.search-icon").addClass("highlight");
  1028. if ($('form#search-box input').val().length > 0) {
  1029. $('form#search-box .reset').show();
  1030. }
  1031. });
  1032. var typing_timer;
  1033. $('form#search-box input[name="query"]').keyup(function(e) {
  1034. if (e.keyCode != 27) {// not esc
  1035. query = $(this).val();
  1036. if (e.keyCode == 40) { // down
  1037. var selected = $("form#search-box .dropdown-menu a.selected");
  1038. if (selected.length == 0) {
  1039. $("form#search-box .dropdown-menu li:first a").addClass('selected');
  1040. } else {
  1041. selected.removeClass("selected");
  1042. if (selected.parent().next().length == 0) {
  1043. selected.parents('ul').children('li').first().children().addClass("selected");
  1044. } else {
  1045. selected.parent().next().children().addClass("selected");
  1046. }
  1047. }
  1048. return false;
  1049. } else if (e.keyCode === 38) { // up
  1050. var selected = $("form#search-box .dropdown-menu a.selected");
  1051. if (selected.length == 0) {
  1052. $("form#search-box .dropdown-menu li:last a").addClass('selected');
  1053. }
  1054. selected.removeClass("selected");
  1055. if (selected.parent().prev().length == 0) {
  1056. selected.parents('ul').children('li').last().children().addClass("selected");
  1057. } else {
  1058. selected.parent().prev().children().addClass("selected");
  1059. }
  1060. return false;
  1061. } else {
  1062. if (query != '') {
  1063. show_searchbox_dropdown(query);
  1064. } else {
  1065. $('form#search-box ul.dropdown-menu').hide();
  1066. $('form#search-box .reset').hide();
  1067. $('form#search-box .spinner').hide();
  1068. return false;
  1069. }
  1070. }
  1071. if (query.length >= 1) {
  1072. if (e.keyCode != 13) {
  1073. typing_timer = setTimeout(function() {
  1074. // preload result
  1075. var url = $('form#search-box').attr('action');
  1076. query = $('form#search-box input[name="query"]').val();
  1077. url = url + '?query=' + query;
  1078. try {
  1079. $.global.preload_request.abort();
  1080. } catch (err) {
  1081. }
  1082. $.global.preloading = query;
  1083. $.global.preload_request = $.ajax({
  1084. type: "OPTIONS",
  1085. url: url,
  1086. cache: true,
  1087. headers: {
  1088. 'X-CSRFToken': get_cookie('_csrf_token')
  1089. },
  1090. dataType: "json",
  1091. success: function(resp) {
  1092. if ( typeof $.global.preload == 'undefined' || $.global.preload == null) {
  1093. $.global.preload = {};
  1094. }
  1095. $.global.preload[query] = resp;
  1096. if ($.global.preload_show_results == true) {
  1097. $.global.preload_show_results = false;
  1098. show_results(resp);
  1099. }
  1100. }
  1101. });
  1102. }, 300);
  1103. }
  1104. else { // enter key pressed
  1105. console.log('enter key pressed')
  1106. return false;
  1107. }
  1108. }
  1109. }
  1110. });
  1111. $('form#search-box input[name="query"]').keydown(function(e) {
  1112. clearTimeout(typing_timer);
  1113. });
  1114. function show_results(resp) {
  1115. hide_searchbox_dropdown();
  1116. hide_loading();
  1117. if (resp.title) {
  1118. $.global.title = document.title;
  1119. update_title(resp.title);
  1120. }
  1121. if (!$.global.body) {
  1122. $.global.body = $("#body").html();
  1123. $.global.scroll = $("body").scrollTop();
  1124. console.log($.global.scroll);
  1125. }
  1126. // $("#left-sidebar").hide();
  1127. $("#body").hide();
  1128. if (resp.body) {
  1129. // resp.body += "<a id='close' class='close-icon' onclick='close_overlay();'></a>";
  1130. $('div#overlay').html(resp.body);
  1131. } else {
  1132. // resp += "<a id='close' class='close-icon' onclick='close_overlay();'></a>";
  1133. $('div#overlay').html(resp);
  1134. }
  1135. $('div#overlay').show();
  1136. $.global.scroll = $("body").scrollTop();
  1137. $('body').animate({
  1138. scrollTop: 0
  1139. }, 'fast');
  1140. refresh('div#overlay');
  1141. }
  1142. $("header nav").on('submit', 'form#search-box', function() {
  1143. $("form#search-box input[name='query']").blur();
  1144. hide_searchbox_dropdown();
  1145. var selected = $("form#search-box .dropdown-menu a.selected");
  1146. if (selected.length != 0 && selected.attr('href').indexOf('/search?query=') == -1) {
  1147. selected.trigger('click');
  1148. return false;
  1149. }
  1150. var url = $(this).attr('action');
  1151. var query = $('input[name="query"]', this).val();
  1152. if ( typeof $.global.preload == 'undefined' || $.global.preload == null) {
  1153. $.global.preload = {};
  1154. }
  1155. if ($.global.preload[query] != null) {
  1156. show_results($.global.preload[query]);
  1157. } else if ($.global.preloading == query) {
  1158. console.log('wait preload results...');
  1159. $.global.preload_show_results = true;
  1160. show_loading();
  1161. } else {
  1162. show_loading();
  1163. href = url + '?query=' + query;
  1164. // try {
  1165. // $.global.search.abort();
  1166. // } catch (err) {}
  1167. $.global.search = $.ajax({
  1168. type: "OPTIONS",
  1169. cache: true,
  1170. dataType: 'json',
  1171. url: href,
  1172. headers: {
  1173. 'X-CSRFToken': get_cookie('_csrf_token')
  1174. },
  1175. error: function(jqXHR, textStatus, errorThrown) {
  1176. show_error();
  1177. hide_loading();
  1178. },
  1179. success: function(resp) {
  1180. hide_loading();
  1181. href = '#!' + href;
  1182. if ($.global.history.length == 10) {
  1183. key = $.global.history.pop();
  1184. sessionStorage.removeItem(key);
  1185. console.log('Remove ' + key + ' from Session Storage');
  1186. }
  1187. sessionStorage[href] = JSON.stringify(resp);
  1188. // save to session storage (for Back button)
  1189. $.global.history.unshift(href);
  1190. history.pushState({
  1191. rel: null,
  1192. path: href
  1193. }, 'Jupo', href);
  1194. show_results(resp);
  1195. return false;
  1196. }
  1197. })
  1198. }
  1199. return false;
  1200. });
  1201. // =========== End search box ===========
  1202. $('#overlay').on("submit", 'form.overlay', function() {
  1203. var submit_button = $('input[type="submit"]', this);
  1204. var submit_button_text = submit_button.val();
  1205. submit_button.val('...');
  1206. submit_button.attr('disabled', 'disabled');
  1207. show_loading();
  1208. $('textarea.mention', this).mentionsInput('val', function(text) {
  1209. $('form.new textarea.marked-up').val(text);
  1210. });
  1211. $.ajax({
  1212. type: "POST",
  1213. cache: false,
  1214. url: $(this).attr('action'),
  1215. data: $(this).serializeArray(),
  1216. dataType: "json",
  1217. success: function(resp) {
  1218. hide_loading();
  1219. submit_button.val(submit_button_text);
  1220. submit_button.attr('disabled', false);
  1221. console.log(resp);
  1222. if (resp.redirect != undefined) {
  1223. open_in_async_mode(resp.redirect);
  1224. return false;
  1225. }
  1226. // Reload body
  1227. // if (resp.reload == true) {
  1228. // url = window.location.href;
  1229. // $.ajax({
  1230. // type: "POST",
  1231. // url: url,
  1232. // dataType: "json",
  1233. // success: function(resp) {
  1234. // console.log('reloaded');
  1235. // $.global.body = resp.body;
  1236. // $("#body").html(resp.body);
  1237. // $.global.scroll = $("body").scrollTop();
  1238. // refresh('div#body');
  1239. // }
  1240. // });
  1241. // }
  1242. //
  1243. // if (!$.global.body) {
  1244. // $.global.body = $("#body").html();
  1245. // $.global.scroll = $("body").scrollTop();
  1246. // console.log($.global.scroll);
  1247. // // console.log($.global.body);
  1248. // }
  1249. //
  1250. // // $("#left-sidebar").hide();
  1251. // $("#body").hide();
  1252. // if (resp.body) {
  1253. // $('div#overlay').html(resp.body);
  1254. // } else {
  1255. // $('div#overlay').html(resp);
  1256. // }
  1257. // ;
  1258. // $('div#overlay').show();
  1259. // $.global.scroll = $("body").scrollTop();
  1260. //
  1261. // $('body').animate({
  1262. // scrollTop: 0
  1263. // }, 'fast');
  1264. //
  1265. // refresh('div#overlay');
  1266. }
  1267. });
  1268. return false;
  1269. });
  1270. $("div#global").on("click", 'a.overlay', function() {
  1271. var href = $(this).attr('href');
  1272. console.log('overlay clicked: ' + href);
  1273. open_in_overlay_mode(href);
  1274. // Hide left sidebar (if is openned)
  1275. $('#global, #main').removeClass('global-default-styles');
  1276. $('#left-sidebar').removeClass('left-sidebar-default-styles');
  1277. return false;
  1278. });
  1279. $("div#global").on("click", 'a.popup', function() {
  1280. var href = $(this).attr('href');
  1281. open_in_popup_mode(href);
  1282. return false;
  1283. });
  1284. // $.global.mouse_inside_overlay = false;
  1285. // $('div#main').on('mouseenter', '#overlay', function() {
  1286. // // var hint = $('span#hint');
  1287. // // $.global.mouse_inside_overlay = true;
  1288. //
  1289. // // if(hint.hasClass('mouse-click')) {
  1290. // // hint.removeClass('mouse-click');
  1291. // // hint.addClass('esc');
  1292. // // hint.html('Press ESC to close');
  1293. // // }
  1294. // })
  1295. // $('div#main').on('mouseleave', '#overlay', function() {
  1296. // // var hint = $('span#hint');
  1297. // // $.global.mouse_inside_overlay = false;
  1298. //
  1299. // // if(!hint.hasClass('mouse-click')) {
  1300. // // hint.html('Press ESC or left mouse button to close');
  1301. // // hint.addClass('mouse-click');
  1302. // // hint.addClass('esc');
  1303. // // }
  1304. // })
  1305. // $('div#overlay').on('mouseover mouseout', function(e) {
  1306. // var hint = $('span#hint');
  1307. //
  1308. // if(e.type == 'mouseover') {
  1309. // $.global.mouse_inside_overlay = true;
  1310. //
  1311. // if(hint.hasClass('mouse-click')) {
  1312. // hint.removeClass('mouse-click');
  1313. // hint.addClass('esc');
  1314. // hint.html('Press ESC to close');
  1315. // }
  1316. //
  1317. // } else {
  1318. // $.global.mouse_inside_overlay = false;
  1319. //
  1320. // if(!hint.hasClass('mouse-click')) {
  1321. // hint.html('Press ESC or left mouse button to close');
  1322. // hint.addClass('mouse-click');
  1323. // hint.addClass('esc');
  1324. // }
  1325. // }
  1326. // });
  1327. // $("body").on('click', '#scroll-to-top, form#search-box input', function() {
  1328. // if ($('#overlay').is(":visible")) {
  1329. // // $.global.mouse_inside_overlay = true;
  1330. // }
  1331. // })
  1332. $('html').on('click', function(e) {
  1333. console.log(e)
  1334. // Scroll to Top
  1335. // if (e.target.id == 'header-container' || e.target.id == 'top-panel-bg') {
  1336. // $('body').animate({
  1337. // scrollTop: 0
  1338. // }, 'fast');
  1339. // }
  1340. // TODO: disable text selection on double click on whitespace area
  1341. if (e.target.name != 'query' && !$('div#overlay').is(":visible")) {
  1342. hide_searchbox_dropdown();
  1343. }
  1344. if (e.target.className == 'background' && $('#popup').is(':visible')) {
  1345. close_popup();
  1346. }
  1347. if (e.target.name != 'query') {
  1348. hide_searchbox_dropdown();
  1349. }
  1350. // Hide left sidebar (if is openned)
  1351. if (e.target.className != 'menu-icon') {
  1352. $('#global, #main').removeClass('global-default-styles');
  1353. $('#left-sidebar').removeClass('left-sidebar-default-styles');
  1354. }
  1355. $('div#filters > ul').hide();
  1356. $('a.dropdown-menu-icon.active').parent().removeClass('active');
  1357. $('a.dropdown-menu-icon.active').next('ul').hide();
  1358. $('a.dropdown-menu-icon.active').removeClass('active');
  1359. $('header nav ul.dropdown-menu').addClass('hidden');
  1360. $('header nav .dropdown-menu-active').removeClass('dropdown-menu-active');
  1361. // Hide contacts search
  1362. $('#friends-online form input').val('');
  1363. $('#friends-online div.results').html('').addClass('hidden');
  1364. // if (!$.global.mouse_inside_overlay && !$('#body').is(":visible") && e.target.nodeName != 'SELECT') {
  1365. //
  1366. // close_overlay();
  1367. //
  1368. // // refresh();
  1369. // }
  1370. });
  1371. $("#body, #overlay").on('click', 'a.see-more', function() {
  1372. $(this).prev('div').hide();
  1373. $(this).next('div.hidden').show();
  1374. $(this).hide();
  1375. })
  1376. $("#body, #overlay").on("click", '.current', function() {
  1377. $(".current ul").remove();
  1378. $(".current").addClass("async");
  1379. $(".current").removeClass("current");
  1380. });
  1381. $("body").on('submit', "#subscription", function() {
  1382. $.ajax({
  1383. type: "POST",
  1384. url: '/notify_me',
  1385. data: $(this).serializeArray(),
  1386. });
  1387. $('div#footer').fadeOut(0);
  1388. $('div#intro h1').fadeOut(0, function() {
  1389. $('div#intro h1').html('Thanks!').fadeIn('fast');
  1390. });
  1391. $('div.info').fadeOut(0, function() {
  1392. $('div.info').html("You're now in the waiting list.<br>We'll email you when Jupo is ready.").fadeIn(3000);
  1393. });
  1394. return false;
  1395. })
  1396. // Invite form
  1397. // $('#body').on('submit', 'form#invite', function() {
  1398. // var msg = $('span', this);
  1399. // var input = $('input[name="email"]', this);
  1400. // $.ajax({
  1401. // type: "POST",
  1402. // url: $(this).attr('action'),
  1403. // data: $(this).serializeArray(),
  1404. // success: function(message) {
  1405. // msg.html(message);
  1406. // input.val('').focus();
  1407. // }
  1408. // });
  1409. // return false;
  1410. // })
  1411. // $('#body').on('keyup', 'form#invite input[name="email"]', function() {
  1412. // var email = $(this).val();
  1413. // if (email != '') {
  1414. // $('form#invite span'…

Large files files are truncated, but you can click here to view the full file