You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

179 lines
5.9 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /**
  2. * Movim Javascript Template functions
  3. * Look at the comments for help.
  4. */
  5. var MovimTpl = {
  6. dragged : false,
  7. moving : false,
  8. percent : false,
  9. append : function(selector, html) {
  10. target = document.querySelector(selector);
  11. if (target) {
  12. target.insertAdjacentHTML('beforeend', html);
  13. }
  14. },
  15. appendAfter : function(selector, html) {
  16. target = document.querySelector(selector);
  17. if (target) {
  18. target.insertAdjacentHTML('afterend', html);
  19. }
  20. },
  21. back : function() {
  22. // If the context menu is shown
  23. var cm = document.querySelector('ul.context_menu');
  24. if (cm != null && cm.className.includes('shown')) {
  25. MovimTpl.toggleContextMenu(document);
  26. } else if (typeof Draw == 'object' && Draw.draw != undefined && Draw.draw.classList.contains('open')) {
  27. Draw.draw.classList.remove('open');
  28. } else if (typeof Snap == 'object' && Snap.snap != undefined && Snap.snap.className !== '') {
  29. if (Snap.snap.classList.contains('upload')) {
  30. Snap.snap.className = 'shoot';
  31. Snap.video.play();
  32. } else {
  33. Snap.end();
  34. }
  35. } else if (document.querySelector('#preview')
  36. && document.querySelector('#preview').innerHTML != '') {
  37. Preview_ajaxHide();
  38. } else if (Drawer.filled()) {
  39. Drawer.clear();
  40. // If a dialog box is shown
  41. } else if (Dialog.filled()) {
  42. Dialog.clear();
  43. // If the menu is shown
  44. } else if (document.querySelector('body > nav').classList.contains('active')) {
  45. document.querySelector('body > nav').classList.remove('active');
  46. // If the panel is shown
  47. } else if (document.querySelector('main').classList.contains('enabled')) {
  48. if (MovimUtils.urlParts().page == 'chat') {
  49. Chat_ajaxGet();
  50. } else {
  51. MovimTpl.hidePanel();
  52. window.history.back();
  53. }
  54. } else {
  55. history.back();
  56. }
  57. },
  58. fill : function(selector, html) {
  59. target = document.querySelector(selector);
  60. if (target) {
  61. target.innerHTML = html;
  62. }
  63. },
  64. hideMenu: function() {
  65. MovimUtils.removeClass('body > nav', 'active');
  66. },
  67. showPanel: function() {
  68. MovimUtils.addClass('main', 'enabled');
  69. MovimUtils.addClass('ul#bottomnavigation', 'hidden');
  70. },
  71. hidePanel: function() {
  72. MovimUtils.removeClass('main', 'enabled');
  73. MovimUtils.removeClass('ul#bottomnavigation', 'hidden');
  74. },
  75. prepend: function(selector, html) {
  76. target = document.querySelector(selector);
  77. if (target) {
  78. target.insertAdjacentHTML('afterbegin', html);
  79. }
  80. },
  81. prependBefore: function(selector, html) {
  82. target = document.querySelector(selector);
  83. if (target) {
  84. target.insertAdjacentHTML('beforebegin', html);
  85. }
  86. },
  87. remove: function(selector) {
  88. target = document.querySelector(selector);
  89. if (target)
  90. target.parentNode.removeChild(target);
  91. },
  92. replace: function (selector, html) {
  93. target = document.querySelector(selector);
  94. if (target) {
  95. var div = document.createElement('div');
  96. div.innerHTML = html;
  97. var element = div.firstChild;
  98. replacedNode = target.parentNode.replaceChild(element, target);
  99. }
  100. },
  101. toggleContextMenu : function(e) {
  102. var contextMenu = document.querySelector('ul.context_menu');
  103. if (contextMenu == null) return;
  104. if (document.querySelector('.show_context_menu').contains(e.target)) {
  105. contextMenu.classList.add('shown');
  106. } else {
  107. contextMenu.classList.remove('shown');
  108. }
  109. },
  110. toggleMenu : function() {
  111. document.querySelector('body > nav').classList.toggle('active');
  112. },
  113. touchEvents: function() {
  114. nav = document.querySelector('body > nav');
  115. if (nav == null) return;
  116. nav.addEventListener('touchstart', function(event) {
  117. //event.preventDefault();
  118. startX = event.targetTouches[0].pageX;
  119. startY = event.targetTouches[0].pageY;
  120. if (
  121. (
  122. (startX < document.body.clientWidth/35 && startY > 56)
  123. ||
  124. (nav.classList.contains('active') && startX > document.body.clientWidth - 50)
  125. )
  126. && MovimTpl.dragged == false) {
  127. nav.classList.add('moving');
  128. MovimTpl.dragged = true;
  129. }
  130. }, true);
  131. nav.addEventListener('touchmove', function(event) {
  132. //event.preventDefault();
  133. moveX = event.targetTouches[0].pageX;
  134. if (MovimTpl.dragged) {
  135. event.preventDefault();
  136. event.stopPropagation();
  137. position = moveX - document.body.clientWidth;
  138. MovimTpl.percent = 1 - Math.abs(moveX) / Math.abs(document.body.clientWidth);
  139. nav.style.transform = 'matrix3d(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, '+position+', 0, 0, 1)';
  140. }
  141. }, true);
  142. nav.addEventListener('touchend', function(event) {
  143. event.preventDefault();
  144. nav.style.transform = '';
  145. if (MovimTpl.dragged) {
  146. nav.classList.remove('moving');
  147. if (!nav.classList.contains('active')
  148. && MovimTpl.percent < 0.80) {
  149. nav.classList.add('active');
  150. } else if (MovimTpl.percent > 0.20) {
  151. nav.classList.remove('active');
  152. }
  153. }
  154. MovimTpl.dragged = false;
  155. }, true);
  156. }
  157. };
  158. movimAddOnload(function() {
  159. MovimTpl.touchEvents();
  160. document.body.addEventListener('click', MovimTpl.toggleContextMenu, false);
  161. });