From 67850f2cee1183c91ad2e5917d1a2b56ed912598 Mon Sep 17 00:00:00 2001 From: Niklas von Hertzen Date: Fri, 11 Jan 2013 22:50:46 +0200 Subject: [PATCH] Refactoring --- src/Core.js | 13 ++----------- src/Preload.js | 39 ++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/Core.js b/src/Core.js index ee79671..1dc22c9 100644 --- a/src/Core.js +++ b/src/Core.js @@ -5,7 +5,6 @@ previousElement, computedCSS, html2canvas; - function h2clog(a) { if (_html2canvas.logging && window.console && window.console.log) { window.console.log(a); @@ -14,17 +13,9 @@ function h2clog(a) { _html2canvas.Util = {}; -_html2canvas.Util.isElementVisible = function (element) { - return ( - _html2canvas.Util.getCSS( element, 'display' ) !== "none" && - _html2canvas.Util.getCSS( element, 'visibility' ) !== "hidden" && - !element.hasAttribute( "data-html2canvas-ignore" ) - ); -}; - -_html2canvas.Util.trimText = (function(native){ +_html2canvas.Util.trimText = (function(isNative){ return function(input){ - if(native) { return native.apply( input ); } + if(isNative) { return isNative.apply( input ); } else { return ((input || '') + '').replace( /^\s+|\s+$/g , '' ); } }; })( String.prototype.trim ); diff --git a/src/Preload.js b/src/Preload.js index 609e5f1..80d4c06 100644 --- a/src/Preload.js +++ b/src/Preload.js @@ -103,12 +103,22 @@ _html2canvas.Preload = function( options ) { loadPseudoElement(element, ":after"); } + function loadGradientImage(backgroundImage, bounds) { + var img = _html2canvas.Generate.Gradient(backgroundImage, bounds); + + if (img !== undefined){ + images[backgroundImage] = { + img: img, + succeeded: true + }; + images.numTotal++; + images.numLoaded++; + start(); + } + } + function loadBackgroundImages(background_image, el) { - var background_images, - src, - img, - bounds; - // opera throws exception on external-content.html + var background_images, bounds; background_images = _html2canvas.Util.parseBackgroundImage(background_image); for(var imageIndex = background_images.length; imageIndex-- > 0;) { @@ -121,25 +131,12 @@ _html2canvas.Preload = function( options ) { continue; } if (background_image.method === 'url') { - src = background_image.args[0]; - methods.loadImage(src); - - } else if( background_image.method.match( /\-?gradient$/ ) ) { + methods.loadImage(background_image.args[0]); + } else if(background_image.method.match(/\-?gradient$/)) { if(bounds === undefined) { bounds = _html2canvas.Util.Bounds(el); } - - img = _html2canvas.Generate.Gradient( background_image.value, bounds); - - if ( img !== undefined ){ - images[background_image.value] = { - img: img, - succeeded: true - }; - images.numTotal++; - images.numLoaded++; - start(); - } + loadGradientImage(background_image.value, bounds); } } }