title-switcher 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -150
- package/browser/titleSwitcher.js +154 -199
- package/browser/titleSwitcher.min.js +1 -1
- package/dist/main.d.ts +90 -0
- package/dist/main.js +154 -199
- package/dist/main.min.js +1 -1
- package/package.json +10 -2
package/browser/titleSwitcher.js
CHANGED
|
@@ -2,24 +2,14 @@
|
|
|
2
2
|
1: [function (require, module, exports) {
|
|
3
3
|
'use strict'
|
|
4
4
|
|
|
5
|
-
// Created by Joshua Heagle
|
|
6
|
-
|
|
7
|
-
/*********************************************
|
|
8
|
-
Title Switcher: to imitate typing and switch to different titles based on DOM.
|
|
9
|
-
Requires titles to be listed as elements inside a div, pass the class of the div as an argument to TitleSwitcher.
|
|
10
|
-
**********************************************/
|
|
11
5
|
require('core-js/modules/es.symbol.to-primitive.js')
|
|
12
6
|
require('core-js/modules/es.date.to-primitive.js')
|
|
13
7
|
require('core-js/modules/es.symbol.js')
|
|
14
8
|
require('core-js/modules/es.symbol.description.js')
|
|
15
9
|
require('core-js/modules/es.number.constructor.js')
|
|
16
|
-
require('core-js/modules/es.object.define-property.js')
|
|
17
10
|
require('core-js/modules/es.symbol.iterator.js')
|
|
18
11
|
function _typeof (o) { '@babel/helpers - typeof'; return _typeof = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? function (o) { return typeof o } : function (o) { return o && typeof Symbol === 'function' && o.constructor === Symbol && o !== Symbol.prototype ? 'symbol' : typeof o }, _typeof(o) }
|
|
19
|
-
|
|
20
|
-
value: true
|
|
21
|
-
})
|
|
22
|
-
exports.default = void 0
|
|
12
|
+
require('core-js/modules/es.object.define-property.js')
|
|
23
13
|
require('core-js/modules/es.regexp.exec.js')
|
|
24
14
|
require('core-js/modules/es.string.replace.js')
|
|
25
15
|
require('core-js/modules/es.regexp.constructor.js')
|
|
@@ -29,189 +19,153 @@
|
|
|
29
19
|
require('core-js/modules/es.array.for-each.js')
|
|
30
20
|
require('core-js/modules/es.object.to-string.js')
|
|
31
21
|
require('core-js/modules/es.string.trim.js')
|
|
32
|
-
require('core-js/modules/web.timers.js')
|
|
33
|
-
require('core-js/modules/esnext.async-iterator.for-each.js')
|
|
34
|
-
require('core-js/modules/esnext.iterator.constructor.js')
|
|
35
|
-
require('core-js/modules/esnext.iterator.for-each.js')
|
|
36
|
-
require('core-js/modules/web.dom-collections.for-each.js')
|
|
37
22
|
require('core-js/modules/es.array.iterator.js')
|
|
38
23
|
require('core-js/modules/es.string.iterator.js')
|
|
39
24
|
require('core-js/modules/es.weak-map.js')
|
|
40
25
|
require('core-js/modules/esnext.weak-map.delete-all.js')
|
|
41
26
|
require('core-js/modules/web.dom-collections.iterator.js')
|
|
27
|
+
require('core-js/modules/web.timers.js')
|
|
28
|
+
require('core-js/modules/esnext.async-iterator.for-each.js')
|
|
29
|
+
require('core-js/modules/esnext.iterator.constructor.js')
|
|
30
|
+
require('core-js/modules/esnext.iterator.for-each.js')
|
|
31
|
+
require('core-js/modules/web.dom-collections.for-each.js')
|
|
42
32
|
var _this = void 0
|
|
43
33
|
function _classCallCheck (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function') } }
|
|
44
34
|
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, _toPropertyKey(descriptor.key), descriptor) } }
|
|
45
35
|
function _createClass (Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, 'prototype', { writable: false }); return Constructor }
|
|
46
36
|
function _toPropertyKey (arg) { var key = _toPrimitive(arg, 'string'); return _typeof(key) === 'symbol' ? key : String(key) }
|
|
47
37
|
function _toPrimitive (input, hint) { if (_typeof(input) !== 'object' || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || 'default'); if (_typeof(res) !== 'object') return res; throw new TypeError('@@toPrimitive must return a primitive value.') } return (hint === 'string' ? String : Number)(input) }
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
var _titlesContainer = /* #__PURE__ */new WeakMap()
|
|
64
|
-
var _typeSurface = /* #__PURE__ */new WeakMap()
|
|
38
|
+
var __classPrivateFieldSet = void 0 && (void 0).__classPrivateFieldSet || function (receiver, state, value, kind, f) {
|
|
39
|
+
if (kind === 'm') throw new TypeError('Private method is not writable')
|
|
40
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a setter')
|
|
41
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver)) throw new TypeError('Cannot write private member to an object whose class did not declare it')
|
|
42
|
+
return kind === 'a' ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value
|
|
43
|
+
}
|
|
44
|
+
var __classPrivateFieldGet = void 0 && (void 0).__classPrivateFieldGet || function (receiver, state, kind, f) {
|
|
45
|
+
if (kind === 'a' && !f) throw new TypeError('Private accessor was defined without a getter')
|
|
46
|
+
if (typeof state === 'function' ? receiver !== state || !f : !state.has(receiver)) throw new TypeError('Cannot read private member from an object whose class did not declare it')
|
|
47
|
+
return kind === 'm' ? f : kind === 'a' ? f.call(receiver) : f ? f.value : state.get(receiver)
|
|
48
|
+
}
|
|
49
|
+
var _TitleSwitcher_active, _TitleSwitcher_currentClass, _TitleSwitcher_currentIndex, _TitleSwitcher_delayEffect, _TitleSwitcher_delaySwitch, _TitleSwitcher_isRandom, _TitleSwitcher_titles, _TitleSwitcher_titlesContainer, _TitleSwitcher_switchStyle, _TitleSwitcher_typeSurface
|
|
50
|
+
Object.defineProperty(exports, '__esModule', {
|
|
51
|
+
value: true
|
|
52
|
+
})
|
|
65
53
|
var TitleSwitcher = /* #__PURE__ */(function () {
|
|
66
|
-
/**
|
|
67
|
-
* Instantiate this as a class to get an instance of TitleSwitcher
|
|
68
|
-
* @param {string} [titlesContainer=''] - The selector where titles are stored
|
|
69
|
-
* @param {Function|string} [switchStyle='typingEffect'] - The function or function name for the effect to apply
|
|
70
|
-
* @constructor
|
|
54
|
+
/**
|
|
55
|
+
* Instantiate this as a class to get an instance of TitleSwitcher
|
|
56
|
+
* @param {string} [titlesContainer=''] - The selector where titles are stored
|
|
57
|
+
* @param {Function|string} [switchStyle='typingEffect'] - The function or function name for the effect to apply
|
|
58
|
+
* @constructor
|
|
71
59
|
*/
|
|
72
60
|
function TitleSwitcher () {
|
|
73
61
|
var titlesContainer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ''
|
|
74
62
|
var switchStyle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'typingEffect'
|
|
75
63
|
_classCallCheck(this, TitleSwitcher)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
})
|
|
96
|
-
_classPrivateFieldInitSpec(this, _isRandom, {
|
|
97
|
-
writable: true,
|
|
98
|
-
value: false
|
|
99
|
-
})
|
|
100
|
-
_classPrivateFieldInitSpec(this, _switchStyle, {
|
|
101
|
-
writable: true,
|
|
102
|
-
value: 'typingEffect'
|
|
103
|
-
})
|
|
104
|
-
_classPrivateFieldInitSpec(this, _titles, {
|
|
105
|
-
writable: true,
|
|
106
|
-
value: []
|
|
107
|
-
})
|
|
108
|
-
_classPrivateFieldInitSpec(this, _titlesContainer, {
|
|
109
|
-
writable: true,
|
|
110
|
-
value: null
|
|
111
|
-
})
|
|
112
|
-
_classPrivateFieldInitSpec(this, _typeSurface, {
|
|
113
|
-
writable: true,
|
|
114
|
-
value: void 0
|
|
115
|
-
})
|
|
116
|
-
_classPrivateFieldSet(this, _currentClass, 'displayTitle')
|
|
117
|
-
_classPrivateFieldSet(this, _switchStyle, this[typeof this[switchStyle] === 'function' ? switchStyle : 'typingEffect'])
|
|
118
|
-
_classPrivateFieldSet(this, _titlesContainer, titlesContainer)
|
|
119
|
-
_classPrivateFieldSet(this, _titles, [])
|
|
64
|
+
_TitleSwitcher_active.set(this, false)
|
|
65
|
+
_TitleSwitcher_currentClass.set(this, 'displayTitle')
|
|
66
|
+
_TitleSwitcher_currentIndex.set(this, 0)
|
|
67
|
+
_TitleSwitcher_delayEffect.set(this, 200)
|
|
68
|
+
_TitleSwitcher_delaySwitch.set(this, 400)
|
|
69
|
+
_TitleSwitcher_isRandom.set(this, false)
|
|
70
|
+
_TitleSwitcher_titles.set(this, [])
|
|
71
|
+
_TitleSwitcher_titlesContainer.set(this, null)
|
|
72
|
+
_TitleSwitcher_switchStyle.set(this, void 0)
|
|
73
|
+
_TitleSwitcher_typeSurface.set(this, void 0)
|
|
74
|
+
__classPrivateFieldSet(this, _TitleSwitcher_currentClass, 'displayTitle', 'f')
|
|
75
|
+
if (typeof switchStyle === 'string') {
|
|
76
|
+
// @ts-ignore Obnoxious error "type 'string' can't be used to index type 'TitleSwitcher'"
|
|
77
|
+
__classPrivateFieldSet(this, _TitleSwitcher_switchStyle, typeof this[switchStyle] === 'function' ? this[switchStyle] : this.typingEffect, 'f')
|
|
78
|
+
} else {
|
|
79
|
+
__classPrivateFieldSet(this, _TitleSwitcher_switchStyle, switchStyle, 'f')
|
|
80
|
+
}
|
|
81
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titlesContainer, null, 'f')
|
|
82
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titles, [], 'f')
|
|
120
83
|
var foundContainers = titlesContainer ? document.querySelectorAll(titlesContainer) : []
|
|
121
84
|
if (foundContainers && foundContainers[0]) {
|
|
122
|
-
|
|
123
|
-
|
|
85
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titlesContainer, foundContainers[0], 'f')
|
|
86
|
+
__classPrivateFieldSet(this, _TitleSwitcher_titles, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').children, 'f')
|
|
124
87
|
}
|
|
125
88
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
*
|
|
129
|
-
* @return {boolean}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieve active
|
|
91
|
+
* @return {boolean}
|
|
130
92
|
*/
|
|
131
93
|
_createClass(TitleSwitcher, [{
|
|
132
94
|
key: 'active',
|
|
133
95
|
get: function get () {
|
|
134
|
-
return
|
|
96
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_active, 'f')
|
|
135
97
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
* @return {string}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieve currentClass
|
|
100
|
+
* @return {string}
|
|
140
101
|
*/
|
|
141
102
|
}, {
|
|
142
103
|
key: 'currentClass',
|
|
143
104
|
get: function get () {
|
|
144
|
-
return
|
|
105
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f')
|
|
145
106
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
*
|
|
149
|
-
* @return {number}
|
|
107
|
+
/**
|
|
108
|
+
* Retrieve currentIndex
|
|
109
|
+
* @return {number}
|
|
150
110
|
*/
|
|
151
111
|
}, {
|
|
152
112
|
key: 'currentIndex',
|
|
153
113
|
get: function get () {
|
|
154
|
-
return
|
|
114
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')
|
|
155
115
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
*
|
|
159
|
-
* @return {number}
|
|
116
|
+
/**
|
|
117
|
+
* Retrieve delayEffect
|
|
118
|
+
* @return {number}
|
|
160
119
|
*/
|
|
161
120
|
}, {
|
|
162
121
|
key: 'delayEffect',
|
|
163
122
|
get: function get () {
|
|
164
|
-
return
|
|
123
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_delayEffect, 'f')
|
|
165
124
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
* @return {number}
|
|
125
|
+
/**
|
|
126
|
+
* Retrieve delaySwitch
|
|
127
|
+
* @return {number}
|
|
170
128
|
*/
|
|
171
129
|
}, {
|
|
172
130
|
key: 'delaySwitch',
|
|
173
131
|
get: function get () {
|
|
174
|
-
return
|
|
132
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_delaySwitch, 'f')
|
|
175
133
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
* @return {string}
|
|
134
|
+
/**
|
|
135
|
+
* Retrieve switchStyle
|
|
136
|
+
* @return {Function}
|
|
180
137
|
*/
|
|
181
138
|
}, {
|
|
182
139
|
key: 'switchStyle',
|
|
183
140
|
get: function get () {
|
|
184
|
-
return
|
|
141
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f')
|
|
185
142
|
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*
|
|
189
|
-
* @return {Array|NodeList}
|
|
143
|
+
/**
|
|
144
|
+
* Retrieve list of titles DOM elements
|
|
145
|
+
* @return {Array<HTMLElement>|HTMLCollection}
|
|
190
146
|
*/
|
|
191
147
|
}, {
|
|
192
148
|
key: 'titles',
|
|
193
149
|
get: function get () {
|
|
194
|
-
return
|
|
150
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')
|
|
195
151
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
*
|
|
199
|
-
* @return {HTMLElement|null}
|
|
152
|
+
/**
|
|
153
|
+
* Retrieve typeSurface used
|
|
154
|
+
* @return {HTMLElement|null}
|
|
200
155
|
*/
|
|
201
156
|
}, {
|
|
202
157
|
key: 'typeSurface',
|
|
203
158
|
get: function get () {
|
|
204
|
-
return
|
|
159
|
+
return __classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f')
|
|
205
160
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
*
|
|
209
|
-
* @param {
|
|
210
|
-
* @param {number} [settings.
|
|
211
|
-
* @param {
|
|
212
|
-
* @param {boolean} [settings.
|
|
213
|
-
* @
|
|
214
|
-
* @returns {TitleSwitcher}
|
|
161
|
+
/**
|
|
162
|
+
* This is the function to begin the switching titles
|
|
163
|
+
* @param {Object} [settings={}]
|
|
164
|
+
* @param {number} [settings.delaySwitch=400]
|
|
165
|
+
* @param {number} [settings.delayEffect=200]
|
|
166
|
+
* @param {boolean} [settings.isRandom=false]
|
|
167
|
+
* @param {boolean} [settings.immediatePause=false]
|
|
168
|
+
* @returns {TitleSwitcher}
|
|
215
169
|
*/
|
|
216
170
|
}, {
|
|
217
171
|
key: 'startTitles',
|
|
@@ -226,73 +180,72 @@
|
|
|
226
180
|
var _ref$immediatePause = _ref.immediatePause
|
|
227
181
|
var immediatePause = _ref$immediatePause === void 0 ? false : _ref$immediatePause
|
|
228
182
|
var typeSurface = 'typeSurface'
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
|
|
235
|
-
console.warn("No titles found for '".concat(
|
|
183
|
+
__classPrivateFieldSet(this, _TitleSwitcher_delaySwitch, delaySwitch, 'f')
|
|
184
|
+
__classPrivateFieldSet(this, _TitleSwitcher_delayEffect, delayEffect, 'f')
|
|
185
|
+
__classPrivateFieldSet(this, _TitleSwitcher_isRandom, isRandom, 'f')
|
|
186
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, !immediatePause, 'f')
|
|
187
|
+
if (__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f') >= __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f').length) {
|
|
188
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, false, 'f')
|
|
189
|
+
console.warn("No titles found for '".concat(__classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f'), "'"))
|
|
236
190
|
return this
|
|
237
191
|
}
|
|
238
|
-
if (
|
|
239
|
-
|
|
192
|
+
if (__classPrivateFieldGet(this, _TitleSwitcher_isRandom, 'f')) {
|
|
193
|
+
__classPrivateFieldSet(this, _TitleSwitcher_currentIndex, Math.round(Math.random() * (__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f').length - 2)) + 1, 'f')
|
|
240
194
|
}
|
|
241
|
-
var currentTitle =
|
|
195
|
+
var currentTitle = __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')]
|
|
242
196
|
if (currentTitle.classList) {
|
|
243
|
-
currentTitle.classList.add(
|
|
197
|
+
currentTitle.classList.add(__classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f'))
|
|
244
198
|
} else {
|
|
245
|
-
currentTitle.className += ' ' +
|
|
199
|
+
currentTitle.className += ' ' + __classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f')
|
|
246
200
|
}
|
|
247
|
-
|
|
201
|
+
// @ts-ignore The Node returned is of type Element, or it should be
|
|
202
|
+
var typeElement = __classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[0].cloneNode(true)
|
|
248
203
|
if (typeElement.classList) {
|
|
249
204
|
typeElement.classList.add(typeSurface)
|
|
250
205
|
} else {
|
|
251
206
|
typeElement.className += ' ' + typeSurface
|
|
252
207
|
}
|
|
253
208
|
if (typeElement.classList) {
|
|
254
|
-
typeElement.classList.remove(
|
|
209
|
+
typeElement.classList.remove(__classPrivateFieldGet(this, _TitleSwitcher_currentClass, 'f'))
|
|
255
210
|
} else {
|
|
256
211
|
typeElement.className = typeElement.className.replace(new RegExp('(^|\\b)' + typeElement.className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ')
|
|
257
212
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
213
|
+
__classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').insertBefore(typeElement, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').firstChild)
|
|
214
|
+
// @ts-ignore the returned Node is a type of HTMLElement
|
|
215
|
+
__classPrivateFieldSet(this, _TitleSwitcher_typeSurface, __classPrivateFieldGet(this, _TitleSwitcher_titlesContainer, 'f').querySelectorAll('.' + typeSurface)[0], 'f')
|
|
216
|
+
__classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f').innerHTML = ''
|
|
217
|
+
__classPrivateFieldGet(this, _TitleSwitcher_typeSurface, 'f').style.display = 'block'
|
|
218
|
+
Array.prototype.forEach.call(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f'), function (title) {
|
|
263
219
|
title.style.display = 'none'
|
|
264
220
|
})
|
|
265
|
-
return this.switchTitle(
|
|
221
|
+
return this.switchTitle(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')], __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f'), this)
|
|
266
222
|
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
* This is the function to pause between switching
|
|
223
|
+
/**
|
|
224
|
+
* This is the function to pause between switching
|
|
270
225
|
*/
|
|
271
226
|
}, {
|
|
272
227
|
key: 'pause',
|
|
273
228
|
value: function pause () {
|
|
274
|
-
|
|
229
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, false, 'f')
|
|
275
230
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
* This is the function to resume after a pause.
|
|
231
|
+
/**
|
|
232
|
+
* This is the function to resume after a pause.
|
|
279
233
|
*/
|
|
280
234
|
}, {
|
|
281
235
|
key: 'resume',
|
|
282
236
|
value: function resume () {
|
|
283
|
-
if (!
|
|
284
|
-
|
|
285
|
-
this.switchTitle(
|
|
237
|
+
if (!__classPrivateFieldGet(this, _TitleSwitcher_active, 'f')) {
|
|
238
|
+
__classPrivateFieldSet(this, _TitleSwitcher_active, true, 'f')
|
|
239
|
+
this.switchTitle(__classPrivateFieldGet(this, _TitleSwitcher_titles, 'f')[__classPrivateFieldGet(this, _TitleSwitcher_currentIndex, 'f')], __classPrivateFieldGet(this, _TitleSwitcher_switchStyle, 'f'), this)
|
|
286
240
|
}
|
|
287
241
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
*
|
|
291
|
-
* @param {
|
|
292
|
-
* @param {
|
|
293
|
-
* @param {
|
|
294
|
-
* @
|
|
295
|
-
* @returns {TitleSwitcher}
|
|
242
|
+
/**
|
|
243
|
+
* This is the core function for switching titles
|
|
244
|
+
* @param {HTMLElement} currentTitle
|
|
245
|
+
* @param {Function} callBackFunction
|
|
246
|
+
* @param {TitleSwitcher} self
|
|
247
|
+
* @param {boolean} [runOnce=false]
|
|
248
|
+
* @returns {TitleSwitcher}
|
|
296
249
|
*/
|
|
297
250
|
}, {
|
|
298
251
|
key: 'switchTitle',
|
|
@@ -300,23 +253,25 @@
|
|
|
300
253
|
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false
|
|
301
254
|
self = self || this
|
|
302
255
|
var currentIndex = 1
|
|
303
|
-
var size =
|
|
256
|
+
var size = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f').length
|
|
304
257
|
for (var i = 1; i < size; ++i) {
|
|
305
|
-
if (
|
|
258
|
+
if (__classPrivateFieldGet(self, _TitleSwitcher_titles, 'f')[i] === currentTitle) {
|
|
306
259
|
currentIndex = i
|
|
307
260
|
break
|
|
308
261
|
}
|
|
309
262
|
}
|
|
310
|
-
if (!
|
|
311
|
-
|
|
263
|
+
if (!__classPrivateFieldGet(self, _TitleSwitcher_active, 'f')) {
|
|
264
|
+
__classPrivateFieldSet(self, _TitleSwitcher_currentIndex, currentIndex, 'f')
|
|
312
265
|
return self
|
|
313
266
|
}
|
|
314
|
-
var maxIndex =
|
|
267
|
+
var maxIndex = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f').length - 1
|
|
315
268
|
var nextIndex = 1
|
|
316
269
|
if (maxIndex === 1) {
|
|
317
|
-
return callBackFunction(currentTitle,
|
|
270
|
+
return callBackFunction(currentTitle, runOnce ? function () {
|
|
271
|
+
return self
|
|
272
|
+
} : self.switchTitle, self, runOnce)
|
|
318
273
|
}
|
|
319
|
-
if (
|
|
274
|
+
if (__classPrivateFieldGet(self, _TitleSwitcher_isRandom, 'f')) {
|
|
320
275
|
if (!self.typeSurface.textContent.trim()) {
|
|
321
276
|
currentIndex = -1
|
|
322
277
|
}
|
|
@@ -329,7 +284,7 @@
|
|
|
329
284
|
}
|
|
330
285
|
nextIndex = currentIndex < maxIndex ? currentIndex + 1 : 1
|
|
331
286
|
}
|
|
332
|
-
var nextTitle =
|
|
287
|
+
var nextTitle = __classPrivateFieldGet(self, _TitleSwitcher_titles, 'f')[nextIndex]
|
|
333
288
|
if (currentTitle.classList) {
|
|
334
289
|
currentTitle.classList.remove(self.currentClass)
|
|
335
290
|
} else {
|
|
@@ -341,17 +296,18 @@
|
|
|
341
296
|
nextTitle.className += ' ' + self.currentClass
|
|
342
297
|
}
|
|
343
298
|
return callBackFunction(nextTitle, runOnce ? function () {
|
|
344
|
-
return
|
|
299
|
+
return self
|
|
345
300
|
} : self.switchTitle, self, runOnce)
|
|
346
301
|
}
|
|
347
302
|
}])
|
|
348
303
|
return TitleSwitcher
|
|
349
304
|
}())
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
*
|
|
353
|
-
* @param {
|
|
354
|
-
* @
|
|
305
|
+
_TitleSwitcher_active = new WeakMap(), _TitleSwitcher_currentClass = new WeakMap(), _TitleSwitcher_currentIndex = new WeakMap(), _TitleSwitcher_delayEffect = new WeakMap(), _TitleSwitcher_delaySwitch = new WeakMap(), _TitleSwitcher_isRandom = new WeakMap(), _TitleSwitcher_titles = new WeakMap(), _TitleSwitcher_titlesContainer = new WeakMap(), _TitleSwitcher_switchStyle = new WeakMap(), _TitleSwitcher_typeSurface = new WeakMap()
|
|
306
|
+
/**
|
|
307
|
+
* This is a helper function to improve the default 'typingEffect'
|
|
308
|
+
* @param {boolean} blinkOn
|
|
309
|
+
* @param {TitleSwitcher} self
|
|
310
|
+
* @return {TitleSwitcher}
|
|
355
311
|
*/
|
|
356
312
|
TitleSwitcher.prototype.cursorBlink = function (blinkOn, self) {
|
|
357
313
|
// display cursor effect
|
|
@@ -364,16 +320,15 @@
|
|
|
364
320
|
}
|
|
365
321
|
return self
|
|
366
322
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* @param {
|
|
373
|
-
* @param {
|
|
374
|
-
* @param {
|
|
375
|
-
* @
|
|
376
|
-
* @returns {TitleSwitcher}
|
|
323
|
+
/**
|
|
324
|
+
* This is the default and example of an effect being implemented when Titles are switched
|
|
325
|
+
* These functions take the currentElement in focus, the switchTitle function as a callback
|
|
326
|
+
* and an instance of the TitleSwitcher
|
|
327
|
+
* @param {HTMLElement} domObject
|
|
328
|
+
* @param {Function} callBackFunction
|
|
329
|
+
* @param {TitleSwitcher} self
|
|
330
|
+
* @param {boolean} [runOnce=false]
|
|
331
|
+
* @returns {TitleSwitcher}
|
|
377
332
|
*/
|
|
378
333
|
TitleSwitcher.prototype.typingEffect = function (domObject, callBackFunction, self) {
|
|
379
334
|
var runOnce = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false
|
|
@@ -387,7 +342,6 @@
|
|
|
387
342
|
}
|
|
388
343
|
}
|
|
389
344
|
domObject = domObject || self.titles[currentIndex + 1]
|
|
390
|
-
callBackFunction = callBackFunction || self.switchStyle
|
|
391
345
|
var blinkOn = true
|
|
392
346
|
var numBlinks = 4
|
|
393
347
|
if (self.typeSurface.hasAttribute('style')) {
|
|
@@ -399,7 +353,6 @@
|
|
|
399
353
|
// If we copied the title style, then display:none is set, so we need to ensure the surface is display:block
|
|
400
354
|
self.typeSurface.innerHTML = ''
|
|
401
355
|
self.typeSurface.style.display = 'block'
|
|
402
|
-
|
|
403
356
|
// Initialize with a few cursor blinks
|
|
404
357
|
for (var _i = 0; _i < numBlinks; ++_i) {
|
|
405
358
|
setTimeout(function () {
|
|
@@ -427,7 +380,7 @@
|
|
|
427
380
|
self.cursorBlink(blinkOn, self)
|
|
428
381
|
if (_j === 0) {
|
|
429
382
|
callBackFunction(domObject, function () {
|
|
430
|
-
return
|
|
383
|
+
return self
|
|
431
384
|
}, self, runOnce)
|
|
432
385
|
// callBackFunction(domObject, runOnce ? () => null : self.switchStyle, self, runOnce)
|
|
433
386
|
}
|
|
@@ -443,10 +396,12 @@
|
|
|
443
396
|
}, numBlinks * self.delaySwitch)
|
|
444
397
|
return self
|
|
445
398
|
}
|
|
446
|
-
|
|
399
|
+
exports.default = TitleSwitcher
|
|
447
400
|
if (void 0) {
|
|
401
|
+
// @ts-ignore 'this' is used in node as the global, and the key CAN be referenced by string
|
|
448
402
|
(void 0).TitleSwitcher = TitleSwitcher
|
|
449
403
|
} else if (typeof window !== 'undefined') {
|
|
404
|
+
// @ts-ignore YES, we can use a string to add a property to Window
|
|
450
405
|
window.TitleSwitcher = TitleSwitcher
|
|
451
406
|
}
|
|
452
407
|
}, { 'core-js/modules/es.array.for-each.js': 154, 'core-js/modules/es.array.iterator.js': 155, 'core-js/modules/es.array.join.js': 156, 'core-js/modules/es.date.to-primitive.js': 157, 'core-js/modules/es.number.constructor.js': 159, 'core-js/modules/es.object.define-property.js': 160, 'core-js/modules/es.object.to-string.js': 162, 'core-js/modules/es.regexp.constructor.js': 163, 'core-js/modules/es.regexp.exec.js': 164, 'core-js/modules/es.regexp.sticky.js': 165, 'core-js/modules/es.regexp.to-string.js': 166, 'core-js/modules/es.string.iterator.js': 167, 'core-js/modules/es.string.replace.js': 168, 'core-js/modules/es.string.trim.js': 169, 'core-js/modules/es.symbol.description.js': 171, 'core-js/modules/es.symbol.iterator.js': 173, 'core-js/modules/es.symbol.js': 174, 'core-js/modules/es.symbol.to-primitive.js': 176, 'core-js/modules/es.weak-map.js': 178, 'core-js/modules/esnext.async-iterator.for-each.js': 179, 'core-js/modules/esnext.iterator.constructor.js': 180, 'core-js/modules/esnext.iterator.for-each.js': 181, 'core-js/modules/esnext.weak-map.delete-all.js': 182, 'core-js/modules/web.dom-collections.for-each.js': 183, 'core-js/modules/web.dom-collections.iterator.js': 184, 'core-js/modules/web.timers.js': 187 }],
|