123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698 |
- CKEDITOR.plugins.add("floatpanel", {
- requires: "panel"
- });
- (function() {
- var panels = {};
- function getPanel(editor, doc, parentElement, definition, level) {
-
- var key = CKEDITOR.tools.genKey(
- doc.getUniqueId(),
- parentElement.getUniqueId(),
- editor.lang.dir,
- editor.uiColor || "",
- definition.css || "",
- level || ""
- ),
- panel = panels[key];
- if (!panel) {
- panel = panels[key] = new CKEDITOR.ui.panel(doc, definition);
- panel.element = parentElement.append(
- CKEDITOR.dom.element.createFromHtml(panel.render(editor), doc)
- );
- panel.element.setStyles({
- display: "none",
- position: "absolute"
- });
- }
- return panel;
- }
-
- CKEDITOR.ui.floatPanel = CKEDITOR.tools.createClass({
-
- $: function(editor, parentElement, definition, level) {
- definition.forceIFrame = 1;
-
-
- if (
- definition.toolbarRelated &&
- editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE
- )
- parentElement = CKEDITOR.document.getById("cke_" + editor.name);
- var doc = parentElement.getDocument(),
- panel = getPanel(editor, doc, parentElement, definition, level || 0),
- element = panel.element,
- iframe = element.getFirst(),
- that = this;
-
- element.disableContextMenu();
- this.element = element;
- this._ = {
- editor: editor,
-
- panel: panel,
- parentElement: parentElement,
- definition: definition,
- document: doc,
- iframe: iframe,
- children: [],
- dir: editor.lang.dir,
- showBlockParams: null,
- markFirst:
- definition.markFirst !== undefined ? definition.markFirst : true
- };
- editor.on("mode", hide);
- editor.on("resize", hide);
-
-
- doc.getWindow().on(
- "resize",
- function() {
- this.reposition();
- },
- this
- );
-
-
-
- function hide() {
- that.hide();
- }
- },
- proto: {
-
- addBlock: function(name, block) {
- return this._.panel.addBlock(name, block);
- },
-
- addListBlock: function(name, multiSelect) {
- return this._.panel.addListBlock(name, multiSelect);
- },
-
- getBlock: function(name) {
- return this._.panel.getBlock(name);
- },
-
- showBlock: function(
- name,
- offsetParent,
- corner,
- offsetX,
- offsetY,
- callback
- ) {
- var panel = this._.panel,
- block = panel.showBlock(name);
- this._.showBlockParams = [].slice.call(arguments);
- this.allowBlur(false);
-
- var editable = this._.editor.editable();
- this._.returnFocus = editable.hasFocus
- ? editable
- : new CKEDITOR.dom.element(CKEDITOR.document.$.activeElement);
- this._.hideTimeout = 0;
- var element = this.element,
- iframe = this._.iframe,
-
- focused =
- CKEDITOR.env.ie && !CKEDITOR.env.edge
- ? iframe
- : new CKEDITOR.dom.window(iframe.$.contentWindow),
- doc = element.getDocument(),
- positionedAncestor = this._.parentElement.getPositionedAncestor(),
- position = offsetParent.getDocumentPosition(doc),
- positionedAncestorPosition = positionedAncestor
- ? positionedAncestor.getDocumentPosition(doc)
- : { x: 0, y: 0 },
- rtl = this._.dir == "rtl",
- left = position.x + (offsetX || 0) - positionedAncestorPosition.x,
- top = position.y + (offsetY || 0) - positionedAncestorPosition.y;
-
- if (rtl && (corner == 1 || corner == 4))
- left += offsetParent.$.offsetWidth;
- else if (!rtl && (corner == 2 || corner == 3))
- left += offsetParent.$.offsetWidth - 1;
- if (corner == 3 || corner == 4) top += offsetParent.$.offsetHeight - 1;
-
- this._.panel._.offsetParentId = offsetParent.getId();
- element.setStyles({
- top: top + "px",
- left: 0,
- display: ""
- });
-
-
- element.setOpacity(0);
-
- element.getFirst().removeStyle("width");
-
- this._.editor.focusManager.add(focused);
-
- if (!this._.blurSet) {
-
-
-
- CKEDITOR.event.useCapture = true;
- focused.on(
- "blur",
- function(ev) {
-
-
-
-
- if (
- !this.allowBlur() ||
- ev.data.getPhase() != CKEDITOR.EVENT_PHASE_AT_TARGET
- )
- return;
- if (this.visible && !this._.activeChild) {
-
-
- if (CKEDITOR.env.iOS) {
- if (!this._.hideTimeout)
- this._.hideTimeout = CKEDITOR.tools.setTimeout(
- doHide,
- 0,
- this
- );
- } else {
- doHide.call(this);
- }
- }
- function doHide() {
-
-
- delete this._.returnFocus;
- this.hide();
- }
- },
- this
- );
- focused.on(
- "focus",
- function() {
- this._.focused = true;
- this.hideChild();
- this.allowBlur(true);
- },
- this
- );
-
-
- if (CKEDITOR.env.iOS) {
-
-
-
- focused.on(
- "touchstart",
- function() {
- clearTimeout(this._.hideTimeout);
- },
- this
- );
-
- focused.on(
- "touchend",
- function() {
- this._.hideTimeout = 0;
- this.focus();
- },
- this
- );
- }
- CKEDITOR.event.useCapture = false;
- this._.blurSet = 1;
- }
- panel.onEscape = CKEDITOR.tools.bind(function(keystroke) {
- if (this.onEscape && this.onEscape(keystroke) === false) return false;
- }, this);
- CKEDITOR.tools.setTimeout(
- function() {
- var panelLoad = CKEDITOR.tools.bind(function() {
- var target = element;
-
-
- target.removeStyle("width");
- if (block.autoSize) {
- var panelDoc = block.element.getDocument(),
- width = (CKEDITOR.env.webkit || CKEDITOR.env.edge
- ? block.element
- : panelDoc.getBody()
- ).$.scrollWidth;
-
-
-
- if (CKEDITOR.env.ie && CKEDITOR.env.quirks && width > 0)
- width +=
- (target.$.offsetWidth || 0) -
- (target.$.clientWidth || 0) +
- 3;
-
- width += 10;
- target.setStyle("width", width + "px");
- var height = block.element.$.scrollHeight;
-
-
-
- if (CKEDITOR.env.ie && CKEDITOR.env.quirks && height > 0)
- height +=
- (target.$.offsetHeight || 0) -
- (target.$.clientHeight || 0) +
- 3;
- target.setStyle("height", height + "px");
-
- panel._.currentBlock.element
- .setStyle("display", "none")
- .removeStyle("display");
- } else {
- target.removeStyle("height");
- }
-
- if (rtl) left -= element.$.offsetWidth;
-
- element.setStyle("left", left + "px");
-
- var panelElement = panel.element,
- panelWindow = panelElement.getWindow(),
- rect = element.$.getBoundingClientRect(),
- viewportSize = panelWindow.getViewPaneSize();
-
- var rectWidth = rect.width || rect.right - rect.left,
- rectHeight = rect.height || rect.bottom - rect.top;
-
- var spaceAfter = rtl
- ? rect.right
- : viewportSize.width - rect.left,
- spaceBefore = rtl ? viewportSize.width - rect.right : rect.left;
- if (rtl) {
- if (spaceAfter < rectWidth) {
-
- if (spaceBefore > rectWidth) left += rectWidth;
-
- else if (viewportSize.width > rectWidth)
- left = left - rect.left;
-
- else left = left - rect.right + viewportSize.width;
- }
- } else if (spaceAfter < rectWidth) {
-
- if (spaceBefore > rectWidth) left -= rectWidth;
-
- else if (viewportSize.width > rectWidth)
- left = left - rect.right + viewportSize.width;
-
- else left = left - rect.left;
- }
-
- var spaceBelow = viewportSize.height - rect.top,
- spaceAbove = rect.top;
- if (spaceBelow < rectHeight) {
-
- if (spaceAbove > rectHeight) top -= rectHeight;
-
- else if (viewportSize.height > rectHeight)
- top = top - rect.bottom + viewportSize.height;
-
- else top = top - rect.top;
- }
-
-
-
- if (CKEDITOR.env.ie && !CKEDITOR.env.edge) {
- var offsetParent = new CKEDITOR.dom.element(
- element.$.offsetParent
- ),
- scrollParent = offsetParent;
-
- if (scrollParent.getName() == "html") {
- scrollParent = scrollParent.getDocument().getBody();
- }
- if (scrollParent.getComputedStyle("direction") == "rtl") {
-
- if (CKEDITOR.env.ie8Compat) {
- left -=
- element.getDocument().getDocumentElement().$.scrollLeft *
- 2;
- } else {
- left -=
- offsetParent.$.scrollWidth - offsetParent.$.clientWidth;
- }
- }
- }
-
-
- var innerElement = element.getFirst(),
- activePanel;
- if ((activePanel = innerElement.getCustomData("activePanel")))
- activePanel.onHide && activePanel.onHide.call(this, 1);
- innerElement.setCustomData("activePanel", this);
- element.setStyles({
- top: top + "px",
- left: left + "px"
- });
- element.setOpacity(1);
- callback && callback();
- }, this);
- panel.isLoaded ? panelLoad() : (panel.onLoad = panelLoad);
- CKEDITOR.tools.setTimeout(
- function() {
- var scrollTop =
- CKEDITOR.env.webkit &&
- CKEDITOR.document.getWindow().getScrollPosition().y;
-
- this.focus();
-
- block.element.focus();
-
- if (CKEDITOR.env.webkit)
- CKEDITOR.document.getBody().$.scrollTop = scrollTop;
-
- this.allowBlur(true);
-
- if (this._.markFirst) {
- if (CKEDITOR.env.ie) {
- CKEDITOR.tools.setTimeout(function() {
- block.markFirstDisplayed
- ? block.markFirstDisplayed()
- : block._.markFirstDisplayed();
- }, 0);
- } else {
- block.markFirstDisplayed
- ? block.markFirstDisplayed()
- : block._.markFirstDisplayed();
- }
- }
- this._.editor.fire("panelShow", this);
- },
- 0,
- this
- );
- },
- CKEDITOR.env.air ? 200 : 0,
- this
- );
- this.visible = 1;
- if (this.onShow) this.onShow.call(this);
- },
-
- reposition: function() {
- var blockParams = this._.showBlockParams;
- if (this.visible && this._.showBlockParams) {
- this.hide();
- this.showBlock.apply(this, blockParams);
- }
- },
-
- focus: function() {
-
-
- if (CKEDITOR.env.webkit) {
- var active = CKEDITOR.document.getActive();
- active && !active.equals(this._.iframe) && active.$.blur();
- }
-
- var focus =
- this._.lastFocused || this._.iframe.getFrameDocument().getWindow();
- focus.focus();
- },
-
- blur: function() {
- var doc = this._.iframe.getFrameDocument(),
- active = doc.getActive();
- active && active.is("a") && (this._.lastFocused = active);
- },
-
- hide: function(returnFocus) {
- if (this.visible && (!this.onHide || this.onHide.call(this) !== true)) {
- this.hideChild();
-
- CKEDITOR.env.gecko &&
- this._.iframe.getFrameDocument().$.activeElement.blur();
- this.element.setStyle("display", "none");
- this.visible = 0;
- this.element.getFirst().removeCustomData("activePanel");
-
- var focusReturn = returnFocus && this._.returnFocus;
- if (focusReturn) {
-
- if (CKEDITOR.env.webkit && focusReturn.type)
- focusReturn.getWindow().$.focus();
- focusReturn.focus();
- }
- delete this._.lastFocused;
- this._.showBlockParams = null;
- this._.editor.fire("panelHide", this);
- }
- },
-
- allowBlur: function(allow) {
-
- var panel = this._.panel;
- if (allow !== undefined) panel.allowBlur = allow;
- return panel.allowBlur;
- },
-
- showAsChild: function(
- panel,
- blockName,
- offsetParent,
- corner,
- offsetX,
- offsetY
- ) {
-
- if (
- this._.activeChild == panel &&
- panel._.panel._.offsetParentId == offsetParent.getId()
- )
- return;
- this.hideChild();
- panel.onHide = CKEDITOR.tools.bind(function() {
-
-
- CKEDITOR.tools.setTimeout(
- function() {
- if (!this._.focused) this.hide();
- },
- 0,
- this
- );
- }, this);
- this._.activeChild = panel;
- this._.focused = false;
- panel.showBlock(blockName, offsetParent, corner, offsetX, offsetY);
- this.blur();
-
- if (CKEDITOR.env.ie7Compat || CKEDITOR.env.ie6Compat) {
- setTimeout(function() {
- panel.element.getChild(0).$.style.cssText += "";
- }, 100);
- }
- },
-
- hideChild: function(restoreFocus) {
- var activeChild = this._.activeChild;
- if (activeChild) {
- delete activeChild.onHide;
- delete this._.activeChild;
- activeChild.hide();
-
- restoreFocus && this.focus();
- }
- }
- }
- });
- CKEDITOR.on("instanceDestroyed", function() {
- var isLastInstance = CKEDITOR.tools.isEmpty(CKEDITOR.instances);
- for (var i in panels) {
- var panel = panels[i];
-
- if (isLastInstance) panel.destroy();
-
- else panel.element.hide();
- }
-
- isLastInstance && (panels = {});
- });
- })();
|