| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- manager.registerUI('more', function (wdeditor, name) {
- var btn = new EditorManager.CheckBox({
- name: name,
-
- title: '',
- labelClassName:"label-more",
- text: '',
- className: 'more right icon-more',
- oninit: function () {
- //按钮填充到新的popup
- var this_ = this;
- this.resetMore();
- wdeditor.registerCommand(name, {
- execCommand: function () {
- var iframeHolder = wdeditor.getUeditor().iframe.parentNode,
- toolbar = wdeditor.getToolbar(),
- frameOriHeight = parseInt(window.getComputedStyle(iframeHolder).height),
- toolbarOriHeight = parseInt(window.getComputedStyle(toolbar).height);
- console.log(toolbar, frameOriHeight, toolbarOriHeight)
- var show = wdeditor.queryCommandState(this_.getCommand());
- if (show) {
- this_.moreMenu.hide(resetHeight);
- if (this_.iid) {
- clearInterval(this_.iid);
- }
- $(".icon-more").blur();
- } else {
- var pl = parseFloat($(wdeditor.btnpanel).css("padding-left")) + parseFloat($(wdeditor.btnpanel).css("margin-left"));
- var offset = {
- top: $(wdeditor.btnpanel).height(),
- left: pl
- };
- console.log(offset)
- this_.moreMenu.show(resetHeight);
- // $(moreMenu).slideDown();
- // popup.element.style.width = parseFloat($(wdeditor.btnpanel).width()) - pl ;
- // popup.showAt(offset);
- }
- function resetHeight() {
- var toolbarNowHeight = parseInt(window.getComputedStyle(toolbar).height);
- console.log(frameOriHeight, toolbarOriHeight, toolbarNowHeight)
- var height=frameOriHeight + toolbarOriHeight - toolbarNowHeight;
- wdeditor.getUeditor().setHeight(height);
- $(wdeditor.getUeditor().body).css("height",(height-25)+"px");
- }
- },
- queryCommandState: function () {
- return this_.moreMenu.isShow();
- }
- });
- },
- getMoreMenu: function () {
- if (this.moreMenu == null) {
- var moreBtn = this.getElement(null, true);
- var moreMenu = this.moreMenu = new moremenu(wdeditor);
- var first = wdeditor.getToolsPanel(0);
- $(first).after(moreMenu);
- }
- return this.moreMenu;
- },
- getMaxLeft: function () {
- var first = wdeditor.getToolsPanel(0);
- first.style.whiteSpace = "nowrap";
- var maxwidth = first.offsetWidth;
- var rightBtn = document.querySelectorAll("#" + wdeditor.id + "Edit .rightBtn");
- var min = maxwidth;
- for (var i = 0; i < rightBtn.length; i++) {
- var left = (rightBtn[i].offsetLeft || $(rightBtn[i]).offset().left) - parseFloat($(rightBtn[i]).css("padding-left")) - parseFloat($(rightBtn[i]).css("padding-right"));
- min = min > left ? left : min;
- }
- // min -= 10;
- return min;
- },
- resetMore: function () {
- var moreBtn = this.getElement(null, true);
- var min = this.getMaxLeft();
- if (min < 0)
- return;
- var te = $(moreBtn);
- var i = 0;
- var moreRight=0 ;
- while ((moreRight=moreBtn.offsetLeft + te.width() + parseFloat(te.css("padding-left")) + parseFloat(te.css("padding-right")))> min) {
- moreBtn.parentNode.insertBefore(moreBtn, moreBtn.previousSibling);
- if (i++ == 100)
- break;
- }
- },
- initMoreBtns: function () {
- var moreMenu = this.getMoreMenu();
- var nextElement;
- var moreBtn = this.getElement(null, true);
- // var i = 0;
- var first = wdeditor.getToolsPanel(0);
- var cns = first.childNodes;
- for (var i = cns.length - 1; i >= 0; i--) {
- var node_ = cns[i];
- if (node_ == moreBtn)
- break;
- if ($(node_).css("float") == "right") {
- continue;
- }
- moreMenu.insertBtn(node_);
- }
- wdeditor.btnpanel.appendChild(this.moreMenu.element);
- },
- setSelectionChange: function () {
- var this_ = this;
- wdeditor
- .addListener("selectionchange", function () {
- this_.resetMore();
- this_.initMoreBtns();
- });
- },
- onToolbarInit: function () {
- this.resetMore();
- this.initMoreBtns();
- }
- });
- var moremenu = function (editor, btns) {
- var editorid = editor.id;
- var element = this.element = document.createElement("div");
- element.id = "toolsPanel_" + editorid + "_more_panel";
- element.onselectstart = "return false";
- element.className = "more_panel";
- element.style.display = 'none';
- element.style.background = "#f7f7f7";
- element.style.maxHeight = "120";
- element.style.lineHeight = "44px";
- element.style.overflowY = "auto";
- element.style.padding = "0px 6px 6px 6px";
- this.btns = [];
- if (btns) {
- for (var i = 0; i < btns.length; i++) {
- var _element = btns[i].getElement();
- this.element.appendChild(_element);
- this.push(_element);
- }
- }
- this.isShow = function () {
- return this.isshow;
- }
- this.insertBtn = function (btn) {
- if (btn) {
- if (btn.getElement) {
- this.element.insertBefore(btn.getElement(), this.element.childNodes[0]);
- this.btns.unshift(btn.element);
- } else {
- this.element.insertBefore(btn, this.element.childNodes[0]);
- this.btns.unshift(btn);
- }
- }
- }
- this.addBtn = function (btn) {
- if (btn) {
- if (btn.getElement) {
- this.element.appendChild(btn.getElement());
- this.btns.push(btn.element);
- } else {
- this.element.appendChild(btn);
- this.btns.push(btn);
- }
- }
- }
- this.show = function (callback) {
- if (typeof $ == "undefined") {
- this.element.style.display = "block";
- callback && callback();
- } else {
- $(this.element).show();
- callback && callback();
- }
- this.isshow = true
- var bar = $(this.element);
- loadScorll(bar);
- bar.getNiceScroll().resize();
- }
- this.hide = function (callback) {
- if (typeof $ == "undefined") {
- this.element.style.display = "none";
- callback && callback();
- } else {
- $(this.element).hide();
- callback && callback();
- }
- this.isshow = false;
- var bar = $(this.element);
- loadScorll(bar);
- bar.getNiceScroll().resize();
- }
- }
- return btn;
- });
|