Skip to content

Commit b7cc70c

Browse files
committed
initial build
1 parent a0f106f commit b7cc70c

File tree

3 files changed

+285
-0
lines changed

3 files changed

+285
-0
lines changed

dist/v-scrollin.esm.js

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { setInterval, clearInterval } from 'timers';
2+
3+
(function(){ if(typeof document !== 'undefined'){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=""; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
4+
5+
var component = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"v-scrollin"},[_vm._v(" "+_vm._s(_vm.scrollingText)+" ")])},staticRenderFns: [],
6+
name: "VScrollin",
7+
props: {
8+
characters: {
9+
// characters used during flicker
10+
type: Array,
11+
required: false,
12+
default: function () { return "qwertyuiopasdfghjklzxcvbnm".split(""); }
13+
},
14+
misses: {
15+
// amount of scrolls before correct letter
16+
type: Number,
17+
required: false,
18+
default: 4
19+
},
20+
speed: {
21+
// delay of each letter scroll (ms)
22+
type: Number,
23+
required: false,
24+
default: 80
25+
}
26+
},
27+
data: function data() {
28+
return {
29+
amountFinished: 0,
30+
currentMisses: 0,
31+
finishedText: this.$slots.default[0].text,
32+
scroll: null,
33+
scrollingText: "",
34+
workingIndices: []
35+
};
36+
},
37+
mounted: function mounted() {
38+
var this$1 = this;
39+
40+
this.fillRandomLetters();
41+
this.scroll = setInterval(function () {
42+
this$1.tick();
43+
}, this.speed);
44+
},
45+
methods: {
46+
fillRandomLetters: function fillRandomLetters() {
47+
var this$1 = this;
48+
49+
var startingLetters = [];
50+
for (var n = 0; n < this.finishedText.length; n++) {
51+
startingLetters.push(this$1.getRandomLetter());
52+
}
53+
this.scrollingText = startingLetters.join("");
54+
},
55+
getRandomLetter: function getRandomLetter() {
56+
return this.characters[
57+
Math.floor(Math.random() * this.characters.length)
58+
];
59+
},
60+
replace: function replace(str, i, replacement) {
61+
return (
62+
str.substr(0, i) + replacement + str.substr(i + replacement.length)
63+
);
64+
},
65+
tick: function tick() {
66+
var this$1 = this;
67+
68+
for (
69+
var n = this.amountFinished;
70+
n < this.amountFinished + this.workingIndices.length;
71+
n++
72+
) {
73+
this$1.scrollingText = this$1.replace(
74+
this$1.scrollingText,
75+
n,
76+
this$1.getRandomLetter()
77+
);
78+
}
79+
if (this.workingIndices.length < 3 && !this.amountFinished) {
80+
this.workingIndices.push(this.workingIndices.length);
81+
}
82+
if (this.scrollingText === this.finishedText) {
83+
clearInterval(this.scroll);
84+
} else if (++this.currentMisses >= this.misses) {
85+
this.scrollingText = this.replace(
86+
this.scrollingText,
87+
this.amountFinished,
88+
this.finishedText[this.amountFinished]
89+
);
90+
this.currentMisses = 0;
91+
if (++this.amountFinished >= this.finishedText.length - 2) {
92+
this.workingIndices
93+
.sort(function(a, b) {
94+
return a - b;
95+
})
96+
.shift();
97+
} else {
98+
this.workingIndices.sort(function(a, b) {
99+
return a - b;
100+
})[0] =
101+
this.amountFinished + 3;
102+
}
103+
}
104+
}
105+
}
106+
};
107+
108+
// Import vue component
109+
110+
// install function executed by Vue.use()
111+
function install(Vue) {
112+
if (install.installed) { return; }
113+
install.installed = true;
114+
Vue.component('VScrollin', component);
115+
}
116+
117+
// Create module definition for Vue.use()
118+
var plugin = {
119+
install: install,
120+
};
121+
122+
// To auto-install when vue is found
123+
var GlobalVue = null;
124+
if (typeof window !== 'undefined') {
125+
GlobalVue = window.Vue;
126+
} else if (typeof global !== 'undefined') {
127+
GlobalVue = global.Vue;
128+
}
129+
if (GlobalVue) {
130+
GlobalVue.use(plugin);
131+
}
132+
133+
// It's possible to expose named exports when writing components that can
134+
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
135+
// export const RollupDemoDirective = component;
136+
137+
export default component;
138+
export { install };

dist/v-scrollin.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/v-scrollin.umd.js

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
(function (global, factory) {
2+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('timers')) :
3+
typeof define === 'function' && define.amd ? define(['exports', 'timers'], factory) :
4+
(factory((global.VScrollin = {}),global.timers));
5+
}(this, (function (exports,timers) { 'use strict';
6+
7+
(function(){ if(typeof document !== 'undefined'){ var head=document.head||document.getElementsByTagName('head')[0], style=document.createElement('style'), css=""; style.type='text/css'; if (style.styleSheet){ style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } head.appendChild(style); } })();
8+
9+
var component = {render: function(){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"v-scrollin"},[_vm._v(" "+_vm._s(_vm.scrollingText)+" ")])},staticRenderFns: [],
10+
name: "VScrollin",
11+
props: {
12+
characters: {
13+
// characters used during flicker
14+
type: Array,
15+
required: false,
16+
default: function () { return "qwertyuiopasdfghjklzxcvbnm".split(""); }
17+
},
18+
misses: {
19+
// amount of scrolls before correct letter
20+
type: Number,
21+
required: false,
22+
default: 4
23+
},
24+
speed: {
25+
// delay of each letter scroll (ms)
26+
type: Number,
27+
required: false,
28+
default: 80
29+
}
30+
},
31+
data: function data() {
32+
return {
33+
amountFinished: 0,
34+
currentMisses: 0,
35+
finishedText: this.$slots.default[0].text,
36+
scroll: null,
37+
scrollingText: "",
38+
workingIndices: []
39+
};
40+
},
41+
mounted: function mounted() {
42+
var this$1 = this;
43+
44+
this.fillRandomLetters();
45+
this.scroll = timers.setInterval(function () {
46+
this$1.tick();
47+
}, this.speed);
48+
},
49+
methods: {
50+
fillRandomLetters: function fillRandomLetters() {
51+
var this$1 = this;
52+
53+
var startingLetters = [];
54+
for (var n = 0; n < this.finishedText.length; n++) {
55+
startingLetters.push(this$1.getRandomLetter());
56+
}
57+
this.scrollingText = startingLetters.join("");
58+
},
59+
getRandomLetter: function getRandomLetter() {
60+
return this.characters[
61+
Math.floor(Math.random() * this.characters.length)
62+
];
63+
},
64+
replace: function replace(str, i, replacement) {
65+
return (
66+
str.substr(0, i) + replacement + str.substr(i + replacement.length)
67+
);
68+
},
69+
tick: function tick() {
70+
var this$1 = this;
71+
72+
for (
73+
var n = this.amountFinished;
74+
n < this.amountFinished + this.workingIndices.length;
75+
n++
76+
) {
77+
this$1.scrollingText = this$1.replace(
78+
this$1.scrollingText,
79+
n,
80+
this$1.getRandomLetter()
81+
);
82+
}
83+
if (this.workingIndices.length < 3 && !this.amountFinished) {
84+
this.workingIndices.push(this.workingIndices.length);
85+
}
86+
if (this.scrollingText === this.finishedText) {
87+
timers.clearInterval(this.scroll);
88+
} else if (++this.currentMisses >= this.misses) {
89+
this.scrollingText = this.replace(
90+
this.scrollingText,
91+
this.amountFinished,
92+
this.finishedText[this.amountFinished]
93+
);
94+
this.currentMisses = 0;
95+
if (++this.amountFinished >= this.finishedText.length - 2) {
96+
this.workingIndices
97+
.sort(function(a, b) {
98+
return a - b;
99+
})
100+
.shift();
101+
} else {
102+
this.workingIndices.sort(function(a, b) {
103+
return a - b;
104+
})[0] =
105+
this.amountFinished + 3;
106+
}
107+
}
108+
}
109+
}
110+
};
111+
112+
// Import vue component
113+
114+
// install function executed by Vue.use()
115+
function install(Vue) {
116+
if (install.installed) { return; }
117+
install.installed = true;
118+
Vue.component('VScrollin', component);
119+
}
120+
121+
// Create module definition for Vue.use()
122+
var plugin = {
123+
install: install,
124+
};
125+
126+
// To auto-install when vue is found
127+
var GlobalVue = null;
128+
if (typeof window !== 'undefined') {
129+
GlobalVue = window.Vue;
130+
} else if (typeof global !== 'undefined') {
131+
GlobalVue = global.Vue;
132+
}
133+
if (GlobalVue) {
134+
GlobalVue.use(plugin);
135+
}
136+
137+
// It's possible to expose named exports when writing components that can
138+
// also be used as directives, etc. - eg. import { RollupDemoDirective } from 'rollup-demo';
139+
// export const RollupDemoDirective = component;
140+
141+
exports.install = install;
142+
exports.default = component;
143+
144+
Object.defineProperty(exports, '__esModule', { value: true });
145+
146+
})));

0 commit comments

Comments
 (0)