mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-05-10 14:54:42 +00:00
`backgroundImage` and `overlayImage` are now `fabric.Image` instances New property `overlayColor` (analog to `backgroundColor`) - should be set with `canvas.setOverlayColor` `backgroundImageOpacity` was removed => use `fabric.Image#opacity` `overlayImageLeft ` was removed => use `fabric.Image#left` `overlayImageTop ` was removed => use `fabric.Image#top` `backgroundImageStretch` was removed => use `fabric.Image#width` and `fabric.Image#height`. If you scale your canvas you have to adjust the backgroundImage width/height manually. Update SVG output. Add 2nd parameter `firstLetterOnly` to `fabric.util.string.capitalize` => only first letter is transformed to uppercase (other letters stay untouched) Add `preserveAspectRatio="none"` to `fabric.Image#toSVG` (otherwise streched backgroundImage and overlayImage didn't work as expected) Update examples - TODO: Update jsfiddles for `setBackgroundImage` and `setOverlayImage` Add unit test Closes issue #270
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
(function() {
|
|
|
|
/* _ES5_COMPAT_START_ */
|
|
if (!String.prototype.trim) {
|
|
/**
|
|
* Trims a string (removing whitespace from the beginning and the end)
|
|
* @function external:String#trim
|
|
* @see <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/Trim">String#trim on MDN</a>
|
|
*/
|
|
String.prototype.trim = function () {
|
|
// this trim is not fully ES3 or ES5 compliant, but it should cover most cases for now
|
|
return this.replace(/^[\s\xA0]+/, '').replace(/[\s\xA0]+$/, '');
|
|
};
|
|
}
|
|
/* _ES5_COMPAT_END_ */
|
|
|
|
/**
|
|
* Camelizes a string
|
|
* @memberOf fabric.util.string
|
|
* @param {String} string String to camelize
|
|
* @return {String} Camelized version of a string
|
|
*/
|
|
function camelize(string) {
|
|
return string.replace(/-+(.)?/g, function(match, character) {
|
|
return character ? character.toUpperCase() : '';
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Capitalizes a string
|
|
* @memberOf fabric.util.string
|
|
* @param {String} string String to capitalize
|
|
* @param {Boolean} [firstLetterOnly] If true only first letter is capitalized and other letters stay untouched,
|
|
* if false first letter is capitalized and other letters are converted to lowercase.
|
|
* @return {String} Capitalized version of a string
|
|
*/
|
|
function capitalize(string, firstLetterOnly) {
|
|
return string.charAt(0).toUpperCase() + (firstLetterOnly ? string.slice(1) : string.slice(1).toLowerCase());
|
|
}
|
|
|
|
/**
|
|
* Escapes XML in a string
|
|
* @memberOf fabric.util.string
|
|
* @param {String} string String to escape
|
|
* @return {String} Escaped version of a string
|
|
*/
|
|
function escapeXml(string) {
|
|
return string.replace(/&/g, '&')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>');
|
|
}
|
|
|
|
/**
|
|
* String utilities
|
|
* @namespace fabric.util.string
|
|
*/
|
|
fabric.util.string = {
|
|
camelize: camelize,
|
|
capitalize: capitalize,
|
|
escapeXml: escapeXml
|
|
};
|
|
}());
|