AJAX in WordPress widget dashboard
I am trying to find the best way to implement AJAX-y slider in WordPress widget dashboard. Since the sidebar admin itself is AJAX, I want to make sure my solution doesn't conflict with what already exists. The purpose of the slider is to use basic options by default, but allow the user to select additional options. The way to do this without AJAX is for the user to select the option, hit the save on the widget, hit the save on the sidebar, and then reload the widget (too many options, IMO).
Any ideas? Thanks!
As far as I understand, you are concerned that the JavaScript code for the "AJAX-y slider" will have some conflicts with the existing code.
Are you worried that your function names might conflict with existing code names? Well, I would suggest a closure style object. Here's an example:
var myobjectname = (function() {
var a_possible_conflict_variable = 42;
function a_possible_conflict_function() {
return "hello!";
}
return { confvar: a_possible_conflict_variable,
confmethod: a_possible_conflict_function };
})();
And then you only need to worry about conflicting myobjectname
with existing code. Just choose what you are unlikely to choose. Then you can access variables and functions through this object:
myobjectname.confvar // 42
myobjectname.confmethod() // "hello!"
a source to share