shepherdjs_rails 1.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +50 -0
- data/Rakefile +29 -0
- data/lib/shepherdjs_rails/engine.rb +4 -0
- data/lib/shepherdjs_rails/version.rb +3 -0
- data/lib/shepherdjs_rails.rb +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/to_time_preserves_timezone.rb +10 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/shepherdjs_rails_test.rb +7 -0
- data/test/test_helper.rb +20 -0
- data/vendor/assets/javascripts/shepherd.js +747 -0
- data/vendor/assets/javascripts/tether.js +1443 -0
- data/vendor/assets/stylesheets/shepherd-theme-arrows-fix.css +5 -0
- data/vendor/assets/stylesheets/shepherd-theme-arrows-plain-buttons.css +215 -0
- data/vendor/assets/stylesheets/shepherd-theme-arrows.css +229 -0
- data/vendor/assets/stylesheets/shepherd-theme-dark.css +246 -0
- data/vendor/assets/stylesheets/shepherd-theme-default.css +246 -0
- data/vendor/assets/stylesheets/shepherd-theme-square-dark.css +248 -0
- data/vendor/assets/stylesheets/shepherd-theme-square.css +248 -0
- data/vendor/assets/stylesheets/shepherd.css +9 -0
- metadata +149 -0
@@ -0,0 +1,747 @@
|
|
1
|
+
//= require tether
|
2
|
+
|
3
|
+
/*! tether-shepherd 1.8.1 */
|
4
|
+
|
5
|
+
(function(root, factory) {
|
6
|
+
if (typeof define === 'function' && define.amd) {
|
7
|
+
define(["tether"], factory);
|
8
|
+
} else if (typeof exports === 'object') {
|
9
|
+
module.exports = factory(require('tether'));
|
10
|
+
} else {
|
11
|
+
root.Shepherd = factory(root.Tether);
|
12
|
+
}
|
13
|
+
}(this, function(Tether) {
|
14
|
+
|
15
|
+
/* global Tether */
|
16
|
+
|
17
|
+
'use strict';
|
18
|
+
|
19
|
+
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
20
|
+
|
21
|
+
var _get = function get(_x5, _x6, _x7) { var _again = true; _function: while (_again) { var object = _x5, property = _x6, receiver = _x7; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x5 = parent; _x6 = property; _x7 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
|
22
|
+
|
23
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
24
|
+
|
25
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
26
|
+
|
27
|
+
var _Tether$Utils = Tether.Utils;
|
28
|
+
var Evented = _Tether$Utils.Evented;
|
29
|
+
var addClass = _Tether$Utils.addClass;
|
30
|
+
var extend = _Tether$Utils.extend;
|
31
|
+
var hasClass = _Tether$Utils.hasClass;
|
32
|
+
var removeClass = _Tether$Utils.removeClass;
|
33
|
+
var uniqueId = _Tether$Utils.uniqueId;
|
34
|
+
|
35
|
+
var Shepherd = new Evented();
|
36
|
+
|
37
|
+
function isUndefined(obj) {
|
38
|
+
return typeof obj === 'undefined';
|
39
|
+
};
|
40
|
+
|
41
|
+
function isArray(obj) {
|
42
|
+
return obj && obj.constructor === Array;
|
43
|
+
};
|
44
|
+
|
45
|
+
function isObject(obj) {
|
46
|
+
return obj && obj.constructor === Object;
|
47
|
+
};
|
48
|
+
|
49
|
+
function isObjectLoose(obj) {
|
50
|
+
return typeof obj === 'object';
|
51
|
+
};
|
52
|
+
|
53
|
+
var ATTACHMENT = {
|
54
|
+
'top right': 'bottom left',
|
55
|
+
'top left': 'bottom right',
|
56
|
+
'top center': 'bottom center',
|
57
|
+
'middle right': 'middle left',
|
58
|
+
'middle left': 'middle right',
|
59
|
+
'middle center': 'middle center',
|
60
|
+
'bottom left': 'top right',
|
61
|
+
'bottom right': 'top left',
|
62
|
+
'bottom center': 'top center',
|
63
|
+
'top': 'bottom center',
|
64
|
+
'left': 'middle right',
|
65
|
+
'right': 'middle left',
|
66
|
+
'bottom': 'top center',
|
67
|
+
'center': 'middle center',
|
68
|
+
'middle': 'middle center'
|
69
|
+
};
|
70
|
+
|
71
|
+
function createFromHTML(html) {
|
72
|
+
var el = document.createElement('div');
|
73
|
+
el.innerHTML = html;
|
74
|
+
return el.children[0];
|
75
|
+
}
|
76
|
+
|
77
|
+
function matchesSelector(el, sel) {
|
78
|
+
var matches = undefined;
|
79
|
+
if (!isUndefined(el.matches)) {
|
80
|
+
matches = el.matches;
|
81
|
+
} else if (!isUndefined(el.matchesSelector)) {
|
82
|
+
matches = el.matchesSelector;
|
83
|
+
} else if (!isUndefined(el.msMatchesSelector)) {
|
84
|
+
matches = el.msMatchesSelector;
|
85
|
+
} else if (!isUndefined(el.webkitMatchesSelector)) {
|
86
|
+
matches = el.webkitMatchesSelector;
|
87
|
+
} else if (!isUndefined(el.mozMatchesSelector)) {
|
88
|
+
matches = el.mozMatchesSelector;
|
89
|
+
} else if (!isUndefined(el.oMatchesSelector)) {
|
90
|
+
matches = el.oMatchesSelector;
|
91
|
+
}
|
92
|
+
return matches.call(el, sel);
|
93
|
+
}
|
94
|
+
|
95
|
+
var positionRe = /^(.+) (top|left|right|bottom|center|\[[a-z ]+\])$/;
|
96
|
+
|
97
|
+
function parsePosition(str) {
|
98
|
+
if (isObjectLoose(str)) {
|
99
|
+
if (str.hasOwnProperty("element") && str.hasOwnProperty("on")) {
|
100
|
+
return str;
|
101
|
+
}
|
102
|
+
return null;
|
103
|
+
}
|
104
|
+
|
105
|
+
var matches = positionRe.exec(str);
|
106
|
+
if (!matches) {
|
107
|
+
return null;
|
108
|
+
}
|
109
|
+
|
110
|
+
var on = matches[2];
|
111
|
+
if (on[0] === '[') {
|
112
|
+
on = on.substring(1, on.length - 1);
|
113
|
+
}
|
114
|
+
|
115
|
+
return {
|
116
|
+
'element': matches[1],
|
117
|
+
'on': on
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
function parseShorthand(obj, props) {
|
122
|
+
if (obj === null || isUndefined(obj)) {
|
123
|
+
return obj;
|
124
|
+
} else if (isObjectLoose(obj)) {
|
125
|
+
return obj;
|
126
|
+
}
|
127
|
+
|
128
|
+
var vals = obj.split(' ');
|
129
|
+
var out = {};
|
130
|
+
var j = props.length - 1;
|
131
|
+
for (var i = vals.length - 1; i >= 0; i--) {
|
132
|
+
if (j === 0) {
|
133
|
+
out[props[j]] = vals.slice(0, i + 1).join(' ');
|
134
|
+
break;
|
135
|
+
} else {
|
136
|
+
out[props[j]] = vals[i];
|
137
|
+
}
|
138
|
+
|
139
|
+
j--;
|
140
|
+
}
|
141
|
+
|
142
|
+
return out;
|
143
|
+
}
|
144
|
+
|
145
|
+
var Step = (function (_Evented) {
|
146
|
+
_inherits(Step, _Evented);
|
147
|
+
|
148
|
+
function Step(tour, options) {
|
149
|
+
_classCallCheck(this, Step);
|
150
|
+
|
151
|
+
_get(Object.getPrototypeOf(Step.prototype), 'constructor', this).call(this, tour, options);
|
152
|
+
this.tour = tour;
|
153
|
+
this.bindMethods();
|
154
|
+
this.setOptions(options);
|
155
|
+
return this;
|
156
|
+
}
|
157
|
+
|
158
|
+
_createClass(Step, [{
|
159
|
+
key: 'bindMethods',
|
160
|
+
value: function bindMethods() {
|
161
|
+
var _this = this;
|
162
|
+
|
163
|
+
var methods = ['_show', 'show', 'hide', 'isOpen', 'cancel', 'complete', 'scrollTo', 'destroy', 'render'];
|
164
|
+
methods.map(function (method) {
|
165
|
+
_this[method] = _this[method].bind(_this);
|
166
|
+
});
|
167
|
+
}
|
168
|
+
}, {
|
169
|
+
key: 'setOptions',
|
170
|
+
value: function setOptions() {
|
171
|
+
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
172
|
+
|
173
|
+
this.options = options;
|
174
|
+
this.destroy();
|
175
|
+
|
176
|
+
this.id = this.options.id || this.id || 'step-' + uniqueId();
|
177
|
+
|
178
|
+
var when = this.options.when;
|
179
|
+
if (when) {
|
180
|
+
for (var _event in when) {
|
181
|
+
if (({}).hasOwnProperty.call(when, _event)) {
|
182
|
+
var handler = when[_event];
|
183
|
+
this.on(_event, handler, this);
|
184
|
+
}
|
185
|
+
}
|
186
|
+
}
|
187
|
+
|
188
|
+
// Button configuration
|
189
|
+
|
190
|
+
var buttonsJson = JSON.stringify(this.options.buttons);
|
191
|
+
var buttonsAreDefault = isUndefined(buttonsJson) || buttonsJson === "true";
|
192
|
+
|
193
|
+
var buttonsAreEmpty = buttonsJson === "{}" || buttonsJson === "[]" || buttonsJson === "null" || buttonsJson === "false";
|
194
|
+
|
195
|
+
var buttonsAreArray = !buttonsAreDefault && isArray(this.options.buttons);
|
196
|
+
|
197
|
+
var buttonsAreObject = !buttonsAreDefault && isObject(this.options.buttons);
|
198
|
+
|
199
|
+
// Show default button if undefined or 'true'
|
200
|
+
if (buttonsAreDefault) {
|
201
|
+
this.options.buttons = [{
|
202
|
+
text: 'Next',
|
203
|
+
action: this.tour.next,
|
204
|
+
classes: 'btn'
|
205
|
+
}];
|
206
|
+
|
207
|
+
// Can pass in an object which will assume asingle button
|
208
|
+
} else if (!buttonsAreEmpty && buttonsAreObject) {
|
209
|
+
this.options.buttons = [this.options.buttons];
|
210
|
+
|
211
|
+
// Falsey/empty values or non-object values prevent buttons from rendering
|
212
|
+
} else if (buttonsAreEmpty || !buttonsAreArray) {
|
213
|
+
this.options.buttons = false;
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}, {
|
217
|
+
key: 'getTour',
|
218
|
+
value: function getTour() {
|
219
|
+
return this.tour;
|
220
|
+
}
|
221
|
+
}, {
|
222
|
+
key: 'bindAdvance',
|
223
|
+
value: function bindAdvance() {
|
224
|
+
var _this2 = this;
|
225
|
+
|
226
|
+
// An empty selector matches the step element
|
227
|
+
|
228
|
+
var _parseShorthand = parseShorthand(this.options.advanceOn, ['selector', 'event']);
|
229
|
+
|
230
|
+
var event = _parseShorthand.event;
|
231
|
+
var selector = _parseShorthand.selector;
|
232
|
+
|
233
|
+
var handler = function handler(e) {
|
234
|
+
if (!_this2.isOpen()) {
|
235
|
+
return;
|
236
|
+
}
|
237
|
+
|
238
|
+
if (!isUndefined(selector)) {
|
239
|
+
if (matchesSelector(e.target, selector)) {
|
240
|
+
_this2.tour.next();
|
241
|
+
}
|
242
|
+
} else {
|
243
|
+
if (_this2.el && e.target === _this2.el) {
|
244
|
+
_this2.tour.next();
|
245
|
+
}
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
// TODO: this should also bind/unbind on show/hide
|
250
|
+
document.body.addEventListener(event, handler);
|
251
|
+
this.on('destroy', function () {
|
252
|
+
return document.body.removeEventListener(event, handler);
|
253
|
+
});
|
254
|
+
}
|
255
|
+
}, {
|
256
|
+
key: 'getAttachTo',
|
257
|
+
value: function getAttachTo() {
|
258
|
+
var opts = parsePosition(this.options.attachTo) || {};
|
259
|
+
var returnOpts = extend({}, opts);
|
260
|
+
|
261
|
+
if (typeof opts.element === 'string') {
|
262
|
+
// Can't override the element in user opts reference because we can't
|
263
|
+
// guarantee that the element will exist in the future.
|
264
|
+
returnOpts.element = document.querySelector(opts.element);
|
265
|
+
if (!returnOpts.element) {
|
266
|
+
console.error('The element for this Shepherd step was not found ' + opts.element);
|
267
|
+
}
|
268
|
+
}
|
269
|
+
|
270
|
+
return returnOpts;
|
271
|
+
}
|
272
|
+
}, {
|
273
|
+
key: 'setupTether',
|
274
|
+
value: function setupTether() {
|
275
|
+
if (isUndefined(Tether)) {
|
276
|
+
throw new Error("Using the attachment feature of Shepherd requires the Tether library");
|
277
|
+
}
|
278
|
+
|
279
|
+
var opts = this.getAttachTo();
|
280
|
+
var attachment = ATTACHMENT[opts.on] || ATTACHMENT.right;
|
281
|
+
if (isUndefined(opts.element)) {
|
282
|
+
opts.element = 'viewport';
|
283
|
+
attachment = 'middle center';
|
284
|
+
}
|
285
|
+
|
286
|
+
var tetherOpts = {
|
287
|
+
classPrefix: 'shepherd',
|
288
|
+
element: this.el,
|
289
|
+
constraints: [{
|
290
|
+
to: 'window',
|
291
|
+
pin: true,
|
292
|
+
attachment: 'together'
|
293
|
+
}],
|
294
|
+
target: opts.element,
|
295
|
+
offset: opts.offset || '0 0',
|
296
|
+
attachment: attachment
|
297
|
+
};
|
298
|
+
|
299
|
+
if (this.tether) {
|
300
|
+
this.tether.destroy();
|
301
|
+
}
|
302
|
+
|
303
|
+
this.tether = new Tether(extend(tetherOpts, this.options.tetherOptions));
|
304
|
+
}
|
305
|
+
}, {
|
306
|
+
key: 'show',
|
307
|
+
value: function show() {
|
308
|
+
var _this3 = this;
|
309
|
+
|
310
|
+
if (!isUndefined(this.options.beforeShowPromise)) {
|
311
|
+
var beforeShowPromise = this.options.beforeShowPromise();
|
312
|
+
if (!isUndefined(beforeShowPromise)) {
|
313
|
+
return beforeShowPromise.then(function () {
|
314
|
+
return _this3._show();
|
315
|
+
});
|
316
|
+
}
|
317
|
+
}
|
318
|
+
this._show();
|
319
|
+
}
|
320
|
+
}, {
|
321
|
+
key: '_show',
|
322
|
+
value: function _show() {
|
323
|
+
var _this4 = this;
|
324
|
+
|
325
|
+
this.trigger('before-show');
|
326
|
+
|
327
|
+
if (!this.el) {
|
328
|
+
this.render();
|
329
|
+
}
|
330
|
+
|
331
|
+
addClass(this.el, 'shepherd-open');
|
332
|
+
|
333
|
+
document.body.setAttribute('data-shepherd-step', this.id);
|
334
|
+
|
335
|
+
this.setupTether();
|
336
|
+
|
337
|
+
if (this.options.scrollTo) {
|
338
|
+
setTimeout(function () {
|
339
|
+
_this4.scrollTo();
|
340
|
+
});
|
341
|
+
}
|
342
|
+
|
343
|
+
this.trigger('show');
|
344
|
+
}
|
345
|
+
}, {
|
346
|
+
key: 'hide',
|
347
|
+
value: function hide() {
|
348
|
+
this.trigger('before-hide');
|
349
|
+
|
350
|
+
removeClass(this.el, 'shepherd-open');
|
351
|
+
|
352
|
+
document.body.removeAttribute('data-shepherd-step');
|
353
|
+
|
354
|
+
if (this.tether) {
|
355
|
+
this.tether.destroy();
|
356
|
+
}
|
357
|
+
this.tether = null;
|
358
|
+
|
359
|
+
this.trigger('hide');
|
360
|
+
}
|
361
|
+
}, {
|
362
|
+
key: 'isOpen',
|
363
|
+
value: function isOpen() {
|
364
|
+
return this.el && hasClass(this.el, 'shepherd-open');
|
365
|
+
}
|
366
|
+
}, {
|
367
|
+
key: 'cancel',
|
368
|
+
value: function cancel() {
|
369
|
+
this.tour.cancel();
|
370
|
+
this.trigger('cancel');
|
371
|
+
}
|
372
|
+
}, {
|
373
|
+
key: 'complete',
|
374
|
+
value: function complete() {
|
375
|
+
this.tour.complete();
|
376
|
+
this.trigger('complete');
|
377
|
+
}
|
378
|
+
}, {
|
379
|
+
key: 'scrollTo',
|
380
|
+
value: function scrollTo() {
|
381
|
+
var _getAttachTo = this.getAttachTo();
|
382
|
+
|
383
|
+
var element = _getAttachTo.element;
|
384
|
+
|
385
|
+
if (!isUndefined(this.options.scrollToHandler)) {
|
386
|
+
this.options.scrollToHandler(element);
|
387
|
+
} else if (!isUndefined(element)) {
|
388
|
+
element.scrollIntoView();
|
389
|
+
}
|
390
|
+
}
|
391
|
+
}, {
|
392
|
+
key: 'destroy',
|
393
|
+
value: function destroy() {
|
394
|
+
if (!isUndefined(this.el) && this.el.parentNode) {
|
395
|
+
this.el.parentNode.removeChild(this.el);
|
396
|
+
delete this.el;
|
397
|
+
}
|
398
|
+
|
399
|
+
if (this.tether) {
|
400
|
+
this.tether.destroy();
|
401
|
+
}
|
402
|
+
this.tether = null;
|
403
|
+
|
404
|
+
this.trigger('destroy');
|
405
|
+
}
|
406
|
+
}, {
|
407
|
+
key: 'render',
|
408
|
+
value: function render() {
|
409
|
+
var _this5 = this;
|
410
|
+
|
411
|
+
if (!isUndefined(this.el)) {
|
412
|
+
this.destroy();
|
413
|
+
}
|
414
|
+
|
415
|
+
this.el = createFromHTML('<div class=\'shepherd-step ' + (this.options.classes || '') + '\' data-id=\'' + this.id + '\' ' + (this.options.idAttribute ? 'id="' + this.options.idAttribute + '"' : '') + '></div>');
|
416
|
+
|
417
|
+
var content = document.createElement('div');
|
418
|
+
content.className = 'shepherd-content';
|
419
|
+
this.el.appendChild(content);
|
420
|
+
|
421
|
+
var header = document.createElement('header');
|
422
|
+
content.appendChild(header);
|
423
|
+
|
424
|
+
if (this.options.title) {
|
425
|
+
header.innerHTML += '<h3 class=\'shepherd-title\'>' + this.options.title + '</h3>';
|
426
|
+
this.el.className += ' shepherd-has-title';
|
427
|
+
}
|
428
|
+
|
429
|
+
if (this.options.showCancelLink) {
|
430
|
+
var link = createFromHTML("<a href class='shepherd-cancel-link'>✕</a>");
|
431
|
+
header.appendChild(link);
|
432
|
+
|
433
|
+
this.el.className += ' shepherd-has-cancel-link';
|
434
|
+
|
435
|
+
this.bindCancelLink(link);
|
436
|
+
}
|
437
|
+
|
438
|
+
if (!isUndefined(this.options.text)) {
|
439
|
+
(function () {
|
440
|
+
var text = createFromHTML("<div class='shepherd-text'></div>");
|
441
|
+
var paragraphs = _this5.options.text;
|
442
|
+
|
443
|
+
if (typeof paragraphs === 'function') {
|
444
|
+
paragraphs = paragraphs.call(_this5, text);
|
445
|
+
}
|
446
|
+
|
447
|
+
if (paragraphs instanceof HTMLElement) {
|
448
|
+
text.appendChild(paragraphs);
|
449
|
+
} else {
|
450
|
+
if (typeof paragraphs === 'string') {
|
451
|
+
paragraphs = [paragraphs];
|
452
|
+
}
|
453
|
+
|
454
|
+
paragraphs.map(function (paragraph) {
|
455
|
+
text.innerHTML += '<p>' + paragraph + '</p>';
|
456
|
+
});
|
457
|
+
}
|
458
|
+
|
459
|
+
content.appendChild(text);
|
460
|
+
})();
|
461
|
+
}
|
462
|
+
|
463
|
+
if (this.options.buttons) {
|
464
|
+
(function () {
|
465
|
+
var footer = document.createElement('footer');
|
466
|
+
var buttons = createFromHTML("<ul class='shepherd-buttons'></ul>");
|
467
|
+
|
468
|
+
_this5.options.buttons.map(function (cfg) {
|
469
|
+
var button = createFromHTML('<li><a class=\'shepherd-button ' + (cfg.classes || '') + '\'>' + cfg.text + '</a>');
|
470
|
+
buttons.appendChild(button);
|
471
|
+
_this5.bindButtonEvents(cfg, button.querySelector('a'));
|
472
|
+
});
|
473
|
+
|
474
|
+
footer.appendChild(buttons);
|
475
|
+
content.appendChild(footer);
|
476
|
+
})();
|
477
|
+
}
|
478
|
+
|
479
|
+
document.body.appendChild(this.el);
|
480
|
+
|
481
|
+
this.setupTether();
|
482
|
+
|
483
|
+
if (this.options.advanceOn) {
|
484
|
+
this.bindAdvance();
|
485
|
+
}
|
486
|
+
}
|
487
|
+
}, {
|
488
|
+
key: 'bindCancelLink',
|
489
|
+
value: function bindCancelLink(link) {
|
490
|
+
var _this6 = this;
|
491
|
+
|
492
|
+
link.addEventListener('click', function (e) {
|
493
|
+
e.preventDefault();
|
494
|
+
_this6.cancel();
|
495
|
+
});
|
496
|
+
}
|
497
|
+
}, {
|
498
|
+
key: 'bindButtonEvents',
|
499
|
+
value: function bindButtonEvents(cfg, el) {
|
500
|
+
var _this7 = this;
|
501
|
+
|
502
|
+
cfg.events = cfg.events || {};
|
503
|
+
if (!isUndefined(cfg.action)) {
|
504
|
+
// Including both a click event and an action is not supported
|
505
|
+
cfg.events.click = cfg.action;
|
506
|
+
}
|
507
|
+
|
508
|
+
for (var _event2 in cfg.events) {
|
509
|
+
if (({}).hasOwnProperty.call(cfg.events, _event2)) {
|
510
|
+
var handler = cfg.events[_event2];
|
511
|
+
if (typeof handler === 'string') {
|
512
|
+
(function () {
|
513
|
+
var page = handler;
|
514
|
+
handler = function () {
|
515
|
+
return _this7.tour.show(page);
|
516
|
+
};
|
517
|
+
})();
|
518
|
+
}
|
519
|
+
el.addEventListener(_event2, handler);
|
520
|
+
}
|
521
|
+
}
|
522
|
+
|
523
|
+
this.on('destroy', function () {
|
524
|
+
for (var _event3 in cfg.events) {
|
525
|
+
if (({}).hasOwnProperty.call(cfg.events, _event3)) {
|
526
|
+
var handler = cfg.events[_event3];
|
527
|
+
el.removeEventListener(_event3, handler);
|
528
|
+
}
|
529
|
+
}
|
530
|
+
});
|
531
|
+
}
|
532
|
+
}]);
|
533
|
+
|
534
|
+
return Step;
|
535
|
+
})(Evented);
|
536
|
+
|
537
|
+
var Tour = (function (_Evented2) {
|
538
|
+
_inherits(Tour, _Evented2);
|
539
|
+
|
540
|
+
function Tour() {
|
541
|
+
var _this8 = this;
|
542
|
+
|
543
|
+
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
544
|
+
|
545
|
+
_classCallCheck(this, Tour);
|
546
|
+
|
547
|
+
_get(Object.getPrototypeOf(Tour.prototype), 'constructor', this).call(this, options);
|
548
|
+
this.bindMethods();
|
549
|
+
this.options = options;
|
550
|
+
this.steps = this.options.steps || [];
|
551
|
+
|
552
|
+
// Pass these events onto the global Shepherd object
|
553
|
+
var events = ['complete', 'cancel', 'hide', 'start', 'show', 'active', 'inactive'];
|
554
|
+
events.map(function (event) {
|
555
|
+
(function (e) {
|
556
|
+
_this8.on(e, function (opts) {
|
557
|
+
opts = opts || {};
|
558
|
+
opts.tour = _this8;
|
559
|
+
Shepherd.trigger(e, opts);
|
560
|
+
});
|
561
|
+
})(event);
|
562
|
+
});
|
563
|
+
|
564
|
+
return this;
|
565
|
+
}
|
566
|
+
|
567
|
+
_createClass(Tour, [{
|
568
|
+
key: 'bindMethods',
|
569
|
+
value: function bindMethods() {
|
570
|
+
var _this9 = this;
|
571
|
+
|
572
|
+
var methods = ['next', 'back', 'cancel', 'complete', 'hide'];
|
573
|
+
methods.map(function (method) {
|
574
|
+
_this9[method] = _this9[method].bind(_this9);
|
575
|
+
});
|
576
|
+
}
|
577
|
+
}, {
|
578
|
+
key: 'addStep',
|
579
|
+
value: function addStep(name, step) {
|
580
|
+
if (isUndefined(step)) {
|
581
|
+
step = name;
|
582
|
+
}
|
583
|
+
|
584
|
+
if (!(step instanceof Step)) {
|
585
|
+
if (typeof name === 'string' || typeof name === 'number') {
|
586
|
+
step.id = name.toString();
|
587
|
+
}
|
588
|
+
step = extend({}, this.options.defaults, step);
|
589
|
+
step = new Step(this, step);
|
590
|
+
} else {
|
591
|
+
step.tour = this;
|
592
|
+
}
|
593
|
+
|
594
|
+
this.steps.push(step);
|
595
|
+
return this;
|
596
|
+
}
|
597
|
+
}, {
|
598
|
+
key: 'removeStep',
|
599
|
+
value: function removeStep(name) {
|
600
|
+
var current = this.getCurrentStep();
|
601
|
+
|
602
|
+
for (var i = 0; i < this.steps.length; ++i) {
|
603
|
+
var step = this.steps[i];
|
604
|
+
if (step.id === name) {
|
605
|
+
if (step.isOpen()) {
|
606
|
+
step.hide();
|
607
|
+
}
|
608
|
+
step.destroy();
|
609
|
+
this.steps.splice(i, 1);
|
610
|
+
break;
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
if (current && current.id === name) {
|
615
|
+
this.currentStep = undefined;
|
616
|
+
|
617
|
+
if (this.steps.length) this.show(0);else this.hide();
|
618
|
+
}
|
619
|
+
}
|
620
|
+
}, {
|
621
|
+
key: 'getById',
|
622
|
+
value: function getById(id) {
|
623
|
+
for (var i = 0; i < this.steps.length; ++i) {
|
624
|
+
var step = this.steps[i];
|
625
|
+
if (step.id === id) {
|
626
|
+
return step;
|
627
|
+
}
|
628
|
+
}
|
629
|
+
}
|
630
|
+
}, {
|
631
|
+
key: 'getCurrentStep',
|
632
|
+
value: function getCurrentStep() {
|
633
|
+
return this.currentStep;
|
634
|
+
}
|
635
|
+
}, {
|
636
|
+
key: 'next',
|
637
|
+
value: function next() {
|
638
|
+
var index = this.steps.indexOf(this.currentStep);
|
639
|
+
|
640
|
+
if (index === this.steps.length - 1) {
|
641
|
+
this.hide(index);
|
642
|
+
this.trigger('complete');
|
643
|
+
this.done();
|
644
|
+
} else {
|
645
|
+
this.show(index + 1, true);
|
646
|
+
}
|
647
|
+
}
|
648
|
+
}, {
|
649
|
+
key: 'back',
|
650
|
+
value: function back() {
|
651
|
+
var index = this.steps.indexOf(this.currentStep);
|
652
|
+
this.show(index - 1, false);
|
653
|
+
}
|
654
|
+
}, {
|
655
|
+
key: 'cancel',
|
656
|
+
value: function cancel() {
|
657
|
+
if (this.currentStep) {
|
658
|
+
this.currentStep.hide();
|
659
|
+
}
|
660
|
+
this.trigger('cancel');
|
661
|
+
this.done();
|
662
|
+
}
|
663
|
+
}, {
|
664
|
+
key: 'complete',
|
665
|
+
value: function complete() {
|
666
|
+
if (this.currentStep) {
|
667
|
+
this.currentStep.hide();
|
668
|
+
}
|
669
|
+
this.trigger('complete');
|
670
|
+
this.done();
|
671
|
+
}
|
672
|
+
}, {
|
673
|
+
key: 'hide',
|
674
|
+
value: function hide() {
|
675
|
+
if (this.currentStep) {
|
676
|
+
this.currentStep.hide();
|
677
|
+
}
|
678
|
+
this.trigger('hide');
|
679
|
+
this.done();
|
680
|
+
}
|
681
|
+
}, {
|
682
|
+
key: 'done',
|
683
|
+
value: function done() {
|
684
|
+
Shepherd.activeTour = null;
|
685
|
+
removeClass(document.body, 'shepherd-active');
|
686
|
+
this.trigger('inactive', { tour: this });
|
687
|
+
}
|
688
|
+
}, {
|
689
|
+
key: 'show',
|
690
|
+
value: function show() {
|
691
|
+
var key = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0];
|
692
|
+
var forward = arguments.length <= 1 || arguments[1] === undefined ? true : arguments[1];
|
693
|
+
|
694
|
+
if (this.currentStep) {
|
695
|
+
this.currentStep.hide();
|
696
|
+
} else {
|
697
|
+
addClass(document.body, 'shepherd-active');
|
698
|
+
this.trigger('active', { tour: this });
|
699
|
+
}
|
700
|
+
|
701
|
+
Shepherd.activeTour = this;
|
702
|
+
|
703
|
+
var next = undefined;
|
704
|
+
|
705
|
+
if (typeof key === 'string') {
|
706
|
+
next = this.getById(key);
|
707
|
+
} else {
|
708
|
+
next = this.steps[key];
|
709
|
+
}
|
710
|
+
|
711
|
+
if (next) {
|
712
|
+
if (!isUndefined(next.options.showOn) && !next.options.showOn()) {
|
713
|
+
var index = this.steps.indexOf(next);
|
714
|
+
var nextIndex = forward ? index + 1 : index - 1;
|
715
|
+
this.show(nextIndex, forward);
|
716
|
+
} else {
|
717
|
+
this.trigger('show', {
|
718
|
+
step: next,
|
719
|
+
previous: this.currentStep
|
720
|
+
});
|
721
|
+
|
722
|
+
if (this.currentStep) {
|
723
|
+
this.currentStep.hide();
|
724
|
+
}
|
725
|
+
|
726
|
+
this.currentStep = next;
|
727
|
+
next.show();
|
728
|
+
}
|
729
|
+
}
|
730
|
+
}
|
731
|
+
}, {
|
732
|
+
key: 'start',
|
733
|
+
value: function start() {
|
734
|
+
this.trigger('start');
|
735
|
+
|
736
|
+
this.currentStep = null;
|
737
|
+
this.next();
|
738
|
+
}
|
739
|
+
}]);
|
740
|
+
|
741
|
+
return Tour;
|
742
|
+
})(Evented);
|
743
|
+
|
744
|
+
extend(Shepherd, { Tour: Tour, Step: Step, Evented: Evented });
|
745
|
+
return Shepherd;
|
746
|
+
|
747
|
+
}));
|