Created
April 21, 2016 07:33
-
-
Save r4fx/21b2e1fc4d2a6902a6f7fa8c219b0549 to your computer and use it in GitHub Desktop.
Orphans fix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Usage | |
* | |
$(function () { | |
$(".todayMenu article").removeOrphans(); | |
}); | |
*/ | |
// using regexp to every single char | |
// having spaces before and after of its | |
// we replace a space with a hard space - | |
// which - naturally - merges this char with the next word / char etc. which have 1,2 or 3 signs | |
$.fn.removeOrphans = function () { | |
$(this).each(function () { | |
if ($(this).length > 0) { | |
var $html = $(this).html(); | |
$html = $html.replace(/(\s)([^\s]{1,3})[\s]+/g, "$1$2 "); | |
$(this).empty().html($html); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment