Yes, we probably all hate those annoying popup messages. But sometimes they might actually be useful. For example, on login, a popup message could be used to notify the user of ... well, something. And, of course, if our client wants one, then our personal opinion is irrelevant. So here's one easy way to make a reasonably simple popup message on login.
1. Plugin using OnWebLogin - sets SESSION value
$_SESSION['loginmessage'] = 'true';
2. Snippet (ShowLoginMessage) - checks for SESSION value and runs the getResourceField snippet if true
<?php
if(isset($_SESSION['loginmessage']) && $_SESSION['loginmessage'] == 'true') {
$output = $modx->runSnippet('getResourceField', array('id'=>'42', 'field'=>'content'));
$_SESSION['loginmessage'] = '';
unset($_SESSION['loginmessage']);
}
return $output;
3. Use snippet in template
<div id="footer">
[[$footerCopyrightBlock]]
<!-- login message will go here -->
[[!ShowLoginMessage]]
</div>
4. Create resource to contain message - use publish/unpublish and access permissions to show or not, and put message container in its content. The div element and its attributes are required for the JQuery UI dialog to do all of the heavy lifting for you.
<div id="popupMessage" title="Put Your Message Title Here">
<p>Lorem ipsum dolor sit amet, tation homero vis in, mea justo scaevola ei, vix tritani corrumpit ut. An nec primis audire facilis. Dolorum phaedrum percipitur sed ut. Ex cum ridens mediocritatem, semper alterum commune ius no, et noster delectus accusata per. Oratio iriure id eum, has ne natum dictas corrumpit.</p>
</div>
5. Javascript - JQuery, JQuery UI, JQuery UI theme, link to theme .css file, dialog initialization script
<link rel="stylesheet" href="assets/js/css/redmond/jquery-ui-1.9.2.custom.min.css" type="text/css" />
<script language="javascript" src="assets/js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script language="javascript" src="assets/js/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
<script>
$(function() {
$( "#popupMessage" ).dialog({
position: { my: "right bottom", at: "right bottom", of: window },
hide: {effect: "fade", duration: 3000}
});
setTimeout(function(){ $("#popupMessage").dialog("close"); }, 6000);
});
</script>
[ed. note: sottwell last edited this post 13 years, 9 months ago.]