Hey there,

I was curious if there was any way to display a Better Message formatted message manually outside of just hooking drupal_set_message() outputs. For example having a link in a template that when clicked shows a Better Message with a specified message, that way you can conceptually show a Better Message which anything anywhere without requiring a page callback to drupal_set_message()

Thanks

Comments

broncomania’s picture

Agree I also need a javscript call to open a message with my own message. This would be nice

nikita petrov’s picture

Hi all!
If you need to output you'r message in better messages format, you can do this:
first you need to add some js files on necessary pages, so put next line into hook _init() in your's module:

function nikita_petrov_init() {
better_messages_add_files(false);
}

After that you must write some javascript:

function show_better_message(title, text) {
        $("#better-messages-wrapper").each(function() { $(this).remove(); });
        $("body").append('<div id="better-messages-wrapper" style="display:none;overflow:visible;position:absolute;z-index:9999;">\n</div>');
                
        var $b = '\
        <div id="better-messages-default">\
          <div id="messages-inner">\
            <table><tbody>\
              <tr><td class="tl"></td><td class="b"></td><td class="tr"></td></tr>\
              <tr><td class="b"></td>\
                <td class="body">\
                  <div class="content">\
                                <h2 class="messages-label status">' + title + '</h2>\
        <div class="messages status">\
        ' + text + '\
        </div>\
                  </div>\
                  <div class="footer"><span class="message-timer"></span><a href="#" class="message-close"></a></div>\
                </td>\
                <td class="b"></td></tr>\
              <tr><td class="bl"></td><td class="b"></td><td class="br"></td></tr>\
            </tbody></table>\
          </div>\
        </div>\
        ';
        
        $("#better-messages-wrapper").html($b).show();
        Drupal.attachBehaviors("#better-messages-wrapper"); 
}

And in you'r javascript you simply must call

show_better_message('Your title', 'your text');

Unfortunatly, i dont know how to render better_messages.tpl.php by javascript, so if you'r theme overriding this, you must change $b variable from show_better_message function as you need.
(maybe someone will implement this with modules http://drupal.org/project/js_theming and http://drupal.org/project/jtemplate or similar?)

bucefal91’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

The 6.x version is no longer supported.