///import core ///import uicore ///import ui/mask.js ///import ui/button.js (function() { var utils = baidu.editor.utils, domUtils = baidu.editor.dom.domUtils, uiUtils = baidu.editor.ui.uiUtils, Mask = baidu.editor.ui.Mask, UIBase = baidu.editor.ui.UIBase, Button = baidu.editor.ui.Button, Dialog = (baidu.editor.ui.Dialog = function(options) { if (options.name) { var name = options.name; var cssRules = options.cssRules; if (!options.className) { options.className = "edui-for-" + name; } if (cssRules) { options.cssRules = ".edui-for-" + name + " .edui-dialog-content {" + cssRules + "}"; } } this.initOptions( utils.extend( { autoReset: true, draggable: true, onok: function() {}, oncancel: function() {}, onclose: function(t, ok) { return ok ? this.onok() : this.oncancel(); }, //是否控制dialog中的scroll事件, 默认为不阻止 holdScroll: false }, options ) ); this.initDialog(); }); var modalMask; var dragMask; var activeDialog; Dialog.prototype = { draggable: false, uiName: "dialog", initDialog: function() { var me = this, theme = this.editor.options.theme; if (this.cssRules) { this.cssRules = ".edui-" + theme + " " + this.cssRules; utils.cssRule("edui-customize-" + this.name + "-style", this.cssRules); } this.initUIBase(); this.modalMask = modalMask || (modalMask = new Mask({ className: "edui-dialog-modalmask", theme: theme, onclick: function() { activeDialog && activeDialog.close(false); } })); this.dragMask = dragMask || (dragMask = new Mask({ className: "edui-dialog-dragmask", theme: theme })); this.closeButton = new Button({ className: "edui-dialog-closebutton", title: me.closeDialog, theme: theme, onclick: function() { me.close(false); } }); this.fullscreen && this.initResizeEvent(); if (this.buttons) { for (var i = 0; i < this.buttons.length; i++) { if (!(this.buttons[i] instanceof Button)) { this.buttons[i] = new Button( utils.extend( this.buttons[i], { editor: this.editor }, true ) ); } } } }, initResizeEvent: function() { var me = this; domUtils.on(window, "resize", function() { if (me._hidden || me._hidden === undefined) { return; } if (me.__resizeTimer) { window.clearTimeout(me.__resizeTimer); } me.__resizeTimer = window.setTimeout(function() { me.__resizeTimer = null; var dialogWrapNode = me.getDom(), contentNode = me.getDom("content"), wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode), contentRect = UE.ui.uiUtils.getClientRect(contentNode), vpRect = uiUtils.getViewportRect(); contentNode.style.width = vpRect.width - wrapRect.width + contentRect.width + "px"; contentNode.style.height = vpRect.height - wrapRect.height + contentRect.height + "px"; dialogWrapNode.style.width = vpRect.width + "px"; dialogWrapNode.style.height = vpRect.height + "px"; me.fireEvent("resize"); }, 100); }); }, fitSize: function() { var popBodyEl = this.getDom("body"); // if (!(baidu.editor.browser.ie && baidu.editor.browser.version == 7)) { // uiUtils.removeStyle(popBodyEl, 'width'); // uiUtils.removeStyle(popBodyEl, 'height'); // } var size = this.mesureSize(); popBodyEl.style.width = size.width + "px"; popBodyEl.style.height = size.height + "px"; return size; }, safeSetOffset: function(offset) { var me = this; var el = me.getDom(); var vpRect = uiUtils.getViewportRect(); var rect = uiUtils.getClientRect(el); var left = offset.left; if (left + rect.width > vpRect.right) { left = vpRect.right - rect.width; } var top = offset.top; if (top + rect.height > vpRect.bottom) { top = vpRect.bottom - rect.height; } el.style.left = Math.max(left, 0) + "px"; el.style.top = Math.max(top, 0) + "px"; }, showAtCenter: function() { var vpRect = uiUtils.getViewportRect(); if (!this.fullscreen) { this.getDom().style.display = ""; var popSize = this.fitSize(); var titleHeight = this.getDom("titlebar").offsetHeight | 0; var left = vpRect.width / 2 - popSize.width / 2; var top = vpRect.height / 2 - (popSize.height - titleHeight) / 2 - titleHeight; var popEl = this.getDom(); this.safeSetOffset({ left: Math.max(left | 0, 0), top: Math.max(top | 0, 0) }); if (!domUtils.hasClass(popEl, "edui-state-centered")) { popEl.className += " edui-state-centered"; } } else { var dialogWrapNode = this.getDom(), contentNode = this.getDom("content"); dialogWrapNode.style.display = "block"; var wrapRect = UE.ui.uiUtils.getClientRect(dialogWrapNode), contentRect = UE.ui.uiUtils.getClientRect(contentNode); dialogWrapNode.style.left = "-100000px"; contentNode.style.width = vpRect.width - wrapRect.width + contentRect.width + "px"; contentNode.style.height = vpRect.height - wrapRect.height + contentRect.height + "px"; dialogWrapNode.style.width = vpRect.width + "px"; dialogWrapNode.style.height = vpRect.height + "px"; dialogWrapNode.style.left = 0; //保存环境的overflow值 this._originalContext = { html: { overflowX: document.documentElement.style.overflowX, overflowY: document.documentElement.style.overflowY }, body: { overflowX: document.body.style.overflowX, overflowY: document.body.style.overflowY } }; document.documentElement.style.overflowX = "hidden"; document.documentElement.style.overflowY = "hidden"; document.body.style.overflowX = "hidden"; document.body.style.overflowY = "hidden"; } this._show(); }, getContentHtml: function() { var contentHtml = ""; if (typeof this.content == "string") { contentHtml = this.content; } else if (this.iframeUrl) { contentHtml = ''; } return contentHtml; }, getHtmlTpl: function() { var footHtml = ""; if (this.buttons) { var buff = []; for (var i = 0; i < this.buttons.length; i++) { buff[i] = this.buttons[i].renderHtml(); } footHtml = '