Skip to content

Instantly share code, notes, and snippets.

@jcreamer898
Created June 18, 2013 21:06
Show Gist options
  • Save jcreamer898/5809353 to your computer and use it in GitHub Desktop.
Save jcreamer898/5809353 to your computer and use it in GitHub Desktop.
trying to find new lines
console.time('addSpans');
$("#editor1 p span").each(function() {
var $self = $(this),
newContent = $(this)[0].innerHTML.split(/\s+(?![^<>]*>)/).map(function(word) { return '<span>' + word + '</span>'; }).join(' ');
$self.html(newContent);
});
console.timeEnd('addSpans');
console.time('process');
$("#editor1 p span span").each(function() {
var $self = $(this), $prev = $self.prev('span'), $next = $self.next('span'), newLine;
if (!$prev.length) return $self.addClass('line-start');
newLine = $self.offset().top > $prev.offset().top;
if (newLine) $prev.addClass('line-end');
});
console.timeEnd('process');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment