1 from pyjamas.ui.HTMLPanel import HTMLPanel
2 from pyjamas.ui.Hyperlink import Hyperlink
3
4 from pyjamas import Window
5 from pyjamas import DOM
6
11
15
24
26 """ replaces <tag href="#pagename">sometext</tag> with:
27 Hyperlink("sometext", "pagename"). Hyperlinks use
28 the History module so the notification will come
29 in on an onHistoryChanged.
30 """
31 self._clear_hyperlinks()
32 tags = self.findTags(tagname)
33 pageloc = Window.getLocation()
34 pagehref = pageloc.getPageHref()
35 for el in tags:
36 href = el.href
37 l = href.split("#")
38 if len(l) != 2:
39 continue
40 if use_page_href and not l[0].startswith(pagehref):
41 continue
42 token = l[1]
43 if not token:
44 continue
45 html = DOM.getInnerHTML(el)
46 parent = DOM.getParent(el)
47 index = DOM.getChildIndex(parent, el)
48 hl = Hyperlink(TargetHistoryToken=token,
49 HTML=html,
50 Element=DOM.createSpan())
51 DOM.insertChild(parent, hl.getElement(), index)
52 parent.removeChild(el)
53
54 self.children.insert(index, hl)
55 hl.setParent(self)
56 self.hyperlinks.append(hl)
57