123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- /*
- This file is part of CPEE.
- CPEE is free software: you can redistribute it and/or modify it under the terms
- of the GNU General Public License as published by the Free Software Foundation,
- either version 3 of the License, or (at your option) any later version.
- CPEE is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- PARTICULAR PURPOSE. See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along with
- CPEE (file COPYING in the main directory). If not, see
- <http://www.gnu.org/licenses/>.
- */
- function ui_click_tab(moi) { // {{{
- $(moi).trigger('click');
- } // }}}
- function ui_close_tab(moi){
- var active = $(moi).parent().attr('data-tab');
- var tabbed = $(moi).parent().parent().parent();
- var is_inactive = $(moi).parent().hasClass('inactive');
- $('*[data-tab=' + active + ']').remove();
- $('*[data-belongs-to-tab=' + active + ']').remove();
- if (!is_inactive)
- ui_click_tab($('ui-tabbar ui-tab.default'));
- }
- function ui_add_close(moi) {
- $(moi).append($('<ui-close>✖</ui-close>'));
- }
- function ui_empty_tab_contents(id) {
- $('ui-content ui-area[data-belongs-to-tab=' + id + ']').empty();
- }
- function ui_add_tab(tabbed,title,id,closeable,additionalclasses) {
- additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
- if ($('ui-tabbar ui-tab[data-tab=' + id + ']').length > 0) {
- ui_activate_tab($('ui-tabbar ui-tab[data-tab=' + id + ']'));
- return false;
- } else {
- var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "'>" + title + "</ui-tab>");
- var insarea = $("<ui-area data-belongs-to-tab='" + id + "' class='inactive'></ui-area>");
- $(tabbed).find('ui-behind').before(instab);
- $(tabbed).find('ui-content').append(insarea);
- ui_add_close($('ui-tabbar ui-tab[data-tab=' + id + ']'));
- return true;
- }
- }
- function ui_clone_tab(tabbar,original,title,id,closeable,additionalclasses) {
- additionalclasses = typeof additionalclasses !== 'undefined' ? additionalclasses : '';
- var instab = $("<ui-tab class='inactive" + (closeable ? ' closeable' : '') + (additionalclasses == '' ? '' : ' ' + additionalclasses) + "' data-tab='" + id + "' id='tab_" + id + "'>" + title + "</ui-tab>");
- var insarea = original.clone();
- insarea.attr("data-belongs-to-tab",id);
- insarea.attr("class","inactive");
- $(tabbar).find('ui-behind').before(instab);
- $(tabbar).parent().append(insarea);
- ui_add_close($('ui-tabbed ui-tab[data-tab=' + id + ']'));
- }
- (function($) { //{{{
- $.fn.dragcolumn = function() {
- var drag = $(this);
- var prev = drag.prev();
- var next = drag.next();
- this.on("mousedown", function(e) {
- drag.addClass('draggable');
- $(document).one("mouseup", function(e) {
- drag.removeClass('draggable');
- e.preventDefault();
- });
- e.preventDefault();
- });
- $(document).on("mousemove", function(e) {
- if (!drag.hasClass('draggable'))
- return;
- // Assume 50/50 split between prev and next then adjust to
- // the next X for prev
- var total = prev.outerWidth() + next.outerWidth();
- var pos = e.pageX - prev.offset().left;
- if (pos > total) {
- pos = total;
- }
- var leftPercentage = pos / total;
- var rightPercentage = 1 - leftPercentage;
- prev.css('flex', leftPercentage.toString());
- next.css('flex', rightPercentage.toString());
- e.preventDefault();
- });
- }
- $.fn.dragresize = function() {
- var drag = $(this);
- var prev = drag.prev();
- var initpos = 0;
- var initheight = $("ui-content",prev).height();
- this.on("mousedown", function(e) {
- drag.addClass('draggable');
- initpos = e.pageY;
- $(document).one("mouseup", function(e) {
- drag.removeClass('draggable');
- e.preventDefault();
- });
- e.preventDefault();
- });
- $(document).on("mousemove", function(e) {
- if (!drag.hasClass('draggable'))
- return;
- var pos = initheight - (initpos - e.pageY);
- if (pos < 0)
- return;
- $("ui-content",prev).css('height', pos.toString());
- e.preventDefault();
- });
- }
- })(jQuery); //}}}
- function ui_activate_tab(moi) { // {{{
- var active = $(moi).attr('data-tab');
- var tabbed = $(moi).parent().parent();
- var tabs = [];
- $("ui-tabbar > ui-tab",tabbed).each(function(){
- if (!$(this).attr('class').match(/switch/)) {
- tabs.push($(this).attr('data-tab'));
- }
- });
- $(".inactive",tabbed).removeClass("inactive");
- $.each(tabs,function(a,b){
- if (b != active) {
- $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
- $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
- }
- });
- } // }}}
- function ui_toggle_vis_tab(moi) {// {{{
- if ($(moi)[0].nodeName == 'UI-TABBED') {
- var tabbed = $(moi);
- }
- if ($(moi)[0].nodeName == 'UI-TAB') {
- var tabbed = $(moi).parent().parent();
- }
- if (tabbed) {
- tabbed.toggleClass('off');
- }
- }// }}}
- $(document).ready(function() {
- if (!($.browser.name == "Firefox" && $.browser.version >= 20) && !($.browser.name == "Chrome" && $.browser.version >= 30)) {
- $('body').children().remove();
- $('body').append('Sorry, only Firefox >= 20.0 and Chrom(e|ium) >= 17 for now.');
- }
- $('ui-rest ui-content ui-resizehandle').dragcolumn();
- $('*[is=x-ui] > ui-resizehandle').dragresize();
- $(document).on('click','ui-tabbar ui-tab.switch',function(){ui_toggle_vis_tab(this);});
- $(document).on('click','ui-tabbar ui-tab:not(.switch)',function(){ui_activate_tab(this);});
- ui_add_close($('ui-tabbar ui-tab.closeable'));
- $(document).on('click','ui-tabbar ui-tab.closeable ui-close',function(){ui_close_tab(this);});
- });
|