title: How can I stop this teletype animation after its first iteration?
body: <p>I am doing a typewriting effect using jquery and found this code and edited it to work perfectly as i need.</p>
  
  <p>But, i have a problem that i am not able to stop the loop.</p>
  
  <p>I tried to detect that the last paragraph is printed so i can add a function after that with no luck.</p>
  
  <p>Your advices and hints are appreciated.</p>
  
  <p>The code is: </p>
  
  <p><a href="http://jsbin.com/araget/33/" rel="nofollow">http://jsbin.com/araget/33/</a></p>
  
  <pre><code>(function ($) {
  
    function typeString($target, str, cursor, delay, cb) {
      $target.html(function (_, html) {
        return html + str[cursor];
      });
  
      if (cursor &lt; str.length - 1) {
        setTimeout(function () {
          typeString($target, str, cursor + 1, delay, cb);
        }, delay);
      }
      else {
        cb();
      }
    }
  
    function deleteString($target, delay, cb) {
      var length;
  
      $target.html(function (_, html) {
        length = html.length;
        return html.substr(0, length - 1);
      });
  
      if (length &gt; 1) {
        setTimeout(function () {
          deleteString($target, delay, cb);
        }, delay);
      }
      else {
        cb();
      }
    }
  
    // jQuery hook
    $.fn.extend({
      teletype: function (opts) {
        var settings = $.extend({}, $.teletype.defaults, opts);
  
        return $(this).each(function () {
          (function loop($tar, idx) {
            // type
            typeString($tar, settings.text[idx], 0, settings.delay, function () {
              // delete
              setTimeout(function () {
                deleteString($tar, settings.delay, function () {
                  loop($tar, (idx + 1) % settings.text.length);
                });
              }, settings.pause);
            });
  
          }($(this), 0));
        });
      }
    });
  
    // plugin defaults  
    $.extend({
      teletype: {
        defaults: {
          delay: 100,
          pause: 5000,
          text: []
        }
      }
    });
  }(jQuery));
  
  $('#target').teletype({
    text: [
      'Lorem ipsum dolor sit amet, consetetur sadipscing elitr,',
      'sed diam nonumy eirmod tempor invidunt ut labore et dolore',
      'magna aliquyam erat, sed diam voluptua. At vero eos et'
    ]
  });
  
  $('#cursor').teletype({
    text: ['_', ' '],
    delay: 0,
    pause: 500
  });
  </code></pre>