Coverage for src/lcdoc/mkdocs/lp/plugs/lightbox/__init__.py: 93.62%

Shortcuts 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

37 statements  

1""" 

2### `lightbox` 

3 

4""" 

5 

6 

7from lcdoc.tools import app lp|index.md

8from lcdoc.mkdocs.tools import script, style lp|index.md

9 

10nocache = True lp|index.md

11formatted = True lp|index.md

12multi_line_to_list = True lp|index.md

13 

14fl = '//cdn.jsdelivr.net/npm/featherlight@1.7.14/release/featherlight' lp|index.md

15sl = '[data-md-color-scheme="slate"] .featherlight' lp|index.md

16fls = style( lp|index.md

17 ''' 

18%(sl)s .featherlight-content { background: #2e303e; } 

19%(sl)s .featherlight-close-icon { background: rgba(255,255,255,.3); color: #fff; } 

20.featherlight .featherlight-content { min-width: 60%% !important; } 

21''' 

22) 

23fls = fls % {'sl': sl} lp|index.md

24 

25# Javascript supporting click events on the 'move next element into a lightbox': 

26# see https://github.com/noelboss/featherlight/issues/300 

27next_elmt_into_lightbox = ''' 

28function next_elmt_into_lightbox(id, event) { 

29 let btn=document.getElementById(id); 

30 let parent = btn.parentNode; 

31 function flclose(event) { 

32 let c = this.$content[0]; 

33 $(parent).after(c); 

34 } 

35 let el = parent.nextElementSibling; 

36 $.featherlight({jquery: el, persist: true, beforeClose: flclose}) 

37} 

38''' 

39 

40 

41h = ' .button-lightbox { color: var(--md-default-fg-color--lighter); }' lp|index.md

42h += '.button-lightbox:hover { color: var(--md-default-fg-color--light); }' lp|index.md

43 

44page_assets = { 

45 'mode': 'jquery', 

46 'header': [ 

47 fl + '.min.js', 

48 fl + '.min.css', 

49 fl + '.gallery.min.js', 

50 fl + '.gallery.min.css', 

51 fls, 

52 script(next_elmt_into_lightbox), 

53 style(h), 

54 ], 

55} 

56 

57fla = ''' 

58$('%(outer_match)s%(match)s').featherlightGallery({ 

59 nextIcon: '»', 

60 previousIcon: '«', 

61 openSpeed: 300, 

62 galleryFadeIn: 300, 

63 targetAttr: '%(target)s' 

64}); 

65$('%(outer_match)s%(match)s').css('cursor', 'zoom-in'); 

66''' 

67 

68# :docs:lightbox-defaults 

69lb_dflt_params = lambda: {'outer_match': '.md-content ', 'match': 'img', 'target': 'src'} lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.mdlp|index.md

70# :docs:lightbox-defaults 

71 

72cur_id = [0] lp|index.md

73 

74 

75def wrap_next_elmt_into_lightbox(): lp|index.md

76 """we use html so that it also works *within* html""" 

77 cur_id[0] += 1 lp|about/coverage.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.md

78 id = 'feather_below_%s' % cur_id[0] lp|about/coverage.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.md

79 md = '''<span id="%(id)s" 

80 title="View in Lightbox" 

81 onclick="next_elmt_into_lightbox('%(id)s')" 

82 style="float:right"> 

83 <span class="fa fa-glasses button-lightbox"></span> 

84 </span> 

85 ''' 

86 md = md % {'id': id} lp|about/coverage.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.md

87 # the caching would insert a marker, not wanted: 

88 return md lp|about/coverage.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.md

89 

90 

91def run(cmd, kw): lp|index.md

92 if kw['mode'] == 'lightbox:': lp|about/coverage.mdlp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

93 return wrap_next_elmt_into_lightbox() lp|about/coverage.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.mdlp|features/lp/plugs/lightbox/index.md

94 if not cmd: 94 ↛ 96line 94 didn't jump to line 96, because the condition on line 94 was never falselp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

95 cmd = '' lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

96 cmds = [cmd] if not isinstance(cmd, list) else cmd lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

97 r = [] lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

98 for cmd in cmds: lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

99 d = lb_dflt_params() lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

100 d.update(kw) lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

101 if isinstance(cmd, dict): 101 ↛ 102line 101 didn't jump to line 102, because the condition on line 101 was never truelp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

102 d.update(cmd) 

103 r.append(fla % d) lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

104 p = '\n'.join(r) lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md

105 return {'res': '', 'footer': {'script': p}} lp|about/navigation.mdlp|features/lp/plugs/chartist/index.mdlp|features/lp/plugs/drawio/index.mdlp|features/lp/plugs/kroki/index.mdlp|features/lp/plugs/lightbox/index.mdlp|index.md