Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "destroy" method #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 60 additions & 1 deletion jquery.roundabout.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
} else {
// bind responsive action
if (settings.responsive) {
$(window).bind("resize", function() {
$(window).bind("resize.roundabout", function() {
methods.stopAutoplay.apply(self);
methods.relayoutChildren.apply(self);
});
Expand Down Expand Up @@ -1179,6 +1179,65 @@

// nothing was triggered, versions are the same
return 0;
},



// destroy
// -----------------------------------------------------------------------

// destroy
// destroys roundabout instance, returning all code to its original state
destroy: function() {
var self = $(this),
data = self.data("roundabout");

// Unbind window listeners
$(window).unbind(".roundabout");

// Unset classes and css on self
self
.removeClass("roundabout-holder")
.removeAttr("style");

// Unset classes and css on children
self
.children(data.childSelector)
.removeClass("roundabout-moveable-item")
.removeClass("roundabout-in-focus")
.removeData("roundabout")
.removeAttr("style");

// Universal unbind
self
.children(data.childSelector)
.andSelf()
.unbind(".roundabout")
.unbind(".roundabout.autoplay");

// un-bind buttons
if (data.btnNext) {
$(data.btnNext).unbind(".roundabout");
}
if (data.btnPrev) {
$(data.btnPrev).bind(".roundabout");
}
if (data.btnToggleAutoplay) {
$(data.btnToggleAutoplay).bind(".roundabout");
}
if (data.btnStartAutoplay) {
$(data.btnStartAutoplay).bind(".roundabout");
}
if (data.btnStopAutoplay) {
$(data.btnStopAutoplay).bind(".roundabout");
}


// @todo: Can we namespace the element.addEventListeners set in the "// on mobile" section?

// Remove all assigned Data
self
.removeData("roundabout");
}
};

Expand Down
Loading