• Resolved poppydev

    (@poppydev)


    Dear Admin,

    Another small change I have made to the plugin that might help others until (if possible) added as a feature update.

    My customer needed to insert an image into their tables(s) without having to understand HTML markup. Even though it works it caused some confusion and allowed users to mess with the markup.

    The only way I could resolve this was through JS within a function:

    function tablepress_image_preview_script() {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
    function convertImageHTMLToElement() {
    $('td').each(function() {
    $(this).html($(this).html().replace(/&lt;img.*?src="(.*?)".*?\/&gt;/g, function(match, src) {
    return '<img src="' + src + '" style="max-width:150px; max-height:150px; width:auto; height:auto;" />';
    }));
    });
    }

    // Run on initial load
    convertImageHTMLToElement();

    // Run after any AJAX content load
    $(document).ajaxComplete(function() {
    convertImageHTMLToElement();
    });
    });
    </script>
    <?php
    }
    add_action('admin_footer', 'tablepress_image_preview_script');

    All this does is look for the html markup inside the table cell after inserting an image and convert it into an image. This removes the chance of anyone breaking the html code by changing it, or deleting what they do not understand, as well as making it easier for those to see what they will be injecting into the front end before saving.

    One thing I would like to see, is a way to style the back end to make the UI of the table easier to work with. The editable fields need to be fluid, and each row width editable.

    I have had to target the admin area with css like this:

    .tablepress-edit-0g-floor .jexcel td[data-x="1"] {min-width 70vw !important}

    etc. for some reason It doesn’t like %, only px and vw. I can only assume its down to the jexcel feature overriding or ignoring these rules.

    If I stretch the table(s) it works but if I refresh the browser they reset. Maybe the tool used to make these fluid needs some tweaks to be able to keep your custom width active. The only other option is Default column width. This works but is applied to all.

    Enjoy. P.S. Please do share if you find a cleaner solution to the above.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    thanks for this suggestion as well! Just to be sure that I understand: Here, you are replacing the escaped HTML code of an image with the unescaped version, so that that the image is shown? But how could someone then edit the HTML code for the image, if they wanted to?

    Regarding the column widths: Indeed, at this time, it’s only possible to set the default width (and number of lines) in the “Screen Options” tab. These settings will be saved and apply to all tables (and columns) alike. I do have plans to make the changes to different columns “stick”, i.e. save them, but I haven’t yet found the best data structure approach for this.

    Best wishes,
    Tobias

    Thread Starter poppydev

    (@poppydev)

    Hi Tobias,

    Thank you for getting back to me.

    In regards to the image. Yes I am escaping the html markup in place of the image but this doesn’t effect the table cell being editable.

    For example. If I highlight the table where the image thumbnail is shown and press delete it removes it. If I undo the changes the html markup returns and I can edit this – which then returns the image on the jQuery request. Something I need to improve on as it takes a few seconds to call the image. Possibly longer.

    Or if I delete the image and left click ‘Insert image’ I can return the image as html until I save the table.

    This is not a resolution to the issue but more a visual perspective. When my customer returns to the table, they will see the thumbnail image and now what they originally used.

    • This reply was modified 1 year, 10 months ago by poppydev.
    Plugin Author Tobias Bäthge

    (@tobiasbg)

    Hi,

    Thanks for the explanation, I definitely understand this better now!

    I like this idea, but I think instead of only adding support for images to TablePress, this can maybe be part of a greater initiative of adding more “visual”/”what you see is what you get” editing to TablePress in the future. I do have some ideas for this already and your approach will come in handy for that as well!

    Best wishes,
    Tobias

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Tablepress – Admin table content img improvements’ is closed to new replies.