66 function isSelected(e) {{ |
66 function isSelected(e) {{ |
67 var selection = window.getSelection(); |
67 var selection = window.getSelection(); |
68 if (selection.type != 'Range') |
68 if (selection.type != 'Range') |
69 return false; |
69 return false; |
70 return window.getSelection().containsNode(e, true); |
70 return window.getSelection().containsNode(e, true); |
|
71 }} |
|
72 function attributeStr(e, a) {{ |
|
73 return e.getAttribute(a) || ''; |
71 }} |
74 }} |
72 var res = {{ |
75 var res = {{ |
73 baseUrl: document.baseURI, |
76 baseUrl: document.baseURI, |
74 alternateText: e.getAttribute('alt'), |
77 alternateText: e.getAttribute('alt'), |
75 boundingRect: '', |
78 boundingRect: '', |
84 tagName: e.tagName.toLowerCase() |
87 tagName: e.tagName.toLowerCase() |
85 }}; |
88 }}; |
86 var r = e.getBoundingClientRect(); |
89 var r = e.getBoundingClientRect(); |
87 res.boundingRect = [r.top, r.left, r.width, r.height]; |
90 res.boundingRect = [r.top, r.left, r.width, r.height]; |
88 if (e.tagName.toLowerCase() == 'img') |
91 if (e.tagName.toLowerCase() == 'img') |
89 res.imageUrl = e.getAttribute('src').trim(); |
92 res.imageUrl = attributeStr(e, 'src').trim(); |
90 if (e.tagName.toLowerCase() == 'a') {{ |
93 if (e.tagName.toLowerCase() == 'a') {{ |
91 res.linkTitle = e.text; |
94 res.linkTitle = e.text; |
92 res.linkUrl = e.getAttribute('href').trim(); |
95 res.linkUrl = attributeStr(e, 'href').trim(); |
93 }} |
96 }} |
94 while (e) {{ |
97 while (e) {{ |
95 if (res.linkTitle == '' && e.tagName.toLowerCase() == 'a') |
98 if (res.linkTitle == '' && e.tagName.toLowerCase() == 'a') |
96 res.linkTitle = e.text; |
99 res.linkTitle = e.text; |
97 if (res.linkUrl == '' && e.tagName.toLowerCase() == 'a') |
100 if (res.linkUrl == '' && e.tagName.toLowerCase() == 'a') |
98 res.linkUrl = e.getAttribute('href').trim(); |
101 res.linkUrl = attributeStr(e, 'href').trim(); |
99 if (res.mediaUrl == '' && isMediaElement(e)) {{ |
102 if (res.mediaUrl == '' && isMediaElement(e)) {{ |
100 res.mediaUrl = e.currentSrc; |
103 res.mediaUrl = e.currentSrc; |
101 res.mediaPaused = e.paused; |
104 res.mediaPaused = e.paused; |
102 res.mediaMuted = e.muted; |
105 res.mediaMuted = e.muted; |
103 }} |
106 }} |