Skip to content

Commit

Permalink
more docs on hyphenation. moved a chunk of code for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Dec 10, 2011
1 parent f56ddf7 commit 3f10031
Showing 1 changed file with 50 additions and 44 deletions.
94 changes: 50 additions & 44 deletions feature-detects/hyphens.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,62 @@
/* see http://dev.davidnewton.ca/the-current-state-of-hyphenation-on-the-web */
/* see dev.davidnewton.ca/the-current-state-of-hyphenation-on-the-web
dev.davidnewton.ca/demos/hyphenation/test.html
/* these tests currently require document.body to be present */
/* There are three tests:
There are three tests:
1. csshyphens - tests hyphens:auto actually adds hyphens to text
2. softhyphens - tests that ­ does its job
3. softhyphensfind - tests that in-browser Find functionality still works correctly with ­
These tests currently require document.body to be present
Hyphenation is language specific, sometimes.
See for more details: http://code.google.com/p/hyphenator/source/diff?spec=svn975&r=975&format=side&path=/trunk/Hyphenator.js#sc_svn975_313
More details at https://github.com/Modernizr/Modernizr/issues/312
*/

(function() {

// functional test of adding hyphens:auto
function test_hyphens_css() {
try {
/* create a div container and a span within that
* these have to be appended to document.body, otherwise some browsers can give false negative */
var div = document.createElement('div'),
span = document.createElement('span'),
divStyle = div.style,
spanHeight = 0,
spanWidth = 0,
result = false,
result1 = false,
result2 = false;
document.body.appendChild(div);
div.appendChild(span);
span.innerHTML = 'Bacon ipsum dolor sit amet jerky velit in culpa hamburger et. Laborum dolor proident, enim dolore duis commodo et strip steak. Salami anim et, veniam consectetur dolore qui tenderloin jowl velit sirloin. Et ad culpa, fatback cillum jowl ball tip ham hock nulla short ribs pariatur aute. Pig pancetta ham bresaola, ut boudin nostrud commodo flank esse cow tongue culpa. Pork belly bresaola enim pig, ea consectetur nisi. Fugiat officia turkey, ea cow jowl pariatur ullamco proident do laborum velit sausage. Magna biltong sint tri-tip commodo sed bacon, esse proident aliquip. Ullamco ham sint fugiat, velit in enim sed mollit nulla cow ut adipisicing nostrud consectetur. Proident dolore beef ribs, laborum nostrud meatball ea laboris rump cupidatat labore culpa. Shankle minim beef, velit sint cupidatat fugiat tenderloin pig et ball tip. Ut cow fatback salami, bacon ball tip et in shank strip steak bresaola. In ut pork belly sed mollit tri-tip magna culpa veniam, short ribs qui in andouille ham consequat. Dolore bacon t-bone, velit short ribs enim strip steak nulla. Voluptate labore ut, biltong swine irure jerky. Cupidatat excepteur aliquip salami dolore. Ball tip strip steak in pork dolor. Ad in esse biltong. Dolore tenderloin exercitation ad pork loin t-bone, dolore in chicken ball tip qui pig. Ut culpa tongue, sint ribeye dolore ex shank voluptate hamburger. Jowl et tempor, boudin pork chop labore ham hock drumstick consectetur tri-tip elit swine meatball chicken ground round. Proident shankle mollit dolore. Shoulder ut duis t-bone quis reprehenderit. Meatloaf dolore minim strip steak, laboris ea aute bacon beef ribs elit shank in veniam drumstick qui. Ex laboris meatball cow tongue pork belly. Ea ball tip reprehenderit pig, sed fatback boudin dolore flank aliquip laboris eu quis. Beef ribs duis beef, cow corned beef adipisicing commodo nisi deserunt exercitation. Cillum dolor t-bone spare ribs, ham hock est sirloin. Brisket irure meatloaf in, boudin pork belly sirloin ball tip. Sirloin sint irure nisi nostrud aliqua. Nostrud nulla aute, enim officia culpa ham hock. Aliqua reprehenderit dolore sunt nostrud sausage, ea boudin pork loin ut t-bone ham tempor. Tri-tip et pancetta drumstick laborum. Ham hock magna do nostrud in proident. Ex ground round fatback, venison non ribeye in.';

/* get size of unhyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;text-justification:newspaper;';
spanHeight = span.offsetHeight;
spanWidth = span.offsetWidth;

/* compare size with hyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;'+
'text-justification:newspaper;'
+ Modernizr._prefixes.join('hyphens:auto; ');

result = (span.offsetHeight != spanHeight || span.offsetWidth != spanWidth);

/* results and cleanup */
div.removeChild(span);
document.body.removeChild(div);
return result;
return result;

This comment has been minimized.

Copy link
@jamesarosen

jamesarosen Dec 10, 2011

Why two returns?

This comment has been minimized.

Copy link
@paulirish

paulirish Dec 10, 2011

Author Member

lol. good question. cc @nwtn .. i think we can remove that. :p

} catch(e) {
return false;
}
}

// for the softhyphens test
function test_hyphens(delimiter, testWidth) {
try {
Expand Down Expand Up @@ -108,46 +154,6 @@
}
}

// functional test of adding hyphens:auto
function test_hyphens_css() {
try {
/* create a div container and a span within that
* these have to be appended to document.body, otherwise some browsers can give false negative */
var div = document.createElement('div'),
span = document.createElement('span'),
divStyle = div.style,
spanHeight = 0,
spanWidth = 0,
result = false,
result1 = false,
result2 = false;
document.body.appendChild(div);
div.appendChild(span);
span.innerHTML = 'Bacon ipsum dolor sit amet jerky velit in culpa hamburger et. Laborum dolor proident, enim dolore duis commodo et strip steak. Salami anim et, veniam consectetur dolore qui tenderloin jowl velit sirloin. Et ad culpa, fatback cillum jowl ball tip ham hock nulla short ribs pariatur aute. Pig pancetta ham bresaola, ut boudin nostrud commodo flank esse cow tongue culpa. Pork belly bresaola enim pig, ea consectetur nisi. Fugiat officia turkey, ea cow jowl pariatur ullamco proident do laborum velit sausage. Magna biltong sint tri-tip commodo sed bacon, esse proident aliquip. Ullamco ham sint fugiat, velit in enim sed mollit nulla cow ut adipisicing nostrud consectetur. Proident dolore beef ribs, laborum nostrud meatball ea laboris rump cupidatat labore culpa. Shankle minim beef, velit sint cupidatat fugiat tenderloin pig et ball tip. Ut cow fatback salami, bacon ball tip et in shank strip steak bresaola. In ut pork belly sed mollit tri-tip magna culpa veniam, short ribs qui in andouille ham consequat. Dolore bacon t-bone, velit short ribs enim strip steak nulla. Voluptate labore ut, biltong swine irure jerky. Cupidatat excepteur aliquip salami dolore. Ball tip strip steak in pork dolor. Ad in esse biltong. Dolore tenderloin exercitation ad pork loin t-bone, dolore in chicken ball tip qui pig. Ut culpa tongue, sint ribeye dolore ex shank voluptate hamburger. Jowl et tempor, boudin pork chop labore ham hock drumstick consectetur tri-tip elit swine meatball chicken ground round. Proident shankle mollit dolore. Shoulder ut duis t-bone quis reprehenderit. Meatloaf dolore minim strip steak, laboris ea aute bacon beef ribs elit shank in veniam drumstick qui. Ex laboris meatball cow tongue pork belly. Ea ball tip reprehenderit pig, sed fatback boudin dolore flank aliquip laboris eu quis. Beef ribs duis beef, cow corned beef adipisicing commodo nisi deserunt exercitation. Cillum dolor t-bone spare ribs, ham hock est sirloin. Brisket irure meatloaf in, boudin pork belly sirloin ball tip. Sirloin sint irure nisi nostrud aliqua. Nostrud nulla aute, enim officia culpa ham hock. Aliqua reprehenderit dolore sunt nostrud sausage, ea boudin pork loin ut t-bone ham tempor. Tri-tip et pancetta drumstick laborum. Ham hock magna do nostrud in proident. Ex ground round fatback, venison non ribeye in.';

/* get size of unhyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;text-justification:newspaper;';
spanHeight = span.offsetHeight;
spanWidth = span.offsetWidth;

/* compare size with hyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;'+
'text-justification:newspaper;'
+ Modernizr._prefixes.join('hyphens:auto; ');

result = (span.offsetHeight != spanHeight || span.offsetWidth != spanWidth);

/* results and cleanup */
div.removeChild(span);
document.body.removeChild(div);
return result;
return result;
} catch(e) {
return false;
}
}


Modernizr.addTest("csshyphens", function() {

if (!Modernizr.testAllProps('hyphens')) return false;
Expand Down Expand Up @@ -178,5 +184,5 @@
return false;
}
});

})();

0 comments on commit 3f10031

Please sign in to comment.