mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
522a443055
* initial typescript conversion * test: update overflow+transform ref test * fix: correctly render pseudo element content * fix: testrunner build * fix: karma test urls * test: update underline tests with <u> elements * test: update to es6-promise polyfill * test: remove watch from server * test: remove flow * format: update prettier for typescript * test: update eslint to use typescript parser * test: update linear gradient reftest * test: update test runner * test: update testrunner promise polyfill * fix: handle display: -webkit-flex correctly (fix #1817) * fix: correctly render gradients with clip & repeat (fix #1773) * fix: webkit-gradient function support * fix: implement radial gradients * fix: text-decoration rendering * fix: missing scroll positions for elements * ci: fix ios 11 tests * fix: ie logging * ci: improve device availability logging * fix: lint errors * ci: update to ios 12 * fix: check for console availability * ci: fix build dependency * test: update text reftests * fix: window reference for unit tests * feat: add hsl/hsla color support * fix: render options * fix: CSSKeyframesRule cssText Permission Denied on Internet Explorer 11 (#1830) * fix: option lint * fix: list type rendering * test: fix platform import * fix: ie css parsing for numbers * ci: add minified build * fix: form element rendering * fix: iframe rendering * fix: re-introduce experimental foreignobject renderer * fix: text-shadow rendering * feat: improve logging * fix: unit test logging * fix: cleanup resources * test: update overflow scrolling to work with ie * build: update build to include typings * fix: do not parse select element children * test: fix onclone test to work with older IEs * test: reduce reftest canvas sizes * test: remove dynamic setUp from list tests * test: update linear-gradient tests * build: remove old source files * build: update docs dependencies * build: fix typescript definition path * ci: include test.js on docs website
157 lines
6.1 KiB
JavaScript
157 lines
6.1 KiB
JavaScript
var h2cSelector, h2cOptions;
|
|
var CI = window.location.search.indexOf('selenium') !== -1;
|
|
var AUTORUN = window.location.search.indexOf('run=false') === -1;
|
|
var REFTEST = window.location.search.indexOf('reftest') !== -1;
|
|
|
|
(function(document, window) {
|
|
function appendScript(src) {
|
|
document.write(
|
|
'<script type="text/javascript" src="' +
|
|
window.location.protocol +
|
|
'//' +
|
|
window.location.host +
|
|
src +
|
|
'.js?' +
|
|
Math.random() +
|
|
'"></script>'
|
|
);
|
|
}
|
|
|
|
(typeof Promise === 'undefined' ? ['/node_modules/es6-promise/dist/es6-promise.auto.min'] : [])
|
|
.concat([
|
|
'/node_modules/jquery/dist/jquery.min',
|
|
'/dist/html2canvas'
|
|
])
|
|
.forEach(appendScript);
|
|
|
|
window.onload = function() {
|
|
(function($) {
|
|
$.fn.html2canvas = function(options) {
|
|
var date = new Date(),
|
|
$message = null,
|
|
timeoutTimer = false,
|
|
timer = date.getTime();
|
|
options = options || {};
|
|
var promise = html2canvas(this[0], options);
|
|
promise['catch'](function(err) {
|
|
console.log('html2canvas threw an error', err);
|
|
});
|
|
|
|
promise.then(function(canvas) {
|
|
var $canvas = $(canvas),
|
|
finishTime = new Date();
|
|
|
|
$canvas
|
|
.addClass('html2canvas')
|
|
.css({
|
|
position: 'absolute',
|
|
left: 0,
|
|
top: 0
|
|
})
|
|
.appendTo(document.body);
|
|
if (!CI) {
|
|
$canvas.siblings().toggle();
|
|
$(window).click(function(event) {
|
|
if (event.button === 0) {
|
|
var scrollTop = $(window).scrollTop();
|
|
$canvas.toggle().siblings().toggle();
|
|
$(document.documentElement).css(
|
|
'background',
|
|
$canvas.is(':visible') ? 'none' : ''
|
|
);
|
|
$(document.body).css(
|
|
'background',
|
|
$canvas.is(':visible') ? 'none' : ''
|
|
);
|
|
throwMessage(
|
|
'Canvas Render ' +
|
|
($canvas.is(':visible') ? 'visible' : 'hidden')
|
|
);
|
|
$(window).scrollTop(scrollTop);
|
|
}
|
|
});
|
|
$(document.documentElement).css(
|
|
'background',
|
|
$canvas.is(':visible') ? 'none' : ''
|
|
);
|
|
$(document.body).css('background', $canvas.is(':visible') ? 'none' : '');
|
|
throwMessage(
|
|
'Screenshot created in ' + (finishTime.getTime() - timer) + ' ms<br />',
|
|
4000
|
|
);
|
|
} else {
|
|
$canvas.css('display', 'none');
|
|
}
|
|
// test if canvas is read-able
|
|
try {
|
|
$canvas[0].toDataURL();
|
|
} catch (e) {
|
|
if ($canvas[0].nodeName.toLowerCase() === 'canvas') {
|
|
// TODO, maybe add a bit less offensive way to present this, but still something that can easily be noticed
|
|
window.alert('Canvas is tainted, unable to read data');
|
|
}
|
|
}
|
|
});
|
|
|
|
function throwMessage(msg, duration) {
|
|
window.clearTimeout(timeoutTimer);
|
|
timeoutTimer = window.setTimeout(function() {
|
|
$message.fadeOut(function() {
|
|
$message.remove();
|
|
$message = null;
|
|
});
|
|
}, duration || 2000);
|
|
if ($message) $message.remove();
|
|
$message = $('<div />')
|
|
.html(msg)
|
|
.css({
|
|
margin: 0,
|
|
padding: 10,
|
|
background: '#000',
|
|
opacity: 0.7,
|
|
position: 'fixed',
|
|
top: 10,
|
|
right: 10,
|
|
fontFamily: 'Tahoma',
|
|
color: '#fff',
|
|
fontSize: 12,
|
|
borderRadius: 12,
|
|
width: 'auto',
|
|
height: 'auto',
|
|
textAlign: 'center',
|
|
textDecoration: 'none',
|
|
display: 'none'
|
|
})
|
|
.appendTo(document.body)
|
|
.fadeIn();
|
|
}
|
|
};
|
|
})(jQuery);
|
|
|
|
h2cSelector = typeof h2cSelector === 'undefined' ? [document.documentElement] : h2cSelector;
|
|
|
|
if (window.setUp) {
|
|
window.setUp();
|
|
}
|
|
|
|
window.run = function() {
|
|
$(h2cSelector).html2canvas(
|
|
$.extend(
|
|
{
|
|
logging: true,
|
|
proxy: 'http://localhost:8081/proxy',
|
|
useCORS: false,
|
|
removeContainer: true
|
|
},
|
|
h2cOptions,
|
|
REFTEST ? {windowWidth: 800, windowHeight: 600} : {}
|
|
)
|
|
);
|
|
};
|
|
|
|
if (typeof dontRun === 'undefined' && AUTORUN) {
|
|
setTimeout(window.run, 100);
|
|
}
|
|
};
|
|
})(document, window);
|