I'm looking to create a general confirmation box that can be easily used by several widgets, but I ran into scope issues and was hoping for a clearer way to do what I'm trying to do.
I currently have the following -
(function() { var global = this; global.confirmationBox = function() { config = { container: '<div>', message:'' } return { config: config, render: function(caller) { var jqContainer = $(config.container); jqContainer.append(config.message); jqContainer.dialog({ buttons: { 'Confirm': caller.confirm_action, Cancel: caller.cancel_action } }); } } }
Currently, I just want to do something as simple as closing a window from a widget, but I think I wrapped my own brain in circles in terms of what it knows what. Does anyone want to help cleanse my puzzled brain?
Cheers, Sam
Received code:
I thought that it might be useful for people who next time will find this topic in search of a solution to a similar problem, to see the code resulting from the useful answers that I received here.
As it turned out, in the end it was pretty simple (as most disappointing mind-balls).
global.confirmationBox = function() { self = this; config = { container: '<div>', message: '', } return { set_config:config, render_message: function(caller) { var jqContainer = $(config.container); jqContainer.attr('id', 'confirmation-dialog'); jqContainer.append(config.message); jqContainer.dialog({ buttons: { 'Confirm': function() { caller.confirm_action(this); }, Cancel: function() { caller.cancel_action(this); } } }); } } }
javascript jquery dialog popup
Steerpike
source share