views:

221

answers:

1

I'm trying to figure out the best way to implement an AJAX-y slider on the control panel of a WordPress widget. Because the sidebar admin itself is AJAX, I want to make sure that my solution doesn't conflict with what's already in place. The goal of the slider is to default to basic options but allow the user to opt-in to advanced options. The way to do this w/o AJAX is to have the user select an option, hit save on the widget, hit save on the sidebar, and then reload the widget (too many options, IMO).

Any ideas? Thanks!

+1  A: 

As I understand it, you're worried that you JavaScript code for the "AJAX-y slider" will have some kind of conflicts with the existing code.

Are you worried that your function names might conflict with those of the existing code? Well, I'd 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 something they are unlikely to choose. You can then access the variables and functions through that object:

myobjectname.confvar // 42
myobjectname.confmethod() // "hello!"
scraimer