app.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. window._ = require('lodash');
  2. window.Popper = require('popper.js').default;
  3. window.pixelfed = window.pixelfed || {};
  4. window.$ = window.jQuery = require('jquery');
  5. require('bootstrap');
  6. window.axios = require('axios');
  7. window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  8. require('readmore-js');
  9. let token = document.head.querySelector('meta[name="csrf-token"]');
  10. if (token) {
  11. window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
  12. } else {
  13. console.error('CSRF token not found.');
  14. }
  15. window.App = window.App || {};
  16. window.App.redirect = function() {
  17. document.querySelectorAll('a').forEach(function(i,k) {
  18. let a = i.getAttribute('href');
  19. if(a && a.length > 5 && a.startsWith('https://')) {
  20. let url = new URL(a);
  21. if(url.host !== window.location.host && url.pathname !== '/i/redirect') {
  22. i.setAttribute('href', '/i/redirect?url=' + encodeURIComponent(a));
  23. }
  24. }
  25. });
  26. }
  27. window.App.boot = function() {
  28. new Vue({ el: '#content'});
  29. }
  30. window.App.util = {
  31. compose: {
  32. post: (function() {
  33. let path = window.location.pathname;
  34. let whitelist = [
  35. '/',
  36. '/timeline/public'
  37. ];
  38. if(whitelist.includes(path)) {
  39. $('#composeModal').modal('show');
  40. } else {
  41. window.location.href = '/?a=co';
  42. }
  43. }),
  44. circle: (function() {
  45. console.log('Unsupported method.');
  46. }),
  47. collection: (function() {
  48. console.log('Unsupported method.');
  49. }),
  50. loop: (function() {
  51. console.log('Unsupported method.');
  52. }),
  53. story: (function() {
  54. console.log('Unsupported method.');
  55. }),
  56. },
  57. time: (function() {
  58. return new Date;
  59. }),
  60. version: 1,
  61. format: {
  62. count: (function(count = 0, locale = 'en-GB', notation = 'compact') {
  63. if(count < 1) {
  64. return 0;
  65. }
  66. return new Intl.NumberFormat(locale, { notation: notation , compactDisplay: "short" }).format(count);
  67. })
  68. },
  69. filters: [
  70. ['1977','filter-1977'],
  71. ['Aden','filter-aden'],
  72. ['Amaro','filter-amaro'],
  73. ['Ashby','filter-ashby'],
  74. ['Brannan','filter-brannan'],
  75. ['Brooklyn','filter-brooklyn'],
  76. ['Charmes','filter-charmes'],
  77. ['Clarendon','filter-clarendon'],
  78. ['Crema','filter-crema'],
  79. ['Dogpatch','filter-dogpatch'],
  80. ['Earlybird','filter-earlybird'],
  81. ['Gingham','filter-gingham'],
  82. ['Ginza','filter-ginza'],
  83. ['Hefe','filter-hefe'],
  84. ['Helena','filter-helena'],
  85. ['Hudson','filter-hudson'],
  86. ['Inkwell','filter-inkwell'],
  87. ['Kelvin','filter-kelvin'],
  88. ['Kuno','filter-juno'],
  89. ['Lark','filter-lark'],
  90. ['Lo-Fi','filter-lofi'],
  91. ['Ludwig','filter-ludwig'],
  92. ['Maven','filter-maven'],
  93. ['Mayfair','filter-mayfair'],
  94. ['Moon','filter-moon'],
  95. ['Nashville','filter-nashville'],
  96. ['Perpetua','filter-perpetua'],
  97. ['Poprocket','filter-poprocket'],
  98. ['Reyes','filter-reyes'],
  99. ['Rise','filter-rise'],
  100. ['Sierra','filter-sierra'],
  101. ['Skyline','filter-skyline'],
  102. ['Slumber','filter-slumber'],
  103. ['Stinson','filter-stinson'],
  104. ['Sutro','filter-sutro'],
  105. ['Toaster','filter-toaster'],
  106. ['Valencia','filter-valencia'],
  107. ['Vesper','filter-vesper'],
  108. ['Walden','filter-walden'],
  109. ['Willow','filter-willow'],
  110. ['X-Pro II','filter-xpro-ii']
  111. ],
  112. emoji: ['😂','💯','❤️','🙌','👏','👌','😍','😯','😢','😅','😁','🙂','😎','😀','🤣','😃','😄','😆','😉','😊','😋','😘','😗','😙','😚','🤗','🤩','🤔','🤨','😐','😑','😶','🙄','😏','😣','😥','😮','🤐','😪','😫','😴','😌','😛','😜','😝','🤤','😒','😓','😔','😕','🙃','🤑','😲','🙁','😖','😞','😟','😤','😭','😦','😧','😨','😩','🤯','😬','😰','😱','😳','🤪','😵','😡','😠','🤬','😷','🤒','🤕','🤢','🤮','🤧','😇','🤠','🤡','🤥','🤫','🤭','🧐','🤓','😈','👿','👹','👺','💀','👻','👽','🤖','💩','😺','😸','😹','😻','😼','😽','🙀','😿','😾','🤲','👐','🤝','👍','👎','👊','✊','🤛','🤜','🤞','✌️','🤟','🤘','👈','👉','👆','👇','☝️','✋','🤚','🖐','🖖','👋','🤙','💪','🖕','✍️','🙏','💍','💄','💋','👄','👅','👂','👃','👣','👁','👀','🧠','🗣','👤','👥'
  113. ],
  114. embed: {
  115. post: (function(url, caption = true, likes = false, layout = 'full') {
  116. let u = url + '/embed?';
  117. u += caption ? 'caption=true&' : 'caption=false&';
  118. u += likes ? 'likes=true&' : 'likes=false&';
  119. u += layout == 'compact' ? 'layout=compact' : 'layout=full';
  120. return '<iframe src="'+u+'" class="pixelfed__embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script async defer src="'+window.location.origin +'/embed.js"><\/script>';
  121. }),
  122. profile: (function(url) {
  123. let u = url + '/embed';
  124. return '<iframe src="'+u+'" class="pixelfed__embed" style="max-width: 100%; border: 0" width="400" allowfullscreen="allowfullscreen"></iframe><script async defer src="'+window.location.origin +'/embed.js"><\/script>';
  125. })
  126. }
  127. };