Added default renderer for image-map portlet
authorThierry Florac <tflorac@ulthar.net>
Fri, 18 Oct 2019 15:22:23 +0200
changeset 493 d7a2c90c7223
parent 492 a6c596f03f3a
child 494 360c04c76995
Added default renderer for image-map portlet
src/pyams_default_theme/shared/imagemap/portlet/__init__.py
src/pyams_default_theme/shared/imagemap/portlet/templates/imagemap-default.pt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/imagemap/portlet/__init__.py	Fri Oct 18 15:22:23 2019 +0200
@@ -0,0 +1,39 @@
+#
+# Copyright (c) 2008-2019 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+from zope.interface import Interface
+
+from pyams_content.component.association.interfaces import IAssociationInfo
+from pyams_content.shared.imagemap.portlet import IImageMapPortletSettings
+from pyams_portal.interfaces import IPortalContext, IPortletRenderer
+from pyams_portal.portlet import PortletRenderer
+from pyams_skin.layer import IPyAMSLayer
+from pyams_template.template import template_config
+from pyams_utils.adapter import adapter_config
+
+
+__docformat__ = 'restructuredtext'
+
+from pyams_default_theme import _
+
+
+@adapter_config(context=(IPortalContext, IPyAMSLayer, Interface, IImageMapPortletSettings),
+                provides=IPortletRenderer)
+@template_config(template='templates/imagemap-default.pt', layer=IPyAMSLayer)
+class ImageMapPortletDefaultRenderer(PortletRenderer):
+    """Image map portlet default renderer"""
+
+    label = _("Responsive SVG image map")
+    weight = 1
+
+    def get_item_info(self, item):
+        return IAssociationInfo(item, None)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_default_theme/shared/imagemap/portlet/templates/imagemap-default.pt	Fri Oct 18 15:22:23 2019 +0200
@@ -0,0 +1,31 @@
+<div i18n:domain="pyams_default_theme"
+	 tal:define="settings view.settings;
+				 imagemap settings.target;">
+	<h2 tal:define="title i18n:settings.title"
+		tal:condition="title">${title}</h2>
+	<div class="wrapper-imagemap"
+		 tal:define="image i18n:imagemap.image;"
+		 tal:condition="image">
+		<img src="${tales:absolute_url(image)}" alt="" />
+		<svg version="1.1"
+			 xmlns="http://www.w3.org/2000/svg"
+			 xmlns:xlink="http://www.w3.org/1999/xlink"
+			 class="imagemap-areas"
+			 tal:define="size image.get_image_size()"
+			 viewBox="0 0 ${size[0]} ${size[1]}">
+			<tal:loop repeat="area imagemap.areas.values()">
+				<tal:var define="item imagemap.get_association(area)"
+						 condition="item and item.visible">
+					<a tal:define="info view.get_item_info(item);
+								   area_title i18n:area.title;
+								   item_title i18n:info.user_title;
+								   title area_title or item_title;"
+					   xlink:href="${item.get_url(request)}"
+					   xlink:title="${title}">
+						<polygon points="${area.svg_points}" />
+					</a>
+				</tal:var>
+			</tal:loop>
+		</svg>
+	</div>
+</div>