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.

166 lines
4.9 KiB

11 years ago
11 years ago
11 years ago
11 years ago
  1. /**
  2. * Movim Javascript Template functions
  3. *
  4. * These are the default callback functions that users may (or may not) use.
  5. *
  6. * Note that all of them take only one parameter. Don't be fooled by this, the
  7. * expected parameter is actually an array containing the real parameters. These
  8. * are checked before use.
  9. *
  10. * Look at the comments for help.
  11. */
  12. // movim_append(div, text)
  13. function movim_append(id, html)
  14. {
  15. target = document.getElementById(id);
  16. if(target) {
  17. target.insertAdjacentHTML('beforeend', html);
  18. }
  19. }
  20. // movim_prepend(div, text)
  21. function movim_prepend(id, html)
  22. {
  23. target = document.getElementById(id);
  24. if(target) {
  25. target.insertAdjacentHTML('afterbegin', html);
  26. }
  27. }
  28. // movim_fill(div, text)
  29. function movim_fill(id, html)
  30. {
  31. target = document.getElementById(id);
  32. if(target) {
  33. target.innerHTML = html;
  34. }
  35. }
  36. // movim_delete(div)
  37. function movim_delete(id)
  38. {
  39. target = document.getElementById(id);
  40. if(target)
  41. target.parentNode.removeChild(target);
  42. }
  43. // movim_replace(id)
  44. function movim_replace(id, html)
  45. {
  46. target = document.getElementById(id);
  47. if(target) {
  48. var div = document.createElement('div');
  49. div.innerHTML = html;
  50. var element = div.firstChild;
  51. replacedNode = target.parentNode.replaceChild(element, target);
  52. }
  53. }
  54. var MovimTpl = {
  55. init : function() {
  56. if(document.getElementById('back') != null)
  57. document.getElementById('back').style.display = 'none';
  58. },
  59. showPanel : function() {
  60. movim_add_class('main section > div:first-child:nth-last-child(2) ~ div', 'enabled');
  61. MovimTpl.scrollPanelTop();
  62. },
  63. hidePanel : function() {
  64. Header_ajaxReset(CURRENT_PAGE);
  65. var selector = 'main section > div:first-child:nth-last-child(2) ~ div';
  66. var inner = document.querySelector(selector + ' div');
  67. movim_remove_class(selector, 'enabled');
  68. // Clear the right panel
  69. //if(inner != null) inner.innerHTML = '';
  70. //else document.querySelector(selector).innerHTML = '';
  71. },
  72. fill : function(selector, html) {
  73. target = document.querySelector(selector);
  74. if(target) {
  75. target.innerHTML = html;
  76. }
  77. },
  78. isPanel : function() {
  79. if(movim_has_class('main section > div:first-child:nth-last-child(2) ~ div', 'enabled')) {
  80. return true;
  81. } else {
  82. return false;
  83. }
  84. },
  85. isPanelScrolled : function() {
  86. var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div div');
  87. if(selector != null) {
  88. return (selector.scrollHeight - selector.scrollTop === selector.clientHeight);
  89. }
  90. },
  91. scrollPanel : function() {
  92. var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div div');
  93. if(selector != null) {
  94. selector.scrollTop = selector.scrollHeight;
  95. }
  96. },
  97. scrollPanelTop : function() {
  98. var selector = document.querySelector('main section > div:first-child:nth-last-child(2) ~ div');
  99. if(selector != null) {
  100. selector.scrollTop = 0;
  101. }
  102. },
  103. toggleMenu : function() {
  104. movim_toggle_class('body > nav', 'active');
  105. },
  106. toggleContextMenu : function(e) {
  107. var element = 'ul.context_menu';
  108. var classname = 'shown';
  109. if(document.querySelector(element) == null) {
  110. return;
  111. }
  112. if(document.querySelector('.show_context_menu').contains(e.target)) {
  113. movim_add_class(element, classname);
  114. return;
  115. }
  116. //if(!document.querySelector(element).contains(e.target))
  117. movim_remove_class(element, classname);
  118. },
  119. toggleActionButton : function() {
  120. movim_toggle_class('.button.action', 'active');
  121. },
  122. hideContextMenu : function() {
  123. movim_remove_class('ul.context_menu', 'shown');
  124. },
  125. hideMenu : function() {
  126. movim_remove_class('body > nav', 'active');
  127. },
  128. back : function() {
  129. // If the contect menu is show
  130. var cm = document.querySelector('ul.context_menu');
  131. if(cm != null && cm.className.includes('shown')) {
  132. MovimTpl.toggleContextMenu(document);
  133. }
  134. // If a dialog box is show
  135. else if(Dialog.filled()) {
  136. Dialog.clear();
  137. // If the menu is shown
  138. } else if(movim_has_class('body > nav', 'active')) {
  139. movim_toggle_class('body > nav', 'active');
  140. // If the panel is shown
  141. } else if(MovimTpl.isPanel()) {
  142. MovimTpl.hidePanel();
  143. } else {
  144. window.history.back();
  145. }
  146. },
  147. getHeaderColor : function() {
  148. var header = document.querySelector('body main > header');
  149. return window.getComputedStyle(header).backgroundColor;
  150. }
  151. }
  152. movim_add_onload(function() {
  153. MovimTpl.init();
  154. document.body.addEventListener('click', MovimTpl.toggleContextMenu, false);
  155. });