ui.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. This file is part of CPEE.
  3. CPEE is free software: you can redistribute it and/or modify it under the terms
  4. of the GNU General Public License as published by the Free Software Foundation,
  5. either version 3 of the License, or (at your option) any later version.
  6. CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
  7. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  8. PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. CPEE (file COPYING in the main directory). If not, see
  11. <http://www.gnu.org/licenses/>.
  12. */
  13. function ui_click_tab(moi) { // {{{
  14. $(moi).trigger('click');
  15. } // }}}
  16. function ui_close_tab(moi){
  17. var active = $(moi).parent().attr('data-tab');
  18. var tabbed = $(moi).parent().parent().parent();
  19. var is_inactive = $(moi).parent().hasClass('inactive');
  20. $('*[data-tab=' + active + ']').remove();
  21. $('*[data-belongs-to-tab=' + active + ']').remove();
  22. if (!is_inactive)
  23. ui_click_tab($('ui-tabbar ui-tab.default'));
  24. }
  25. function ui_add_close(moi) {
  26. $(moi).append($('<ui-close>✖</ui-close>'));
  27. }
  28. function ui_empty_tab_contents(id) {
  29. $('ui-content ui-area[data-belongs-to-tab=' + id + ']').empty();
  30. }
  31. function ui_add_tab(tabbed,title,id,closeable,additionalclasses) {
  32. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  33. if ($('ui-tabbar ui-tab[data-tab=' + id + ']').length > 0) {
  34. ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']'));
  35. return false;
  36. } else {
  37. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "'>" + title + "</ui-tab>");
  38. var insarea = $("<ui-area data-belongs-to-tab='" + id + "' class='inactive' id="+ id +"></ui-area>");
  39. $(tabbed).find('ui-behind').before(instab);
  40. $(tabbed).find('ui-content').append(insarea);
  41. ui_add_close($('ui-tabbar ui-tab[data-tab=' + id + ']'));
  42. return true;
  43. }
  44. }
  45. function create_new_tab(title, id,terms) {
  46. //console.log(title,id);
  47. if (terms != "empty"){
  48. var terms = atob(terms);
  49. var theDiv = document.getElementById(id);
  50. //var content = document.createTextNode("Test");
  51. //var content = document.createTextNode(terms);
  52. var newElement = document.createElement('div');
  53. var textElement = document.createElement('div');
  54. var array_terms = JSON.parse(terms);
  55. var len = Object.keys(array_terms).length;
  56. console.log(len);
  57. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO document </a><br>";
  58. for (var key in array_terms) {
  59. console.log(key);
  60. //theDiv.appendChild(document.createTextNode(terms[key]));
  61. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','"+array_terms[key]+"')>"+key+" </a><br>";
  62. }
  63. newElement.setAttribute('id', "iso_"+id);
  64. console.log(terms);
  65. console.log(textElement)
  66. newElement.innerHTML = "<iframe width=100% height=1000px src= '{{ url_for('static', filename='isos/') }}"+ id + ".PDF)'> </iframe>";
  67. theDiv.appendChild(textElement);
  68. theDiv.appendChild(newElement);
  69. }
  70. else{
  71. var theDiv = document.getElementById(id);
  72. var newElement = document.createElement('div');
  73. var textElement = document.createElement('div');
  74. textElement.innerHTML += "<a onclick=change_isos_tab('"+id+"','start')> Start of ISO File. </a><br>";
  75. newElement.setAttribute('id', "iso_"+id);
  76. //console.log(terms);
  77. newElement.innerHTML = "<iframe width=100% height=1000px src= '+{{ url_for('static', filename='isos/') }}"+ id + ".PDF)'> </iframe>";
  78. //newElement.innerHTML ="<h1> hallooo </>"
  79. theDiv.appendChild(textElement);
  80. theDiv.appendChild(newElement);
  81. }
  82. return true;
  83. }
  84. function change_isos_tab(id, term){
  85. var theDiv = document.getElementById("iso_"+id);
  86. if (term == "start"){
  87. term = 1;
  88. }
  89. theDiv.innerHTML = "<iframe width=100% height=1000px src= '{{ url_for('static', filename='isos/') }}+" id + ".PDF#page="+ term+"')'> </iframe>";
  90. console.log(id,term);
  91. return true;
  92. }
  93. function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses, terms) {
  94. var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
  95. console.log("test");
  96. if (state) { create_new_tab(title, id, terms); }
  97. if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
  98. return state;
  99. }
  100. function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
  101. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  102. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
  103. var insarea = original.clone();
  104. insarea.attr("data-belongs-to-tab",id);
  105. insarea.attr("class","inactive");
  106. $(tabbar).find('ui-behind').before(instab);
  107. $(tabbar).parent().append(insarea);
  108. ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
  109. }
  110. (function($) { //{{{
  111. $.fn.dragcolumn = function() {
  112. var drag = $(this);
  113. var prev = drag.prev();
  114. var next = drag.next();
  115. this.on("mousedown", function(e) {
  116. drag.addClass('draggable');
  117. $(document).one("mouseup", function(e) {
  118. drag.removeClass('draggable');
  119. e.preventDefault();
  120. });
  121. e.preventDefault();
  122. });
  123. $(document).on("mousemove", function(e) {
  124. if (!drag.hasClass('draggable'))
  125. return;
  126. // Assume 50/50 split between prev and next then adjust to
  127. // the next X for prev
  128. var total = prev.outerWidth() + next.outerWidth();
  129. var pos = e.pageX - prev.offset().left;
  130. if (pos > total) {
  131. pos = total;
  132. }
  133. var leftPercentage = pos / total;
  134. var rightPercentage = 1 - leftPercentage;
  135. prev.css('flex', leftPercentage.toString());
  136. next.css('flex', rightPercentage.toString());
  137. e.preventDefault();
  138. });
  139. }
  140. $.fn.dragresize = function() {
  141. var drag = $(this);
  142. var prev = drag.prev();
  143. var initpos = 0;
  144. var initheight = $("ui-content",prev).height();
  145. this.on("mousedown", function(e) {
  146. drag.addClass('draggable');
  147. initpos = e.pageY;
  148. $(document).one("mouseup", function(e) {
  149. drag.removeClass('draggable');
  150. e.preventDefault();
  151. });
  152. e.preventDefault();
  153. });
  154. $(document).on("mousemove", function(e) {
  155. if (!drag.hasClass('draggable'))
  156. return;
  157. var pos = initheight - (initpos - e.pageY);
  158. if (pos < 0)
  159. return;
  160. $("ui-content",prev).css('height', pos.toString());
  161. e.preventDefault();
  162. });
  163. }
  164. })(jQuery); //}}}
  165. function ui_activate_tab(moi) { // {{{
  166. var active = $(moi).attr('data-tab');
  167. var tabbed = $(moi).parent().parent();
  168. var tabs = [];
  169. $("ui-tabbar > ui-tab",tabbed).each(function(){
  170. if (!$(this).attr('class').match(/switch/)) {
  171. tabs.push($(this).attr('data-tab'));
  172. }
  173. });
  174. $(".inactive",tabbed).removeClass("inactive");
  175. $.each(tabs,function(a,b){
  176. if (b != active) {
  177. $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
  178. $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
  179. }
  180. });
  181. } // }}}
  182. function ui_toggle_vis_tab(moi) {// {{{
  183. if ($(moi)[0].nodeName == 'UI-TABBED') {
  184. var tabbed = $(moi);
  185. }
  186. if ($(moi)[0].nodeName == 'UI-TAB') {
  187. var tabbed = $(moi).parent().parent();
  188. }
  189. if (tabbed) {
  190. tabbed.toggleClass('off');
  191. }
  192. }// }}}
  193. $(document).ready(function() {
  194. if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
  195. $('body').children().remove();
  196. $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
  197. }
  198. $('ui-rest ui-content ui-resizehandle').dragcolumn();
  199. $('*[is=x-ui] > ui-resizehandle').dragresize();
  200. $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
  201. $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
  202. ui_add_close($('ui-tabbar ui-tab.closeable'));
  203. $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
  204. });