Kaynağa Gözat

Find nearby comments and make them into tooltips

Scott Lahteine 10 yıl önce
ebeveyn
işleme
1a548c1bc1

+ 49
- 0
Marlin/configurator/css/configurator.css Dosyayı Görüntüle

@@ -72,3 +72,52 @@ fieldset legend { display: none; }
72 72
 
73 73
 #serial_stepper { padding-top: 0.75em; display: block; float: left; }
74 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 Dosyayı Görüntüle

@@ -28,7 +28,7 @@ String.prototype.lpad = function(len, chr) {
28 28
 String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) : this; };
29 29
 String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
30 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 34
  * selectField.addOptions takes an array or keyed object
@@ -206,6 +206,9 @@ var configuratorApp = (function(){
206 206
       }
207 207
     },
208 208
 
209
+    /**
210
+     * Process a file after it's been successfully loaded
211
+     */
209 212
     fileLoaded: function(filename, txt) {
210 213
       this.log("fileLoaded:"+filename,4);
211 214
       switch(filename) {
@@ -263,10 +266,8 @@ var configuratorApp = (function(){
263 266
         var name = $(this).attr('name');
264 267
         $(this).attr({id: name});
265 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 273
       // Get all 'switchable' class items and add a checkbox
@@ -300,6 +301,9 @@ var configuratorApp = (function(){
300 301
       });
301 302
     },
302 303
 
304
+    /**
305
+     * Update all fields on the form after loading a configuration
306
+     */
303 307
     refreshConfigForm: function() {
304 308
 
305 309
       /**
@@ -345,11 +349,6 @@ var configuratorApp = (function(){
345 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 353
      * Make a field responsive and initialize its defineInfo
355 354
      */
@@ -357,8 +356,15 @@ var configuratorApp = (function(){
357 356
       this.log("initField:"+name,4);
358 357
       var $elm = $('#'+name), elm = $elm[0];
359 358
       if (elm.defineInfo == null) {
360
-        elm.defineInfo = this.getDefineInfo(name, adv);
359
+        var inf = elm.defineInfo = this.getDefineInfo(name, adv);
361 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 369
       this.setFieldFromDefine(name);
364 370
     },
@@ -551,13 +557,14 @@ var configuratorApp = (function(){
551 557
     getDefineInfo: function(name, adv) {
552 558
       if (adv === undefined) adv = false;
553 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 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 568
       if (result !== null) {
562 569
         $.extend(info, {
563 570
           val_i:  1,
@@ -567,13 +574,13 @@ var configuratorApp = (function(){
567 574
           define: result[2],
568 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 580
       else {
574 581
         // a define with quotes
575 582
         findDef = new RegExp('^(.*//)?(.*#define[ \\t]+' + elm.id + '[ \\t]+)("[^"]*")([ \\t]*/[*/].*)?$', 'm');
576
-        result = findDef.exec($c.text());
583
+        result = findDef.exec(txt);
577 584
         if (result !== null) {
578 585
           $.extend(info, {
579 586
             type:   'quoted',
@@ -582,13 +589,13 @@ var configuratorApp = (function(){
582 589
             define: result[2],
583 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 595
         else {
589 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 599
           if (result !== null) {
593 600
             $.extend(info, {
594 601
               type:   'plain',
@@ -597,19 +604,41 @@ var configuratorApp = (function(){
597 604
               define: result[2],
598 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 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 637
       else
611 638
         info = null;
612 639
 
640
+      this.log(info,2);
641
+
613 642
       return info;
614 643
     },
615 644
 

Loading…
İptal
Kaydet