Skip to content

Commit

Permalink
Rename toDataURL() to dataUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
premasagar committed Oct 8, 2013
1 parent 87a3856 commit 6f3fc13
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
22 changes: 11 additions & 11 deletions pablo.js
Expand Up @@ -100,16 +100,16 @@

support = (function(){
var createCanvas = 'getContext' in document.createElement('canvas'),
dataURL = 'btoa' in window,
imageSvg = dataURL;
dataUrl = 'btoa' in window,
imageSvg = dataUrl;

return {
basic: true,
classList: 'classList' in testElement,
dataURL: dataURL,
dataUrl: dataUrl,
imageSvg: imageSvg,
canvas: imageSvg && createCanvas,
download: dataURL && 'createEvent' in document && 'download' in document.createElement('a')
download: dataUrl && 'createEvent' in document && 'download' in document.createElement('a')
};
}());

Expand Down Expand Up @@ -1123,8 +1123,8 @@
};
}()),

toDataURL: (function(){
if (support.dataURL){
dataUrl: (function(){
if (support.dataUrl){
return function(){
var collection, markup;

Expand All @@ -1143,7 +1143,7 @@
//return window.URL.createObjectURL(blob);
};
}
// Can't generate dataURL (use a polyfill to enable the toDataURL method in an unsupported browser)
// Can't generate dataUrl (use a polyfill to enable the dataUrl method in an unsupported browser)
return function(){};
}()),

Expand Down Expand Up @@ -1202,8 +1202,8 @@
height: el.height
});
});
// Set the image src, using the collection's toDataUrl() method
el.src = this.toDataURL();
// Set the image src, using the collection's dataUrl() method
el.src = this.dataUrl();
}

// PNG, JPEG or other format supported by the browser
Expand Down Expand Up @@ -1234,8 +1234,8 @@
download: function(filename){
var link = Pablo(document.createElement('a')),
markup = this.markup(this),
url = this.toDataURL(),
// An alternative approach to using toDataURL is to create a Blob
url = this.dataUrl(),
// An alternative approach to using dataUrl is to create a Blob
//blob = new window.Blob([markup], {type:'image/svg+xml'}),
//url = window.URL.createObjectURL(blob),
event;
Expand Down
36 changes: 33 additions & 3 deletions tests/tests.js
Expand Up @@ -146,12 +146,42 @@
it.skip(test('svgElement.children', typeof testElement.children === 'object'));
});

describe('Support for dataURL() and toImage("svg")', function(){
describe('Support for dataUrl() and toImage("svg")', function(){
it.skip(test('window.btoa', 'btoa' in window));
});

describe('Support for toImage("png") and toImage("jpeg")', function(){
it.skip('TODO');
function testImageCreation(imageType, done){
//ctx.fillStyle = "rgb(200,0,0)";
//ctx.fillRect(10, 10, 55, 50);
var canvas1 = document.createElement('canvas'),
ctx1 = canvas1.getContext('2d'),
testRect = Pablo.rect({width:1, height:1, fill:'red'}),
testSvg = Pablo.svg().append(testRect).crop();

canvas1.width = canvas1.height = 1;
ctx1.fillStyle = 'red';
ctx1.fillRect(0,0,1,1);

// Pablo('body').empty().append(image);
// TODO: if image var not created first, on jpeg, this fails

testRect.toImage(imageType)
.on('load', function(){
done();
})
.on('pablo:error', function(){
done(new Error('Image failed to load'));
});
}

it('image("png")', function(done){
testImageCreation('png', done);
});

it('image("jpeg")', function(done){
testImageCreation('jpeg', done);
});
});

describe('Support for toCanvas() method', function(){
Expand All @@ -162,7 +192,7 @@
describe('Support for download() method', function(){
it.skip(test('document.createEvent', 'createEvent' in document));
it.skip(test('HTML <a> elements have "download" attribute', 'download' in document.createElement('a')));
it.skip(test('can call dataURL()', 'btoa' in window));
it.skip(test('can call dataUrl()', 'btoa' in window));
});

describe('Alternative native APIs for download() support', function(){
Expand Down

0 comments on commit 6f3fc13

Please sign in to comment.