Merge pull request #63 from cobexer/minification-improvements

Minification improvements
This commit is contained in:
Niklas von Hertzen 2012-02-27 11:09:26 -08:00
commit f485028d30
13 changed files with 86 additions and 52 deletions

3
.gitignore vendored
View File

@ -5,8 +5,7 @@
/tests/cache/
/tests/flashcanvas.html
/lib/
/dist/
/build/*.js
/build/
index.html
image.jpg
screenshots.html

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml version="1.0" encoding="utf-8"?>
<project name="html2canvas" basedir="." default="build">
<property name="src.dir" location="src"/>
<property name="lib.dir" location="../lib"/>
@ -11,44 +11,56 @@
<property name="JQUERY_PLUGIN_NAME" value="jquery.plugin.html2canvas.js"/>
<loadfile property="version" srcfile="version.txt" />
<fileset id="sourcefiles" dir="${src.dir}">
<include name="LICENSE"/>
<include name="Core.js"/>
<include name="Generate.js"/>
<include name="Parse.js"/>
<include name="Preload.js"/>
<include name="Queue.js"/>
<include name="Renderer.js"/>
</fileset>
<path id="sourcefiles">
<filelist dir="${src.dir}">
<file name="LICENSE"/>
<file name="html2canvas-pre.txt"/>
<file name="Core.js"/>
<file name="Generate.js"/>
<file name="Parse.js"/>
<file name="Preload.js"/>
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
<file name="html2canvas-post.txt"/>
</filelist>
</path>
<path id="jquery-plugin">
<fileset dir="${src.dir}" includes="LICENSE"/>
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
</path>
<target name="plugins">
<target name="build-dir">
<echo>Creating directory ${build.dir}...</echo>
<mkdir dir="${build.dir}"/>
</target>
<target name="plugins" depends="build-dir">
<echo>Creating ${JQUERY_PLUGIN_NAME}...</echo>
<concat fixlastline="yes" destfile="${build.dir}/${JQUERY_PLUGIN_NAME}">
<path refid="jquery-plugin"/>
</concat>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JQUERY_PLUGIN_NAME}" />
</target>
<pathconvert property="prettty-sourcefiles" pathsep="${line.separator}" refid="sourcefiles"></pathconvert>
<target name="build" depends="plugins">
<target name="build" depends="build-dir,plugins">
<echo>Concatenating files:${line.separator}${prettty-sourcefiles}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
<fileset refid="sourcefiles"/>
<path refid="sourcefiles"/>
</concat>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME}" />
</target>
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
classpath="${lib.dir}/compiler.jar" onerror="report"/>
<target name="release" depends="build">
<target name="syntaxcheck" depends="build-dir,build">
<jscomp compilationLevel="simple" warning="verbose"
debug="false"
output="${build.dir}/${JS_NAME_MIN}">
output="${build.dir}/${JS_NAME_MIN}.tmp">
<externs dir="${lib.dir}">
<file name="${jquery-externs}"/>
</externs>
@ -61,15 +73,28 @@
<file name="Preload.js"/>
<file name="Queue.js"/>
<file name="Renderer.js"/>
<file name="Util.js"/>
</sources>
</jscomp>
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
</target>
<target name="release" depends="build-dir,build,syntaxcheck">
<jscomp compilationLevel="simple" warning="verbose"
debug="false"
output="${build.dir}/${JS_NAME_MIN}">
<externs dir="${lib.dir}">
<file name="${jquery-externs}"/>
</externs>
<sources dir="${build.dir}">
<file name="${JS_NAME}"/>
</sources>
</jscomp>
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
</target>
<target name="clean">
<delete file="${build.dir}/${JS_NAME}"></delete>
<delete file="${build.dir}/${JS_NAME_MIN}"></delete>
<delete file="${build.dir}/${JQUERY_PLUGIN_NAME}"></delete>
<delete dir="${build.dir}"></delete>
</target>
</project>

View File

View File

@ -37,10 +37,15 @@ For more information and examples, please visit the <a href="http://html2canvas.
### Changelog ###
v0.33 -
* Improved minification saved ~1K! (<a href="https://github.com/cobexer/html2canvas/commit/b82be022b2b9240bd503e078ac980bde2b953e43">cobexer</a>)
v0.32 - 20.2.2012
* Added changelog!
* Added bookmarklet (<a href="https://github.com/niklasvh/html2canvas/commit/b320dd306e1a2d32a3bc5a71b6ebf6d8c060cde5">cobexer</a>)
* Option to select single element to render (<a href="https://github.com/niklasvh/html2canvas/commit/0cb252ada91c84ef411288b317c03e97da1f12ad">niklasvh</a>)
* Fixed closure compiler warnings (<a href="https://github.com/niklasvh/html2canvas/commit/36ff1ec7aadcbdf66851a0b77f0b9e87e4a8e4a1">cobexer</a>)
* Enable profiling in FF (<a href="https://github.com/niklasvh/html2canvas/commit/bbd75286a8406cf9e5aea01fdb7950d547edefb9">cobexer</a>)
* Enable profiling in FF (<a href="https://github.com/niklasvh/html2canvas/commit/bbd75286a8406cf9e5aea01fdb7950d547edefb9">cobexer</a>)

View File

@ -10,11 +10,13 @@ var html2canvas = {};
html2canvas.logging = false;
html2canvas.log = function (a) {
function h2clog(a) {
if (html2canvas.logging && window.console && window.console.log) {
window.console.log(a);
}
};
}
html2canvas.log = h2clog; // for compatibility with the jquery plugin
html2canvas.Util = {};
@ -140,8 +142,8 @@ html2canvas.Util.Children = function(el) {
try {
children = $(el).contents();
} catch (ex) {
html2canvas.log("html2canvas.Util.Children failed with exception: " + ex.message);
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
children = [];
}
return children;
}
};

View File

@ -108,7 +108,7 @@ html2canvas.Generate.Gradient = function(src, bounds) {
lingrad.addColorStop(increment * i, steps[i]);
}
catch(e) {
html2canvas.log(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
h2clog(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
}
}

View File

@ -1002,7 +1002,7 @@ html2canvas.Parse = function (element, images, opts) {
}
}else{
html2canvas.log("html2canvas: Error loading background:" + background_image);
h2clog("html2canvas: Error loading background:" + background_image);
//console.log(images);
}
@ -1051,7 +1051,7 @@ html2canvas.Parse = function (element, images, opts) {
stack = {
ctx: html2canvas.canvasContext( docDim.width || w , docDim.height || h ),
ctx: h2cRenderContext( docDim.width || w , docDim.height || h ),
zIndex: zindex,
opacity: opacity * parentStack.opacity,
cssPosition: cssPosition
@ -1162,7 +1162,7 @@ html2canvas.Parse = function (element, images, opts) {
);
}else{
html2canvas.log("html2canvas: Error loading <img>:" + imgSrc);
h2clog("html2canvas: Error loading <img>:" + imgSrc);
}
break;
case "INPUT":

View File

@ -45,7 +45,7 @@ html2canvas.Preload = function(element, opts){
}
function start(){
html2canvas.log("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
if (!images.firstRun && images.numLoaded >= images.numTotal){
/*
@ -57,7 +57,7 @@ html2canvas.Preload = function(element, opts){
options.complete(images);
}
html2canvas.log("Finished loading images: # " + images.numTotal + " (failed: " + images.numFailed + ")");
h2clog("Finished loading images: # " + images.numTotal + " (failed: " + images.numFailed + ")");
}
}
@ -169,7 +169,7 @@ html2canvas.Preload = function(element, opts){
elNodeType = el.nodeType;
} catch (ex) {
elNodeType = false;
html2canvas.log("html2canvas: failed to access some element's nodeType - Exception: " + ex.message);
h2clog("html2canvas: failed to access some element's nodeType - Exception: " + ex.message);
}
if (elNodeType === 1 || elNodeType === undefined){
@ -256,9 +256,9 @@ html2canvas.Preload = function(element, opts){
var img, src;
if (!images.cleanupDone) {
if (cause && typeof cause === "string") {
html2canvas.log("html2canvas: Cleanup because: " + cause);
h2clog("html2canvas: Cleanup because: " + cause);
} else {
html2canvas.log("html2canvas: Cleanup after timeout: " + options.timeout + " ms.");
h2clog("html2canvas: Cleanup after timeout: " + options.timeout + " ms.");
}
for (src in images) {
@ -276,7 +276,7 @@ html2canvas.Preload = function(element, opts){
}
images.numLoaded++;
images.numFailed++;
html2canvas.log("html2canvas: Cleaned up failed img: '" + src + "' Steps: " + images.numLoaded + " / " + images.numTotal);
h2clog("html2canvas: Cleaned up failed img: '" + src + "' Steps: " + images.numLoaded + " / " + images.numTotal);
}
}
}
@ -307,19 +307,19 @@ html2canvas.Preload = function(element, opts){
if (options.timeout > 0) {
timeoutTimer = window.setTimeout(methods.cleanupDOM, options.timeout);
}
html2canvas.log('html2canvas: Preload starts: finding background-images');
h2clog('html2canvas: Preload starts: finding background-images');
images.firstRun = true;
getImages( element );
html2canvas.log('html2canvas: Preload: Finding images');
h2clog('html2canvas: Preload: Finding images');
// load <img> images
for (i = 0; i < imgLen; i+=1){
methods.loadImage( domImages[i].getAttribute( "src" ) );
}
images.firstRun = false;
html2canvas.log('html2canvas: Preload: Done.');
h2clog('html2canvas: Preload: Done.');
if ( images.numTotal === images.numLoaded ) {
start();
}

View File

@ -5,7 +5,7 @@
Released under MIT License
*/
html2canvas.canvasContext = function (width, height) {
function h2cRenderContext(width, height) {
var storage = [];
return {
storage: storage,
@ -40,4 +40,4 @@ html2canvas.canvasContext = function (width, height) {
});
}
};
};
}

View File

@ -176,7 +176,7 @@ html2canvas.Renderer = function(parseQueue, opts){
}
html2canvas.log("html2canvas: Renderer: Canvas renderer done - returning canvas obj");
h2clog("html2canvas: Renderer: Canvas renderer done - returning canvas obj");
// this.canvasRenderStorage(queue,this.ctx);
queueLen = options.elements.length;
@ -390,7 +390,7 @@ html2canvas.Renderer = function(parseQueue, opts){
html2canvas.log("html2canvas: Renderer: SVG Renderer done - returning SVG DOM obj");
h2clog("html2canvas: Renderer: SVG Renderer done - returning SVG DOM obj");
return svg;
@ -405,11 +405,11 @@ html2canvas.Renderer = function(parseQueue, opts){
case "canvas":
canvas = doc.createElement('canvas');
if (canvas.getContext){
html2canvas.log("html2canvas: Renderer: using canvas renderer");
h2clog("html2canvas: Renderer: using canvas renderer");
return canvasRenderer(parseQueue);
} else {
usingFlashcanvas = true;
html2canvas.log("html2canvas: Renderer: canvas not available, using flashcanvas");
h2clog("html2canvas: Renderer: canvas not available, using flashcanvas");
var script = doc.createElement("script");
script.src = options.flashcanvas;
@ -436,7 +436,7 @@ html2canvas.Renderer = function(parseQueue, opts){
window.setTimeout( intervalFunc, 250 );
} else {
html2canvas.log("html2canvas: Renderer: Can't track when flashcanvas is loaded");
h2clog("html2canvas: Renderer: Can't track when flashcanvas is loaded");
}
@ -446,9 +446,9 @@ html2canvas.Renderer = function(parseQueue, opts){
})(script, function(){
if (typeof FlashCanvas !== "undefined") {
html2canvas.log("html2canvas: Renderer: Flashcanvas initialized");
FlashCanvas.initElement( canvas );
if (typeof window.FlashCanvas !== "undefined") {
h2clog("html2canvas: Renderer: Flashcanvas initialized");
window.FlashCanvas.initElement( canvas );
canvasRenderer(parseQueue);
}
});
@ -460,7 +460,7 @@ html2canvas.Renderer = function(parseQueue, opts){
break;
case "svg":
if (doc.createElementNS){
html2canvas.log("html2canvas: Renderer: using SVG renderer");
h2clog("html2canvas: Renderer: using SVG renderer");
return svgRenderer(parseQueue);
}
break;

2
src/html2canvas-post.txt Normal file
View File

@ -0,0 +1,2 @@
window.html2canvas = html2canvas;
}(window, document));

1
src/html2canvas-pre.txt Normal file
View File

@ -0,0 +1 @@
(function(window, document, undefined){

View File

@ -8,7 +8,7 @@
(function(document, window) {
var scrStart = '<script type="text/javascript" src="', scrEnd = '"></script>';
document.write(scrStart + '../external/jquery-1.6.2.js' + scrEnd);
var html2canvas = ['Core', 'Generate', 'Parse', 'Preload', 'Queue', 'Renderer', 'plugins/jquery.plugin.html2canvas'], i;
var html2canvas = ['Core', 'Generate', 'Parse', 'Preload', 'Queue', 'Renderer', 'Util', 'plugins/jquery.plugin.html2canvas'], i;
for (i = 0; i < html2canvas.length; ++i) {
document.write(scrStart + '../src/' + html2canvas[i] + '.js' + scrEnd);
}