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

Include complex HTML in dialog #40

Closed
pferrel opened this issue Dec 25, 2013 · 4 comments
Closed

Include complex HTML in dialog #40

pferrel opened this issue Dec 25, 2013 · 4 comments
Labels

Comments

@pferrel
Copy link

pferrel commented Dec 25, 2013

I need to create a fairly complex modal sidebar for something like settings. I'd like to have is slide out from the left and remain in place attached to the left side of the viewport/window. The user will fiddle with settings and dismiss at some point.

I can see how to do most of this but wonder about how to put the fairly complex HTML into the dialog.

@adamschwartz
Copy link
Contributor

You can place any HTML you want inside a dialog. You can do this by setting content in the options object you pass to vex.open(options), or you can manually append it yourself since you are returned the $vexContent jQuery-ed DOM element from the open call. So let's say you have a page like this:

<html>
<head>
    <style>.templates { display: none }</style>
<body>
    <header><!--- .. --></header>
    <main><!--- .. --></main>
    <div class="templates">
        <sidebar id="sidebarTemplate"><!--- .. --></sidebar>
    </div>
</body>

You could either do this:

vex.open({
    content: $(sidebarTemplate).clone()
});

Or this:

var $vexContent = vex.open();
$vexContent.append($(sidebarTemplate).clone());

Of course, you'll additionally want to set the className option property to style the modal on the left in the way you desire. I'd recommend looking at the recently added theme "Bottom Right Corner" for guidance there.

@pferrel
Copy link
Author

pferrel commented Dec 25, 2013

Ah, tricky. I’ve been struggling with passing html as strings but never thought to do that.
thanks a bunch

@adamschwartz
Copy link
Contributor

No problem. There is more info in the Advanced page of the docs as well.

@qodeboy
Copy link

qodeboy commented Jun 17, 2016

Cloning HTML could produce duplicated IDs, which is bad and could introduce issues with other JS libraries or CSS. In my case, to warkaround this I wrapped up my templates into <script type="text/html"></script> and instead of cloning just doing $.html():

$(document).on('click', '[data-vex-toggle="modal"]', function (e) {
        e.preventDefault();

        var $trigger = $(this);
        var $template = $('script[type="text/html"]#' + $trigger.data('template'));

        if (!$template.length) {
            return;
        }

        vex.open({
            content: $template.html(),
            className: 'vex-theme-default'
        });
    });

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

No branches or pull requests

3 participants