mirror of
https://github.com/fastmail/Squire.git
synced 2025-01-03 05:00:13 -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
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -2866,10 +2866,13 @@ proto.hasFormat = function ( tag, attributes, range ) {
|
|||
// holding the cursor. If there's a selection, returns an empty object.
|
||||
proto.getFontInfo = function ( range ) {
|
||||
var fontInfo = {
|
||||
color: undefined,
|
||||
backgroundColor: undefined,
|
||||
family: undefined,
|
||||
size: undefined
|
||||
},
|
||||
element, style;
|
||||
};
|
||||
var seenAttributes = 0;
|
||||
var element, style;
|
||||
|
||||
if ( !range && !( range = this.getSelection() ) ) {
|
||||
return fontInfo;
|
||||
|
@ -2880,13 +2883,22 @@ proto.getFontInfo = function ( range ) {
|
|||
if ( element.nodeType === TEXT_NODE ) {
|
||||
element = element.parentNode;
|
||||
}
|
||||
while ( !( fontInfo.family && fontInfo.size ) &&
|
||||
element && ( style = element.style ) ) {
|
||||
while ( seenAttributes < 4 && 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 ) {
|
||||
fontInfo.family = style.fontFamily;
|
||||
seenAttributes += 1;
|
||||
}
|
||||
if ( !fontInfo.size ) {
|
||||
fontInfo.size = style.fontSize;
|
||||
seenAttributes += 1;
|
||||
}
|
||||
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.
|
||||
proto.getFontInfo = function ( range ) {
|
||||
var fontInfo = {
|
||||
color: undefined,
|
||||
backgroundColor: undefined,
|
||||
family: undefined,
|
||||
size: undefined
|
||||
},
|
||||
element, style;
|
||||
};
|
||||
var seenAttributes = 0;
|
||||
var element, style;
|
||||
|
||||
if ( !range && !( range = this.getSelection() ) ) {
|
||||
return fontInfo;
|
||||
|
@ -748,13 +751,22 @@ proto.getFontInfo = function ( range ) {
|
|||
if ( element.nodeType === TEXT_NODE ) {
|
||||
element = element.parentNode;
|
||||
}
|
||||
while ( !( fontInfo.family && fontInfo.size ) &&
|
||||
element && ( style = element.style ) ) {
|
||||
while ( seenAttributes < 4 && 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 ) {
|
||||
fontInfo.family = style.fontFamily;
|
||||
seenAttributes += 1;
|
||||
}
|
||||
if ( !fontInfo.size ) {
|
||||
fontInfo.size = style.fontSize;
|
||||
seenAttributes += 1;
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue