AndyRussG has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/79555


Change subject: Added experimental uncacheable prop to guiders
......................................................................

Added experimental uncacheable prop to guiders

Added an experimental uncacheable property to guiders. If set to
true, a guider's DOM element is deleted from the DOM and
recreated every time it is shown. This allows programmatic modification
of its characteristics each time it's shown. This change has not been
thoroughly tested and should be considered experimental. **In theory,
existing functionality is unaffected, but this should be reviewed
more carefully before this change is merged to production.**

Change-Id: I4e182ba01ba773a36aa79e91c70c2bd8947c63be
---
M modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
1 file changed, 30 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GuidedTour 
refs/changes/55/79555/1

diff --git a/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js 
b/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
index 369f1b2..398284a 100644
--- a/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
+++ b/modules/mediawiki.libs.guiders/mediawiki.libs.guiders.js
@@ -104,6 +104,10 @@
                title: 'Sample title goes here',
                width: 400,
                xButton: false, // this places a closer "x" button in the top 
right of the guider
+
+               // Guiders should be uncacheable only as a special case. Note: 
potential
+               // problem because of when defaults are mixed in, see comments 
in _guiderById.
+               uncacheable: false,
                _advanceHandler: null //action to do on advance. Set by 
bindAdvanceHandler closure done on show()
        };
 
@@ -511,11 +515,23 @@
         * @return {Object} guider object
         */
        guiders._guiderById = function(id) {
-               if (typeof guiders._guiders[id] === 'undefined') {
-                       if (typeof guiders._guiderInits[id] === 'undefined') {
+               var myGuider = guiders._guiderInits[id];
+
+               // TODO Potential problem here because defaults haven't been 
mixed in
+               // yet. This works because uncacheable may be undefined, which
+               // evaluates to false. If we were to define a cacheable 
property instead
+               // this would be a problem. Consider moving where defaults are 
mixed
+               // in?
+               var uncacheable = false;
+               if (myGuider) {
+                       uncacheable = myGuider.uncacheable;
+               }
+
+               if (typeof guiders._guiders[id] === 'undefined' || uncacheable) 
{
+                       if (myGuider === 'undefined') {
                                throw 'Cannot find guider with id ' + id;
                        }
-                       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;
@@ -797,6 +813,17 @@
                myGuider = $.extend({}, guiders._defaultSettings, 
passedSettings);
                myGuider.id = myGuider.id || String(Math.floor(Math.random() * 
1000));
 
+               // If this guider is uncacheable, then it's re-created every 
time
+               // it's shown. In that case, make sure any elements previously
+               // created are deleted.
+               if (myGuider.uncacheable) {
+                       $("#" + myGuider.id).remove();
+
+                       if (myGuider.elem) {
+                               delete myGuider.elem;
+                       }
+               }
+
                guiderElement = $(guiders._htmlSkeleton);
                myGuider.elem = guiderElement;
                if (typeof myGuider.classString !== 'undefined' && 
myGuider.classString !== null) {

-- 
To view, visit https://gerrit.wikimedia.org/r/79555
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4e182ba01ba773a36aa79e91c70c2bd8947c63be
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GuidedTour
Gerrit-Branch: master
Gerrit-Owner: AndyRussG <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to