mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
moved backgroundPosition to utils
This commit is contained in:
parent
031f8733ac
commit
aa127655dc
57
src/Core.js
57
src/Core.js
@ -125,6 +125,63 @@ _html2canvas.Util.getCSS = function (el, attribute) {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
_html2canvas.Util.BackgroundPosition = function ( el, bounds, image ) {
|
||||||
|
// TODO add support for multi image backgrounds
|
||||||
|
|
||||||
|
var bgposition = (function( bgp ){
|
||||||
|
|
||||||
|
if (bgp !== undefined) {
|
||||||
|
return (bgp.split(",")[0] || "0 0").split(" ");
|
||||||
|
} else {
|
||||||
|
// Older IE uses -x and -y
|
||||||
|
return [ _html2canvas.Util.getCSS( el, "backgroundPositionX" ), _html2canvas.Util.getCSS( el, "backgroundPositionY" ) ];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})( _html2canvas.Util.getCSS( el, "backgroundPosition" ) ),
|
||||||
|
topPos,
|
||||||
|
left,
|
||||||
|
percentage,
|
||||||
|
val;
|
||||||
|
|
||||||
|
if (bgposition.length === 1){
|
||||||
|
val = bgposition;
|
||||||
|
|
||||||
|
bgposition = [];
|
||||||
|
|
||||||
|
bgposition[0] = val;
|
||||||
|
bgposition[1] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (bgposition[0].toString().indexOf("%") !== -1){
|
||||||
|
percentage = (parseFloat(bgposition[0])/100);
|
||||||
|
left = ((bounds.width * percentage)-(image.width*percentage));
|
||||||
|
|
||||||
|
}else{
|
||||||
|
left = parseInt(bgposition[0],10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bgposition[1].toString().indexOf("%") !== -1){
|
||||||
|
|
||||||
|
percentage = (parseFloat(bgposition[1])/100);
|
||||||
|
topPos = ((bounds.height * percentage)-(image.height*percentage));
|
||||||
|
}else{
|
||||||
|
topPos = parseInt(bgposition[1],10);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
top: topPos,
|
||||||
|
left: left
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
_html2canvas.Util.Extend = function (options, defaults) {
|
_html2canvas.Util.Extend = function (options, defaults) {
|
||||||
var key;
|
var key;
|
||||||
for (key in options) {
|
for (key in options) {
|
||||||
|
56
src/Parse.js
56
src/Parse.js
@ -699,61 +699,7 @@ _html2canvas.Parse = function ( images, options ) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getBackgroundPosition(el, bounds, image){
|
|
||||||
// TODO add support for multi image backgrounds
|
|
||||||
|
|
||||||
var bgposition = (function( bgp ){
|
|
||||||
|
|
||||||
if (bgp !== undefined) {
|
|
||||||
return (bgp.split(",")[0] || "0 0").split(" ");
|
|
||||||
} else {
|
|
||||||
// Older IE uses -x and -y
|
|
||||||
return [ getCSS(el, "backgroundPositionX"), getCSS(el, "backgroundPositionY") ];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
})( getCSS(el, "backgroundPosition") ),
|
|
||||||
topPos,
|
|
||||||
left,
|
|
||||||
percentage,
|
|
||||||
val;
|
|
||||||
|
|
||||||
if (bgposition.length === 1){
|
|
||||||
val = bgposition;
|
|
||||||
|
|
||||||
bgposition = [];
|
|
||||||
|
|
||||||
bgposition[0] = val;
|
|
||||||
bgposition[1] = val;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (bgposition[0].toString().indexOf("%") !== -1){
|
|
||||||
percentage = (parseFloat(bgposition[0])/100);
|
|
||||||
left = ((bounds.width * percentage)-(image.width*percentage));
|
|
||||||
|
|
||||||
}else{
|
|
||||||
left = parseInt(bgposition[0],10);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bgposition[1].toString().indexOf("%") !== -1){
|
|
||||||
|
|
||||||
percentage = (parseFloat(bgposition[1])/100);
|
|
||||||
topPos = ((bounds.height * percentage)-(image.height*percentage));
|
|
||||||
}else{
|
|
||||||
topPos = parseInt(bgposition[1],10);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
top: topPos,
|
|
||||||
left: left
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderImage (ctx, image, sx, sy, sw, sh, dx, dy, dw, dh) {
|
function renderImage (ctx, image, sx, sy, sw, sh, dx, dy, dw, dh) {
|
||||||
ctx.drawImage(
|
ctx.drawImage(
|
||||||
@ -875,7 +821,7 @@ _html2canvas.Parse = function ( images, options ) {
|
|||||||
image = loadImage( background_image );
|
image = loadImage( background_image );
|
||||||
|
|
||||||
|
|
||||||
bgp = getBackgroundPosition(el, bounds, image);
|
bgp = _html2canvas.Util.BackgroundPosition(el, bounds, image);
|
||||||
|
|
||||||
|
|
||||||
if ( image ){
|
if ( image ){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user