From 19b706bbfa32836ff0e173976c9c30a1ba8f37a8 Mon Sep 17 00:00:00 2001 From: Mark MacKay Date: Thu, 25 Oct 2012 20:30:58 -0500 Subject: [PATCH] re-enabling drag and drop import --- editor/svg-editor.js | 71 ++- editor/svgedit.compiled.js | 871 ++++++++++++++++---------------- method-draw/index.html | 2 + method-draw/svg-editor.js | 71 ++- method-draw/svgedit.compiled.js | 871 ++++++++++++++++---------------- 5 files changed, 944 insertions(+), 942 deletions(-) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index 6a0c39f..4f7925f 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -3625,42 +3625,41 @@ //image handling else { - alert("sorry, bitmap import is temporalily disabled") - //var reader = new FileReader(); - //reader.onloadend = function(e) { - // // lets insert the new image until we know its dimensions - // insertNewImage = function(img_width, img_height){ - // var newImage = svgCanvas.addSvgElementFromJson({ - // "element": "image", - // "attr": { - // "x": 0, - // "y": 0, - // "width": img_width, - // "height": img_height, - // "id": svgCanvas.getNextId(), - // "style": "pointer-events:inherit" - // } - // }); - // svgCanvas.setHref(newImage, e.target.result); - // svgCanvas.selectOnly([newImage]) - // svgCanvas.alignSelectedElements("m", "page") - // svgCanvas.alignSelectedElements("c", "page") - // updateContextPanel(); - // } - // // put a placeholder img so we know the default dimensions - // var img_width = 100; - // var img_height = 100; - // var img = new Image() - // img.src = e.target.result - // document.body.appendChild(img); - // img.onload = function() { - // img_width = img.offsetWidth - // img_height = img.offsetHeight - // insertNewImage(img_width, img_height); - // document.body.removeChild(img); - // } - //}; - //reader.readAsDataURL(file) + var reader = new FileReader(); + reader.onloadend = function(e) { + // lets insert the new image until we know its dimensions + insertNewImage = function(img_width, img_height){ + var newImage = svgCanvas.addSvgElementFromJson({ + "element": "image", + "attr": { + "x": 0, + "y": 0, + "width": img_width, + "height": img_height, + "id": svgCanvas.getNextId(), + "style": "pointer-events:inherit" + } + }); + svgCanvas.setHref(newImage, e.target.result); + svgCanvas.selectOnly([newImage]) + svgCanvas.alignSelectedElements("m", "page") + svgCanvas.alignSelectedElements("c", "page") + updateContextPanel(); + } + // put a placeholder img so we know the default dimensions + var img_width = 100; + var img_height = 100; + var img = new Image() + img.src = e.target.result + document.body.appendChild(img); + img.onload = function() { + img_width = img.offsetWidth + img_height = img.offsetHeight + insertNewImage(img_width, img_height); + document.body.removeChild(img); + } + }; + reader.readAsDataURL(file) } } } diff --git a/editor/svgedit.compiled.js b/editor/svgedit.compiled.js index f9f4e18..254126c 100644 --- a/editor/svgedit.compiled.js +++ b/editor/svgedit.compiled.js @@ -1,30 +1,30 @@ -function touchHandler(a){var s=a.changedTouches,g=s[0],b="";switch(a.type){case "touchstart":b="mousedown";break;case "touchmove":b="mousemove";break;case "touchend":b="mouseup";break;default:return}var p=document.createEvent("MouseEvent");p.initMouseEvent(b,true,true,window,1,g.screenX,g.screenY,g.clientX,g.clientY,false,false,false,false,0,null);if(s.length<2){g.target.dispatchEvent(p);a.preventDefault()}};(function(a){function s(g){if(typeof g.data==="string"){var b=g.handler,p=g.data.toLowerCase().split(" ");g.handler=function(w){if(!(this!==w.target&&(/textarea|select/i.test(w.target.nodeName)||w.target.type==="text"))){var d=w.type!=="keypress"&&a.hotkeys.specialKeys[w.which],f=String.fromCharCode(w.which).toLowerCase(),c="",m={};if(w.altKey&&d!=="alt")c+="alt+";if(w.ctrlKey&&d!=="ctrl")c+="ctrl+";if(w.metaKey&&!w.ctrlKey&&d!=="meta")c+="meta+";if(w.shiftKey&&d!=="shift")c+="shift+";if(d)m[c+d]= -true;else{m[c+f]=true;m[c+a.hotkeys.shiftNums[f]]=true;if(c==="shift+")m[a.hotkeys.shiftNums[f]]=true}d=0;for(f=p.length;d","/":"?","\\":"|"}};a.each(["keydown","keyup","keypress"],function(){a.event.special[this]={add:s}})})(jQuery);(function(a,s){function g(ca){return typeof ca==="string"}function b(ca){var U=c.call(arguments,1);return function(){return ca.apply(this,U.concat(c.call(arguments)))}}function p(ca,U,Z,na,pa){var ma;if(na!==f){U=Z.match(ca?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);Z=U[3]||"";if(pa===2&&g(na))na=na.replace(ca?ea:V,"");else{ma=q(U[2]);na=g(na)?q[ca?ga:N](na):na;na=pa===2?na:pa===1?a.extend({},na,ma):a.extend({},ma,na);na=v(na);if(ca)na=na.replace(Ba,m)}ca=U[1]+(ca?"#":na||!U[1]?"?":"")+na+Z}else ca= -U(Z!==f?Z:s[oa][Y]);return ca}function w(ca,U,Z){if(U===f||typeof U==="boolean"){Z=U;U=v[ca?ga:N]()}else U=g(U)?U.replace(ca?ea:V,""):U;return q(U,Z)}function d(ca,U,Z,na){if(!g(Z)&&typeof Z!=="object"){na=Z;Z=U;U=f}return this.each(function(){var pa=a(this),ma=U||S()[(this.nodeName||"").toLowerCase()]||"",la=ma&&pa.attr(ma)||"";pa.attr(ma,v[ca](la,Z,na))})}var f,c=Array.prototype.slice,m=decodeURIComponent,v=a.param,C,q,L,Q=a.bbq=a.bbq||{},K,I,S,R=a.event.special,N="querystring",ga="fragment",oa= -"location",Y="href",V=/^.*\?|#.*$/g,ea=/^.*\#/,Ba,ja={};v[N]=b(p,0,function(ca){return ca.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")});v[ga]=C=b(p,1,function(ca){return ca.replace(/^[^#]*#?(.*)$/,"$1")});C.noEscape=function(ca){ca=ca||"";ca=a.map(ca.split(""),encodeURIComponent);Ba=RegExp(ca.join("|"),"g")};C.noEscape(",/");a.deparam=q=function(ca,U){var Z={},na={"true":true,"false":false,"null":null};a.each(ca.replace(/\+/g," ").split("&"),function(pa,ma){var la=ma.split("="),ya=m(la[0]),za=Z,Ja= -0,Ia=ya.split("]["),Ha=Ia.length-1;if(/\[/.test(Ia[0])&&/\]$/.test(Ia[Ha])){Ia[Ha]=Ia[Ha].replace(/\]$/,"");Ia=Ia.shift().split("[").concat(Ia);Ha=Ia.length-1}else Ha=0;if(la.length===2){la=m(la[1]);if(U)la=la&&!isNaN(la)?+la:la==="undefined"?f:na[la]!==f?na[la]:la;if(Ha)for(;Ja<=Ha;Ja++){ya=Ia[Ja]===""?za.length:Ia[Ja];za=za[ya]=Ja","/":"?","\\":"|"}};a.each(["keydown","keyup","keypress"],function(){a.event.special[this]={add:s}})})(jQuery);(function(a,s){function g(ca){return typeof ca==="string"}function b(ca){var U=c.call(arguments,1);return function(){return ca.apply(this,U.concat(c.call(arguments)))}}function p(ca,U,Z,na,pa){var ma;if(na!==f){U=Z.match(ca?/^([^#]*)\#?(.*)$/:/^([^#?]*)\??([^#]*)(#?.*)/);Z=U[3]||"";if(pa===2&&g(na))na=na.replace(ca?ea:V,"");else{ma=q(U[2]);na=g(na)?q[ca?ga:N](na):na;na=pa===2?na:pa===1?a.extend({},na,ma):a.extend({},ma,na);na=v(na);if(ca)na=na.replace(Ba,n)}ca=U[1]+(ca?"#":na||!U[1]?"?":"")+na+Z}else ca= +U(Z!==f?Z:s[oa][Y]);return ca}function w(ca,U,Z){if(U===f||typeof U==="boolean"){Z=U;U=v[ca?ga:N]()}else U=g(U)?U.replace(ca?ea:V,""):U;return q(U,Z)}function d(ca,U,Z,na){if(!g(Z)&&typeof Z!=="object"){na=Z;Z=U;U=f}return this.each(function(){var pa=a(this),ma=U||S()[(this.nodeName||"").toLowerCase()]||"",la=ma&&pa.attr(ma)||"";pa.attr(ma,v[ca](la,Z,na))})}var f,c=Array.prototype.slice,n=decodeURIComponent,v=a.param,C,q,L,Q=a.bbq=a.bbq||{},K,I,S,R=a.event.special,N="querystring",ga="fragment",oa= +"location",Y="href",V=/^.*\?|#.*$/g,ea=/^.*\#/,Ba,ja={};v[N]=b(p,0,function(ca){return ca.replace(/(?:^[^?#]*\?([^#]*).*$)?.*/,"$1")});v[ga]=C=b(p,1,function(ca){return ca.replace(/^[^#]*#?(.*)$/,"$1")});C.noEscape=function(ca){ca=ca||"";ca=a.map(ca.split(""),encodeURIComponent);Ba=RegExp(ca.join("|"),"g")};C.noEscape(",/");a.deparam=q=function(ca,U){var Z={},na={"true":true,"false":false,"null":null};a.each(ca.replace(/\+/g," ").split("&"),function(pa,ma){var la=ma.split("="),ya=n(la[0]),za=Z,Ja= +0,Ia=ya.split("]["),Fa=Ia.length-1;if(/\[/.test(Ia[0])&&/\]$/.test(Ia[Fa])){Ia[Fa]=Ia[Fa].replace(/\]$/,"");Ia=Ia.shift().split("[").concat(Ia);Fa=Ia.length-1}else Fa=0;if(la.length===2){la=n(la[1]);if(U)la=la&&!isNaN(la)?+la:la==="undefined"?f:na[la]!==f?na[la]:la;if(Fa)for(;Ja<=Fa;Ja++){ya=Ia[Ja]===""?za.length:Ia[Ja];za=za[ya]=Ja').hide().insertAfter("body")[0].contentWindow; +(function(a,s,g){function b(C){C=C||s[d][f];return C.replace(/^[^#]*#?(.*)$/,"$1")}var p,w=a.event.special,d="location",f="href",c=document.documentMode,n=a.browser.msie&&(c===g||c<8),v="onhashchange"in s&&!n;a.hashchangeDelay=100;w.hashchange=a.extend(w.hashchange,{setup:function(){if(v)return false;a(p.start)},teardown:function(){if(v)return false;a(p.stop)}});p=function(){function C(){K=I=function(S){return S};if(n){Q=a('