").append(m.parseHTML(a)).find(d):a)}).complete(c&&function(a,b){g.each(c,e||[a.responseText,b,a])}),this},m.each(["ajaxStart","ajaxStop","ajaxComplete","ajaxError","ajaxSuccess","ajaxSend"],function(a,b){m.fn[b]=function(a){return this.on(b,a)}}),m.expr.filters.animated=function(a){return m.grep(m.timers,function(b){return a===b.elem}).length};var cd=a.document.documentElement;function dd(a){return m.isWindow(a)?a:9===a.nodeType?a.defaultView||a.parentWindow:!1}m.offset={setOffset:function(a,b,c){var d,e,f,g,h,i,j,k=m.css(a,"position"),l=m(a),n={};"static"===k&&(a.style.position="relative"),h=l.offset(),f=m.css(a,"top"),i=m.css(a,"left"),j=("absolute"===k||"fixed"===k)&&m.inArray("auto",[f,i])>-1,j?(d=l.position(),g=d.top,e=d.left):(g=parseFloat(f)||0,e=parseFloat(i)||0),m.isFunction(b)&&(b=b.call(a,c,h)),null!=b.top&&(n.top=b.top-h.top+g),null!=b.left&&(n.left=b.left-h.left+e),"using"in b?b.using.call(a,n):l.css(n)}},m.fn.extend({offset:function(a){if(arguments.length)return void 0===a?this:this.each(function(b){m.offset.setOffset(this,a,b)});var b,c,d={top:0,left:0},e=this[0],f=e&&e.ownerDocument;if(f)return b=f.documentElement,m.contains(b,e)?(typeof e.getBoundingClientRect!==K&&(d=e.getBoundingClientRect()),c=dd(f),{top:d.top+(c.pageYOffset||b.scrollTop)-(b.clientTop||0),left:d.left+(c.pageXOffset||b.scrollLeft)-(b.clientLeft||0)}):d},position:function(){if(this[0]){var a,b,c={top:0,left:0},d=this[0];return"fixed"===m.css(d,"position")?b=d.getBoundingClientRect():(a=this.offsetParent(),b=this.offset(),m.nodeName(a[0],"html")||(c=a.offset()),c.top+=m.css(a[0],"borderTopWidth",!0),c.left+=m.css(a[0],"borderLeftWidth",!0)),{top:b.top-c.top-m.css(d,"marginTop",!0),left:b.left-c.left-m.css(d,"marginLeft",!0)}}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||cd;while(a&&!m.nodeName(a,"html")&&"static"===m.css(a,"position"))a=a.offsetParent;return a||cd})}}),m.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,b){var c=/Y/.test(b);m.fn[a]=function(d){return V(this,function(a,d,e){var f=dd(a);return void 0===e?f?b in f?f[b]:f.document.documentElement[d]:a[d]:void(f?f.scrollTo(c?m(f).scrollLeft():e,c?e:m(f).scrollTop()):a[d]=e)},a,d,arguments.length,null)}}),m.each(["top","left"],function(a,b){m.cssHooks[b]=Lb(k.pixelPosition,function(a,c){return c?(c=Jb(a,b),Hb.test(c)?m(a).position()[b]+"px":c):void 0})}),m.each({Height:"height",Width:"width"},function(a,b){m.each({padding:"inner"+a,content:b,"":"outer"+a},function(c,d){m.fn[d]=function(d,e){var f=arguments.length&&(c||"boolean"!=typeof d),g=c||(d===!0||e===!0?"margin":"border");return V(this,function(b,c,d){var e;return m.isWindow(b)?b.document.documentElement["client"+a]:9===b.nodeType?(e=b.documentElement,Math.max(b.body["scroll"+a],e["scroll"+a],b.body["offset"+a],e["offset"+a],e["client"+a])):void 0===d?m.css(b,c,g):m.style(b,c,d,g)},b,f?d:void 0,f,null)}})}),m.fn.size=function(){return this.length},m.fn.andSelf=m.fn.addBack,"function"==typeof define&&define.amd&&define("jquery",[],function(){return m});var ed=a.jQuery,fd=a.$;return m.noConflict=function(b){return a.$===m&&(a.$=fd),b&&a.jQuery===m&&(a.jQuery=ed),m},typeof b===K&&(a.jQuery=a.$=m),m});
diff --git a/dist/dom-to-image.min.js b/dist/dom-to-image.min.js
index ded7a489..cfdbc056 100644
--- a/dist/dom-to-image.min.js
+++ b/dist/dom-to-image.min.js
@@ -1,2 +1,2 @@
-/*! dom-to-image 20-04-2015 */
-"use strict";!function(){function a(a,b,d){var e=getComputedStyle(b);if(c)a.style.cssText=e.cssText;else for(var f in e)isNaN(parseInt(f,10))&&"function"!=typeof e[f]&&!/^(cssText|length|parentRule)$/.test(f)&&(a.style[f]=e[f])}function b(b,c){var d=b.querySelectorAll("*"),e=c.querySelectorAll("*");a(b,c,1),Array.prototype.forEach.call(d,function(b,c){a(b,e[c])}),b.style.margin=b.style.marginLeft=b.style.marginTop=b.style.marginBottom=b.style.marginRight=""}var c=""!==getComputedStyle(document.body).cssText;window.domvas={toImage:function(a,c,d,e,f,g){f=f||0,g=g||0;var h=a.cloneNode(!0);b(h,a),h.setAttribute("xmlns","http://www.w3.org/1999/xhtml");var i=(new XMLSerializer).serializeToString(h),j="data:image/svg+xml,
",k=new Image;k.src=j,k.onload=function(){c&&c.call(this,this)}}}}();
\ No newline at end of file
+/*! dom-to-image 22-04-2015 */
+!function(a){"use strict";function b(b,c){var d=a.window.getComputedStyle(b);if(d.cssText)return void(c.style.cssText=d.cssText);for(var e=0;e
"+i+"",k=new Image;k.src=j,k.onload=function(){b&&b.call(k,k)}}}}a.domvas=d()}(this);
\ No newline at end of file
diff --git a/src/domvas.js b/src/domvas.js
index e1ded561..94e4f384 100644
--- a/src/domvas.js
+++ b/src/domvas.js
@@ -1,21 +1,21 @@
(function (global) {
"use strict";
- var supportsCSSText = getComputedStyle(document.body).cssText !== "";
+ function copyCss(source, target) {
+ var sourceStyle = global.window.getComputedStyle(source);
- function copyCSS(elem, origElem, log) {
-
- var computedStyle = getComputedStyle(origElem);
-
- if (supportsCSSText) {
- elem.style.cssText = computedStyle.cssText;
- } else {
- // Really, Firefox?
- for (var prop in computedStyle) {
- if (isNaN(parseInt(prop, 10)) && typeof computedStyle[prop] !== 'function' && !(/^(cssText|length|parentRule)$/).test(prop)) {
- elem.style[prop] = computedStyle[prop];
- }
- }
+ if (sourceStyle.cssText) {
+ target.style.cssText = sourceStyle.cssText;
+ return;
+ }
+
+ for (var i = 0; i < sourceStyle.length; i++) {
+ var propertyName = sourceStyle[i];
+ target.style.setProperty(
+ propertyName,
+ sourceStyle.getPropertyValue(propertyName),
+ sourceStyle.getPropertyPriority(propertyName)
+ );
}
}
@@ -25,11 +25,11 @@
var origChildren = origElem.querySelectorAll('*');
// copy the current style to the clone
- copyCSS(elem, origElem, 1);
+ copyCss(origElem, elem);
// collect all nodes within the element, copy the current style to the clone
Array.prototype.forEach.call(children, function (child, i) {
- copyCSS(child, origChildren[i]);
+ copyCss(origChildren[i], child);
});
// strip margins from the outer element
@@ -70,7 +70,7 @@
// when loaded, fire onload callback with actual image node
img.onload = function () {
if (callback) {
- callback.call(this, this);
+ callback.call(img, img);
}
};
}
diff --git a/src/test.html b/src/test.html
new file mode 100644
index 00000000..6364a88e
--- /dev/null
+++ b/src/test.html
@@ -0,0 +1,23 @@
+