Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add outputfilter to enable croppingeditor link on editable images
- Loading branch information
Showing
8 changed files
with
98 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/plone/app/imagecropping/browser/static/editor_overlay.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function($) { | ||
$(function() { | ||
$("a.croppingeditor").prepOverlay({ | ||
subtype:'ajax', | ||
formselector:'#coords', | ||
closeselector:"input[name='form.button.Cancel']" | ||
}); | ||
$(document).bind("formOverlayLoadSuccess", function() { | ||
imagecropping.init_editor(); | ||
}) | ||
}) | ||
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
''' | ||
Created on 15.04.2013 | ||
@author: peterm | ||
''' | ||
from Products.CMFCore.utils import _checkPermission | ||
from plone.outputfilters.interfaces import IFilter | ||
from zope.component import adapter | ||
from zope.interface import Interface, implementer | ||
from zope.publisher.interfaces import IRequest | ||
import re | ||
|
||
|
||
img_tag = re.compile(r"<img[^>]*>") | ||
src_attr = re.compile(r'src="([^"]*)"') | ||
|
||
|
||
@adapter(Interface, IRequest) | ||
@implementer(IFilter) | ||
class CroppingEditorLink(object): | ||
|
||
# important, that our order is before | ||
# resolveuid_and_caption filter order=800 | ||
# so we can read the scale out of the src attribute | ||
# XXX: there might be a better approach to do this | ||
order = 700 | ||
|
||
def __init__(self, context, request): | ||
self.context = context | ||
self.request = request | ||
|
||
def is_enabled(self): | ||
return _checkPermission("Modify portal content", self.context) | ||
|
||
def __call__(self, data): | ||
img_tags = img_tag.findall(data) | ||
for tag in img_tags: | ||
src = src_attr.search(tag).groups(0) | ||
if len(src) > 0: | ||
x, uuid, x, field, scale = src[0].split("/") | ||
editor_link = \ | ||
"""<a href="resolveuid/%(uid)s/@@croppingeditor?""" \ | ||
"""fieldname=%(field)s&scalename=%(scale)s&""" \ | ||
"""hide_scales=1" class="croppingeditor">%(tag)s</a>""" % \ | ||
dict(uid=uuid, field=field, scale=scale, tag=tag) | ||
data = data.replace(tag, editor_link) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?xml version="1.0"?> | ||
<object name="portal_javascripts"> | ||
|
||
<javascript id="++resource++plone.app.imagecropping.static/editor_overlay.js" | ||
enabled="1" compression="safe" authenticated="True" cacheable="True" | ||
cookable="True" expression="" inline="False" /> | ||
</object> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<metadata> | ||
<version>0003</version> | ||
<version>0004</version> | ||
</metadata> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters