cockpit/lib/ui.js in cpee-1.3.176 vs cockpit/lib/ui.js in cpee-1.3.177
- old
+ new
@@ -12,53 +12,103 @@
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($) { //{{{
+ $.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_tab_click(moi) { // {{{
- var active = $(moi).attr('id').replace(/tab/,'');
- var tab = $(moi).parent().parent().parent().parent();
+ var active = $(moi).attr('data-tab');
+ var tabbed = $(moi).parents('ui-tabbed, ui-rest');
var tabs = [];
- $("td.tab",tab).each(function(){
+ $("ui-tabbar ui-tab",tabbed).each(function(){
if (!$(this).attr('class').match(/switch/))
- tabs.push($(this).attr('id').replace(/tab/,''));
+ tabs.push($(this).attr('data-tab'));
});
- $(".inactive",tab).removeClass("inactive");
+ $(".inactive",tabbed).removeClass("inactive");
$.each(tabs,function(a,b){
if (b != active) {
- $("#tab" + b).addClass("inactive");
- $("#area" + b).addClass("inactive");
+ $("ui-tabbar ui-tab[data-tab=" + b + "]",tabbed).addClass("inactive");
+ $("ui-content *[data-belongs-to-tab=" + b + "]",tabbed).addClass("inactive");
}
});
- ui_rest_resize();
} // }}}
function ui_toggle_vis_tab(moi) {// {{{
- var tabbar = $(moi).parent().parent().parent();
- var tab = $(tabbar).parent();
- var fix = $(tab).parent();
- $('h1',moi).toggleClass('margin');
- $("tr.border",tabbar).toggleClass('hidden');
- $("div.tabbelow",tab).toggleClass('hidden');
- $("td.tabbehind button",tabbar).toggleClass('hidden');
- if ($(fix).attr('class') && $(fix).attr('class').match(/fixedstate/)) {
- $(".fixedstatehollow").height($(fix).height());
- }
- ui_rest_resize();
+ var tabbed = $(moi).parents('ui-tabbed');
+ tabbed.toggleClass('off');
}// }}}
-function ui_rest_resize() {
- if ($('div.tabbed.rest .tabbar')) {
- var theight = $(window).height() - $('div.tabbed.rest .tabbar').offset().top - $('div.tabbed.rest .tabbar').height();
- $('div.tabbed.rest .tabbelow').each(function(key,ele){
- $(ele).height(theight - parseInt($(ele).css('padding-top')) - parseInt($(ele).css('padding-bottom')) );
- });
- $('div.tabbed.rest .tabbelow .column').each(function(key,ele){
- $(ele).height(theight - parseInt($(ele).css('padding-top')) - parseInt($(ele).css('padding-bottom')) );
- });
- }
-}
-
$(document).ready(function() {
- $(window).resize(ui_rest_resize);
- $('.tabbed table.tabbar td.tab.switch').click(function(){ui_toggle_vis_tab(this);});
- $('.tabbed table.tabbar td.tab').not('.switch').click(function(){ui_tab_click(this);});
+ 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();
+ $('ui-tabbar ui-tab.switch').click(function(){ui_toggle_vis_tab(this);});
+ $('ui-tabbar ui-tab').not('.switch').click(function(){ui_tab_click(this);});
});