Procházet zdrojové kódy

Find nearby comments and make them into tooltips

Scott Lahteine před 10 roky
rodič
revize
1a548c1bc1

+ 49
- 0
Marlin/configurator/css/configurator.css Zobrazit soubor

72
 
72
 
73
 #serial_stepper { padding-top: 0.75em; display: block; float: left; }
73
 #serial_stepper { padding-top: 0.75em; display: block; float: left; }
74
 #SERIAL_PORT { display: none; }
74
 #SERIAL_PORT { display: none; }
75
+
76
+.tooltip { position: relative; }
77
+.tooltip::before {
78
+	content: attr(data-tooltip);
79
+	font-family: sans-serif;
80
+	font-size: 85%;
81
+	text-align: left;
82
+	position: absolute;
83
+	z-index: 999;
84
+	/*white-space:pre-wrap;*/
85
+	bottom: 9999px;
86
+	left: 110px;
87
+	color: #000;
88
+	padding: 8px;
89
+	line-height: 1.1;
90
+	max-width: 30em;
91
+	opacity: 0;
92
+	border-radius: 1em;
93
+	border: 2px solid #73d699;
94
+	background: #e2ff99; /* Old browsers */
95
+	background: -moz-linear-gradient(top,  #e2ff99 0%, #73d699 100%); /* FF3.6+ */
96
+	background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#e2ff99), color-stop(100%,#73d699)); /* Chrome,Safari4+ */
97
+	background: -webkit-linear-gradient(top,  #e2ff99 0%,#73d699 100%); /* Chrome10+,Safari5.1+ */
98
+	background: -o-linear-gradient(top,  #e2ff99 0%,#73d699 100%); /* Opera 11.10+ */
99
+	background: -ms-linear-gradient(top,  #e2ff99 0%,#73d699 100%); /* IE10+ */
100
+	background: linear-gradient(to bottom,  #e2ff99 0%,#73d699 100%); /* W3C */
101
+	filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#e2ff99', endColorstr='#73d699',GradientType=0 ); /* IE6-9 */
102
+	-webkit-box-shadow: 0px 6px 25px -4px rgba(0,0,0,0.75);
103
+	-moz-box-shadow: 0px 6px 25px -4px rgba(0,0,0,0.75);
104
+	box-shadow: 0px 6px 25px -4px rgba(0,0,0,0.75);
105
+	}
106
+.tooltip:hover::before {
107
+	opacity: 1;
108
+	bottom: 30px;
109
+	}
110
+.tooltip:hover::after {
111
+	content: "";
112
+	opacity: 1;
113
+	width: 0;
114
+	height: 0;
115
+	border-left: 8px solid transparent;
116
+	border-right: 8px solid transparent;
117
+	border-top: 8px solid #73d699;
118
+	z-index: 999;
119
+	position: absolute;
120
+	/*white-space: nowrap;*/
121
+	top: 2px;
122
+	left: 130px;
123
+	}

+ 56
- 27
Marlin/configurator/js/configurator.js Zobrazit soubor

28
 String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) : this; };
28
 String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) : this; };
29
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
29
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
30
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
30
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
31
-String.prototype.lineCount = function()      { return this.split(/\r?\n|\r/).length; };
31
+String.prototype.lineCount = function()      { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : len; };
32
 
32
 
33
 /**
33
 /**
34
  * selectField.addOptions takes an array or keyed object
34
  * selectField.addOptions takes an array or keyed object
206
       }
206
       }
207
     },
207
     },
208
 
208
 
209
+    /**
210
+     * Process a file after it's been successfully loaded
211
+     */
209
     fileLoaded: function(filename, txt) {
212
     fileLoaded: function(filename, txt) {
210
       this.log("fileLoaded:"+filename,4);
213
       this.log("fileLoaded:"+filename,4);
211
       switch(filename) {
214
       switch(filename) {
263
         var name = $(this).attr('name');
266
         var name = $(this).attr('name');
264
         $(this).attr({id: name});
267
         $(this).attr({id: name});
265
         // Attach its label sibling
268
         // Attach its label sibling
266
-        var $label = $(this).prev();
267
-        if ($label[0].tagName == 'LABEL') {
268
-          $label.attr('for',name);
269
-        }
269
+        var $label = $(this).prev('label');
270
+        if ($label.length) $label.attr('for',name);
270
       });
271
       });
271
 
272
 
272
       // Get all 'switchable' class items and add a checkbox
273
       // Get all 'switchable' class items and add a checkbox
300
       });
301
       });
301
     },
302
     },
302
 
303
 
304
+    /**
305
+     * Update all fields on the form after loading a configuration
306
+     */
303
     refreshConfigForm: function() {
307
     refreshConfigForm: function() {
304
 
308
 
305
       /**
309
       /**
345
       this.initField('TEMP_RESIDENCY_TIME');
349
       this.initField('TEMP_RESIDENCY_TIME');
346
     },
350
     },
347
 
351
 
348
-    setTextAndHighlight: function($field, txt, name) {
349
-      var $elm = $('#'+name), elm = $elm[0], inf = elm.defineInfo;
350
-      if (inf == null) return;
351
-    },
352
-
353
     /**
352
     /**
354
      * Make a field responsive and initialize its defineInfo
353
      * Make a field responsive and initialize its defineInfo
355
      */
354
      */
357
       this.log("initField:"+name,4);
356
       this.log("initField:"+name,4);
358
       var $elm = $('#'+name), elm = $elm[0];
357
       var $elm = $('#'+name), elm = $elm[0];
359
       if (elm.defineInfo == null) {
358
       if (elm.defineInfo == null) {
360
-        elm.defineInfo = this.getDefineInfo(name, adv);
359
+        var inf = elm.defineInfo = this.getDefineInfo(name, adv);
361
         $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
360
         $elm.on($elm.attr('type') == 'text' ? 'input' : 'change', this.handleChange);
361
+        var comm = inf.comment;
362
+        var $tipme = $elm.prev('label');
363
+        if ($tipme.length) {
364
+          comm ?
365
+            $tipme.addClass('tooltip').attr('data-tooltip',comm) :
366
+            $tipme.removeClass('tooltip').removeAttr('data-tooltip');
367
+        }
362
       }
368
       }
363
       this.setFieldFromDefine(name);
369
       this.setFieldFromDefine(name);
364
     },
370
     },
551
     getDefineInfo: function(name, adv) {
557
     getDefineInfo: function(name, adv) {
552
       if (adv === undefined) adv = false;
558
       if (adv === undefined) adv = false;
553
       this.log('getDefineInfo:'+name,4);
559
       this.log('getDefineInfo:'+name,4);
554
-      var $elm = $('#'+name), elm = $elm[0];
555
-      var $c = adv ? $config_adv : $config;
560
+      var $elm = $('#'+name), elm = $elm[0],
561
+          $c = adv ? $config_adv : $config,
562
+          txt = $c.text();
556
 
563
 
557
       // a switch line with no value
564
       // a switch line with no value
558
-      var findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm');
559
-      var result = findDef.exec($c.text());
560
-      var info = { type:0, adv:adv, field:$c[0], val_i: 2 };
565
+      var findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + elm.id + ')([ \\t]*/[*/].*)?$', 'm'),
566
+          result = findDef.exec(txt),
567
+          info = { type:0, adv:adv, field:$c[0], val_i: 2 };
561
       if (result !== null) {
568
       if (result !== null) {
562
         $.extend(info, {
569
         $.extend(info, {
563
           val_i:  1,
570
           val_i:  1,
567
           define: result[2],
574
           define: result[2],
568
           post:   result[3] === undefined ? '' : result[3]
575
           post:   result[3] === undefined ? '' : result[3]
569
         });
576
         });
570
-        info.regex = new RegExp('( *//)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
571
-        info.repl =  new RegExp('( *)(\/\/)?( *' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
577
+        info.regex = new RegExp('([ \\t]*//)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
578
+        info.repl =  new RegExp('([ \\t]*)(\/\/)?([ \\t]*' + info.define.regEsc() + info.post.regEsc() + ')', 'm');
572
       }
579
       }
573
       else {
580
       else {
574
         // a define with quotes
581
         // a define with quotes
575
         findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
582
         findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
576
-        result = findDef.exec($c.text());
583
+        result = findDef.exec(txt);
577
         if (result !== null) {
584
         if (result !== null) {
578
           $.extend(info, {
585
           $.extend(info, {
579
             type:   'quoted',
586
             type:   'quoted',
582
             define: result[2],
589
             define: result[2],
583
             post:   result[4] === undefined ? '' : result[4]
590
             post:   result[4] === undefined ? '' : result[4]
584
           });
591
           });
585
-          info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
586
-          info.repl  = new RegExp('(( *//)? *' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
592
+          info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '"([^"]*)"' + info.post.regEsc(), 'm');
593
+          info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '")[^"]*("' + info.post.regEsc() + ')', 'm');
587
         }
594
         }
588
         else {
595
         else {
589
           // a define with no quotes
596
           // a define with no quotes
590
-          findDef = new RegExp('^( *//)?( *#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
591
-          result = findDef.exec($c.text());
597
+          findDef = new RegExp('^([ \\t]*//)?([ \\t]*#define[ \\t]+' + elm.id + '[ \\t]+)(\\S*)([ \\t]*/[*/].*)?$', 'm');
598
+          result = findDef.exec(txt);
592
           if (result !== null) {
599
           if (result !== null) {
593
             $.extend(info, {
600
             $.extend(info, {
594
               type:   'plain',
601
               type:   'plain',
597
               define: result[2],
604
               define: result[2],
598
               post:   result[4] === undefined ? '' : result[4]
605
               post:   result[4] === undefined ? '' : result[4]
599
             });
606
             });
600
-            info.regex = new RegExp('( *//)? *' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
601
-            info.repl  = new RegExp('(( *//)? *' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
607
+            info.regex = new RegExp('([ \\t]*//)?[ \\t]*' + info.define.regEsc() + '(\\S*)' + info.post.regEsc(), 'm');
608
+            info.repl  = new RegExp('(([ \\t]*//)?[ \\t]*' + info.define.regEsc() + ')\\S*(' + info.post.regEsc() + ')', 'm');
602
           }
609
           }
603
         }
610
         }
604
       }
611
       }
605
 
612
 
606
       if (info.type) {
613
       if (info.type) {
607
-        info.lineNum = this.getLineNumberOfText(info.line, $c.text());
608
-        this.log(info,2);
614
+        var comment = '';
615
+        // Get the end-of-line comment, if there is one
616
+        findDef = new RegExp('.*#define[ \\t].*/[/*]+[ \\t]*(.*)');
617
+        if (info.line.search(findDef) >= 0) {
618
+          comment = info.line.replace(findDef, '$1');
619
+        }
620
+        else {
621
+          // Get all the comments immediately before the item
622
+          var r, s;
623
+          findDef = new RegExp('([ \\t]*(//|#)[^\n]+\n){1,4}\\s{0,1}' + info.line, 'g');
624
+          if (r = findDef.exec(txt)) {
625
+            findDef = new RegExp('^[ \\t]*//+[ \\t]*(.*)[ \\t]*$', 'gm');
626
+            while((s = findDef.exec(r[0])) !== null) {
627
+              if (s[1].match(/\/\/[ \\t]*#define/) == null)
628
+                comment += s[1] + "\n";
629
+            }
630
+          }
631
+        }
632
+        $.extend(info, {
633
+          comment: comment.trim(),
634
+          lineNum: this.getLineNumberOfText(info.line, txt)
635
+        });
609
       }
636
       }
610
       else
637
       else
611
         info = null;
638
         info = null;
612
 
639
 
640
+      this.log(info,2);
641
+
613
       return info;
642
       return info;
614
     },
643
     },
615
 
644
 

Loading…
Zrušit
Uložit