Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking in a table #57

Closed
tpg198 opened this issue Dec 14, 2012 · 6 comments
Closed

Breaking in a table #57

tpg198 opened this issue Dec 14, 2012 · 6 comments

Comments

@tpg198
Copy link

tpg198 commented Dec 14, 2012

When the slice point is in the middle of a table, the read more link appears before the top of table.

Example of this behaviour here http://jsfiddle.net/fFdDW/4/

I fixed this locally by modifying the backup function to not break in the middle of a table.

function backup(txt, preserveWords) {
if ( txt.lastIndexOf('<') > txt.lastIndexOf('>') ) {
txt = txt.slice( 0, txt.lastIndexOf('<') );
}
if ( txt.toLowerCase().indexOf('<table') > -1 ) {
txt = txt.slice( 0, txt.toLowerCase().indexOf('<table') );
}
if (preserveWords) {
txt = txt.replace(rAmpWordEnd,'');
}
return $.trim(txt);
}

A more generalised solution would be to allow a user to configure any elements that should not be broken by the slice.

Thanks for jqueryexpander :-)

@JamesMcFall
Copy link

I'm having this issue too where the read more link was being output and then another table was being output beneath it. I don't know what the previous poster meant by their code, because the only bit he added is mangled.

I've hacked this locally to get a dirty quick fix out and all I did was:

Modify the backup() method

If the splitter point is in the middle of a table, drop that table from the text that's going to be output.

    function backup(txt, preserveWords) {
            if ( txt.lastIndexOf('<') > txt.lastIndexOf('>') ) {
                txt = txt.slice( 0, txt.lastIndexOf('<') );
            }

            // Check if we're in the middle of a table, and if so, cut out the table
            lastOpenTable = txt.lastIndexOf('<table');
            lastClosedTable = txt.lastIndexOf('</table>');
            if (lastOpenTable > 0 && lastClosedTable > 0) {
                if (lastOpenTable > lastClosedTable) {
                    txt = txt.slice( 0, lastOpenTable );
                }
            }

            if (preserveWords) {
                txt = txt.replace(rAmpWordEnd,'');
            }

            return $.trim(txt);
        }

Modify the buildHTML() method

buildHTML() was putting the read more link before the tag (the end of my content finished with a closing table tag) so I've just made buildHTML() always append the read more tag (instead of tucking it inside the closing tag).

My solution is definitely a quick hack and isn't a "solution"... but it's got me out of trouble in this instance.

Thanks for your work on the plugin. Hopefully you can resolve this issue properly at some stage.

  • James

@travco
Copy link
Contributor

travco commented Jul 9, 2014

@JamesMcFall I wasn't able to reproduce this in the current state of the plugin. It closed out the table, tr, and td without an issue.

If you still have the HTML (or have a rough idea of what you were doing) where you were applying expander, I'd really appreciate it if you could check it again or post it so I can start looking for a more global solution.

@JamesMcFall
Copy link

Hi @travco. I don't remember which project this was on (this is going back 8-9 months) sorry. I'll have a look tonight and see if I can dig up what it was on. Thanks.

@travco
Copy link
Contributor

travco commented Jul 23, 2014

Judging by the lack of a reply the search didn't yield well. Thank you regardless for making an effort to look @JamesMcFall, I don't blame you for not remembering which project used which plugin almost a year back.

There were some changes to how the plugin handles where it slices recently, and they -should- have resolved most of the issues involving slicing inside of HTML elements.

If you suddenly stumble across anything, feel free to post it in here so Karl can reopen the issue.

@kswedberg Close issue?

@JamesMcFall
Copy link

Hi Travis,
Apologies on not getting back to you. I couldn't find the specific project sorry. It's nestled in somewhere amongst hundreds of projects on our GitLab setup at work :s

Feel free to close the issue. If I notice anything next time I use it I'll let you know.

Thanks for the plugin.

@kswedberg
Copy link
Owner

thanks, @JamesMcFall . Closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants