只读模式
group, 分享
评论更多问题
博客标签总是存在一个
This commit is contained in:
lealife
2015-06-15 18:01:48 +08:00
parent 7e458bb433
commit 6987a38820
1453 changed files with 114561 additions and 91536 deletions

323
public/tinymce/classes/ui/FloatPanel.js Normal file → Executable file
View File

@ -25,9 +25,164 @@ define("tinymce/ui/FloatPanel", [
], function(Panel, Movable, Resizable, DomUtils) {
"use strict";
var documentClickHandler, documentScrollHandler, visiblePanels = [];
var documentClickHandler, documentScrollHandler, windowResizeHandler, visiblePanels = [];
var zOrder = [], hasModal;
function bindDocumentClickHandler() {
function isChildOf(ctrl, parent) {
while (ctrl) {
if (ctrl == parent) {
return true;
}
ctrl = ctrl.parent();
}
}
if (!documentClickHandler) {
documentClickHandler = function(e) {
// Gecko fires click event and in the wrong order on Mac so lets normalize
if (e.button == 2) {
return;
}
// Hide any float panel when a click is out side that float panel and the
// float panels direct parent for example a click on a menu button
var i = visiblePanels.length;
while (i--) {
var panel = visiblePanels[i], clickCtrl = panel.getParentCtrl(e.target);
if (panel.settings.autohide) {
if (clickCtrl) {
if (isChildOf(clickCtrl, panel) || panel.parent() === clickCtrl) {
continue;
}
}
e = panel.fire('autohide', {target: e.target});
if (!e.isDefaultPrevented()) {
panel.hide();
}
}
}
};
DomUtils.on(document, 'click', documentClickHandler);
}
}
function bindDocumentScrollHandler() {
if (!documentScrollHandler) {
documentScrollHandler = function() {
var i;
i = visiblePanels.length;
while (i--) {
repositionPanel(visiblePanels[i]);
}
};
DomUtils.on(window, 'scroll', documentScrollHandler);
}
}
function bindWindowResizeHandler() {
if (!windowResizeHandler) {
var docElm = document.documentElement, clientWidth = docElm.clientWidth, clientHeight = docElm.clientHeight;
windowResizeHandler = function() {
// Workaround for #7065 IE 7 fires resize events event though the window wasn't resized
if (!document.all || clientWidth != docElm.clientWidth || clientHeight != docElm.clientHeight) {
clientWidth = docElm.clientWidth;
clientHeight = docElm.clientHeight;
FloatPanel.hideAll();
}
};
DomUtils.on(window, 'resize', windowResizeHandler);
}
}
/**
* Repositions the panel to the top of page if the panel is outside of the visual viewport. It will
* also reposition all child panels of the current panel.
*/
function repositionPanel(panel) {
var scrollY = DomUtils.getViewPort().y;
function toggleFixedChildPanels(fixed, deltaY) {
var parent;
for (var i = 0; i < visiblePanels.length; i++) {
if (visiblePanels[i] != panel) {
parent = visiblePanels[i].parent();
while (parent && (parent = parent.parent())) {
if (parent == panel) {
visiblePanels[i].fixed(fixed).moveBy(0, deltaY).repaint();
}
}
}
}
}
if (panel.settings.autofix) {
if (!panel._fixed) {
panel._autoFixY = panel.layoutRect().y;
if (panel._autoFixY < scrollY) {
panel.fixed(true).layoutRect({y: 0}).repaint();
toggleFixedChildPanels(true, scrollY - panel._autoFixY);
}
} else {
if (panel._autoFixY > scrollY) {
panel.fixed(false).layoutRect({y: panel._autoFixY}).repaint();
toggleFixedChildPanels(false, panel._autoFixY - scrollY);
}
}
}
}
function addRemove(add, ctrl) {
var i, zIndex = FloatPanel.zIndex || 0xFFFF, topModal;
if (add) {
zOrder.push(ctrl);
} else {
i = zOrder.length;
while (i--) {
if (zOrder[i] === ctrl) {
zOrder.splice(i, 1);
}
}
}
if (zOrder.length) {
for (i = 0; i < zOrder.length; i++) {
if (zOrder[i].modal) {
zIndex++;
topModal = zOrder[i];
}
zOrder[i].getEl().style.zIndex = zIndex;
zOrder[i].zIndex = zIndex;
zIndex++;
}
}
var modalBlockEl = document.getElementById(ctrl.classPrefix + 'modal-block');
if (topModal) {
DomUtils.css(modalBlockEl, 'z-index', topModal.zIndex - 1);
} else if (modalBlockEl) {
modalBlockEl.parentNode.removeChild(modalBlockEl);
hasModal = false;
}
FloatPanel.currentZIndex = zIndex;
}
var FloatPanel = Panel.extend({
Mixins: [Movable, Resizable],
@ -41,84 +196,6 @@ define("tinymce/ui/FloatPanel", [
init: function(settings) {
var self = this;
function reorder() {
var i, zIndex = FloatPanel.zIndex || 0xFFFF, topModal;
if (zOrder.length) {
for (i = 0; i < zOrder.length; i++) {
if (zOrder[i].modal) {
zIndex++;
topModal = zOrder[i];
}
zOrder[i].getEl().style.zIndex = zIndex;
zOrder[i].zIndex = zIndex;
zIndex++;
}
}
var modalBlockEl = document.getElementById(self.classPrefix + 'modal-block');
if (topModal) {
DomUtils.css(modalBlockEl, 'z-index', topModal.zIndex - 1);
} else if (modalBlockEl) {
modalBlockEl.parentNode.removeChild(modalBlockEl);
hasModal = false;
}
FloatPanel.currentZIndex = zIndex;
}
function isChildOf(ctrl, parent) {
while (ctrl) {
if (ctrl == parent) {
return true;
}
ctrl = ctrl.parent();
}
}
/**
* Repositions the panel to the top of page if the panel is outside of the visual viewport. It will
* also reposition all child panels of the current panel.
*/
function repositionPanel(panel) {
var scrollY = DomUtils.getViewPort().y;
function toggleFixedChildPanels(fixed, deltaY) {
var parent;
for (var i = 0; i < visiblePanels.length; i++) {
if (visiblePanels[i] != panel) {
parent = visiblePanels[i].parent();
while (parent && (parent = parent.parent())) {
if (parent == panel) {
visiblePanels[i].fixed(fixed).moveBy(0, deltaY).repaint();
}
}
}
}
}
if (panel.settings.autofix) {
if (!panel._fixed) {
panel._autoFixY = panel.layoutRect().y;
if (panel._autoFixY < scrollY) {
panel.fixed(true).layoutRect({y: 0}).repaint();
toggleFixedChildPanels(true, scrollY - panel._autoFixY);
}
} else {
if (panel._autoFixY > scrollY) {
panel.fixed(false).layoutRect({y: panel._autoFixY}).repaint();
toggleFixedChildPanels(false, panel._autoFixY - scrollY);
}
}
}
}
self._super(settings);
self._eventsRoot = self;
@ -126,50 +203,13 @@ define("tinymce/ui/FloatPanel", [
// Hide floatpanes on click out side the root button
if (settings.autohide) {
if (!documentClickHandler) {
documentClickHandler = function(e) {
var i, clickCtrl = self.getParentCtrl(e.target);
// Hide any float panel when a click is out side that float panel and the
// float panels direct parent for example a click on a menu button
i = visiblePanels.length;
while (i--) {
var panel = visiblePanels[i];
if (panel.settings.autohide) {
if (clickCtrl) {
if (isChildOf(clickCtrl, panel) || panel.parent() === clickCtrl) {
continue;
}
}
e = panel.fire('autohide', {target: e.target});
if (!e.isDefaultPrevented()) {
panel.hide();
}
}
}
};
DomUtils.on(document, 'click', documentClickHandler);
}
bindDocumentClickHandler();
bindWindowResizeHandler();
visiblePanels.push(self);
}
if (settings.autofix) {
if (!documentScrollHandler) {
documentScrollHandler = function() {
var i;
i = visiblePanels.length;
while (i--) {
repositionPanel(visiblePanels[i]);
}
};
DomUtils.on(window, 'scroll', documentScrollHandler);
}
bindDocumentScrollHandler();
self.on('move', function() {
repositionPanel(this);
@ -195,22 +235,7 @@ define("tinymce/ui/FloatPanel", [
hasModal = true;
}
zOrder.push(self);
reorder();
}
});
self.on('close hide', function(e) {
if (e.control == self) {
var i = zOrder.length;
while (i--) {
if (zOrder[i] === self) {
zOrder.splice(i, 1);
}
}
reorder();
addRemove(true, self);
}
});
@ -281,11 +306,14 @@ define("tinymce/ui/FloatPanel", [
*/
hide: function() {
removeVisiblePanel(this);
addRemove(false, this);
return this._super();
},
/**
* Hides all visible the float panels.
* Hide all visible float panels with he autohide setting enabled. This is for
* manually hiding floating menus or panels.
*
* @method hideAll
*/
@ -301,9 +329,12 @@ define("tinymce/ui/FloatPanel", [
close: function() {
var self = this;
self.fire('close');
if (!self.fire('close').isDefaultPrevented()) {
self.remove();
addRemove(false, self);
}
return self.remove();
return self;
},
/**
@ -314,11 +345,22 @@ define("tinymce/ui/FloatPanel", [
remove: function() {
removeVisiblePanel(this);
this._super();
},
postRender: function() {
var self = this;
if (self.settings.bodyRole) {
this.getEl('body').setAttribute('role', self.settings.bodyRole);
}
return self._super();
}
});
/**
* Hides all visible the float panels.
* Hide all visible float panels with he autohide setting enabled. This is for
* manually hiding floating menus or panels.
*
* @static
* @method hideAll
@ -329,8 +371,7 @@ define("tinymce/ui/FloatPanel", [
while (i--) {
var panel = visiblePanels[i];
if (panel.settings.autohide) {
panel.fire('cancel', {}, false);
if (panel && panel.settings.autohide) {
panel.hide();
visiblePanels.splice(i, 1);
}