From 89f7f70f5af3a477cf502ce99a49a1159fbe8696 Mon Sep 17 00:00:00 2001 From: Yomi Colledge Date: Fri, 25 Jun 2010 10:40:57 +0100 Subject: [PATCH] Moved common flash rendering functionality into its own plugin --- .../jquery.render.flash.message.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 public/javascripts/jquery.render.flash.message.js diff --git a/public/javascripts/jquery.render.flash.message.js b/public/javascripts/jquery.render.flash.message.js new file mode 100644 index 00000000..1fcf1c89 --- /dev/null +++ b/public/javascripts/jquery.render.flash.message.js @@ -0,0 +1,30 @@ +(function($) { +/** +* A simple flash message render used for when we return an AJAX response +* @todo Add optional animation functionality +**/ +$.fn.renderFlashMessage = function(options) { + var opts = $.extend({}, $.fn.renderFlashMessage.defaults, options); + + return this.each(function() { + var $this = $(this), + $flashDiv = $("
").addClass("flash"), + $flashNoticeDiv = $("
").addClass("notice").html(opts.flashMessage); + + $this.before($flashDiv.html($flashNoticeDiv)); + }); + + // private function for debugging + function debug($obj) { + if (window.console && window.console.log) { + window.console.log($obj); + } + } +}; + +// default options +$.fn.renderFlashMessage.defaults = { + flashMessage: 'Default flash message' +}; + +})(jQuery); \ No newline at end of file