Commits

Alexandre Rossi committed 1266db6

single page themes support

Comments (0)

Files changed (19)

 
     <variablelist>
 
-      <varlistentry>
-        <term><filename><replaceable>theme</replaceable>/browse.thtml</filename></term>
-        <listitem>
-            <para>The XHTML template for the theme browse page (displaying
-            one picture).</para>
-        </listitem>
-      </varlistentry>
+        <varlistentry>
+            <term><filename><replaceable>theme</replaceable>/browse.thtml</filename></term>
+            <listitem>
+                <para>The XHTML template for the theme browse page (displaying
+                one picture).</para>
+            </listitem>
+        </varlistentry>
 
-      <varlistentry>
-        <term><filename><replaceable>theme</replaceable>/dirindex.thtml</filename></term>
-        <listitem>
-            <para>The XHTML template for the directory index page (pictures
-            and sub-galleries links).</para>
-        </listitem>
-      </varlistentry>
+        <varlistentry>
+            <term><filename><replaceable>theme</replaceable>/dirindex.thtml</filename> or <filename><replaceable>theme</replaceable>/dynindex.thtml</filename></term>
+            <listitem>
+                <para>The XHTML template for the directory index page (pictures
+                and sub-galleries links).</para>
+            </listitem>
+        </varlistentry>
 
     </variablelist>
 
+    <para>Depending on which index file is present, the theme will be:</para>
+
+    <variablelist>
+        <varlistentry>
+            <term><filename>dirindex.thtml</filename>: fully static</term>
+            <listitem>
+                <para>one HTML page per picture, per size and one index per
+                size, or</para>
+            </listitem>
+        </varlistentry>
+
+        <varlistentry>
+            <term><filename>dynindex.thtml</filename>: dynamic</term>
+            <listitem>
+                <para>only one index per directory is to be generated.</para>
+            </listitem>
+        </varlistentry>
+    </variablelist>
+
     <para>Missing template files will be searched for in the
     <parameter>default</parameter> theme.</para>
 

lazygal/generators.py

         sys.exit(1)
 
 
-THEME_DIR = os.path.join(DATAPATH, 'themes')
-USER_THEME_DIR = os.path.expanduser(os.path.join('~', '.lazygal', 'themes'))
-THEME_SHARED_FILE_PREFIX = 'SHARED_'
 DEST_SHARED_DIRECTORY_NAME = 'shared'
 
 
             if self.webgal.original and not self.webgal.orig_base:
                 self.add_dependency(self.get_original())
 
-            self.browse_pages[size_name] = self.get_browse_page(size_name)
-            if self.webgal.album.force_gen_pages:
-                self.browse_pages[size_name].stamp_delete()
+            if self.webgal.album.theme.kind == 'static':
+                self.browse_pages[size_name] = self.get_browse_page(size_name)
+                if self.webgal.album.force_gen_pages:
+                    self.browse_pages[size_name].stamp_delete()
 
     def set_next(self, media):
         self.next = media
 
     def get_original_or_symlink(self):
         if not self.webgal.orig_symlink:
-            return genfile.MediaOriginal(self.webgal, self.media)
+            return genfile.CopyMediaOriginal(self.webgal, self.media)
         else:
             return genfile.SymlinkMediaOriginal(self.webgal, self.media)
 
             self.original = self.get_original_or_symlink()
         return self.original
 
+    def get_browse_page(self, size_name):
+        return genpage.WebalbumBrowsePage(self.webgal, size_name, self)
+
 
 class WebalbumImageTask(WebalbumMediaTask):
     """
         if self.webgal.newsizers[size_name] == 'original':
             return self.get_original_or_symlink()
         else:
-            return genmedia.ImageOtherSize(self.webgal, self.media, size_name)
-
-    def get_browse_page(self, size_name):
-        return genpage.WebalbumImagePage(self.webgal, size_name, self)
+            sized = genmedia.ImageOtherSize(self.webgal, self.media, size_name)
+            self.media.get_size() # probe size to check if media is broken
+            if not self.media.broken\
+            and sized.get_size() == sized.source_media.get_size():
+                # Do not process if size is the same
+                return self.get_original()
+            else:
+                return sized
 
 
 class WebalbumVideoTask(WebalbumMediaTask):
 
         self.add_dependency(self.webvideo)
 
-    def get_browse_page(self, size_name):
-        return genpage.WebalbumVideoPage(self.webgal, size_name, self)
-
     def get_resized(self, size_name):
         if not self.webvideo:
             self.webvideo = genmedia.WebVideo(self.webgal, self.media,
         self.default_size_name = self.browse_sizes[0]
 
         self.tpl_vars = self.__load_tpl_vars()
-        styles = self.album.get_avail_styles(
-            self.album.theme, self.config.get('webgal', 'default-style'))
+        styles = self.album.theme.get_avail_styles(
+            self.config.get('webgal', 'default-style'))
         self.tpl_vars.update({'styles': styles})
 
         self.set_original(self.config.getboolean('webgal', 'original'),
 
         self.expected_shared_files = []
         for shared_file in glob.glob(
-                os.path.join(self.album.tpl_dir,
-                             THEME_SHARED_FILE_PREFIX + '*')):
+                os.path.join(self.album.theme.tpl_dir,
+                             tpl.THEME_SHARED_FILE_PREFIX + '*')):
             shared_file_name = os.path.basename(shared_file).\
-                replace(THEME_SHARED_FILE_PREFIX, '')
+                replace(tpl.THEME_SHARED_FILE_PREFIX, '')
             shared_file_dest = os.path.join(self.path,
                                             shared_file_name)
 
-            if self.album.tpl_loader.is_known_template_type(shared_file):
+            if self.album.theme.tpl_loader.is_known_template_type(shared_file):
                 sf = genpage.SharedFileTemplate(album, shared_file,
                                                 shared_file_dest,
                                                 tpl_vars)
         self.clean_dest = self.config.getboolean('global', 'clean-destination')
         self.force_gen_pages = self.config.getboolean('global', 'force-gen-pages')
 
-        self.tpl_loader = None
-
         self.set_theme(self.config.get('global', 'theme'))
 
         self.dir_flattening_depth = self.config.getint('global', 'dir-flattening-depth')
 
-    def set_theme(self, theme=tpl.DEFAULT_TEMPLATE):
-        self.theme = theme
-
-        # First try user directory
-        self.tpl_dir = os.path.join(USER_THEME_DIR, self.theme)
-        if not os.path.exists(self.tpl_dir):
-            # Fallback to system themes
-            self.tpl_dir = os.path.join(THEME_DIR, self.theme)
-            if not os.path.exists(self.tpl_dir):
-                raise ValueError(_('Theme %s not found') % self.theme)
-
-        self.tpl_loader = tpl.TplFactory(os.path.join(THEME_DIR,
-                                                      tpl.DEFAULT_TEMPLATE),
-                                         self.tpl_dir)
-
-        # Load styles templates
-        for style in self.get_avail_styles(theme):
-            style_filename = style['filename']
-            try:
-                self.tpl_loader.load(style_filename)
-            except ValueError:
-                # Not a known emplate ext, ignore
-                pass
-
-    def get_avail_styles(self, theme, default_style=None):
-        style_files_mask = os.path.join(self.tpl_dir,
-                                        THEME_SHARED_FILE_PREFIX + '*' + 'css')
-        styles = []
-        for style_tpl_file in glob.glob(style_files_mask):
-            style = {}
-            tpl_filename = os.path.basename(style_tpl_file).split('.')[0]
-            style['filename'] = tpl_filename[len(THEME_SHARED_FILE_PREFIX):]
-            style['name'] = self._str_humanize(style['filename'])
-            if default_style is not None:
-                if style['filename'] == default_style:
-                    style['rel'] = 'stylesheet'
-                else:
-                    style['rel'] = 'alternate stylesheet'
-            styles.append(style)
-        return styles
+    def set_theme(self, theme=tpl.DEFAULT_THEME):
+        self.theme = tpl.Theme(os.path.join(DATAPATH, 'themes'), theme)
 
     def _str_humanize(self, text):
         dash_replaced = text.replace('_', ' ')

lazygal/genfile.py

 import pathutils
 
 
-class MediaOriginal(make.FileCopy):
-
-    def __init__(self, dir, source_media):
-        self.dir = dir
-        self.source_media = source_media
-
-        self.filename = source_media.filename
-
-        self.path = os.path.join(self.dir.path, self.filename)
-        make.FileCopy.__init__(self, source_media.path, self.path)
-
-    def get_size(self):
-        return self.source_media.get_size()
-
-    def build(self):
-        logging.info("  CP %s" % self.filename)
-        logging.debug("(%s)" % self.path)
-        make.FileCopy.build(self)
-
-
-class SymlinkMediaOriginal(make.FileSymlink):
-
-    def __init__(self, dir, source_media):
-        self.dir = dir
-        self.source_media = source_media
-
-        self.filename = source_media.filename
-
-        self.path = os.path.join(self.dir.path, self.filename)
-        make.FileSymlink.__init__(self, source_media.path, self.path)
-
-    def get_size(self):
-        return self.source_media.get_size()
-
-    def build(self):
-        logging.info("  SYMLINK %s" % self.filename)
-        logging.debug("(%s)" % self.path)
-        make.FileSymlink.build(self)
-
-
 class WebalbumFile(make.FileMakeObject):
 
     def __init__(self, path, dir):
-        make.FileMakeObject.__init__(self, path)
+        super(WebalbumFile, self).__init__(path)
         self.dir = dir
         self.path = path
 
             return ret
 
 
+class MediaOriginal(WebalbumFile):
+
+    def __init__(self, dir, source_media):
+        self.filename = source_media.filename
+        path = os.path.join(dir.path, self.filename)
+        super(MediaOriginal, self).__init__(path, dir)
+
+        self.source_media = source_media
+
+        self.set_dep_only()
+
+    def get_size(self):
+        return self.source_media.get_size()
+
+
+class CopyMediaOriginal(MediaOriginal):
+
+    def __init__(self, dir, source_media):
+        super(CopyMediaOriginal, self).__init__(dir, source_media)
+        self.add_dependency(make.FileCopy(self.source_media.path, self.path))
+
+    def build(self):
+        logging.info("  CP %s" % self.filename)
+        logging.debug("(%s)" % self.path)
+
+
+class SymlinkMediaOriginal(MediaOriginal):
+
+    def __init__(self, dir, source_media):
+        super(SymlinkMediaOriginal, self).__init__(dir, source_media)
+        self.add_dependency(make.FileSymlink(self.source_media.path, self.path))
+
+    def build(self):
+        logging.info("  SYMLINK %s" % self.filename)
+        logging.debug("(%s)" % self.path)
+
+
 class WebalbumArchive(WebalbumFile):
 
     def __init__(self, webgal_dir):

lazygal/genpage.py

 import pathutils
 import genfile
 import feeds
+import tplvars
 
 
 class WebalbumPage(genfile.WebalbumFile):
         self.page_template = self.load_tpl(tpl_ident)
 
     def load_tpl(self, tpl_ident):
-        tpl = self.dir.album.tpl_loader.load(tpl_ident)
+        tpl = self.dir.album.theme.tpl_loader.load(tpl_ident)
         self.add_file_dependency(tpl.path)
         for subtpl in tpl.subtemplates():
             self.add_file_dependency(subtpl.path)
         tpl_values.update(self.dir.tpl_vars)
         return tpl_values
 
-    def _gen_other_media_link(self, media):
-        if media:
-            link_vals = {}
-
-            link_vals['type'] = media.media.type
-
-            link_vals['link'] = media.browse_pages[self.size_name].rel_path(self.dir, url=True)
-            link_vals['link'] = self.url_quote(link_vals['link'])
-
-            link_vals['thumb'] = media.thumb.rel_path(self.dir, url=True)
-            link_vals['thumb'] = self.url_quote(link_vals['thumb'])
-
-            if not media.media.broken:
-                link_vals['thumb_width'],\
-                    link_vals['thumb_height'] = media.thumb.get_size()
-
-            link_vals['thumb_name'] = self.dir.album._str_humanize(media.media.name)
-
-            return link_vals
-        else:
-            return None
-
     def _get_osize_links(self, filename):
         osize_index_links = []
         for osize_name in self.dir.browse_sizes:
 
         return osize_index_links
 
-    def _get_webgal_id(self, srcdir_path):
-        if self.dir.should_be_flattened(srcdir_path):
-            rawid = self.dir.source_dir.rel_path(self.dir.flattening_srcpath(srcdir_path), srcdir_path)
-        else:
-            rawid = os.path.basename(srcdir_path)
-        return rawid.replace(' /\\', '_')
+    def _add_size_qualifier(self, path, size_name=None):
+        if size_name is None:
+            size_name = self.size_name
 
-    def _get_webgal_link(self, srcdir_path):
-        link_target = self._add_size_qualifier('index.html', self.size_name)
-
-        if self.dir.should_be_flattened(srcdir_path):
-            # Add anchor target to get straight to gallery listing
-            link_target = link_target + '#' + self._get_webgal_id(srcdir_path)
-
-        # Add relative path to link if needed
-        index_path = None
-        if self.dir.should_be_flattened(srcdir_path):
-            index_path = self.dir.flattening_srcpath(srcdir_path)
-        if srcdir_path != self.dir.source_dir.path:
-            index_path = srcdir_path
-        if index_path is not None:
-            index_path = self.dir.rel_path_to_src(index_path)
-            index_path = pathutils.url_path(index_path)
-            link_target = posixpath.join(index_path, link_target)
-
-        return self.url_quote(link_target)
-
-    def _gen_webgal_path(self):
-        wg_path = []
-        for dirmd in self.dir.source_dir.parents_metadata():
-            wg = {}
-            wg['link'] = self._get_webgal_link(dirmd.dir_path)
-            wg['name'] = dirmd.get_title()
-            wg['root'] = dirmd.dir_path == self.dir.album.source_dir
-            wg['current'] = dirmd.dir_path == self.dir.source_dir.path
-            wg_path.append(wg)
-
-        wg_path.reverse()
-        return wg_path
-
-    def _add_size_qualifier(self, path, size_name):
         return self.dir._add_size_qualifier(path, size_name)
 
     def _do_not_escape(self, value):
         self.media = self.webalbum_media.media
         WebalbumPage.__init__(self, dir, size_name, self.media.name)
 
-        self.browse_media = self.webalbum_media.resized[size_name]
-        self.add_dependency(self.browse_media)
+        self.add_dependency(self.webalbum_media.resized[size_name])
         if webalbum_media.original:
             self.add_dependency(self.webalbum_media.original)
 
         self.set_template('browse.thtml')
         self.load_tpl(self.media.type + '.thtml')
 
+    def add_extra_vals(self, tpl_values):
+        tpl_values.update(tplvars.media_vars(self, self.webalbum_media).full())
+
     def build(self):
         page_rel_path = self.rel_path(self.dir.flattening_dir)
         logging.info(_("  XHTML %s") % page_rel_path)
         tpl_values = self.init_tpl_values()
 
         # Breadcrumbs
-        tpl_values['webgal_path'] = self._gen_webgal_path()
+        tpl_values['webgal_path'] = tplvars.Webgal(self, self.dir).path()
 
         tpl_values['name'] = self.media.filename
         tpl_values['mediatype'] = self.media.type
 
         prev = self.webalbum_media.previous
         if prev:
-            tpl_values['prev_link'] = self._gen_other_media_link(prev)
+            tpl_values['prev_link'] = tplvars.Media(self, prev).link()
 
         next = self.webalbum_media.next
         if next:
-            tpl_values['next_link'] = self._gen_other_media_link(next)
+            tpl_values['next_link'] = tplvars.Media(self, next).link()
 
         tpl_values['index_link'] = self._add_size_qualifier('index.html',
                                                             self.size_name)
         self.page_template.dump(tpl_values, self.page_path)
 
 
-class WebalbumImagePage(WebalbumBrowsePage):
-
-    def __init__(self, dir, size_name, webalbum_image):
-        WebalbumBrowsePage.__init__(self, dir, size_name, webalbum_image)
-        self.image = self.media
-
-    def add_extra_vals(self, tpl_values):
-        tpl_values['img_src'] = self.browse_media.filename
-        tpl_values['img_src'] = self.url_quote(tpl_values['img_src'])
-
-        tpl_values['image_name'] = self.image.filename
-
-        tpl_values['img_width'], tpl_values['img_height'] = self.webalbum_media.resized[self.size_name].get_size()
-
-        if self.dir.config.getboolean('webgal', 'publish-metadata'):
-            img_date = self.image.get_date_taken()
-            tpl_values['image_date'] = img_date.strftime(_("on %d/%m/%Y at %H:%M"))
-            tpl_values['image_datetime'] = img_date
-
-            image_info = self.image.info()
-            if image_info:
-                comment = image_info.get_comment()
-                if comment == '' or comment is None:
-                    tpl_values['comment'] = None
-                else:
-                    tpl_values['comment'] = self._do_not_escape(comment)
-
-                tpl_values['camera_name'] = image_info.get_camera_name()
-                tpl_values['lens_name'] = image_info.get_lens_name()
-                tpl_values['flash'] = image_info.get_flash()
-                tpl_values['exposure'] = image_info.get_exposure()
-                tpl_values['iso'] = image_info.get_iso()
-                tpl_values['fnumber'] = image_info.get_fnumber()
-                tpl_values['focal_length'] = image_info.get_focal_length()
-                tpl_values['authorship'] = image_info.get_authorship()
-
-
-class WebalbumVideoPage(WebalbumBrowsePage):
-
-    def __init__(self, webgal, size_name, webalbum_video):
-        WebalbumBrowsePage.__init__(self, webgal, size_name, webalbum_video)
-        self.video = self.media
-
-    def add_extra_vals(self, tpl_values):
-        tpl_values['video_src'] = self.browse_media.filename
-        tpl_values['video_src'] = self.url_quote(tpl_values['video_src'])
-
-
 class WebalbumIndexPage(WebalbumPage):
 
     FILENAME_BASE_STRING = 'index'
 
             if size_name in dir.browse_sizes:
                 for media in medias:
-                    if media.thumb: self.add_dependency(media.thumb)
-                    self.add_dependency(media.browse_pages[size_name])
-                    # Ensure dir depends on browse page (usefull for cleanup
-                    # checks when dir is flattenend).
-                    dir.add_dependency(media.browse_pages[size_name])
+                    if media.thumb:
+                        self.add_dependency(media.thumb)
+                    if self.dir.album.theme.kind == 'static':
+                        self.add_dependency(media.browse_pages[size_name])
+                        # Ensure dir depends on browse page (usefull for cleanup
+                        # checks when dir is flattenend).
+                        dir.add_dependency(media.browse_pages[size_name])
             else:
                 logging.warning(_("  Size '%s' is not available in '%s' due to configuration: medias won't be shown on index.") % (size_name, dir.path))
 
         for subgal in self.subgals:
             self.add_dependency(subgal.source_dir)
 
-        self.set_template('dirindex.thtml')
+        if self.dir.album.theme.kind == 'static':
+            self.set_template('dirindex.thtml')
+        elif self.dir.album.theme.kind == 'dynamic':
+            self.set_template('dynindex.thtml')
 
     def _get_paginated_name(self, page_number=None):
         if page_number is None:
 
         return onum_index_links
 
-    def _get_dir_info(self, dir=None):
-        if dir is None:
-            dir = self.dir
-
-        dir_info = {}
-        if dir.source_dir.metadata:
-            dir_info.update(dir.source_dir.metadata.get())
-            if 'album_description' in dir_info.keys():
-                dir_info['album_description'] =\
-                    self._do_not_escape(dir_info['album_description'])
-
-        if 'album_name' not in dir_info.keys():
-            dir_info['album_name'] = dir.source_dir.human_name
-
-        if dir.dirzip:
-            archive_rel_path = dir.dirzip.rel_path(self.dir, url=True)
-            dir_info['dirzip'] = self.url_quote(archive_rel_path)
-            dir_info['dirzip_size'] = self.format_filesize(dir.dirzip.size())
-
-        dir_info['is_main'] = dir is self.dir
-
-        dir_info['image_count'] = dir.source_dir.get_media_count('image')
-        dir_info['subgal_count'] = len(dir.source_dir.subdirs)
-
-        dir_info['id'] = self.url_quote(self._get_webgal_id(dir.source_dir.path))
-
-        return dir_info
-
     def _get_subgal_links(self):
         subgal_links = []
         for subgal in self.dir.subgals:
-            dir_info = self._get_dir_info(subgal)
-            dir_info['link'] = posixpath.join(subgal.source_dir.name,
-                                              self._get_related_index_fn())
-            dir_info['link'] = self.url_quote(dir_info['link'])
-            dir_info['album_picture'] = \
-                posixpath.join(subgal.source_dir.name,
-                               self.dir.get_webalbumpic_filename())
-            dir_info['album_picture'] = self.url_quote(dir_info['album_picture'])
+            dir_info = tplvars.Webgal(self, subgal).link_info()
             subgal_links.append(dir_info)
         return subgal_links
 
 
         # Breadcrumbs (current is static, see dirindex.thtml, that's why the
         # last item of the list is removed).
-        values['webgal_path'] = self._gen_webgal_path()[:-1]
+        values['webgal_path'] = tplvars.Webgal(self, self.dir).path()[:-1]
 
         if not self.dir.source_dir.is_album_root():
             # Parent index link not for album root
 
         values['medias'] = []
         for subdir, medias in self.galleries:
-            info = self._get_dir_info(subdir)
+            info = tplvars.Webgal(self, subdir).info()
             if self.size_name in subdir.browse_sizes:
-                media_links = [self._gen_other_media_link(media)
+                media_links = [tplvars.media_vars(self, media).full()
                                for media in medias]
             else:
                 # This happens when this dir index size is not available in the
                 media_links = []
             values['medias'].append((info, media_links, ))
 
-        values.update(self._get_dir_info())
+        values.update(tplvars.Webgal(self, self.dir).info())
 
         values['rel_root'] = pathutils.url_path(self.dir.source_dir.rel_root()) + '/'
         values['rel_path'] = pathutils.url_path(self.dir.source_dir.strip_root())
             self.pub_url = self.pub_url + '/'
 
         self.feed = feeds.RSS20(self.pub_url)
-        self.item_template = self.album.tpl_loader.load('feeditem.thtml')
+        self.item_template = self.album.theme.tpl_loader.load('feeditem.thtml')
 
     def set_title(self, title):
         self.feed.title = title
     def __init__(self, album, shared_tpl_name, shared_file_dest_tplname,
                  tpl_vars):
         self.album = album
-        self.tpl = self.album.tpl_loader.load(shared_tpl_name)
+        self.tpl = self.album.theme.tpl_loader.load(shared_tpl_name)
         self.tpl_vars = tpl_vars
 
         # Remove the 't' from the beginning of ext
 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 import os
+import glob
 from genshi.core import START
 from genshi.template import TemplateLoader, MarkupTemplate, NewTextTemplate
 from genshi.template import TemplateNotFound
 import timeutils
 
 
-DEFAULT_TEMPLATE = 'default'
+DEFAULT_THEME = 'default'
+USER_THEME_DIR = os.path.expanduser(os.path.join('~', '.lazygal', 'themes'))
+THEME_SHARED_FILE_PREFIX = 'SHARED_'
 
 
 class LazygalTemplate(object):
             raise ValueError(_('Unknown template type for %s' % tpl_ident))
 
 
+class Theme(object):
+
+    def __init__(self, themes_dir, name):
+        self.name = name
+
+        # First try user directory
+        self.tpl_dir = os.path.join(USER_THEME_DIR, self.name)
+        if not os.path.exists(self.tpl_dir):
+            # Fallback to system themes
+            self.tpl_dir = os.path.join(themes_dir, self.name)
+            if not os.path.exists(self.tpl_dir):
+                raise ValueError(_('Theme %s not found') % self.name)
+
+        self.tpl_loader = TplFactory(os.path.join(themes_dir, DEFAULT_THEME),
+                                     self.tpl_dir)
+
+        # Load styles templates
+        for style in self.get_avail_styles():
+            style_filename = style['filename']
+            try:
+                self.tpl_loader.load(style_filename)
+            except ValueError:
+                # Not a known emplate ext, ignore
+                pass
+
+        # find out theme kind
+        try:
+            self.tpl_loader.load('dynindex.thtml')
+        except TemplateNotFound:
+            self.kind = 'static'
+        else:
+            self.kind = 'dynamic'
+
+    def get_avail_styles(self, default_style=None):
+        style_files_mask = os.path.join(self.tpl_dir,
+                                        THEME_SHARED_FILE_PREFIX + '*' + 'css')
+        styles = []
+        for style_tpl_file in glob.glob(style_files_mask):
+            style = {}
+            tpl_filename = os.path.basename(style_tpl_file).split('.')[0]
+            style['filename'] = tpl_filename[len(THEME_SHARED_FILE_PREFIX):]
+            style['name'] = style['filename'].replace('_', ' ')
+            if default_style is not None:
+                if style['filename'] == default_style:
+                    style['rel'] = 'stylesheet'
+                else:
+                    style['rel'] = 'alternate stylesheet'
+            styles.append(style)
+        return styles
+
+
 # vim: ts=4 sw=4 expandtab

lazygal/tplvars.py

+# Lazygal, a lazy static web gallery generator.
+# Copyright (C) 2013 Alexandre Rossi <alexandre.rossi@gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+
+import os
+import re
+import posixpath
+
+import pathutils
+
+
+class TemplateVariables(object):
+
+    def __init__(self, page):
+        self.page = page
+
+
+class Media(TemplateVariables):
+
+    def __init__(self, page, webalbum_media):
+        super(Media, self).__init__(page)
+        self.webalbum_media = webalbum_media
+        self.media = webalbum_media.media
+
+    def link(self):
+        if self.webalbum_media:
+            link_vals = {}
+
+            link_vals['type'] = self.media.type
+
+            if self.page.dir.album.theme.kind == 'static':
+                link_vals['link'] = self.webalbum_media.browse_pages[self.page.size_name].rel_path(self.page.dir, url=True)
+            elif self.page.dir.album.theme.kind == 'dynamic':
+                link_vals['link'] = self.webalbum_media.resized[self.page.size_name].rel_path(self.page.dir, url=True)
+            link_vals['link'] = self.page.url_quote(link_vals['link'])
+
+            link_vals['thumb'] = self.webalbum_media.thumb.rel_path(self.page.dir, url=True)
+            link_vals['thumb'] = self.page.url_quote(link_vals['thumb'])
+
+            if not self.media.broken:
+                link_vals['thumb_width'],\
+                    link_vals['thumb_height'] = self.webalbum_media.thumb.get_size()
+
+            link_vals['thumb_name'] = self.page.dir.album._str_humanize(self.media.name)
+
+            return link_vals
+        else:
+            return None
+
+
+class Image(Media):
+
+    def full(self):
+        tpl_values = self.link()
+        tpl_values['img_src'] = self.webalbum_media.resized[self.page.size_name].filename
+        tpl_values['img_src'] = self.page.url_quote(tpl_values['img_src'])
+
+        tpl_values['image_name'] = self.media.filename
+
+        tpl_values['img_width'], tpl_values['img_height'] = self.webalbum_media.resized[self.page.size_name].get_size()
+
+        if self.page.dir.config.getboolean('webgal', 'publish-metadata'):
+            img_date = self.media.get_date_taken()
+            tpl_values['image_date'] = img_date.strftime(_("on %d/%m/%Y at %H:%M"))
+            tpl_values['image_datetime'] = img_date
+
+            image_info = self.media.info()
+            if image_info:
+                comment = image_info.get_comment()
+                if comment == '' or comment is None:
+                    tpl_values['comment'] = None
+                else:
+                    tpl_values['comment'] = self.page._do_not_escape(comment)
+
+                tpl_values['camera_name'] = image_info.get_camera_name()
+                tpl_values['lens_name'] = image_info.get_lens_name()
+                tpl_values['flash'] = image_info.get_flash()
+                tpl_values['exposure'] = image_info.get_exposure()
+                tpl_values['iso'] = image_info.get_iso()
+                tpl_values['fnumber'] = image_info.get_fnumber()
+                tpl_values['focal_length'] = image_info.get_focal_length()
+                tpl_values['authorship'] = image_info.get_authorship()
+
+        return tpl_values
+
+
+class Video(Media):
+
+    def full(self):
+        tpl_values = self.link()
+        tpl_values['video_src'] = self.media.filename
+        tpl_values['video_src'] = self.page.url_quote(tpl_values['video_src'])
+        return tpl_values
+
+
+def media_vars(page, webalbum_media):
+    cls = None
+    if webalbum_media.media.type == 'image':
+        cls = Image
+    elif webalbum_media.media.type == 'video':
+        cls = Video
+    else:
+        raise NotImplementedError
+    return cls(page, webalbum_media)
+
+
+class SrcPath(TemplateVariables):
+
+    def __init__(self, page, srcpath):
+        super(SrcPath, self).__init__(page)
+        self.srcpath = srcpath
+
+    def should_be_flattened(self):
+        return self.page.dir.should_be_flattened(self.srcpath)
+
+    def id(self):
+        if self.should_be_flattened():
+            rawid = self.page.dir.source_dir.rel_path(self.page.dir.flattening_srcpath(self.srcpath), self.srcpath)
+        else:
+            rawid = os.path.basename(self.srcpath)
+        return re.sub(r'[/ \\]', '_', rawid)
+
+    def link(self):
+        link_target = self.page._add_size_qualifier('index.html')
+
+        if self.should_be_flattened():
+            # Add anchor target to get straight to gallery listing
+            link_target = link_target + '#' + self.id()
+
+        # Add relative path to link if needed
+        index_path = None
+        if self.should_be_flattened():
+            index_path = self.page.dir.flattening_srcpath(self.srcpath)
+        elif self.srcpath != self.page.dir.source_dir.path:
+            index_path = self.srcpath
+        if index_path is not None:
+            index_path = self.page.dir.rel_path_to_src(index_path)
+            index_path = pathutils.url_path(index_path)
+            link_target = posixpath.join(index_path, link_target)
+
+        return self.page.url_quote(link_target)
+
+    def path(self):
+        wg_path = []
+        for dirmd in self.page.dir.source_dir.parents_metadata():
+            wg = {}
+            wg['link'] = SrcPath(self.page, dirmd.dir_path).link()
+            wg['name'] = dirmd.get_title()
+            wg['root'] = dirmd.dir_path == self.page.dir.album.source_dir
+            wg['current'] = dirmd.dir_path == self.page.dir.source_dir.path
+            wg_path.append(wg)
+
+        wg_path.reverse()
+        return wg_path
+
+
+class Webgal(SrcPath):
+
+    def __init__(self, page, webgal):
+        super(Webgal, self).__init__(page, webgal.source_dir.path)
+        self.webgal = webgal
+
+    def info(self):
+        dir_info = {}
+        if self.webgal.source_dir.metadata:
+            dir_info.update(self.webgal.source_dir.metadata.get())
+            if 'album_description' in dir_info.keys():
+                dir_info['album_description'] =\
+                    self.page._do_not_escape(dir_info['album_description'])
+
+        if 'album_name' not in dir_info:
+            dir_info['album_name'] = self.webgal.source_dir.human_name
+
+        if self.webgal.dirzip:
+            archive_rel_path = self.webgal.dirzip.rel_path(self.page.dir,
+                                                           url=True)
+            dir_info['dirzip'] = self.page.url_quote(archive_rel_path)
+            dir_info['dirzip_size'] = self.page.format_filesize(self.webgal.dirzip.size())
+
+        dir_info['is_main'] = self.webgal is self.page.dir
+
+        dir_info['image_count'] = self.webgal.source_dir.get_media_count('image')
+        dir_info['subgal_count'] = len(self.webgal.source_dir.subdirs)
+
+        dir_info['id'] = self.page.url_quote(self.id())
+
+        return dir_info
+
+    def link_info(self):
+        link_info = self.info()
+        link_info['link'] = self.link()
+        link_info['album_picture'] = \
+                posixpath.join(self.webgal.source_dir.name,
+                               self.webgal.get_webalbumpic_filename())
+        link_info['album_picture'] = self.page.url_quote(link_info['album_picture'])
+        return link_info
+
+
+# vim: ts=4 sw=4 expandtab

themes/singlepage/SHARED_basic.css

+.media {
+		position: relative;
+		display: inline-block;
+}
+
+.video_arrow {
+		position: absolute;
+		border: none;
+		width: 40%;
+		top: 0;
+		bottom: 0;
+		left: 0;
+		right: 0;
+		margin: auto;
+}

themes/singlepage/SHARED_colorbox.css

+/*
+    ColorBox Core Style:
+    The following CSS is consistent between example themes and should not be altered.
+*/
+#colorbox, #cboxOverlay, #cboxWrapper{position:absolute; top:0; left:0; z-index:9999; overflow:hidden;}
+#cboxOverlay{position:fixed; width:100%; height:100%;}
+#cboxMiddleLeft, #cboxBottomLeft{clear:left;}
+#cboxContent{position:relative;}
+#cboxLoadedContent{overflow:auto;}
+#cboxTitle{margin:0;}
+#cboxLoadingOverlay, #cboxLoadingGraphic{position:absolute; top:0; left:0; width:100%; height:100%;}
+#cboxPrevious, #cboxNext, #cboxClose, #cboxSlideshow{cursor:pointer;}
+.cboxPhoto{float:left; margin:auto; border:0; display:block; max-width:none;}
+.cboxIframe{width:100%; height:100%; display:block; border:0;}
+#colorbox, #cboxContent, #cboxLoadedContent{box-sizing:content-box; -moz-box-sizing:content-box; -webkit-box-sizing:content-box;}
+
+/*
+    User Style:
+    Change the following styles to modify the appearance of ColorBox.  They are
+    ordered & tabbed in a way that represents the nesting of the generated HTML.
+*/
+#cboxOverlay{background:#000;}
+#colorbox{}
+    #cboxContent{margin-top:20px;}
+        .cboxIframe{background:#fff;}
+        #cboxError{padding:50px; border:1px solid #ccc;}
+        #cboxLoadedContent{border:5px solid #000; background:#fff;}
+        #cboxTitle{position:absolute; top:-20px; left:0; color:#ccc;}
+        #cboxCurrent{position:absolute; top:-20px; right:0px; color:#ccc;}
+        #cboxSlideshow{position:absolute; top:-20px; right:90px; color:#fff;}
+        #cboxPrevious{position:absolute; top:50%; left:5px; margin-top:-32px; background:url(controls.png) no-repeat top left; width:28px; height:65px; text-indent:-9999px;}
+        #cboxPrevious:hover{background-position:bottom left;}
+        #cboxNext{position:absolute; top:50%; right:5px; margin-top:-32px; background:url(controls.png) no-repeat top right; width:28px; height:65px; text-indent:-9999px;}
+        #cboxNext:hover{background-position:bottom right;}
+        #cboxLoadingOverlay{background:#000;}
+        #cboxLoadingGraphic{background:url(loading.gif) no-repeat center center;}
+        #cboxClose{position:absolute; top:5px; right:5px; display:block; background:url(controls.png) no-repeat top center; width:38px; height:19px; text-indent:-9999px;}
+        #cboxClose:hover{background-position:bottom center;}

themes/singlepage/SHARED_controls.png

Added
New image

themes/singlepage/SHARED_default.css

+@import url("basic.css");
+@import url("colorbox.css");
+
+body{
+    background: white;
+}
+
+a {
+    color: black;
+}
+
+.title {
+    display: none;
+}
+
+.title h1{
+    margin-top: .1em;
+}
+
+.inline_enum ul{
+    margin-left: 0;
+    padding-left: 0;
+    display: inline;
+}
+
+.inline_enum ul li {
+    margin-left: 0;
+    padding-left: 2px;
+    border: none;
+    list-style: none;
+    display: inline;
+}
+
+#breadcrumbs {
+    padding: 3px;
+    margin-bottom: 25px;
+    font-size: small;
+}
+
+#breadcrumbs ul li:after {
+    content: "\0020 \0020 \0020 \00BB \0020";
+}
+
+#breadcrumbs ul li.bc_current:after {
+    content: " ";
+}
+
+#osize_links ul li:after {
+    content: "   |";
+}
+
+#osize_links ul li:last-child:after {
+    content: " ";
+}
+
+#onum_links ul li:after {
+    content: "   |";
+}
+
+#onum_links ul li:last-child:after {
+    content: " ";
+}
+
+#osize_links {
+    font-size: small;
+    text-align:center;
+    margin: 1em;
+}
+
+#onum_links{
+    font-size: small;
+    text-align:center;
+}
+
+div.subgal_link {
+    float: left;
+    padding: 1em;
+    width: 50em;
+}
+
+div.subgal_image {
+    float: left;
+    margin-right: 2em;
+    margin-left: 4em;
+    width:180px;
+}
+
+div.subgal_image img {
+    margin: 0;
+    border: none;
+}
+
+div.subgal_description p{
+    text-align:justify;
+}
+
+.media_links{
+    padding: 2em;
+}
+
+img.media{
+    border: solid black 1px;
+    margin: 1em;
+}
+
+.caption {
+    display:none;
+}
+
+#lazygalfooter{
+    padding-top: 3em;
+    clear: both;
+    font-size: x-small;
+}
+
+/*
+ * vim: ts=4 sw=4 expandtab
+ */

themes/singlepage/SHARED_jquery.colorbox.js

+// ColorBox v1.3.20.1 - jQuery lightbox plugin
+// (c) 2012 Jack Moore - jacklmoore.com
+// License: http://www.opensource.org/licenses/mit-license.php
+(function ($, document, window) {
+	var
+	// Default settings object.
+	// See http://jacklmoore.com/colorbox for details.
+	defaults = {
+		transition: "elastic",
+		speed: 300,
+		width: false,
+		initialWidth: "600",
+		innerWidth: false,
+		maxWidth: false,
+		height: false,
+		initialHeight: "450",
+		innerHeight: false,
+		maxHeight: false,
+		scalePhotos: true,
+		scrolling: true,
+		inline: false,
+		html: false,
+		iframe: false,
+		fastIframe: true,
+		photo: false,
+		href: false,
+		title: false,
+		rel: false,
+		opacity: 0.9,
+		preloading: true,
+
+		current: "image {current} of {total}",
+		previous: "previous",
+		next: "next",
+		close: "close",
+		xhrError: "This content failed to load.",
+		imgError: "This image failed to load.",
+
+		open: false,
+		returnFocus: true,
+		reposition: true,
+		loop: true,
+		slideshow: false,
+		slideshowAuto: true,
+		slideshowSpeed: 2500,
+		slideshowStart: "start slideshow",
+		slideshowStop: "stop slideshow",
+		onOpen: false,
+		onLoad: false,
+		onComplete: false,
+		onCleanup: false,
+		onClosed: false,
+		overlayClose: true,
+		escKey: true,
+		arrowKey: true,
+		top: false,
+		bottom: false,
+		left: false,
+		right: false,
+		fixed: false,
+		data: undefined
+	},
+	
+	// Abstracting the HTML and event identifiers for easy rebranding
+	colorbox = 'colorbox',
+	prefix = 'cbox',
+	boxElement = prefix + 'Element',
+	
+	// Events
+	event_open = prefix + '_open',
+	event_load = prefix + '_load',
+	event_complete = prefix + '_complete',
+	event_cleanup = prefix + '_cleanup',
+	event_closed = prefix + '_closed',
+	event_purge = prefix + '_purge',
+	
+	// Special Handling for IE
+	isIE = !$.support.opacity && !$.support.style, // IE7 & IE8
+	isIE6 = isIE && !window.XMLHttpRequest, // IE6
+	event_ie6 = prefix + '_IE6',
+
+	// Cached jQuery Object Variables
+	$overlay,
+	$box,
+	$wrap,
+	$content,
+	$topBorder,
+	$leftBorder,
+	$rightBorder,
+	$bottomBorder,
+	$related,
+	$window,
+	$loaded,
+	$loadingBay,
+	$loadingOverlay,
+	$title,
+	$current,
+	$slideshow,
+	$next,
+	$prev,
+	$close,
+	$groupControls,
+	
+	// Variables for cached values or use across multiple functions
+	settings,
+	interfaceHeight,
+	interfaceWidth,
+	loadedHeight,
+	loadedWidth,
+	element,
+	index,
+	photo,
+	open,
+	active,
+	closing,
+	loadingTimer,
+	publicMethod,
+	div = "div",
+	init;
+
+	// ****************
+	// HELPER FUNCTIONS
+	// ****************
+	
+	// Convience function for creating new jQuery objects
+	function $tag(tag, id, css) {
+		var element = document.createElement(tag);
+
+		if (id) {
+			element.id = prefix + id;
+		}
+
+		if (css) {
+			element.style.cssText = css;
+		}
+
+		return $(element);
+	}
+
+	// Determine the next and previous members in a group.
+	function getIndex(increment) {
+		var
+		max = $related.length,
+		newIndex = (index + increment) % max;
+		
+		return (newIndex < 0) ? max + newIndex : newIndex;
+	}
+
+	// Convert '%' and 'px' values to integers
+	function setSize(size, dimension) {
+		return Math.round((/%/.test(size) ? ((dimension === 'x' ? winWidth() : winHeight()) / 100) : 1) * parseInt(size, 10));
+	}
+	
+	// Checks an href to see if it is a photo.
+	// There is a force photo option (photo: true) for hrefs that cannot be matched by this regex.
+	function isImage(url) {
+		return settings.photo || /\.(gif|png|jp(e|g|eg)|bmp|ico)((#|\?).*)?$/i.test(url);
+	}
+	
+	function winWidth() {
+		// $(window).width() is incorrect for some mobile browsers, but
+		// window.innerWidth is unsupported in IE8 and lower.
+		return window.innerWidth || $window.width();
+	}
+
+	function winHeight() {
+		return window.innerHeight || $window.height();
+	}
+
+	// Assigns function results to their respective properties
+	function makeSettings() {
+		var i,
+			data = $.data(element, colorbox);
+		
+		if (data == null) {
+			settings = $.extend({}, defaults);
+			if (console && console.log) {
+				console.log('Error: cboxElement missing settings object');
+			}
+		} else {
+			settings = $.extend({}, data);
+		}
+		
+		for (i in settings) {
+			if ($.isFunction(settings[i]) && i.slice(0, 2) !== 'on') { // checks to make sure the function isn't one of the callbacks, they will be handled at the appropriate time.
+				settings[i] = settings[i].call(element);
+			}
+		}
+		
+		settings.rel = settings.rel || element.rel || 'nofollow';
+		settings.href = settings.href || $(element).attr('href');
+		settings.title = settings.title || element.title;
+		
+		if (typeof settings.href === "string") {
+			settings.href = $.trim(settings.href);
+		}
+	}
+
+	function trigger(event, callback) {
+		$.event.trigger(event);
+		if (callback) {
+			callback.call(element);
+		}
+	}
+
+	// Slideshow functionality
+	function slideshow() {
+		var
+		timeOut,
+		className = prefix + "Slideshow_",
+		click = "click." + prefix,
+		start,
+		stop,
+		clear;
+		
+		if (settings.slideshow && $related[1]) {
+			start = function () {
+				$slideshow
+					.text(settings.slideshowStop)
+					.unbind(click)
+					.bind(event_complete, function () {
+						if (settings.loop || $related[index + 1]) {
+							timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
+						}
+					})
+					.bind(event_load, function () {
+						clearTimeout(timeOut);
+					})
+					.one(click + ' ' + event_cleanup, stop);
+				$box.removeClass(className + "off").addClass(className + "on");
+				timeOut = setTimeout(publicMethod.next, settings.slideshowSpeed);
+			};
+			
+			stop = function () {
+				clearTimeout(timeOut);
+				$slideshow
+					.text(settings.slideshowStart)
+					.unbind([event_complete, event_load, event_cleanup, click].join(' '))
+					.one(click, function () {
+						publicMethod.next();
+						start();
+					});
+				$box.removeClass(className + "on").addClass(className + "off");
+			};
+			
+			if (settings.slideshowAuto) {
+				start();
+			} else {
+				stop();
+			}
+		} else {
+			$box.removeClass(className + "off " + className + "on");
+		}
+	}
+
+	function launch(target) {
+		if (!closing) {
+			
+			element = target;
+			
+			makeSettings();
+			
+			$related = $(element);
+			
+			index = 0;
+			
+			if (settings.rel !== 'nofollow') {
+				$related = $('.' + boxElement).filter(function () {
+					var data = $.data(this, colorbox),
+						relRelated;
+
+					if (data) {
+						relRelated =  data.rel || this.rel;
+					}
+					
+					return (relRelated === settings.rel);
+				});
+				index = $related.index(element);
+				
+				// Check direct calls to ColorBox.
+				if (index === -1) {
+					$related = $related.add(element);
+					index = $related.length - 1;
+				}
+			}
+			
+			if (!open) {
+				open = active = true; // Prevents the page-change action from queuing up if the visitor holds down the left or right keys.
+				
+				$box.show();
+				
+				if (settings.returnFocus) {
+					$(element).blur().one(event_closed, function () {
+						$(this).focus();
+					});
+				}
+				
+				// +settings.opacity avoids a problem in IE when using non-zero-prefixed-string-values, like '.5'
+				$overlay.css({"opacity": +settings.opacity, "cursor": settings.overlayClose ? "pointer" : "auto"}).show();
+				
+				// Opens inital empty ColorBox prior to content being loaded.
+				settings.w = setSize(settings.initialWidth, 'x');
+				settings.h = setSize(settings.initialHeight, 'y');
+				publicMethod.position();
+				
+				if (isIE6) {
+					$window.bind('resize.' + event_ie6 + ' scroll.' + event_ie6, function () {
+						$overlay.css({width: winWidth(), height: winHeight(), top: $window.scrollTop(), left: $window.scrollLeft()});
+					}).trigger('resize.' + event_ie6);
+				}
+				
+				trigger(event_open, settings.onOpen);
+				
+				$groupControls.add($title).hide();
+				
+				$close.html(settings.close).show();
+			}
+			
+			publicMethod.load(true);
+		}
+	}
+
+	// ColorBox's markup needs to be added to the DOM prior to being called
+	// so that the browser will go ahead and load the CSS background images.
+	function appendHTML() {
+		if (!$box && document.body) {
+			init = false;
+
+			$window = $(window);
+			$box = $tag(div).attr({id: colorbox, 'class': isIE ? prefix + (isIE6 ? 'IE6' : 'IE') : ''}).hide();
+			$overlay = $tag(div, "Overlay", isIE6 ? 'position:absolute' : '').hide();
+			$loadingOverlay = $tag(div, "LoadingOverlay").add($tag(div, "LoadingGraphic"));
+			$wrap = $tag(div, "Wrapper");
+			$content = $tag(div, "Content").append(
+				$loaded = $tag(div, "LoadedContent", 'width:0; height:0; overflow:hidden'),
+				$title = $tag(div, "Title"),
+				$current = $tag(div, "Current"),
+				$next = $tag(div, "Next"),
+				$prev = $tag(div, "Previous"),
+				$slideshow = $tag(div, "Slideshow").bind(event_open, slideshow),
+				$close = $tag(div, "Close")
+			);
+			
+			$wrap.append( // The 3x3 Grid that makes up ColorBox
+				$tag(div).append(
+					$tag(div, "TopLeft"),
+					$topBorder = $tag(div, "TopCenter"),
+					$tag(div, "TopRight")
+				),
+				$tag(div, false, 'clear:left').append(
+					$leftBorder = $tag(div, "MiddleLeft"),
+					$content,
+					$rightBorder = $tag(div, "MiddleRight")
+				),
+				$tag(div, false, 'clear:left').append(
+					$tag(div, "BottomLeft"),
+					$bottomBorder = $tag(div, "BottomCenter"),
+					$tag(div, "BottomRight")
+				)
+			).find('div div').css({'float': 'left'});
+			
+			$loadingBay = $tag(div, false, 'position:absolute; width:9999px; visibility:hidden; display:none');
+			
+			$groupControls = $next.add($prev).add($current).add($slideshow);
+
+			$(document.body).append($overlay, $box.append($wrap, $loadingBay));
+		}
+	}
+
+	// Add ColorBox's event bindings
+	function addBindings() {
+		if ($box) {
+			if (!init) {
+				init = true;
+
+				// Cache values needed for size calculations
+				interfaceHeight = $topBorder.height() + $bottomBorder.height() + $content.outerHeight(true) - $content.height();//Subtraction needed for IE6
+				interfaceWidth = $leftBorder.width() + $rightBorder.width() + $content.outerWidth(true) - $content.width();
+				loadedHeight = $loaded.outerHeight(true);
+				loadedWidth = $loaded.outerWidth(true);
+				
+				// Setting padding to remove the need to do size conversions during the animation step.
+				$box.css({"padding-bottom": interfaceHeight, "padding-right": interfaceWidth});
+
+				// Anonymous functions here keep the public method from being cached, thereby allowing them to be redefined on the fly.
+				$next.click(function () {
+					publicMethod.next();
+				});
+				$prev.click(function () {
+					publicMethod.prev();
+				});
+				$close.click(function () {
+					publicMethod.close();
+				});
+				$overlay.click(function () {
+					if (settings.overlayClose) {
+						publicMethod.close();
+					}
+				});
+				
+				// Key Bindings
+				$(document).bind('keydown.' + prefix, function (e) {
+					var key = e.keyCode;
+					if (open && settings.escKey && key === 27) {
+						e.preventDefault();
+						publicMethod.close();
+					}
+					if (open && settings.arrowKey && $related[1]) {
+						if (key === 37) {
+							e.preventDefault();
+							$prev.click();
+						} else if (key === 39) {
+							e.preventDefault();
+							$next.click();
+						}
+					}
+				});
+
+				$('.' + boxElement, document).live('click', function (e) {
+					// ignore non-left-mouse-clicks and clicks modified with ctrl / command, shift, or alt.
+					// See: http://jacklmoore.com/notes/click-events/
+					if (!(e.which > 1 || e.shiftKey || e.altKey || e.metaKey)) {
+						e.preventDefault();
+						launch(this);
+					}
+				});
+			}
+			return true;
+		}
+		return false;
+	}
+
+	// Don't do anything if ColorBox already exists.
+	if ($.colorbox) {
+		return;
+	}
+
+	// Append the HTML when the DOM loads
+	$(appendHTML);
+
+
+	// ****************
+	// PUBLIC FUNCTIONS
+	// Usage format: $.fn.colorbox.close();
+	// Usage from within an iframe: parent.$.fn.colorbox.close();
+	// ****************
+	
+	publicMethod = $.fn[colorbox] = $[colorbox] = function (options, callback) {
+		var $this = this;
+		
+		options = options || {};
+		
+		appendHTML();
+
+		if (addBindings()) {
+			if (!$this[0]) {
+				if ($this.selector) { // if a selector was given and it didn't match any elements, go ahead and exit.
+					return $this;
+				}
+				// if no selector was given (ie. $.colorbox()), create a temporary element to work with
+				$this = $('<a/>');
+				options.open = true; // assume an immediate open
+			}
+			
+			if (callback) {
+				options.onComplete = callback;
+			}
+			
+			$this.each(function () {
+				$.data(this, colorbox, $.extend({}, $.data(this, colorbox) || defaults, options));
+			}).addClass(boxElement);
+			
+			if (($.isFunction(options.open) && options.open.call($this)) || options.open) {
+				launch($this[0]);
+			}
+		}
+		
+		return $this;
+	};
+
+	publicMethod.position = function (speed, loadedCallback) {
+		var
+		css,
+		top = 0,
+		left = 0,
+		offset = $box.offset(),
+		scrollTop,
+		scrollLeft;
+		
+		$window.unbind('resize.' + prefix);
+
+		// remove the modal so that it doesn't influence the document width/height
+		$box.css({top: -9e4, left: -9e4});
+
+		scrollTop = $window.scrollTop();
+		scrollLeft = $window.scrollLeft();
+
+		if (settings.fixed && !isIE6) {
+			offset.top -= scrollTop;
+			offset.left -= scrollLeft;
+			$box.css({position: 'fixed'});
+		} else {
+			top = scrollTop;
+			left = scrollLeft;
+			$box.css({position: 'absolute'});
+		}
+
+		// keeps the top and left positions within the browser's viewport.
+		if (settings.right !== false) {
+			left += Math.max(winWidth() - settings.w - loadedWidth - interfaceWidth - setSize(settings.right, 'x'), 0);
+		} else if (settings.left !== false) {
+			left += setSize(settings.left, 'x');
+		} else {
+			left += Math.round(Math.max(winWidth() - settings.w - loadedWidth - interfaceWidth, 0) / 2);
+		}
+		
+		if (settings.bottom !== false) {
+			top += Math.max(winHeight() - settings.h - loadedHeight - interfaceHeight - setSize(settings.bottom, 'y'), 0);
+		} else if (settings.top !== false) {
+			top += setSize(settings.top, 'y');
+		} else {
+			top += Math.round(Math.max(winHeight() - settings.h - loadedHeight - interfaceHeight, 0) / 2);
+		}
+
+		$box.css({top: offset.top, left: offset.left});
+
+		// setting the speed to 0 to reduce the delay between same-sized content.
+		speed = ($box.width() === settings.w + loadedWidth && $box.height() === settings.h + loadedHeight) ? 0 : speed || 0;
+		
+		// this gives the wrapper plenty of breathing room so it's floated contents can move around smoothly,
+		// but it has to be shrank down around the size of div#colorbox when it's done.  If not,
+		// it can invoke an obscure IE bug when using iframes.
+		$wrap[0].style.width = $wrap[0].style.height = "9999px";
+		
+		function modalDimensions(that) {
+			$topBorder[0].style.width = $bottomBorder[0].style.width = $content[0].style.width = that.style.width;
+			$content[0].style.height = $leftBorder[0].style.height = $rightBorder[0].style.height = that.style.height;
+		}
+
+		css = {width: settings.w + loadedWidth, height: settings.h + loadedHeight, top: top, left: left};
+		if(speed===0){ // temporary workaround to side-step jQuery-UI 1.8 bug (http://bugs.jquery.com/ticket/12273)
+			$box.css(css);
+		}
+		$box.dequeue().animate(css, {
+			duration: speed,
+			complete: function () {
+				modalDimensions(this);
+				
+				active = false;
+				
+				// shrink the wrapper down to exactly the size of colorbox to avoid a bug in IE's iframe implementation.
+				$wrap[0].style.width = (settings.w + loadedWidth + interfaceWidth) + "px";
+				$wrap[0].style.height = (settings.h + loadedHeight + interfaceHeight) + "px";
+				
+				if (settings.reposition) {
+					setTimeout(function () {  // small delay before binding onresize due to an IE8 bug.
+						$window.bind('resize.' + prefix, publicMethod.position);
+					}, 1);
+				}
+
+				if (loadedCallback) {
+					loadedCallback();
+				}
+			},
+			step: function () {
+				modalDimensions(this);
+			}
+		});
+	};
+
+	publicMethod.resize = function (options) {
+		if (open) {
+			options = options || {};
+			
+			if (options.width) {
+				settings.w = setSize(options.width, 'x') - loadedWidth - interfaceWidth;
+			}
+			if (options.innerWidth) {
+				settings.w = setSize(options.innerWidth, 'x');
+			}
+			$loaded.css({width: settings.w});
+			
+			if (options.height) {
+				settings.h = setSize(options.height, 'y') - loadedHeight - interfaceHeight;
+			}
+			if (options.innerHeight) {
+				settings.h = setSize(options.innerHeight, 'y');
+			}
+			if (!options.innerHeight && !options.height) {
+				$loaded.css({height: "auto"});
+				settings.h = $loaded.height();
+			}
+			$loaded.css({height: settings.h});
+			
+			publicMethod.position(settings.transition === "none" ? 0 : settings.speed);
+		}
+	};
+
+	publicMethod.prep = function (object) {
+		if (!open) {
+			return;
+		}
+		
+		var callback, speed = settings.transition === "none" ? 0 : settings.speed;
+		
+		$loaded.remove();
+		$loaded = $tag(div, 'LoadedContent').append(object);
+		
+		function getWidth() {
+			settings.w = settings.w || $loaded.width();
+			settings.w = settings.mw && settings.mw < settings.w ? settings.mw : settings.w;
+			return settings.w;
+		}
+		function getHeight() {
+			settings.h = settings.h || $loaded.height();
+			settings.h = settings.mh && settings.mh < settings.h ? settings.mh : settings.h;
+			return settings.h;
+		}
+		
+		$loaded.hide()
+		.appendTo($loadingBay.show())// content has to be appended to the DOM for accurate size calculations.
+		.css({width: getWidth(), overflow: settings.scrolling ? 'auto' : 'hidden'})
+		.css({height: getHeight()})// sets the height independently from the width in case the new width influences the value of height.
+		.prependTo($content);
+		
+		$loadingBay.hide();
+		
+		// floating the IMG removes the bottom line-height and fixed a problem where IE miscalculates the width of the parent element as 100% of the document width.
+		//$(photo).css({'float': 'none', marginLeft: 'auto', marginRight: 'auto'});
+		
+		$(photo).css({'float': 'none'});
+		
+		// Hides SELECT elements in IE6 because they would otherwise sit on top of the overlay.
+		if (isIE6) {
+			$('select').not($box.find('select')).filter(function () {
+				return this.style.visibility !== 'hidden';
+			}).css({'visibility': 'hidden'}).one(event_cleanup, function () {
+				this.style.visibility = 'inherit';
+			});
+		}
+		
+		callback = function () {
+			var preload,
+				i,
+				total = $related.length,
+				iframe,
+				frameBorder = 'frameBorder',
+				allowTransparency = 'allowTransparency',
+				complete,
+				src,
+				img,
+				data;
+			
+			if (!open) {
+				return;
+			}
+			
+			function removeFilter() {
+				if (isIE) {
+					$box[0].style.removeAttribute('filter');
+				}
+			}
+			
+			complete = function () {
+				clearTimeout(loadingTimer);
+				// Detaching forces Andriod stock browser to redraw the area underneat the loading overlay.  Hiding alone isn't enough.
+				$loadingOverlay.detach().hide();
+				trigger(event_complete, settings.onComplete);
+			};
+			
+			if (isIE) {
+				//This fadeIn helps the bicubic resampling to kick-in.
+				if (photo) {
+					$loaded.fadeIn(100);
+				}
+			}
+			
+			$title.html(settings.title).add($loaded).show();
+			
+			if (total > 1) { // handle grouping
+				if (typeof settings.current === "string") {
+					$current.html(settings.current.replace('{current}', index + 1).replace('{total}', total)).show();
+				}
+				
+				$next[(settings.loop || index < total - 1) ? "show" : "hide"]().html(settings.next);
+				$prev[(settings.loop || index) ? "show" : "hide"]().html(settings.previous);
+				
+				if (settings.slideshow) {
+					$slideshow.show();
+				}
+				
+				// Preloads images within a rel group
+				if (settings.preloading) {
+					preload = [
+						getIndex(-1),
+						getIndex(1)
+					];
+					while (i = $related[preload.pop()]) {
+						data = $.data(i, colorbox);
+						
+						if (data && data.href) {
+							src = data.href;
+							if ($.isFunction(src)) {
+								src = src.call(i);
+							}
+						} else {
+							src = i.href;
+						}
+
+						if (isImage(src)) {
+							img = new Image();
+							img.src = src;
+						}
+					}
+				}
+			} else {
+				$groupControls.hide();
+			}
+			
+			if (settings.iframe) {
+				iframe = $tag('iframe')[0];
+				
+				if (frameBorder in iframe) {
+					iframe[frameBorder] = 0;
+				}
+				if (allowTransparency in iframe) {
+					iframe[allowTransparency] = "true";
+				}
+				// give the iframe a unique name to prevent caching
+				iframe.name = prefix + (+new Date());
+				if (settings.fastIframe) {
+					complete();
+				} else {
+					$(iframe).one('load', complete);
+				}
+				iframe.src = settings.href;
+				if (!settings.scrolling) {
+					iframe.scrolling = "no";
+				}
+				$(iframe).addClass(prefix + 'Iframe').appendTo($loaded).one(event_purge, function () {
+					iframe.src = "//about:blank";
+				});
+			} else {
+				complete();
+			}
+			
+			if (settings.transition === 'fade') {
+				$box.fadeTo(speed, 1, removeFilter);
+			} else {
+				removeFilter();
+			}
+		};
+		
+		if (settings.transition === 'fade') {
+			$box.fadeTo(speed, 0, function () {
+				publicMethod.position(0, callback);
+			});
+		} else {
+			publicMethod.position(speed, callback);
+		}
+	};
+
+	publicMethod.load = function (launched) {
+		var href, setResize, prep = publicMethod.prep;
+		
+		active = true;
+		
+		photo = false;
+		
+		element = $related[index];
+		
+		if (!launched) {
+			makeSettings();
+		}
+		
+		trigger(event_purge);
+		
+		trigger(event_load, settings.onLoad);
+		
+		settings.h = settings.height ?
+				setSize(settings.height, 'y') - loadedHeight - interfaceHeight :
+				settings.innerHeight && setSize(settings.innerHeight, 'y');
+		
+		settings.w = settings.width ?
+				setSize(settings.width, 'x') - loadedWidth - interfaceWidth :
+				settings.innerWidth && setSize(settings.innerWidth, 'x');
+		
+		// Sets the minimum dimensions for use in image scaling
+		settings.mw = settings.w;
+		settings.mh = settings.h;
+		
+		// Re-evaluate the minimum width and height based on maxWidth and maxHeight values.
+		// If the width or height exceed the maxWidth or maxHeight, use the maximum values instead.
+		if (settings.maxWidth) {
+			settings.mw = setSize(settings.maxWidth, 'x') - loadedWidth - interfaceWidth;
+			settings.mw = settings.w && settings.w < settings.mw ? settings.w : settings.mw;
+		}
+		if (settings.maxHeight) {
+			settings.mh = setSize(settings.maxHeight, 'y') - loadedHeight - interfaceHeight;
+			settings.mh = settings.h && settings.h < settings.mh ? settings.h : settings.mh;
+		}
+		
+		href = settings.href;
+		
+		loadingTimer = setTimeout(function () {
+			$loadingOverlay.show().appendTo($content);
+		}, 100);
+		
+		if (settings.inline) {
+			// Inserts an empty placeholder where inline content is being pulled from.
+			// An event is bound to put inline content back when ColorBox closes or loads new content.
+			$tag(div).hide().insertBefore($(href)[0]).one(event_purge, function () {
+				$(this).replaceWith($loaded.children());
+			});
+			prep($(href));
+		} else if (settings.iframe) {
+			// IFrame element won't be added to the DOM until it is ready to be displayed,
+			// to avoid problems with DOM-ready JS that might be trying to run in that iframe.
+			prep(" ");
+		} else if (settings.html) {
+			prep(settings.html);
+		} else if (isImage(href)) {
+			$(photo = new Image())
+			.addClass(prefix + 'Photo')
+			.error(function () {
+				settings.title = false;
+				prep($tag(div, 'Error').html(settings.imgError));
+			})
+			.load(function () {
+				var percent;
+				photo.onload = null; //stops animated gifs from firing the onload repeatedly.
+				
+				if (settings.scalePhotos) {
+					setResize = function () {
+						photo.height -= photo.height * percent;
+						photo.width -= photo.width * percent;
+					};
+					if (settings.mw && photo.width > settings.mw) {
+						percent = (photo.width - settings.mw) / photo.width;
+						setResize();
+					}
+					if (settings.mh && photo.height > settings.mh) {
+						percent = (photo.height - settings.mh) / photo.height;
+						setResize();
+					}
+				}
+				
+				if (settings.h) {
+					photo.style.marginTop = Math.max(settings.h - photo.height, 0) / 2 + 'px';
+				}
+				
+				if ($related[1] && (settings.loop || $related[index + 1])) {
+					photo.style.cursor = 'pointer';
+					photo.onclick = function () {
+						publicMethod.next();
+					};
+				}
+				
+				if (isIE) {
+					photo.style.msInterpolationMode = 'bicubic';
+				}
+				
+				setTimeout(function () { // A pause because Chrome will sometimes report a 0 by 0 size otherwise.
+					prep(photo);
+				}, 1);
+			});
+			
+			setTimeout(function () { // A pause because Opera 10.6+ will sometimes not run the onload function otherwise.
+				photo.src = href;
+			}, 1);
+		} else if (href) {
+			$loadingBay.load(href, settings.data, function (data, status, xhr) {
+				prep(status === 'error' ? $tag(div, 'Error').html(settings.xhrError) : $(this).contents());
+			});
+		}
+	};
+		
+	// Navigates to the next page/image in a set.
+	publicMethod.next = function () {
+		if (!active && $related[1] && (settings.loop || $related[index + 1])) {
+			index = getIndex(1);
+			publicMethod.load();
+		}
+	};
+	
+	publicMethod.prev = function () {
+		if (!active && $related[1] && (settings.loop || index)) {
+			index = getIndex(-1);
+			publicMethod.load();
+		}
+	};
+
+	// Note: to use this within an iframe use the following format: parent.$.fn.colorbox.close();
+	publicMethod.close = function () {
+		if (open && !closing) {
+			
+			closing = true;
+			
+			open = false;
+			
+			trigger(event_cleanup, settings.onCleanup);
+			
+			$window.unbind('.' + prefix + ' .' + event_ie6);
+			
+			$overlay.fadeTo(200, 0);
+			
+			$box.stop().fadeTo(300, 0, function () {
+			
+				$box.add($overlay).css({'opacity': 1, cursor: 'auto'}).hide();
+				
+				trigger(event_purge);
+				
+				$loaded.remove();
+				
+				setTimeout(function () {
+					closing = false;
+					trigger(event_closed, settings.onClosed);
+				}, 1);
+			});
+		}
+	};
+
+	// Removes changes ColorBox made to the document, but does not remove the plugin
+	// from jQuery.
+	publicMethod.remove = function () {
+		$([]).add($box).add($overlay).remove();
+		$box = null;
+		$('.' + boxElement)
+			.removeData(colorbox)
+			.removeClass(boxElement)