{I" class:ETI"BundledAsset;FI"logical_path;TI"sketchily_embed.js;TI" pathname;TI"O/home/dantemss/Desktop/sketchily/app/assets/javascripts/sketchily_embed.js;FI"content_type;TI"application/javascript;TI" mtime;Tl+ l:QI" length;Tiã/I" digest;TI"%cd4be2cfb6226c011931a67b944f5fad;FI" source;TI"ã//* function embedded_svg_edit(frame){ //initialize communication this.frame = frame; this.stack = []; //callback stack var editapi = this; window.addEventListener("message", function(e){ if(e.data.substr(0,5) == "ERROR"){ editapi.stack.splice(0,1)[0](e.data,"error") }else{ editapi.stack.splice(0,1)[0](e.data) } }, false) } embedded_svg_edit.prototype.call = function(code, callback){ this.stack.push(callback); this.frame.contentWindow.postMessage(code,"*"); } embedded_svg_edit.prototype.getSvgString = function(callback){ this.call("svgCanvas.getSvgString()",callback) } embedded_svg_edit.prototype.setSvgString = function(svg){ this.call("svgCanvas.setSvgString('"+svg.replace(/'/g, "\\'")+"')"); } */ /* Embedded SVG-edit API General usage: - Have an iframe somewhere pointing to a version of svg-edit > r1000 - Initialize the magic with: var svgCanvas = new embedded_svg_edit(window.frames['svgedit']); - Pass functions in this format: svgCanvas.setSvgString("string") - Or if a callback is needed: svgCanvas.setSvgString("string")(function(data, error){ if(error){ //there was an error }else{ //handle data } }) Everything is done with the same API as the real svg-edit, and all documentation is unchanged. The only difference is when handling returns, the callback notation is used instead. var blah = new embedded_svg_edit(window.frames['svgedit']); blah.clearSelection("woot","blah",1337,[1,2,3,4,5,"moo"],-42,{a: "tree",b:6, c: 9})(function(){console.log("GET DATA",arguments)}) */ function embedded_svg_edit(frame){ //initialize communication this.frame = frame; //this.stack = [] //callback stack this.callbacks = {}; //successor to stack this.encode = embedded_svg_edit.encode; //List of functions extracted with this: //Run in firebug on http://svg-edit.googlecode.com/svn/trunk/docs/files/svgcanvas-js.html //for(var i=0,q=[],f = document.querySelectorAll("div.CFunction h3.CTitle a");i> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output[p++] = KEYSTR.charAt(enc1); output[p++] = KEYSTR.charAt(enc2); output[p++] = KEYSTR.charAt(enc3); output[p++] = KEYSTR.charAt(enc4); } while (i < input.length); return output.join(''); }; // Function: sketchily_decode64 // Converts a string from base64 var sketchily_decode64 = function(input) { if(window.atob) return window.atob(input); var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = KEYSTR.indexOf(input.charAt(i++)); enc2 = KEYSTR.indexOf(input.charAt(i++)); enc3 = KEYSTR.indexOf(input.charAt(i++)); enc4 = KEYSTR.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return unescape(output); }; // Function: sketchily_convertToXMLReferences // Converts a string to use XML references var sketchily_convertToXMLReferences = function(input) { var output = ''; for (var n = 0; n < input.length; n++){ var c = input.charCodeAt(n); if (c < 128) { output += input[n]; } else if(c > 127) { output += ("&#" + c + ";"); } } return output; }; var svgCanvas = svgCanvas || {}; function submitHandler(event) { var id = event.data; svgCanvas[id].getSvgString()(function (data, error) { handleSvgData(data, error, id); }); event.preventDefault(); event.stopImmediatePropagation(); } function attachSubmitHandler(event) { var id = event.data; $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler); } function handleSvgData(data, error, id) { if (error) { alert('Error: ' + error); } else { var input = $("input#" + id); var form = input.closest("form"); input.attr("value", sketchily_encode64("\n" + data)); form.off("submit.svgedit_" + id); form.one("submit.svgedit_" + id, null, id, attachSubmitHandler); form.submit(); } } function initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) { var frame = document.getElementById("svgedit_" + id); svgCanvas[id] = new embedded_svg_edit(frame); var doc = frame.contentDocument; if (!doc) { doc = frame.contentWindow.document; } if (hide_menu) { var mainButton = doc.getElementById('main_button'); mainButton.parentNode.removeChild(mainButton); var toolsTop = doc.getElementById('tools_top'); toolsTop.style.left = '5px'; } if (hide_image_tool) { var imageTool = doc.getElementById('tool_image'); imageTool.parentNode.removeChild(imageTool); } if (!show_hyperlink_tool) { var hyperlinkTool = doc.getElementById('tool_make_link'); hyperlinkTool.parentNode.removeChild(hyperlinkTool); } if (!url) { svgCanvas[id].setSvgString(sketchily_decode64(value)); } $("input#" + id).closest("form").on("submit.svgedit_" + id, null, id, submitHandler); $("#svgedit_" + id).css('visibility', ''); } function attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url) { var frame = $("#svgedit_" + id); if (frame.attr('src')) { frame.load(function () { initEmbed(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url); }); } else { setTimeout(function () { attachLoadHandler(id, value, hide_menu, hide_image_tool, show_hyperlink_tool, url); }, 0); } } ; ;TI"required_assets_digest;TI"%2d1abebdcf0bdcf4b382963a8a25dc8c;FI" _version;TI"%ac1cd7cf9811f9938e2b8937c60a24e6;F