mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-24 21:13:35 -04:00
Get jQuery selectors highlighting again
This commit is contained in:
parent
5314c60fd9
commit
56de72410a
1 changed files with 9 additions and 3 deletions
|
@ -92,6 +92,7 @@ module.exports = class WebSurfaceView extends CocoView
|
|||
rawCss = styleNode.children[0].nodeValue
|
||||
@rawCssLines ?= []
|
||||
@rawCssLines = @rawCssLines.concat(rawCss.split('\n'))
|
||||
@rawJQueryLines = _.filter (html.split('\n').map (line) -> (line.match(/^.*\$\(\s*['"].*['"]\s*\).*$/g) or [])[0])
|
||||
# TODO: Move this hack for extracting CSS selectors
|
||||
cssSelectors = _.flatten dekuStyles.children.map (styleNode) ->
|
||||
rawCss = styleNode.children[0].nodeValue
|
||||
|
@ -124,10 +125,15 @@ module.exports = class WebSurfaceView extends CocoView
|
|||
trimLine = (line.match(/\s(.*)\s*{/)?[1] or line).trim().split(/ +/).join(' ')
|
||||
hoveredCssSelector = _.find @cssSelectors, (selector) ->
|
||||
trimLine is selector
|
||||
@iframe.contentWindow.postMessage({ type: 'highlight-css-selector', selector: hoveredCssSelector }, '*')
|
||||
else if _.contains(@rawJQueryLines, line)
|
||||
# It's a jQuery call
|
||||
trimLine = (line.match(/\$\(\s*['"](.*)['"]\s*\)/)?[1] or '').trim()
|
||||
hoveredCssSelector = _.find @cssSelectors, (selector) ->
|
||||
trimLine is selector
|
||||
else
|
||||
# They're not hovering over CSS, so don't highlight anything
|
||||
@iframe.contentWindow.postMessage({ type: 'highlight-css-selector', selector: '' }, '*')
|
||||
# They're not hovering over a line with a selector, so don't highlight anything
|
||||
hoveredCssSelector = ''
|
||||
@iframe.contentWindow.postMessage({ type: 'highlight-css-selector', selector: hoveredCssSelector }, '*')
|
||||
null
|
||||
|
||||
onIframeMessage: (event) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue