mirror of
https://github.com/documize/community.git
synced 2025-07-23 15:19:42 +02:00
saving and inserting reusable content blocks
This commit is contained in:
parent
fdbf03b25c
commit
b7fa3b9006
32 changed files with 1334 additions and 768 deletions
139
app/vendor/tether.js
vendored
139
app/vendor/tether.js
vendored
|
@ -1,4 +1,4 @@
|
|||
/*! tether 1.3.2 */
|
||||
/*! tether 1.4.0 */
|
||||
|
||||
(function(root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
|
@ -23,6 +23,32 @@ if (typeof TetherBase === 'undefined') {
|
|||
|
||||
var zeroElement = null;
|
||||
|
||||
// Same as native getBoundingClientRect, except it takes into account parent <frame> offsets
|
||||
// if the element lies within a nested document (<frame> or <iframe>-like).
|
||||
function getActualBoundingClientRect(node) {
|
||||
var boundingRect = node.getBoundingClientRect();
|
||||
|
||||
// The original object returned by getBoundingClientRect is immutable, so we clone it
|
||||
// We can't use extend because the properties are not considered part of the object by hasOwnProperty in IE9
|
||||
var rect = {};
|
||||
for (var k in boundingRect) {
|
||||
rect[k] = boundingRect[k];
|
||||
}
|
||||
|
||||
if (node.ownerDocument !== document) {
|
||||
var _frameElement = node.ownerDocument.defaultView.frameElement;
|
||||
if (_frameElement) {
|
||||
var frameRect = getActualBoundingClientRect(_frameElement);
|
||||
rect.top += frameRect.top;
|
||||
rect.bottom += frameRect.top;
|
||||
rect.left += frameRect.left;
|
||||
rect.right += frameRect.left;
|
||||
}
|
||||
}
|
||||
|
||||
return rect;
|
||||
}
|
||||
|
||||
function getScrollParents(el) {
|
||||
// In firefox if the el is inside an iframe with display: none; window.getComputedStyle() will return null;
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=548397
|
||||
|
@ -51,14 +77,20 @@ function getScrollParents(el) {
|
|||
var overflowX = _style.overflowX;
|
||||
var overflowY = _style.overflowY;
|
||||
|
||||
if (/(auto|scroll)/.test(overflow + overflowY + overflowX)) {
|
||||
if (/(auto|scroll|overlay)/.test(overflow + overflowY + overflowX)) {
|
||||
if (position !== 'absolute' || ['relative', 'absolute', 'fixed'].indexOf(style.position) >= 0) {
|
||||
parents.push(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parents.push(document.body);
|
||||
parents.push(el.ownerDocument.body);
|
||||
|
||||
// If the node is within a frame, account for the parent window scroll
|
||||
if (el.ownerDocument !== document) {
|
||||
parents.push(el.ownerDocument.defaultView);
|
||||
}
|
||||
|
||||
return parents;
|
||||
}
|
||||
|
||||
|
@ -76,7 +108,7 @@ var getOrigin = function getOrigin() {
|
|||
// are equivilant or not. We place an element at the top left of the page that will
|
||||
// get the same jitter, so we can cancel the two out.
|
||||
var node = zeroElement;
|
||||
if (!node) {
|
||||
if (!node || !document.body.contains(node)) {
|
||||
node = document.createElement('div');
|
||||
node.setAttribute('data-tether-id', uniqueId());
|
||||
extend(node.style, {
|
||||
|
@ -92,13 +124,7 @@ var getOrigin = function getOrigin() {
|
|||
|
||||
var id = node.getAttribute('data-tether-id');
|
||||
if (typeof zeroPosCache[id] === 'undefined') {
|
||||
zeroPosCache[id] = {};
|
||||
|
||||
var rect = node.getBoundingClientRect();
|
||||
for (var k in rect) {
|
||||
// Can't use extend, as on IE9, elements don't resolve to be hasOwnProperty
|
||||
zeroPosCache[id][k] = rect[k];
|
||||
}
|
||||
zeroPosCache[id] = getActualBoundingClientRect(node);
|
||||
|
||||
// Clear the cache when this position call is done
|
||||
defer(function () {
|
||||
|
@ -127,13 +153,7 @@ function getBounds(el) {
|
|||
|
||||
var docEl = doc.documentElement;
|
||||
|
||||
var box = {};
|
||||
// The original object returned by getBoundingClientRect is immutable, so we clone it
|
||||
// We can't use extend because the properties are not considered part of the object by hasOwnProperty in IE9
|
||||
var rect = el.getBoundingClientRect();
|
||||
for (var k in rect) {
|
||||
box[k] = rect[k];
|
||||
}
|
||||
var box = getActualBoundingClientRect(el);
|
||||
|
||||
var origin = getOrigin();
|
||||
|
||||
|
@ -159,7 +179,11 @@ function getOffsetParent(el) {
|
|||
return el.offsetParent || document.documentElement;
|
||||
}
|
||||
|
||||
var _scrollBarSize = null;
|
||||
function getScrollBarSize() {
|
||||
if (_scrollBarSize) {
|
||||
return _scrollBarSize;
|
||||
}
|
||||
var inner = document.createElement('div');
|
||||
inner.style.width = '100%';
|
||||
inner.style.height = '200px';
|
||||
|
@ -192,7 +216,8 @@ function getScrollBarSize() {
|
|||
|
||||
var width = widthContained - widthScroll;
|
||||
|
||||
return { width: width, height: width };
|
||||
_scrollBarSize = { width: width, height: width };
|
||||
return _scrollBarSize;
|
||||
}
|
||||
|
||||
function extend() {
|
||||
|
@ -252,7 +277,9 @@ function hasClass(el, name) {
|
|||
}
|
||||
|
||||
function getClassName(el) {
|
||||
if (el.className instanceof SVGAnimatedString) {
|
||||
// Can't use just SVGAnimatedString here since nodes within a Frame in IE have
|
||||
// completely separately SVGAnimatedString base classes
|
||||
if (el.className instanceof el.ownerDocument.defaultView.SVGAnimatedString) {
|
||||
return el.className.baseVal;
|
||||
}
|
||||
return el.className;
|
||||
|
@ -371,6 +398,7 @@ var Evented = (function () {
|
|||
})();
|
||||
|
||||
TetherBase.Utils = {
|
||||
getActualBoundingClientRect: getActualBoundingClientRect,
|
||||
getScrollParents: getScrollParents,
|
||||
getBounds: getBounds,
|
||||
getOffsetParent: getOffsetParent,
|
||||
|
@ -429,7 +457,7 @@ var transformKey = (function () {
|
|||
}
|
||||
var el = document.createElement('div');
|
||||
|
||||
var transforms = ['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
|
||||
var transforms = ['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform'];
|
||||
for (var i = 0; i < transforms.length; ++i) {
|
||||
var key = transforms[i];
|
||||
if (el.style[key] !== undefined) {
|
||||
|
@ -828,7 +856,7 @@ var TetherClass = (function (_Evented) {
|
|||
this.enabled = true;
|
||||
|
||||
this.scrollParents.forEach(function (parent) {
|
||||
if (parent !== document) {
|
||||
if (parent !== _this3.target.ownerDocument) {
|
||||
parent.addEventListener('scroll', _this3.position);
|
||||
}
|
||||
});
|
||||
|
@ -1028,21 +1056,24 @@ var TetherClass = (function (_Evented) {
|
|||
}
|
||||
};
|
||||
|
||||
var doc = this.target.ownerDocument;
|
||||
var win = doc.defaultView;
|
||||
|
||||
var scrollbarSize = undefined;
|
||||
if (document.body.scrollWidth > window.innerWidth) {
|
||||
if (win.innerHeight > doc.documentElement.clientHeight) {
|
||||
scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
|
||||
next.viewport.bottom -= scrollbarSize.height;
|
||||
}
|
||||
|
||||
if (document.body.scrollHeight > window.innerHeight) {
|
||||
if (win.innerWidth > doc.documentElement.clientWidth) {
|
||||
scrollbarSize = this.cache('scrollbar-size', getScrollBarSize);
|
||||
next.viewport.right -= scrollbarSize.width;
|
||||
}
|
||||
|
||||
if (['', 'static'].indexOf(document.body.style.position) === -1 || ['', 'static'].indexOf(document.body.parentElement.style.position) === -1) {
|
||||
if (['', 'static'].indexOf(doc.body.style.position) === -1 || ['', 'static'].indexOf(doc.body.parentElement.style.position) === -1) {
|
||||
// Absolute positioning in the body will be relative to the page, not the 'initial containing block'
|
||||
next.page.bottom = document.body.scrollHeight - top - height;
|
||||
next.page.right = document.body.scrollWidth - left - width;
|
||||
next.page.bottom = doc.body.scrollHeight - top - height;
|
||||
next.page.right = doc.body.scrollWidth - left - width;
|
||||
}
|
||||
|
||||
if (typeof this.options.optimizations !== 'undefined' && this.options.optimizations.moveElement !== false && !(typeof this.targetModifier !== 'undefined')) {
|
||||
|
@ -1061,8 +1092,8 @@ var TetherClass = (function (_Evented) {
|
|||
offsetBorder[side.toLowerCase()] = parseFloat(offsetParentStyle['border' + side + 'Width']);
|
||||
});
|
||||
|
||||
offsetPosition.right = document.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
|
||||
offsetPosition.bottom = document.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
|
||||
offsetPosition.right = doc.body.scrollWidth - offsetPosition.left - offsetParentSize.width + offsetBorder.right;
|
||||
offsetPosition.bottom = doc.body.scrollHeight - offsetPosition.top - offsetParentSize.height + offsetBorder.bottom;
|
||||
|
||||
if (next.page.top >= offsetPosition.top + offsetBorder.top && next.page.bottom >= offsetPosition.bottom) {
|
||||
if (next.page.left >= offsetPosition.left + offsetBorder.left && next.page.right >= offsetPosition.right) {
|
||||
|
@ -1155,7 +1186,16 @@ var TetherClass = (function (_Evented) {
|
|||
xPos = -_pos.right;
|
||||
}
|
||||
|
||||
css[transformKey] = 'translateX(' + Math.round(xPos) + 'px) translateY(' + Math.round(yPos) + 'px)';
|
||||
if (window.matchMedia) {
|
||||
// HubSpot/tether#207
|
||||
var retina = window.matchMedia('only screen and (min-resolution: 1.3dppx)').matches || window.matchMedia('only screen and (-webkit-min-device-pixel-ratio: 1.3)').matches;
|
||||
if (!retina) {
|
||||
xPos = Math.round(xPos);
|
||||
yPos = Math.round(yPos);
|
||||
}
|
||||
}
|
||||
|
||||
css[transformKey] = 'translateX(' + xPos + 'px) translateY(' + yPos + 'px)';
|
||||
|
||||
if (transformKey !== 'msTransform') {
|
||||
// The Z transform will keep this in the GPU (faster, and prevents artifacts),
|
||||
|
@ -1207,20 +1247,24 @@ var TetherClass = (function (_Evented) {
|
|||
}
|
||||
|
||||
if (!moved) {
|
||||
var offsetParentIsBody = true;
|
||||
var currentNode = this.element.parentNode;
|
||||
while (currentNode && currentNode.nodeType === 1 && currentNode.tagName !== 'BODY') {
|
||||
if (getComputedStyle(currentNode).position !== 'static') {
|
||||
offsetParentIsBody = false;
|
||||
break;
|
||||
if (this.options.bodyElement) {
|
||||
this.options.bodyElement.appendChild(this.element);
|
||||
} else {
|
||||
var offsetParentIsBody = true;
|
||||
var currentNode = this.element.parentNode;
|
||||
while (currentNode && currentNode.nodeType === 1 && currentNode.tagName !== 'BODY') {
|
||||
if (getComputedStyle(currentNode).position !== 'static') {
|
||||
offsetParentIsBody = false;
|
||||
break;
|
||||
}
|
||||
|
||||
currentNode = currentNode.parentNode;
|
||||
}
|
||||
|
||||
currentNode = currentNode.parentNode;
|
||||
}
|
||||
|
||||
if (!offsetParentIsBody) {
|
||||
this.element.parentNode.removeChild(this.element);
|
||||
document.body.appendChild(this.element);
|
||||
if (!offsetParentIsBody) {
|
||||
this.element.parentNode.removeChild(this.element);
|
||||
this.element.ownerDocument.body.appendChild(this.element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1240,6 +1284,7 @@ var TetherClass = (function (_Evented) {
|
|||
if (write) {
|
||||
defer(function () {
|
||||
extend(_this8.element.style, writeCSS);
|
||||
_this8.trigger('repositioned');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1280,12 +1325,22 @@ function getBoundingRect(tether, to) {
|
|||
|
||||
if (typeof to.nodeType !== 'undefined') {
|
||||
(function () {
|
||||
var node = to;
|
||||
var size = getBounds(to);
|
||||
var pos = size;
|
||||
var style = getComputedStyle(to);
|
||||
|
||||
to = [pos.left, pos.top, size.width + pos.left, size.height + pos.top];
|
||||
|
||||
// Account any parent Frames scroll offset
|
||||
if (node.ownerDocument !== document) {
|
||||
var win = node.ownerDocument.defaultView;
|
||||
to[0] += win.pageXOffset;
|
||||
to[1] += win.pageYOffset;
|
||||
to[2] += win.pageXOffset;
|
||||
to[3] += win.pageYOffset;
|
||||
}
|
||||
|
||||
BOUNDS_FORMAT.forEach(function (side, i) {
|
||||
side = side[0].toUpperCase() + side.substr(1);
|
||||
if (side === 'Top' || side === 'Left') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue