seiyria/bootstrap-slider — pull request #39 by rovolution (2013-11-16 02:47:49+00:00)
Title: Error is now thrown when public method is called by element without Slider object bound to it

hi seiyria,

This pull request is in response to [Issue#38](https://github.com/seiyria/bootstrap-slider/issues/38).

I implemented the functionality such that when a user tries to call a Slider instance method from an element that does not have a slider object bound to its 'slider' data attribute, the following error gets thrown:

```
Uncaught Error: Calling context element does not have instance of Slider bound to it. Check your code to make sure the JQuery object returned from the call to the slider() initializer is calling the method
```
I did this for the following reasons:
* To ensure that Slider instance methods can only be called by an element with a Slider object bound to its 'slider' data property. This Slider object is instantiated and bound within the bootstrap-slider library when a user creates a slider instance.
* Users can get a better understanding of where the error is coming from (and how they can avoid triggering it). Hence the suggestion within the error message to interface with the slider API using the wrapped JQuery element reference returned from the slider() initializer.

The way the check works is that when a user attempts to call a slider public method, the code will check to see if the element calling the method:

a) has an data property 'slider' bound to it
and
b) if so, is that property value an instance of Slider (via the native JS instanceof method)

Here is the method where the check occurs. It is called within the **invokePublicMethod()** function.

If the sliderObject bound to the element is valid, it is returned. If not, it will throw an error.
```
function retrieveSliderObjectFromElement(element) {
var sliderObject = $(element).data('slider');
if(sliderObject && sliderObject instanceof Slider) {
return sliderObject;
} else {
throw new Error(ErrorMsgs.callingContextNotSliderInstance);
}
}
```

I added tests to the PublicMethodSpecs file.

Let me know your thoughts/questions/feedback.

Thanks!