mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-04 22:00:09 -05:00
parent
0d1f1cf44b
commit
df25d6d596
4 changed files with 39 additions and 15 deletions
|
@ -181,7 +181,7 @@ Returns the path through the DOM tree from the `<body>` element to the current c
|
||||||
|
|
||||||
### getFontInfo
|
### getFontInfo
|
||||||
|
|
||||||
Returns an object containing the font-family and font-size information for the element the cursor is in, if any was set. It uses style declarations to detect this, and so will not detect FONT tags. If a selection across multiple elements has been made, it will return an empty object.
|
Returns an object containing the active font family, size, colour and background colour for the the current cursor position, if any are set. The property names are respectively `family`, `size`, `color` and `backgroundColor`. It looks at style attributes to detect this, so will not detect `<FONT>` tags or non-inline styles. If a selection across multiple elements has been made, it will return an empty object.
|
||||||
|
|
||||||
### getSelection
|
### getSelection
|
||||||
|
|
||||||
|
|
|
@ -2866,10 +2866,13 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
||||||
// holding the cursor. If there's a selection, returns an empty object.
|
// holding the cursor. If there's a selection, returns an empty object.
|
||||||
proto.getFontInfo = function ( range ) {
|
proto.getFontInfo = function ( range ) {
|
||||||
var fontInfo = {
|
var fontInfo = {
|
||||||
family: undefined,
|
color: undefined,
|
||||||
size: undefined
|
backgroundColor: undefined,
|
||||||
},
|
family: undefined,
|
||||||
element, style;
|
size: undefined
|
||||||
|
};
|
||||||
|
var seenAttributes = 0;
|
||||||
|
var element, style;
|
||||||
|
|
||||||
if ( !range && !( range = this.getSelection() ) ) {
|
if ( !range && !( range = this.getSelection() ) ) {
|
||||||
return fontInfo;
|
return fontInfo;
|
||||||
|
@ -2880,13 +2883,22 @@ proto.getFontInfo = function ( range ) {
|
||||||
if ( element.nodeType === TEXT_NODE ) {
|
if ( element.nodeType === TEXT_NODE ) {
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
while ( !( fontInfo.family && fontInfo.size ) &&
|
while ( seenAttributes < 4 && element && ( style = element.style ) ) {
|
||||||
element && ( style = element.style ) ) {
|
if ( !fontInfo.color ) {
|
||||||
|
fontInfo.color = style.color;
|
||||||
|
seenAttributes += 1;
|
||||||
|
}
|
||||||
|
if ( !fontInfo.backgroundColor ) {
|
||||||
|
fontInfo.backgroundColor = style.backgroundColor;
|
||||||
|
seenAttributes += 1;
|
||||||
|
}
|
||||||
if ( !fontInfo.family ) {
|
if ( !fontInfo.family ) {
|
||||||
fontInfo.family = style.fontFamily;
|
fontInfo.family = style.fontFamily;
|
||||||
|
seenAttributes += 1;
|
||||||
}
|
}
|
||||||
if ( !fontInfo.size ) {
|
if ( !fontInfo.size ) {
|
||||||
fontInfo.size = style.fontSize;
|
fontInfo.size = style.fontSize;
|
||||||
|
seenAttributes += 1;
|
||||||
}
|
}
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -734,10 +734,13 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
||||||
// holding the cursor. If there's a selection, returns an empty object.
|
// holding the cursor. If there's a selection, returns an empty object.
|
||||||
proto.getFontInfo = function ( range ) {
|
proto.getFontInfo = function ( range ) {
|
||||||
var fontInfo = {
|
var fontInfo = {
|
||||||
family: undefined,
|
color: undefined,
|
||||||
size: undefined
|
backgroundColor: undefined,
|
||||||
},
|
family: undefined,
|
||||||
element, style;
|
size: undefined
|
||||||
|
};
|
||||||
|
var seenAttributes = 0;
|
||||||
|
var element, style;
|
||||||
|
|
||||||
if ( !range && !( range = this.getSelection() ) ) {
|
if ( !range && !( range = this.getSelection() ) ) {
|
||||||
return fontInfo;
|
return fontInfo;
|
||||||
|
@ -748,13 +751,22 @@ proto.getFontInfo = function ( range ) {
|
||||||
if ( element.nodeType === TEXT_NODE ) {
|
if ( element.nodeType === TEXT_NODE ) {
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
while ( !( fontInfo.family && fontInfo.size ) &&
|
while ( seenAttributes < 4 && element && ( style = element.style ) ) {
|
||||||
element && ( style = element.style ) ) {
|
if ( !fontInfo.color ) {
|
||||||
|
fontInfo.color = style.color;
|
||||||
|
seenAttributes += 1;
|
||||||
|
}
|
||||||
|
if ( !fontInfo.backgroundColor ) {
|
||||||
|
fontInfo.backgroundColor = style.backgroundColor;
|
||||||
|
seenAttributes += 1;
|
||||||
|
}
|
||||||
if ( !fontInfo.family ) {
|
if ( !fontInfo.family ) {
|
||||||
fontInfo.family = style.fontFamily;
|
fontInfo.family = style.fontFamily;
|
||||||
|
seenAttributes += 1;
|
||||||
}
|
}
|
||||||
if ( !fontInfo.size ) {
|
if ( !fontInfo.size ) {
|
||||||
fontInfo.size = style.fontSize;
|
fontInfo.size = style.fontSize;
|
||||||
|
seenAttributes += 1;
|
||||||
}
|
}
|
||||||
element = element.parentNode;
|
element = element.parentNode;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue