Skip to content

Commit bbe27d6

Browse files
author
Rafael Staib
committed
Add destroy method to remove control behavior
1 parent a1ee0f5 commit bbe27d6

12 files changed

+164
-19
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.0.2
4+
5+
- Add destroy method to remove the control functionality completely
6+
37
## 1.0.1
48

59
- Fixed an iframe border and scrolling issue for older browsers (IE8 and lower)

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Everything you need to start is:
2020
<meta charset="utf-8">
2121
<script src="jquery.js"></script>
2222
<script src="jquery.steps.js"></script>
23+
<link href="jquery.steps.css" rel="stylesheet">
2324
</head>
2425
<body>
2526
<script>

build/jquery.steps-1.0.1.zip

-12.5 KB
Binary file not shown.

build/jquery.steps-1.0.2.zip

13.2 KB
Binary file not shown.

build/jquery.steps.js

+67-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* jQuery Steps v1.0.1 - 08/23/2013
2+
* jQuery Steps v1.0.2 - 10/15/2013
33
* Copyright (c) 2013 Rafael Staib (http://www.jquery-steps.com)
44
* Licensed under MIT http://www.opensource.org/licenses/MIT
55
*/
@@ -84,6 +84,43 @@ function decreaseCurrentIndexBy(state, decreaseBy)
8484
return state.currentIndex - decreaseBy;
8585
}
8686

87+
function destroy(wizard, options)
88+
{
89+
var eventNamespace = getEventNamespace(wizard);
90+
91+
92+
wizard.unbind(eventNamespace).removeData("uid").removeData("options")
93+
.removeData("state").removeData("steps").removeData("eventNamespace")
94+
.find(".actions a").unbind(eventNamespace);
95+
96+
97+
wizard.removeClass(options.clearFixCssClass + " vertical");
98+
99+
var contents = wizard.find(".content > *");
100+
101+
102+
contents.removeData("loaded").removeData("mode").removeData("url");
103+
104+
105+
contents.removeAttr("id").removeAttr("role").removeAttr("tabindex")
106+
.removeAttr("class").removeAttr("style")._removeAria("labelledby")
107+
._removeAria("hidden");
108+
109+
110+
wizard.find(".content > [data-mode='async'],.content > [data-mode='iframe']").empty();
111+
112+
var wizardSubstitute = $(format("<{0} class=\"{1}\"></{0}>", wizard.get(0).tagName, wizard.attr("class")));
113+
114+
if (wizard.attr("id") != null && wizard.attr("id") !== "")
115+
{
116+
wizardSubstitute._setId(wizard.attr("id"));
117+
}
118+
119+
wizardSubstitute.html(wizard.find(".content").html());
120+
wizard.after(wizardSubstitute);
121+
wizard.remove();
122+
}
123+
87124
function finishStep(wizard, state)
88125
{
89126
var currentStep = wizard.find(".steps li").eq(state.currentIndex);
@@ -111,6 +148,19 @@ function format(value)
111148
return value;
112149
}
113150

151+
function getEventNamespace(wizard)
152+
{
153+
var eventNamespace = wizard.data("eventNamespace");
154+
155+
if (eventNamespace == null)
156+
{
157+
eventNamespace = "." + getUniqueId(wizard);
158+
wizard.data("eventNamespace", eventNamespace);
159+
}
160+
161+
return eventNamespace;
162+
}
163+
114164
function getStepAnchor(wizard, index)
115165
{
116166
var uniqueId = getUniqueId(wizard);
@@ -551,17 +601,19 @@ function refreshSteps(wizard, options, state, index)
551601

552602
function registerEvents(wizard, options)
553603
{
554-
wizard.bind("finishing.steps", options.onFinishing);
555-
wizard.bind("finished.steps", options.onFinished);
556-
wizard.bind("stepChanging.steps", options.onStepChanging);
557-
wizard.bind("stepChanged.steps", options.onStepChanged);
604+
var eventNamespace = getEventNamespace(wizard);
605+
606+
wizard.bind("finishing" + eventNamespace, options.onFinishing);
607+
wizard.bind("finished" + eventNamespace, options.onFinished);
608+
wizard.bind("stepChanging" + eventNamespace, options.onStepChanging);
609+
wizard.bind("stepChanged" + eventNamespace, options.onStepChanged);
558610

559611
if (options.enableKeyNavigation)
560612
{
561-
wizard.bind("keyup.steps", keyUpHandler);
613+
wizard.bind("keyup" + eventNamespace, keyUpHandler);
562614
}
563615

564-
wizard.find(".actions a").bind("click.steps", paginationClickHandler);
616+
wizard.find(".actions a").bind("click" + eventNamespace, paginationClickHandler);
565617
}
566618

567619
function removeStep(wizard, options, state, index)
@@ -747,7 +799,7 @@ function renderTitle(wizard, options, state, header, index)
747799
}
748800

749801

750-
stepItem.children("a").bind("click.steps", stepClickHandler);
802+
stepItem.children("a").bind("click" + getEventNamespace(wizard), stepClickHandler);
751803
}
752804

753805
function saveCurrentStateToCookie(wizard, options, state)
@@ -876,6 +928,13 @@ $.fn.steps.add = function (step)
876928
return insertStep(this, options, state, state.stepCount, step);
877929
};
878930

931+
$.fn.steps.destroy = function ()
932+
{
933+
var options = getOptions(this);
934+
935+
return destroy(this, options);
936+
};
937+
879938
$.fn.steps.finish = function ()
880939
{
881940
var state = getState(this);

build/jquery.steps.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nuget/jQuery.Steps.1.0.1.nupkg

-14.7 KB
Binary file not shown.

nuget/jQuery.Steps.1.0.2.nupkg

15.2 KB
Binary file not shown.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jquery-steps",
33
"title": "jQuery Steps",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"description": "A powerful jQuery wizard plugin that supports accessibility and HTML5",
66
"homepage": "http://www.jquery-steps.com",
77
"author": {

src/privates.js

+76-7
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,51 @@ function decreaseCurrentIndexBy(state, decreaseBy)
145145
return state.currentIndex - decreaseBy;
146146
}
147147

148+
/**
149+
* Removes the control functionality completely and transforms the current state to the initial HTML structure.
150+
*
151+
* @static
152+
* @private
153+
* @method destroy
154+
* @param wizard {Object} A jQuery wizard object
155+
**/
156+
function destroy(wizard, options)
157+
{
158+
var eventNamespace = getEventNamespace(wizard);
159+
160+
// Remove virtual data objects from the wizard
161+
wizard.unbind(eventNamespace).removeData("uid").removeData("options")
162+
.removeData("state").removeData("steps").removeData("eventNamespace")
163+
.find(".actions a").unbind(eventNamespace);
164+
165+
// Remove attributes and CSS classes from the wizard
166+
wizard.removeClass(options.clearFixCssClass + " vertical");
167+
168+
var contents = wizard.find(".content > *");
169+
170+
// Remove virtual data objects from panels and their titles
171+
contents.removeData("loaded").removeData("mode").removeData("url");
172+
173+
// Remove attributes, CSS classes and reset inline styles on all panels and their titles
174+
contents.removeAttr("id").removeAttr("role").removeAttr("tabindex")
175+
.removeAttr("class").removeAttr("style")._removeAria("labelledby")
176+
._removeAria("hidden");
177+
178+
// Empty panels if the mode is set to 'async' or 'iframe'
179+
wizard.find(".content > [data-mode='async'],.content > [data-mode='iframe']").empty();
180+
181+
var wizardSubstitute = $(format("<{0} class=\"{1}\"></{0}>", wizard.get(0).tagName, wizard.attr("class")));
182+
183+
if (wizard.attr("id") != null && wizard.attr("id") !== "")
184+
{
185+
wizardSubstitute._setId(wizard.attr("id"));
186+
}
187+
188+
wizardSubstitute.html(wizard.find(".content").html());
189+
wizard.after(wizardSubstitute);
190+
wizard.remove();
191+
}
192+
148193
/**
149194
* Triggers the onFinishing and onFinished event.
150195
*
@@ -181,6 +226,28 @@ function format(value)
181226
return value;
182227
}
183228

229+
/**
230+
* Gets or creates if not exist an unique event namespace for the given wizard instance.
231+
*
232+
* @static
233+
* @private
234+
* @method getEventNamespace
235+
* @param wizard {Object} A jQuery wizard object
236+
* @return {String} Returns the unique event namespace for the given wizard
237+
*/
238+
function getEventNamespace(wizard)
239+
{
240+
var eventNamespace = wizard.data("eventNamespace");
241+
242+
if (eventNamespace == null)
243+
{
244+
eventNamespace = "." + getUniqueId(wizard);
245+
wizard.data("eventNamespace", eventNamespace);
246+
}
247+
248+
return eventNamespace;
249+
}
250+
184251
function getStepAnchor(wizard, index)
185252
{
186253
var uniqueId = getUniqueId(wizard);
@@ -791,17 +858,19 @@ function refreshSteps(wizard, options, state, index)
791858

792859
function registerEvents(wizard, options)
793860
{
794-
wizard.bind("finishing.steps", options.onFinishing);
795-
wizard.bind("finished.steps", options.onFinished);
796-
wizard.bind("stepChanging.steps", options.onStepChanging);
797-
wizard.bind("stepChanged.steps", options.onStepChanged);
861+
var eventNamespace = getEventNamespace(wizard);
862+
863+
wizard.bind("finishing" + eventNamespace, options.onFinishing);
864+
wizard.bind("finished" + eventNamespace, options.onFinished);
865+
wizard.bind("stepChanging" + eventNamespace, options.onStepChanging);
866+
wizard.bind("stepChanged" + eventNamespace, options.onStepChanged);
798867

799868
if (options.enableKeyNavigation)
800869
{
801-
wizard.bind("keyup.steps", keyUpHandler);
870+
wizard.bind("keyup" + eventNamespace, keyUpHandler);
802871
}
803872

804-
wizard.find(".actions a").bind("click.steps", paginationClickHandler);
873+
wizard.find(".actions a").bind("click" + eventNamespace, paginationClickHandler);
805874
}
806875

807876
/**
@@ -1051,7 +1120,7 @@ function renderTitle(wizard, options, state, header, index)
10511120
}
10521121

10531122
// Register click event
1054-
stepItem.children("a").bind("click.steps", stepClickHandler);
1123+
stepItem.children("a").bind("click" + getEventNamespace(wizard), stepClickHandler);
10551124
}
10561125

10571126
/**

src/publics.js

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ $.fn.steps.add = function (step)
3838
return insertStep(this, options, state, state.stepCount, step);
3939
};
4040

41+
/**
42+
* Removes the control functionality completely and transforms the current state to the initial HTML structure.
43+
*
44+
* @method destroy
45+
**/
46+
$.fn.steps.destroy = function ()
47+
{
48+
var options = getOptions(this);
49+
50+
return destroy(this, options);
51+
};
52+
4153
/**
4254
* Triggers the onFinishing and onFinished event.
4355
*

steps.jquery.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"tabs",
1515
"steps"
1616
],
17-
"version": "1.0.1",
17+
"version": "1.0.2",
1818
"author": {
1919
"name": "Rafael Staib",
2020
"email": "me@rafaelstaib.com",

0 commit comments

Comments
 (0)