Marlin Configurator 0.1a
+Marlin Configurator
Enter values in the form, get a Marlin configuration.
Will include a drop-down of known configurations.
'+msg+'
'), err = $err[0]; $('#message').prepend($err); var baseColor = $err.css('color').replace(/rgba?\(([^),]+,[^),]+,[^),]+).*/, 'rgba($1,'); @@ -155,7 +155,7 @@ var configuratorApp = (function(){ } else { $('#message p.error, #message p.warning').each(function() { - if (typeof this.pulser != 'undefined' && this.pulser) + if (this.pulser !== undefined && this.pulser) clearInterval(this.pulser); $(this).remove(); }); @@ -440,30 +440,16 @@ var configuratorApp = (function(){ switch(inf.type) { case 'switch': var slash = val ? '' : '//'; - newline = (inf.pre + slash + inf.define + inf.post); + newline = inf.line.replace(inf.repl, '$1'+slash+'$3'); break; case 'quoted': - if (isCheck) { - this.log(name + ' should not be a checkbox', 1); - var slash = val ? '' : '//'; - newline = (inf.pre + slash + inf.define + '"'+val+'"' + inf.post); - } - else { - newline = inf.pre + inf.define + '"'+val+'"' + inf.post; - } - break; case 'plain': - if (isCheck) { - this.log(name + ' should not be a checkbox', 1); - var slash = val ? '' : '//'; - newline = (inf.pre + slash + inf.define + val + inf.post); - } - else { - newline = inf.pre + inf.define + val + inf.post; - } + if (isCheck) + this.setMessage(name + ' should not be a checkbox!', 'error'); + else + newline = inf.line.replace(inf.repl, '$1'+val.replace('$','\\$')+'$3'); break; } - this.setDefineLine(name, newline); }, @@ -536,7 +522,7 @@ var configuratorApp = (function(){ * Purge #define information for one of the config files */ purgeDefineInfo: function(adv) { - if (typeof adv == 'undefined') adv = false; + if (adv === undefined) adv = false; $('[defineInfo]').each(function() { if (adv === this.defineInfo.adv) $(this).removeProp('defineInfo'); }); @@ -546,7 +532,7 @@ var configuratorApp = (function(){ * Update #define information for one of the config files */ refreshDefineInfo: function(adv) { - if (typeof adv == 'undefined') adv = false; + if (adv === undefined) adv = false; $('[defineInfo]').each(function() { if (adv == this.defineInfo.adv) this.defineInfo = self.getDefineInfo(this.id, adv); }); @@ -561,7 +547,7 @@ var configuratorApp = (function(){ * Determine the line number of the #define so it can be scrolled to. */ getDefineInfo: function(name, adv) { - if (typeof adv == 'undefined') adv = false; + if (adv === undefined) adv = false; this.log('getDefineInfo:'+name,4); var $elm = $('#'+name), elm = $elm[0]; var $c = adv ? $config_adv : $config; @@ -569,63 +555,66 @@ var configuratorApp = (function(){ // a switch line with no value var findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm'); var result = findDef.exec($c.text()); + var info = { type:0, adv:adv, field:$c[0], val_i: 2 }; if (result !== null) { - var info = { - type:'switch', adv:adv, field:$c[0], val_i: 1, - line: result[0], // whole line - pre: result[1] === undefined ? '' : result[1].replace('//',''), + $.extend(info, { + val_i: 1, + type: 'switch', + line: result[0], // whole line + pre: result[1] === undefined ? '' : result[1].replace('//',''), define: result[2], - post: result[3] === undefined ? '' : result[3] - }; - info.repl = info.regex = new RegExp('(.*//)?(.*' + info.define.regEsc() + info.post.regEsc() + ')', 'm'); - info.lineNum = this.getLineInText(info.line, $c.text()); - this.log(info,2); - return info; + post: result[3] === undefined ? '' : result[3] + }); + info.regex = new RegExp('( *//)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm'); + info.repl = new RegExp('( *)(\/\/)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm'); + } + else { + // a define with quotes + findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm'); + result = findDef.exec($c.text()); + if (result !== null) { + $.extend(info, { + type: 'quoted', + line: result[0], + pre: result[1] === undefined ? '' : result[1].replace('//',''), + define: result[2], + post: result[4] === undefined ? '' : result[4] + }); + info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm'); + info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm'); + } + else { + // a define with no quotes + findDef = new RegExp('^( *//)?( *#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm'); + result = findDef.exec($c.text()); + if (result !== null) { + $.extend(info, { + type: 'plain', + line: result[0], + pre: result[1] === undefined ? '' : result[1].replace('//',''), + define: result[2], + post: result[4] === undefined ? '' : result[4] + }); + info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm'); + info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm'); + } + } } - // a define with quotes - findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm'); - result = findDef.exec($c.text()); - if (result !== null) { - var info = { - type:'quoted', adv:adv, field:$c[0], val_i: 2, - line: result[0], - pre: result[1] === undefined ? '' : result[1].replace('//',''), - define: result[2], - post: result[4] === undefined ? '' : result[4] - }; - info.regex = new RegExp('(.*//)?.*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm'); - info.repl = new RegExp('((.*//)?.*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm'); - info.lineNum = this.getLineInText(info.line, $c.text()); + if (info.type) { + info.lineNum = this.getLineNumberOfText(info.line, $c.text()); this.log(info,2); - return info; } + else + info = null; - // a define with no quotes - findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm'); - result = findDef.exec($c.text()); - if (result !== null) { - var info = { - type:'plain', adv:adv, field:$c[0], val_i: 2, - line: result[0], - pre: result[1] === undefined ? '' : result[1].replace('//',''), - define: result[2], - post: result[4] === undefined ? '' : result[4] - }; - info.regex = new RegExp('(.*//)?.*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm'); - info.repl = new RegExp('((.*//)?.*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm'); - info.lineNum = this.getLineInText(info.line, $c.text()); - this.log(info,2); - return info; - } - - return null; + return info; }, /** * Count the number of lines before a match, return -1 on fail */ - getLineInText: function(line, txt) { + getLineNumberOfText: function(line, txt) { var pos = txt.indexOf(line); return (pos < 0) ? pos : txt.substr(0, pos).lineCount(); }, @@ -636,7 +625,7 @@ var configuratorApp = (function(){ }, logOnce: function(o) { - if (typeof o.didLogThisObject === 'undefined') { + if (o.didLogThisObject === undefined) { this.log(o); o.didLogThisObject = true; }