From 44c02061d73f93dd068a426456665da1d79e0ba4 Mon Sep 17 00:00:00 2001 From: Matt Minuti Date: Tue, 1 Sep 2015 20:54:20 -0400 Subject: [PATCH] Did some cleanup of semicolons and stuff. jshint is interesting. --- .jshintrc | 5 + blockscad/blockscad.js | 98 ++++++----- blockscad/blockscad_compressed.js | 282 +++++++++++++++--------------- blockscad/stl.js | 4 +- blockscad/text.js | 39 +++-- blockscad/utils.js | 5 +- blockscad/viewer.js | 18 +- blockscad/viewer_compressed.js | 6 +- 8 files changed, 236 insertions(+), 221 deletions(-) create mode 100644 .jshintrc diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..6b05efc --- /dev/null +++ b/.jshintrc @@ -0,0 +1,5 @@ +{ + "browser": true, + "devel": true, + "jquery": true +} diff --git a/blockscad/blockscad.js b/blockscad/blockscad.js index f535c54..e5e0eac 100644 --- a/blockscad/blockscad.js +++ b/blockscad/blockscad.js @@ -123,7 +123,7 @@ Blockscad.init = function() { var h = $( window ).height(); // resize the viewer if (gProcessor) { - var h = gProcessor.viewerdiv.offsetHeight; + h = gProcessor.viewerdiv.offsetHeight; var w = gProcessor.viewerdiv.offsetWidth; gProcessor.viewer.rendered_resize(w,h); } @@ -160,7 +160,7 @@ Blockscad.init = function() { $( '#axesButton' ).click(function() { // toggle whether or not we draw the axes, then redraw Blockscad.drawAxes = (Blockscad.drawAxes + 1) % 2; - $( '#axesButton' ).toggleClass("btn-pushed") + $( '#axesButton' ).toggleClass("btn-pushed"); gProcessor.viewer.onDraw(); }); @@ -203,10 +203,11 @@ $( "#target" ).click(function() { //console.log("in readSingleFile. f is ", f); if (f) { + var proj_name; if (replaceOld) { // use the name of the loaded file to fill the "file loading" and "project name" boxes. - var proj_name = f.name.substr(0,f.name.lastIndexOf('(')) || f.name; + proj_name = f.name.substr(0,f.name.lastIndexOf('(')) || f.name; proj_name = proj_name.substr(0,f.name.lastIndexOf('.')) || proj_name; // trim any whitespace from the beginning or end of the project name @@ -240,7 +241,7 @@ $( "#target" ).click(function() { Blockly.fireUiEvent(window, 'resize'); Blockscad.clearStlBlocks(); - } + }; r.readAsText(f); // in order that we can read this filename again, I'll clear out the current filename @@ -308,10 +309,11 @@ $( "#target" ).click(function() { Blockscad.csg_center[proj_name_use] = center; // I've got a file here. What should I do with it? + var bt_input; if (Blockscad.currentInterestingBlock) { // console.log('the current block is:', Blockscad.currentInterestingBlock); var fn_input = Blockscad.currentInterestingBlock.getField('STL_FILENAME'); - var bt_input = Blockscad.currentInterestingBlock.getField('STL_BUTTON'); + bt_input = Blockscad.currentInterestingBlock.getField('STL_BUTTON'); var ct_input = Blockscad.currentInterestingBlock.getField('STL_CONTENTS'); fn_input.setText(f.name); fn_input.setVisible(true); @@ -331,13 +333,13 @@ $( "#target" ).click(function() { //console.log("xml is:",xml); var stuff = Blockly.Xml.textToDom(xml); var newblock = Blockly.Xml.domToBlock(Blockscad.workspace, stuff.firstChild); - var bt_input = newblock.getField('STL_BUTTON'); + bt_input = newblock.getField('STL_BUTTON'); bt_input.setVisible(false); newblock.setCommentText(f.name + '\ncenter:(' + center + ')'); newblock.render(); } - } + }; r.readAsBinaryString(f); // in order that we can read this filename again, I'll clear out the current filename $("#importStl")[0].value = ''; @@ -350,10 +352,10 @@ $( "#target" ).click(function() { } else { alert("Failed to load file"); } - } - $('#file-menu').on('change', '#loadLocal', function(e) { readSingleFile(e, true)}); - $('#file-menu').on('change', '#importLocal', function(e) { readSingleFile(e, false)}); - $('#file-menu').on('change', '#importStl', function(e) { Blockscad.readStlFile(e)}); + }; + $('#file-menu').on('change', '#loadLocal', function(e) { readSingleFile(e, true);}); + $('#file-menu').on('change', '#importLocal', function(e) { readSingleFile(e, false);}); + $('#file-menu').on('change', '#importStl', function(e) { Blockscad.readStlFile(e);}); //End FileSaver.js stuff @@ -459,7 +461,7 @@ Blockscad.clearStlBlocks = function() { } } -} +}; // Start a new project (save old project to account if logged in, clear blocks, clear rendered view) Blockscad.newProject = function() { @@ -481,7 +483,7 @@ Blockscad.newProject = function() { // if the user was on the code tab, switch them to the blocks tab. $('#displayBlocks').click(); -} +}; Blockscad.clearProject = function() { @@ -505,7 +507,7 @@ Blockscad.clearProject = function() { $('#project-name').val('Untitled'); $('#projectView').hide(); $('#editView').show(); -} +}; @@ -529,7 +531,7 @@ Blockscad.resetView = function() { gProcessor.viewer.viewReset(); } } -} +}; // check for if there are both 2D and 3D shapes to be rendered Blockscad.mixes2and3D = function() { @@ -544,21 +546,21 @@ Blockscad.mixes2and3D = function() { if (Blockscad.stackIsShape(topBlocks[i])) { hasShape = 1; var cat = topBlocks[i].category; - + var mytype; if (cat == 'PRIMITIVE_CSG') hasCSG++; if (cat == 'PRIMITIVE_CAG') hasCAG++; if (cat == 'TRANSFORM' || cat == 'SET_OP') { - var mytype = topBlocks[i].getInput('A').connection.check_; + mytype = topBlocks[i].getInput('A').connection.check_; if (mytype.length == 1 && mytype[0] == 'CSG') hasCSG++; if (mytype.length == 1 && mytype[0] == 'CAG') hasCAG++; } if (cat == 'LOOP') { - var mytype = topBlocks[i].getInput('DO').connection.check_; + mytype = topBlocks[i].getInput('DO').connection.check_; if (mytype.length == 1 && mytype[0] == 'CSG') hasCSG++; if (mytype.length == 1 && mytype[0] == 'CAG') hasCAG++; } if (cat == 'PROCEDURE') { - var mytype = topBlocks[i].myType_; + mytype = topBlocks[i].myType_; if (mytype && mytype == 'CSG') hasCSG++; if (mytype && mytype == 'CAG') hasCAG++; } @@ -573,7 +575,7 @@ Blockscad.mixes2and3D = function() { Blockscad.assignBlockTypes(Blockly.mainWorkspace.getTopBlocks()); } return [(hasCSG && hasCAG), hasShape]; -} +}; Blockscad.doRender = function() { // First, lets clear any old error messages. @@ -588,7 +590,7 @@ Blockscad.doRender = function() { var mixes = Blockscad.mixes2and3D(); - if (mixes[1] == 0) { // doesn't have any CSG or CAG shapes at all! + if (mixes[1] === 0) { // doesn't have any CSG or CAG shapes at all! $( '#error-message' ).html("Error: Nothing to Render"); $( '#error-message' ).addClass("has-error"); // HACK: file load is too slow - if user tries to render during file load @@ -614,15 +616,16 @@ Blockscad.doRender = function() { Blockscad.illegalValue = []; var code = Blockly.OpenSCAD.workspaceToCode(Blockscad.workspace); var gotErr = false; + var others, blk; if (Blockscad.missingFields.length > 0) { // highlight the missing blocks, set up/display the correct error message for (var i = 0; i < Blockscad.missingFields.length; i++) { - var blk = Blockly.mainWorkspace.getBlockById(Blockscad.missingFields[i]); + blk = Blockly.mainWorkspace.getBlockById(Blockscad.missingFields[i]); blk.unselect(); blk.backlight(); // if block is in a collapsed parent, highlight collapsed parent too - var others = blk.collapsedParents(); + others = blk.collapsedParents(); if (others) for (var j=0; j < others.length; j++) { others[j].unselect(); @@ -634,11 +637,11 @@ Blockscad.doRender = function() { if (Blockscad.illegalValue.length > 0) { // highlight the missing blocks, set up/display the correct error message for (var i = 0; i < Blockscad.illegalValue.length; i++) { - var blk = Blockly.mainWorkspace.getBlockById(Blockscad.illegalValue[i]); + blk = Blockly.mainWorkspace.getBlockById(Blockscad.illegalValue[i]); blk.unselect(); blk.backlight(); // if block is in a collapsed parent, highlight collapsed parent too - var others = blk.collapsedParents(); + others = blk.collapsedParents(); if (others) for (var j=0; j < others.length; j++) { others[j].unselect(); @@ -677,14 +680,14 @@ Blockscad.doRender = function() { else { Blockscad.renderCode(code); } -} +}; Blockscad.renderCode = function(code) { var csgcode = ''; var code_good = true; try { // console.log("code was: ",code); - window.setTimeout(function (){ csgcode = openscadOpenJscadParser.parse(code) }, 0); + window.setTimeout(function (){ csgcode = openscadOpenJscadParser.parse(code); }, 0); //code = openscadOpenJscadParser.parse(code); //console.log("code is now:",code); } @@ -704,7 +707,7 @@ Blockscad.renderCode = function(code) { $('#renderButton').html('Render'); } -} +}; // Blockscad.isRealChange is called from Blockscad.workspaceChanged to see if // the changes should count as "undoable" or should be ignored. @@ -753,7 +756,7 @@ Blockscad.isRealChange = function() { // this is the "block deleted" condition Blockscad.undo.fieldChanging = 0; // were all the blocks deleted? - if (Blockscad.undo.blockList.length == 0) { + if (Blockscad.undo.blockList.length === 0) { // All blocks were deleted. An undo would have to restore current.xml here. } else { @@ -769,7 +772,7 @@ Blockscad.isRealChange = function() { // A block has been added here. Get the new block. If it has a category, // send it to assignBlockTypes. (might want to get parent too for undo?) Blockscad.undo.fieldChanging = 0; - if (Blockscad.undo.oldBlockList.length == 0) { + if (Blockscad.undo.oldBlockList.length === 0) { // We just refreshed, loaded Blockscad.assignBlockTypes(Blockly.mainWorkspace.getTopBlocks()); // console.log("whole workspace refreshed"); @@ -846,7 +849,7 @@ Blockscad.isRealChange = function() { } return false; -}// end Blockscad.isRealChange() +};// end Blockscad.isRealChange() Blockscad.workspaceChanged = function () { @@ -883,9 +886,9 @@ Blockscad.workspaceChanged = function () { // I need to reassign block types to ALL BLOCKS afterwards (grr) Blockscad.assignBlockTypes(Blockly.mainWorkspace.getTopBlocks()); } - if (Blockscad.undo.just_did_undo == 0) { + if (Blockscad.undo.just_did_undo === 0) { // push Blockscad.current_xml onto undo stack - if (Blockscad.undo.current_xml != null) { + if (Blockscad.undo.current_xml !== null) { Blockscad.undo.undoStack.push(Blockscad.undo.current_xml); } // refill current_xml with the new, changed, xml state @@ -928,7 +931,7 @@ Blockscad.workspaceChanged = function () { else { $('#redoButton').prop('disabled', true); } -} // end workspaceChanged() +}; // end workspaceChanged() Blockscad.getExtraRootBlock = function(old,current) { //console.log("starting getExtraRootBlock"); var gotOne = 0; @@ -973,7 +976,7 @@ Blockscad.getExtraRootBlock = function(old,current) { } // console.log("getExtraRootBlock failed!"); return 0; // this should never happen -} // end getExtraRootBlock() +}; // this get block from id function searches a given list of blocks, // instead of the blocks in the main workspace. Needed for typing. @@ -1022,7 +1025,7 @@ Blockscad.onUndo = function() { } -} // end onUndo() +}; // end onUndo() Blockscad.onRedo = function() { //console.log("Redo button activated!\n"); @@ -1040,7 +1043,7 @@ Blockscad.onRedo = function() { Blockscad.undo.just_did_undo = 1; //console.log("just_did_undo = 1"); } -} // end onRedo() +}; // end onRedo() // disable any math or logic or variable blocks sitting around onthe workspace. Blockscad.checkMathOrphans = function() { @@ -1057,7 +1060,7 @@ Blockscad.checkMathOrphans = function() { topBlocks[i].setDisabled(true); } } -} // end checkMathOrphans() +}; // end checkMathOrphans() // enable any disabled math blocks in an enabled parent. // sometimes we'll be sent a parent block, and need to check its children. @@ -1077,13 +1080,13 @@ Blockscad.enableMathBlocks = function(block) { } } } -} +}; Blockscad.aCallerBlock = function(block, callers) { for (var i = 0; i < callers.length; i++) if (block == callers[i]) return true; return false; -} // end Blockscad.aCallerBlock +}; // end Blockscad.aCallerBlock // have a single block, and want to find out what type it's stack makes it? // This is for procedure call block typing. @@ -1117,7 +1120,7 @@ Blockscad.findBlockType = function(block, callers) { return('CAG'); } else return('EITHER'); -} +}; // is this block attached to an actual primitive (2D or 3D)? Needed for missing fields calc. // if the block has a disabled parent, it won't be rendered and doesn't count. @@ -1131,7 +1134,7 @@ Blockscad.stackIsShape = function(block) { return true; } return false; -} +}; // Blockscad.assignBlockTypes // input: array of blocks whose trees need typing @@ -1182,7 +1185,7 @@ Blockscad.assignBlockTypes = function(blocks) { //console.log("in assignBlockTypes(foundCSG,foundCAG)",foundCSG,foundCAG); //console.log("blockStack",blockStack); } -} +}; Blockscad.hasExtrudeParent = function(block) { do { if (block.category == 'EXTRUDE') @@ -1190,7 +1193,7 @@ Blockscad.hasExtrudeParent = function(block) { block = block.parentBlock_; } while (block); return false; -} +}; // -- BEGIN OPENJSCAD STUFF -- @@ -1218,7 +1221,8 @@ Blockscad.initLanguage = function() { // Sort languages alphabetically. var languages = []; - for (var lang in BSUtils.LANGUAGE_NAME) { + var lang; + for (lang in BSUtils.LANGUAGE_NAME) { languages.push([BSUtils.LANGUAGE_NAME[lang], lang]); } var comp = function(a, b) { @@ -1233,7 +1237,7 @@ Blockscad.initLanguage = function() { languageMenu.options.length = 0; for (var i = 0; i < languages.length; i++) { var tuple = languages[i]; - var lang = tuple[tuple.length - 1]; + lang = tuple[tuple.length - 1]; var option = new Option(tuple[0], lang); if (lang == BSUtils.LANG) { option.selected = true; @@ -1273,4 +1277,4 @@ Blockscad.saveBlocksLocal = function() { else { alert("SAVE FAILED. Please give your project a name, then try again."); } -} +}; diff --git a/blockscad/blockscad_compressed.js b/blockscad/blockscad_compressed.js index 866859a..e5856fc 100644 --- a/blockscad/blockscad_compressed.js +++ b/blockscad/blockscad_compressed.js @@ -23,35 +23,36 @@ Blockscad.Auth.loggedIn=function(a,b){Blockscad.Auth.isLoggedIn=1;Blockscad.Auth $("#file-menu").html('
  • My Projects
  • \n
  • New
  • \n
  • Save
  • \n
  • Save As A Copy
  • \n
  • \n
  • Save Blocks to your Computer
  • \n
  • \n\nLoad Blocks from your Computer\n
  • \n
  • \n
  • \n\nImport Blocks into Current Project\n
  • \n
  • \n\nImport STL into Current Project\n
  • \n')}; Blockscad.Auth.forgotPassword=function(){$("#login-user").modal("hide");$("#pw-recover").modal("show")};Blockscad.Auth.checkForUser=function(){$.get(Blockscad.Auth.sessionTestURL,function(a,b){if(a.match(/^SUCCESS/)){var d=a.split(" ");Blockscad.Auth.loggedIn(d[1],d[2])}}).fail(function(a,b){Blockscad.Auth.notLoggedIn()})}; Blockscad.Auth.listProject=function(){0a.length&&(d.text(Blockscad.FORM_ERRORS.passwordLength),b=!0));b?(d.addClass("form-error-message"),Blockscad.Auth.goodPassword=!1):(d.removeClass("form-error-message"),Blockscad.Auth.goodPassword=!0)}; Blockscad.Auth.validatePasswordMatch=function(a){a=$(this).parent().prev().find("input").val();var b=$(this).val(),d=$(this).parent().find(".password-confirm-error");d.text("");a!=b?(d.text(Blockscad.FORM_ERRORS.passwordConfirm),d.addClass("form-error-message"),Blockscad.Auth.goodPasswordMatch=!1):(d.removeClass("form-error-message"),Blockscad.Auth.goodPasswordMatch=!0)}; Blockscad.Auth.validateEmail=function(){var a=!1,b=$(this).val(),d=$(this).next("div").find(".email-error");d.text("");b.length?/\S+@\S+\.\S+/.test(b)||(d.html(Blockscad.FORM_ERRORS.emailInvalid),a=!0):(d.html(Blockscad.FORM_ERRORS.emailEmpty),a=!0);a?(d.addClass("form-error-message"),Blockscad.Auth.goodEmail=!1):(d.removeClass("form-error-message"),Blockscad.Auth.goodEmail=!0)}; Blockscad.Auth.validateUsername=function(a,b){var d=$("#register-username").val(),e=!1,k=$("#username-error");k.text("");d.length||b||(k.text(Blockscad.FORM_ERRORS.usernameEmpty),e=!0);if(d.length&&(3>d.length||30Blockscad.csg_commands[p].length){var n=Base64.toBase64(RawDeflate.deflate(Base64.utob(Blockscad.csg_commands[p]))); -window.localStorage.setItem(l,n);window.localStorage.setItem(u,Blockscad.csg_center[p])}}}window.localStorage.setItem(b,Blockly.Xml.domToText(a));window.localStorage.setItem(d,$("#project-name").val());window.localStorage.setItem(e,Blockscad.Auth.current_project)}};BlocklyStorage.backupOnUnload=function(){window.addEventListener("unload",BlocklyStorage.backupBlocks_,!1)}; -BlocklyStorage.restoreBlocks=function(){var a=window.location.href.split("#")[0],b=a+"proj_name",d=a+"current_project";console.log(window.localStorage);if("localStorage"in window&&window.localStorage[a]){var e=Blockly.Xml.textToDom(window.localStorage[a]);Blockly.Xml.domToWorkspace(Blockscad.workspace,e);for(var e=Blockscad.workspace.getAllBlocks(),k=0;kBlockscad.csg_commands[q].length){var l=Base64.toBase64(RawDeflate.deflate(Base64.utob(Blockscad.csg_commands[q]))); +window.localStorage.setItem(n,l);window.localStorage.setItem(w,Blockscad.csg_center[q])}}}window.localStorage.setItem(b,Blockly.Xml.domToText(a));window.localStorage.setItem(d,$("#project-name").val());window.localStorage.setItem(e,Blockscad.Auth.current_project)}};BlocklyStorage.backupOnUnload=function(){window.addEventListener("unload",BlocklyStorage.backupBlocks_,!1)}; +BlocklyStorage.restoreBlocks=function(){var a=window.location.href.split("#")[0],b=a+"proj_name",d=a+"current_project";console.log(window.localStorage);if("localStorage"in window&&window.localStorage[a]){var e=Blockly.Xml.textToDom(window.localStorage[a]);Blockly.Xml.domToWorkspace(Blockscad.workspace,e);for(var e=Blockscad.workspace.getAllBlocks(),k=0;kd[0]?1:a[0]b[0]?1:a[0]screen.availWidth&&a.setAttribute("content","width=725, initial-scale=.35, user-scalable=no")}; BSUtils.initReadonly=function(){Blockly.inject(document.getElementById("blockly"),{path:"./",readOnly:!0,rtl:BSUtils.isRtl(),scrollbars:!1});var a=BSUtils.getStringParamFromUrl("xml",""),a=Blockly.Xml.textToDom(""+a+"");Blockly.Xml.domToWorkspace(Blockly.mainWorkspace,a)}; -BSUtils.loadBlocks=function(a){try{var b=window.sessionStorage.loadOnceBlocks}catch(d){b=null}"BlocklyStorage"in window&&1=b.length?"?lang="+a:b.match(/[?&]lang=[^&]*/)?b.replace(/([?&]lang=)[^&]*/,"$1"+a):b.replace(/\?/,"?lang="+a+"&");window.location=window.location.protocol+"//"+ window.location.host+window.location.pathname+b};BSUtils.isDialogVisible_=!1;BSUtils.dialogOrigin_=null;BSUtils.dialogDispose_=null; -BSUtils.showDialog=function(a,b,d,e,k,g){function p(){BSUtils.isDialogVisible_&&(l.style.visibility="visible",l.style.zIndex=1,u.style.visibility="hidden")}BSUtils.isDialogVisible_&&BSUtils.hideDialog(!1);BSUtils.isDialogVisible_=!0;BSUtils.dialogOrigin_=b;BSUtils.dialogDispose_=g;var l=document.getElementById("dialog");g=document.getElementById("dialogShadow");var u=document.getElementById("dialogBorder"),n;for(n in k)l.style[n]=k[n];e&&(g.style.visibility="visible",g.style.opacity=.3,e=document.createElement("div"), -e.id="dialogHeader",l.appendChild(e),BSUtils.dialogMouseDownWrapper_=Blockly.bindEvent_(e,"mousedown",null,BSUtils.dialogMouseDown_));l.appendChild(a);a.className=a.className.replace("dialogHiddenContent","");d&&b?(BSUtils.matchBorder_(b,!1,.2),BSUtils.matchBorder_(l,!0,.8),window.setTimeout(p,175)):p()};BSUtils.dialogStartX_=0;BSUtils.dialogStartY_=0; +BSUtils.showDialog=function(a,b,d,e,k,g){function q(){BSUtils.isDialogVisible_&&(n.style.visibility="visible",n.style.zIndex=1,w.style.visibility="hidden")}BSUtils.isDialogVisible_&&BSUtils.hideDialog(!1);BSUtils.isDialogVisible_=!0;BSUtils.dialogOrigin_=b;BSUtils.dialogDispose_=g;var n=document.getElementById("dialog");g=document.getElementById("dialogShadow");var w=document.getElementById("dialogBorder"),l;for(l in k)n.style[l]=k[l];e&&(g.style.visibility="visible",g.style.opacity=.3,e=document.createElement("div"), +e.id="dialogHeader",n.appendChild(e),BSUtils.dialogMouseDownWrapper_=Blockly.bindEvent_(e,"mousedown",null,BSUtils.dialogMouseDown_));n.appendChild(a);a.className=a.className.replace("dialogHiddenContent","");d&&b?(BSUtils.matchBorder_(b,!1,.2),BSUtils.matchBorder_(n,!0,.8),window.setTimeout(q,175)):q()};BSUtils.dialogStartX_=0;BSUtils.dialogStartY_=0; BSUtils.dialogMouseDown_=function(a){BSUtils.dialogUnbindDragEvents_();if(!Blockly.isRightButton(a)){var b=document.getElementById("dialog");BSUtils.dialogStartX_=b.offsetLeft-a.clientX;BSUtils.dialogStartY_=b.offsetTop-a.clientY;BSUtils.dialogMouseUpWrapper_=Blockly.bindEvent_(document,"mouseup",null,BSUtils.dialogUnbindDragEvents_);BSUtils.dialogMouseMoveWrapper_=Blockly.bindEvent_(document,"mousemove",null,BSUtils.dialogMouseMove_);a.stopPropagation()}}; BSUtils.dialogMouseMove_=function(a){var b=document.getElementById("dialog"),d=BSUtils.dialogStartX_+a.clientX;a=BSUtils.dialogStartY_+a.clientY;a=Math.max(a,0);a=Math.min(a,window.innerHeight-b.offsetHeight);d=Math.max(d,0);d=Math.min(d,window.innerWidth-b.offsetWidth);b.style.left=d+"px";b.style.top=a+"px"}; BSUtils.dialogUnbindDragEvents_=function(){BSUtils.dialogMouseUpWrapper_&&(Blockly.unbindEvent_(BSUtils.dialogMouseUpWrapper_),BSUtils.dialogMouseUpWrapper_=null);BSUtils.dialogMouseMoveWrapper_&&(Blockly.unbindEvent_(BSUtils.dialogMouseMoveWrapper_),BSUtils.dialogMouseMoveWrapper_=null)}; @@ -63,153 +64,156 @@ BSUtils.storageAlert=function(a){var b=document.getElementById("containerStorage BSUtils.dialogKeyDown_=function(a){!BSUtils.isDialogVisible_||13!=a.keyCode&&27!=a.keyCode&&32!=a.keyCode||(BSUtils.hideDialog(!0),a.stopPropagation(),a.preventDefault())};BSUtils.startDialogKeyDown=function(){document.body.addEventListener("keydown",BSUtils.dialogKeyDown_,!0)};BSUtils.stopDialogKeyDown=function(){document.body.removeEventListener("keydown",BSUtils.dialogKeyDown_,!0)};BSUtils.getMsg=function(a){var b=BSUtils.getMsgOrNull(a);return null===b?"[Unknown message: "+a+"]":b}; BSUtils.getMsgOrNull=function(a){return(a=document.getElementById(a))?(a=a.textContent,a=a.replace(/\\n/g,"\n")):null};BSUtils.addTouchEvents=function(){if("ontouchstart"in document.documentElement)for(var a=document.getElementsByTagName("button"),b=0,d;d=a[b];b++)d.ontouchend||(d.ontouchend=d.onclick)};window.addEventListener("load",BSUtils.addTouchEvents,!1); BSUtils.bindClick=function(a,b){"string"==typeof a&&(a=document.getElementById(a));a.addEventListener("click",b,!0);a.addEventListener("touchend",b,!0)};Blockscad=Blockscad||{};Blockscad.Toolbox=Blockscad.Toolbox||{};BlocklyStorage=BlocklyStorage||{};Blockly=Blockly||{};BSUtils=BSUtils||{};Blockscad.version="1.0.0";Blockscad.offline=!1;var gCurrentFile=null,gProcessor=null,editor=null,gCurrentFiles=[],gMemFs=[],gMemFsCount=0,gMemFsTotal=0,gMemFsChanged=0,gRootFs=[],_includePath="./";Blockscad.drawAxes=1; -Blockscad.init=function(){function a(a,b){var k=a.target.files[0];if(k){if(b)var g=k.name.substr(0,k.name.lastIndexOf("("))||k.name,g=g.substr(0,k.name.lastIndexOf("."))||g,g=g.replace(/^\s+|\s+$/g,"");!Blockscad.offline&&b&&(Blockscad.Auth.isLoggedIn&&0$("#main").height()-$(".resizableDiv").height()&&$(".resizableDiv").height($("#main").height()-70);20>$("#main").width()-$(".resizableDiv").width()&& -$(".resizableDiv").width($("#main").width()-20);$(".resizableDiv").position({of:$("#main"),my:"right top",at:"right top",offset:"-12 -55"})},!1);Blockscad.workspace=Blockly.inject(document.getElementById("blocklyDiv"),{media:"blockly/media/",zoom:{enabled:!0,scaleSpeed:1.1,controls:!0},trashcan:!1,toolbox:Blockscad.Toolbox.other});BSUtils.loadBlocks("");"BlocklyStorage"in window&&BlocklyStorage.backupOnUnload();$(".resizableDiv").resizable({handles:"s,w,sw",resize:function(a,b){var k=$(window).height(); -gProcessor&&(k=gProcessor.viewerdiv.offsetHeight,gProcessor.viewer.rendered_resize(gProcessor.viewerdiv.offsetWidth,k));20>$("#main").width()-b.size.width&&(b.size.width=$("#main").width()-20);70>$("#main").height()-b.size.height&&(b.size.height=$("#main").height()-70);b.position.left=$(window).width()-(b.size.width+12);b.position.top=55}});Blockly.fireUiEvent(window,"resize");Blockscad.offline||Blockscad.Auth.init();BSUtils.bindClick("trashButton",function(){Blockscad.discard()});BSUtils.bindClick("renderButton", -Blockscad.doRender);BSUtils.bindClick("undoButton",Blockscad.onUndo);BSUtils.bindClick("redoButton",Blockscad.onRedo);$("#axesButton").click(function(){Blockscad.drawAxes=(Blockscad.drawAxes+1)%2;$("#axesButton").toggleClass("btn-pushed");gProcessor.viewer.onDraw()});$("#displayCode").click(function(){var a=document.getElementById("openScadPre"),b=Blockly.OpenSCAD.workspaceToCode(Blockscad.workspace);a.textContent=b;"function"==typeof prettyPrintOne&&(b=a.innerHTML,b=prettyPrintOne(b,"js"),a.innerHTML= -b);Blockly.fireUiEvent(window,"resize")});$("#renderButton").prop("disabled",!0);$("#throw-it-away").click(Blockscad.clearProject);$("#target").click(function(){alert("Handler for .click() called.")});Blockscad.readStlFile=function(a){var b=a.target.files[0];b?(a=new FileReader,a.onload=function(a){a=importSTL(a.target.result);var d=a[0];(a=a[1])||(a="blah");for(var p=b.name.substr(0,b.name.lastIndexOf("("))||b.name,p=p.substr(0,b.name.lastIndexOf("."))||p,l=p=p.replace(/^\s+|\s+$/g,""),u=1,n=0;Blockscad.csg_commands[l]&& -!n;)d!=Blockscad.csg_commands[l]?(l=p+"_"+u,u++):n=1;Blockscad.csg_commands[l]=d;Blockscad.csg_filename[l]=n?Blockscad.csg_filename[l]+(b.name+":::"):b.name+":::";Blockscad.csg_center[l]=a;Blockscad.currentInterestingBlock?(p=Blockscad.currentInterestingBlock.getField("STL_FILENAME"),d=Blockscad.currentInterestingBlock.getField("STL_BUTTON"),u=Blockscad.currentInterestingBlock.getField("STL_CONTENTS"),p.setText(b.name),p.setVisible(!0),d.setVisible(!1),u.setText(l),Blockscad.currentInterestingBlock.setCommentText(b.name+ -"\ncenter:("+a+")"),Blockscad.currentInterestingBlock=null):(l=Blockly.Xml.textToDom(''+b.name+'Browse'+l+""),l=Blockly.Xml.domToBlock(Blockscad.workspace,l.firstChild),d=l.getField("STL_BUTTON"),d.setVisible(!1),l.setCommentText(b.name+"\ncenter:("+a+")"),l.render())},a.readAsBinaryString(b),$("#importStl")[0].value= -"",$("#displayBlocks").click(),$("#renderButton").prop("disabled",!1)):alert("Failed to load file")};$("#file-menu").on("change","#loadLocal",function(b){a(b,!0)});$("#file-menu").on("change","#importLocal",function(b){a(b,!1)});$("#file-menu").on("change","#importStl",function(a){Blockscad.readStlFile(a)});gProcessor=new Blockscad.Processor(document.getElementById("renderDiv"));BSUtils.bindClick("viewReset",Blockscad.resetView);Blockscad.undo={blockList:[],oldBlockList:[],undoStack:[],redoStack:[], -current_xml:null,blockCount:0,yesthis:0,fieldChanging:0,blockIds:[],fieldValues:[],parentIds:[],oldBlockIds:[],oldFieldValues:[],oldParentIds:[],just_did_undo:0};Blockscad.workspace.addUndoListener(Blockscad.workspaceChanged);Blockscad.offline||Blockscad.Auth.checkForUser();$("#help-menu").on("click","#about",function(){$("#about-modal").modal("show")});$("#file-menu").on("click","#saveLocal",Blockscad.saveBlocksLocal)};document.write('