Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# encoding: utf-8 

2from . import * 

3 

4 

5def dropdown( 

6 buttonSize="default", 

7 buttonColor="default", 

8 linkNotButton=False, 

9 menuTitle="#", 

10 splitButton=False, 

11 splitButtonHref=False, 

12 linkList=[], 

13 separatedLinkList=False, 

14 pull=False, 

15 htmlId=False, 

16 htmlClass=False, 

17 direction="down", 

18 popover=False, 

19 onPhone=True, 

20 onTablet=True, 

21 onDesktop=True): 

22 """ 

23 *get a toggleable, contextual menu for displaying lists of links. Made interactive with the dropdown JavaScript plugin. You need to wrap the dropdown's trigger and the dropdown menu within .dropdown, or another element that declares position: relative* 

24 

25 - ``buttonSize`` -- size of button [ mini | small | default | large ] 

26 - ``buttonColor`` -- [ default | sucess | error | warning | info ] 

27 - ``menuTitle`` -- the title of the menu 

28 - ``splitButton`` -- split the button into a separate action button and a dropdown 

29 - ``splitButtonHref`` -- link for the split button 

30 - ``linkList`` -- a list of (linked) items items that the menu should display 

31 - ``separatedLinkList`` -- a list of (linked) items items that the menu should display below divider 

32 - ``pull`` -- [ false | right | left ] (e.g Add ``right`` to a ``.dropdown-menu`` to right align the dropdown menu.) 

33 - ``direction`` -- drop [ down | up ] 

34 - ``popover`` -- add a popover for this dropdown 

35 - ``onPhone`` -- does this container get displayed on a phone sized screen 

36 - ``onTablet`` -- does this container get displayed on a tablet sized screen 

37 - ``onDesktop`` -- does this container get displayed on a desktop sized screen* 

38 

39 **Return** 

40 

41 - ``dropdown`` -- the dropdown menu 

42 """ 

43 # Twitter Bootstrap notes 

44 # ------------------------ 

45 # Add .pull-right to a .dropdown-menu to right align the dropdown menu. 

46 # Add .disabled to a <li> in the dropdown to disable the link. 

47 # Add .dropdown-submenu to any li in an existing dropdown menu for 

48 # automatic styling. 

49 thisLinkList = "" 

50 for link in linkList: 

51 link = link.replace('<a ', '<a tabindex="-1"') 

52 thisLinkList = """%(thisLinkList)s %(link)s""" % locals() 

53 

54 thisSeparatedLinkList = "" 

55 if separatedLinkList: 

56 thisSeparatedLinkList = """<li class="divider"></li>""" 

57 for link in separatedLinkList: 

58 thisSeparatedLinkList = """%(thisSeparatedLinkList)s %(link)s""" % locals( 

59 ) 

60 

61 thisLinkList = "%(thisLinkList)s %(thisSeparatedLinkList)s" % locals() 

62 

63 if buttonSize == "default": 

64 buttonSize = "" 

65 else: 

66 buttonSize = "btn-%(buttonSize)s" % locals() 

67 

68 buttonColor = "btn-%(buttonColor)s" % locals() 

69 

70 if htmlId is False: 

71 htmlId = "" 

72 else: 

73 htmlId = """id="%(htmlId)s" """ % locals() 

74 

75 if htmlClass is False: 

76 htmlClass = "" 

77 

78 if direction == "up": 

79 direction = "dropup" 

80 else: 

81 direction = "" 

82 

83 if popover is False: 

84 popover = "" 

85 

86 if splitButton: 

87 content = """class="btn %(buttonSize)s %(buttonColor)s" %(popover)s>%(menuTitle)s""" % locals( 

88 ) 

89 if splitButtonHref is not False: 

90 topButton = """<a href="%(splitButtonHref)s" %(content)s</a>""" % locals( 

91 ) 

92 else: 

93 topButton = """<button %(content)s</button>""" % locals() 

94 

95 dropdownButton = """ 

96 %(topButton)s 

97 <button class="btn %(buttonSize)s %(buttonColor)s dropdown-toggle" data-toggle="dropdown"> 

98 <span class="caret"></span> 

99 </button>""" % locals() 

100 popover = "" 

101 elif not linkNotButton: 

102 dropdownButton = """ 

103 <button class="btn %(buttonSize)s %(buttonColor)s dropdown-toggle" %(popover)s data-toggle="dropdown" href="#"> 

104 %(menuTitle)s 

105 <span class="caret"></span> 

106 </button>""" % locals() 

107 else: 

108 dropdownButton = """ 

109 <a class="btn btn-link dropdown-toggle" %(popover)s data-toggle="dropdown" href="#"> 

110 %(menuTitle)s 

111 <span class="caret"></span> 

112 </a>""" % locals() 

113 

114 if pull: 

115 pull = """pull-%(pull)s""" % locals() 

116 else: 

117 pull = "" 

118 

119 if onPhone: 

120 onPhone = "" 

121 else: 

122 onPhone = "hidden-phone" 

123 if onTablet: 

124 onTablet = "" 

125 else: 

126 onTablet = "hidden-tablet" 

127 if onDesktop: 

128 onDesktop = "" 

129 else: 

130 onDesktop = "hidden-desktop" 

131 

132 dropdown = """ 

133 <div class="btn-group %(pull)s %(onPhone)s %(onTablet)s %(onDesktop)s %(direction)s %(htmlClass)s" %(htmlId)s> 

134 %(dropdownButton)s 

135 <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu"> 

136 <!-- dropdown menu links --> 

137 %(thisLinkList)s 

138 </ul> 

139 </div>""" % locals() 

140 

141 return dropdown