ui.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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= '/static/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= '/static/isos/" + id + ".PDF')'> </iframe>";
  78. theDiv.appendChild(textElement);
  79. theDiv.appendChild(newElement);
  80. }
  81. return true;
  82. }
  83. function change_isos_tab(id, term){
  84. var theDiv = document.getElementById("iso_"+id);
  85. if (term == "start"){
  86. term = 1;
  87. }
  88. theDiv.innerHTML = "<iframe width=100% height=1000px src= '/static/isos/" + id + ".PDF#page="+ term+"')'> </iframe>";
  89. console.log(id,term);
  90. return true;
  91. }
  92. function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses, terms) {
  93. var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
  94. console.log("test");
  95. if (state) { create_new_tab(title, id, terms); }
  96. if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
  97. return state;
  98. }
  99. function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
  100. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  101. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
  102. var insarea = original.clone();
  103. insarea.attr("data-belongs-to-tab",id);
  104. insarea.attr("class","inactive");
  105. $(tabbar).find('ui-behind').before(instab);
  106. $(tabbar).parent().append(insarea);
  107. ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
  108. }
  109. (function($) { //{{{
  110. $.fn.dragcolumn = function() {
  111. var drag = $(this);
  112. var prev = drag.prev();
  113. var next = drag.next();
  114. this.on("mousedown", function(e) {
  115. drag.addClass('draggable');
  116. $(document).one("mouseup", function(e) {
  117. drag.removeClass('draggable');
  118. e.preventDefault();
  119. });
  120. e.preventDefault();
  121. });
  122. $(document).on("mousemove", function(e) {
  123. if (!drag.hasClass('draggable'))
  124. return;
  125. // Assume 50/50 split between prev and next then adjust to
  126. // the next X for prev
  127. var total = prev.outerWidth() + next.outerWidth();
  128. var pos = e.pageX - prev.offset().left;
  129. if (pos > total) {
  130. pos = total;
  131. }
  132. var leftPercentage = pos / total;
  133. var rightPercentage = 1 - leftPercentage;
  134. prev.css('flex', leftPercentage.toString());
  135. next.css('flex', rightPercentage.toString());
  136. e.preventDefault();
  137. });
  138. }
  139. $.fn.dragresize = function() {
  140. var drag = $(this);
  141. var prev = drag.prev();
  142. var initpos = 0;
  143. var initheight = $("ui-content",prev).height();
  144. this.on("mousedown", function(e) {
  145. drag.addClass('draggable');
  146. initpos = e.pageY;
  147. $(document).one("mouseup", function(e) {
  148. drag.removeClass('draggable');
  149. e.preventDefault();
  150. });
  151. e.preventDefault();
  152. });
  153. $(document).on("mousemove", function(e) {
  154. if (!drag.hasClass('draggable'))
  155. return;
  156. var pos = initheight - (initpos - e.pageY);
  157. if (pos < 0)
  158. return;
  159. $("ui-content",prev).css('height', pos.toString());
  160. e.preventDefault();
  161. });
  162. }
  163. })(jQuery); //}}}
  164. function ui_activate_tab(moi) { // {{{
  165. var active = $(moi).attr('data-tab');
  166. var tabbed = $(moi).parent().parent();
  167. var tabs = [];
  168. $("ui-tabbar > ui-tab",tabbed).each(function(){
  169. if (!$(this).attr('class').match(/switch/)) {
  170. tabs.push($(this).attr('data-tab'));
  171. }
  172. });
  173. $(".inactive",tabbed).removeClass("inactive");
  174. $.each(tabs,function(a,b){
  175. if (b != active) {
  176. $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
  177. $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
  178. }
  179. });
  180. } // }}}
  181. function ui_toggle_vis_tab(moi) {// {{{
  182. if ($(moi)[0].nodeName == 'UI-TABBED') {
  183. var tabbed = $(moi);
  184. }
  185. if ($(moi)[0].nodeName == 'UI-TAB') {
  186. var tabbed = $(moi).parent().parent();
  187. }
  188. if (tabbed) {
  189. tabbed.toggleClass('off');
  190. }
  191. }// }}}
  192. $(document).ready(function() {
  193. if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
  194. $('body').children().remove();
  195. $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
  196. }
  197. $('ui-rest ui-content ui-resizehandle').dragcolumn();
  198. $('*[is=x-ui] > ui-resizehandle').dragresize();
  199. $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
  200. $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
  201. ui_add_close($('ui-tabbar ui-tab.closeable'));
  202. $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
  203. });