Exemplo n.º 1
0
    def replaceLinks(self, tagname="a", use_page_href=True, ajaxify=False):
        """ replaces <tag href="#pagename">sometext</tag> with:
            Hyperlink("sometext", "pagename").  Hyperlinks use
            the History module so the notification will come
            in on an onHistoryChanged.
        """
        self._clear_hyperlinks()
        tags = self.findTags(tagname)
        pageloc = Window.getLocation()
        pagehref = pageloc.getPageHref()
        for el in tags:
            href = el.href
            l = href.split("#")
            if len(l) != 2:
                continue
            if use_page_href and not l[0].startswith(pagehref):
                continue
            token = l[1]
            if not token:
                continue
            html = DOM.getInnerHTML(el)
            parent = DOM.getParent(el)
            index = DOM.getChildIndex(parent, el)
            if ajaxify:
                token = '!%s' % token
            hl = Hyperlink(TargetHistoryToken=token,
                           HTML=html,
                           Element=DOM.createSpan())
            DOM.insertChild(parent, hl.getElement(), index)
            parent.removeChild(el)

            self.children.insert(index, hl)
            hl.setParent(self)
            self.hyperlinks.append(hl)
Exemplo n.º 2
0
 def replaceLinks(self, tagname="a"):
     """ replaces <tag href="#pagename">sometext</tag> with:
         Hyperlink("sometext", "pagename")
     """
     tags = self.findTags(tagname)
     pageloc = Window.getLocation()
     pagehref = pageloc.getPageHref()
     for el in tags:
         href = el.href
         l = href.split("#")
         if len(l) != 2:
             continue
         if l[0] != pagehref:
             continue
         token = l[1]
         if not token:
             continue
         html = DOM.getInnerHTML(el)
         parent = DOM.getParent(el)
         index = DOM.getChildIndex(parent, el)
         hl = Hyperlink(TargetHistoryToken=token,
                        HTML=html,
                        Element=DOM.createSpan())
         DOM.insertChild(parent, hl.getElement(), index)
         self.children.insert(index, hl)
         parent.removeChild(el)