0
Fork 0
mirror of https://github.com/fastmail/Squire.git synced 2024-12-22 07:13:08 -05:00

Path contains format values

Add values of font size, font face, and color to the path. This allows
us to distinguish path changes to different formats.
This commit is contained in:
Andy Kauffman 2016-07-06 13:27:22 -04:00 committed by Neil Jenkins
parent 3428d61331
commit 964070ee46
5 changed files with 49 additions and 10 deletions

View file

@ -17,6 +17,11 @@ var START_TO_END = 1; // Range.START_TO_END
var END_TO_END = 2; // Range.END_TO_END
var END_TO_START = 3; // Range.END_TO_START
var HIGHLIGHT_CLASS = 'highlight';
var COLOUR_CLASS = 'colour';
var FONT_FAMILY_CLASS = 'font';
var FONT_SIZE_CLASS = 'size';
var ZWS = '\u200B';
var win = doc.defaultView;
@ -284,6 +289,20 @@ function getPath ( node, root ) {
if ( dir = node.dir ) {
path += '[dir=' + dir + ']';
}
if( classNames ) {
if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) {
path += '[backgroundColor=' + node.style.backgroundColor.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) {
path += '[color=' + node.style.color.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) {
path += '[fontFamily=' + node.style.fontFamily.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) {
path += '[fontSize=' + node.style.fontSize + ']';
}
}
}
}
return path;
@ -1695,7 +1714,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
'class': 'highlight',
'class': HIGHLIGHT_CLASS,
style: 'background-color:' + colour
});
}
@ -1704,7 +1723,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
'class': 'colour',
'class': COLOUR_CLASS,
style: 'color:' + colour
});
}
@ -1725,7 +1744,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, family ) {
return createElement( doc, 'SPAN', {
'class': 'font',
'class': FONT_FAMILY_CLASS,
style: 'font-family:' + family
});
}
@ -1734,7 +1753,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, size ) {
return createElement( doc, 'SPAN', {
'class': 'size',
'class': FONT_SIZE_CLASS,
style: 'font-size:' + size
});
}

File diff suppressed because one or more lines are too long

View file

@ -15,7 +15,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
'class': 'highlight',
'class': HIGHLIGHT_CLASS,
style: 'background-color:' + colour
});
}
@ -24,7 +24,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, colour ) {
return createElement( doc, 'SPAN', {
'class': 'colour',
'class': COLOUR_CLASS,
style: 'color:' + colour
});
}
@ -45,7 +45,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, family ) {
return createElement( doc, 'SPAN', {
'class': 'font',
'class': FONT_FAMILY_CLASS,
style: 'font-family:' + family
});
}
@ -54,7 +54,7 @@ var styleToSemantic = {
regexp: notWS,
replace: function ( doc, size ) {
return createElement( doc, 'SPAN', {
'class': 'size',
'class': FONT_SIZE_CLASS,
style: 'font-size:' + size
});
}

View file

@ -13,6 +13,11 @@ var START_TO_END = 1; // Range.START_TO_END
var END_TO_END = 2; // Range.END_TO_END
var END_TO_START = 3; // Range.END_TO_START
var HIGHLIGHT_CLASS = 'highlight';
var COLOUR_CLASS = 'colour';
var FONT_FAMILY_CLASS = 'font';
var FONT_SIZE_CLASS = 'size';
var ZWS = '\u200B';
var win = doc.defaultView;

View file

@ -113,6 +113,20 @@ function getPath ( node, root ) {
if ( dir = node.dir ) {
path += '[dir=' + dir + ']';
}
if( classNames ) {
if ( indexOf.call( classNames, HIGHLIGHT_CLASS ) > -1 ) {
path += '[backgroundColor=' + node.style.backgroundColor.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, COLOUR_CLASS ) > -1 ) {
path += '[color=' + node.style.color.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, FONT_FAMILY_CLASS ) > -1 ) {
path += '[fontFamily=' + node.style.fontFamily.replace(/ /g,'') + ']';
}
if ( indexOf.call( classNames, FONT_SIZE_CLASS ) > -1 ) {
path += '[fontSize=' + node.style.fontSize + ']';
}
}
}
}
return path;