com web/php: flashMessage() now accepts jQuery objects too: js/common.js

From: Date: Sun, 15 Dec 2013 23:10:12 +0000
Subject: com web/php: flashMessage() now accepts jQuery objects too: js/common.js
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-17652@lists.php.net to get a copy of this message
Commit: 965643135dd83499931eb19bb280944b2529a6ee Author: Dejan Marjanovic <dejan.marjanovic@gmail.com> Mon, 16 Dec 2013 00:10:12 +0100 Parents: be0f25fccdb365cf57be668606bf549224914351 Branches: master Link: http://git.php.net/?p=web/php.git;a=commitdiff;h=965643135dd83499931eb19bb280944b2529a6ee Log: flashMessage() now accepts jQuery objects too Changed paths: M js/common.js Diff: diff --git a/js/common.js b/js/common.js index db08c81..9955047 100755 --- a/js/common.js +++ b/js/common.js @@ -308,13 +308,7 @@ $(document).ready(function() { /* {{{ Init template generated flash messages */ $('#flash-message .message').each(function() { - var alertType = $(this).data('type') || 'success'; - var timeout = $(this).data('timeout') || 6000; - var n = flashMessage({ - text: $(this).html(), - type: alertType, - timeout: timeout - }); + flashMessage($(this)); }); /* }}} */ @@ -380,7 +374,7 @@ $(function() { /* }}} */ /* {{{ Flash Messenger */ -function flashMessage(options) +function flashMessage(o) { var defaults = { timeout: 6000, @@ -389,13 +383,29 @@ function flashMessage(options) parent: '#flash-message', }; - var options = $.extend(defaults, options); + // Options are passed, set defaults and generate message + if ( ! o.jquery) + { + var options = $.extend(defaults, o); - var id = 'id_' + Math.random().toString().replace('0.', ''); - var message = $('<div />').addClass('message ' + options.type).data('type', options.type).attr('id', id).html(options.text); - $(options.parent).append(message); + var id = 'id_' + Math.random().toString().replace('0.', ''); + + var message = $('<div />') + .addClass('message ' + options.type) + .data('type', options.type) + .attr('id', id) + .html(options.text); - var o = $('#' + id); + $(options.parent).append(message); + + var o = $('#' + id); + } + // jQuery object is passed, that means the message is pre-generated + // Only timeout is adjustable via data-timeout="" + else + { + var options = {timeout: o.data('timeout')}; + } var remove = function(o) { o.slideUp(400, function() {

« previous php.webmaster (#17652) next »