Source

django-cloudi / widgets.py

Full commit
from django import forms
from django.utils.safestring import mark_safe


class CloudImages(forms.TextInput):
    class Media:
        js = (
             'fancybox/jquery.fancybox-1.3.4.pack.js',
            )
        css = {
            'screen': ('fancybox/jquery.fancybox-1.3.4.css',),
            }


    def __init__(self, attrs=None):
        self.attrs = {'class': 'cloudimages'}
        if attrs:
            self.attrs.update(attrs)
        super(CloudImages, self).__init__(attrs)

    def render(self, name, value, attrs=None):
        rendered = super(CloudImages, self).render(name, value, attrs)
        return rendered + mark_safe(u'''<script type="text/javascript">
            $(document).ready(function () {
                $('#id_%s').after("<a class='cloudimages' href='/cloud/'>Upload Image</a>");
                $('.cloudimages').fancybox({
                'autoScale'         : false,
                'transitionIn'      : 'none',
                'transitionOut'     : 'none',
                'type'              : 'iframe'
                 });

            });                        
            </script>''' % (name,))