/*
* The Strangecode Codebase - a general application development framework for PHP
* For details visit the project site:
* Copyright © 2014 Strangecode, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
// Codebase functions will be under the Strangecode namespace, unless they are added to the jQuery object for chaining.
var Strangecode = Strangecode || {};
/*
* Class for managing user messages. This is the contructor function.
*
* @access public
* @param object containing object options:
{
container: '#sc-msg-formvalidator',
above_msg: 'Oops!'
}
* @author Quinn Comendant
* @version 1.0
* @since 18 Mar 2014 23:24:15
*
* Example of use:
---------------------------------------------------------------------
var sc_msg = new Strangecode.Msg({
container: '#sc-msg-formvalidator',
above_msg: 'The following errors occurred:'
});
sc_msg.raise('Oops, you fuxt up!', 'sc-msg-error');
sc_msg.clear();
sc_msg.raise('Ok, now you’re cool.', 'sc-msg-success');
---------------------------------------------------------------------
*/
Strangecode.Msg = function(options) {
// Merge options with defaults
this.o = $.extend({
container: '#sc-msg:last',
above_msg: '',
gotohash: true
}, options || {});
};
/*
* Raises a message to the user.
*
* @access public
* @param string message The message to display.
* @param string class The class to apply to the message div (when using codebase CSS, it is useful to use one of: sc-msg-success, sc-msg-notice, sc-msg-warning, sc-msg-error)
* @author Quinn Comendant
* @version 1.0
* @since 18 Mar 2014 23:24:15
*/
Strangecode.Msg.prototype.raise = function(message, msg_class) {
// If an "above msg" is provided, and one doesn't already exist, add it to the message box.
if (this.o.above_msg.length && !$(this.o.container).find('.sc-above').length) {
$(this.o.container).append($('').text(this.o.above_msg));
}
// Use 'sc-msg-error' as default class string.
msg_class = (typeof msg_class === 'undefined') ? 'sc-msg-error' : msg_class;
// Append this raised message to the sc-msg stack, if it doesn't exist already.
if (!$(this.o.container).find(':contains("' + message + '")').length) {
$(this.o.container).append($('').text(message)).show();
// $(this.o.container).append($('').hide().text(message).append('×'));
// $('.sc-js-msg').slideDown('fast');
}
if (this.o.gotohash) {
$(document.body).animate({
'scrollTop': $(this.o.container).offset().top
}, 'fast');
}
};
/*
* Removes all messages previously created by Msg.raise.
*
* @access public
* @param string message The message to display.
* @param string class The class to apply to the message div (when using codebase CSS, it is useful to use one of: sc-msg-success, sc-msg-notice, sc-msg-warning, sc-msg-error)
* @author Quinn Comendant
* @version 1.0
* @since 18 Mar 2014 23:24:15
*/
Strangecode.Msg.prototype.clear = function() {
// Append this raised message to the sc-msg stack.
var msg_class = (typeof msg_class === 'undefined') ? 'sc-msg-error' : msg_class;
$(this.o.container).find('.sc-js-msg').remove();
};