coffeescript-ui
Version:
Coffeescript User Interface System
70 lines (60 loc) • 1.89 kB
text/coffeescript
###
* coffeescript-ui - Coffeescript User Interface System (CUI)
* Copyright (c) 2013 - 2016 Programmfabrik GmbH
* MIT Licence
* https://github.com/programmfabrik/coffeescript-ui, http://www.coffeescript-ui.org
###
class CUI.DocumentBrowser.NodeMatch extends CUI.Element
initOpts: ->
super()
title_match:
check: CUI.DocumentBrowser.SearchMatch
text_matches:
check: (v) ->
for item in v
if item not instanceof CUI.DocumentBrowser.SearchMatch
return false
true
searchQuery:
check: CUI.DocumentBrowser.SearchQuery
node:
check: CUI.DocumentBrowser.Node
marked: (markdown) ->
.getBrowser().marked(, markdown)
render: ->
titlePath =[]
for part in .getTitlePath()
titlePath.push(CUI.util.toHtml(part))
if
# replace last item
titlePath[titlePath.length-1] = .getHighlighted()
# console.debug titlePath
lbl = new CUI.Label
class: "cui-document-browser-search-match--title"
multiline: true
content: CUI.dom.htmlToNodes(titlePath.join("<span class='cui-document-browser-node-match-hierarchy'>"+new CUI.Icon(icon: "right").DOM.outerHTML+"</span>"))
CUI.dom.setAttribute(lbl.DOM, "tabindex", 0)
CUI.Events.listen
type: "focus"
node: lbl
call: (ev) =>
.select(search: .getSearch())
return
arr = [ lbl ]
if
ul = CUI.dom.element("UL")
arr.push(ul)
for text_match in
html = text_match.getHighlighted(true)
li = CUI.dom.element("LI", title: text_match.getString(), tabindex: 0)
do (text_match) =>
CUI.Events.listen
type: "focus"
node: li
call: (ev) =>
.select(search: .getSearch(), nodeIdx: text_match.nodeIdx)
return
CUI.dom.append(li, CUI.dom.htmlToNodes(html))
ul.appendChild(li)
arr