Permalink
Browse files

some minor renaming and refactoring

naming was confusing. make clear we use/generate css seclectos
  • Loading branch information...
1 parent b6dcd17 commit c90e05c4bd0ac7dac89a27ffa60e8451d8f4f584 @cognominal committed Jul 5, 2012
Showing with 62 additions and 78 deletions.
  1. +30 −43 js/LiteViewport.js
  2. +32 −35 src/LiteViewport.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -3,7 +3,9 @@
# The ode is refactored to support multiple lite viewports on a single page.
# `&MarkupForLiteViewport' generates markup. The inner routine `idAndClass` appends the
# string `viewportId` is appended to the component panes' class names to create an unique id
-# $("#{lid} .code").removeClass "hilitedRuleNm"
+# $("#{lSel} .code").removeClass "hilitedRuleNm"
+
+# in variable/parameter names "elt" stands for element, "sel" for selector
# class names used for DH.
# `opr` for current operator, `opd` for associated operands if any
@@ -65,9 +67,9 @@ $ ->
# hilite ev
- toggleLiteViewport = (lid) ->
- currentRulePane = $("#{lid} .currentRulePane")
- parsePathPane = $("#{lid} .parsePathPane")
+ toggleLiteViewport = (lSel) ->
+ currentRulePane = $("#{lSel} .currentRulePane")
+ parsePathPane = $("#{lSel} .parsePathPane")
none = currentRulePane.css("display") == 'none' || parsePathPane.css("display") == 'none'
display = if none then 'block' else 'none'
if none
@@ -83,21 +85,21 @@ $ ->
$('.liteViewport').live 'dblclick', (ev) ->
elt = ev.currentTarget
- lid = liteId elt
- toggleLiteViewport lid
+ lSel = liteSel elt
+ toggleLiteViewport lSel
$(".parsePathItem").live 'vmouseover', (ev) ->
elt = ev.currentTarget
$(".parsePathSubitem").live 'vmouseover', (ev) ->
return unless dynamicHiliteP
elt = ev.currentTarget
- lid = liteId elt
- dehilite lid
-# $("#{lid} .code").removeClass "editing"
+ lSel = liteSel elt
+ dehilite lSel
+# $("#{lSel} .code").removeClass "editing"
# dynamicHiliteP = false
-# $("#{lid} .code").removeClass "hilitedRuleNm"
-# $("#{lid} .parsePathSubItem").removeClass "hilitedRuleNm"
+# $("#{lSel} .code").removeClass "hilitedRuleNm"
+# $("#{lSel} .parsePathSubItem").removeClass "hilitedRuleNm"
elt = ev.currentTarget
id = elt.id
$(elt).addClass "hilitedRuleNm" # color the subcomponent
@@ -130,19 +132,14 @@ $ ->
# "paneName-viewPortSpecificSuffix". Each pane has a unique `paneName` within a viewport.
# so far we have only one viewport type which is "liteViewPort".
- # get the html id of a pane named `paneNm` that is a parent of `elt`
- paneId = (elt, paneNm) ->
+ # get the css selector for a pane named `paneNm` that is a parent of `elt`
+ paneSel = (elt, paneNm) ->
# get the id of the viewport to extract the unique suffix
id = $(elt).parents().add($(elt)).filter(".liteViewport").attr('id')
- re = /-(\w+)$/;
- match = re.exec(id)
- console.log 'wtf' if !match
- alert unless match?.length
- id = match[1]
- return "##{paneNm+'-'+id}" if paneNm
- id;
+ "##{paneNm}-#{/-(\w+)$/.exec(id)[1]}"
+
- liteId = (elt) -> paneId elt, 'liteViewport'
+ liteSel = (elt) -> paneSel elt, 'liteViewport'
# given an `elt`, extract the associated rule name
@@ -158,7 +155,7 @@ $ ->
# ruleElt = (litePortviewId) -> $("#currentRulePane-#{litePortviewId}")
showRule = (elt, ruleNm) ->
- ruleElt = $( paneId elt, "currentRulePane")
+ ruleElt = $( paneSel elt, "currentRulePane")
rules = JSON.parse ruleElt.attr('data')
ruleElt.text rules[ruleNm] if rules[ruleNm]
@@ -170,9 +167,9 @@ $ ->
hilite = (ev) ->
elt = ev.currentTarget
- lid = liteId elt
- dehilite(lid)
- showParsePath(elt, lid)
+ lSel = liteSel elt
+ dehilite(lSel)
+ showParsePath(elt, lSel)
# extract the current rule code to add it to the rule pane
dad = elt.parentNode
showRule elt, rule if rule = ruleNm dad
@@ -184,9 +181,9 @@ $ ->
if unnamedP elt
$(dad).children().filter(unnamedP).addClass 'opr'
- dehilite = (lid) ->
+ dehilite = (lSel) ->
for klass in [ 'opd' , 'opr', 'editing', 'hilitedRuleNm']
- $("#{lid} .#{klass}").removeClass klass
+ $("#{lSel} .#{klass}").removeClass klass
# A parsepath vieport displays the reduction sequence from the parse root.
@@ -195,8 +192,8 @@ $ ->
# the corresponding parse components are grouped into an td element;
# that is, they are grouped vertically
- showParsePath = (elt, lid) ->
- $("#{lid} .code").removeClass "hilitedRuleNm"
+ showParsePath = (elt, lSel) ->
+ $("#{lSel} .code").removeClass "hilitedRuleNm"
parsePath = []
AddToPath = (elt, sameText = false) ->
@@ -217,15 +214,15 @@ $ ->
AddToPath elt, sameText
# display the parse path
- ParsePathElt = $("#{lid} .parsePathPane")
+ ParsePathElt = $("#{lSel} .parsePathPane")
ParsePathElt.html("<table><tr></tr></table>")
for item in parsePath
itemHtml =''
for si in item
itemHtml += "<div class='parsePathSubitem' id='item#{si.id}'>#{si.cnm}</div>"
ParsePathElt.append "<td class='parsePathItem'>#{itemHtml}</td>"
- insertParseTree = (elt, data, liteId) ->
+ insertParseTree = (elt, data, liteSel) ->
id = 0
appendElt = (elt, s, klass) ->
@@ -242,7 +239,7 @@ $ ->
# 'named' means 'rule-*'. Used for DH.
e.addClass 'named'
# unique id to hilite from the parse path pane (broken feature. why?)
- e.attr 'id', "#{liteId}-#{id++}" # `prefix` will be the viewport name.
+ e.attr 'id', "#{liteSel}-#{id++}" # `prefix` will be the viewport name.
e.addClass 'code' # is that necessary except for the englobing element?
[ e, id ]
@@ -260,9 +257,9 @@ $ ->
insertSubtree elt, parseTree, id
- generateLitePortviewContent = (elt, data, liteId) ->
- insertParseTree elt, data, liteId;
- ruleElt = $("#currentRulePane-#{liteId}")
+ generateLitePortviewContent = (elt, data, liteSel) ->
+ insertParseTree elt, data, liteSel;
+ ruleElt = $("#currentRulePane-#{liteSel}")
ruleElt.attr('data', JSON.stringify(data.rules))
generateLite = (j) ->

0 comments on commit c90e05c

Please sign in to comment.