diff --git a/CHANGELOG.md b/CHANGELOG.md index b9b50662..95c5dee5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Change Log +### v0.3.0 (2017/06/02) + * [#337](https://github.com/linkedin/hopscotch/pull/337) Refactor build to generate UMD and AMD artifacts + ### v0.2.8 (2017/05/04) * [#323](https://github.com/linkedin/hopscotch/pull/323) Fix the rest of the deprecated gradient warnings diff --git a/archives/hopscotch-0.3.0.tar.gz b/archives/hopscotch-0.3.0.tar.gz new file mode 100644 index 00000000..920ae257 Binary files /dev/null and b/archives/hopscotch-0.3.0.tar.gz differ diff --git a/archives/hopscotch-0.3.0.zip b/archives/hopscotch-0.3.0.zip new file mode 100644 index 00000000..c496d8e1 Binary files /dev/null and b/archives/hopscotch-0.3.0.zip differ diff --git a/dist/css/hopscotch.css b/dist/css/hopscotch.css index 6a806b06..be644d8e 100644 --- a/dist/css/hopscotch.css +++ b/dist/css/hopscotch.css @@ -1,4 +1,4 @@ -/**! hopscotch - v0.2.8 +/**! hopscotch - v0.3.0 * * Copyright 2017 LinkedIn Corp. All rights reserved. * diff --git a/dist/css/hopscotch.min.css b/dist/css/hopscotch.min.css index 9f014154..696f8ec6 100644 --- a/dist/css/hopscotch.min.css +++ b/dist/css/hopscotch.min.css @@ -1,4 +1,4 @@ -/**! hopscotch - v0.2.8 +/**! hopscotch - v0.3.0 * * Copyright 2017 LinkedIn Corp. All rights reserved. * diff --git a/dist/js/hopscotch.js b/dist/js/hopscotch.js index e994257b..e7bc43ed 100644 --- a/dist/js/hopscotch.js +++ b/dist/js/hopscotch.js @@ -1,4 +1,4 @@ -/**! hopscotch - v0.2.8 +/**! hopscotch - v0.3.0 * * Copyright 2017 LinkedIn Corp. All rights reserved. * @@ -14,58 +14,51 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -(function(context, factory) { - 'use strict'; - - if (typeof define === 'function' && define.amd) { - // AMD. Register as an anonymous module. - define([], factory); - } else if (typeof exports === 'object') { - // Node/CommonJS - module.exports = factory(); - } else { - var namespace = 'hopscotch'; - // Browser globals - if (context[namespace]) { - // Hopscotch already exists. - return; - } - context[namespace] = factory(); - } -}(this, (function() { - var Hopscotch, - HopscotchBubble, - HopscotchCalloutManager, - HopscotchI18N, - customI18N, - customRenderer, - customEscape, - templateToUse = 'bubble_default', - Sizzle = window.Sizzle || null, - utils, - callbacks, - helpers, - winLoadHandler, - defaultOpts, - winHopscotch, - undefinedStr = 'undefined', - waitingToStart = false, // is a tour waiting for the document to finish - // loading so that it can start? - hasJquery = (typeof jQuery !== undefinedStr), - hasSessionStorage = false, - isStorageWritable = false, - document = window.document, - validIdRegEx = /^[a-zA-Z]+[a-zA-Z0-9_-]*$/, - rtlMatches = { - left: 'right', - right: 'left' - }; +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global.hopscotch = factory()); +}(this, (function () { 'use strict'; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }; + + /* global document */ + + var Hopscotch; + var HopscotchBubble; + var HopscotchCalloutManager; + var HopscotchI18N; + var customI18N; + var customRenderer; + var customEscape; + var templateToUse = 'bubble_default'; + var Sizzle = window.Sizzle || null; + var utils; + var callbacks; + var helpers; + var winLoadHandler; + var defaultOpts; + var winHopscotch; + var undefinedStr = 'undefined'; + var waitingToStart = false; + var hasJquery = (typeof jQuery === 'undefined' ? 'undefined' : _typeof(jQuery)) !== undefinedStr; + var hasSessionStorage = false; + var isStorageWritable = false; + var validIdRegEx = /^[a-zA-Z]+[a-zA-Z0-9_-]*$/; + var rtlMatches = { + left: 'right', + right: 'left' + }; // If cookies are disabled, accessing sessionStorage can throw an error. // sessionStorage could also throw an error in Safari on write (even though it exists). // So, we'll try writing to sessionStorage to verify it's available. try { - if(typeof window.sessionStorage !== undefinedStr){ + if (_typeof(window.sessionStorage) !== undefinedStr) { hasSessionStorage = true; sessionStorage.setItem('hopscotch.test.storage', 'ok'); sessionStorage.removeItem('hopscotch.test.storage'); @@ -73,23 +66,23 @@ } } catch (err) {} - defaultOpts = { - smoothScroll: true, - scrollDuration: 1000, + defaultOpts = { + smoothScroll: true, + scrollDuration: 1000, scrollTopMargin: 200, showCloseButton: true, - showPrevButton: false, - showNextButton: true, - bubbleWidth: 280, - bubblePadding: 15, - arrowWidth: 20, + showPrevButton: false, + showNextButton: true, + bubbleWidth: 280, + bubblePadding: 15, + arrowWidth: 20, skipIfNoElement: true, - isRtl: false, - cookieName: 'hopscotch.tour.state' + isRtl: false, + cookieName: 'hopscotch.tour.state' }; if (!Array.isArray) { - Array.isArray = function(obj) { + Array.isArray = function (obj) { return Object.prototype.toString.call(obj) === '[object Array]'; }; } @@ -99,7 +92,7 @@ * * @private */ - winLoadHandler = function() { + winLoadHandler = function winLoadHandler() { if (waitingToStart) { winHopscotch.startTour(); } @@ -123,17 +116,12 @@ * * @private */ - addClass: function(domEl, classToAdd) { - var domClasses, - classToAddArr, - setClass, - i, - len; + addClass: function addClass(domEl, classToAdd) { + var domClasses, classToAddArr, setClass, i, len; if (!domEl.className) { domEl.className = classToAdd; - } - else { + } else { classToAddArr = classToAdd.split(/\s+/); domClasses = ' ' + domEl.className + ' '; for (i = 0, len = classToAddArr.length; i < len; ++i) { @@ -141,7 +129,7 @@ domClasses += classToAddArr[i] + ' '; } } - domEl.className = domClasses.replace(/^\s+|\s+$/g,''); + domEl.className = domClasses.replace(/^\s+|\s+$/g, ''); } }, @@ -152,19 +140,15 @@ * * @private */ - removeClass: function(domEl, classToRemove) { - var domClasses, - classToRemoveArr, - currClass, - i, - len; + removeClass: function removeClass(domEl, classToRemove) { + var domClasses, classToRemoveArr, currClass, i, len; classToRemoveArr = classToRemove.split(/\s+/); domClasses = ' ' + domEl.className + ' '; for (i = 0, len = classToRemoveArr.length; i < len; ++i) { domClasses = domClasses.replace(' ' + classToRemoveArr[i] + ' ', ' '); } - domEl.className = domClasses.replace(/^\s+|\s+$/g,''); + domEl.className = domClasses.replace(/^\s+|\s+$/g, ''); }, /** @@ -172,21 +156,27 @@ * ======== * Determine if a given DOM element has a class. */ - hasClass: function(domEl, classToCheck){ + hasClass: function hasClass(domEl, classToCheck) { var classes; - if(!domEl.className){ return false; } + if (!domEl.className) { + return false; + } classes = ' ' + domEl.className + ' '; - return (classes.indexOf(' ' + classToCheck + ' ') !== -1); + return classes.indexOf(' ' + classToCheck + ' ') !== -1; }, /** * @private */ - getPixelValue: function(val) { - var valType = typeof val; - if (valType === 'number') { return val; } - if (valType === 'string') { return parseInt(val, 10); } + getPixelValue: function getPixelValue(val) { + var valType = typeof val === 'undefined' ? 'undefined' : _typeof(val); + if (valType === 'number') { + return val; + } + if (valType === 'string') { + return parseInt(val, 10); + } return 0; }, @@ -195,8 +185,8 @@ * * @private */ - valOrDefault: function(val, valDefault) { - return typeof val !== undefinedStr ? val : valDefault; + valOrDefault: function valOrDefault(val, valDefault) { + return (typeof val === 'undefined' ? 'undefined' : _typeof(val)) !== undefinedStr ? val : valDefault; }, /** @@ -204,7 +194,7 @@ * Example input: ["my_fn", "arg1", 2, "arg3"] * @private */ - invokeCallbackArrayHelper: function(arr) { + invokeCallbackArrayHelper: function invokeCallbackArrayHelper(arr) { // Logic for a single callback var fn; if (Array.isArray(arr)) { @@ -223,15 +213,15 @@ * [["my_fn_1", "arg1", "arg2"], function() { ... }] * @private */ - invokeCallbackArray: function(arr) { + invokeCallbackArray: function invokeCallbackArray(arr) { var i, len; if (Array.isArray(arr)) { if (typeof arr[0] === 'string') { // Assume there are no nested arrays. This is the one and only callback. return utils.invokeCallbackArrayHelper(arr); - } - else { // assume an array + } else { + // assume an array for (i = 0, len = arr.length; i < len; ++i) { utils.invokeCallback(arr[i]); } @@ -244,14 +234,15 @@ * or an array that references a registered helper function. * @private */ - invokeCallback: function(cb) { + invokeCallback: function invokeCallback(cb) { if (typeof cb === 'function') { return cb(); } - if (typeof cb === 'string' && helpers[cb]) { // name of a helper + if (typeof cb === 'string' && helpers[cb]) { + // name of a helper return helpers[cb](); - } - else { // assuming array + } else { + // assuming array return utils.invokeCallbackArray(cb); } }, @@ -262,7 +253,7 @@ * * @private */ - invokeEventCallbacks: function(evtType, stepCb) { + invokeEventCallbacks: function invokeEventCallbacks(evtType, stepCb) { var cbArr = callbacks[evtType], callback, fn, @@ -273,7 +264,7 @@ return this.invokeCallback(stepCb); } - for (i=0, len=cbArr.length; i 0)), + buttons: { + showPrev: utils.valOrDefault(step.showPrevButton, this.opt.showPrevButton) && this._getStepNum(idx) > 0, showNext: utils.valOrDefault(step.showNextButton, this.opt.showNextButton), - showCTA: utils.valOrDefault((step.showCTAButton && step.ctaLabel), false), + showCTA: utils.valOrDefault(step.showCTAButton && step.ctaLabel, false), ctaLabel: step.ctaLabel, showClose: utils.valOrDefault(this.opt.showCloseButton, true) }, - step:{ + step: { num: idx, isLast: utils.valOrDefault(isLast, false), - title: (step.title || ''), - content: (step.content || ''), + title: step.title || '', + content: step.content || '', isRtl: step.isRtl, placement: step.placement, padding: utils.valOrDefault(step.padding, this.opt.bubblePadding), width: utils.getPixelValue(step.width) || this.opt.bubbleWidth, - customData: (step.customData || {}) + customData: step.customData || {} }, - tour:{ + tour: { isTour: this.opt.isTourBubble, numSteps: totalSteps, unsafe: utils.valOrDefault(unsafe, false), - customData: (customTourData || {}) + customData: customTourData || {} } }; // Render the bubble's content. // Use tour renderer if available, then the global customRenderer if defined. - if(typeof tourSpecificRenderer === 'function'){ + if (typeof tourSpecificRenderer === 'function') { el.innerHTML = tourSpecificRenderer(opts); - } - else if(typeof tourSpecificRenderer === 'string'){ - if(!winHopscotch.templates || (typeof winHopscotch.templates[tourSpecificRenderer] !== 'function')){ + } else if (typeof tourSpecificRenderer === 'string') { + if (!winHopscotch.templates || typeof winHopscotch.templates[tourSpecificRenderer] !== 'function') { throw new Error('Bubble rendering failed - template "' + tourSpecificRenderer + '" is not a function.'); } el.innerHTML = winHopscotch.templates[tourSpecificRenderer](opts); - } - else if(customRenderer){ + } else if (customRenderer) { el.innerHTML = customRenderer(opts); - } - else{ - if(!winHopscotch.templates || (typeof winHopscotch.templates[templateToUse] !== 'function')){ + } else { + if (!winHopscotch.templates || typeof winHopscotch.templates[templateToUse] !== 'function') { throw new Error('Bubble rendering failed - template "' + templateToUse + '" is not a function.'); } el.innerHTML = winHopscotch.templates[templateToUse](opts); } // Find arrow among new child elements. - children = el.children; - numChildren = children.length; - for (i = 0; i < numChildren; i++){ + var children = el.children; + var numChildren = children.length; + var node; + for (i = 0; i < numChildren; i++) { node = children[i]; - if(utils.hasClass(node, 'hopscotch-arrow')){ + if (utils.hasClass(node, 'hopscotch-arrow')) { this.arrowEl = node; } } // Set z-index and arrow placement - el.style.zIndex = (typeof step.zindex === 'number') ? step.zindex : ''; + el.style.zIndex = typeof step.zindex === 'number' ? step.zindex : ''; this._setArrow(step.placement); // Set bubble positioning @@ -879,16 +851,16 @@ * * @private */ - _getStepNum: function(idx) { + _getStepNum: function _getStepNum(idx) { var skippedStepsCount = 0, stepIdx, skippedSteps = winHopscotch.getSkippedStepsIndexes(), i, len = skippedSteps.length; //count number of steps skipped before current step - for(i = 0; i < len; i++) { + for (i = 0; i < len; i++) { stepIdx = skippedSteps[i]; - if(stepIdx= currTour.steps.length) { step = null; - } - else { + } else { step = currTour.steps[currStepNum]; } return step; }, + /** * Used for nextOnTargetClick * * @private */ - targetClickNextFn = function() { + targetClickNextFn = function targetClickNextFn() { self.nextStep(); }, + /** * adjustWindowScroll * @@ -1416,117 +1395,126 @@ * @private * @param {Function} cb Callback to invoke after done scrolling. */ - adjustWindowScroll = function(cb) { - var bubble = getBubble(), + adjustWindowScroll = function adjustWindowScroll(cb) { + var bubble = getBubble(), - // Calculate the bubble element top and bottom position - bubbleEl = bubble.element, - bubbleTop = utils.getPixelValue(bubbleEl.style.top), - bubbleBottom = bubbleTop + utils.getPixelValue(bubbleEl.offsetHeight), - // Calculate the target element top and bottom position - targetEl = utils.getStepTarget(getCurrStep()), - targetBounds = targetEl.getBoundingClientRect(), - targetElTop = targetBounds.top + utils.getScrollTop(), + // Calculate the bubble element top and bottom position + bubbleEl = bubble.element, + bubbleTop = utils.getPixelValue(bubbleEl.style.top), + bubbleBottom = bubbleTop + utils.getPixelValue(bubbleEl.offsetHeight), + + + // Calculate the target element top and bottom position + targetEl = utils.getStepTarget(getCurrStep()), + targetBounds = targetEl.getBoundingClientRect(), + targetElTop = targetBounds.top + utils.getScrollTop(), targetElBottom = targetBounds.bottom + utils.getScrollTop(), - // The higher of the two: bubble or target - targetTop = (bubbleTop < targetElTop) ? bubbleTop : targetElTop, - // The lower of the two: bubble or target - targetBottom = (bubbleBottom > targetElBottom) ? bubbleBottom : targetElBottom, - // Calculate the current viewport top and bottom - windowTop = utils.getScrollTop(), - windowBottom = windowTop + utils.getWindowHeight(), + // The higher of the two: bubble or target + targetTop = bubbleTop < targetElTop ? bubbleTop : targetElTop, + + // The lower of the two: bubble or target + targetBottom = bubbleBottom > targetElBottom ? bubbleBottom : targetElBottom, - // This is our final target scroll value. - scrollToVal = targetTop - getOption('scrollTopMargin'), + // Calculate the current viewport top and bottom + windowTop = utils.getScrollTop(), + windowBottom = windowTop + utils.getWindowHeight(), + + + // This is our final target scroll value. + scrollToVal = targetTop - getOption('scrollTopMargin'), scrollEl, yuiAnim, yuiEase, direction, scrollIncr, scrollTimeout, - scrollTimeoutFn; + _scrollTimeoutFn; // Target and bubble are both visible in viewport if (targetTop >= windowTop && (targetTop <= windowTop + getOption('scrollTopMargin') || targetBottom <= windowBottom)) { - if (cb) { cb(); } // HopscotchBubble.show + if (cb) { + cb(); + } // HopscotchBubble.show } // Abrupt scroll to scroll target else if (!getOption('smoothScroll')) { - window.scrollTo(0, scrollToVal); + window.scrollTo(0, scrollToVal); - if (cb) { cb(); } // HopscotchBubble.show - } - - // Smooth scroll to scroll target - else { - // Use YUI if it exists - if (typeof YAHOO !== undefinedStr && - typeof YAHOO.env !== undefinedStr && - typeof YAHOO.env.ua !== undefinedStr && - typeof YAHOO.util !== undefinedStr && - typeof YAHOO.util.Scroll !== undefinedStr) { - scrollEl = YAHOO.env.ua.webkit ? document.body : document.documentElement; - yuiEase = YAHOO.util.Easing ? YAHOO.util.Easing.easeOut : undefined; - yuiAnim = new YAHOO.util.Scroll(scrollEl, { - scroll: { to: [0, scrollToVal] } - }, getOption('scrollDuration')/1000, yuiEase); - yuiAnim.onComplete.subscribe(cb); - yuiAnim.animate(); + if (cb) { + cb(); + } // HopscotchBubble.show } - // Use jQuery if it exists - else if (hasJquery) { - jQuery('body, html').animate({ scrollTop: scrollToVal }, getOption('scrollDuration'), cb); - } - - // Use my crummy setInterval scroll solution if we're using plain, vanilla Javascript. + // Smooth scroll to scroll target else { - if (scrollToVal < 0) { - scrollToVal = 0; - } - - // 48 * 10 == 480ms scroll duration - // make it slightly less than CSS transition duration because of - // setInterval overhead. - // To increase or decrease duration, change the divisor of scrollIncr. - direction = (windowTop > targetTop) ? -1 : 1; // -1 means scrolling up, 1 means down - scrollIncr = Math.abs(windowTop - scrollToVal) / (getOption('scrollDuration')/10); - scrollTimeoutFn = function() { - var scrollTop = utils.getScrollTop(), - scrollTarget = scrollTop + (direction * scrollIncr); - - if ((direction > 0 && scrollTarget >= scrollToVal) || - (direction < 0 && scrollTarget <= scrollToVal)) { - // Overshot our target. Just manually set to equal the target - // and clear the interval - scrollTarget = scrollToVal; - if (cb) { cb(); } // HopscotchBubble.show - window.scrollTo(0, scrollTarget); - return; - } - - window.scrollTo(0, scrollTarget); - - if (utils.getScrollTop() === scrollTop) { - // Couldn't scroll any further. - if (cb) { cb(); } // HopscotchBubble.show - return; + // Use YUI if it exists + if ((typeof YAHOO === 'undefined' ? 'undefined' : _typeof(YAHOO)) !== undefinedStr && _typeof(YAHOO.env) !== undefinedStr && _typeof(YAHOO.env.ua) !== undefinedStr && _typeof(YAHOO.util) !== undefinedStr && _typeof(YAHOO.util.Scroll) !== undefinedStr) { + scrollEl = YAHOO.env.ua.webkit ? document.body : document.documentElement; + yuiEase = YAHOO.util.Easing ? YAHOO.util.Easing.easeOut : undefined; + yuiAnim = new YAHOO.util.Scroll(scrollEl, { + scroll: { to: [0, scrollToVal] } + }, getOption('scrollDuration') / 1000, yuiEase); + yuiAnim.onComplete.subscribe(cb); + yuiAnim.animate(); } - // If we reached this point, that means there's still more to scroll. - setTimeout(scrollTimeoutFn, 10); - }; + // Use jQuery if it exists + else if (hasJquery) { + jQuery('body, html').animate({ scrollTop: scrollToVal }, getOption('scrollDuration'), cb); + } - scrollTimeoutFn(); - } - } + // Use my crummy setInterval scroll solution if we're using plain, vanilla Javascript. + else { + if (scrollToVal < 0) { + scrollToVal = 0; + } + + // 48 * 10 == 480ms scroll duration + // make it slightly less than CSS transition duration because of + // setInterval overhead. + // To increase or decrease duration, change the divisor of scrollIncr. + direction = windowTop > targetTop ? -1 : 1; // -1 means scrolling up, 1 means down + scrollIncr = Math.abs(windowTop - scrollToVal) / (getOption('scrollDuration') / 10); + _scrollTimeoutFn = function scrollTimeoutFn() { + var scrollTop = utils.getScrollTop(), + scrollTarget = scrollTop + direction * scrollIncr; + + if (direction > 0 && scrollTarget >= scrollToVal || direction < 0 && scrollTarget <= scrollToVal) { + // Overshot our target. Just manually set to equal the target + // and clear the interval + scrollTarget = scrollToVal; + if (cb) { + cb(); + } // HopscotchBubble.show + window.scrollTo(0, scrollTarget); + return; + } + + window.scrollTo(0, scrollTarget); + + if (utils.getScrollTop() === scrollTop) { + // Couldn't scroll any further. + if (cb) { + cb(); + } // HopscotchBubble.show + return; + } + + // If we reached this point, that means there's still more to scroll. + setTimeout(_scrollTimeoutFn, 10); + }; + + _scrollTimeoutFn(); + } + } }, + /** * goToStepWithTarget * @@ -1537,30 +1525,26 @@ * @param {Number} direction Either 1 for incrementing or -1 for decrementing * @param {Function} cb The callback function to be invoked when the step has been found */ - goToStepWithTarget = function(direction, cb) { - var target, - step, - goToStepFn; + goToStepWithTarget = function goToStepWithTarget(direction, cb) { + var target, step, goToStepFn; - if (currStepNum + direction >= 0 && - currStepNum + direction < currTour.steps.length) { + if (currStepNum + direction >= 0 && currStepNum + direction < currTour.steps.length) { currStepNum += direction; step = getCurrStep(); - goToStepFn = function() { + goToStepFn = function goToStepFn() { target = utils.getStepTarget(step); if (target) { //this step was previously skipped, but now its target exists, //remove this step from skipped steps set - if(skippedSteps[currStepNum]) { + if (skippedSteps[currStepNum]) { delete skippedSteps[currStepNum]; } // We're done! Return the step number via the callback. cb(currStepNum); - } - else { + } else { //mark this step as skipped, since its target wasn't found skippedSteps[currStepNum] = true; // Haven't found a valid target yet. Recursively call @@ -1572,16 +1556,15 @@ if (step.delay) { setTimeout(goToStepFn, step.delay); - } - else { + } else { goToStepFn(); } - } - else { + } else { cb(-1); // signal that we didn't find any step with a valid target } }, + /** * changeStep * @@ -1592,7 +1575,7 @@ * @param {Boolean} doCallbacks Flag for invoking onNext or onPrev callbacks * @param {Number} direction Either 1 for "next" or -1 for "prev" */ - changeStep = function(doCallbacks, direction) { + changeStep = function changeStep(doCallbacks, direction) { var bubble = getBubble(), self = this, step, @@ -1614,9 +1597,8 @@ origStep = step; if (direction > 0) { wasMultiPage = origStep.multipage; - } - else { - wasMultiPage = (currStepNum > 0 && currTour.steps[currStepNum-1].multipage); + } else { + wasMultiPage = currStepNum > 0 && currTour.steps[currStepNum - 1].multipage; } /** @@ -1624,7 +1606,7 @@ * * @private */ - changeStepCb = function(stepNum) { + changeStepCb = function changeStepCb(stepNum) { var doShowFollowingStep; if (stepNum === -1) { @@ -1635,8 +1617,7 @@ if (doCallbacks) { if (direction > 0) { doShowFollowingStep = utils.invokeEventCallbacks('next', origStep.onNext); - } - else { + } else { doShowFollowingStep = utils.invokeEventCallbacks('prev', origStep.onPrev); } } @@ -1649,7 +1630,7 @@ if (wasMultiPage) { // Update state for the next page - setStateHelper(); + setStateHelper(); // Next step is on a different page, so no need to attempt to render it. return; @@ -1661,19 +1642,17 @@ // don't show the next step. if (doShowFollowingStep) { this.showStep(stepNum); - } - else { + } else { // Halt tour (but don't clear state) this.endTour(false); } }; if (!wasMultiPage && getOption('skipIfNoElement')) { - goToStepWithTarget(direction, function(stepNum) { + goToStepWithTarget(direction, function (stepNum) { changeStepCb.call(self, stepNum); }); - } - else if (currStepNum + direction >= 0 && currStepNum + direction < currTour.steps.length) { + } else if (currStepNum + direction >= 0 && currStepNum + direction < currTour.steps.length) { // only try incrementing once, and invoke error callback if no target is found currStepNum += direction; step = getCurrStep(); @@ -1689,6 +1668,7 @@ return this; }, + /** * loadTour * @@ -1697,7 +1677,7 @@ * @private * @param tour The tour JSON object */ - loadTour = function(tour) { + loadTour = function loadTour(tour) { var tmpOpt = {}, prop, tourState, @@ -1705,9 +1685,7 @@ // Set tour-specific configurations for (prop in tour) { - if (tour.hasOwnProperty(prop) && - prop !== 'id' && - prop !== 'steps') { + if (tour.hasOwnProperty(prop) && prop !== 'id' && prop !== 'steps') { tmpOpt[prop] = tour[prop]; } } @@ -1719,32 +1697,32 @@ // Get existing tour state, if it exists. tourState = utils.getState(getOption('cookieName')); if (tourState) { - tourStateValues = tourState.split(':'); - cookieTourId = tourStateValues[0]; // selecting tour is not supported by this framework. - cookieTourStep = tourStateValues[1]; + tourStateValues = tourState.split(':'); + cookieTourId = tourStateValues[0]; // selecting tour is not supported by this framework. + cookieTourStep = tourStateValues[1]; - if(tourStateValues.length > 2) { + if (tourStateValues.length > 2) { cookieSkippedSteps = tourStateValues[2].split(','); } - cookieTourStep = parseInt(cookieTourStep, 10); + cookieTourStep = parseInt(cookieTourStep, 10); } return this; }, + /** * Find the first step to show for a tour. (What is the first step with a * target on the page?) */ - findStartingStep = function(startStepNum, savedSkippedSteps, cb) { - var step, - target; + findStartingStep = function findStartingStep(startStepNum, savedSkippedSteps, cb) { + var step, target; currStepNum = startStepNum || 0; skippedSteps = savedSkippedSteps || {}; - step = getCurrStep(); - target = utils.getStepTarget(step); + step = getCurrStep(); + target = utils.getStepTarget(step); if (target) { // First step had an existing target. @@ -1766,18 +1744,16 @@ if (getOption('skipIfNoElement')) { goToStepWithTarget(1, cb); return; - } - else { + } else { currStepNum = -1; cb(currStepNum); } } }, - - showStepHelper = function(stepNum) { - var step = currTour.steps[stepNum], - bubble = getBubble(), - targetEl = utils.getStepTarget(step); + showStepHelper = function showStepHelper(stepNum) { + var step = currTour.steps[stepNum], + bubble = getBubble(), + targetEl = utils.getStepTarget(step); function showBubble() { bubble.show(); @@ -1794,12 +1770,11 @@ bubble.hide(false); - bubble.render(step, stepNum, function(adjustScroll) { + bubble.render(step, stepNum, function (adjustScroll) { // when done adjusting window scroll, call showBubble helper fn if (adjustScroll) { adjustWindowScroll(showBubble); - } - else { + } else { showBubble(); } @@ -1811,18 +1786,18 @@ setStateHelper(); }, - - setStateHelper = function() { + setStateHelper = function setStateHelper() { var cookieVal = currTour.id + ':' + currStepNum, - skipedStepIndexes = winHopscotch.getSkippedStepsIndexes(); + skipedStepIndexes = winHopscotch.getSkippedStepsIndexes(); - if(skipedStepIndexes && skipedStepIndexes.length > 0) { + if (skipedStepIndexes && skipedStepIndexes.length > 0) { cookieVal += ':' + skipedStepIndexes.join(','); } utils.setState(getOption('cookieName'), cookieVal, 1); }, + /** * init * @@ -1830,7 +1805,7 @@ * * @private */ - init = function(initOptions) { + init = function init(initOptions) { if (initOptions) { //initOptions.cookieName = initOptions.cookieName || 'hopscotch.tour.state'; this.configure(initOptions); @@ -1845,8 +1820,8 @@ * @returns {Object} HopscotchCalloutManager * */ - this.getCalloutManager = function() { - if (typeof calloutMgr === undefinedStr) { + this.getCalloutManager = function () { + if ((typeof calloutMgr === 'undefined' ? 'undefined' : _typeof(calloutMgr)) === undefinedStr) { calloutMgr = new HopscotchCalloutManager(); } @@ -1863,7 +1838,7 @@ * @returns {Object} Hopscotch * */ - this.startTour = function(tour, stepNum) { + this.startTour = function (tour, stepNum) { var bubble, currStepNum, skippedSteps = {}, @@ -1872,23 +1847,22 @@ // loadTour if we are calling startTour directly. (When we call startTour // from window onLoad handler, we'll use currTour) if (!currTour) { - + // Sanity check! Is there a tour? - if(!tour){ + if (!tour) { throw new Error('Tour data is required for startTour.'); } // Check validity of tour ID. If invalid, throw an error. - if(!tour.id || !validIdRegEx.test(tour.id)) { + if (!tour.id || !validIdRegEx.test(tour.id)) { throw new Error('Tour ID is using an invalid format. Use alphanumeric, underscores, and/or hyphens only. First character must be a letter.'); } currTour = tour; loadTour.call(this, tour); - } - if (typeof stepNum !== undefinedStr) { + if ((typeof stepNum === 'undefined' ? 'undefined' : _typeof(stepNum)) !== undefinedStr) { if (stepNum >= currTour.steps.length) { throw new Error('Specified step number out of bounds.'); } @@ -1902,21 +1876,20 @@ return this; } - if (typeof currStepNum === "undefined" && currTour.id === cookieTourId && typeof cookieTourStep !== undefinedStr) { + if (typeof currStepNum === "undefined" && currTour.id === cookieTourId && (typeof cookieTourStep === 'undefined' ? 'undefined' : _typeof(cookieTourStep)) !== undefinedStr) { currStepNum = cookieTourStep; - if(cookieSkippedSteps.length > 0){ - for(var i = 0, len = cookieSkippedSteps.length; i < len; i++) { + if (cookieSkippedSteps.length > 0) { + for (var i = 0, len = cookieSkippedSteps.length; i < len; i++) { skippedSteps[cookieSkippedSteps[i]] = true; } } - } - else if (!currStepNum) { + } else if (!currStepNum) { currStepNum = 0; } // Find the current step we should begin the tour on, and then actually start the tour. - findStartingStep(currStepNum, skippedSteps, function(stepNum) { - var target = (stepNum !== -1) && utils.getStepTarget(currTour.steps[stepNum]); + findStartingStep(currStepNum, skippedSteps, function (stepNum) { + var target = stepNum !== -1 && utils.getStepTarget(currTour.steps[stepNum]); if (!target) { // Should we trigger onEnd callback? Let's err on the side of caution @@ -1941,8 +1914,7 @@ if (getOption('skipIfNoElement')) { self.nextStep(false); } - } - else { + } else { self.showStep(stepNum); } }); @@ -1958,10 +1930,10 @@ * @stepNum {Number} stepNum The step number to show * @returns {Object} Hopscotch */ - this.showStep = function(stepNum) { + this.showStep = function (stepNum) { var step = currTour.steps[stepNum], prevStepNum = currStepNum; - if(!utils.getStepTarget(step)) { + if (!utils.getStepTarget(step)) { currStepNum = stepNum; utils.invokeEventCallbacks('error'); currStepNum = prevStepNum; @@ -1969,11 +1941,10 @@ } if (step.delay) { - setTimeout(function() { + setTimeout(function () { showStepHelper(stepNum); }, step.delay); - } - else { + } else { showStepHelper(stepNum); } return this; @@ -1987,7 +1958,7 @@ * @param {Boolean} doCallbacks Flag for invoking onPrev callback. Defaults to true. * @returns {Object} Hopscotch */ - this.prevStep = function(doCallbacks) { + this.prevStep = function (doCallbacks) { changeStep.call(this, doCallbacks, -1); return this; }; @@ -2000,7 +1971,7 @@ * @param {Boolean} doCallbacks Flag for invoking onNext callback. Defaults to true. * @returns {Object} Hopscotch */ - this.nextStep = function(doCallbacks) { + this.nextStep = function (doCallbacks) { changeStep.call(this, doCallbacks, 1); return this; }; @@ -2014,22 +1985,22 @@ * @param {Boolean} doCallbacks Flag for invoking 'onEnd' callbacks. Defaults to true. * @returns {Object} Hopscotch */ - this.endTour = function(clearState, doCallbacks) { - var bubble = getBubble(), - currentStep; + this.endTour = function (clearState, doCallbacks) { + var bubble = getBubble(), + currentStep; - clearState = utils.valOrDefault(clearState, true); - doCallbacks = utils.valOrDefault(doCallbacks, true); + clearState = utils.valOrDefault(clearState, true); + doCallbacks = utils.valOrDefault(doCallbacks, true); //remove event listener if current step had it added - if(currTour) { + if (currTour) { currentStep = getCurrStep(); - if(currentStep && currentStep.nextOnTargetClick) { + if (currentStep && currentStep.nextOnTargetClick) { utils.removeEvtListener(utils.getStepTarget(currentStep), 'click', targetClickNextFn); } } - currStepNum = 0; + currStepNum = 0; cookieTourStep = undefined; bubble.hide(); @@ -2058,7 +2029,7 @@ * * @return {Object} The currently loaded tour. */ - this.getCurrTour = function() { + this.getCurrTour = function () { return currTour; }; @@ -2067,7 +2038,7 @@ * * @return {Object} The currently visible target. */ - this.getCurrTarget = function() { + this.getCurrTarget = function () { return utils.getStepTarget(getCurrStep()); }; @@ -2076,7 +2047,7 @@ * * @return {number} The current zero-based step number. */ - this.getCurrStepNum = function() { + this.getCurrStepNum = function () { return currStepNum; }; @@ -2085,11 +2056,11 @@ * * @return {Array} Array of skipped step indexes */ - this.getSkippedStepsIndexes = function() { + this.getSkippedStepsIndexes = function () { var skippedStepsIdxArray = [], - stepIds; + stepIds; - for(stepIds in skippedSteps){ + for (stepIds in skippedSteps) { skippedStepsIdxArray.push(stepIds); } @@ -2105,9 +2076,9 @@ * * @returns {Object} Hopscotch */ - this.refreshBubblePosition = function() { + this.refreshBubblePosition = function () { var currStep = getCurrStep(); - if(currStep){ + if (currStep) { getBubble().setPosition(currStep); } this.getCalloutManager().refreshCalloutPositions(); @@ -2125,7 +2096,7 @@ * For internal use only! * @returns {Object} Hopscotch */ - this.listen = function(evtType, cb, isTourCb) { + this.listen = function (evtType, cb, isTourCb) { if (evtType) { callbacks[evtType].push({ cb: cb, fromTour: isTourCb }); } @@ -2141,7 +2112,7 @@ * @param {Function} cb The callback to remove. * @returns {Object} Hopscotch */ - this.unlisten = function(evtType, cb) { + this.unlisten = function (evtType, cb) { var evtCallbacks = callbacks[evtType], i, len; @@ -2167,25 +2138,21 @@ * by a tour. Defaults to false. * @returns {Object} Hopscotch */ - this.removeCallbacks = function(evtName, tourOnly) { - var cbArr, - i, - len, - evt; + this.removeCallbacks = function (evtName, tourOnly) { + var cbArr, i, len, evt; // If evtName is null or undefined, remove callbacks for all events. for (evt in callbacks) { if (!evtName || evtName === evt) { if (tourOnly) { cbArr = callbacks[evt]; - for (i=0, len=cbArr.length; i < len; ++i) { + for (i = 0, len = cbArr.length; i < len; ++i) { if (cbArr[i].fromTour) { cbArr.splice(i--, 1); --len; } } - } - else { + } else { callbacks[evt] = []; } } @@ -2201,17 +2168,17 @@ * @param {String} id The id of the function. * @param {Function} id The callback function. */ - this.registerHelper = function(id, fn) { + this.registerHelper = function (id, fn) { if (typeof id === 'string' && typeof fn === 'function') { helpers[id] = fn; } }; - this.unregisterHelper = function(id) { + this.unregisterHelper = function (id) { helpers[id] = null; }; - this.invokeHelper = function(id) { + this.invokeHelper = function (id) { var args = [], i, len; @@ -2233,7 +2200,7 @@ * @param {String} name The cookie name * @returns {Object} Hopscotch */ - this.setCookieName = function(name) { + this.setCookieName = function (name) { opt.cookieName = name; return this; }; @@ -2245,7 +2212,7 @@ * * @returns {Object} Hopscotch */ - this.resetDefaultOptions = function() { + this.resetDefaultOptions = function () { opt = {}; return this; }; @@ -2257,7 +2224,7 @@ * * @returns {Object} Hopscotch */ - this.resetDefaultI18N = function() { + this.resetDefaultI18N = function () { customI18N = {}; return this; }; @@ -2269,7 +2236,7 @@ * * @returns {String} State of previous tour run, or empty string if none exists. */ - this.getState = function() { + this.getState = function () { return utils.getState(getOption('cookieName')); }; @@ -2281,7 +2248,7 @@ * @param options * @param {Boolean} isTourOptions Should be set to true when setting options from a tour definition. */ - _configure = function(options, isTourOptions) { + _configure = function _configure(options, isTourOptions) { var bubble, events = ['next', 'prev', 'start', 'end', 'show', 'error', 'close'], eventPropName, @@ -2304,9 +2271,7 @@ // to a function. eventPropName = 'on' + events[i].charAt(0).toUpperCase() + events[i].substring(1); if (options[eventPropName]) { - this.listen(events[i], - options[eventPropName], - isTourOptions); + this.listen(events[i], options[eventPropName], isTourOptions); } } @@ -2404,7 +2369,7 @@ * @param {Object} options A hash of configuration options. * @returns {Object} Hopscotch */ - this.configure = function(options) { + this.configure = function (options) { return _configure.call(this, options, false); }; @@ -2416,14 +2381,13 @@ * @param {String|Function(obj)} The template to use for rendering. * @returns {Object} The Hopscotch object (for chaining). */ - this.setRenderer = function(render){ - var typeOfRender = typeof render; + this.setRenderer = function (render) { + var typeOfRender = typeof render === 'undefined' ? 'undefined' : _typeof(render); - if(typeOfRender === 'string'){ + if (typeOfRender === 'string') { templateToUse = render; customRenderer = undefined; - } - else if(typeOfRender === 'function'){ + } else if (typeOfRender === 'function') { customRenderer = render; } return this; @@ -2435,8 +2399,8 @@ * @param {Function} - The escape method to use. * @returns {Object} The Hopscotch object (for chaining). */ - this.setEscaper = function(esc){ - if (typeof esc === 'function'){ + this.setEscaper = function (esc) { + if (typeof esc === 'function') { customEscape = esc; } return this; @@ -2447,10 +2411,10 @@ winHopscotch = new Hopscotch(); -// Template includes, placed inside a closure to ensure we don't -// end up declaring our shim globally. -(function(){ -var _ = {}; + // Template includes, placed inside a closure to ensure we don't + // end up declaring our shim globally. + (function () { + var _ = {}; /* * Adapted from the Underscore.js framework. Check it out at * https://github.com/jashkenas/underscore @@ -2468,7 +2432,7 @@ _.escape = function(str){ }); } -this["templates"] = this["templates"] || {}; + this["templates"] = this["templates"] || {}; this["templates"]["bubble_default"] = function(data) { var __t, __p = '', __e = _.escape, __j = Array.prototype.join; @@ -2538,8 +2502,10 @@ __p += '"),e+="\n ",g.showCTA&&(e+='"),e+="\n ",g.showNext&&(e+='"),e+="\n \n ",g.showClose&&(e+='"),e+='\n\n
\n
\n
\n
\n'}}.call(m),m}); \ No newline at end of file +!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.hopscotch=b()}(this,function(){"use strict";var a,b,c,d,e,f,g,h,i,j,k,l,m,n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},o="bubble_default",p=window.Sizzle||null,q="undefined",r=!1,s=("undefined"==typeof jQuery?"undefined":n(jQuery))!==q,t=!1,u=!1,v=/^[a-zA-Z]+[a-zA-Z0-9_-]*$/,w={left:"right",right:"left"};try{n(window.sessionStorage)!==q&&(t=!0,sessionStorage.setItem("hopscotch.test.storage","ok"),sessionStorage.removeItem("hopscotch.test.storage"),u=!0)}catch(x){}l={smoothScroll:!0,scrollDuration:1e3,scrollTopMargin:200,showCloseButton:!0,showPrevButton:!1,showNextButton:!0,bubbleWidth:280,bubblePadding:15,arrowWidth:20,skipIfNoElement:!0,isRtl:!1,cookieName:"hopscotch.tour.state"},Array.isArray||(Array.isArray=function(a){return"[object Array]"===Object.prototype.toString.call(a)}),k=function(){r&&m.startTour()},h={addClass:function(a,b){var c,d,e,f;if(a.className){for(d=b.split(/\s+/),c=" "+a.className+" ",e=0,f=d.length;f>e;++e)c.indexOf(" "+d[e]+" ")<0&&(c+=d[e]+" ");a.className=c.replace(/^\s+|\s+$/g,"")}else a.className=b},removeClass:function(a,b){var c,d,e,f;for(d=b.split(/\s+/),c=" "+a.className+" ",e=0,f=d.length;f>e;++e)c=c.replace(" "+d[e]+" "," ");a.className=c.replace(/^\s+|\s+$/g,"")},hasClass:function(a,b){var c;return a.className?(c=" "+a.className+" ",-1!==c.indexOf(" "+b+" ")):!1},getPixelValue:function(a){var b="undefined"==typeof a?"undefined":n(a);return"number"===b?a:"string"===b?parseInt(a,10):0},valOrDefault:function(a,b){return("undefined"==typeof a?"undefined":n(a))!==q?a:b},invokeCallbackArrayHelper:function(a){var b;return Array.isArray(a)&&(b=j[a[0]],"function"==typeof b)?b.apply(this,a.slice(1)):void 0},invokeCallbackArray:function(a){var b,c;if(Array.isArray(a)){if("string"==typeof a[0])return h.invokeCallbackArrayHelper(a);for(b=0,c=a.length;c>b;++b)h.invokeCallback(a[b])}},invokeCallback:function(a){return"function"==typeof a?a():"string"==typeof a&&j[a]?j[a]():h.invokeCallbackArray(a)},invokeEventCallbacks:function(a,b){var c,d,e=i[a];if(b)return this.invokeCallback(b);for(c=0,d=e.length;d>c;++c)this.invokeCallback(e[c].cb)},getScrollTop:function(){var a;return a=n(window.pageYOffset)!==q?window.pageYOffset:document.documentElement.scrollTop},getScrollLeft:function(){var a;return a=n(window.pageXOffset)!==q?window.pageXOffset:document.documentElement.scrollLeft},getWindowHeight:function(){return window.innerHeight||document.documentElement.clientHeight},addEvtListener:function(a,b,c){return a?a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent("on"+b,c):void 0},removeEvtListener:function(a,b,c){return a?a.removeEventListener?a.removeEventListener(b,c,!1):a.detachEvent("on"+b,c):void 0},documentIsReady:function(){return"complete"===document.readyState},evtPreventDefault:function(a){a.preventDefault?a.preventDefault():event&&(event.returnValue=!1)},extend:function(a,b){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c])},getStepTargetHelper:function(a){var b=document.getElementById(a);if(b)return b;if(s)return b=jQuery(a),b.length?b[0]:null;if(p)return b=new p(a),b.length?b[0]:null;if(document.querySelector)try{return document.querySelector(a)}catch(c){}return/^#[a-zA-Z][\w-_:.]*$/.test(a)?document.getElementById(a.substring(1)):null},getStepTarget:function(a){var b;if(!a||!a.target)return null;if("string"==typeof a.target)return h.getStepTargetHelper(a.target);if(Array.isArray(a.target)){var c,d;for(c=0,d=a.target.length;d>c;c++)if("string"==typeof a.target[c]&&(b=h.getStepTargetHelper(a.target[c])))return b;return null}return a.target},getI18NString:function(a){return e[a]||d[a]},setState:function(a,b,c){var d,e="";if(t&&u)try{sessionStorage.setItem(a,b)}catch(f){u=!1,this.setState(a,b,c)}else t&&sessionStorage.removeItem(a),c&&(d=new Date,d.setTime(d.getTime()+24*c*60*60*1e3),e="; expires="+d.toGMTString()),document.cookie=a+"="+b+e+"; path=/"},getState:function(a){var b,c,d,e=a+"=",f=document.cookie.split(";");if(t&&(d=sessionStorage.getItem(a)))return d;for(b=0;b0,showNext:h.valOrDefault(a.showNextButton,this.opt.showNextButton),showCTA:h.valOrDefault(a.showCTAButton&&a.ctaLabel,!1),ctaLabel:a.ctaLabel,showClose:h.valOrDefault(this.opt.showCloseButton,!0)},step:{num:b,isLast:h.valOrDefault(n,!1),title:a.title||"",content:a.content||"",isRtl:a.isRtl,placement:a.placement,padding:h.valOrDefault(a.padding,this.opt.bubblePadding),width:h.getPixelValue(a.width)||this.opt.bubbleWidth,customData:a.customData||{}},tour:{isTour:this.opt.isTourBubble,numSteps:j,unsafe:h.valOrDefault(g,!1),customData:e||{}}},"function"==typeof d)r.innerHTML=d(q);else if("string"==typeof d){if(!m.templates||"function"!=typeof m.templates[d])throw new Error('Bubble rendering failed - template "'+d+'" is not a function.');r.innerHTML=m.templates[d](q)}else if(f)r.innerHTML=f(q);else{if(!m.templates||"function"!=typeof m.templates[o])throw new Error('Bubble rendering failed - template "'+o+'" is not a function.');r.innerHTML=m.templates[o](q)}var s,t=r.children,u=t.length;for(p=0;u>p;p++)s=t[p],h.hasClass(s,"hopscotch-arrow")&&(this.arrowEl=s);return r.style.zIndex="number"==typeof a.zindex?a.zindex:"",this._setArrow(a.placement),this.hide(!1),this.setPosition(a),c&&c(!a.fixedElement),this},_getStepNum:function(a){var b,c,d=0,e=m.getSkippedStepsIndexes(),f=e.length;for(c=0;f>c;c++)b=e[c],a>b&&d++;return a-d},_getStepI18nNum:function(a){var b=h.getI18NString("stepNums");return b&&au||u>=t.steps.length?null:t.steps[u]},G=function(){z.nextStep()},H=function(a){var b,c,d,e,f,g,i=C(),j=i.element,k=h.getPixelValue(j.style.top),l=k+h.getPixelValue(j.offsetHeight),m=h.getStepTarget(F()),o=m.getBoundingClientRect(),p=o.top+h.getScrollTop(),r=o.bottom+h.getScrollTop(),t=p>k?k:p,u=l>r?l:r,v=h.getScrollTop(),w=v+h.getWindowHeight(),x=t-E("scrollTopMargin");t>=v&&(t<=v+E("scrollTopMargin")||w>=u)?a&&a():E("smoothScroll")?("undefined"==typeof YAHOO?"undefined":n(YAHOO))!==q&&n(YAHOO.env)!==q&&n(YAHOO.env.ua)!==q&&n(YAHOO.util)!==q&&n(YAHOO.util.Scroll)!==q?(b=YAHOO.env.ua.webkit?document.body:document.documentElement,d=YAHOO.util.Easing?YAHOO.util.Easing.easeOut:void 0,c=new YAHOO.util.Scroll(b,{scroll:{to:[0,x]}},E("scrollDuration")/1e3,d),c.onComplete.subscribe(a),c.animate()):s?jQuery("body, html").animate({scrollTop:x},E("scrollDuration"),a):(0>x&&(x=0),e=v>t?-1:1,f=Math.abs(v-x)/(E("scrollDuration")/10),(g=function(){var b=h.getScrollTop(),c=b+e*f;return e>0&&c>=x||0>e&&x>=c?(c=x,a&&a(),void window.scrollTo(0,c)):(window.scrollTo(0,c),h.getScrollTop()===b?void(a&&a()):void setTimeout(g,10))})()):(window.scrollTo(0,x),a&&a())},I=function P(a,b){var c,d,e;u+a>=0&&u+a0?d.multipage:u>0&&t.steps[u-1].multipage,f=function(c){var f;if(-1===c)return this.endTour(!0);if(a&&(f=b>0?h.invokeEventCallbacks("next",d.onNext):h.invokeEventCallbacks("prev",d.onPrev)),c===u){if(e)return void N();f=h.valOrDefault(f,!0),f?this.showStep(c):this.endTour(!1)}},!e&&E("skipIfNoElement"))I(b,function(a){f.call(i,a)});else if(u+b>=0&&u+b2&&(B=d[2].split(",")),x=parseInt(x,10)),this},L=function(a,b,c){var d,e;if(u=a||0,A=b||{},d=F(),e=h.getStepTarget(d))return void c(u);if(!e){if(h.invokeEventCallbacks("error"),A[u]=!0,E("skipIfNoElement"))return void I(1,c);u=-1,c(u)}},M=function(a){function b(){d.show(),h.invokeEventCallbacks("show",c.onShow)}var c=t.steps[a],d=C(),e=h.getStepTarget(c);u!==a&&F().nextOnTargetClick&&h.removeEvtListener(h.getStepTarget(F()),"click",G),u=a,d.hide(!1),d.render(c,a,function(a){a?H(b):b(),c.nextOnTargetClick&&h.addEvtListener(e,"click",G)}),N()},N=function(){var a=t.id+":"+u,b=m.getSkippedStepsIndexes();b&&b.length>0&&(a+=":"+b.join(",")),h.setState(E("cookieName"),a,1)},O=function(a){a&&this.configure(a)};this.getCalloutManager=function(){return("undefined"==typeof k?"undefined":n(k))===q&&(k=new c),k},this.startTour=function(a,b){var c,d,e={},f=this;if(!t){if(!a)throw new Error("Tour data is required for startTour.");if(!a.id||!v.test(a.id))throw new Error("Tour ID is using an invalid format. Use alphanumeric, underscores, and/or hyphens only. First character must be a letter.");t=a,K.call(this,a)}if(("undefined"==typeof b?"undefined":n(b))!==q){if(b>=t.steps.length)throw new Error("Specified step number out of bounds.");d=b}if(!h.documentIsReady())return r=!0,this;if("undefined"==typeof d&&t.id===w&&("undefined"==typeof x?"undefined":n(x))!==q){if(d=x,B.length>0)for(var g=0,i=B.length;i>g;g++)e[B[g]]=!0}else d||(d=0);return L(d,e,function(a){var b=-1!==a&&h.getStepTarget(t.steps[a]);return b?(h.invokeEventCallbacks("start"),c=C(),c.hide(!1),f.isActive=!0,void(h.getStepTarget(F())?f.showStep(a):(h.invokeEventCallbacks("error"),E("skipIfNoElement")&&f.nextStep(!1)))):void f.endTour(!1,!1)}),this},this.showStep=function(a){var b=t.steps[a],c=u;return h.getStepTarget(b)?(b.delay?setTimeout(function(){M(a)},b.delay):M(a),this):(u=a,h.invokeEventCallbacks("error"),void(u=c))},this.prevStep=function(a){return J.call(this,a,-1),this},this.nextStep=function(a){return J.call(this,a,1),this},this.endTour=function(a,b){var c,d=C();return a=h.valOrDefault(a,!0),b=h.valOrDefault(b,!0),t&&(c=F(),c&&c.nextOnTargetClick&&h.removeEvtListener(h.getStepTarget(c),"click",G)),u=0,x=void 0,d.hide(),a&&h.clearState(E("cookieName")),this.isActive&&(this.isActive=!1,t&&b&&h.invokeEventCallbacks("end")),this.removeCallbacks(null,!0),this.resetDefaultOptions(),D(),t=null,this},this.getCurrTour=function(){return t},this.getCurrTarget=function(){return h.getStepTarget(F())},this.getCurrStepNum=function(){return u},this.getSkippedStepsIndexes=function(){var a,b=[];for(a in A)b.push(a);return b},this.refreshBubblePosition=function(){var a=F();return a&&C().setPosition(a),this.getCalloutManager().refreshCalloutPositions(),this},this.listen=function(a,b,c){return a&&i[a].push({cb:b,fromTour:c}),this},this.unlisten=function(a,b){var c,d,e=i[a];for(c=0,d=e.length;d>c;++c)e[c].cb===b&&e.splice(c,1);return this},this.removeCallbacks=function(a,b){var c,d,e,f;for(f in i)if(!a||a===f)if(b)for(c=i[f],d=0,e=c.length;e>d;++d)c[d].fromTour&&(c.splice(d--,1),--e);else i[f]=[];return this},this.registerHelper=function(a,b){"string"==typeof a&&"function"==typeof b&&(j[a]=b)},this.unregisterHelper=function(a){j[a]=null},this.invokeHelper=function(a){var b,c,d=[];for(b=1,c=arguments.length;c>b;++b)d.push(arguments[b]);j[a]&&j[a].call(null,d)},this.setCookieName=function(a){return p.cookieName=a,this},this.resetDefaultOptions=function(){return p={},this},this.resetDefaultI18N=function(){return e={},this},this.getState=function(){return h.getState(E("cookieName"))},y=function(a,b){var c,d,f,g,i=["next","prev","start","end","show","error","close"];for(p||this.resetDefaultOptions(),h.extend(p,a),a&&h.extend(e,a.i18n),f=0,g=i.length;g>f;++f)d="on"+i[f].charAt(0).toUpperCase()+i[f].substring(1),a[d]&&this.listen(i[f],a[d],b);return c=C(!0),this},this.configure=function(a){return y.call(this,a,!1)},this.setRenderer=function(a){var b="undefined"==typeof a?"undefined":n(a);return"string"===b?(o=a,f=void 0):"function"===b&&(f=a),this},this.setEscaper=function(a){return"function"==typeof a&&(g=a),this},O.call(this,a)},m=new a,function(){var a={};a.escape=function(a){return g?g(a):null==a?"":(""+a).replace(new RegExp("[&<>\"']","g"),function(a){return"&"==a?"&":"<"==a?"<":">"==a?">":'"'==a?""":"'"==a?"'":void 0})},this.templates=this.templates||{},this.templates.bubble_default=function(b){function c(b,c){return c?a.escape(b):b}var d,e="";a.escape,Array.prototype.join;e+="\n";var f=b.i18n,g=b.buttons,h=b.step,i=b.tour;return e+='\n
\n ',i.isTour&&(e+=''+(null==(d=f.stepNum)?"":d)+""),e+='\n
\n ',""!==h.title&&(e+='

'+(null==(d=c(h.title,i.unsafe))?"":d)+"

"),e+="\n ",""!==h.content&&(e+='
'+(null==(d=c(h.content,i.unsafe))?"":d)+"
"),e+='\n
\n
\n ',g.showPrev&&(e+='"),e+="\n ",g.showCTA&&(e+='"),e+="\n ",g.showNext&&(e+='"),e+="\n
\n ",g.showClose&&(e+='"),e+='\n
\n
\n
\n
\n
\n'}}.call(m);var y=m;return y}); \ No newline at end of file diff --git a/package.json b/package.json index e75b3637..5c7e69ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hopscotch", - "version": "0.2.8", + "version": "0.3.0", "description": "A framework to make it easy for developers to add product tours to their pages.", "main": "dist/js/hopscotch.min.js", "directories": {