Permalink
Browse files

Switch from BlobBuilder to Blob and fix the preview

  • Loading branch information...
1 parent f98fd4f commit 2575531524d8073ea2802b3da366382a4dcfccb7 @louisremi committed Dec 14, 2012
Showing with 17 additions and 15 deletions.
  1. +17 −15 app/index.js
View
32 app/index.js
@@ -24,10 +24,7 @@ var SvgFile = Backbone.Model.extend({
fileReq.responseType = "arraybuffer";
fileReq.onload = function() {
- var blobBuilder = new BlobBuilder();
- blobBuilder.append( fileReq.response );
-
- self.load( blobBuilder.getBlob("image/svg+xml") );
+ self.load( new Blob( [fileReq.response], {type: "image/svg+xml" } ) );
};
fileReq.send();
@@ -99,15 +96,19 @@ var JsonView = Backbone.View.extend({
});
var RaphaelView = Backbone.View.extend({
- render: function() {
- if ( this.model.json == "" ) { return; }
+ events: {
+ change: "render"
+ },
+
+ render: function( json ) {
+ if ( json == "" ) { return; }
- var obj = JSON.parse( this.model.json ),
- width = Math.ceil( json.width ),
- height = Math.ceil( json.height );
+ var obj = JSON.parse( json ),
+ width = Math.ceil( obj.width ),
+ height = Math.ceil( obj.height );
- json.width = 300;
- json.height = 300;
+ obj.width = 300;
+ obj.height = 300;
this.el.innerHTML = "";
@@ -139,7 +140,7 @@ $fileButton.onclick = function() {
jsonOutput.set( "loading", true );
$fileInput.click();
-}
+};
svgFile.on("change", function() {
if ( svgFile.hasChanged( "loading" ) ) {
@@ -157,17 +158,18 @@ svgFile.on("change", function() {
svgFile.on("change", function() {
if ( svgFile.hasChanged( "html" ) ) {
$svgFrame.body.innerHTML = svgFile.get("html");
- jsonOutput.set( "json", JSON.stringify( svgtojs( $svgFrame.querySelector("svg") ) ) )
- console.log( jsonOutput.get("json") );
+ jsonOutput.set( "json", JSON.stringify( svgtojs( $svgFrame.querySelector("svg") ) ) );
jsonView.render();
}
});
jsonOutput.on("change", function() {
- if ( svgFile.hasChanged("loading") ) {
+ if ( jsonOutput.hasChanged("loading") ) {
c( jsonView.el, jsonOutput.get("loading") ? "add" : "remove", "loading" );
c( raphaelView.el, jsonOutput.get("loading") ? "add" : "remove", "loading" );
}
+
+ raphaelView.render( this.get("json") );
});
$fileInput.onchange = function( event ) {

0 comments on commit 2575531

Please sign in to comment.