-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change style parset to more futureproof quirk
- Loading branch information
Oliver Pulges
committed
Nov 11, 2013
1 parent
a3b8cb3
commit 98427ba
Showing
7 changed files
with
105 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
(function(wysihtml5) { | ||
var RGBA_REGEX = /^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d\.]+)\s*\)/i, | ||
RGB_REGEX = /^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/i, | ||
HEX6_REGEX = /^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])/i, | ||
HEX3_REGEX = /^#([0-9a-f])([0-9a-f])([0-9a-f])/i; | ||
|
||
wysihtml5.quirks.styleParser = { | ||
|
||
parseColor: function(stylesStr, paramName) { | ||
var paramRegex = new RegExp("(^|\\s|;)" + paramName + "\\s*:\\s*[^;$]+" , "gi"), | ||
params = stylesStr.match(paramRegex), | ||
radix = 10, | ||
str, colorMatch; | ||
|
||
if (params) { | ||
for (var i = params.length; i--;) { | ||
params[i] = wysihtml5.lang.string(params[i].split(':')[1]).trim(); | ||
} | ||
str = params[params.length-1]; | ||
|
||
if (RGBA_REGEX.test(str)) { | ||
colorMatch = str.match(RGBA_REGEX); | ||
} else if (RGB_REGEX.test(str)) { | ||
colorMatch = str.match(RGB_REGEX); | ||
} else if (HEX6_REGEX.test(str)) { | ||
colorMatch = str.match(HEX6_REGEX); | ||
radix = 16; | ||
} else if (HEX3_REGEX.test(str)) { | ||
colorMatch = str.match(HEX3_REGEX); | ||
colorMatch.shift(); | ||
colorMatch.push(1); | ||
return wysihtml5.lang.array(colorMatch).map(function(d, idx) { | ||
return (idx < 3) ? (parseInt(d, 16) * 16) + parseInt(d, 16): parseFloat(d); | ||
}); | ||
} | ||
|
||
if (colorMatch) { | ||
colorMatch.shift(); | ||
if (!colorMatch[3]) { | ||
colorMatch.push(1); | ||
} | ||
return wysihtml5.lang.array(colorMatch).map(function(d, idx) { | ||
return (idx < 3) ? parseInt(d, radix): parseFloat(d); | ||
}); | ||
} | ||
} | ||
return false; | ||
}, | ||
|
||
unparseColor: function(val, props) { | ||
if (props) { | ||
if (props == "hex") { | ||
return (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase()); | ||
} else if (props == "hash") { | ||
return "#" + (val[0].toString(16).toUpperCase()) + (val[1].toString(16).toUpperCase()) + (val[2].toString(16).toUpperCase()); | ||
} else if (props == "rgb") { | ||
return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")"; | ||
} else if (props == "rgba") { | ||
return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")"; | ||
} else if (props == "csv") { | ||
return val[0] + "," + val[1] + "," + val[2] + "," + val[3]; | ||
} | ||
} | ||
|
||
if (val[3] && val[3] !== 1) { | ||
return "rgba(" + val[0] + "," + val[1] + "," + val[2] + "," + val[3] + ")"; | ||
} else { | ||
return "rgb(" + val[0] + "," + val[1] + "," + val[2] + ")"; | ||
} | ||
} | ||
}; | ||
|
||
})(wysihtml5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters