Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media Previewer #767

Merged
merged 51 commits into from
Sep 30, 2015
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
e95133b
initial stab at preview feature
pandafulmanda Sep 1, 2015
da2418b
stashing changes for now
pandafulmanda Sep 8, 2015
dddb292
basic functionality of link preview in place
pandafulmanda Sep 8, 2015
978c1f3
Merge branch 'master' into feature/link-preview
pandafulmanda Sep 8, 2015
5083319
media previewer shows on hover
pandafulmanda Sep 8, 2015
1587ce5
some media previewer clean up
pandafulmanda Sep 8, 2015
e87f82f
merging in tutor-table mixin yay
pandafulmanda Sep 8, 2015
42a42cd
add table styles to media previewer
pandafulmanda Sep 8, 2015
00d6166
refinement around when to show popover/only show popover when media i…
pandafulmanda Sep 9, 2015
702d49d
make sure popover positions when image content loads, fix table highl…
pandafulmanda Sep 9, 2015
c29963e
cleaning up old method
pandafulmanda Sep 9, 2015
b7cf2e8
make big tables scrollable in preview
pandafulmanda Sep 11, 2015
08c2bdd
popover figures out an optimal placement, left or right based on content
pandafulmanda Sep 11, 2015
5cd9e32
separate popover positioning logic from media previewer specific stuffs
pandafulmanda Sep 11, 2015
7208bfe
merge and resolve print safe
pandafulmanda Sep 11, 2015
279bc72
task can parse exercise html as well, test media flux
pandafulmanda Sep 11, 2015
2dd5adf
test interactions of media previewer
pandafulmanda Sep 11, 2015
3e01316
clean up tests a bit, add tests for tutor popover component, checking…
pandafulmanda Sep 11, 2015
e5e00e9
Merge branch 'master' into feature/link-preview
pandafulmanda Sep 15, 2015
26d04c8
merging in master updates to external linking styling and resolving
pandafulmanda Sep 15, 2015
3241ef2
link to media in refernce book if media not on page
pandafulmanda Sep 15, 2015
dbc6778
tutor popover auto scrollable when content is too tall for window
pandafulmanda Sep 16, 2015
5f1e4d2
make link previewer a loadable
pandafulmanda Sep 16, 2015
d8c9f70
resolve conflicts from styles update
pandafulmanda Sep 17, 2015
07cd1bf
adjust scrollable popover test to fake scrollable sooner
pandafulmanda Sep 17, 2015
fa413cf
i would like this test to pass on travis
pandafulmanda Sep 17, 2015
14312e7
handle links to figures on a different page as well
pandafulmanda Sep 21, 2015
3d910bb
Merge branch 'feature/link-preview' into feature/link-preview-async
pandafulmanda Sep 21, 2015
a0265d6
pull out step reading content to it's own more specifc content so tha…
pandafulmanda Sep 22, 2015
00131f4
link out prop for media previewer
pandafulmanda Sep 22, 2015
4a4be3a
try to help with the finicky-ness of the tests that fake window sizes
pandafulmanda Sep 22, 2015
f10f0a1
tests for async media loading into link previewer
pandafulmanda Sep 22, 2015
805a093
add image loading indication
pandafulmanda Sep 23, 2015
35b0690
relax image on load testing
pandafulmanda Sep 23, 2015
eb2c2f8
Travis, let my tests go.
pandafulmanda Sep 23, 2015
ba26df8
add space to show loading label
pandafulmanda Sep 23, 2015
6fefd7a
resolve conflicts from scrolling pr
pandafulmanda Sep 23, 2015
e53a7e5
clean up scroll to mixin function names, clean up target styling
pandafulmanda Sep 23, 2015
74e96ea
Merge branch 'feature/link-preview' into feature/link-preview-async
pandafulmanda Sep 23, 2015
50183b3
help travis with tests hopefully
pandafulmanda Sep 23, 2015
da0b946
resolve conflicts from parent test updates, clean up faking popover code
pandafulmanda Sep 23, 2015
a667af2
update target to link-target, make tutor-popover more flexible about …
pandafulmanda Sep 28, 2015
d74ae0f
update specs for media preview to use link-target, check for width ov…
pandafulmanda Sep 28, 2015
9ee45a6
allow other content in tutor-popover other than just html string
pandafulmanda Sep 28, 2015
2c7905c
there was some weird thing where isMounted as return false during the…
pandafulmanda Sep 28, 2015
24afed4
fix clone with props warning for media popover
pandafulmanda Sep 28, 2015
5aedd9b
split up image loading tests for popover to make the tests less senst…
pandafulmanda Sep 28, 2015
6e073fd
adjustments to figure out travis
pandafulmanda Sep 28, 2015
c64dfdf
Merge branch 'master' into feature/link-preview-async
pandafulmanda Sep 28, 2015
2af2c83
force images to not be loaded initially in tests
pandafulmanda Sep 29, 2015
ad355da
loosen test for travis
pandafulmanda Sep 29, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions api/tasks/4.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
{
"id": "876",
"formats": ["multiple-choice","free-response"],
"stem_html":"Is the glass half full or half empty?",
"stem_html":"Is the glass half full or half empty in this <a href='#figure-from-another-step'>figure</a>?",
"answers":[
{"id":"id3","content_html":"Half Full"},
{"id":"id4","content_html":"Half Empty"}
Expand All @@ -55,7 +55,7 @@
{ "id": "step-id-4-3",
"type": "reading",
"content_url": "http://archive.cnx.org/contents/3e1fc4c6-b090-47c1-8170-8578198cc3f0@8.html",
"content_html": "<p>MathML rendered by MathJax: <math xmlns='http://www.w3.org/1998/Math/MathML'><mfrac><mi>x</mi><mn>2</mn></math></p><div class='note links-to-physics'><div class='title'>Links to Physics</div><div class='para'><div class='title'>Astrology: Galileo’s Ship</div><figure id='fig25-3'><img src='http://placekitten.com/g/500/300'><figcaption>Galileo Galilei (1564-1642)</figcaption></figure><div class='note grasp-check'><div class='title'>Grasp Check</div><div class='para'>Why did the tennis ball appear to be going straight up and down at the same time that it moved along a curved path?</div></div></div><p>The idea that a description of motion depends on the reference frame of the observer has been known for hundreds of years. The 17th-century astronomer Galileo Galilei <a href='#fig25-3'>[link]</a> was one o</p></div><div class='note tips-for-success'><div class='title'>Tips for Success!</div><div class='para'>In some books x or s is used instead of d to describe position. In addition, a subscript is sometimes used to describe horizontal position, dx, or vertical position, dy.<a href='http://rice.edu'>Rice Link</a></div></div>"
"content_html": "<figure id='figure-from-another-step'><img src='http://placekitten.com/g/200/300'></figure><p>MathML rendered by MathJax: <math xmlns='http://www.w3.org/1998/Math/MathML'><mfrac><mi>x</mi><mn>2</mn></math></p><div class='note links-to-physics'><div class='title'>Links to Physics</div><div class='para'><div class='title'>Astrology: Galileo’s Ship</div><figure id='fig25-3'><img src='http://placekitten.com/g/500/300'><figcaption>Galileo Galilei (1564-1642)</figcaption></figure><div class='note grasp-check'><div class='title'>Grasp Check</div><div class='para'>Why did the tennis ball appear to be going straight up and down at the same time that it moved along a curved path?</div></div></div><p>The idea that a description of motion depends on the reference frame of the observer has been known for hundreds of years. The 17th-century astronomer Galileo Galilei <a href='#fig25-3'>[link]</a> was one o</p></div><div class='note tips-for-success'><div class='title'>Tips for Success!</div><div class='para'>In some books x or s is used instead of d to describe position. In addition, a subscript is sometimes used to describe horizontal position, dx, or vertical position, dy.<a href='http://rice.edu'>Rice Link</a></div></div>"
},
{ "id": "step-id-4-4",
"type": "interactive",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"es6-promise": "^2.3",
"flux-react": "~2.6.4",
"font-awesome": "~4.3.0",
"htmlparser2": "^3.8.3",
"jquery": "^2.1.4",
"markdown-it": "^4.1.1",
"mime-types": "^2.1.3",
Expand Down
21 changes: 4 additions & 17 deletions resources/styles/book-content/base.less
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ div[data-type="document-title"] ~ p:first-of-type {
.tutor-reading-first-letter();
}

.tutor-figure();
figure {
display: table;
text-align: left;
margin-right: 30px;
margin-bottom: 20px;
padding: 0;
float: left;
img {
max-width: 100%;
border: 1px solid @border-color;
margin: 10px 0 0 0;
padding: 0;
}

&.full-width:not(.splash) {
width: 100%;
}
Expand All @@ -74,18 +66,13 @@ figure {
img { width: 100%; }
}
}

figcaption {
display: table-caption;
caption-side: bottom;
color: @caption-font-color;
padding: 10px 0;
font-weight: 300;
font-style: italic;
line-height: 150%;
border-bottom: 1px solid;
border-color: @border-color;
}
}

// images inside a figure that occurs right after a title are full-width
.title + figure {
width: 100%;
Expand Down
51 changes: 38 additions & 13 deletions resources/styles/book-content/target.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,71 @@
background-color: @tutor-highlight;
}

.highlight-target(transition) {
.highlight-target();
.transition(background-color .1s ease-out);
.highlight-target(will-transition) {
.transition(background-color .5s ease-out);
}

a[target=_blank] { .tutor-external-link-indicator(); }

figure {
&:target, .target {
.highlight-target(will-transition);

&:target, &.target, &.target-scroll {
img {
mix-blend-mode: multiply;
}
}
&:target, .target {


&:target, &.target {
.highlight-animation();

> * {
.highlight-animation();
}
}
.target {
.highlight-target(transition);

&.target-scroll {
.highlight-target();

> * {
.highlight-target(transition);
.highlight-target();
}
}

}

section, div, span, table {
&:target, .target {

&::after {
.highlight-target(will-transition);
}

&:target, &.target, &.target-scroll {
position: relative;

img {
mix-blend-mode: multiply;
}

&::after {
content: ' ';
width: 100%;
height: 100%;
position: absolute;
top: 0;
mix-blend-mode: multiply;
}
}
&:target {
.highlight-animation();

&:target, &.target {
&::after {
.highlight-animation();
}
}
.target {
.highlight-target(transition);

&.target-scroll::after {
.highlight-target();
}
}

Expand Down
47 changes: 47 additions & 0 deletions resources/styles/components/media-preview.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.media-preview {
max-width: 50%;

&.scrollable {
.popover-content {
overflow: auto;
width: 100%;
height: inherit;
}
}

.tutor-figure();
.tutor-tables(@tutor-neutral-light, @tutor-neutral-light);

table {
text-align: left;

td {
padding: 4px;
}
}

figure span {
min-height: 1.75rem;
min-width: 100%;
position: relative;
.tutor-subtle-load(will-load; 'Loading...');

&::after {
font-size: 1.75rem;
line-height: 1em;
}
}

.image-loading {
figure {
min-width: 300px;
span {
.tutor-subtle-load(loading);
}
}
}
}

.media-preview-link {
display: inline-block;
}
25 changes: 25 additions & 0 deletions resources/styles/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,31 @@
}
}

.tutor-figure(){
figure {
display: table;
text-align: left;
padding: 0;
float: left;
img {
max-width: 100%;
border: 1px solid @border-color;
margin: 10px 0 0 0;
padding: 0;
}

figcaption {
display: table-caption;
caption-side: bottom;
color: @caption-font-color;
padding: 10px 0;
font-weight: 300;
font-style: italic;
line-height: 150%;
}
}
}

.tutor-tables() {
table {
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions resources/styles/tutor.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
@import './components/tutor-input';
@import './components/reference-book/index';
@import './components/tutor-input';
@import './components/media-preview';

// OLD Global
@import './old/global/buttons';
Expand Down
2 changes: 2 additions & 0 deletions resources/styles/variables/tutor-bootstrap.less
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

@link-hover-color: darken(@link-color, 5%);


@popover-max-width: none;
// //== Scaffolding
// //
// //## Settings for some of the most global styles.
Expand Down
72 changes: 38 additions & 34 deletions src/components/book-content-mixin.cjsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ React = require 'react'
_ = require 'underscore'
S = require '../helpers/string'
dom = require '../helpers/dom'

{MediaPreview} = require './media-preview'
{CourseStore} = require '../flux/course'
{TaskStepStore} = require '../flux/task-step'
{MediaStore} = require '../flux/media'
ScrollTo = require './scroll-to'

# According to the tagging legend exercises with a link should have `a.os-embed`
Expand All @@ -28,18 +31,16 @@ LinkContentMixin =
componentDidUpdate: ->
@processLinks()

componentWillUnmount: ->
@cleanUpLinks()

contextTypes:
router: React.PropTypes.func

getCnxIdOfHref: (href) ->
beforeHash = _.first(href.split('#'))
_.last(beforeHash.split('/'))

getMediaTag: (media) ->
# form media tag text based on data-type or tag name
tag = media.getAttribute('data-type') or media.tagName
S.capitalize(tag)

buildReferenceBookLink: (cnxId) ->
{courseId} = @context.router.getCurrentParams()
{query} = @props
Expand All @@ -61,44 +62,47 @@ LinkContentMixin =
trueHref = link.getAttribute('href')
link.hash.length > 0 and trueHref.substr(0, 1) isnt '#'

linkMediaElsewhere: (mediaCNXId, mediaLink) ->
pageUrl = @buildReferenceBookLink(mediaCNXId)
mediaLink.href = pageUrl + mediaLink.hash
mediaLink.target = '_blank' if @shouldOpenNewTab?()
# do this to ignore this link once adjusted
mediaLink.dataset.targeted = 'media'
getMedia: (mediaId) ->
root = @getDOMNode()
root.querySelector("##{mediaId}")

isMediaOnPage: (link) ->
cleanUpLinks: ->
root = @getDOMNode()
try
media = root.querySelector(link.hash)
previewNodes = root.getElementsByClassName('media-preview-wrapper')

_.each(previewNodes, (previewNode) ->
React.unmountComponentAtNode(previewNode)
)

linkPreview: (link) ->
mediaId = link.hash.replace('#', '')
mediaDOM = @getMedia(mediaId) if mediaId
mediaCNXId = @getCnxIdOfHref(link.getAttribute('href')) or @props.cnxId or @getCnxId?()

previewNode = document.createElement('span')
previewNode.classList.add('media-preview-wrapper')
link.parentNode.replaceChild(previewNode, link)

media?
mediaProps =
mediaId: mediaId
cnxId: mediaCNXId
bookHref: @buildReferenceBookLink(mediaCNXId)
mediaDOMOnParent: mediaDOM
shouldLinkOut: @shouldOpenNewTab?()

mediaPreview = <MediaPreview {...mediaProps}>
{link.innerText}
</MediaPreview>

React.render(mediaPreview, previewNode)

processLink: (link) ->
if @isMediaLink(link)
if not @hasCNXId(link) and @isMediaOnPage(link)
@linkToThisPage(link)
return null
else
@linkToAnotherPage(link)
return null
@linkPreview(link)
return null
else
return link

linkToAnotherPage: (link) ->
mediaCNXId = @getCnxIdOfHref(link.getAttribute('href')) or @props.cnxId or @getCnxId?()
@linkMediaElsewhere(mediaCNXId, link)

linkToThisPage: (link) ->
root = @getDOMNode()
media = root.querySelector(link.hash)
tag = @getMediaTag(media)
link.innerText = tag if link.innerText is '[link]' and tag?
link.target = '_self'
# do this to ignore this link once adjusted
link.dataset.targeted = 'media'

processLinks: ->
_.defer(@_processLinks)

Expand Down
Loading