wdEditor.more.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. manager.registerUI('more', function (wdeditor, name) {
  2. var btn = new EditorManager.CheckBox({
  3. name: name,
  4. title: '',
  5. labelClassName:"label-more",
  6. text: '',
  7. className: 'more right icon-more',
  8. oninit: function () {
  9. //按钮填充到新的popup
  10. var this_ = this;
  11. this.resetMore();
  12. wdeditor.registerCommand(name, {
  13. execCommand: function () {
  14. var iframeHolder = wdeditor.getUeditor().iframe.parentNode,
  15. toolbar = wdeditor.getToolbar(),
  16. frameOriHeight = parseInt(window.getComputedStyle(iframeHolder).height),
  17. toolbarOriHeight = parseInt(window.getComputedStyle(toolbar).height);
  18. console.log(toolbar, frameOriHeight, toolbarOriHeight)
  19. var show = wdeditor.queryCommandState(this_.getCommand());
  20. if (show) {
  21. this_.moreMenu.hide(resetHeight);
  22. if (this_.iid) {
  23. clearInterval(this_.iid);
  24. }
  25. $(".icon-more").blur();
  26. } else {
  27. var pl = parseFloat($(wdeditor.btnpanel).css("padding-left")) + parseFloat($(wdeditor.btnpanel).css("margin-left"));
  28. var offset = {
  29. top: $(wdeditor.btnpanel).height(),
  30. left: pl
  31. };
  32. console.log(offset)
  33. this_.moreMenu.show(resetHeight);
  34. // $(moreMenu).slideDown();
  35. // popup.element.style.width = parseFloat($(wdeditor.btnpanel).width()) - pl ;
  36. // popup.showAt(offset);
  37. }
  38. function resetHeight() {
  39. var toolbarNowHeight = parseInt(window.getComputedStyle(toolbar).height);
  40. console.log(frameOriHeight, toolbarOriHeight, toolbarNowHeight)
  41. var height=frameOriHeight + toolbarOriHeight - toolbarNowHeight;
  42. wdeditor.getUeditor().setHeight(height);
  43. $(wdeditor.getUeditor().body).css("height",(height-25)+"px");
  44. }
  45. },
  46. queryCommandState: function () {
  47. return this_.moreMenu.isShow();
  48. }
  49. });
  50. },
  51. getMoreMenu: function () {
  52. if (this.moreMenu == null) {
  53. var moreBtn = this.getElement(null, true);
  54. var moreMenu = this.moreMenu = new moremenu(wdeditor);
  55. var first = wdeditor.getToolsPanel(0);
  56. $(first).after(moreMenu);
  57. }
  58. return this.moreMenu;
  59. },
  60. getMaxLeft: function () {
  61. var first = wdeditor.getToolsPanel(0);
  62. first.style.whiteSpace = "nowrap";
  63. var maxwidth = first.offsetWidth;
  64. var rightBtn = document.querySelectorAll("#" + wdeditor.id + "Edit .rightBtn");
  65. var min = maxwidth;
  66. for (var i = 0; i < rightBtn.length; i++) {
  67. var left = (rightBtn[i].offsetLeft || $(rightBtn[i]).offset().left) - parseFloat($(rightBtn[i]).css("padding-left")) - parseFloat($(rightBtn[i]).css("padding-right"));
  68. min = min > left ? left : min;
  69. }
  70. // min -= 10;
  71. return min;
  72. },
  73. resetMore: function () {
  74. var moreBtn = this.getElement(null, true);
  75. var min = this.getMaxLeft();
  76. if (min < 0)
  77. return;
  78. var te = $(moreBtn);
  79. var i = 0;
  80. var moreRight=0 ;
  81. while ((moreRight=moreBtn.offsetLeft + te.width() + parseFloat(te.css("padding-left")) + parseFloat(te.css("padding-right")))> min) {
  82. moreBtn.parentNode.insertBefore(moreBtn, moreBtn.previousSibling);
  83. if (i++ == 100)
  84. break;
  85. }
  86. },
  87. initMoreBtns: function () {
  88. var moreMenu = this.getMoreMenu();
  89. var nextElement;
  90. var moreBtn = this.getElement(null, true);
  91. // var i = 0;
  92. var first = wdeditor.getToolsPanel(0);
  93. var cns = first.childNodes;
  94. for (var i = cns.length - 1; i >= 0; i--) {
  95. var node_ = cns[i];
  96. if (node_ == moreBtn)
  97. break;
  98. if ($(node_).css("float") == "right") {
  99. continue;
  100. }
  101. moreMenu.insertBtn(node_);
  102. }
  103. wdeditor.btnpanel.appendChild(this.moreMenu.element);
  104. },
  105. setSelectionChange: function () {
  106. var this_ = this;
  107. wdeditor
  108. .addListener("selectionchange", function () {
  109. this_.resetMore();
  110. this_.initMoreBtns();
  111. });
  112. },
  113. onToolbarInit: function () {
  114. this.resetMore();
  115. this.initMoreBtns();
  116. }
  117. });
  118. var moremenu = function (editor, btns) {
  119. var editorid = editor.id;
  120. var element = this.element = document.createElement("div");
  121. element.id = "toolsPanel_" + editorid + "_more_panel";
  122. element.onselectstart = "return false";
  123. element.className = "more_panel";
  124. element.style.display = 'none';
  125. element.style.background = "#f7f7f7";
  126. element.style.maxHeight = "120";
  127. element.style.lineHeight = "44px";
  128. element.style.overflowY = "auto";
  129. element.style.padding = "0px 6px 6px 6px";
  130. this.btns = [];
  131. if (btns) {
  132. for (var i = 0; i < btns.length; i++) {
  133. var _element = btns[i].getElement();
  134. this.element.appendChild(_element);
  135. this.push(_element);
  136. }
  137. }
  138. this.isShow = function () {
  139. return this.isshow;
  140. }
  141. this.insertBtn = function (btn) {
  142. if (btn) {
  143. if (btn.getElement) {
  144. this.element.insertBefore(btn.getElement(), this.element.childNodes[0]);
  145. this.btns.unshift(btn.element);
  146. } else {
  147. this.element.insertBefore(btn, this.element.childNodes[0]);
  148. this.btns.unshift(btn);
  149. }
  150. }
  151. }
  152. this.addBtn = function (btn) {
  153. if (btn) {
  154. if (btn.getElement) {
  155. this.element.appendChild(btn.getElement());
  156. this.btns.push(btn.element);
  157. } else {
  158. this.element.appendChild(btn);
  159. this.btns.push(btn);
  160. }
  161. }
  162. }
  163. this.show = function (callback) {
  164. if (typeof $ == "undefined") {
  165. this.element.style.display = "block";
  166. callback && callback();
  167. } else {
  168. $(this.element).show();
  169. callback && callback();
  170. }
  171. this.isshow = true
  172. var bar = $(this.element);
  173. loadScorll(bar);
  174. bar.getNiceScroll().resize();
  175. }
  176. this.hide = function (callback) {
  177. if (typeof $ == "undefined") {
  178. this.element.style.display = "none";
  179. callback && callback();
  180. } else {
  181. $(this.element).hide();
  182. callback && callback();
  183. }
  184. this.isshow = false;
  185. var bar = $(this.element);
  186. loadScorll(bar);
  187. bar.getNiceScroll().resize();
  188. }
  189. }
  190. return btn;
  191. });