Last active
November 24, 2016 00:29
-
-
Save dannyvassallo/8768f8ac13e4f422ec7d to your computer and use it in GitHub Desktop.
Replace Rails 4 confirmation/prompts with a toast message from Dogfalo Materialize CSS. Regular repo - https://github.com/Dogfalo/materialize Sass Gem - https://github.com/mkhairi/materialize-sass Website - http://materializecss.com/
This file contains 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 characters
$ -> | |
$.rails.allowAction = (link) -> | |
return true unless link.attr("data-confirm") | |
$.rails.showConfirmDialog link | |
false | |
$.rails.confirmed = (link) -> | |
link.removeAttr "data-confirm" | |
link.trigger "click.rails" | |
$.rails.showConfirmDialog = (link) -> | |
html = undefined | |
message = undefined | |
message = link.attr("data-confirm") | |
html = "<div id=\"modal1\" class=\"modal\" style=\"z-index: 1003; display: block; opacity: 1; transform: scaleX(1); top: 10%;\"> <div class=\"modal-content\"><h4>" + message + "</h4></div><div class=\"modal-footer\"><a class=\"modal-action modal-close waves-effect waves-red btn-flat close\">Cancel</a><a class=\"modal-action modal-close waves-effect waves-green btn-flat confirm\">OK</a></div></div>" | |
$("body").append html | |
$("#modal1").openModal complete: -> | |
$("#modal1").remove() | |
return $("#modal1 .confirm").on("click", -> | |
$.rails.confirmed link | |
) | |
$("#modal1 .close").on "click", -> | |
$("#modal1").closeModal() |
This file contains 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 characters
$(function() { | |
$.rails.allowAction = function(link) { | |
if (!link.attr('data-confirm')) { | |
return true; | |
} | |
$.rails.showConfirmDialog(link); | |
return false; | |
}; | |
$.rails.confirmed = function(link) { | |
link.removeAttr('data-confirm'); | |
return link.trigger('click.rails'); | |
}; | |
$.rails.showConfirmDialog = function(link) { | |
var html, message; | |
message = link.attr('data-confirm'); | |
html = "<div id=\"modal1\" class=\"modal\" style=\"z-index: 1003; display: block; opacity: 1; transform: scaleX(1); top: 10%;\"> <div class=\"modal-content\"><h4>" + message + "</h4></div><div class=\"modal-footer\"><a class=\"modal-action modal-close waves-effect waves-red btn-flat close\">Cancel</a><a class=\"modal-action modal-close waves-effect waves-green btn-flat confirm\">OK</a></div></div>"; | |
$('body').append(html); | |
$('#modal1').openModal({ | |
complete: function() { | |
$('#modal1').remove(); | |
} | |
}); | |
return $('#modal1 .confirm').on('click', function() { | |
return $.rails.confirmed(link); | |
}); | |
return $('#modal1 .close').on('click', function() { | |
return $('#modal1').closeModal(); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ive updated this to work with v0.97.8 here: https://gist.github.com/chris-gooley/6d84f13b6bdc178411390ebe1fef9604