flow.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. $(function()
  2. {
  3. /* Add title for table td. */
  4. $('.main-table .table tbody tr').each(function()
  5. {
  6. $(this).find('td').each(function()
  7. {
  8. $(this).attr('title', $(this).text());
  9. });
  10. });
  11. $('table tr td .dropdown .dropdown-menu').closest('td').css('overflow', 'visible');
  12. $('table tr').each(function(){$(this).find('td:last').removeAttr('title');});
  13. $('.main-table .table tbody tr').each(function()
  14. {
  15. var $aTag = $(this).find('td').eq(0).find('a');
  16. if($aTag.length > 0) $aTag.prop('outerHTML', $aTag.html());
  17. });
  18. if(!$('td.actions').is(':hidden')) {$('td.actions').each(function(){fixOperateMenu($(this));});}
  19. $(window).resize(function()
  20. {
  21. if(!$('td.actions').is(':hidden')) $('td.actions').each(function(){fixOperateMenu($(this));});
  22. });
  23. });
  24. function fixOperateMenu($td)
  25. {
  26. var aList = $td.children('a').map(function(){return $(this).outerWidth(true);}).get();
  27. var $moreMenu = $td.find('.dropdown-menu').parent();
  28. var tdWidth = $td.width();
  29. var aWidth = aList.length ? aList.reduce(function(a, b){return a + b;}) : 0;
  30. var mWidth = $moreMenu.length ? $moreMenu.outerWidth(true) : 0;
  31. if(tdWidth < aWidth + mWidth)
  32. {
  33. if(!aList.length) return false;
  34. if($moreMenu.length == 0)
  35. {
  36. $moreMenu = $("<div id='moreMenu' class='dropdown'><a href='javascript:;' data-toggle='dropdown'>" + window.more + "<span class='caret'></span></a><ul class='dropdown-menu pull-right'></ul></div>");
  37. $td.append($moreMenu);
  38. }
  39. var $lastA = $td.children('a:last');
  40. $moreMenu.children('.dropdown-menu').prepend($('<li>').append($lastA));
  41. fixOperateMenu($td);
  42. }
  43. else if(tdWidth > aWidth + mWidth + 30)
  44. {
  45. if($moreMenu.length == 0) return false;
  46. var $firstli = $moreMenu.find('.dropdown-menu li:first');
  47. $moreMenu.before($firstli.html() + ' ');
  48. $firstli.remove();
  49. if(!$moreMenu.find('.dropdown-menu li').length) $moreMenu.remove();
  50. }
  51. }