UU跑腿标准版

ligerToolBar.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /**
  2. * jQuery ligerUI 1.2.4
  3. *
  4. * http://ligerui.com
  5. *
  6. * Author daomi 2014 [ gd_star@163.com ]
  7. *
  8. */
  9. (function ($)
  10. {
  11. $.fn.ligerToolBar = function (options)
  12. {
  13. return $.ligerui.run.call(this, "ligerToolBar", arguments);
  14. };
  15. $.fn.ligerGetToolBarManager = function ()
  16. {
  17. return $.ligerui.run.call(this, "ligerGetToolBarManager", arguments);
  18. };
  19. $.ligerDefaults.ToolBar = {};
  20. $.ligerMethos.ToolBar = {};
  21. $.ligerui.controls.ToolBar = function (element, options)
  22. {
  23. $.ligerui.controls.ToolBar.base.constructor.call(this, element, options);
  24. };
  25. $.ligerui.controls.ToolBar.ligerExtend($.ligerui.core.UIComponent, {
  26. __getType: function ()
  27. {
  28. return 'ToolBar';
  29. },
  30. __idPrev: function ()
  31. {
  32. return 'ToolBar';
  33. },
  34. _extendMethods: function ()
  35. {
  36. return $.ligerMethos.ToolBar;
  37. },
  38. _render: function ()
  39. {
  40. var g = this, p = this.options;
  41. g.toolbarItemCount = 0;
  42. g.toolBar = $(this.element);
  43. g.toolBar.addClass("l-toolbar");
  44. g.set(p);
  45. },
  46. _setItems: function (items)
  47. {
  48. var g = this;
  49. g.toolBar.html("");
  50. $(items).each(function (i, item)
  51. {
  52. g.addItem(item);
  53. });
  54. },
  55. removeItem: function (itemid)
  56. {
  57. var g = this, p = this.options;
  58. $("> .l-toolbar-item[toolbarid=" + itemid + "]", g.toolBar).remove();
  59. },
  60. setEnabled: function (itemid)
  61. {
  62. var g = this, p = this.options;
  63. $("> .l-toolbar-item[toolbarid=" + itemid + "]", g.toolBar).removeClass("l-toolbar-item-disable");
  64. },
  65. setDisabled: function (itemid)
  66. {
  67. var g = this, p = this.options;
  68. $("> .l-toolbar-item[toolbarid=" + itemid + "]", g.toolBar).addClass("l-toolbar-item-disable");
  69. },
  70. isEnable: function (itemid)
  71. {
  72. var g = this, p = this.options;
  73. return !$("> .l-toolbar-item[toolbarid=" + itemid + "]", g.toolBar).hasClass("l-toolbar-item-disable");
  74. },
  75. addItem: function (item)
  76. {
  77. var g = this, p = this.options;
  78. if (item.line || item.type == "line")
  79. {
  80. g.toolBar.append('<div class="l-bar-separator"></div>');
  81. return;
  82. }
  83. if (item.type == "text")
  84. {
  85. g.toolBar.append('<div class="l-toolbar-item l-toolbar-text"><span>' + item.text || "" + '</span></div>');
  86. return;
  87. }
  88. var ditem = $('<div class="l-toolbar-item l-panel-btn"><span></span><div class="l-panel-btn-l"></div><div class="l-panel-btn-r"></div></div>');
  89. g.toolBar.append(ditem);
  90. if(!item.id) item.id = 'item-'+(++g.toolbarItemCount);
  91. ditem.attr("toolbarid", item.id);
  92. if (item.img)
  93. {
  94. ditem.append("<img src='" + item.img + "' />");
  95. ditem.addClass("l-toolbar-item-hasicon");
  96. }
  97. else if (item.icon)
  98. {
  99. ditem.append("<div class='l-icon l-icon-" + item.icon + "'></div>");
  100. ditem.addClass("l-toolbar-item-hasicon");
  101. }
  102. else if (item.color)
  103. {
  104. ditem.append("<div class='l-toolbar-item-color' style='background:"+item.color+"'></div>");
  105. ditem.addClass("l-toolbar-item-hasicon");
  106. }
  107. item.text && $("span:first", ditem).html(item.text);
  108. item.disable && ditem.addClass("l-toolbar-item-disable");
  109. item.click && ditem.click(function () { if ($(this).hasClass("l-toolbar-item-disable")) return;item.click(item); });
  110. if (item.menu)
  111. {
  112. item.menu = $.ligerMenu(item.menu);
  113. ditem.hover(function ()
  114. {
  115. if ($(this).hasClass("l-toolbar-item-disable")) return;
  116. g.actionMenu && g.actionMenu.hide();
  117. var left = $(this).offset().left;
  118. var top = $(this).offset().top + $(this).height();
  119. item.menu.show({ top: top, left: left });
  120. g.actionMenu = item.menu;
  121. $(this).addClass("l-panel-btn-over");
  122. }, function ()
  123. {
  124. if ($(this).hasClass("l-toolbar-item-disable")) return;
  125. $(this).removeClass("l-panel-btn-over");
  126. });
  127. }
  128. else
  129. {
  130. ditem.hover(function ()
  131. {
  132. if ($(this).hasClass("l-toolbar-item-disable")) return;
  133. $(this).addClass("l-panel-btn-over");
  134. }, function ()
  135. {
  136. if ($(this).hasClass("l-toolbar-item-disable")) return;
  137. $(this).removeClass("l-panel-btn-over");
  138. });
  139. }
  140. }
  141. });
  142. //旧写法保留
  143. $.ligerui.controls.ToolBar.prototype.setEnable = $.ligerui.controls.ToolBar.prototype.setEnabled;
  144. $.ligerui.controls.ToolBar.prototype.setDisable = $.ligerui.controls.ToolBar.prototype.setDisabled;
  145. })(jQuery);