jenkins-bot has submitted this change and it was merged.
Change subject: Filter out elements that are not :visible when attaching.
......................................................................
Filter out elements that are not :visible when attaching.
Thus, if the only candidate(s) are non-:visible elements, it will
fallback to the center, as with entirely missing elements.
Non-:visible elements are not handled by jQuery offset, so
_getAttachCss returns meaningless values (e.g. (0, 0)) for them.
To do this consistently, this introduces a small private helper method,
guiders._getAttachTarget.
Change-Id: Ic862e14022ae6e1b21b1241c36a619b398a8eccf
---
M modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
1 file changed, 27 insertions(+), 11 deletions(-)
Approvals:
Spage: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
b/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
index 369f1b2..393f626 100644
--- a/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
+++ b/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
@@ -460,6 +460,22 @@
};
/**
+ * Gets element to attach to, wrapped by jQuery. Filters out elements
that are not
+ * :visible, such as (such as those with display: none).
+ *
+ * @private
+ *
+ * @param {Object} guider guider being attached
+ *
+ * @return {jQuery|null} jQuery node for element, or null for no match
+ */
+ guiders._getAttachTarget = function(guider) {
+ var $node = $(guider.attachTo).filter( ':visible:first' );
+
+ return $node.length > 0 ? $node : null;
+ };
+
+ /**
* Attaches a guider
*
* @param {Object} myGuider guider to attach
@@ -467,23 +483,23 @@
* or undefined for invalid input.
*/
guiders._attach = function(myGuider) {
- var position, attachTo, css, rightOfGuider, flipVertically,
+ var position, $attachTarget, css, rightOfGuider, flipVertically,
flipHorizontally;
if (typeof myGuider !== 'object') {
return;
}
+ $attachTarget = guiders._getAttachTarget(myGuider);
+
// We keep a local position, separate from the originally
requested one.
// We alter this locally for auto-flip and missing elements.
//
// However, the DOM or window size may change later, and on
each attach we want to start
// with the originally requested position as the baseline.
+ position = $attachTarget !== null ? myGuider.position : 0;
- attachTo = $(myGuider.attachTo);
- position = attachTo.length > 0 ? myGuider.position : 0;
-
- css = guiders._getAttachCss(attachTo, myGuider, position);
+ css = guiders._getAttachCss($attachTarget, myGuider, position);
if (myGuider.flipToKeepOnScreen) {
rightOfGuider = css.left + myGuider.width;
@@ -494,7 +510,7 @@
vertical: flipVertically,
horizontal: flipHorizontally
});
- css = guiders._getAttachCss(attachTo, myGuider,
position);
+ css = guiders._getAttachCss($attachTarget,
myGuider, position);
}
}
@@ -517,8 +533,8 @@
}
var myGuider = guiders._guiderInits[id];
// this can happen when resume() hits a snag somewhere
- if (myGuider.attachTo && guiders.failStep &&
($(myGuider.attachTo).length === 0)) {
- throw 'Guider attachment not found with id ' +
myGuider.attachTo;
+ if (myGuider.attachTo && guiders.failStep &&
guiders._getAttachTarget(myGuider) !== null) {
+ throw 'Guider attachment not found with
selector ' + myGuider.attachTo;
}
guiders.createGuider(myGuider);
delete guiders._guiderInits[id]; //prevents recursion
@@ -988,9 +1004,9 @@
nextGuiderId = myGuider.next || null;
if (nextGuiderId !== null && nextGuiderId !== '') {
if ( ( nextGuiderData =
guiders._guiderInits[nextGuiderId] ) ) {
- //don't attach if it doesn't exist in DOM
- testInDom = $(nextGuiderData.attachTo);
- if ( testInDom.length > 0 ) {
+ // Only attach if it exists and is :visible
+ testInDom =
guiders._getAttachTarget(nextGuiderData);
+ if ( testInDom !== null ) {
guiders.createGuider(nextGuiderData);
nextGuiderData = undefined;
}
--
To view, visit https://gerrit.wikimedia.org/r/77486
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic862e14022ae6e1b21b1241c36a619b398a8eccf
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/GuidedTour
Gerrit-Branch: master
Gerrit-Owner: Mattflaschen <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Spage <[email protected]>
Gerrit-Reviewer: Swalling <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits