Skip to content

Commit

Permalink
Did some cleanup of semicolons and stuff. jshint is interesting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Minuti committed Sep 2, 2015
1 parent 769afae commit 44c0206
Show file tree
Hide file tree
Showing 8 changed files with 236 additions and 221 deletions.
5 changes: 5 additions & 0 deletions .jshintrc
@@ -0,0 +1,5 @@
{
"browser": true,
"devel": true,
"jquery": true
}
98 changes: 51 additions & 47 deletions blockscad/blockscad.js
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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 = '';
Expand All @@ -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


Expand Down Expand Up @@ -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() {
Expand All @@ -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() {

Expand All @@ -505,7 +507,7 @@ Blockscad.clearProject = function() {
$('#project-name').val('Untitled');
$('#projectView').hide();
$('#editView').show();
}
};



Expand All @@ -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() {
Expand All @@ -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++;
}
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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");
Expand Down Expand Up @@ -846,7 +849,7 @@ Blockscad.isRealChange = function() {
}

return false;
}// end Blockscad.isRealChange()
};// end Blockscad.isRealChange()

Blockscad.workspaceChanged = function () {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1022,7 +1025,7 @@ Blockscad.onUndo = function() {


}
} // end onUndo()
}; // end onUndo()

Blockscad.onRedo = function() {
//console.log("Redo button activated!\n");
Expand All @@ -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() {
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -1131,7 +1134,7 @@ Blockscad.stackIsShape = function(block) {
return true;
}
return false;
}
};

// Blockscad.assignBlockTypes
// input: array of blocks whose trees need typing
Expand Down Expand Up @@ -1182,15 +1185,15 @@ 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')
return true;
block = block.parentBlock_;
} while (block);
return false;
}
};


// -- BEGIN OPENJSCAD STUFF --
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -1273,4 +1277,4 @@ Blockscad.saveBlocksLocal = function() {
else {
alert("SAVE FAILED. Please give your project a name, then try again.");
}
}
};

0 comments on commit 44c0206

Please sign in to comment.