|  | 
|  | 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