Skip to content

Commit 5d90d0c

Browse files
committed
added onafterchange method, and call it just before the end of _showElement method
difference with onchange is that onchange is executed first time upon entering _showElement method. This will fail if we want to, for example, set focus to the current input element being shown, because the element is modified in _showElement method. onafterchange is executed just before the end of _showElement method, so any changes to the current element will persist. I found this especially useful when trying to set focus to an input element which is currently being intro-ed using jquery's .focus().
1 parent 4f20edc commit 5d90d0c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

intro.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@
635635
window.scrollBy(0, bottom + 100); // 70px + 30px padding from edge to look nice
636636
}
637637
}
638+
639+
if (typeof (this._introAfterChangeCallback) !== 'undefined') {
640+
this._introAfterChangeCallback.call(this, targetElement.element);
641+
}
638642
}
639643

640644
/**
@@ -867,6 +871,14 @@
867871
}
868872
return this;
869873
},
874+
onafterchange: function(providedCallback) {
875+
if (typeof (providedCallback) === 'function') {
876+
this._introAfterChangeCallback = providedCallback;
877+
} else {
878+
throw new Error('Provided callback for onafterchange was not a function');
879+
}
880+
return this;
881+
},
870882
oncomplete: function(providedCallback) {
871883
if (typeof (providedCallback) === 'function') {
872884
this._introCompleteCallback = providedCallback;

0 commit comments

Comments
 (0)