ui.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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) {
  46. console.log(title,id);
  47. var theDiv = document.getElementById(id);
  48. var content = document.createTextNode(id);
  49. var content = document.createTextNode(id);
  50. var newElement = document.createElement('div');
  51. newElement.setAttribute('id', id);
  52. newElement.innerHTML = "<iframe width=100% height=1000px src= '/static/isos/" + id + ".PDF')'> </iframe>";
  53. theDiv.appendChild(content);
  54. theDiv.appendChild(newElement);
  55. return true;
  56. }
  57. function ui_add_tab_active(tabbed,title,id,closeable,additionalclasses) {
  58. var state = ui_add_tab(tabbed,title,id,closeable,additionalclasses);
  59. if (state) { create_new_tab(title, id); }
  60. if (state) { ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']')); }
  61. return state;
  62. }
  63. function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
  64. additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
  65. var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
  66. var insarea = original.clone();
  67. insarea.attr("data-belongs-to-tab",id);
  68. insarea.attr("class","inactive");
  69. $(tabbar).find('ui-behind').before(instab);
  70. $(tabbar).parent().append(insarea);
  71. ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
  72. }
  73. (function($) { //{{{
  74. $.fn.dragcolumn = function() {
  75. var drag = $(this);
  76. var prev = drag.prev();
  77. var next = drag.next();
  78. this.on("mousedown", function(e) {
  79. drag.addClass('draggable');
  80. $(document).one("mouseup", function(e) {
  81. drag.removeClass('draggable');
  82. e.preventDefault();
  83. });
  84. e.preventDefault();
  85. });
  86. $(document).on("mousemove", function(e) {
  87. if (!drag.hasClass('draggable'))
  88. return;
  89. // Assume 50/50 split between prev and next then adjust to
  90. // the next X for prev
  91. var total = prev.outerWidth() + next.outerWidth();
  92. var pos = e.pageX - prev.offset().left;
  93. if (pos > total) {
  94. pos = total;
  95. }
  96. var leftPercentage = pos / total;
  97. var rightPercentage = 1 - leftPercentage;
  98. prev.css('flex', leftPercentage.toString());
  99. next.css('flex', rightPercentage.toString());
  100. e.preventDefault();
  101. });
  102. }
  103. $.fn.dragresize = function() {
  104. var drag = $(this);
  105. var prev = drag.prev();
  106. var initpos = 0;
  107. var initheight = $("ui-content",prev).height();
  108. this.on("mousedown", function(e) {
  109. drag.addClass('draggable');
  110. initpos = e.pageY;
  111. $(document).one("mouseup", function(e) {
  112. drag.removeClass('draggable');
  113. e.preventDefault();
  114. });
  115. e.preventDefault();
  116. });
  117. $(document).on("mousemove", function(e) {
  118. if (!drag.hasClass('draggable'))
  119. return;
  120. var pos = initheight - (initpos - e.pageY);
  121. if (pos < 0)
  122. return;
  123. $("ui-content",prev).css('height', pos.toString());
  124. e.preventDefault();
  125. });
  126. }
  127. })(jQuery); //}}}
  128. function ui_activate_tab(moi) { // {{{
  129. var active = $(moi).attr('data-tab');
  130. var tabbed = $(moi).parent().parent();
  131. var tabs = [];
  132. $("ui-tabbar > ui-tab",tabbed).each(function(){
  133. if (!$(this).attr('class').match(/switch/)) {
  134. tabs.push($(this).attr('data-tab'));
  135. }
  136. });
  137. $(".inactive",tabbed).removeClass("inactive");
  138. $.each(tabs,function(a,b){
  139. if (b != active) {
  140. $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
  141. $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
  142. }
  143. });
  144. } // }}}
  145. function ui_toggle_vis_tab(moi) {// {{{
  146. if ($(moi)[0].nodeName == 'UI-TABBED') {
  147. var tabbed = $(moi);
  148. }
  149. if ($(moi)[0].nodeName == 'UI-TAB') {
  150. var tabbed = $(moi).parent().parent();
  151. }
  152. if (tabbed) {
  153. tabbed.toggleClass('off');
  154. }
  155. }// }}}
  156. $(document).ready(function() {
  157. if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
  158. $('body').children().remove();
  159. $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
  160. }
  161. $('ui-rest ui-content ui-resizehandle').dragcolumn();
  162. $('*[is=x-ui] > ui-resizehandle').dragresize();
  163. $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
  164. $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
  165. ui_add_close($('ui-tabbar ui-tab.closeable'));
  166. $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
  167. });