|
1 | | -/*! superplaceholder.js - v0.1.0 - 2016-02-29 |
| 1 | +/*! superplaceholder.js - v0.1.1 - 2016-03-06 |
2 | 2 | * http://kushagragour.in/lab/superplaceholderjs/ |
3 | 3 | * Copyright (c) 2016 Kushagra Gour; Licensed CC-BY-ND-4.0 */ |
4 | 4 |
|
|
19 | 19 | letterDelay: 100, //milliseconds |
20 | 20 | sentenceDelay: 1000, //milliseconds |
21 | 21 | loop: false, |
22 | | - startOnFocus: true |
| 22 | + startOnFocus: true, |
| 23 | + shuffle: false, |
| 24 | + showCursor: true, |
| 25 | + cursor: '|' |
23 | 26 | }; |
24 | 27 |
|
25 | 28 | // Constructor: PlaceHolder |
|
33 | 36 | } |
34 | 37 |
|
35 | 38 | PlaceHolder.prototype.begin = function() { |
36 | | - var self = this; |
| 39 | + var self = this, |
| 40 | + temp, |
| 41 | + randomIndex; |
37 | 42 | self.originalPlaceholder = self.el.getAttribute('placeholder'); |
| 43 | + if (self.options.shuffle) { |
| 44 | + for (var i = self.texts.length; i--;) { |
| 45 | + randomIndex = ~~(Math.random() * i); |
| 46 | + temp = self.texts[randomIndex]; |
| 47 | + self.texts[randomIndex] = self.texts[i]; |
| 48 | + self.texts[i] = temp; |
| 49 | + } |
| 50 | + } |
| 51 | + |
38 | 52 | if (self.options.startOnFocus) { |
39 | 53 | self.el.addEventListener('focus', function () { |
40 | 54 | self.processText(0); |
|
65 | 79 | function setTimeoutCallback(index) { |
66 | 80 | // Add cursor `|` after current substring unless we are showing last |
67 | 81 | // character of the string. |
68 | | - self.el.setAttribute('placeholder', str.substr(0, index + 1) + (index === str.length - 1 ? '' : '|')); |
| 82 | + self.el.setAttribute('placeholder', str.substr(0, index + 1) + (index === str.length - 1 || !self.options.showCursor ? '' : self.options.cursor)); |
69 | 83 | if (index === str.length - 1) { |
70 | 84 | callback(); |
71 | 85 | } |
|
0 commit comments