Topic Closed
mahotilo
91 Posts

Is it possible to make option for automatic creation of gallery images captions based on file name?

It will be very useful in many cases. 

For example it may be a simple button "Set captions from file names" for batch process of all images in gallery

3 years ago#9996

juergen
1.4K Posts
51.6K Downloads
16 Plugins
design, web development & visual effects

Your suggestion with the button would require to change the gallery code.

A simple solution would be to add these lines to your template.php

<?php
$page->jQueryCode .= '
  $(document).on("cbox_complete", function(){
    var filename = $("#cboxLoadedContent .cboxPhoto").attr("src").split("/").pop();
    $("#cboxTitle").text(filename);
  });
';
?>

This will simply set the images' file names as caption.
 

Edited: 3 years ago#10007

mahotilo
91 Posts

I will try it as you say

Thank you, Juergen .

Your help is really invaluable to TS community.

3 years ago#10009

juergen
1.4K Posts
51.6K Downloads
16 Plugins
design, web development & visual effects

BTW: If you want to strip the file extension and replace underscores with spaces, use this:

<?php 
$page->jQueryCode .= '
  $(document).on("cbox_complete", function(){ 
    var filename = $("#cboxLoadedContent .cboxPhoto").attr("src").split("/").pop(); 
    var caption = filename.substring(0, filename.lastIndexOf(".")).split("_").join(" ");
    $("#cboxTitle").text(caption);
  }); 
'; 
?>
3 years ago#10011

mahotilo
91 Posts

Thanks!

I have tried you code. It is nice but it patch only Colorbox window appearance.

Inspired with yours code I have made a patch for gallery_edit_202.js

I know, It is rough. But it completely satisfied me.

I have changed this function

 function n(b, f) {
    gp_editor.edit_div.find(".gp_to_remove").remove();
    l.find(".gp_to_remove").remove();
    b.attr({"data-cmd":gp_editor.img_name, "data-arg":gp_editor.img_rel, title:"", "class":gp_editor.img_rel});
// !!!!! Patch. Caption from file name
    var e = $(b), c = e.find("img").attr("src");
    var d = c.substring(c.lastIndexOf("/")+1, c.lastIndexOf(".",c.lastIndexOf(".")-1)).split("_").join(" ");
    var a = $("<li>").append(b).append('<div class="caption">'+d+'</div>');
// ^^^^^^^^^^^^^^^^^^^^^^^^    
    f ? f.replaceWith(a) : h.append(a);
    a.trigger("gp_gallery_add");
    gp_editor.addedImage(a);
    p(a);
  }


Next step is to add a checkbox into Inline editor for option. But, It too difficult for me:)

So it will be nice if someone try to complete my idea  and send patch on Github.

3 years ago#10014

juergen
1.4K Posts
51.6K Downloads
16 Plugins
design, web development & visual effects

In my opinion, it would need 3 options to make it a useful, general-purpose feature

  • a checkbox:  [ x ] automatically use image file names as captions when adding new images
  • a button: [ replace empty captions with image file names ]
  • a 2nd button: [ replace all captions with image file names ]

This might be posssible as a plugin, extending the gallery editor (not yet tried).
I'm uncertain if it actually should be added to the default gallery editor.

Edited: 3 years ago#10015

mahotilo
91 Posts

Yes it will be super. I still think that it should be the property of the TS, but the plugin is also convenient (and faster to release).

I also think 2nd button [ replace all captions with image file names ] may be simple [clear all]. Together with 1st button it gives same functionality plus another one.

But really fantastic option is possibility to export/import plain txt file with file names and captions.
In some cases it is dangerous to name files on server with Cyrillic symbols. So "caption from file name" is not a complete solution for gallery automation.
Export/import should be cure in all cases. But I understand all the risks of importing file with errors.

By the way. This problem (set up captions for images) rises for me after the TS 5. New gallery settings window on the right is not very convenient to edit image captions. It was much easier to do directly in the gallery. But I still love in TS 5.

Edited: 3 years ago#10016

Topic Closed

 

News

Typesetter 5.1
8/12/2017

Typesetter 5.0.1 is now available for download. 5.1 includes bug fixes, UI/UX improvements, ... Read More

Over 8 Times Faster Than Wordpress
5/3/2016

We've known for a long time that Typesetter is fast. It's something we take pride ... Read More

More News

creisi productions

Dienstleistungen von creisi productions, Luzern (Schweiz): * Konzeption, Planung und Erstellung Ihres Internet-Auftritts * Betreuung und Aktualisierung/Pflege Ihrer Website * ...

Find out more about our Provider Spotlight

Log In

  Register