mirror of
https://github.com/moodle/moodle.git
synced 2025-04-12 20:12:15 +02:00
MDL-61234 tool_usertours: Wrap library calls in pendingjs
This commit is contained in:
parent
f68150ad05
commit
64c9b4046c
@ -1 +1 @@
|
||||
define(["core/ajax","tool_usertours/tour","jquery","core/templates","core/str","core/log","core/notification"],function(a,b,c,d,e,f,g){var h={tourId:null,currentTour:null,context:null,init:function(a,b,d){h.tourId=a,h.context=d,"undefined"==typeof b&&(b=!0),b&&h.fetchTour(a),h.addResetLink(),c("body").on("click",'[data-action="tool_usertours/resetpagetour"]',function(a){a.preventDefault(),h.resetTourState(h.tourId)})},fetchTour:function(b){c.when(a.call([{methodname:"tool_usertours_fetch_and_start_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0],d.render("tool_usertours/tourstep",{})).then(function(a,c){h.startBootstrapTour(b,c[0],a.tourconfig)}).fail(g.exception)},addResetLink:function(){var a;a=c(c(".tool_usertours-resettourcontainer").length?".tool_usertours-resettourcontainer":c(".logininfo").length?".logininfo":c("footer").length?"footer":"body"),d.render("tool_usertours/resettour",{}).done(function(b,c){d.appendNodeContents(a,b,c)})},startBootstrapTour:function(a,c,d){h.currentTour&&(d.onEnd=null,h.currentTour.endTour(),delete h.currentTour),d.eventHandlers={afterEnd:[h.markTourComplete],afterRender:[h.markStepShown]},d.tourName=d.name,delete d.name,d.template=c,d.steps=d.steps.map(function(a){return"undefined"!=typeof a.element&&(a.target=a.element,delete a.element),"undefined"!=typeof a.reflex&&(a.moveOnClick=!!a.reflex,delete a.reflex),"undefined"!=typeof a.content&&(a.body=a.content,delete a.content),a}),h.currentTour=new b(d),h.currentTour.startTour()},markStepShown:function(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_step_shown",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},markTourComplete:function(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_complete_tour",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},resetTourState:function(b){c.when(a.call([{methodname:"tool_usertours_reset_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0]).then(function(a){a.startTour&&h.fetchTour(a.startTour)}).fail(g.exception)}};return{init:h.init,resetTourState:h.resetTourState}});
|
||||
define(["core/ajax","tool_usertours/tour","jquery","core/templates","core/str","core/log","core/notification"],function(a,b,c,d,e,f,g){var h={tourId:null,currentTour:null,context:null,init:function(a,b,d){h.tourId=a,h.context=d,"undefined"==typeof b&&(b=!0),b&&h.fetchTour(a),h.addResetLink(),c("body").on("click",'[data-action="tool_usertours/resetpagetour"]',function(a){a.preventDefault(),h.resetTourState(h.tourId)})},fetchTour:function(b){M.util.js_pending("admin_usertour_fetchTour"+b),c.when(a.call([{methodname:"tool_usertours_fetch_and_start_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0],d.render("tool_usertours/tourstep",{})).then(function(a,c){return h.startBootstrapTour(b,c[0],a.tourconfig)}).always(function(){M.util.js_complete("admin_usertour_fetchTour"+b)}).fail(g.exception)},addResetLink:function(){var a;M.util.js_pending("admin_usertour_addResetLink"),a=c(c(".tool_usertours-resettourcontainer").length?".tool_usertours-resettourcontainer":c(".logininfo").length?".logininfo":c("footer").length?"footer":"body"),d.render("tool_usertours/resettour",{}).then(function(b,c){d.appendNodeContents(a,b,c)}).always(function(){M.util.js_complete("admin_usertour_addResetLink")}).fail()},startBootstrapTour:function(a,c,d){return h.currentTour&&(d.onEnd=null,h.currentTour.endTour(),delete h.currentTour),d.eventHandlers={afterEnd:[h.markTourComplete],afterRender:[h.markStepShown]},d.tourName=d.name,delete d.name,d.template=c,d.steps=d.steps.map(function(a){return"undefined"!=typeof a.element&&(a.target=a.element,delete a.element),"undefined"!=typeof a.reflex&&(a.moveOnClick=!!a.reflex,delete a.reflex),"undefined"!=typeof a.content&&(a.body=a.content,delete a.content),a}),h.currentTour=new b(d),h.currentTour.startTour()},markStepShown:function(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_step_shown",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},markTourComplete:function(){var b=this.getStepConfig(this.getCurrentStepNumber());c.when(a.call([{methodname:"tool_usertours_complete_tour",args:{tourid:h.tourId,context:h.context,pageurl:window.location.href,stepid:b.stepid,stepindex:this.getCurrentStepNumber()}}])[0]).fail(f.error)},resetTourState:function(b){c.when(a.call([{methodname:"tool_usertours_reset_tour",args:{tourid:b,context:h.context,pageurl:window.location.href}}])[0]).then(function(a){a.startTour&&h.fetchTour(a.startTour)}).fail(g.exception)}};return{init:h.init,resetTourState:h.resetTourState}});
|
@ -54,6 +54,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
* @param {Number} tourId The ID of the tour to start.
|
||||
*/
|
||||
fetchTour: function(tourId) {
|
||||
M.util.js_pending('admin_usertour_fetchTour' + tourId);
|
||||
$.when(
|
||||
ajax.call([
|
||||
{
|
||||
@ -66,10 +67,16 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
}
|
||||
])[0],
|
||||
templates.render('tool_usertours/tourstep', {})
|
||||
).then(function(response, template) {
|
||||
usertours.startBootstrapTour(tourId, template[0], response.tourconfig);
|
||||
)
|
||||
.then(function(response, template) {
|
||||
return usertours.startBootstrapTour(tourId, template[0], response.tourconfig);
|
||||
})
|
||||
.always(function() {
|
||||
M.util.js_complete('admin_usertour_fetchTour' + tourId);
|
||||
|
||||
return;
|
||||
}).fail(notification.exception);
|
||||
})
|
||||
.fail(notification.exception);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -79,6 +86,8 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
*/
|
||||
addResetLink: function() {
|
||||
var ele;
|
||||
M.util.js_pending('admin_usertour_addResetLink');
|
||||
|
||||
// Append the link to the most suitable place on the page
|
||||
// with fallback to legacy selectors and finally the body
|
||||
// if there is no better place.
|
||||
@ -92,9 +101,17 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
ele = $('body');
|
||||
}
|
||||
templates.render('tool_usertours/resettour', {})
|
||||
.done(function(html, js) {
|
||||
templates.appendNodeContents(ele, html, js);
|
||||
});
|
||||
.then(function(html, js) {
|
||||
templates.appendNodeContents(ele, html, js);
|
||||
|
||||
return;
|
||||
})
|
||||
.always(function() {
|
||||
M.util.js_complete('admin_usertour_addResetLink');
|
||||
|
||||
return;
|
||||
})
|
||||
.fail();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -104,6 +121,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
* @param {Number} tourId The ID of the tour to start.
|
||||
* @param {String} template The template to use.
|
||||
* @param {Object} tourConfig The tour configuration.
|
||||
* @return {Object}
|
||||
*/
|
||||
startBootstrapTour: function(tourId, template, tourConfig) {
|
||||
if (usertours.currentTour) {
|
||||
@ -147,7 +165,7 @@ function(ajax, BootstrapTour, $, templates, str, log, notification) {
|
||||
});
|
||||
|
||||
usertours.currentTour = new BootstrapTour(tourConfig);
|
||||
usertours.currentTour.startTour();
|
||||
return usertours.currentTour.startTour();
|
||||
},
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user