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 builtins import str 

3from . import * 

4import khufu 

5 

6 

7def tabbableNavigation( 

8 contentDictionary={}, # { name : content } 

9 fadeIn=True, 

10 direction='top', 

11 htmlClass=False, 

12 htmlId=False, 

13 uniqueNavigationId=False, 

14 contentCount={} 

15): 

16 """ Generate a tabbable Navigation 

17 

18 **Key Arguments** 

19 

20 - ``contentDictionary`` -- the content dictionary { name : content } 

21 - ``fadeIn`` -- make tabs fade in 

22 - ``direction`` -- the position of the tabs [ above | below | left | right ] 

23 - ``uniqueNavigationId`` -- a unique id for this navigation block if more than one on page 

24 

25 

26 **Return** 

27 

28 - ``tabbableNavigation`` -- the tabbableNavigation """ 

29 

30 if fadeIn is True: 

31 fadeIn = 'fade' 

32 else: 

33 fadeIn = '' 

34 titleList = '' 

35 contentList = '' 

36 count = 0 

37 

38 # turn contentCounts into badges 

39 for i in list(contentDictionary.keys()): 

40 if i in list(contentCount.keys()): 

41 contentCount[i] = khufu.badge( 

42 text=str(contentCount[i]), 

43 level='inverse' 

44 ) 

45 else: 

46 contentCount[i] = "" 

47 

48 if htmlClass is False: 

49 htmlClass = "" 

50 

51 if htmlId is False: 

52 htmlId = "" 

53 else: 

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

55 

56 if uniqueNavigationId is False: 

57 uniqueNavigationId = "" 

58 elif isinstance(uniqueNavigationId, int) and not isinstance(uniqueNavigationId, bool): 

59 uniqueNavigationId = """id%(uniqueNavigationId)s""" % locals() 

60 

61 for k, v in list(contentDictionary.items()): 

62 badge = contentCount[k] 

63 if count == 0: 

64 titleList = """%(titleList)s<li class="active"><a href="#tab%(uniqueNavigationId)s%(count)s" data-toggle="tab">%(k)s %(badge)s</a></li>""" % locals( 

65 ) 

66 contentList = \ 

67 """%(contentList)s 

68 <div class="tab-pane active %(fadeIn)s" id="tab%(uniqueNavigationId)s%(count)s"> 

69 <p>%(v)s</p> 

70 </div>""" \ 

71 % locals() 

72 else: 

73 titleList = """%(titleList)s<li><a href="#tab%(uniqueNavigationId)s%(count)s" data-toggle="tab">%(k)s %(badge)s</a></li>""" % locals( 

74 ) 

75 contentList = \ 

76 """%(contentList)s 

77 <div class="tab-pane %(fadeIn)s" id="tab%(uniqueNavigationId)s%(count)s"> 

78 <p>%(v)s</p> 

79 </div>""" \ 

80 % locals() 

81 count += 1 

82 tabbableNavigation = \ 

83 """ 

84 <div class="tabbable %(htmlClass)s" %(htmlId)s> 

85 <ul class="nav nav-tabs"> 

86 %(titleList)s 

87 </ul> 

88 <div class="tab-content"> 

89 %(contentList)s 

90 </div> 

91 </div>""" \ 

92 % locals() 

93 if direction != 'top': 

94 tabbableNavigation = \ 

95 """ 

96 <div class="tabbable tabs-%(direction)s %(htmlClass)s" %(htmlId)s> 

97 <div class="tab-content"> 

98 %(contentList)s 

99 </div> 

100 <ul class="nav nav-tabs"> 

101 %(titleList)s 

102 </ul> 

103 </div>""" \ 

104 % locals() 

105 return tabbableNavigation