summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@users.sourceforge.net>2009-01-03 15:20:58 +0100
committerTomas Bzatek <tbzatek@users.sourceforge.net>2009-01-03 15:20:58 +0100
commita90b52cda533af04dd8c827029d093cfde44090c (patch)
treecdc699fa562cdde28b2e04a4a476b7bf194cef9a
parentf7168d75b60c4d36083529d1c465f58d14a48c03 (diff)
downloadcataract-a90b52cda533af04dd8c827029d093cfde44090c.tar.xz
Scroll to parent item when going up
-rw-r--r--generators.c40
-rw-r--r--items.h3
-rw-r--r--sample/src/setup.xml6
-rw-r--r--setup.c5
-rw-r--r--setup.h1
-rw-r--r--templates/template-album.tmpl6
-rw-r--r--templates/template-index.tmpl6
7 files changed, 49 insertions, 18 deletions
diff --git a/generators.c b/generators.c
index 4e36648..170c283 100644
--- a/generators.c
+++ b/generators.c
@@ -215,11 +215,11 @@ write_html_album (TGallerySetup *setup,
gboolean in_img_separator;
gboolean in_go_up_string;
char *b;
- char *s1, *s2, *s3, *s4;
+ char *s1, *s2, *s3, *s4, *s5;
TAlbum *parent;
TIndexItem *item;
TIndexItem *tmp_item;
- int level;
+ int level, old_parent_item_index;
gboolean res;
int i;
unsigned long img_w, img_h;
@@ -328,8 +328,14 @@ write_html_album (TGallerySetup *setup,
in_go_up_string = FALSE;
free (b);
/* print the "Go Up" string if not toplevel */
- if (items->parent_index)
+ if (items->parent_index) {
b = strdup (buf_go_up_string);
+ if (strstr (b, "$(GO_UP_LINK)")) {
+ s1 = setup->use_inpage_links ? g_strdup_printf ("../index.html#i%d", items->parent_item_index + 1) : g_strdup ("../index.html");
+ str_replace (&b, "$(GO_UP_LINK)", s1, NULL);
+ g_free (s1);
+ }
+ }
else continue;
}
if (in_go_up_string) {
@@ -411,17 +417,21 @@ write_html_album (TGallerySetup *setup,
if (strstr (b, "<!-- $(NAV_BAR) -->")) {
s1 = g_strdup (items->ID);
fix_entities (&s1);
+ old_parent_item_index = items->parent_item_index + 1;
parent = items->parent_index;
level = 1;
while (parent) {
s3 = make_string ("../", level);
s4 = g_strdup (parent->ID);
fix_entities (&s4);
- s2 = g_strconcat ("<a href=\"", s3, "index.html\">", s4, "</a> &gt; ", s1, NULL);
+ s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", old_parent_item_index) : g_strdup ("");
+ s2 = g_strdup_printf ("<a href=\"%sindex.html%s\">%s</a> &gt; %s", s3, s5, s4, s1);
free (s3);
g_free (s1);
g_free (s4);
+ g_free (s5);
s1 = s2;
+ old_parent_item_index = parent->parent_item_index + 1;
parent = parent->parent_index;
level++;
}
@@ -496,13 +506,18 @@ write_html_album (TGallerySetup *setup,
str_replace (&s1, "<!-- $(IMG_DESCRIPTION) -->", s2, NULL);
g_free (s2);
}
- if (strstr(s1, "<!-- $(ALBUM_NUM_ITEMS) -->")) {
+ if (strstr (s1, "<!-- $(ALBUM_NUM_ITEMS) -->")) {
s3 = g_strconcat (items->base_dir, "/", item->path, "/index.xml", NULL);
s2 = g_strdup_printf ("%d", get_album_objects_count (s3));
str_replace (&s1, "<!-- $(ALBUM_NUM_ITEMS) -->", s2, NULL);
g_free (s2);
g_free (s3);
}
+ if (strstr (s1, "<!-- $(IMG_LIST_ID) -->")) {
+ s2 = g_strdup_printf ("i%d", i + 1);
+ str_replace (&s1, "<!-- $(IMG_LIST_ID) -->", s2, NULL);
+ g_free (s2);
+ }
if (strstr (s1, "<!-- $(IMG_THUMBNAIL) -->")) {
s2 = g_strconcat (THUMBNAIL_DIR, "/", thumb, NULL);
str_replace (&s1, "<!-- $(IMG_THUMBNAIL) -->", s2, NULL);
@@ -601,12 +616,12 @@ write_html_image (TGallerySetup *setup,
TIndexItem *tmp_item;
TAlbum *parent;
int i;
- char *s1, *s2, *s3, *s4;
+ char *s1, *s2, *s3, *s4, *s5;
char *imgname, *preload_imgname;
char *title, *title_desc;
char *b;
gboolean res;
- int level;
+ int level, old_parent_item_index;
gboolean override_title_meta;
@@ -785,11 +800,14 @@ write_html_image (TGallerySetup *setup,
s3 = make_string ("../", level);
s4 = g_strdup (parent->ID);
fix_entities (&s4);
- s2 = g_strconcat ("<a href=\"", s3, "index.html\">", s4, "</a> &gt; ", s1, NULL);
+ s5 = setup->use_inpage_links ? g_strdup_printf ("#i%d", parent == parent_items ? item_index : old_parent_item_index) : g_strdup ("");
+ s2 = g_strdup_printf ("<a href=\"%sindex.html%s\">%s</a> &gt; %s", s3, s5, s4, s1);
free (s3);
g_free (s1);
g_free (s4);
+ g_free (s5);
s1 = s2;
+ old_parent_item_index = parent->parent_item_index + 1;
parent = parent->parent_index;
level++;
}
@@ -984,7 +1002,8 @@ gboolean
build_tree (TGallerySetup *setup,
const char *src_tree,
const char *dst_dir,
- TAlbum *parent_index)
+ TAlbum *parent_index,
+ int parent_item_index)
{
char *idx_file;
TAlbum *items;
@@ -1034,6 +1053,7 @@ build_tree (TGallerySetup *setup,
}
g_free (idx_file);
items->parent_index = parent_index;
+ items->parent_item_index = parent_item_index;
/* Copy support files */
@@ -1125,7 +1145,7 @@ build_tree (TGallerySetup *setup,
if (item->type == INDEX_ITEM_TYPE_PICTURE) {
s1 = g_strconcat (src_tree, "/", item->path, "/", NULL);
s2 = g_strconcat (dst_dir, "/", item->path, "/", NULL);
- build_tree (setup, s1, s2, items);
+ build_tree (setup, s1, s2, items, i);
g_free (s1);
g_free (s2);
}
diff --git a/items.h b/items.h
index e917e82..810f758 100644
--- a/items.h
+++ b/items.h
@@ -40,7 +40,8 @@ typedef struct {
char *footnote;
GPtrArray *items;
char *base_dir;
- void *parent_index; // pointer to the parent TAlbum structure
+ void *parent_index; /* pointer to the parent TAlbum structure */
+ int parent_item_index; /* item index in the parent album */
int quality;
unsigned long landscape_width;
unsigned long landscape_height;
diff --git a/sample/src/setup.xml b/sample/src/setup.xml
index 22c6823..ca2c338 100644
--- a/sample/src/setup.xml
+++ b/sample/src/setup.xml
@@ -64,6 +64,12 @@
<add_copyright>This is custom copyright string added to every picture.
And the second line.</add_copyright>
</meta>
+
+ <navigation>
+ <!-- enabled: jump to the parent item when going up in the structure -->
+ <!-- disabled: links will always go to the top of the parent page -->
+ <use_inpage_links value="yes" />
+ </navigation>
<footer><![CDATA[
<div class="footer">So this is footer, suitable place for copyright, W3C validation links and advertisement! |
diff --git a/setup.c b/setup.c
index 0584130..40da036 100644
--- a/setup.c
+++ b/setup.c
@@ -124,11 +124,14 @@ parse_setup_xml (const char *filename, TGallerySetup *setup)
setup->erase_exif_thumbnail = s ? strcasecmp (s, "yes") == 0 : FALSE; /* default to FALSE */
if (s) g_free (s);
s = xml_file_get_node_attribute (xml, "/gallery_setup/meta/use_title_as_meta", "value");
- setup->use_title_as_meta = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to FALSE */
+ setup->use_title_as_meta = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
if (s) g_free (s);
setup->site_title = xml_file_get_node_attribute (xml, "/gallery_setup/meta/site", "title");
setup->add_copyright = xml_file_get_node_value (xml, "/gallery_setup/meta/add_copyright/text()");
+ s = xml_file_get_node_attribute (xml, "/gallery_setup/navigation/use_inpage_links", "value");
+ setup->use_inpage_links = s ? strcasecmp (s, "yes") == 0 : TRUE; /* default to TRUE */
+ if (s) g_free (s);
xml_parser_close (xml);
diff --git a/setup.h b/setup.h
index 4b2592d..8affdd6 100644
--- a/setup.h
+++ b/setup.h
@@ -61,6 +61,7 @@ typedef struct {
char *site_title;
char *add_copyright;
+ gboolean use_inpage_links;
} TGallerySetup;
diff --git a/templates/template-album.tmpl b/templates/template-album.tmpl
index f8e0a06..355c290 100644
--- a/templates/template-album.tmpl
+++ b/templates/template-album.tmpl
@@ -24,7 +24,7 @@
<!-- ## Description -->
<div class="desc">
<!-- $(BEGIN_GO_UP) -->
-<div class="desc_date">:. <a href="../index.html" id="exif_line_a">Go Up</a><br /><br /><br /></div>
+<div class="desc_date">:. <a href="$(GO_UP_LINK)" id="exif_line_a">Go Up</a><br /><br /><br /></div>
<!-- $(END_GO_UP) -->
<!-- $(TITLE) -->
<div class="desc_text"><!-- $(DESCRIPTION) --></div>
@@ -35,7 +35,7 @@
<div class="bigthumbnails">
<!-- $(BEGIN_IMG_LIST) -->
<!-- $(BEGIN_IMG_LIST_LANDSCAPE) -->
- <div class="one_thumbnail">
+ <div class="one_thumbnail" id="<!-- $(IMG_LIST_ID) -->">
<a href="<!-- $(IMG_SUBPAGE) -->">
<img src="<!-- $(IMG_THUMBNAIL) -->" alt="<!-- $(IMG_TITLE) -->" /><br />
<span class="thumb_name"><!-- $(IMG_FILENAME) --></span>
@@ -43,7 +43,7 @@
</div>
<!-- $(END_IMG_LIST_LANDSCAPE) -->
<!-- $(BEGIN_IMG_LIST_PORTRAIT) -->
- <div class="one_thumbnail">
+ <div class="one_thumbnail" id="<!-- $(IMG_LIST_ID) -->">
<a href="<!-- $(IMG_SUBPAGE) -->">
<img src="<!-- $(IMG_THUMBNAIL) -->" alt="<!-- $(IMG_TITLE) -->" class="portrait" /><br />
<span class="thumb_name"><!-- $(IMG_FILENAME) --></span>
diff --git a/templates/template-index.tmpl b/templates/template-index.tmpl
index 684482b..f335014 100644
--- a/templates/template-index.tmpl
+++ b/templates/template-index.tmpl
@@ -24,7 +24,7 @@
<!-- ## Description -->
<div class="desc">
<!-- $(BEGIN_GO_UP) -->
-<div class="desc_date">:. <a href="../index.html" id="exif_line_a">Go Up</a><br /><br /><br /></div>
+<div class="desc_date">:. <a href="$(GO_UP_LINK)" id="exif_line_a">Go Up</a><br /><br /><br /></div>
<!-- $(END_GO_UP) -->
<!-- $(TITLE) -->
<div class="desc_text"><!-- $(DESCRIPTION) --></div>
@@ -35,7 +35,7 @@
<div class="albumlist">
<!-- $(BEGIN_IMG_LIST) -->
<!-- $(BEGIN_IMG_LIST_LANDSCAPE) -->
- <div class="one_album">
+ <div class="one_album" id="<!-- $(IMG_LIST_ID) -->">
<a href="<!-- $(ALBUM_SUBPATH) -->">
<img src="<!-- $(IMG_THUMBNAIL) -->" alt="<!-- $(IMG_TITLE) -->" />
<span class="album_text"><!-- $(IMG_TITLE) --></span><br /><br /><br />
@@ -45,7 +45,7 @@
</div>
<!-- $(END_IMG_LIST_LANDSCAPE) -->
<!-- $(BEGIN_IMG_LIST_PORTRAIT) -->
- <div class="one_album">
+ <div class="one_album" id="<!-- $(IMG_LIST_ID) -->">
<a href="<!-- $(ALBUM_SUBPATH) -->">
<img src="<!-- $(IMG_THUMBNAIL) -->" alt="<!-- $(IMG_TITLE) -->" />
<span class="album_text_portrait"><!-- $(IMG_TITLE) --></span><br /><br /><br />