Advertisement
Guest User

Untitled

a guest
May 28th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. ! function(t) {
  2. "use strict";
  3. var s = function(s, o) {
  4. this.el = t(s), this.options = t.extend({}, t.fn.typed.defaults, o), this.isInput = this.el.is("input"), this.attr = this.options.attr, this.showCursor = this.isInput ? !1 : this.options.showCursor, this.elContent = this.attr ? this.el.attr(this.attr) : this.el.text(), this.contentType = this.options.contentType, this.typeSpeed = this.options.typeSpeed, this.startDelay = this.options.startDelay, this.backSpeed = this.options.backSpeed, this.backDelay = this.options.backDelay, this.strings = this.options.strings, this.strPos = 0, this.arrayPos = 0, this.stopNum = 0, this.loop = this.options.loop, this.loopCount = this.options.loopCount, this.curLoop = 0, this.stop = !1, this.cursorChar = this.options.cursorChar, this.build()
  5. };
  6. s.prototype = {
  7. constructor: s,
  8. init: function() {
  9. var t = this;
  10. t.timeout = setTimeout(function() {
  11. t.typewrite(t.strings[t.arrayPos], t.strPos)
  12. }, t.startDelay)
  13. },
  14. build: function() {
  15. this.showCursor === !0 && (this.cursor = t('<span class="typed-cursor">' + this.cursorChar + "</span>"), this.el.after(this.cursor)), this.init()
  16. },
  17. typewrite: function(t, s) {
  18. if (this.stop !== !0) {
  19. var o = Math.round(70 * Math.random()) + this.typeSpeed,
  20. e = this;
  21. e.timeout = setTimeout(function() {
  22. var o = 0,
  23. i = t.substr(s);
  24. if ("^" === i.charAt(0)) {
  25. var r = 1;
  26. /^\^\d+/.test(i) && (i = /\d+/.exec(i)[0], r += i.length, o = parseInt(i)), t = t.substring(0, s) + t.substring(s + r)
  27. }
  28. if ("html" === e.contentType) {
  29. var n = t.substr(s).charAt(0);
  30. if ("<" === n || "&" === n) {
  31. var a = "",
  32. h = "";
  33. for (h = "<" === n ? ">" : ";"; t.substr(s).charAt(0) !== h;) a += t.substr(s).charAt(0), s++;
  34. s++, a += h
  35. }
  36. }
  37. e.timeout = setTimeout(function() {
  38. if (s === t.length) {
  39. if (e.options.onStringTyped(e.arrayPos), e.arrayPos === e.strings.length - 1 && (e.options.callback(), e.curLoop++, e.loop === !1 || e.curLoop === e.loopCount)) return;
  40. e.timeout = setTimeout(function() {
  41. e.backspace(t, s)
  42. }, e.backDelay)
  43. } else {
  44. 0 === s && e.options.preStringTyped(e.arrayPos);
  45. var o = t.substr(0, s + 1);
  46. e.attr ? e.el.attr(e.attr, o) : e.isInput ? e.el.val(o) : "html" === e.contentType ? e.el.html(o) : e.el.text(o), s++, e.typewrite(t, s)
  47. }
  48. }, o)
  49. }, o)
  50. }
  51. },
  52. backspace: function(t, s) {
  53. if (this.stop !== !0) {
  54. var o = Math.round(70 * Math.random()) + this.backSpeed,
  55. e = this;
  56. e.timeout = setTimeout(function() {
  57. if ("html" === e.contentType && ">" === t.substr(s).charAt(0)) {
  58. for (var o = "";
  59. "<" !== t.substr(s).charAt(0);) o -= t.substr(s).charAt(0), s--;
  60. s--, o += "<"
  61. }
  62. var i = t.substr(0, s);
  63. e.attr ? e.el.attr(e.attr, i) : e.isInput ? e.el.val(i) : "html" === e.contentType ? e.el.html(i) : e.el.text(i), s > e.stopNum ? (s--, e.backspace(t, s)) : s <= e.stopNum && (e.arrayPos++, e.arrayPos === e.strings.length ? (e.arrayPos = 0, e.init()) : e.typewrite(e.strings[e.arrayPos], s))
  64. }, o)
  65. }
  66. },
  67. reset: function() {
  68. var t = this;
  69. clearInterval(t.timeout);
  70. var s = this.el.attr("id");
  71. this.el.after('<span id="' + s + '"/>'), this.el.remove(), "undefined" != typeof this.cursor && this.cursor.remove(), t.options.resetCallback()
  72. }
  73. }, t.fn.typed = function(o) {
  74. return this.each(function() {
  75. var e = t(this),
  76. i = e.data("typed"),
  77. r = "object" == typeof o && o;
  78. i || e.data("typed", i = new s(this, r)), "string" == typeof o && i[o]()
  79. })
  80. }, t.fn.typed.defaults = {
  81. strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
  82. typeSpeed: 0,
  83. startDelay: 0,
  84. backSpeed: 0,
  85. backDelay: 500,
  86. loop: !1,
  87. loopCount: !1,
  88. showCursor: !0,
  89. cursorChar: "|",
  90. attr: null,
  91. contentType: "html",
  92. callback: function() {},
  93. preStringTyped: function() {},
  94. onStringTyped: function() {},
  95. resetCallback: function() {}
  96. }
  97. }(window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement