Skip to content

Commit

Permalink
adobeGH-173 add video capability
Browse files Browse the repository at this point in the history
- video component (no group) that outputs one video tag per breakpoint,
- dialog that comes with it,
- add ability to include fields in a responsive loop,
- add video to flex that way
  • Loading branch information
npeltier committed Oct 20, 2020
1 parent af8b20b commit 60f10cc
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,17 @@ public class ResponsiveInclude extends SlingSafeMethodsServlet implements Resour
public static final String RESOURCE_TYPE = "dx/admin/responsive/include";
private static final String PN_TYPE = "resourceType";
private static final String PN_LOOP = "dxResponsiveItem";
private static final String PN_FOLLOW = "dxResponsiveFollow";
private static final String PN_NAME = "name";
private static final String PN_TITLE = "jcr:title";
private static final String PN_PATH = "path";
private static final String PN_DESCRIPTION = "jcr:description";
private static final String PN_INVALID = "invalid";
private static final String SLING_FOLDER = "sling:Folder";
private static final String PN_RESOURCE_TYPE = "sling:" + PN_TYPE;
private static final String MNT_PREFIX = "/mnt/override";
private static final String CONTENT_ROOT = "/content";
private static final String APPS_PREFIX = "/apps/";
private static final String SLASH = "/";

Configuration configuration;
Expand Down Expand Up @@ -289,6 +292,11 @@ void copyTree(Breakpoint[] breakpoints, Node referrer, Resource target, Breakpoi
String name = childConf.getName();
if (breakpoint == null && childConf.hasProperty(PN_LOOP)) {
loopTree(breakpoints, childConf, target);
} else if (breakpoint != null && childConf.hasProperty(PN_FOLLOW) && childConf.hasProperty(PN_PATH)) {
String path = childConf.getProperty(PN_PATH).getString();
path = path.startsWith(SLASH) ? path : APPS_PREFIX + path;
Node followedChildConf = childConf.getSession().getNode(path);
copyTree(breakpoints, followedChildConf, target, breakpoint);
} else {
Node childTarget = targetNode.hasNode(name) ? targetNode.getNode(name) : targetNode.addNode(name, childConf.getPrimaryNodeType().getName());
logger.debug("writing tree {}", childTarget.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public void setup() {
context.registerInjectActivateService(include, "appChange", true,
"dialogRoots", new String[] {"/apps/dx"},
"cacheRoot", CACHE_ROOT_TEST);
String randomPath = "/some/path/with/an/item/container/anotherText";
context.build().resource(randomPath, "sling:resourceType", "text", "name", "./anotherText");
context.build().resource(INCLUDE_ROOT, "sling:resourceType", ResponsiveInclude.RESOURCE_TYPE, "resourceType","dialog/panel")
.siblingsMode()
.resource("items/general", "sling:resourceType", "text", "name","./generalText")
Expand All @@ -71,6 +73,7 @@ public void setup() {
.resource("text", "sling:resourceType", "text", "name", "./respText")
.resource("check", "sling:resourceType", "check", "name", "./check")
.resource("checkType", "sling:resourceType", "checkType", "name", "./check@TypeHint")
.resource("include", "sling:resourceType","someInclude", "path", "/some/path/with/an/item/container", "dxResponsiveFollow", true)
.commit();
context.currentResource(context.resourceResolver().getResource(INCLUDE_ROOT));
context.requestPathInfo().setSuffix(CONTENT_ROOT);
Expand All @@ -82,25 +85,24 @@ public void testPath() {
include.getIncludePath(context.currentResource()));
}

void assertField(String path, String field, String value) {
ValueMap vm = getVM(path);
assertNotNull(vm);
assertEquals(value, vm.get(field));
}

@Test
public void testIncludeResourceBuilding() throws LoginException, RepositoryException {
Resource resource = include.getIncludeResource(include.getBreakpoints(context.request()), context.currentResource());
assertNotNull(resource);
assertEquals(CACHE_ROOT, resource.getPath());
assertEquals("dialog/panel", resource.getValueMap().get("sling:resourceType"));
ValueMap generalItem = getVM(CACHE_ROOT + "/items/general");
assertNotNull(generalItem);
assertEquals("./generalText", generalItem.get("name"));
String tabletItem = CACHE_ROOT + "/items/respTablet";
ValueMap vmTablet = getVM(tabletItem);
assertNotNull(vmTablet);
assertEquals("Tablet", vmTablet.get("jcr:title"));
ValueMap check = getVM(tabletItem + "/items/check");
assertNotNull(check);
assertEquals("./checkTablet", check.get("name"));
ValueMap checkType = getVM(tabletItem + "/items/checkType");
assertNotNull(checkType);
assertEquals("./checkTablet@TypeHint", checkType.get("name"));
String path = CACHE_ROOT + "/items/";
assertField(path + "general","name", "./generalText");
assertField(path + "respTablet","jcr:title", "Tablet");
assertField(path + "respTablet/items/check","name", "./checkTablet");
assertField(path + "respTablet/items/checkType", "name", "./checkTablet@TypeHint");
assertField(path + "respDesktop/items/anotherText", "name", "./anotherTextDesktop");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
jcr:primaryType="cq:Component"
jcr:title="Video"
componentGroup=".dx"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="UTF-8"?>
<jcr:root
xmlns:sling="http://sling.apache.org/jcr/sling/1.0"
xmlns:cq="http://www.day.com/jcr/cq/1.0"
xmlns:granite="http://www.adobe.com/jcr/granite/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
jcr:primaryType="nt:unstructured"
jcr:title="Video"
sling:resourceType="cq/gui/components/authoring/dialog">
<content jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/fixedcolumns">
<items jcr:primaryType="nt:unstructured">
<column
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<items jcr:primaryType="nt:unstructured">
<videoURL
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/pathfield"
fieldLabel="Video"
fieldDescription="Must be an MP4 file."
name="./videoURL"
rootPath="/content/dam">
</videoURL>
<videoLoop
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Loop Video"
checked="{Boolean}true"
value="true"
uncheckedValue="{Boolean}false"
name="./videoLoop">
</videoLoop>
<videoLoopTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
value="Boolean"
name="./videoLoop@TypeHint"/>
<videoPlayOnEnterView
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Play video when it enters the view."
checked="{Boolean}true"
value="true"
uncheckedValue="{Boolean}false"
name="./videoPlayOnEnterView">
</videoPlayOnEnterView>
<videoPlayOnEnterViewTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
value="Boolean"
name="./videoPlayOnEnterView@TypeHint"/>
<videoPlayOnHover
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Play video when a cursor hovers over it."
checked="{Boolean}true"
value="true"
uncheckedValue="{Boolean}false"
name="./videoPlayOnHover">
</videoPlayOnHover>
<videoPlayOnHoverTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
value="Boolean"
name="./videoPlayOnHover@TypeHint"/>
<videoCrop
jcr:primaryType="nt:unstructured"
granite:class="cq-dialog-dropdown-showhide"
sling:resourceType="granite/ui/components/coral/foundation/form/select"
fieldLabel="Cropping"
name="./videoCrop">
<granite:data
jcr:primaryType="nt:unstructured"
cq-dialog-dropdown-showhide-target=".list-option-video-crop"/>
<items jcr:primaryType="nt:unstructured">
<video
jcr:primaryType="nt:unstructured"
text="Crop Video"
value="crop-video"/>
<content
granite:hide="${cqDesign.disableMobileAbsolute}"
jcr:primaryType="nt:unstructured"
text="Crop Content"
value="crop-content"/>
</items>
</videoCrop>
<cropVideoContainer
granite:class="hide list-option-video-crop"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<granite:data
jcr:primaryType="nt:unstructured"
showhidetargetvalue="crop-video"/>
<items jcr:primaryType="nt:unstructured">
<note
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/alert"
size="S"
jcr:title="This will crop the video to fit the size of the component."/>
</items>
</cropVideoContainer>
<cropContentContainer
granite:class="hide list-option-video-crop"
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/container">
<granite:data
jcr:primaryType="nt:unstructured"
showhidetargetvalue="crop-content"/>
<items jcr:primaryType="nt:unstructured">
<note
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/alert"
size="S"
jcr:title="Video will be full-size. If contents go beyond this size, they will be cropped."/>
<videoControls
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/checkbox"
text="Show Controls"
fieldDescription="If checked, content on top of video will not be selectable so controls can be used by the visitor."
value="true"
name="./videoControls"/>
<videoControlsTypeHint
jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/coral/foundation/form/hidden"
value="Boolean"
name="./videoControls@TypeHint"/>
</items>
</cropContentContainer>
</items>
</column>
</items>
</content>
</jcr:root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="video-Wrapper ${properties.videoCrop || 'crop-video'} ${properties.videoPlayOnView ? 'has-playOnView' : ''} ${properties.videoPlayOnHover ? 'has-playOnHover' : ''}"
data-sly-list.bp="${breakpoints}">
<video data-sly-test.src="${resprops.videoURL[bp.key]}" class="${resprops.videoURL.mobile ? 'video-mobile' : ''} ${!resprops.videoURL.tablet ? 'video-tablet' : ''} ${!resprops.videoURL.tablet && !resprops.videoURL.desktop ? 'video-desktop' : ''}"
preload="${wcmmode.disabled ? 'none' : 'metadata'}"
playsinline muted loop="${resprops.videoLoop[bp.key]}" controls="${resprops.videoControls[bp.key]}">
<source src="${src}" type="video/mp4">
</video>
</div>
2 changes: 1 addition & 1 deletion apps/docs/app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>com.adobe.dx</groupId>
<artifactId>core</artifactId>
<version>0.1.0</version>
<version>0.1.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.adobe.dx</groupId>
Expand Down
Loading

0 comments on commit 60f10cc

Please sign in to comment.