Permalink
Browse files

Squashed commit of the following:

commit 87205f1
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sun Dec 30 18:50:12 2012 -0600

    update documentation

commit 63222e3
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sun Dec 30 18:48:22 2012 -0600

    add example for new tag specification

commit be73ea2
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sun Dec 30 18:47:56 2012 -0600

    fix the markupContent function

commit 93b84ad
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sun Dec 30 18:47:18 2012 -0600

    check input tag and force it to become wrapped in brackets

commit 7551b68
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sun Dec 30 13:56:36 2012 -0600

    add brackets around tag

commit 2552050
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sat Dec 29 23:01:24 2012 -0600

    remove wrap,
    update _markupContent function to select the deepest child.
    convert spaces to tabs ( formatting )
    remove spaces from params

commit f06dd91
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Sat Dec 29 22:52:48 2012 -0600

    ignore vim

commit 0e52fcd
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Fri Dec 14 00:30:32 2012 -0600

    remove build script per request

commit 5ce5f53
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 16:30:23 2012 -0600

    remove logging

commit 0ebd660
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 16:03:46 2012 -0600

    add wrap to example

commit 017e192
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:59:56 2012 -0600

    add minified version

commit aab6b84
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:59:42 2012 -0600

    add build script

commit ee0e226
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:58:19 2012 -0600

    use helper function for marking up content

commit b412e0c
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:57:58 2012 -0600

    add markup content helper function

commit 0ccf6fc
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:57:23 2012 -0600

    add wrap as a setting

commit 1263d8b
Author: Luke Thomas <luk3thomas@gmail.com>
Date:   Thu Dec 13 15:56:24 2012 -0600

    remove braces
  • Loading branch information...
luk3thomas authored and jeremyharris committed Jan 2, 2013
1 parent ccd01ca commit d8f15f554290834296b496293d96cf1c3dce401d
Showing with 49 additions and 17 deletions.
  1. +1 −0 .gitignore
  2. +8 −8 README.md
  3. +2 −2 demos.html
  4. +38 −7 jquery.splitlines.js
View
@@ -0,0 +1 @@
*.sw[o-p]
View
@@ -20,20 +20,20 @@ line individually. Works with nested HTML tags.
### Javascript
$('#mytext').splitLines({
tag: 'div',
tag: '<div><span class="someClass">',
width: 200,
keepHtml: true
});
### Result
<div id="mytext">
<div>This is an</div>
<div><strong>example</strong> of</div>
<div>some long</div>
<div>text that we</div>
<div>want to split</div>
<div>into lines.</div>
<div><span class="someClass">This is an</span></div>
<div><span class="someClass"><strong>example</strong> of</span></div>
<div><span class="someClass">some long</span></div>
<div><span class="someClass">text that we</span></div>
<div><span class="someClass">want to split</span></div>
<div><span class="someClass">into lines.</span></div>
</div>
Now go forth, and animate!
@@ -60,4 +60,4 @@ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
@@ -74,7 +74,7 @@
$(document).ready(function() {
$('#example-1').splitLines();
$('#example-2').splitLines({tag:'span', width:200});
$('#example-2').splitLines({tag:'<span class="inline"><strong>', width:200});
$('#example-3').splitLines();
$('#example-4').splitLines();
$('#example-5').splitLines({width: 200});
@@ -183,4 +183,4 @@ <h1>jQuery <span class="code">splitLines()</span> demos</h1>
</div>
</div>
</body>
</html>
</html>
View
@@ -61,19 +61,50 @@
return text.split(/\s+/);
}
/**
* Checks the tag to make sure it contains tags
*
* @param tag
*/
function _checkTags(tag) {
if(!tag.match(/<|>/))
return ['<', tag, '>'].join('');
return tag;
}
/**
* Formats html with tags and wrappers.
*
* @param tag
* @param html content wrapped by the tag
*/
function _markupContent(tag, html) {
// wrap in a temp div so .html() gives us the tags we specify
tag = '<div>' + tag;
// find the deepest child, add html, then find the parent
return $(tag)
.find('*:not(:has("*"))')
.html(html)
.parentsUntil()
.slice(-1)
.html();
}
/**
* The jQuery plugin function. See the top of this file for information on the
* options
*/
$.fn.splitLines = function(options) {
var settings = {
width: 'auto',
tag: 'div',
tag: '<div>',
wrap: '',
keepHtml: true
};
if (options) {
if (options)
$.extend(settings, options);
}
settings.tag = _checkTags(settings.tag);
var newHtml = _createTemp(this);
var contents = this.contents();
var text = this.text();
@@ -95,21 +126,21 @@
if (tempLine.html() == prev) {
// repeating word, it will never fit so just use it instead of failing
prev = '';
newHtml.append('<'+settings.tag+'>'+tempLine.html()+'</'+settings.tag+'>');
newHtml.append(_markupContent(settings.tag, tempLine.html()));
tempLine.html('');
continue;
}
if (tempLine.height() > maxHeight) {
prev = tempLine.html();
tempLine.html(html);
newHtml.append('<'+settings.tag+'>'+tempLine.html()+'</'+settings.tag+'>');
newHtml.append(_markupContent(settings.tag, tempLine.html()));
tempLine.html('');
w--;
}
}
newHtml.append('<'+settings.tag+'>'+tempLine.html()+'</'+settings.tag+'>');
newHtml.append(_markupContent(settings.tag, tempLine.html()));
this.html(newHtml.html());
};
})(jQuery);
})(jQuery);

0 comments on commit d8f15f5

Please sign in to comment.