1 """
2 Anchor Widget, use this to create the equivalent of the <a></a> tag.
3
4 Copyright(C) 2010, Martin Hellwig
5 Copyright(C) 2010, Luke Leighton <lkcl@lkcl.net>
6
7 License: Apache Software Foundation v2
8
9 Here is an example for using it with an image::
10
11 if __name__ == '__main__':
12 from pyjamas.ui.RootPanel import RootPanel
13 from pyjamas.ui.Image import Image
14 root = RootPanel()
15 image = Image('http://pyjs.org/img/pyjamas.128x128.png')
16 anchor = Anchor(Widget=image, Href='http://pyjs.org')
17 root.add(anchor)
18 """
19
20 from pyjamas import DOM
21 from pyjamas.ui.Widget import Widget
22 from pyjamas.ui.ClickListener import ClickHandler
23
25 "Attribute definition class with method set and remove"
26 - def __init__(self, element, attribute,
27 attribute_type=None, type_restriction=None):
28 self.element = element
29 self.attribute = attribute
30 self._type = attribute_type
31 self._restriction = type_restriction
32
34 "Get the value"
35 return DOM.getAttribute(self.element, self.attribute)
36
37 - def set(self, value):
38 "Set the value"
39 DOM.setAttribute(self.element, self.attribute, value)
40
42 "Remove the attribute from the element"
43 DOM.removeAttribute(self.element, self.attribute)
44
46 "Attribute container class"
48 self.name = _Attribute(element, 'name', 'cdata', 'cs')
49 self.href = _Attribute(element, 'href', 'uri', 'ct')
50 self.hreflang = _Attribute(element, 'hreflang', 'langcode', 'ci')
51 self.type = _Attribute(element, 'type', 'content-type', 'ci')
52 self.rel = _Attribute(element, 'rel', 'link-types' ,'ci')
53 self.rev = _Attribute(element, 'rev', 'link-types', 'ci')
54 self.charset = _Attribute(element, 'charset', 'charset', 'ci')
55 self.target = _Attribute(element, 'target', 'target', 'ci')
56
57 -class Anchor(Widget, ClickHandler, _Attributes):
58 """Anchor attribute, use this to create the equivalent of the <a></a> tag.
59 The attributes: name, href. hreflang, type, rel, rev, charset are in the
60 namespace of the Anchor instance.
61 These attributes themselves have the functions 'set' and 'remove'
62 For example:
63 anchor = Anchor()
64 anchor.href.set('http://www.dcuktec.com')
65 """
74
82
89
92