Skip to content

Instantly share code, notes, and snippets.

@jayfresh
Created September 4, 2014 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jayfresh/f8e61419c3c56e1a7448 to your computer and use it in GitHub Desktop.
Save jayfresh/f8e61419c3c56e1a7448 to your computer and use it in GitHub Desktop.
modal widgets - how to close them
/*
This is a paraphrased version of some code I'm working on.
What I'm trying to achieve is:
- open a modal with a custom footer (see 'footer' property of the addTiddler call)
- the footer contains a $button widget with a custom message
- listen for the custom message on $tw.rootWidget and update localstorage to note the button has been clicked
- then close the modal and show another div
I've got as far as the last step. The event handler on $tw.rootWidget doesn't give me any
of the widgets that make up the modal, so I can't dispatch 'tw-close-tiddler' on them. Dispatch
'tw-close-tiddler' on $tw.rootWidget doesn't do anything (which I expect).
Is there a way grab a reference to the widgets in the modal so I can dispatch 'tw-close-tiddler' on them?
If not, is there another to close the modal I could use?
*/
var title = 'Terms & Conditions',
message = $('.welcome-tool > div.card').html().replace('&','&');
$tw.wiki.addTiddler({
title: title,
text: message,
footer: '<$button class="welcome-tool-submit btn btn-primary btn-lg btn-block disabled" message="welcome-tool-submit">Accept and Get Started</$button>'
});
$tw.rootWidget.addEventListener("welcome-tool-submit", function() {
localStorage.setItem('ctrlio-terms-accepted', 'true');
// TO-DO: close the widget and show the tools card
});
window.setTimeout(function() {
if ($tw.modal.modalCount === 0) {
$tw.modal.display(title);
}
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment