Reputation: 2936
In creating my first jQuery plugin I want to use selectors inside the plugin code that are confined to the outermost selector. this.selector is perfect. It is, however, being taken away. :/ So rather than code a depreciated property I want to use the best practice.
I want to insure that I affect only items within the selector. Right now my plugin has mad spillage. My var panelCount is of course counting the whole page hiding and cycling more than it should etc.
snip...
var defaults = { displayCount: 2, startIndex: 0, panelClass: "panels", hoverClass: "hover", rounded: false }, settings = $.extend({}, defaults, options);
var panelCount = $("." + settings.panelClass).length; //needs restraints
snip
I use the following call to try to make sure chaining works.
$('.DisplayWall').metro({displayCount:2,hoverClass:"hover"}).css("color","red");
I have a fiddle here.
Upvotes: 4
Views: 1388
Reputation: 95066
The replacement for this.selector
is to not rely on the selector being used and instead use the element that was selected. Therefore, you should re-implement the this.each()
and then properly filter your selection per instance.
this.each(function () {
var $this = $(this);
$('.next',this).click(function () {
$('.previous',this)
$("." + settings.panelClass,this)
//etc...
})
Now, if you had TWO DisplayWall
elements, they would each work independently.
Don't forget that inside SetDisplay, this
is Window.
Upvotes: 2