-
-
Save birchestx/1c2357ca46a9c2a08934 to your computer and use it in GitHub Desktop.
Revisions
-
Karen Baker revised this gist
Jan 25, 2015 . 1 changed file with 7 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,4 +22,10 @@ $(document).ajaxComplete (event, request) -> </div> </div>") if msg #delete the flash message (if it was there before) when an ajax request returns no flash message $("#flash_hook").replaceWith("<div id='flash_hook'></div>") unless msg jQuery -> # empty the flash hook when close modal $(".modal").on "hidden.bs.modal", -> $("#flash_hook").empty() return -
hbrandl revised this gist
Jan 18, 2014 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ # encoding: UTF-8 class ApplicationController < ActionController::Base protect_from_forgery -
hbrandl revised this gist
Jan 18, 2014 . 2 changed files with 4 additions and 1 deletion.There are no files selected for viewing
File renamed without changes.This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,10 @@ class ApplicationController < ActionController::Base def flash_to_headers return unless request.xhr? msg = flash_message #replace german umlaute encoded in utf-8 to html escaped ones msg = msg.gsub("ä","ä").gsub("ü","ü").gsub("ö","ö").gsub("Ä","Ä").gsub("Ü","Ü").gsub("Ö","Ö").gsub("ß","ß") response.headers['X-Message'] = msg response.headers["X-Message-Type"] = flash_type.to_s flash.discard # don't want the flash to appear when you reload page -
hbrandl revised this gist
Jan 18, 2014 . 3 changed files with 22 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ Rails flash messages with AJAX requests & twitter-bootstrap 2.3 Forked from https://gist.github.com/linjunpop/3410235 Based on Stackoverflow answer: http://stackoverflow.com/a/10167659/656428 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,13 @@ def flash_message end def flash_type #:keep will instruct the js to not update or remove the shown message. #just write flash[:keep] = true (or any other value) in your controller code [:error, :warning, :notice, :keep].each do |type| return type unless flash[type].blank? end #don't return the array from above which would happen if we don't have an explicit return statement #returning :empty will also allow you to easily know that no flash message was transmitted return :empty end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,25 @@ #ajax call to show flash messages when they are transmitted in the header #this code assumes the following # 1) you're using twitter-bootstrap 2.3 (although it will work if you don't) # 2) you've got a div with the id flash_hook somewhere in your html code $(document).ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") alert_type = 'alert-success' alert_type = 'alert-error' unless request.getResponseHeader("X-Message-Type").indexOf("error") is -1 unless request.getResponseHeader("X-Message-Type").indexOf("keep") is 0 #add flash message if there is any text to display $("#flash_hook").replaceWith("<div id='flash_hook'> <p> </p> <div class='row'> <div class='span10 offset1'> <div class='alert " + alert_type + "'> <button type='button' class='close' data-dismiss='alert'>×</button> " + msg + " </div> </div> </div> </div>") if msg #delete the flash message (if it was there before) when an ajax request returns no flash message $("#flash_hook").replaceWith("<div id='flash_hook'></div>") unless msg -
hbrandl revised this gist
Dec 26, 2013 . 1 changed file with 4 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,10 @@ class ApplicationController < ActionController::Base def flash_to_headers return unless request.xhr? msg = flash_message #replace german umlaute encoded in utf-8 to html escaped ones msg = msg.gsub("ä","ä").gsub("ü","ü").gsub("ö","ö").gsub("Ä","Ä").gsub("Ü","Ü").gsub("Ö","Ö").gsub("ß","ß") response.headers['X-Message'] = msg response.headers["X-Message-Type"] = flash_type.to_s flash.discard # don't want the flash to appear when you reload page -
hbrandl renamed this gist
Jul 26, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,6 @@ Rails flash messages with AJAX requests & twitter-bootstrap Forked from https://gist.github.com/linjunpop/3410235 Based on Stackoverflow answer: http://stackoverflow.com/a/10167659/656428 License: MIT -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,4 +17,6 @@ $(document).ajaxComplete (event, request) -> </div> </div> </div> </div>") if msg #delete the flash message (if it was there before) when an ajax request returns no flash message $("#flash_hook").replaceWith("<div id='flash_hook'></div>") unless msg -
hbrandl revised this gist
Mar 27, 2013 . No changes.There are no files selected for viewing
-
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,12 +7,14 @@ $(document).ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") alert_type = 'alert-success' alert_type = 'alert-error' unless request.getResponseHeader("X-Message-Type").indexOf("error") is -1 $("#flash_hook").replaceWith("<div id='flash_hook'> <p> </p> <div class='row'> <div class='span10 offset1'> <div class='alert " + alert_type + "'> <button type='button' class='close' data-dismiss='alert'>×</button> " + msg + " </div> </div> </div> </div>") if msg -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,12 +7,14 @@ $(document).ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") alert_type = 'alert-success' alert_type = 'alert-error' unless request.getResponseHeader("X-Message-Type").indexOf("error") is -1 $("#flash_hook").replaceWith("<div id='flash_hook'> <p> </p> <div class='row'> <div class='span10 offset1'> <div class='alert " + alert_type + "'> <button type='button' class='close' data-dismiss='alert'>×</button> " + msg + " </div> </div> </div> </div>") if msg -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,4 @@ Rails flash messages with AJAX requests & twitter-bootstrap Forked from https://gist.github.com/linjunpop/3410235 Based on Stackoverflow answer: http://stackoverflow.com/a/10167659/656428 -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 15 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,18 @@ #ajax call to show flash messages when they are transmitted in the header #this code assumes the following # 1) you're using twitter-bootstrap (although it will work if you don't) # 2) you've got a div with the id flash_hook somewhere in your html code $(document).ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") alert_type = 'alert-success' alert_type = 'alert-error' unless request.getResponseHeader("X-Message-Type").indexOf("error") is -1 $("#flash_hook").replaceWith("<p> </p> <div class='row'> <div class='span10 offset1'> <div class='alert " + alert_type + "'> <button type='button' class='close' data-dismiss='alert'>×</button> " + msg + " </div> </div> </div>") if msg -
hbrandl revised this gist
Mar 27, 2013 . 2 changed files with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ <!DOCTYPE html> <html> <head> </head> <body> <!-- flash_message.js.coffee expects to find a div with this id in your html code --> <div id="flash_hook"></div> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +0,0 @@ -
hbrandl revised this gist
Mar 27, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,6 +17,8 @@ def flash_message [:error, :warning, :notice].each do |type| return flash[type] unless flash[type].blank? end # if we don't return something here, the above code will return "error, warning, notice" return '' end def flash_type -
linjunpop revised this gist
Aug 28, 2012 . 1 changed file with 14 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,27 +1,27 @@ class ApplicationController < ActionController::Base protect_from_forgery after_filter :flash_to_headers private def flash_to_headers return unless request.xhr? response.headers['X-Message'] = flash_message response.headers["X-Message-Type"] = flash_type.to_s flash.discard # don't want the flash to appear when you reload page end def flash_message [:error, :warning, :notice].each do |type| return flash[type] unless flash[type].blank? end end def flash_type [:error, :warning, :notice].each do |type| return type unless flash[type].blank? end end end -
linjunpop revised this gist
Aug 21, 2012 . 1 changed file with 3 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,8 @@ show_ajax_message = (msg, type) -> $("#flash-message").html "<div id='flash-#{type}'>#{msg}</div>" $("#flash-#{type}").delay(5000).slideUp 'slow' $(document).ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") type = request.getResponseHeader("X-Message-Type") show_ajax_message msg, type #use whatever popup, notification or whatever plugin you want -
linjunpop revised this gist
Aug 21, 2012 . 2 changed files with 15 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,18 +0,0 @@ This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # FLASH NOTICE ANIMATION fade_flash = -> $("#flash_notice").delay(5000).fadeOut "slow" $("#flash_alert").delay(5000).fadeOut "slow" $("#flash_error").delay(5000).fadeOut "slow" fade_flash() show_ajax_message = (msg, type) -> $("#flash-message").html "<div id='flash_#{type}'>#{msg}</div>" fade_flash() $("#flash-message").ajaxComplete (event, request) -> msg = request.getResponseHeader("X-Message") type = request.getResponseHeader("X-Message-Type") show_ajax_message msg, type #use whatever popup, notification or whatever plugin you want -
linjunpop created this gist
Aug 21, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ Rails flash messages with AJAX requests original: http://stackoverflow.com/a/10167659/656428 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ #flash-message - flash.each do |name, msg| = content_tag :div, msg, :id => "flash_#{name}" This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ // FLASH NOTICE ANIMATION var fade_flash = function() { $("#flash_notice").delay(5000).fadeOut("slow"); $("#flash_alert").delay(5000).fadeOut("slow"); $("#flash_error").delay(5000).fadeOut("slow"); }; fade_flash(); var show_ajax_message = function(msg, type) { $("#flash-message").html('<div id="flash_'+type+'">'+msg+'</div>'); fade_flash(); }; $("#flash-message").ajaxComplete(function(event, request) { var msg = request.getResponseHeader('X-Message'); var type = request.getResponseHeader('X-Message-Type'); show_ajax_message(msg, type); //use whatever popup, notification or whatever plugin you want }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ class ApplicationController < ActionController::Base protect_from_forgery after_filter :flash_to_headers def flash_to_headers return unless request.xhr? response.headers['X-Message'] = flash_message response.headers["X-Message-Type"] = flash_type.to_s flash.discard # don't want the flash to appear when you reload page end private def flash_message [:error, :warning, :notice].each do |type| return flash[type] unless flash[type].blank? end end def flash_type [:error, :warning, :notice].each do |type| return type unless flash[type].blank? end end end