Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
61 changes: 38 additions & 23 deletions src/main/webapp/WEB-INF/apsadmin/jsp/portal/previewPage.jsp
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="wp" uri="/aps-core" %>

<s:set var="currentSize" value="screenSize" />

<c:set var="currentUsernameVar" value="${sessionScope.currentUser}" />
<s:set var="currentUsernameVar" value="#attr.currentUsernameVar" />
<c:if test="${null != sessionScope.currentUser.profile}">
<c:set var="currentUsernameVar" value="${sessionScope.currentUser.profile.displayName}" />
</c:if>

<wp:ifauthorized permission="reviewer" var="hasReviewPermission" />
<s:set var="hasReviewPermission" value="#attr.hasReviewPermission" />

<s:set var="langstr">[<s:iterator value="langs" status="langstatus">{"code": "<s:property value="code" />", "descr": "<s:property value="descr" />"}<s:if test="!#langstatus.last">,</s:if></s:iterator>]</s:set>

<html>
<head>
<link rel="stylesheet" type="text/css" href="<wp:resourceURL />administration/patternfly/css/patternfly.min.css"/>
<link rel="stylesheet" type="text/css" href="<wp:resourceURL />administration/css/pages/previewPage.css"/>
<link rel="stylesheet" type="text/css" href="<wp:resourceURL />administration/preview-components/static/css/main.d69a348f.chunk.css"/>
<link rel="stylesheet" type="text/css" href="<wp:resourceURL />administration/preview-components/static/css/2.416eeee3.chunk.css"/>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script>
Expand All @@ -15,35 +29,36 @@
token: '<s:property value="token" />',
pageCode: '<s:property value="pageCode" />',
previewWidth: '<s:property value="#currentSize.width" />',
previewHeight: '<s:property value="#currentSize.width" />'
previewHeight: '<s:property value="#currentSize.height" />',
languages: '<s:property value="langstr" />',
};
</script>
<script src="<wp:resourceURL />administration/preview-components/static/js/2.54bba170.chunk.js"></script>
<script src="<wp:resourceURL />administration/preview-components/static/js/main.2bb14483.chunk.js"></script>
<script src="<wp:resourceURL />administration/preview-components/static/js/runtime-main.4b714230.js"></script>
<script src="<wp:resourceURL />administration/js/pages/previewPage.js"></script>
</head>
<body>
<preview-control-bar
id="controlBar"
app-builder-domain="<wp:info key="systemParam" paramName="appBuilderBaseURL" />"
resolution-width="<s:property value="#currentSize.width" />"
resolution-height="<s:property value="#currentSize.height" />"
user-logged="${currentUsernameVar}"
languages="<s:property value="langstr" escapeHtml="true" />"
current-lang="<s:property value="lang" />"
locale="<s:property value="lang" />"
has-permission-review="${hasReviewPermission}"
></preview-control-bar>
<div class="main-container">
<iframe id="previewFrame">
</iframe>
</div>
<div class="bottom-bar">
<label for="preview-mode-select"><s:text name="previewPage.previewMode" /></label>
<select id="preview-mode-select" class="preview-mode-select">
<option value="desktop"><s:text name="previewPage.option.desktop" /></option>
<option value="tablet"><s:text name="previewPage.option.tablet" /></option>
<option value="smartphone"><s:text name="previewPage.option.smartphone" /></option>
<option value="custom"><s:text name="previewPage.option.custom" /></option>
</select>

<div class="custom-panel">
<input class="custom-width" onkeypress="return event.charCode >= 48 && event.charCode <= 57"/>
x
<input class="custom-height" onkeypress="return event.charCode >= 48 && event.charCode <= 57"/>
<button class="btn custom-size-btn"><s:text name="label.ok" /></button>
<div class="preview-area">
<iframe id="previewFrame">
</iframe>
</div>

<label for="preview-mode-lang"><s:text name="previewPage.lang" /></label>
<s:select list="langs" id="preview-mode-lang" name="lang" listKey="code" listValue="descr"></s:select>

<preview-comments-bar
locale="<s:property value="lang" />"
has-permission-review="${hasReviewPermission}"
></preview-comments-bar>
</div>
</body>
</html>
Expand Down
54 changes: 10 additions & 44 deletions src/main/webapp/resources/administration/css/pages/previewPage.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,24 @@ html, body {

.main-container {
text-align: center;
padding-bottom: 60px;
display: flex;
}

#previewFrame {
background: #fff;
max-height: calc(100vh - 50px);
}

.bottom-bar {
position: fixed;
bottom: 0;
width: 100%;
height: 50px;
background: #dcdadc;
text-align: center;
}

.bottom-bar label[for="preview-mode-select"] {
margin: 0 20px;
height: 50px;
line-height: 50px;
}

.bottom-bar .preview-mode-select {
display: inline-block;
width: 200px;
margin: 0 10px;
}

.bottom-bar .custom-panel {
display: inline-block;
background: #fff;
border: 1px solid #777;
padding: 5px;
margin: 5px 20px 5px 5px;
}

.bottom-bar .custom-panel .custom-width,
.bottom-bar .custom-panel .custom-height {
width: 60px;
height: 20px;
text-align: center;
margin: 2px 5px;
.preview-area {
flex: 1;
}

.bottom-bar .custom-panel .custom-size-btn {
background: #31a2de;
color: #fff;
height: 24px;
margin-top: -2px;
margin-left: 5px;
.main-container preview-comments-bar {
width: 0;
transition: width .1s;
overflow: hidden;
}

#preview-mode-lang {
margin-left: 10px;
.main-container.show-comments preview-comments-bar {
width: 287px;
}
151 changes: 59 additions & 92 deletions src/main/webapp/resources/administration/js/pages/previewPage.js
Original file line number Diff line number Diff line change
@@ -1,97 +1,64 @@
$(function () {



var sizeMap = {
desktop: {
width: '100%',
height: '100%'
},
tablet: {
width: '768px',
height: '1024px'
},
smartphone: {
width: '360px',
height: '640px'
}
};
var customSizes = {};

var $customPanel = $('.custom-panel'),
$customWidthInput = $customPanel.find('.custom-width'),
$customHeightInput = $customPanel.find('.custom-height'),
$customOkBtn = $('.custom-size-btn'),
$previewModeSelect = $('.preview-mode-select'),
$langSelect = $('#preview-mode-lang'),
$previewFrame = $('iframe#previewFrame');



function updatePreviewSize() {
var key = $previewModeSelect.val(),
width, height;

if (key === 'custom') {
$customWidthInput.removeAttr('disabled');
$customHeightInput.removeAttr('disabled');

customSizes = {
width: customSizes.width || $customWidthInput.val() || 100,
height: customSizes.height || $customHeightInput.val() || 100
};
width = customSizes.width + 'px';
height = customSizes.height + 'px';
$customWidthInput.val(customSizes.width);
$customHeightInput.val(customSizes.height);

} else if (key && sizeMap[key]) {
$customWidthInput.attr('disabled', 'disabled');
$customHeightInput.attr('disabled', 'disabled');

width = sizeMap[key].width;
height = sizeMap[key].height;
$customWidthInput.val(width);
$customHeightInput.val(height);
}
$previewFrame
.attr('width', width)
.attr('height', height);

const sizeOptions = {
desktop: {
width: '100%',
height: '100%'
},
tablet: {
width: '768px',
height: '1024px'
},
smartphone: {
width: '360px',
height: '640px'
}
};

var previewFrame, mainContainer, controlBar, commentBar, commentsOpened = false;

function updateIframeUrl() {
var normalizedBaseUrl = PROPERTY.baseUrl.replace(/\/$/, ''),
previewUrl = [normalizedBaseUrl, 'preview', PROPERTY.lang, PROPERTY.pageCode].join('/');
previewUrl += '?' + [ 'token='+encodeURIComponent(PROPERTY.token) ].join('&');

$previewFrame.attr('src', previewUrl);
const toggleCommentsBar = (open = false) => {
commentsOpened = open;
if (commentsOpened) {
mainContainer.classList.add('show-comments');
} else {
mainContainer.classList.remove('show-comments');
}


updateIframeUrl();
$customWidthInput.val(PROPERTY.previewWidth);
$customHeightInput.val(PROPERTY.previewHeight);
$previewModeSelect.val('custom');
$langSelect.val(PROPERTY.lang);

updatePreviewSize();

};


$previewModeSelect.change(function () {
updatePreviewSize();
});

$langSelect.change(function(){
PROPERTY.lang = $langSelect.val();
updateIframeUrl();

});

$customOkBtn.click(function() {
updatePreviewSize();
});

});
const handleChangePreviewSize = (ev) => {
const { width, height } = ev && ev.detail || {
width: PROPERTY.previewWidth,
height: PROPERTY.previewHeight,
};
previewFrame.setAttribute('width', width.replace(/px/i, ''));
previewFrame.setAttribute('height', height.replace(/px/i, ''));
};

const handleCloseComments = () => {
toggleCommentsBar(false);
controlBar.setAttribute('comments-opened', 'false');
};

const handleChangeIframeUrl = (ev) => {
const lang = ev && ev.detail || PROPERTY.lang;
var normalizedBaseUrl = PROPERTY.baseUrl.replace(/\/$/, ''),
previewUrl = [normalizedBaseUrl, 'preview', lang, PROPERTY.pageCode].join('/');
previewUrl += '?' + [ 'token='+encodeURIComponent(PROPERTY.token) ].join('&');

previewFrame.setAttribute('src', previewUrl);
}

const pageReady = () => {
previewFrame = document.getElementById('previewFrame');
mainContainer = document.querySelector('.main-container');
controlBar = document.getElementById('controlBar');
commentBar = document.querySelector('preview-comments-bar');
controlBar.addEventListener(PreviewControlBarEvent.RESOLUTION_CHANGE, handleChangePreviewSize);
controlBar.addEventListener(PreviewControlBarEvent.CHANGE_LANGUAGE, handleChangeIframeUrl);
controlBar.addEventListener(PreviewControlBarEvent.COMMENT_TOGGLE, ({ detail }) => toggleCommentsBar(detail));

commentBar.addEventListener(PreviewCommentsBarEvent.COMMENT_CLOSE, handleCloseComments);
handleChangeIframeUrl();
handleChangePreviewSize();
}

document.addEventListener("DOMContentLoaded", pageReady);

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading