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 range 

3from . import * 

4 

5 

6def image( 

7 src="http://placehold.it/200x200", 

8 href=False, 

9 display=False, # [ rounded | circle | polaroid ] 

10 pull="left", # [ "left" | "right" | "center" ] 

11 htmlClass=False, 

12 htmlId=False, 

13 thumbnail=False, 

14 width=False, 

15 height=False, 

16 onPhone=True, 

17 onTablet=True, 

18 onDesktop=True, 

19 clickToModal=False, 

20 openInNewTab=False, 

21 modal=False): 

22 """*Create an HTML image (with ot without link). Based on the Twitter bootstrap setup.* 

23 

24 **Key Arguments** 

25 

26 - ``src`` -- image url 

27 - ``href`` -- image link url 

28 - ``display`` -- how the image is to be displayed [ rounded | circle | polaroid ] 

29 - ``pull`` -- how to align the image if within a `<div>` [ "left" | "right" | "center" ] 

30 - ``htmlId`` -- the id of the image 

31 - ``htmlClass`` -- the class of the image 

32 - ``width`` -- the width of the image 

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

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

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

36 - ``clickToModal`` -- if you want to display the image in a modal when clicked? 

37 - ``openInNewTab`` -- open image link in new tab? 

38 - ``modal`` -- is this linked to a modal? 

39 

40 **Return** 

41 

42 - ``image`` - the formatted image 

43 """ 

44 falseList = [thumbnail, pull] 

45 for i in range(len(falseList)): 

46 if not falseList[i]: 

47 falseList[i] = "" 

48 

49 [thumbnail, pull] = falseList 

50 

51 if thumbnail is True: 

52 thumbnail = "thumbnail" 

53 

54 if pull: 

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

56 

57 if not display: 

58 display = "" 

59 else: 

60 display = """img-%(display)s""" % locals() 

61 if not htmlClass: 

62 htmlClass = "" 

63 if width: 

64 width = """width=%(width)s""" % locals() 

65 else: 

66 width = "" 

67 

68 if height: 

69 height = """height=%(height)s""" % locals() 

70 else: 

71 height = "" 

72 

73 if onPhone: 

74 onPhone = "" 

75 else: 

76 onPhone = "hidden-phone" 

77 if onTablet: 

78 onTablet = "" 

79 else: 

80 onTablet = "hidden-tablet" 

81 if onDesktop: 

82 onDesktop = "" 

83 else: 

84 onDesktop = "hidden-desktop" 

85 

86 if htmlId: 

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

88 else: 

89 htmlId = "" 

90 

91 if clickToModal is False: 

92 clickToModal = "" 

93 else: 

94 clickToModal = "clickToModal" 

95 

96 if modal: 

97 modal = 'data-toggle=modal' 

98 else: 

99 modal = "" 

100 

101 if "holder.js" in src: 

102 src = """data-src="%(src)s" """ % locals() 

103 else: 

104 src = """src="%(src)s" """ % locals() 

105 

106 image = """<img %(src)s class="%(display)s %(htmlClass)s %(onPhone)s %(onTablet)s %(onDesktop)s %(pull)s %(clickToModal)s" %(htmlId)s %(width)s %(height)s >""" % locals( 

107 ) 

108 

109 if openInNewTab is not False: 

110 openInNewTab = """target="_blank" """ 

111 else: 

112 openInNewTab = "" 

113 

114 if href: 

115 image = """<a href="%(href)s" class="%(thumbnail)s %(onPhone)s %(onTablet)s %(onDesktop)s %(pull)s" %(htmlId)s %(openInNewTab)s %(modal)s>%(image)s</a>""" % locals( 

116 ) 

117 

118 return image