Index: js_theming.messages.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/js_theming/js_theming.messages.js,v retrieving revision 1.1 diff -u -p -r1.1 js_theming.messages.js --- js_theming.messages.js 19 Jul 2008 09:27:18 -0000 1.1 +++ js_theming.messages.js 3 Oct 2008 15:38:25 -0000 @@ -7,19 +7,19 @@ Drupal.messages = { messages: {}, /* Messages storage object */ length: 0, /* Length of the messages object. Represents number of different message types */ -/** - * Return all messages that have been set. - * - * @param $type - * (optional) Only return messages of this type. - * @param $clear_queue - * (optional) Set to FALSE if you do not want to clear the messages queue - * @return - * An associative array, the key is the message type, the value an array - * of messages. If the $type parameter is passed, you get only that type, - * or an empty array if there are no such messages. If $type is not passed, - * all message types are returned, or an empty array if none exist. - */ + /** + * Return all messages that have been set. + * + * @param $type + * (optional) Only return messages of this type. + * @param $clear_queue + * (optional) Set to FALSE if you do not want to clear the messages queue + * @return + * An associative array, the key is the message type, the value an array + * of messages. If the $type parameter is passed, you get only that type, + * or an empty array if there are no such messages. If $type is not passed, + * all message types are returned, or an empty array if none exist. + */ /* @todo: make sure this function covers all edge cases*/ get: function(type, clearQueue) { var temp = this.messages; @@ -50,28 +50,31 @@ Drupal.messages = { } return {length:0}; }, -/** - * Set a message which reflects the status of the performed operation. - * - * If the function is called with no arguments, this function returns all set - * messages without clearing them. - * - * @param $message - * The message should begin with a capital letter and always ends with a - * period '.'. - * @param $type - * The type of the message. One of the following values are possible: - * - 'status' - * - 'warning' - * - 'error' - * @param $repeat - * If this is FALSE and the message is already set, then the message won't - * be repeated. - */ + /** + * Set a message which reflects the status of the performed operation. + * + * If the function is called with no arguments, this function returns all set + * messages without clearing them. + * + * @param $message + * The message should begin with a capital letter and always ends with a + * period '.'. + * @param $type + * The type of the message. One of the following values are possible: + * - 'status' + * - 'warning' + * - 'error' + * @param $repeat + * If this is FALSE and the message is already set, then the message won't + * be repeated. + */ set: function(message, type, repeat) {/* @todo: repeat feature is not working yet, fix */ - if ( type == undefined ) { - type = 'status'; - } + // Don't log anything if there's no message to log. + if (!message) { + return; + } + + type = type || 'status'; if ( repeat == undefined) { repeat = true; } @@ -79,9 +82,15 @@ Drupal.messages = { this.messages[type] = []; this.length++; } - if ( message != undefined && (repeat || !this.messages[type].some(Drupal.messages.strEqual, message))) { - this.messages[type].push(message + this.messages[type].length); - } + + // If repeat is off then we don't display a duplicate? + if (!repeat && this.messages[type].some(/*function (m) {return (this == m);}*/this.strEqual, message)) { + return; // Don't show a repeated message. + } + else { + this.messages[type].push(message); + } + $('.js_theming_messages').prepend('
'); this.enforceMaxMessages(Drupal.settings.maxMessagesInQueue); /* remove old messages */ this.hide(Drupal.settings.statusMessageDuration * 1000); @@ -92,16 +101,14 @@ Drupal.messages = { return (element == this); }, /** - * Perform a number of behaviors on page load + * Initialize the messages object. */ init: function() { this.hide(Drupal.settings.statusMessageDuration * 1000); /* Trigger the messages hide effect */ }, /* Helps removing messages if too many appear on the screen */ enforceMaxMessages: function (max) { - if ( max == undefined ) { - max = 10; /* default to 10 messages on screen at a time */ - } + max = max || 10; // default to 10 messages on screen at a time var currentMessages = $('.js_theming_messages').children('.messages'); for ( var i = 0; i < currentMessages.length;i++) { if ( i >= max ) {/*removes all messages beyond the maximum allowed*/ @@ -111,15 +118,16 @@ Drupal.messages = { }, /* Hides the status message after number of seconds */ hide: function(duration) { + duration = duration || 10000; // Default is ten seconds. clearTimeout(Drupal.messages.performingHide); - if ( duration == undefined ) { - duration = 10000; /* default to 10 seconds */ - } + $(".js_theming_messages").show(); /* We've hid it before, lets show it first */ /* Should we hide the status messages? */ if (Drupal.settings.enableHideMessages == 1 ) { Drupal.messages.performingHide = setTimeout(function(){ - $(".js_theming_messages").hide(); + // Hide the container, then remove all of the messages so they + // don't show again. + $(".js_theming_messages").hide().children('.messages').remove(); }, /* How long the messages will remain visible before hiding ( in milliseconds ) */ duration);