Skip to content

Commit f485028

Browse files
committed
Merge pull request niklasvh#63 from cobexer/minification-improvements
Minification improvements
2 parents 84a6764 + 5878c20 commit f485028

13 files changed

Lines changed: 86 additions & 52 deletions

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
/tests/cache/
66
/tests/flashcanvas.html
77
/lib/
8-
/dist/
9-
/build/*.js
8+
/build/
109
index.html
1110
image.jpg
1211
screenshots.html

build.xml

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="ISO-8859-1"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<project name="html2canvas" basedir="." default="build">
33
<property name="src.dir" location="src"/>
44
<property name="lib.dir" location="../lib"/>
@@ -11,44 +11,56 @@
1111
<property name="JQUERY_PLUGIN_NAME" value="jquery.plugin.html2canvas.js"/>
1212
<loadfile property="version" srcfile="version.txt" />
1313

14-
<fileset id="sourcefiles" dir="${src.dir}">
15-
<include name="LICENSE"/>
16-
<include name="Core.js"/>
17-
<include name="Generate.js"/>
18-
<include name="Parse.js"/>
19-
<include name="Preload.js"/>
20-
<include name="Queue.js"/>
21-
<include name="Renderer.js"/>
22-
</fileset>
14+
<path id="sourcefiles">
15+
<filelist dir="${src.dir}">
16+
<file name="LICENSE"/>
17+
<file name="html2canvas-pre.txt"/>
18+
<file name="Core.js"/>
19+
<file name="Generate.js"/>
20+
<file name="Parse.js"/>
21+
<file name="Preload.js"/>
22+
<file name="Queue.js"/>
23+
<file name="Renderer.js"/>
24+
<file name="Util.js"/>
25+
<file name="html2canvas-post.txt"/>
26+
</filelist>
27+
</path>
2328

2429
<path id="jquery-plugin">
2530
<fileset dir="${src.dir}" includes="LICENSE"/>
26-
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
31+
<fileset dir="${src.dir}/plugins" includes="${JQUERY_PLUGIN_NAME}"/>
2732
</path>
2833

29-
<target name="plugins">
34+
<target name="build-dir">
35+
<echo>Creating directory ${build.dir}...</echo>
36+
<mkdir dir="${build.dir}"/>
37+
</target>
38+
39+
<target name="plugins" depends="build-dir">
40+
<echo>Creating ${JQUERY_PLUGIN_NAME}...</echo>
3041
<concat fixlastline="yes" destfile="${build.dir}/${JQUERY_PLUGIN_NAME}">
3142
<path refid="jquery-plugin"/>
3243
</concat>
3344
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JQUERY_PLUGIN_NAME}" />
3445
</target>
3546

47+
<pathconvert property="prettty-sourcefiles" pathsep="${line.separator}" refid="sourcefiles"></pathconvert>
3648

37-
<target name="build" depends="plugins">
49+
<target name="build" depends="build-dir,plugins">
50+
<echo>Concatenating files:${line.separator}${prettty-sourcefiles}${line.separator}into ${build.dir}/${JS_NAME}...</echo>
3851
<concat fixlastline="yes" destfile="${build.dir}/${JS_NAME}">
39-
<fileset refid="sourcefiles"/>
52+
<path refid="sourcefiles"/>
4053
</concat>
4154
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME}" />
4255
</target>
4356

44-
4557
<taskdef name="jscomp" classname="com.google.javascript.jscomp.ant.CompileTask"
4658
classpath="${lib.dir}/compiler.jar" onerror="report"/>
4759

48-
<target name="release" depends="build">
60+
<target name="syntaxcheck" depends="build-dir,build">
4961
<jscomp compilationLevel="simple" warning="verbose"
5062
debug="false"
51-
output="${build.dir}/${JS_NAME_MIN}">
63+
output="${build.dir}/${JS_NAME_MIN}.tmp">
5264
<externs dir="${lib.dir}">
5365
<file name="${jquery-externs}"/>
5466
</externs>
@@ -61,15 +73,28 @@
6173
<file name="Preload.js"/>
6274
<file name="Queue.js"/>
6375
<file name="Renderer.js"/>
76+
<file name="Util.js"/>
77+
</sources>
78+
</jscomp>
79+
<delete file="${build.dir}/${JS_NAME_MIN}.tmp"></delete>
80+
</target>
81+
82+
<target name="release" depends="build-dir,build,syntaxcheck">
83+
<jscomp compilationLevel="simple" warning="verbose"
84+
debug="false"
85+
output="${build.dir}/${JS_NAME_MIN}">
86+
<externs dir="${lib.dir}">
87+
<file name="${jquery-externs}"/>
88+
</externs>
89+
<sources dir="${build.dir}">
90+
<file name="${JS_NAME}"/>
6491
</sources>
6592
</jscomp>
6693
<replaceregexp match="@VERSION@" replace="${version}" flags="g" byline="true" file="${build.dir}/${JS_NAME_MIN}" />
6794
</target>
6895

6996
<target name="clean">
70-
<delete file="${build.dir}/${JS_NAME}"></delete>
71-
<delete file="${build.dir}/${JS_NAME_MIN}"></delete>
72-
<delete file="${build.dir}/${JQUERY_PLUGIN_NAME}"></delete>
97+
<delete dir="${build.dir}"></delete>
7398
</target>
7499
</project>
75100

build/.gitkeepdir

Whitespace-only changes.

readme.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ For more information and examples, please visit the <a href="http://html2canvas.
3737

3838
### Changelog ###
3939

40+
v0.33 -
41+
42+
* Improved minification saved ~1K! (<a href="https://github.com/cobexer/html2canvas/commit/b82be022b2b9240bd503e078ac980bde2b953e43">cobexer</a>)
43+
44+
4045
v0.32 - 20.2.2012
4146

4247
* Added changelog!
4348
* Added bookmarklet (<a href="https://github.com/niklasvh/html2canvas/commit/b320dd306e1a2d32a3bc5a71b6ebf6d8c060cde5">cobexer</a>)
4449
* Option to select single element to render (<a href="https://github.com/niklasvh/html2canvas/commit/0cb252ada91c84ef411288b317c03e97da1f12ad">niklasvh</a>)
4550
* Fixed closure compiler warnings (<a href="https://github.com/niklasvh/html2canvas/commit/36ff1ec7aadcbdf66851a0b77f0b9e87e4a8e4a1">cobexer</a>)
46-
* Enable profiling in FF (<a href="https://github.com/niklasvh/html2canvas/commit/bbd75286a8406cf9e5aea01fdb7950d547edefb9">cobexer</a>)
51+
* Enable profiling in FF (<a href="https://github.com/niklasvh/html2canvas/commit/bbd75286a8406cf9e5aea01fdb7950d547edefb9">cobexer</a>)

src/Core.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ var html2canvas = {};
1010

1111
html2canvas.logging = false;
1212

13-
html2canvas.log = function (a) {
13+
function h2clog(a) {
1414
if (html2canvas.logging && window.console && window.console.log) {
1515
window.console.log(a);
1616
}
17-
};
17+
}
18+
19+
html2canvas.log = h2clog; // for compatibility with the jquery plugin
1820

1921
html2canvas.Util = {};
2022

@@ -140,8 +142,8 @@ html2canvas.Util.Children = function(el) {
140142
try {
141143
children = $(el).contents();
142144
} catch (ex) {
143-
html2canvas.log("html2canvas.Util.Children failed with exception: " + ex.message);
145+
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
144146
children = [];
145147
}
146148
return children;
147-
}
149+
};

src/Generate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ html2canvas.Generate.Gradient = function(src, bounds) {
108108
lingrad.addColorStop(increment * i, steps[i]);
109109
}
110110
catch(e) {
111-
html2canvas.log(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
111+
h2clog(['failed to add color stop: ', e, '; tried to add: ', steps[i], '; stop: ', i, '; in: ', src]);
112112
}
113113
}
114114

src/Parse.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ html2canvas.Parse = function (element, images, opts) {
10021002

10031003
}
10041004
}else{
1005-
html2canvas.log("html2canvas: Error loading background:" + background_image);
1005+
h2clog("html2canvas: Error loading background:" + background_image);
10061006
//console.log(images);
10071007
}
10081008

@@ -1051,7 +1051,7 @@ html2canvas.Parse = function (element, images, opts) {
10511051

10521052

10531053
stack = {
1054-
ctx: html2canvas.canvasContext( docDim.width || w , docDim.height || h ),
1054+
ctx: h2cRenderContext( docDim.width || w , docDim.height || h ),
10551055
zIndex: zindex,
10561056
opacity: opacity * parentStack.opacity,
10571057
cssPosition: cssPosition
@@ -1162,7 +1162,7 @@ html2canvas.Parse = function (element, images, opts) {
11621162
);
11631163

11641164
}else{
1165-
html2canvas.log("html2canvas: Error loading <img>:" + imgSrc);
1165+
h2clog("html2canvas: Error loading <img>:" + imgSrc);
11661166
}
11671167
break;
11681168
case "INPUT":

src/Preload.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ html2canvas.Preload = function(element, opts){
4545
}
4646

4747
function start(){
48-
html2canvas.log("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
48+
h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
4949
if (!images.firstRun && images.numLoaded >= images.numTotal){
5050

5151
/*
@@ -57,7 +57,7 @@ html2canvas.Preload = function(element, opts){
5757
options.complete(images);
5858
}
5959

60-
html2canvas.log("Finished loading images: # " + images.numTotal + " (failed: " + images.numFailed + ")");
60+
h2clog("Finished loading images: # " + images.numTotal + " (failed: " + images.numFailed + ")");
6161
}
6262
}
6363

@@ -169,7 +169,7 @@ html2canvas.Preload = function(element, opts){
169169
elNodeType = el.nodeType;
170170
} catch (ex) {
171171
elNodeType = false;
172-
html2canvas.log("html2canvas: failed to access some element's nodeType - Exception: " + ex.message);
172+
h2clog("html2canvas: failed to access some element's nodeType - Exception: " + ex.message);
173173
}
174174

175175
if (elNodeType === 1 || elNodeType === undefined){
@@ -256,9 +256,9 @@ html2canvas.Preload = function(element, opts){
256256
var img, src;
257257
if (!images.cleanupDone) {
258258
if (cause && typeof cause === "string") {
259-
html2canvas.log("html2canvas: Cleanup because: " + cause);
259+
h2clog("html2canvas: Cleanup because: " + cause);
260260
} else {
261-
html2canvas.log("html2canvas: Cleanup after timeout: " + options.timeout + " ms.");
261+
h2clog("html2canvas: Cleanup after timeout: " + options.timeout + " ms.");
262262
}
263263

264264
for (src in images) {
@@ -276,7 +276,7 @@ html2canvas.Preload = function(element, opts){
276276
}
277277
images.numLoaded++;
278278
images.numFailed++;
279-
html2canvas.log("html2canvas: Cleaned up failed img: '" + src + "' Steps: " + images.numLoaded + " / " + images.numTotal);
279+
h2clog("html2canvas: Cleaned up failed img: '" + src + "' Steps: " + images.numLoaded + " / " + images.numTotal);
280280
}
281281
}
282282
}
@@ -307,19 +307,19 @@ html2canvas.Preload = function(element, opts){
307307
if (options.timeout > 0) {
308308
timeoutTimer = window.setTimeout(methods.cleanupDOM, options.timeout);
309309
}
310-
html2canvas.log('html2canvas: Preload starts: finding background-images');
310+
h2clog('html2canvas: Preload starts: finding background-images');
311311
images.firstRun = true;
312312

313313
getImages( element );
314314

315-
html2canvas.log('html2canvas: Preload: Finding images');
315+
h2clog('html2canvas: Preload: Finding images');
316316
// load <img> images
317317
for (i = 0; i < imgLen; i+=1){
318318
methods.loadImage( domImages[i].getAttribute( "src" ) );
319319
}
320320

321321
images.firstRun = false;
322-
html2canvas.log('html2canvas: Preload: Done.');
322+
h2clog('html2canvas: Preload: Done.');
323323
if ( images.numTotal === images.numLoaded ) {
324324
start();
325325
}

src/Queue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
Released under MIT License
77
*/
8-
html2canvas.canvasContext = function (width, height) {
8+
function h2cRenderContext(width, height) {
99
var storage = [];
1010
return {
1111
storage: storage,
@@ -40,4 +40,4 @@ html2canvas.canvasContext = function (width, height) {
4040
});
4141
}
4242
};
43-
};
43+
}

src/Renderer.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ html2canvas.Renderer = function(parseQueue, opts){
176176

177177

178178
}
179-
html2canvas.log("html2canvas: Renderer: Canvas renderer done - returning canvas obj");
179+
h2clog("html2canvas: Renderer: Canvas renderer done - returning canvas obj");
180180

181181
// this.canvasRenderStorage(queue,this.ctx);
182182
queueLen = options.elements.length;
@@ -390,7 +390,7 @@ html2canvas.Renderer = function(parseQueue, opts){
390390

391391

392392

393-
html2canvas.log("html2canvas: Renderer: SVG Renderer done - returning SVG DOM obj");
393+
h2clog("html2canvas: Renderer: SVG Renderer done - returning SVG DOM obj");
394394

395395
return svg;
396396

@@ -405,11 +405,11 @@ html2canvas.Renderer = function(parseQueue, opts){
405405
case "canvas":
406406
canvas = doc.createElement('canvas');
407407
if (canvas.getContext){
408-
html2canvas.log("html2canvas: Renderer: using canvas renderer");
408+
h2clog("html2canvas: Renderer: using canvas renderer");
409409
return canvasRenderer(parseQueue);
410410
} else {
411411
usingFlashcanvas = true;
412-
html2canvas.log("html2canvas: Renderer: canvas not available, using flashcanvas");
412+
h2clog("html2canvas: Renderer: canvas not available, using flashcanvas");
413413
var script = doc.createElement("script");
414414
script.src = options.flashcanvas;
415415

@@ -436,7 +436,7 @@ html2canvas.Renderer = function(parseQueue, opts){
436436
window.setTimeout( intervalFunc, 250 );
437437

438438
} else {
439-
html2canvas.log("html2canvas: Renderer: Can't track when flashcanvas is loaded");
439+
h2clog("html2canvas: Renderer: Can't track when flashcanvas is loaded");
440440

441441
}
442442

@@ -446,9 +446,9 @@ html2canvas.Renderer = function(parseQueue, opts){
446446

447447
})(script, function(){
448448

449-
if (typeof FlashCanvas !== "undefined") {
450-
html2canvas.log("html2canvas: Renderer: Flashcanvas initialized");
451-
FlashCanvas.initElement( canvas );
449+
if (typeof window.FlashCanvas !== "undefined") {
450+
h2clog("html2canvas: Renderer: Flashcanvas initialized");
451+
window.FlashCanvas.initElement( canvas );
452452
canvasRenderer(parseQueue);
453453
}
454454
});
@@ -460,7 +460,7 @@ html2canvas.Renderer = function(parseQueue, opts){
460460
break;
461461
case "svg":
462462
if (doc.createElementNS){
463-
html2canvas.log("html2canvas: Renderer: using SVG renderer");
463+
h2clog("html2canvas: Renderer: using SVG renderer");
464464
return svgRenderer(parseQueue);
465465
}
466466
break;

0 commit comments

Comments
 (0)