mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Refactoring
This commit is contained in:
parent
25abef772e
commit
55641a0fd8
37
src/Core.js
37
src/Core.js
@ -18,7 +18,11 @@ _html2canvas.Util.trimText = (function(isNative){
|
|||||||
if(isNative) { return isNative.apply( input ); }
|
if(isNative) { return isNative.apply( input ); }
|
||||||
else { return ((input || '') + '').replace( /^\s+|\s+$/g , '' ); }
|
else { return ((input || '') + '').replace( /^\s+|\s+$/g , '' ); }
|
||||||
};
|
};
|
||||||
})( String.prototype.trim );
|
})(String.prototype.trim);
|
||||||
|
|
||||||
|
_html2canvas.Util.asFloat = function(v) {
|
||||||
|
return parseFloat(v);
|
||||||
|
};
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// TODO: support all possible length values
|
// TODO: support all possible length values
|
||||||
@ -256,18 +260,18 @@ _html2canvas.Util.resizeBounds = function( current_width, current_height, target
|
|||||||
if(!stretch_mode || stretch_mode === 'auto') {
|
if(!stretch_mode || stretch_mode === 'auto') {
|
||||||
output_width = target_width;
|
output_width = target_width;
|
||||||
output_height = target_height;
|
output_height = target_height;
|
||||||
|
} else if(target_ratio < current_ratio ^ stretch_mode === 'contain') {
|
||||||
} else {
|
|
||||||
if(target_ratio < current_ratio ^ stretch_mode === 'contain') {
|
|
||||||
output_height = target_height;
|
output_height = target_height;
|
||||||
output_width = target_height * current_ratio;
|
output_width = target_height * current_ratio;
|
||||||
} else {
|
} else {
|
||||||
output_width = target_width;
|
output_width = target_width;
|
||||||
output_height = target_width / current_ratio;
|
output_height = target_width / current_ratio;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return { width: output_width, height: output_height };
|
return {
|
||||||
|
width: output_width,
|
||||||
|
height: output_height
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function backgroundBoundsFactory( prop, el, bounds, image, imageIndex, backgroundSize ) {
|
function backgroundBoundsFactory( prop, el, bounds, image, imageIndex, backgroundSize ) {
|
||||||
@ -356,22 +360,17 @@ _html2canvas.Util.Extend = function (options, defaults) {
|
|||||||
_html2canvas.Util.Children = function( elem ) {
|
_html2canvas.Util.Children = function( elem ) {
|
||||||
var children;
|
var children;
|
||||||
try {
|
try {
|
||||||
|
children = (elem.nodeName && elem.nodeName.toUpperCase() === "IFRAME") ? elem.contentDocument || elem.contentWindow.document : (function(array) {
|
||||||
children = (elem.nodeName && elem.nodeName.toUpperCase() === "IFRAME") ?
|
|
||||||
elem.contentDocument || elem.contentWindow.document : (function( array ){
|
|
||||||
var ret = [];
|
var ret = [];
|
||||||
|
if (array !== null) {
|
||||||
if ( array !== null ) {
|
(function(first, second ) {
|
||||||
|
|
||||||
(function( first, second ) {
|
|
||||||
var i = first.length,
|
var i = first.length,
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
if (typeof second.length === "number") {
|
if (typeof second.length === "number") {
|
||||||
for ( var l = second.length; j < l; j++ ) {
|
for (var l = second.length; j < l; j++) {
|
||||||
first[ i++ ] = second[ j ];
|
first[i++] = second[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
while (second[j] !== undefined) {
|
while (second[j] !== undefined) {
|
||||||
first[i++] = second[j++];
|
first[i++] = second[j++];
|
||||||
@ -381,12 +380,10 @@ _html2canvas.Util.Children = function( elem ) {
|
|||||||
first.length = i;
|
first.length = i;
|
||||||
|
|
||||||
return first;
|
return first;
|
||||||
})( ret, array );
|
})(ret, array);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
})( elem.childNodes );
|
})(elem.childNodes);
|
||||||
|
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
|
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user