My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

configurator.js 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**
  2. * configurator.js
  3. *
  4. * Marlin Configuration Utility
  5. * - Web form for entering configuration options
  6. * - A reprap calculator to calculate movement values
  7. * - Uses HTML5 to generate downloadables in Javascript
  8. * - Reads and parses standard configuration files from local folders
  9. *
  10. * Supporting functions
  11. * - Parser to read Marlin Configuration.h and Configuration_adv.h files
  12. * - Utilities to replace values in configuration files
  13. */
  14. "use strict";
  15. $(function(){
  16. var marlin_config = 'config';
  17. // Extend String
  18. String.prototype.lpad = function(len, chr) {
  19. if (chr === undefined) { chr = ' '; }
  20. var s = this+'', need = len - s.length;
  21. if (need > 0) { s = new Array(need+1).join(chr) + s; }
  22. return s;
  23. };
  24. String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) : this; };
  25. String.prototype.zeroPad = function(len) { return this.prePad(len, '0'); };
  26. String.prototype.regEsc = function() { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
  27. String.prototype.lineCount = function() { return this.split(/\r?\n|\r/).length; };
  28. /**
  29. * selectField.addOptions takes an array or keyed object
  30. */
  31. $.fn.extend({
  32. addOptions: function(arrObj) {
  33. return this.each(function() {
  34. var sel = $(this);
  35. var isArr = Object.prototype.toString.call(arrObj) == "[object Array]";
  36. $.each(arrObj, function(k, v) {
  37. sel.append( $('<option>',{value:isArr?v:k}).text(v) );
  38. });
  39. });
  40. }
  41. });
  42. // The app is a singleton
  43. var configuratorApp = (function(){
  44. // private variables and functions go here
  45. var self,
  46. pi2 = Math.PI * 2,
  47. has_boards = false, has_config = false, has_config_adv = false,
  48. boards_file = 'boards.h',
  49. config_file = 'Configuration.h',
  50. config_adv_file = 'Configuration_adv.h',
  51. $config = $('#config_text'),
  52. $config_adv = $('#config_adv_text'),
  53. boards_list = {},
  54. therms_list = {},
  55. total_config_lines,
  56. total_config_adv_lines;
  57. // Return this anonymous object as configuratorApp
  58. return {
  59. my_public_var: 4,
  60. logging: 1,
  61. init: function() {
  62. self = this; // a 'this' for use when 'this' is something else
  63. // Set up the form
  64. this.initConfigForm();
  65. // Make tabs for the fieldsets
  66. var $fset = $('#config_form fieldset');
  67. var $tabs = $('<ul>',{class:'tabs'}), ind = 1;
  68. $('#config_form fieldset').each(function(){
  69. var tabID = 'TAB'+ind;
  70. $(this).addClass(tabID);
  71. var $leg = $(this).find('legend');
  72. var $link = $('<a>',{href:'#'+ind,id:tabID}).text($leg.text());
  73. $tabs.append($('<li>').append($link));
  74. $link.click(function(e){
  75. e.preventDefault;
  76. var ind = this.id;
  77. $tabs.find('.active').removeClass('active');
  78. $(this).addClass('active');
  79. $fset.hide();
  80. $fset.filter('.'+this.id).show();
  81. return false;
  82. });
  83. ind++;
  84. });
  85. $tabs.appendTo('#tabs');
  86. $('<br>',{class:'clear'}).appendTo('#tabs');
  87. $tabs.find('a:first').trigger('click');
  88. // Make a droppable file uploader, if possible
  89. var $uploader = $('#file-upload');
  90. var fileUploader = new BinaryFileUploader({
  91. element: $uploader[0],
  92. onFileLoad: function(file) { self.handleFileLoad(file, $uploader); }
  93. });
  94. if (!fileUploader.hasFileUploaderSupport())
  95. this.setMessage("Your browser doesn't support the file reading API.", 'error');
  96. // Read boards.h, Configuration.h, Configuration_adv.h
  97. var ajax_count = 0, success_count = 0;
  98. var loaded_items = {};
  99. var config_files = [boards_file, config_file, config_adv_file];
  100. $.each(config_files, function(i,fname){
  101. self.log("Loading " + fname + "...", 3);
  102. $.ajax({
  103. url: marlin_config+'/'+fname,
  104. type: 'GET',
  105. async: true,
  106. cache: false,
  107. success: function(txt) {
  108. self.log("Loaded " + fname + "...", 3);
  109. loaded_items[fname] = function(){ self.fileLoaded(fname, txt); };
  110. success_count++;
  111. },
  112. complete: function() {
  113. ajax_count++;
  114. if (ajax_count >= 3) {
  115. $.each(config_files, function(i,fname){ if (loaded_items[fname] !== undefined) loaded_items[fname](); });
  116. self.refreshConfigForm();
  117. if (success_count < ajax_count)
  118. self.setMessage('Unable to load configurations. Use the upload field instead.', 'error');
  119. }
  120. }
  121. });
  122. });
  123. },
  124. setMessage: function(msg,type) {
  125. if (msg) {
  126. if (type === undefined) type = 'message';
  127. var $err = $('<p class="'+type+'">'+msg+'</p>'), err = $err[0];
  128. $('#message').prepend($err);
  129. var baseColor = $err.css('color').replace(/rgba?\(([^),]+,[^),]+,[^),]+).*/, 'rgba($1,');
  130. var d = new Date();
  131. err.startTime = d.getTime();
  132. err.pulser = setInterval(function(){
  133. d = new Date();
  134. var pulse_time = (d.getTime() - err.startTime);
  135. $err.css({color:baseColor+(0.5+Math.sin(pulse_time/200)*0.4)+')'});
  136. if (pulse_time > 5000) {
  137. clearInterval(err.pulser);
  138. $err.remove();
  139. }
  140. }, 50);
  141. }
  142. else {
  143. $('#message p.error, #message p.warning').each(function() {
  144. if (this.pulser !== undefined && this.pulser)
  145. clearInterval(this.pulser);
  146. $(this).remove();
  147. });
  148. }
  149. },
  150. /**
  151. * Init the boards array from a boards.h file
  152. */
  153. initBoardsFromText: function(txt) {
  154. boards_list = {};
  155. var r, findDef = new RegExp('[ \\t]*#define[ \\t]+(BOARD_[\\w_]+)[ \\t]+(\\d+)[ \\t]*(//[ \\t]*)?(.+)?', 'gm');
  156. while((r = findDef.exec(txt)) !== null) {
  157. boards_list[r[1]] = r[2].prePad(3, '  ') + " — " + r[4].replace(/\).*/, ')');
  158. }
  159. this.log("Loaded boards", 3); this.log(boards_list, 3);
  160. has_boards = true;
  161. },
  162. /**
  163. * Init the thermistors array from the Configuration.h file
  164. */
  165. initThermistorsFromText: function(txt) {
  166. // Get all the thermistors and save them into an object
  167. var r, s, findDef = new RegExp('(//.*\n)+\\s+(#define[ \\t]+TEMP_SENSOR_0)', 'g');
  168. r = findDef.exec(txt);
  169. findDef = new RegExp('^//[ \\t]*([-\\d]+)[ \\t]+is[ \\t]+(.*)[ \\t]*$', 'gm');
  170. while((s = findDef.exec(r[0])) !== null) {
  171. therms_list[s[1]] = s[1].prePad(4, '  ') + " — " + s[2];
  172. }
  173. },
  174. /**
  175. * Handle a file being dropped on the file field
  176. */
  177. handleFileLoad: function(txt, $uploader) {
  178. txt += '';
  179. var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
  180. switch(filename) {
  181. case boards_file:
  182. case config_file:
  183. case config_adv_file:
  184. this.fileLoaded(filename, txt);
  185. break;
  186. default:
  187. this.log("Can't parse "+filename, 1);
  188. break;
  189. }
  190. },
  191. fileLoaded: function(filename, txt) {
  192. this.log("fileLoaded:"+filename,4);
  193. switch(filename) {
  194. case boards_file:
  195. this.initBoardsFromText(txt);
  196. $('#MOTHERBOARD').html('').addOptions(boards_list);
  197. if (has_config) this.initField('MOTHERBOARD');
  198. this.setMessage(boards_file+' loaded successfully.');
  199. break;
  200. case config_file:
  201. if (has_boards) {
  202. $config.text(txt);
  203. total_config_lines = txt.lineCount();
  204. this.initThermistorsFromText(txt);
  205. this.purgeDefineInfo(false);
  206. this.refreshConfigForm();
  207. this.setMessage(config_file+' loaded successfully.');
  208. has_config = true;
  209. }
  210. else {
  211. this.setMessage("Upload a " + boards_file + " file first!", 'error');
  212. }
  213. break;
  214. case config_adv_file:
  215. if (has_config) {
  216. $config_adv.text(txt);
  217. total_config_adv_lines = txt.lineCount();
  218. this.purgeDefineInfo(true);
  219. this.refreshConfigForm();
  220. this.setMessage(config_adv_file+' loaded successfully.');
  221. has_config_adv = true;
  222. }
  223. else {
  224. this.setMessage("Upload a " + config_file + " file first!", 'error');
  225. }
  226. break;
  227. }
  228. },
  229. /**
  230. * Add enhancements to the form
  231. */
  232. initConfigForm: function() {
  233. // Modify form fields and make the form responsive.
  234. // As values change on the form, we could update the
  235. // contents of text areas containing the configs, for
  236. // example.
  237. // while(!$config_adv.text() == null) {}
  238. // while(!$config.text() == null) {}
  239. // Go through all form items with names
  240. $('#config_form').find('[name]').each(function() {
  241. // Set its id to its name
  242. var name = $(this).attr('name');
  243. $(this).attr({id: name});
  244. // Attach its label sibling
  245. var $label = $(this).prev();
  246. if ($label[0].tagName == 'LABEL') {
  247. $label.attr('for',name);
  248. }
  249. });
  250. // Get all 'switchable' class items and add a checkbox
  251. $('#config_form .switchable').each(function(){
  252. $(this).after(
  253. $('<input>',{type:'checkbox',value:'1',class:'enabler'}).prop('checked',true)
  254. .attr('id',this.id + '-switch')
  255. .change(self.handleSwitch)
  256. );
  257. });
  258. // Add options to the popup menus
  259. $('#SERIAL_PORT').addOptions([0,1,2,3,4,5,6,7]);
  260. $('#BAUDRATE').addOptions([2400,9600,19200,38400,57600,115200,250000]);
  261. $('#EXTRUDERS').addOptions([1,2,3,4]);
  262. $('#POWER_SUPPLY').addOptions({'1':'ATX','2':'Xbox 360'});
  263. // Replace the Serial popup menu with a stepper control
  264. $('#serial_stepper').jstepper({
  265. min: 0,
  266. max: 3,
  267. val: $('#SERIAL_PORT').val(),
  268. arrowWidth: '18px',
  269. arrowHeight: '15px',
  270. color: '#FFF',
  271. acolor: '#F70',
  272. hcolor: '#FF0',
  273. id: 'select-me',
  274. textStyle: {width:'1.5em',fontSize:'120%',textAlign:'center'},
  275. onChange: function(v) { $('#SERIAL_PORT').val(v).trigger('change'); }
  276. });
  277. },
  278. refreshConfigForm: function() {
  279. /**
  280. * For now I'm manually creating these references
  281. * but I should be able to parse Configuration.h
  282. * and iterate the #defines.
  283. *
  284. * For any #ifdef blocks I can create field groups
  285. * which can be dimmed together when the option
  286. * is disabled.
  287. *
  288. * Then we only need to specify exceptions to
  289. * standard behavior, (which is to add a text field)
  290. */
  291. this.initField('SERIAL_PORT');
  292. this.initField('BAUDRATE');
  293. this.initField('BTENABLED');
  294. $('#MOTHERBOARD').html('').addOptions(boards_list);
  295. this.initField('MOTHERBOARD');
  296. this.initField('CUSTOM_MENDEL_NAME');
  297. this.initField('MACHINE_UUID');
  298. this.initField('EXTRUDERS');
  299. this.initField('POWER_SUPPLY');
  300. this.initField('PS_DEFAULT_OFF');
  301. $('#TEMP_SENSOR_0, #TEMP_SENSOR_1, #TEMP_SENSOR_2, #TEMP_SENSOR_BED').html('').addOptions(therms_list);
  302. this.initField('TEMP_SENSOR_0');
  303. this.initField('TEMP_SENSOR_1');
  304. this.initField('TEMP_SENSOR_2');
  305. this.initField('TEMP_SENSOR_BED');
  306. this.initField('TEMP_SENSOR_1_AS_REDUNDANT');
  307. this.initField('MAX_REDUNDANT_TEMP_SENSOR_DIFF');
  308. this.initField('TEMP_RESIDENCY_TIME');
  309. },
  310. setTextAndHighlight: function($field, txt, name) {
  311. var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
  312. if (inf == null) return;
  313. },
  314. /**
  315. * Make a field responsive and initialize its defineInfo
  316. */
  317. initField: function(name, adv) {
  318. this.log("initField:"+name,4);
  319. var $elm = $('#'+name), elm = $elm[0];
  320. if (elm.defineInfo == null) {
  321. elm.defineInfo = this.getDefineInfo(name, adv);
  322. $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
  323. }
  324. this.setFieldFromDefine(name);
  325. },
  326. /**
  327. * Handle any value field being changed
  328. */
  329. handleChange: function() { self.updateDefineFromField(this.id); },
  330. /**
  331. * Handle a switch checkbox being changed
  332. */
  333. handleSwitch: function() {
  334. var $elm = $(this), $prev = $elm.prev();
  335. var on = $elm.prop('checked') || false;
  336. $prev.attr('disabled', !on);
  337. self.setDefineEnabled($prev[0].id, on);
  338. },
  339. /**
  340. * Get the current value of a #define (from the config text)
  341. */
  342. defineValue: function(name) {
  343. this.log('defineValue:'+name,4);
  344. var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
  345. if (inf == null) return 'n/a';
  346. var result = inf.regex.exec($(inf.field).text());
  347. this.log(result,2);
  348. return inf.type == 'switch' ? result[inf.val_i] != '//' : result[inf.val_i];
  349. },
  350. /**
  351. * Get the current enabled state of a #define (from the config text)
  352. */
  353. defineIsEnabled: function(name) {
  354. this.log('defineIsEnabled:'+name,4);
  355. var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
  356. if (inf == null) return false;
  357. var result = inf.regex.exec($(inf.field).text());
  358. this.log(result,2);
  359. var on = result !== null ? result[1].trim() != '//' : true;
  360. this.log(name + ' = ' + on, 2);
  361. return on;
  362. },
  363. /**
  364. * Set a #define enabled or disabled by altering the config text
  365. */
  366. setDefineEnabled: function(name, val) {
  367. this.log('setDefineEnabled:'+name,4);
  368. var $elm = $('#'+name), inf = $elm[0].defineInfo;
  369. if (inf == null) return;
  370. var slash = val ? '' : '//';
  371. var newline = inf.line
  372. .replace(/^([ \t]*)(\/\/)([ \t]*)/, '$1$3') // remove slashes
  373. .replace(inf.pre+inf.define, inf.pre+slash+inf.define); // add them back
  374. this.setDefineLine(name, newline);
  375. },
  376. /**
  377. * Update a #define (from the form) by altering the config text
  378. */
  379. updateDefineFromField: function(name) {
  380. this.log('updateDefineFromField:'+name,4);
  381. var $elm = $('#'+name), inf = $elm[0].defineInfo;
  382. if (inf == null) return;
  383. var isCheck = $elm.attr('type') == 'checkbox',
  384. val = isCheck ? $elm.prop('checked') : $elm.val();
  385. var newline;
  386. switch(inf.type) {
  387. case 'switch':
  388. var slash = val ? '' : '//';
  389. newline = inf.line.replace(inf.repl, '$1'+slash+'$3');
  390. break;
  391. case 'quoted':
  392. case 'plain':
  393. if (isCheck)
  394. this.setMessage(name + ' should not be a checkbox!', 'error');
  395. else
  396. newline = inf.line.replace(inf.repl, '$1'+val.replace('$','\\$')+'$3');
  397. break;
  398. }
  399. this.setDefineLine(name, newline);
  400. },
  401. /**
  402. * Set the define's line in the text to a new line,
  403. * then update, highlight, and scroll to the line
  404. */
  405. setDefineLine: function(name, newline) {
  406. var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
  407. var $c = $(inf.field), txt = $c.text();
  408. var hilite_token = '[HIGHLIGHTER-TOKEN]';
  409. txt = txt.replace(inf.line, hilite_token + newline);
  410. inf.line = newline;
  411. this.log(newline, 2);
  412. // Convert txt into HTML before storing
  413. var html = $('<div/>').text(txt).html().replace(hilite_token, '<span></span>');
  414. // Set the final text including the highlighter
  415. $c.html(html);
  416. // Scroll to reveal the define
  417. this.scrollToDefine(name);
  418. },
  419. /**
  420. * Scroll a pre box to reveal a #define
  421. */
  422. scrollToDefine: function(name, always) {
  423. this.log('scrollToDefine:'+name,4);
  424. var $elm = $('#'+name), inf = $elm[0].defineInfo, $c = $(inf.field);
  425. // Scroll to the altered text if it isn't visible
  426. var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
  427. textScrollY = inf.lineNum * scrollHeight/(inf.adv ? total_config_adv_lines : total_config_lines) - halfHeight;
  428. if (textScrollY < 0)
  429. textScrollY = 0;
  430. else if (textScrollY > scrollHeight)
  431. textScrollY = scrollHeight - 1;
  432. if (always == true || Math.abs($c.prop('scrollTop') - textScrollY) > halfHeight)
  433. $c.animate({ scrollTop: textScrollY < 0 ? 0 : textScrollY });
  434. },
  435. /**
  436. * Set a form field to the current #define value in the config text
  437. */
  438. setFieldFromDefine: function(name) {
  439. var $elm = $('#'+name), val = this.defineValue(name);
  440. this.log('setFieldFromDefine:' + name + ' to ' + val, 4);
  441. // Set the field value
  442. $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
  443. // If the item has a checkbox then set enabled state too
  444. var $cb = $('#'+name+'-switch');
  445. if ($cb.length) {
  446. var on = self.defineIsEnabled(name);
  447. $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
  448. $cb.prop('checked', on); // check/uncheck the checkbox
  449. }
  450. },
  451. /**
  452. * Purge #define information for one of the config files
  453. */
  454. purgeDefineInfo: function(adv) {
  455. if (adv === undefined) adv = false;
  456. $('[name]').each(function() {
  457. var inf = this.defineInfo;
  458. if (inf && adv === inf.adv) $(this).removeProp('defineInfo');
  459. });
  460. },
  461. /**
  462. * Update #define information for one of the config files
  463. */
  464. refreshDefineInfo: function(adv) {
  465. if (adv === undefined) adv = false;
  466. $('[name]').each(function() {
  467. var inf = this.defineInfo;
  468. if (inf && adv == inf.adv) this.defineInfo = self.getDefineInfo(this.id, adv);
  469. });
  470. },
  471. /**
  472. * Get information about a #define from configuration file text:
  473. *
  474. * Pre-examine the #define for its prefix, value position, suffix, etc.
  475. * Construct a regex for the #define to quickly find (and replace) values.
  476. * Store the existing #define line as the key to finding it later.
  477. * Determine the line number of the #define so it can be scrolled to.
  478. */
  479. getDefineInfo: function(name, adv) {
  480. if (adv === undefined) adv = false;
  481. this.log('getDefineInfo:'+name,4);
  482. var $elm = $('#'+name), elm = $elm[0];
  483. var $c = adv ? $config_adv : $config;
  484. // a switch line with no value
  485. var findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm');
  486. var result = findDef.exec($c.text());
  487. var info = { type:0, adv:adv, field:$c[0], val_i: 2 };
  488. if (result !== null) {
  489. $.extend(info, {
  490. val_i: 1,
  491. type: 'switch',
  492. line: result[0], // whole line
  493. pre: result[1] === undefined ? '' : result[1].replace('//',''),
  494. define: result[2],
  495. post: result[3] === undefined ? '' : result[3]
  496. });
  497. info.regex = new RegExp('( *//)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
  498. info.repl = new RegExp('( *)(\/\/)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
  499. }
  500. else {
  501. // a define with quotes
  502. findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
  503. result = findDef.exec($c.text());
  504. if (result !== null) {
  505. $.extend(info, {
  506. type: 'quoted',
  507. line: result[0],
  508. pre: result[1] === undefined ? '' : result[1].replace('//',''),
  509. define: result[2],
  510. post: result[4] === undefined ? '' : result[4]
  511. });
  512. info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
  513. info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
  514. }
  515. else {
  516. // a define with no quotes
  517. findDef = new RegExp('^( *//)?( *#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
  518. result = findDef.exec($c.text());
  519. if (result !== null) {
  520. $.extend(info, {
  521. type: 'plain',
  522. line: result[0],
  523. pre: result[1] === undefined ? '' : result[1].replace('//',''),
  524. define: result[2],
  525. post: result[4] === undefined ? '' : result[4]
  526. });
  527. info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
  528. info.repl = new RegExp('(( *//)? *' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
  529. }
  530. }
  531. }
  532. if (info.type) {
  533. info.lineNum = this.getLineNumberOfText(info.line, $c.text());
  534. this.log(info,2);
  535. }
  536. else
  537. info = null;
  538. return info;
  539. },
  540. /**
  541. * Count the number of lines before a match, return -1 on fail
  542. */
  543. getLineNumberOfText: function(line, txt) {
  544. var pos = txt.indexOf(line);
  545. return (pos < 0) ? pos : txt.substr(0, pos).lineCount();
  546. },
  547. log: function(o,l) {
  548. if (l === undefined) l = 0;
  549. if (this.logging>=l*1) console.log(o);
  550. },
  551. logOnce: function(o) {
  552. if (o.didLogThisObject === undefined) {
  553. this.log(o);
  554. o.didLogThisObject = true;
  555. }
  556. },
  557. EOF: null
  558. };
  559. })();
  560. // Typically the app would be in its own file, but this would be here
  561. configuratorApp.init();
  562. });