2016-08-11 22:05:23 +08:00
|
|
|
/*
|
2016-08-26 04:26:53 +08:00
|
|
|
* Converts JSON data received from the server to flat array of values.
|
2016-08-11 22:05:23 +08:00
|
|
|
*/
|
2016-08-05 23:00:29 +08:00
|
|
|
function jsonToValuesArray(jsonData) {
|
2016-08-31 23:52:45 +08:00
|
|
|
var errMsgs = [];
|
2016-08-05 23:00:29 +08:00
|
|
|
for (var key in jsonData) {
|
|
|
|
var values = jsonData[key];
|
2016-08-31 23:52:45 +08:00
|
|
|
$.each(values, function (idx, val) {
|
|
|
|
errMsgs.push(val);
|
|
|
|
});
|
2016-08-05 23:00:29 +08:00
|
|
|
}
|
|
|
|
return errMsgs;
|
|
|
|
}
|
2016-08-26 04:26:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Calls callback function on AJAX success (because built-in functions don't
|
|
|
|
* work!)
|
|
|
|
*/
|
|
|
|
$.fn.onAjaxComplete = function (cb) {
|
2016-08-31 23:52:45 +08:00
|
|
|
$(this)
|
|
|
|
.on('ajax:success', function () {
|
|
|
|
cb();
|
|
|
|
})
|
|
|
|
.on('ajax:error', function () {
|
|
|
|
cb();
|
|
|
|
});
|
2016-08-26 04:26:53 +08:00
|
|
|
}
|
2016-11-14 21:27:35 +08:00
|
|
|
|
2016-11-17 23:53:55 +08:00
|
|
|
// Number of all tutorial steps
|
|
|
|
var TUTORIAL_STEPS_CNT = 26;
|
2016-11-14 21:27:35 +08:00
|
|
|
|
|
|
|
/**
|
2016-11-16 03:12:40 +08:00
|
|
|
* Initializes tutorial steps for the current page.
|
2016-11-17 01:21:29 +08:00
|
|
|
* NOTE: You can specify steps manually in JS with steps parameter (preferred
|
|
|
|
* way), or hardcode them in HTML
|
2016-11-16 03:12:40 +08:00
|
|
|
* NOTE: If some steps edit page, then this function needs to be called several
|
2016-11-16 18:14:51 +08:00
|
|
|
* times for the same page, but for different steps. The same goes if the page
|
|
|
|
* has discontinuous tutorial steps. In such cases, use steps branching, e.g.:
|
|
|
|
* @example
|
|
|
|
* var tutorialData = Cookies.get('tutorial_data');
|
|
|
|
* if (tutorialData) {
|
|
|
|
* tutorialData = JSON.parse(tutorialData);
|
|
|
|
* var stepNum = parseInt(Cookies.get('current_tutorial_step'), 10);
|
|
|
|
*
|
|
|
|
* if (stepNum >= 6 && stepNum <= 7) {
|
|
|
|
* ...
|
|
|
|
* } else if ...
|
|
|
|
* NOTE: If an element the popup is pointing at is of lesser horizontal length
|
|
|
|
* than the popup itself, then it will not be positioned correctly if it's
|
|
|
|
* position is top or bottom, so set/change the step's position to either left
|
|
|
|
* or right (and don't use any custom styling!), e.g.:
|
|
|
|
* @example
|
|
|
|
* var steps = [
|
|
|
|
* {
|
|
|
|
* ...
|
|
|
|
* position: 'right'
|
|
|
|
* },
|
|
|
|
* {
|
|
|
|
* ...
|
|
|
|
* ];
|
2016-11-17 01:21:29 +08:00
|
|
|
* NOTE: If only one page step is needed, then make pageFirstStepN ==
|
|
|
|
* pageLastStepN (both represent the one and only step number)
|
2016-11-16 18:14:51 +08:00
|
|
|
*
|
2016-11-17 01:21:29 +08:00
|
|
|
* @param {number} pageFirstStepN Page's first step number
|
|
|
|
* @param {number} pageLastStepN Page's last step number
|
2016-11-14 21:27:35 +08:00
|
|
|
* @param {string} nextPagePath Next page absolute path
|
2016-11-16 20:22:07 +08:00
|
|
|
* @param {function} beforeCb Callback called before the tutorial starts. Mainly
|
|
|
|
* used for setting 'pointer-events: none' on the elements the page's steps
|
|
|
|
* highlight.
|
|
|
|
* @param {function} endCb Callback called after the tutorial ends. Mainly used
|
|
|
|
* for setting 'pointer-events: auto' on the elements the page's steps
|
|
|
|
* highlight.
|
2016-11-16 02:30:17 +08:00
|
|
|
* @param {object} steps Optional JSON containing introJs steps. They can be
|
|
|
|
* specified here, or hardcoded in HTML.
|
2016-11-14 21:27:35 +08:00
|
|
|
*/
|
2016-11-17 01:21:29 +08:00
|
|
|
function initPageTutorialSteps(pageFirstStepN, pageLastStepN, nextPagePath,
|
2016-11-16 03:12:40 +08:00
|
|
|
beforeCb, endCb, steps) {
|
2016-11-14 21:27:35 +08:00
|
|
|
var tutorialData = Cookies.get('tutorial_data');
|
|
|
|
if (tutorialData) {
|
|
|
|
tutorialData = JSON.parse(tutorialData);
|
|
|
|
var stepNum = parseInt(Cookies.get('current_tutorial_step'), 10);
|
|
|
|
if (isNaN(stepNum)) {
|
2016-11-17 01:21:29 +08:00
|
|
|
// Cookies data initialization
|
2016-11-14 21:27:35 +08:00
|
|
|
stepNum = 1;
|
|
|
|
Cookies.set('current_tutorial_step', stepNum);
|
2016-11-16 02:30:17 +08:00
|
|
|
tutorialData[0].backPagesPaths = [];
|
|
|
|
Cookies.set('tutorial_data', tutorialData);
|
2016-11-14 21:27:35 +08:00
|
|
|
}
|
2016-11-16 02:30:17 +08:00
|
|
|
var thisPagePath = window.location.pathname;
|
2016-11-14 21:27:35 +08:00
|
|
|
beforeCb();
|
|
|
|
|
|
|
|
// Initialize tutorial for the current page's steps
|
2016-11-17 01:21:29 +08:00
|
|
|
var doneLabel = (pageLastStepN === TUTORIAL_STEPS_CNT) ?
|
2016-11-14 21:27:35 +08:00
|
|
|
'Start using sciNote' : 'End tutorial';
|
2016-11-16 02:30:17 +08:00
|
|
|
if (_.isUndefined(steps)) {
|
|
|
|
introJs()
|
|
|
|
.setOptions({
|
|
|
|
overlayOpacity: '0.2',
|
|
|
|
prevLabel: 'Back',
|
|
|
|
nextLabel: 'Next',
|
|
|
|
skipLabel: 'End tutorial',
|
|
|
|
doneLabel: doneLabel,
|
|
|
|
showBullets: false,
|
|
|
|
showStepNumbers: false,
|
|
|
|
exitOnOverlayClick: false,
|
|
|
|
exitOnEsc: false,
|
|
|
|
disableInteraction: true,
|
2016-11-22 21:14:42 +08:00
|
|
|
keyboardNavigation: false,
|
2016-11-16 02:30:17 +08:00
|
|
|
tooltipClass: 'custom next-page-link'
|
|
|
|
})
|
2016-11-17 01:21:29 +08:00
|
|
|
.goToStep(stepNum - (pageFirstStepN - 1))
|
2016-11-19 01:14:45 +08:00
|
|
|
.onexit(function() {
|
|
|
|
Cookies.remove('tutorial_data');
|
|
|
|
Cookies.remove('current_tutorial_step');
|
2016-11-23 17:48:43 +08:00
|
|
|
location.reload();
|
2016-11-19 01:14:45 +08:00
|
|
|
})
|
|
|
|
.oncomplete(function() {
|
|
|
|
Cookies.remove('tutorial_data');
|
|
|
|
Cookies.remove('current_tutorial_step');
|
2016-11-23 17:48:43 +08:00
|
|
|
location.reload();
|
2016-11-19 01:14:45 +08:00
|
|
|
})
|
2016-11-16 02:30:17 +08:00
|
|
|
.start();
|
|
|
|
} else {
|
2016-11-17 01:21:29 +08:00
|
|
|
if (pageFirstStepN === pageLastStepN) {
|
2016-11-16 21:31:50 +08:00
|
|
|
// Only one page step, so add another fake one, so the back and next
|
|
|
|
// buttons are added to the popup
|
|
|
|
steps.push({});
|
|
|
|
}
|
2016-11-16 02:30:17 +08:00
|
|
|
introJs()
|
|
|
|
.setOptions({
|
|
|
|
overlayOpacity: '0.2',
|
|
|
|
prevLabel: 'Back',
|
|
|
|
nextLabel: 'Next',
|
|
|
|
skipLabel: 'End tutorial',
|
|
|
|
doneLabel: doneLabel,
|
|
|
|
showBullets: false,
|
|
|
|
showStepNumbers: false,
|
|
|
|
exitOnOverlayClick: false,
|
|
|
|
exitOnEsc: false,
|
|
|
|
disableInteraction: true,
|
2016-11-22 21:14:42 +08:00
|
|
|
keyboardNavigation: false,
|
2016-11-16 02:30:17 +08:00
|
|
|
tooltipClass: 'custom next-page-link',
|
|
|
|
steps: steps
|
|
|
|
})
|
2016-11-18 23:49:26 +08:00
|
|
|
.onexit(function() {
|
|
|
|
location.reload();
|
|
|
|
})
|
|
|
|
.oncomplete(function() {
|
|
|
|
location.reload();
|
|
|
|
})
|
2016-11-17 01:21:29 +08:00
|
|
|
.goToStep(stepNum - (pageFirstStepN - 1))
|
2016-11-19 01:14:45 +08:00
|
|
|
.onexit(function() {
|
|
|
|
Cookies.remove('tutorial_data');
|
|
|
|
Cookies.remove('current_tutorial_step');
|
|
|
|
})
|
|
|
|
.oncomplete(function() {
|
|
|
|
Cookies.remove('tutorial_data');
|
|
|
|
Cookies.remove('current_tutorial_step');
|
|
|
|
})
|
2016-11-16 02:30:17 +08:00
|
|
|
.start();
|
|
|
|
}
|
2016-11-14 21:27:35 +08:00
|
|
|
|
|
|
|
// Page navigation when coming to this page from previous/next page
|
|
|
|
$(function() {
|
2016-11-17 01:21:29 +08:00
|
|
|
if (stepNum === pageFirstStepN && stepNum > 1) {
|
2016-11-14 21:27:35 +08:00
|
|
|
$('.introjs-prevbutton').removeClass('introjs-disabled');
|
2016-11-17 01:21:29 +08:00
|
|
|
} else if (stepNum === pageLastStepN && stepNum < TUTORIAL_STEPS_CNT) {
|
2016-11-14 21:27:35 +08:00
|
|
|
$('.introjs-nextbutton').removeClass('introjs-disabled');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Page navigation when already on this page
|
|
|
|
|
|
|
|
$('.introjs-skipbutton').click(function() {
|
|
|
|
Cookies.remove('tutorial_data');
|
|
|
|
Cookies.remove('current_tutorial_step');
|
|
|
|
|
2016-11-16 03:12:40 +08:00
|
|
|
endCb();
|
2016-11-14 21:27:35 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
$('.introjs-prevbutton').click(function() {
|
|
|
|
if (stepNum > 1) {
|
|
|
|
Cookies.set('current_tutorial_step', --stepNum);
|
|
|
|
|
2016-11-17 01:21:29 +08:00
|
|
|
if (stepNum === pageFirstStepN && stepNum > 1) {
|
2016-11-14 21:27:35 +08:00
|
|
|
$('.introjs-prevbutton').removeClass('introjs-disabled');
|
2016-11-17 01:21:29 +08:00
|
|
|
} else if (stepNum < pageFirstStepN) {
|
2016-11-16 02:30:17 +08:00
|
|
|
// Go to previous page;
|
|
|
|
|
|
|
|
var prevPagePath = tutorialData[0].backPagesPaths.pop();
|
|
|
|
Cookies.set('tutorial_data', tutorialData);
|
|
|
|
$('.introjs-prevbutton').attr('href', prevPagePath);
|
2016-11-16 20:22:07 +08:00
|
|
|
introJs().exit();
|
2016-11-16 03:12:40 +08:00
|
|
|
endCb();
|
2016-11-14 21:27:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('.introjs-nextbutton').click(function() {
|
|
|
|
if (stepNum < TUTORIAL_STEPS_CNT) {
|
|
|
|
Cookies.set('current_tutorial_step', ++stepNum);
|
|
|
|
|
2016-11-17 01:21:29 +08:00
|
|
|
if (stepNum === pageLastStepN && stepNum < TUTORIAL_STEPS_CNT) {
|
2016-11-14 21:27:35 +08:00
|
|
|
$('.introjs-nextbutton').removeClass('introjs-disabled');
|
2016-11-17 01:21:29 +08:00
|
|
|
} else if (stepNum > pageLastStepN) {
|
2016-11-16 02:30:17 +08:00
|
|
|
// Go to next page
|
2016-11-14 21:27:35 +08:00
|
|
|
|
2016-11-16 02:30:17 +08:00
|
|
|
tutorialData[0].backPagesPaths.push(thisPagePath);
|
2016-11-14 21:27:35 +08:00
|
|
|
Cookies.set('tutorial_data', tutorialData);
|
|
|
|
$('.introjs-nextbutton').attr('href', nextPagePath);
|
2016-11-16 20:22:07 +08:00
|
|
|
introJs().exit();
|
2016-11-16 03:12:40 +08:00
|
|
|
endCb();
|
2016-11-14 21:27:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|