Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Liferay 7.2 CE, automatic scroll to full content asset: how to disable it?
I have an Asset Publisher, showing a content detail through a display
page ("Set as the Default Asset Publisher for This
Page" set) and it works great, showing me the content with
the usual URL myportal/-/my-content-name.
So far, so
good...the only problem is that at the end of page loading, the
content is scrolled up to the following anchor injected by Liferay:
...
<div class="asset-full-content clearfix mb-5
default-asset-publisher no-title ">
<span class="asset-anchor lfr-asset-anchor"
id="55130"></span> ... </div>
Is that possible to disable this unwanted behaviour?
Thank you.
I never find where we can change this.
I am interested if you find a solution.
This the only way we found to get rid of that using a classic "widget page" (approved by the support, overwise we would need to use display page) : create a fragment to override the jsp which provide the anchor.
Notes : removing "" doesn't work. The anchor effect is provided by a javascript.To do that, follow the procedure detailed below.
1) Create a new fragment module which I will call "asset-publisher-fragment" (you can create a mvc-portlet if you don't have the fragment template in you IDE, just remove every Java classes and .jsp and only keep the META-INF.ressources folder empty.
2) Edit the bnd.bnd file to add the proper "Fragment-Host" :
Bundle-Name: asset-publisher-fragment
Bundle-SymbolicName: asset.publisher.fragment
Bundle-Version: 1.0.0
Fragment-Host: com.liferay.asset.publisher.web
3) Create a new file "view_content.jsp" in "META-INF.ressources" with the following content :
<%--
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
--%>
<%@ include file="/init.jsp" %>
<liferay-util:dynamic-include key="com.liferay.asset.publisher.web#/view_content.jsp#pre" />
<%
AssetPublisherViewContentDisplayContext assetPublisherViewContentDisplayContext = new AssetPublisherViewContentDisplayContext(renderRequest, assetPublisherDisplayContext.isEnablePermissions());
if (Validator.isNotNull(assetPublisherViewContentDisplayContext.getReturnToFullPageURL())) {
portletDisplay.setURLBack(assetPublisherViewContentDisplayContext.getReturnToFullPageURL());
}
%>
<c:choose>
<c:when test="<%= assetPublisherViewContentDisplayContext.isAssetEntryVisible() %>">
<%
AssetEntry assetEntry = assetPublisherViewContentDisplayContext.getAssetEntry();
AssetRenderer<!--?--> assetRenderer = assetPublisherViewContentDisplayContext.getAssetRenderer();
request.setAttribute("view.jsp-assetEntry", assetEntry);
request.setAttribute("view.jsp-assetRenderer", assetRenderer);
request.setAttribute("view.jsp-assetRendererFactory", assetPublisherViewContentDisplayContext.getAssetRendererFactory());
request.setAttribute("view.jsp-print", assetPublisherViewContentDisplayContext.getPrint());
request.setAttribute("view.jsp-showBackURL", assetPublisherViewContentDisplayContext.isShowBackURL());
PortalUtil.addPortletBreadcrumbEntry(request, assetRenderer.getTitle(locale), currentURL);
String summary = StringUtil.shorten(assetRenderer.getSummary(liferayPortletRequest, liferayPortletResponse), assetPublisherDisplayContext.getAbstractLength());
PortalUtil.setPageDescription(summary, request);
PortalUtil.setPageKeywords(assetHelper.getAssetKeywords(assetEntry.getClassName(), assetEntry.getClassPK()), request);
PortalUtil.setPageTitle(assetRenderer.getTitle(locale), request);
%>
<liferay-util:include page="/view_asset_entry_full_content.jsp" servletContext="<%= application %>" />
</c:when>
<c:otherwise>
<liferay-util:include page="/error.jsp" servletContext="<%= application %>" />
</c:otherwise>
</c:choose>
<liferay-util:dynamic-include key="com.liferay.asset.publisher.web#/view_content.jsp#post" />
Notes : we just removed thisJS part wich annoy us :
<aui:script>
Liferay.once('allPortletsReady', function() {
if (!Liferay.Browser.isIe()) {
document
.getElementById('p_p_id_<%= portletDisplay.getId() %>_')
.scrollIntoView();
}
});
</aui:script>
4) Deploy the module and, that's it.
I will try this... Eric.
Here is my awful solution for this awful behaviour.
Liferay.Browser.isIe = () => true;
This script has to be called as late as possible and this to avoid other Liferay scripts to consider your browser as IE. As the "allPortletsReady" event is fired after the DOM is rendered, this should'nt be a problem.
Hope this helps.
J.
Powered by Liferay™