Browse Source

Optimize initial loading, code cleanup

Scott Lahteine 9 years ago
parent
commit
f2710e11d1
2 changed files with 120 additions and 119 deletions
  1. 6
    7
      Marlin/configurator/css/configurator.css
  2. 114
    112
      Marlin/configurator/js/configurator.js

+ 6
- 7
Marlin/configurator/css/configurator.css View File

91
 	margin-right: -450px;
91
 	margin-right: -450px;
92
 	text-align: right;
92
 	text-align: right;
93
 	}
93
 	}
94
-label.blocked, span.label.blocked { color: #AAA; }
94
+label.blocked, label.added.blocked, label.added.blocked.sublabel { color: #AAA; }
95
 
95
 
96
-span.label {
97
-	display: block;
98
-	float: left;
96
+label.added.sublabel {
97
+	width: auto;
99
 	margin: 11px -2.5em 0 1em;
98
 	margin: 11px -2.5em 0 1em;
100
-	padding-right: 3em;
99
+	padding: 0 3em 0 0;
101
 	font-style: italic;
100
 	font-style: italic;
102
 	color: #444;
101
 	color: #444;
103
 	}
102
 	}
104
-label+span.label {
103
+label+label.added.sublabel {
105
 	margin-left: 0;
104
 	margin-left: 0;
106
 	}
105
 	}
107
 
106
 
341
 
340
 
342
 }
341
 }
343
 
342
 
344
-/*span.label.blocked, .blocked { display: none; }*/
343
+/*label.blocked, .blocked { display: none; }*/
345
 
344
 

+ 114
- 112
Marlin/configurator/js/configurator.js View File

146
       $tooltip = $('#tooltip'),
146
       $tooltip = $('#tooltip'),
147
       $cfg = $('#config_text'), $adv = $('#config_adv_text'),
147
       $cfg = $('#config_text'), $adv = $('#config_adv_text'),
148
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
148
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
149
+      config_file_list = [ boards_file, config_file, config_adv_file ],
150
+      config_list = [ $config, $config_adv ],
149
       define_info = {},
151
       define_info = {},
150
       define_list = [[],[]],
152
       define_list = [[],[]],
151
       define_groups = [{},{}],
153
       define_groups = [{},{}],
199
       // Read boards.h, Configuration.h, Configuration_adv.h
201
       // Read boards.h, Configuration.h, Configuration_adv.h
200
       var ajax_count = 0, success_count = 0;
202
       var ajax_count = 0, success_count = 0;
201
       var loaded_items = {};
203
       var loaded_items = {};
202
-      var config_files = [boards_file, config_file, config_adv_file];
203
       var isGithub = config.type == 'github';
204
       var isGithub = config.type == 'github';
204
       var rateLimit = 0;
205
       var rateLimit = 0;
205
-      $.each(config_files, function(i,fname){
206
+      $.each(config_file_list, function(i,fname){
206
         var url = config_path(fname);
207
         var url = config_path(fname);
207
         $.ajax({
208
         $.ajax({
208
           url: url,
209
           url: url,
215
             if (req.status == 200) {
216
             if (req.status == 200) {
216
               if (typeof req.responseText === 'string') {
217
               if (typeof req.responseText === 'string') {
217
                 var txt = req.responseText;
218
                 var txt = req.responseText;
218
-                loaded_items[fname] = function(){ self.fileLoaded(fname, txt); };
219
+                loaded_items[fname] = function(){ self.fileLoaded(fname, txt, true); };
219
                 success_count++;
220
                 success_count++;
220
                 // self.setMessage('The request for "'+fname+'" may be malformed.', 'error');
221
                 // self.setMessage('The request for "'+fname+'" may be malformed.', 'error');
221
               }
222
               }
236
                   timeLeft: Math.floor(txt.meta['X-RateLimit-Reset'] - Date.now()/1000),
237
                   timeLeft: Math.floor(txt.meta['X-RateLimit-Reset'] - Date.now()/1000),
237
                 };
238
                 };
238
               }
239
               }
239
-              loaded_items[fname] = function(){ self.fileLoaded(fname, isGithub ? atob(txt.data.content.replace(/\s/g, '')) : txt); };
240
+              loaded_items[fname] = function(){ self.fileLoaded(fname, isGithub ? atob(txt.data.content.replace(/\s/g, '')) : txt, true); };
240
               success_count++;
241
               success_count++;
241
             }
242
             }
242
           },
243
           },
243
           complete: function() {
244
           complete: function() {
244
             ajax_count++;
245
             ajax_count++;
245
-            if (ajax_count >= config_files.length) {
246
+            if (ajax_count >= config_file_list.length) {
246
               // If not all files loaded set an error
247
               // If not all files loaded set an error
247
               if (success_count < ajax_count)
248
               if (success_count < ajax_count)
248
                 self.setMessage('Unable to load configurations. Try the upload field.', 'error');
249
                 self.setMessage('Unable to load configurations. Try the upload field.', 'error');
260
                 }
261
                 }
261
               }
262
               }
262
               // Post-process all the loaded files
263
               // Post-process all the loaded files
263
-              $.each(config_files, function(){ if (loaded_items[this]) loaded_items[this](); });
264
+              $.each(config_file_list, function(){ if (loaded_items[this]) loaded_items[this](); });
264
             }
265
             }
265
           }
266
           }
266
         });
267
         });
270
     /**
271
     /**
271
      * Make a download link visible and active
272
      * Make a download link visible and active
272
      */
273
      */
273
-    activateDownloadLink: function(adv) {
274
-      var $c = adv ? $config_adv : $config, txt = $c.text();
275
-      var filename = (adv ? config_adv_file : config_file);
274
+    activateDownloadLink: function(cindex) {
275
+      var filename = config_file_list[cindex+1];
276
+      var $c = config_list[cindex], txt = $c.text();
276
       $c.prevAll('.download:first')
277
       $c.prevAll('.download:first')
277
         .unbind('mouseover click')
278
         .unbind('mouseover click')
278
         .mouseover(function() {
279
         .mouseover(function() {
303
         .click(function(){
304
         .click(function(){
304
           var $button = $(this);
305
           var $button = $(this);
305
           var zip = new JSZip();
306
           var zip = new JSZip();
306
-          zip.file(config_file, $config.text());
307
-          zip.file(config_adv_file, $config_adv.text());
307
+          for (var e in [0,1]) zip.file(config_file_list[e+1], config_list[e].text());
308
           var zipped = zip.generate({type:'blob'});
308
           var zipped = zip.generate({type:'blob'});
309
           saveAs(zipped, $button.attr('download'));
309
           saveAs(zipped, $button.attr('download'));
310
           return false;
310
           return false;
341
     /**
341
     /**
342
      * Get all the unique define names
342
      * Get all the unique define names
343
      */
343
      */
344
-    initDefineList: function(index, txt) {
344
+    initDefineList: function(cindex) {
345
       var section = 'hidden',
345
       var section = 'hidden',
346
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
346
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'],
347
           define_sect = {},
347
           define_sect = {},
348
+          txt = config_list[cindex].text(),
348
           r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
349
           r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm');
349
       while((r = findDef.exec(txt)) !== null) {
350
       while((r = findDef.exec(txt)) !== null) {
350
         var name = r[2];
351
         var name = r[2];
353
         else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect))
354
         else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect))
354
           define_sect[name] = section;
355
           define_sect[name] = section;
355
       }
356
       }
356
-      define_list[index] = Object.keys(define_sect);
357
+      define_list[cindex] = Object.keys(define_sect);
357
       $.extend(define_section, define_sect);
358
       $.extend(define_section, define_sect);
358
-      this.log(define_list[index], 2);
359
+      this.log(define_list[cindex], 2);
359
     },
360
     },
360
 
361
 
361
     /**
362
     /**
362
      * Find the defines in one of the configs that are just variants.
363
      * Find the defines in one of the configs that are just variants.
363
      * Group them together for form-building and other uses.
364
      * Group them together for form-building and other uses.
364
      */
365
      */
365
-    refreshDefineGroups: function(index) {
366
+    refreshDefineGroups: function(cindex) {
366
       var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
367
       var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
367
       var match_prev, patt, title, nameList, groups = {}, match_section;
368
       var match_prev, patt, title, nameList, groups = {}, match_section;
368
-      $.each(define_list[index], function() {
369
+      $.each(define_list[cindex], function(i, name) {
369
         if (match_prev) {
370
         if (match_prev) {
370
-          if (match_prev.exec(this) && define_section[this] == match_section) {
371
-            nameList.push(this);
371
+          if (match_prev.exec(name) && define_section[name] == match_section) {
372
+            nameList.push(name);
372
           }
373
           }
373
           else {
374
           else {
374
             if (nameList.length > 1) {
375
             if (nameList.length > 1) {
375
-              $.each(nameList, function(){
376
-                groups[this] = {
376
+              $.each(nameList, function(i,n){
377
+                groups[n] = {
377
                   pattern: patt,
378
                   pattern: patt,
378
                   title: title,
379
                   title: title,
379
                   count: nameList.length
380
                   count: nameList.length
384
           }
385
           }
385
         }
386
         }
386
         if (!match_prev) {
387
         if (!match_prev) {
387
-          var r = findDef.exec(this);
388
+          var r = findDef.exec(name);
388
           if (r != null) {
389
           if (r != null) {
389
             switch(r[2]) {
390
             switch(r[2]) {
390
               case '0':
391
               case '0':
425
               patt = '^' + r[1] + patt + r[7] + '$';
426
               patt = '^' + r[1] + patt + r[7] + '$';
426
               title = r[1] + title + r[7];
427
               title = r[1] + title + r[7];
427
               match_prev = new RegExp(patt);
428
               match_prev = new RegExp(patt);
428
-              match_section = define_section[this];
429
-              nameList = [ this ];
429
+              match_section = define_section[name];
430
+              nameList = [ name ];
430
             }
431
             }
431
           }
432
           }
432
         }
433
         }
433
       });
434
       });
434
-      define_groups[index] = groups;
435
+      define_groups[cindex] = groups;
435
     },
436
     },
436
 
437
 
437
     /**
438
     /**
442
     initDependentGroups: function() {
443
     initDependentGroups: function() {
443
       var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
444
       var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
444
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
445
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
445
-      $.each([$config, $config_adv], function(i, $v) {
446
+      $.each(config_list, function(i, $v) {
446
         var ifStack = [];
447
         var ifStack = [];
447
         var r, txt = $v.text();
448
         var r, txt = $v.text();
448
         while((r = findBlock.exec(txt)) !== null) {
449
         while((r = findBlock.exec(txt)) !== null) {
481
                 var cond = c[0], line = c[1];
482
                 var cond = c[0], line = c[1];
482
                 self.log("pop " + c[0], 4);
483
                 self.log("pop " + c[0], 4);
483
                 if (dependentGroups[cond] === undefined) dependentGroups[cond] = [];
484
                 if (dependentGroups[cond] === undefined) dependentGroups[cond] = [];
484
-                dependentGroups[cond].push({adv:i,start:line,end:lineNum});
485
+                dependentGroups[cond].push({cindex:i,start:line,end:lineNum});
485
                 if (r[1] == 'else') {
486
                 if (r[1] == 'else') {
486
                   // Reverse the condition
487
                   // Reverse the condition
487
                   cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
488
                   cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond);
504
      */
505
      */
505
     initDefineInfo: function() {
506
     initDefineInfo: function() {
506
       $.each(define_list, function(e,def_list){
507
       $.each(define_list, function(e,def_list){
507
-        var adv = e == 1;
508
-        $.each(def_list, function(i,name) {
509
-          define_info[name] = self.getDefineInfo(name, adv);
508
+        $.each(def_list, function(i, name) {
509
+          define_info[name] = self.getDefineInfo(name, e);
510
         });
510
         });
511
       });
511
       });
512
     },
512
     },
515
      * Create fields for defines in a config that have none
515
      * Create fields for defines in a config that have none
516
      * Use define_groups data to group fields together
516
      * Use define_groups data to group fields together
517
      */
517
      */
518
-    createFieldsForDefines: function(index) {
519
-      var n = 0, fail_list = [];
520
-      var grouping = false, group_pattern, group_regex, subitem, group_section, group_class;
521
-      $.each(define_list[index], function(i,name) {
518
+    createFieldsForDefines: function(cindex) {
519
+      // var n = 0;
520
+      var grouping = false, group = define_groups[cindex],
521
+          g_pattern, g_regex, g_subitem, g_section, g_class,
522
+          fail_list = [];
523
+      $.each(define_list[cindex], function(i, name) {
522
         var section = define_section[name];
524
         var section = define_section[name];
523
         if (section != 'hidden' && !$('#'+name).length) {
525
         if (section != 'hidden' && !$('#'+name).length) {
524
           var inf = define_info[name];
526
           var inf = define_info[name];
529
 
531
 
530
             // Is this field in a sequence?
532
             // Is this field in a sequence?
531
             // Then see if it's the second or after
533
             // Then see if it's the second or after
532
-            var group = define_groups[index];
533
             if (grouping) {
534
             if (grouping) {
534
-              if (name in group && group_pattern == group[name].pattern && group_section == section) {
535
-                subitem = true;
536
-                sublabel = group_regex.exec(name)[1];
535
+              if (name in group && g_pattern == group[name].pattern && g_section == section) {
536
+                g_subitem = true;
537
+                sublabel = g_regex.exec(name)[1];
537
               }
538
               }
538
               else
539
               else
539
                 grouping = false;
540
                 grouping = false;
541
             // Start grouping?
542
             // Start grouping?
542
             if (!grouping && name in group) {
543
             if (!grouping && name in group) {
543
               grouping = true;
544
               grouping = true;
544
-              subitem = false;
545
+              g_subitem = false;
545
               var grp = group[name];
546
               var grp = group[name];
546
-              group_pattern = grp.pattern;
547
-              group_class = 'one_of_' + grp.count;
547
+              g_pattern = grp.pattern;
548
+              g_class = 'one_of_' + grp.count;
548
               label_text = grp.title;
549
               label_text = grp.title;
549
-              group_regex = new RegExp(group_pattern);
550
-              group_section = section;
551
-              sublabel = group_regex.exec(name)[1];
550
+              g_regex = new RegExp(g_pattern);
551
+              g_section = section;
552
+              sublabel = g_regex.exec(name)[1];
552
             }
553
             }
553
 
554
 
554
             var $ff = $('#'+section), $newfield,
555
             var $ff = $('#'+section), $newfield,
555
                 avail = eval(inf.enabled);
556
                 avail = eval(inf.enabled);
556
 
557
 
557
-            if (!(grouping && subitem)) {
558
+            if (!(grouping && g_subitem)) {
558
 
559
 
559
               var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
560
               var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
560
 
561
 
572
               for (var i=0; i<inf.size; i++) {
573
               for (var i=0; i<inf.size; i++) {
573
                 var fieldname = i > 0 ? name+'-'+i : name;
574
                 var fieldname = i > 0 ? name+'-'+i : name;
574
                 $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
575
                 $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
575
-                if (grouping) $newfield.addClass(group_class);
576
+                if (grouping) $newfield.addClass(g_class);
576
                 $ff.append($newfield);
577
                 $ff.append($newfield);
577
               }
578
               }
578
             }
579
             }
594
               }
595
               }
595
               $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
596
               $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
596
               if (grouping) {
597
               if (grouping) {
597
-                $newfield.addClass(group_class);
598
+                $newfield.addClass(g_class);
598
                 if (sublabel)
599
                 if (sublabel)
599
-                  $ff.append($('<span class="label"/>').text(sublabel.toTitleCase()).unblock(avail));
600
+                  $ff.append($('<label>',{class:'added sublabel',for:name}).text(sublabel.toTitleCase()).unblock(avail));
600
               }
601
               }
601
               // Add the new field to the form
602
               // Add the new field to the form
602
               $ff.append($newfield);
603
               $ff.append($newfield);
606
             fail_list.push(name);
607
             fail_list.push(name);
607
         }
608
         }
608
       });
609
       });
609
-      if (fail_list) this.log('Unable to parse:\n' + fail_list.join('\n'), 2);
610
+      if (fail_list.length) this.log('Unable to parse:\n' + fail_list.join('\n'), 2);
610
     },
611
     },
611
 
612
 
612
     /**
613
     /**
615
     handleFileLoad: function(txt, $uploader) {
616
     handleFileLoad: function(txt, $uploader) {
616
       txt += '';
617
       txt += '';
617
       var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
618
       var filename = $uploader.val().replace(/.*[\/\\](.*)$/, '$1');
618
-      switch(filename) {
619
-        case boards_file:
620
-        case config_file:
621
-        case config_adv_file:
622
-          this.fileLoaded(filename, txt);
623
-          break;
624
-        default:
625
-          this.setMessage("Can't parse '"+filename+"'!");
626
-          break;
627
-      }
619
+      if ($.inArray(filename, config_file_list))
620
+        this.fileLoaded(filename, txt);
621
+      else
622
+        this.setMessage("Can't parse '"+filename+"'!");
628
     },
623
     },
629
 
624
 
630
     /**
625
     /**
631
      * Process a file after it's been successfully loaded
626
      * Process a file after it's been successfully loaded
632
      */
627
      */
633
-    fileLoaded: function(filename, txt) {
628
+    fileLoaded: function(filename, txt, wait) {
634
       this.log("fileLoaded:"+filename,4);
629
       this.log("fileLoaded:"+filename,4);
635
-      var err, init_index;
630
+      var err, cindex;
636
       switch(filename) {
631
       switch(filename) {
637
         case boards_file:
632
         case boards_file:
638
           this.initBoardsFromText(txt);
633
           this.initBoardsFromText(txt);
644
             $config.text(txt);
639
             $config.text(txt);
645
             total_config_lines = txt.lineCount();
640
             total_config_lines = txt.lineCount();
646
             // this.initThermistorList(txt);
641
             // this.initThermistorList(txt);
647
-            init_index = 0;
642
+            if (!wait) cindex = 0;
648
             has_config = true;
643
             has_config = true;
649
-            if (has_config_adv)
644
+            if (has_config_adv) {
650
               this.activateDownloadAllLink();
645
               this.activateDownloadAllLink();
646
+              if (wait) cindex = 2;
647
+            }
651
           }
648
           }
652
           else {
649
           else {
653
             err = boards_file;
650
             err = boards_file;
657
           if (has_config) {
654
           if (has_config) {
658
             $config_adv.text(txt);
655
             $config_adv.text(txt);
659
             total_config_adv_lines = txt.lineCount();
656
             total_config_adv_lines = txt.lineCount();
660
-            init_index = 1;
657
+            if (!wait) cindex = 1;
661
             has_config_adv = true;
658
             has_config_adv = true;
662
-            if (has_config)
659
+            if (has_config) {
663
               this.activateDownloadAllLink();
660
               this.activateDownloadAllLink();
661
+              if (wait) cindex = 2;
662
+            }
664
           }
663
           }
665
           else {
664
           else {
666
             err = config_file;
665
             err = config_file;
668
           break;
667
           break;
669
       }
668
       }
670
       // When a config file loads defines need update
669
       // When a config file loads defines need update
671
-      if (init_index != null) {
672
-        var adv = init_index == 1;
670
+      if (cindex != null) this.prepareConfigData(cindex);
671
+
672
+      this.setMessage(err
673
+        ? 'Please upload a "' + boards_file + '" file first!'
674
+        : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
675
+      );
676
+    },
677
+
678
+    prepareConfigData: function(cindex) {
679
+      var inds = (cindex == 2) ? [ 0, 1 ] : [ cindex ];
680
+      $.each(inds, function(i,e){
673
         // Purge old fields from the form, clear the define list
681
         // Purge old fields from the form, clear the define list
674
-        this.purgeAddedFields(init_index);
682
+        self.purgeAddedFields(e);
675
         // Build the define_list
683
         // Build the define_list
676
-        this.initDefineList(init_index, txt);
684
+        self.initDefineList(e);
677
         // TODO: Find sequential names and group them
685
         // TODO: Find sequential names and group them
678
         //       Allows related settings to occupy one line in the form
686
         //       Allows related settings to occupy one line in the form
679
-        this.refreshDefineGroups(init_index);
680
-        // Build the dependent defines list
681
-        this.initDependentGroups(); // all config text
682
-        // Get define_info for all known defines
683
-        this.initDefineInfo();      // all config text
687
+        self.refreshDefineGroups(e);
688
+      });
689
+      // Build the dependent defines list
690
+      this.initDependentGroups(); // all config text
691
+      // Get define_info for all known defines
692
+      this.initDefineInfo();      // all config text
693
+      $.each(inds, function(i,e){
684
         // Create new fields
694
         // Create new fields
685
-        this.createFieldsForDefines(init_index); // create new fields
695
+        self.createFieldsForDefines(e); // create new fields
686
         // Init the fields, set values, etc
696
         // Init the fields, set values, etc
687
-        this.refreshConfigForm(init_index);
688
-        this.activateDownloadLink(adv);
689
-      }
690
-      this.setMessage(err
691
-        ? 'Please upload a "' + boards_file + '" file first!'
692
-        : '"' + filename + '" loaded successfully.', err ? 'error' : 'message'
693
-      );
697
+        self.refreshConfigForm(e);
698
+        self.activateDownloadLink(e);
699
+      });
694
     },
700
     },
695
 
701
 
696
     /**
702
     /**
782
     /**
788
     /**
783
      * Update all fields on the form after loading a configuration
789
      * Update all fields on the form after loading a configuration
784
      */
790
      */
785
-    refreshConfigForm: function(init_index) {
791
+    refreshConfigForm: function(cindex) {
786
 
792
 
787
       /**
793
       /**
788
        * Any manually-created form elements will remain
794
        * Any manually-created form elements will remain
803
 
809
 
804
       // Init all existing fields, getting define info for those that need it
810
       // Init all existing fields, getting define info for those that need it
805
       // refreshing the options and updating their current values
811
       // refreshing the options and updating their current values
806
-      $.each(define_list[init_index], function() {
807
-        if ($('#'+this).length) {
808
-          self.initField(this);
809
-          self.initFieldValue(this);
812
+      $.each(define_list[cindex], function(i, name) {
813
+        if ($('#'+name).length) {
814
+          self.initField(name);
815
+          self.initFieldValue(name);
810
         }
816
         }
811
         else
817
         else
812
-          self.log(this + " is not on the page yet.", 2);
818
+          self.log(name + " is not on the page yet.", 2);
813
       });
819
       });
814
 
820
 
815
       // Set enabled state based on dependencies
821
       // Set enabled state based on dependencies
835
       // check and update enabled state for the field.
841
       // check and update enabled state for the field.
836
       //
842
       //
837
       $.each(define_list, function(e,def_list){
843
       $.each(define_list, function(e,def_list){
838
-        $.each(def_list, function() {
839
-          var inf = define_info[this];
844
+        $.each(def_list, function(i, name) {
845
+          var inf = define_info[name];
840
           if (inf && inf.enabled != 'true') {
846
           if (inf && inf.enabled != 'true') {
841
-            var $elm = $('#'+this), ena = eval(inf.enabled);
842
-            var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(this);
847
+            var $elm = $('#'+name), ena = eval(inf.enabled);
848
+            var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(name);
843
             // Make any switch toggle also
849
             // Make any switch toggle also
844
-            $('#'+this+'-switch').attr('disabled', !ena);
850
+            $('#'+name+'-switch').attr('disabled', !ena);
845
             $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
851
             $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
846
-            //self.log("Setting " + this + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
847
-            // Dim label for unavailable element
848
-            $elm.prevAll('label, span.label').filter(':first').unblock(ena);
852
+            //self.log("Setting " + name + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
853
+            $('label[for="'+name+'"]').unblock(ena);
849
           }
854
           }
850
         });
855
         });
851
       });
856
       });
852
     },
857
     },
853
 
858
 
854
     /**
859
     /**
855
-     * Make the field responsive, add optional tooltip, enabler box
860
+     * Make a field responsive, tooltip its label(s), add enabler if needed
856
      */
861
      */
857
     initField: function(name) {
862
     initField: function(name) {
858
       this.log("initField:"+name,4);
863
       this.log("initField:"+name,4);
861
 
866
 
862
       // Create a tooltip on the label if there is one
867
       // Create a tooltip on the label if there is one
863
       if (inf.tooltip) {
868
       if (inf.tooltip) {
864
-        // previous label or 
865
-        var $tipme = $elm.prevAll('label, span.label').filter(':first');
869
+        // label for the item
870
+        var $tipme = $('label[for="'+name+'"]');
866
         if ($tipme.length) {
871
         if ($tipme.length) {
867
           $tipme.unbind('mouseenter mouseleave');
872
           $tipme.unbind('mouseenter mouseleave');
868
           $tipme.hover(
873
           $tipme.hover(
1071
 
1076
 
1072
       // Scroll to the altered text if it isn't visible
1077
       // Scroll to the altered text if it isn't visible
1073
       var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
1078
       var halfHeight = $c.height()/2, scrollHeight = $c.prop('scrollHeight'),
1074
-          lineHeight = scrollHeight/(inf.adv ? total_config_adv_lines : total_config_lines),
1079
+          lineHeight = scrollHeight/[total_config_lines, total_config_adv_lines][inf.cindex],
1075
           textScrollY = (inf.lineNum * lineHeight - halfHeight).limit(0, scrollHeight - 1);
1080
           textScrollY = (inf.lineNum * lineHeight - halfHeight).limit(0, scrollHeight - 1);
1076
 
1081
 
1077
       if (always || Math.abs($c.prop('scrollTop') - textScrollY) > halfHeight) {
1082
       if (always || Math.abs($c.prop('scrollTop') - textScrollY) > halfHeight) {
1109
         $elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
1114
         $elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
1110
       }
1115
       }
1111
 
1116
 
1112
-      // set label color
1113
-      $elm.prevAll('label, span.label').filter(':first').unblock(avail);
1117
+      $('label[for="'+name+'"]').unblock(avail);
1114
     },
1118
     },
1115
 
1119
 
1116
     /**
1120
     /**
1117
      * Purge added fields and all their define info
1121
      * Purge added fields and all their define info
1118
      */
1122
      */
1119
-    purgeAddedFields: function(index) {
1120
-      $.each(define_list[index], function(){
1121
-        $('#'+this + ",[id^='"+this+"-'],label[for='"+this+"']").filter('.added').remove();
1123
+    purgeAddedFields: function(cindex) {
1124
+      $.each(define_list[cindex], function(i, name){
1125
+        $('#'+name + ",[id^='"+name+"-'],label[for='"+name+"']").filter('.added').remove();
1122
       });
1126
       });
1123
-      define_list[index] = [];
1127
+      define_list[cindex] = [];
1124
     },
1128
     },
1125
 
1129
 
1126
     /**
1130
     /**
1133
      *   - Gather nearby comments to be used as tooltips.
1137
      *   - Gather nearby comments to be used as tooltips.
1134
      *   - Look for JSON in nearby comments to use as select options.
1138
      *   - Look for JSON in nearby comments to use as select options.
1135
      */
1139
      */
1136
-    getDefineInfo: function(name, adv) {
1137
-      if (adv === undefined) adv = false;
1140
+    getDefineInfo: function(name, cindex) {
1141
+      if (cindex === undefined) cindex = 0;
1138
       this.log('getDefineInfo:'+name,4);
1142
       this.log('getDefineInfo:'+name,4);
1139
-      var $c = adv ? $config_adv : $config,
1140
-          txt = $c.text();
1143
+      var $c = config_list[cindex], txt = $c.text();
1141
 
1144
 
1142
       // a switch line with no value
1145
       // a switch line with no value
1143
       var findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*/[*/].*)?$', 'm'),
1146
       var findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + name + ')([ \\t]*/[*/].*)?$', 'm'),
1144
           result = findDef.exec(txt),
1147
           result = findDef.exec(txt),
1145
-          info = { type:0, adv:adv, field:$c[0], val_i: 2 };
1148
+          info = { type:0, cindex:cindex, field:$c[0], val_i: 2 };
1146
       if (result !== null) {
1149
       if (result !== null) {
1147
         $.extend(info, {
1150
         $.extend(info, {
1148
           val_i:  1,
1151
           val_i:  1,
1250
 
1253
 
1251
         // See if this define is enabled conditionally
1254
         // See if this define is enabled conditionally
1252
         var enable_cond = '';
1255
         var enable_cond = '';
1253
-        var adv_index = adv ? 1 : 0;
1254
         $.each(dependentGroups, function(cond,dat){
1256
         $.each(dependentGroups, function(cond,dat){
1255
           $.each(dat, function(i,o){
1257
           $.each(dat, function(i,o){
1256
-            if (o.adv == adv_index && lineNum > o.start && lineNum < o.end) {
1258
+            if (o.cindex == cindex && lineNum > o.start && lineNum < o.end) {
1257
               // self.log(name + " is in range " + o.start + "-" + o.end, 2);
1259
               // self.log(name + " is in range " + o.start + "-" + o.end, 2);
1258
               // if this setting is in a range, conditions are added
1260
               // if this setting is in a range, conditions are added
1259
               if (enable_cond != '') enable_cond += ' && ';
1261
               if (enable_cond != '') enable_cond += ' && ';

Loading…
Cancel
Save