Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 4 commits
  • 4 files changed
  • 0 comments
  • 1 contributor
Jul 05, 2012
Stéphane Payrard correct the TBD b6dcd17
Stéphane Payrard some minor renaming and refactoring
naming was confusing. make clear we use/generate css seclectos
c90e05c
Stéphane Payrard more refactoring
-parsePaneIterm highlighted using css now
-broke paneSel in sub function including liteNm which I
will soon use
-removed commented out code
61c7d35
Jul 06, 2012
Stéphane Payrard hiliting of reduced text was an off by one error 4eaec6b
6  TBD
@@ -22,9 +22,9 @@ Need folding too.
22 22
 
23 23
 ## TBD
24 24
 
25  
-* fix the current token highlighting when hoevering over the parse path pane
26  
-* simple click should freeze a lite (done but need a froze indicator)
27  
-* esc should unfreeze it go up the parse tree
  25
+*  Define and work highlighting directed by textual material
  26
+* Simple click should freeze a lite (done but need a froze indicator). Probably the freezing should be per pane.  working the first TBD iterm may help on that. Also using :hover for DH was a bad idea
  27
+* esc should go up the parse tree
28 28
 * Implement a recorder and a demo mode
29 29
 * Parse path barpaned to be scrollable
30 30
 * clone a lite to be able to drag it into a SFW page.
4  css/zbrew.css
@@ -53,12 +53,12 @@ div.text {
53 53
 
54 54
 .parsePathItem  {  padding:  4px; }
55 55
 
56  
-.parsePathSubItem:hover  {
  56
+.parsePathSubitem:hover  {
57 57
 /*  padding:  4px;*/
58 58
   background-color : #BBB
59 59
 }
60 60
 
61  
-.parsePathSubItem {
  61
+.parsePathSubitem {
62 62
    display: block;
63 63
 }
64 64
 
80  js/LiteViewport.js
@@ -2,7 +2,7 @@
2 2
 (function() {
3 3
 
4 4
   $(function() {
5  
-    var cloneLiteViewport, dehilite, dynamicHiliteP, generateLite, generateLitePortviewContent, hilite, insertParseTree, j, liteId, markupForLiteViewport, paneId, ruleNm, showParsePath, showRule, toggleLiteViewport, _i, _len, _ref, _results;
  5
+    var cloneLiteViewport, dehilite, dynamicHiliteP, generateLite, generateLitePortviewContent, hilite, insertParseTree, j, liteId, liteNm, liteSel, markupForLiteViewport, paneSel, ruleNm, showParsePath, showRule, toggleLiteViewport, _i, _len, _ref, _results;
6 6
     dynamicHiliteP = true;
7 7
     markupForLiteViewport = function(viewportId) {
8 8
       var idAndClass;
@@ -28,10 +28,10 @@
28 28
       ev.stopPropagation();
29 29
       return hilite(ev);
30 30
     });
31  
-    toggleLiteViewport = function(lid) {
  31
+    toggleLiteViewport = function(lSel) {
32 32
       var currentRulePane, display, none, parsePathPane;
33  
-      currentRulePane = $("" + lid + " .currentRulePane");
34  
-      parsePathPane = $("" + lid + " .parsePathPane");
  33
+      currentRulePane = $("" + lSel + " .currentRulePane");
  34
+      parsePathPane = $("" + lSel + " .parsePathPane");
35 35
       none = currentRulePane.css("display") === 'none' || parsePathPane.css("display") === 'none';
36 36
       display = none ? 'block' : 'none';
37 37
       if (none) {
@@ -46,49 +46,37 @@
46 46
       return dynamicHiliteP = !dynamicHiliteP;
47 47
     });
48 48
     $('.liteViewport').live('dblclick', function(ev) {
49  
-      var elt, lid;
  49
+      var elt, lSel;
50 50
       elt = ev.currentTarget;
51  
-      lid = liteId(elt);
52  
-      return toggleLiteViewport(lid);
  51
+      lSel = liteSel(elt);
  52
+      return toggleLiteViewport(lSel);
53 53
     });
54 54
     $(".parsePathItem").live('vmouseover', function(ev) {
55 55
       var elt;
56 56
       return elt = ev.currentTarget;
57 57
     });
58 58
     $(".parsePathSubitem").live('vmouseover', function(ev) {
59  
-      var elt, id, lid;
  59
+      var elt, id;
60 60
       if (!dynamicHiliteP) {
61 61
         return;
62 62
       }
63 63
       elt = ev.currentTarget;
64  
-      lid = liteId(elt);
65  
-      dehilite(lid);
66  
-      elt = ev.currentTarget;
  64
+      dehilite(liteSel(elt));
67 65
       id = elt.id;
68  
-      $(elt).addClass("hilitedRuleNm");
69 66
       showRule(elt, $(elt).text());
70  
-      return $('#' + id.substring(5)).addClass("hilitedRuleNm");
  67
+      return $('#' + id.substring(4)).addClass("hilitedRuleNm");
71 68
     });
72  
-    paneId = function(elt, paneNm) {
73  
-      var id, match, re;
74  
-      id = $(elt).parents().add($(elt)).filter(".liteViewport").attr('id');
75  
-      re = /-(\w+)$/;
76  
-      match = re.exec(id);
77  
-      if (!match) {
78  
-        console.log('wtf');
79  
-      }
80  
-      if (!(match != null ? match.length : void 0)) {
81  
-        alert;
82  
-
83  
-      }
84  
-      id = match[1];
85  
-      if (paneNm) {
86  
-        return "#" + (paneNm + '-' + id);
87  
-      }
88  
-      return id;
  69
+    paneSel = function(elt, paneNm) {
  70
+      return "#" + paneNm + "-" + (liteNm(elt));
89 71
     };
90 72
     liteId = function(elt) {
91  
-      return paneId(elt, 'liteViewport');
  73
+      return $(elt).parents().add($(elt)).filter(".liteViewport").attr('id');
  74
+    };
  75
+    liteNm = function(elt) {
  76
+      return /-(\w+)$/.exec(liteId(elt))[1];
  77
+    };
  78
+    liteSel = function(elt) {
  79
+      return paneSel(elt, 'liteViewport');
92 80
     };
93 81
     ruleNm = function(elt) {
94 82
       var classNm, m, _i, _len, _ref;
@@ -104,18 +92,18 @@
104 92
     };
105 93
     showRule = function(elt, ruleNm) {
106 94
       var ruleElt, rules;
107  
-      ruleElt = $(paneId(elt, "currentRulePane"));
  95
+      ruleElt = $(paneSel(elt, "currentRulePane"));
108 96
       rules = JSON.parse(ruleElt.attr('data'));
109 97
       if (rules[ruleNm]) {
110 98
         return ruleElt.text(rules[ruleNm]);
111 99
       }
112 100
     };
113 101
     hilite = function(ev) {
114  
-      var dad, elt, lid, rule, unnamedP;
  102
+      var dad, elt, lSel, rule, unnamedP;
115 103
       elt = ev.currentTarget;
116  
-      lid = liteId(elt);
117  
-      dehilite(lid);
118  
-      showParsePath(elt, lid);
  104
+      lSel = liteSel(elt);
  105
+      dehilite(lSel);
  106
+      showParsePath(elt, lSel);
119 107
       dad = elt.parentNode;
120 108
       if (rule = ruleNm(dad)) {
121 109
         showRule(elt, rule);
@@ -128,19 +116,19 @@
128 116
         return $(dad).children().filter(unnamedP).addClass('opr');
129 117
       }
130 118
     };
131  
-    dehilite = function(lid) {
  119
+    dehilite = function(lSel) {
132 120
       var klass, _i, _len, _ref, _results;
133 121
       _ref = ['opd', 'opr', 'editing', 'hilitedRuleNm'];
134 122
       _results = [];
135 123
       for (_i = 0, _len = _ref.length; _i < _len; _i++) {
136 124
         klass = _ref[_i];
137  
-        _results.push($("" + lid + " ." + klass).removeClass(klass));
  125
+        _results.push($("" + lSel + " ." + klass).removeClass(klass));
138 126
       }
139 127
       return _results;
140 128
     };
141  
-    showParsePath = function(elt, lid) {
  129
+    showParsePath = function(elt, lSel) {
142 130
       var AddToPath, ParsePathElt, item, itemHtml, parsePath, prevText, sameText, si, text, _i, _j, _len, _len1, _results;
143  
-      $("" + lid + " .code").removeClass("hilitedRuleNm");
  131
+      $("" + lSel + " .code").removeClass("hilitedRuleNm");
144 132
       parsePath = [];
145 133
       AddToPath = function(elt, sameText) {
146 134
         var obj;
@@ -167,7 +155,7 @@
167 155
         prevText = text;
168 156
         AddToPath(elt, sameText);
169 157
       }
170  
-      ParsePathElt = $("" + lid + " .parsePathPane");
  158
+      ParsePathElt = $("" + lSel + " .parsePathPane");
171 159
       ParsePathElt.html("<table><tr></tr></table>");
172 160
       _results = [];
173 161
       for (_i = 0, _len = parsePath.length; _i < _len; _i++) {
@@ -181,7 +169,7 @@
181 169
       }
182 170
       return _results;
183 171
     };
184  
-    insertParseTree = function(elt, data, liteId) {
  172
+    insertParseTree = function(elt, data, liteSel) {
185 173
       var appendElt, docco, id, insertSubtree, parseTree;
186 174
       id = 0;
187 175
       appendElt = function(elt, s, klass) {
@@ -198,7 +186,7 @@
198 186
           e.addClass('rule-' + klass);
199 187
           e.addClass('named');
200 188
         }
201  
-        e.attr('id', "" + liteId + "-" + (id++));
  189
+        e.attr('id', "" + liteSel + "-" + (id++));
202 190
         e.addClass('code');
203 191
         return [e, id];
204 192
       };
@@ -228,10 +216,10 @@
228 216
       docco = data.docco;
229 217
       return insertSubtree(elt, parseTree, id);
230 218
     };
231  
-    generateLitePortviewContent = function(elt, data, liteId) {
  219
+    generateLitePortviewContent = function(elt, data, liteSel) {
232 220
       var ruleElt;
233  
-      insertParseTree(elt, data, liteId);
234  
-      ruleElt = $("#currentRulePane-" + liteId);
  221
+      insertParseTree(elt, data, liteSel);
  222
+      ruleElt = $("#currentRulePane-" + liteSel);
235 223
       return ruleElt.attr('data', JSON.stringify(data.rules));
236 224
     };
237 225
     generateLite = function(j) {
72  src/LiteViewport.coffee
@@ -3,7 +3,9 @@
3 3
 # The ode is refactored to support multiple lite viewports on a single page.
4 4
 # `&MarkupForLiteViewport' generates markup. The inner routine `idAndClass` appends the
5 5
 # string `viewportId` is appended to the component panes' class names to create an unique id
6  
-#  $("#{lid} .code").removeClass "hilitedRuleNm"
  6
+#  $("#{lSel} .code").removeClass "hilitedRuleNm"
  7
+
  8
+# in variable/parameter names "elt" stands for element, "sel" for selector
7 9
 
8 10
 # class names used for DH.
9 11
 # `opr` for current operator, `opd` for associated operands if any
@@ -65,9 +67,9 @@ $ ->
65 67
 #       hilite ev
66 68
 
67 69
 
68  
-  toggleLiteViewport = (lid) ->
69  
-    currentRulePane = $("#{lid} .currentRulePane")
70  
-    parsePathPane   = $("#{lid} .parsePathPane")
  70
+  toggleLiteViewport = (lSel) ->
  71
+    currentRulePane = $("#{lSel} .currentRulePane")
  72
+    parsePathPane   = $("#{lSel} .parsePathPane")
71 73
     none = currentRulePane.css("display") == 'none' || parsePathPane.css("display") == 'none'
72 74
     display = if none then 'block' else 'none'
73 75
     if none
@@ -83,8 +85,8 @@ $ ->
83 85
 
84 86
   $('.liteViewport').live 'dblclick', (ev) ->
85 87
     elt = ev.currentTarget
86  
-    lid = liteId elt
87  
-    toggleLiteViewport lid
  88
+    lSel = liteSel elt
  89
+    toggleLiteViewport lSel
88 90
 
89 91
   $(".parsePathItem").live 'vmouseover', (ev) ->
90 92
     elt = ev.currentTarget
@@ -92,17 +94,11 @@ $ ->
92 94
   $(".parsePathSubitem").live 'vmouseover', (ev) ->
93 95
     return unless dynamicHiliteP
94 96
     elt = ev.currentTarget
95  
-    lid = liteId elt
96  
-    dehilite lid
97  
-#    $("#{lid} .code").removeClass "editing"
98  
-#    dynamicHiliteP = false
99  
-#    $("#{lid} .code").removeClass "hilitedRuleNm"
100  
-#    $("#{lid} .parsePathSubItem").removeClass "hilitedRuleNm"
101  
-    elt = ev.currentTarget
  97
+    dehilite liteSel elt
102 98
     id  = elt.id
103  
-    $(elt).addClass "hilitedRuleNm"              # color the subcomponent
  99
+#    $(elt).addClass "hilitedRuleNm"              # color the subcomponent
104 100
     showRule elt, $(elt).text()
105  
-    $( '#' + id.substring 5  ).addClass "hilitedRuleNm"  # color the corresponding code chunk
  101
+    $( '#' + id.substring 4  ).addClass "hilitedRuleNm"  # color the corresponding code chunk
106 102
 
107 103
 # # need to support keymaps
108 104
 # # inhibited handler
@@ -130,20 +126,12 @@ $ ->
130 126
 #  "paneName-viewPortSpecificSuffix". Each pane has a unique `paneName` within a viewport.
131 127
 # so far we have only one viewport type which is "liteViewPort".
132 128
 
133  
-  # get the html id of a pane named `paneNm` that is a parent of `elt`
134  
-  paneId = (elt, paneNm) ->
135  
-    # get the id of the viewport to extract the unique suffix
136  
-    id = $(elt).parents().add($(elt)).filter(".liteViewport").attr('id')
137  
-    re = /-(\w+)$/;
138  
-    match = re.exec(id)
139  
-    console.log 'wtf' if !match
140  
-    alert unless match?.length
141  
-    id = match[1]
142  
-    return "##{paneNm+'-'+id}" if paneNm
143  
-    id;
144  
-
145  
-  liteId = (elt) -> paneId elt, 'liteViewport'
  129
+  # get the css selector for a pane named `paneNm` that is a parent of `elt`
  130
+  paneSel = (elt, paneNm) ->  "##{paneNm}-#{liteNm elt}"
146 131
 
  132
+  liteId  = (elt) ->  $(elt).parents().add($(elt)).filter(".liteViewport").attr('id')
  133
+  liteNm  = (elt) -> /-(\w+)$/.exec(liteId elt)[1]
  134
+  liteSel = (elt) -> paneSel elt, 'liteViewport'
147 135
 
148 136
 # given an `elt`, extract the associated rule name
149 137
 #  from the class name of the form rule-*.
@@ -158,7 +146,7 @@ $ ->
158 146
 #  ruleElt = (litePortviewId) -> $("#currentRulePane-#{litePortviewId}")
159 147
 
160 148
   showRule = (elt, ruleNm) ->
161  
-    ruleElt = $( paneId elt, "currentRulePane")
  149
+    ruleElt = $( paneSel elt, "currentRulePane")
162 150
     rules = JSON.parse ruleElt.attr('data')
163 151
     ruleElt.text rules[ruleNm] if rules[ruleNm]
164 152
 
@@ -170,9 +158,9 @@ $ ->
170 158
 
171 159
   hilite = (ev) ->
172 160
     elt = ev.currentTarget
173  
-    lid = liteId elt
174  
-    dehilite(lid)
175  
-    showParsePath(elt, lid)
  161
+    lSel = liteSel elt
  162
+    dehilite(lSel)
  163
+    showParsePath(elt, lSel)
176 164
     # extract the current rule code to add it to the rule pane
177 165
     dad = elt.parentNode
178 166
     showRule elt, rule if rule = ruleNm dad
@@ -184,9 +172,9 @@ $ ->
184 172
     if unnamedP elt
185 173
       $(dad).children().filter(unnamedP).addClass 'opr'
186 174
 
187  
-  dehilite = (lid) ->
  175
+  dehilite = (lSel) ->
188 176
     for klass in [ 'opd' , 'opr', 'editing', 'hilitedRuleNm']
189  
-      $("#{lid} .#{klass}").removeClass klass
  177
+      $("#{lSel} .#{klass}").removeClass klass
190 178
 
191 179
 
192 180
 # A parsepath vieport displays the reduction sequence from the parse root.
@@ -195,8 +183,8 @@ $ ->
195 183
 # the corresponding parse components are grouped into an td element;
196 184
 # that is, they are grouped vertically
197 185
 
198  
-  showParsePath = (elt, lid) ->
199  
-    $("#{lid} .code").removeClass "hilitedRuleNm"
  186
+  showParsePath = (elt, lSel) ->
  187
+    $("#{lSel} .code").removeClass "hilitedRuleNm"
200 188
     parsePath = []
201 189
 
202 190
     AddToPath = (elt, sameText = false) ->
@@ -217,7 +205,7 @@ $ ->
217 205
       AddToPath elt, sameText
218 206
 
219 207
 # display the parse path
220  
-    ParsePathElt = $("#{lid} .parsePathPane")
  208
+    ParsePathElt = $("#{lSel} .parsePathPane")
221 209
     ParsePathElt.html("<table><tr></tr></table>")
222 210
     for item in parsePath
223 211
       itemHtml =''
@@ -225,7 +213,7 @@ $ ->
225 213
           itemHtml += "<div class='parsePathSubitem' id='item#{si.id}'>#{si.cnm}</div>"
226 214
       ParsePathElt.append "<td class='parsePathItem'>#{itemHtml}</td>"
227 215
 
228  
-  insertParseTree = (elt, data, liteId) ->
  216
+  insertParseTree = (elt, data, liteSel) ->
229 217
     id = 0
230 218
 
231 219
     appendElt =  (elt, s, klass) ->
@@ -242,7 +230,7 @@ $ ->
242 230
         # 'named' means 'rule-*'. Used for DH.
243 231
         e.addClass 'named'
244 232
         # unique id to hilite from the parse path pane (broken feature. why?)
245  
-      e.attr 'id', "#{liteId}-#{id++}" # `prefix` will be the viewport name.
  233
+      e.attr 'id', "#{liteSel}-#{id++}" # `prefix` will be the viewport name.
246 234
       e.addClass 'code'  # is that necessary except for the englobing element?
247 235
       [ e, id ]
248 236
 
@@ -260,9 +248,9 @@ $ ->
260 248
     insertSubtree elt, parseTree, id
261 249
 
262 250
 
263  
-  generateLitePortviewContent = (elt, data, liteId) ->
264  
-    insertParseTree elt, data, liteId;
265  
-    ruleElt = $("#currentRulePane-#{liteId}")
  251
+  generateLitePortviewContent = (elt, data, liteSel) ->
  252
+    insertParseTree elt, data, liteSel;
  253
+    ruleElt = $("#currentRulePane-#{liteSel}")
266 254
     ruleElt.attr('data', JSON.stringify(data.rules))
267 255
 
268 256
   generateLite = (j) ->

No commit comments for this range

Something went wrong with that request. Please try again.