Skip to content

Commit

Permalink
Remove Cycle2 dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
rodfersou committed Dec 6, 2017
1 parent 21d0856 commit 7906eac
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 75 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Share and Enjoy
- André Nogueira
- Héctor Velarde
- Rodrigo Ferreira de Souza
- `Cycle2 slideshow plugin for jQuery`_
- `Swiper - Most Modern Mobile Touch Slider`_
- Font Awesome (`icon`_)
- Wolfgang Beyer (`Mandelbrot image set`_ used in tests)

Development sponsored by Simples Consultoria.

.. _`Cycle2 slideshow plugin for jQuery`: http://jquery.malsup.com/cycle2/
.. _`Swiper - Most Modern Mobile Touch Slider`: http://idangero.us/swiper/
.. _`icon`: http://fontawesome.io/icon/picture-o/
.. _`Mandelbrot image set`: https://commons.wikimedia.org/wiki/File:Mandel_zoom_00_mandelbrot_set.jpg
17 changes: 2 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,11 @@ If `ftw.zipexport`_ is installed, you will also be able to download all images o
Internals
---------

``Photo Gallery`` uses Cycle2 slideshow plugin for jQuery and it can load its resources from the Plone JS registry if they are present there.
``Photo Gallery`` uses Swiper slideshow plugin for jQuery and it can load its resources from the Plone JS registry if they are present there.

If you're using ``Photo Gallery`` with other packages that use Cycle2 also (like `collective.nitf`_ or `covertile.cycle2`_),
it is highly recommended that you register those resources to load them once and avoid conflicts.

You can use a ``jsregistry.xml`` file that includes the following:

.. code-block:: xml
<javascript id="++resource++collective.js.cycle2/jquery.cycle2.min.js"
cacheable="True" compression="none" cookable="True" enabled="True" />
<javascript id="++resource++collective.js.cycle2/jquery.cycle2.carousel.min.js"
cacheable="True" compression="none" cookable="True" enabled="True" />
<javascript id="++resource++collective.js.cycle2/jquery.cycle2.swipe.min.js"
cacheable="True" compression="none" cookable="True" enabled="True" />
If you're using ``Photo Gallery`` with other packages that use Swiper also (like `collective.nitf`_).

.. _`collective.nitf`: https://pypi.python.org/pypi/collective.nitf
.. _`covertile.cycle2`: https://pypi.python.org/pypi/covertile.cycle2

Not Entirely Unlike
===================
Expand Down
7 changes: 0 additions & 7 deletions src/sc/photogallery/browser/templates/view.pt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
metal:use-macro="context/main_template/macros/master"
i18n:domain="sc.photogallery">
<head>
<metal:javascriptslot fill-slot="javascript_head_slot">
<tal:scripts repeat="js view/js_resources">
<script tal:attributes="src string:${portal_url}/${js}"></script>
</tal:scripts>
</metal:javascriptslot>
</head>
<body>
<metal:block fill-slot="content-core" tal:define="is_empty view/is_empty">
<tal:text define="text context/text/output|nothing">
Expand Down
3 changes: 1 addition & 2 deletions src/sc/photogallery/browser/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from sc.photogallery.config import HAS_ZIPEXPORT
from sc.photogallery.interfaces import IPhotoGallerySettings
from sc.photogallery.utils import last_modified
from sc.photogallery.utils import PhotoGalleryMixin
from zope.component import getMultiAdapter

import os
Expand All @@ -17,7 +16,7 @@
from ftw.zipexport.interfaces import IZipRepresentation


class View(DefaultView, PhotoGalleryMixin):
class View(DefaultView):
"""Slideshow view for Photo Gallery content type."""

def id(self):
Expand Down
7 changes: 0 additions & 7 deletions src/sc/photogallery/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@

PROJECTNAME = 'sc.photogallery'

# Cycle2 JS resources used by the package
JS_RESOURCES = (
'++resource++collective.js.cycle2/jquery.cycle2.min.js',
'++resource++collective.js.cycle2/jquery.cycle2.carousel.min.js',
'++resource++collective.js.cycle2/jquery.cycle2.swipe.min.js',
)

HAS_ZIPEXPORT = True
try:
pkg_resources.get_distribution('ftw.zipexport')
Expand Down
4 changes: 0 additions & 4 deletions src/sc/photogallery/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def setUpZope(self, app, configurationContext):
import ftw.zipexport
self.loadZCML(package=ftw.zipexport)

import collective.js.cycle2
self.loadZCML(package=collective.js.cycle2)

import sc.photogallery
self.loadZCML(package=sc.photogallery)

Expand All @@ -71,7 +68,6 @@ def setUpPloneSite(self, portal):
if HAS_ZIPEXPORT:
self.applyProfile(portal, 'ftw.zipexport:default')

self.applyProfile(portal, 'collective.js.cycle2:default')
self.applyProfile(portal, 'sc.photogallery:default')

current_dir = os.path.abspath(os.path.dirname(__file__))
Expand Down
6 changes: 0 additions & 6 deletions src/sc/photogallery/tests/test_photogallery_tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,3 @@ def test_render_photogallery(self):
self.portal, 'Photo Gallery', 'g1')
self.tile.populate_with_object(g1)
self.assertIn(u'slideshow-player', self.tile())

def test_render_js_resources(self):
from sc.photogallery.config import JS_RESOURCES
rendered = self.tile()
for js in JS_RESOURCES:
self.assertIn(js, rendered)
6 changes: 0 additions & 6 deletions src/sc/photogallery/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ def _enable_download(self):
record = IPhotoGallerySettings.__identifier__ + '.enable_download'
api.portal.set_registry_record(record, True)

def test_render_js_resources(self):
from sc.photogallery.config import JS_RESOURCES
rendered = self.view()
for js in JS_RESOURCES:
self.assertIn(js, rendered)

def test_can_download(self):
self.assertFalse(self.view.can_download)
self._enable_download()
Expand Down
5 changes: 0 additions & 5 deletions src/sc/photogallery/tiles/photogallery.pt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="sc.photogallery">
<head tal:define="portal_url context/@@plone_portal_state/portal_url">
<tal:scripts repeat="js view/js_resources">
<script tal:attributes="src string:${portal_url}/${js}"></script>
</tal:scripts>
</head>
<body tal:define="is_empty nocall:view/is_empty">
<p tal:condition="python:is_empty and view.is_compose_mode()">
Drag&amp;drop a Photo Gallery here.
Expand Down
3 changes: 1 addition & 2 deletions src/sc/photogallery/tiles/photogallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from plone.uuid.interfaces import IUUID
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from sc.photogallery import _
from sc.photogallery.utils import PhotoGalleryMixin
from zope import schema
from zope.interface import implementer

Expand All @@ -24,7 +23,7 @@ class IPhotoGalleryTile(IPersistentCoverTile):


@implementer(IPhotoGalleryTile)
class PhotoGalleryTile(PersistentCoverTile, PhotoGalleryMixin):
class PhotoGalleryTile(PersistentCoverTile):

"""A tile that shows a photo gallery."""

Expand Down
19 changes: 0 additions & 19 deletions src/sc/photogallery/utils.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
# -*- coding: utf-8 -*-
from plone import api
from sc.photogallery.config import JS_RESOURCES


class PhotoGalleryMixin:

"""Common methods and functions used by views and and tiles."""

def js_resources(self):
"""Return a list of JS resources that are not available in the
registry, but need to be loaded anyway. This way the slideshow
could use resources registered locally or globally.
:returns: list of ids
:rtype: list
"""
js_registry = api.portal.get_tool('portal_javascripts')
global_resources = js_registry.getResourceIds()
return [r for r in JS_RESOURCES if r not in global_resources]


def last_modified(context):
Expand Down

0 comments on commit 7906eac

Please sign in to comment.