Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

cleanup of hyphens test. no more scroll fixes neccessary. fixes #366

  • Loading branch information...
commit 5de022e9739e841daac3cf311eade9903155e20b 1 parent 1c8e8ee
@paulirish paulirish authored
Showing with 29 additions and 11 deletions.
  1. +29 −11 feature-detects/css-hyphens.js
View
40 feature-detects/css-hyphens.js
@@ -18,6 +18,11 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
(function() {
+ if (!document.body){
+ window.console && console.warn('document.body doesn\'t exist. Modernizr hyphens test needs it.')
+ return;
+ }
+
// functional test of adding hyphens:auto
function test_hyphens_css() {
try {
@@ -30,11 +35,14 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
spanWidth = 0,
result = false,
result1 = false,
- result2 = false;
- document.body.appendChild(div);
+ result2 = false,
+ firstChild = document.body.firstElementChild || document.body.firstChild;
+
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.';
+ document.body.insertBefore(div, firstChild);
+
/* get size of unhyphenated text */
divStyle.cssText = 'position:absolute;top:0;left:0;width:5em;text-align:justify;text-justification:newspaper;';
spanHeight = span.offsetHeight;
@@ -48,8 +56,9 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
result = (span.offsetHeight != spanHeight || span.offsetWidth != spanWidth);
/* results and cleanup */
- div.removeChild(span);
document.body.removeChild(div);
+ div.removeChild(span);
+
return result;
} catch(e) {
return false;
@@ -67,11 +76,14 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
spanSize = 0,
result = false,
result1 = false,
- result2 = false;
- document.body.appendChild(div);
- div.appendChild(span);
- divStyle.cssText = 'position:absolute;top:0;left:0;overflow:visible;width:1.25em;';
+ result2 = false,
+ firstChild = document.body.firstElementChild || document.body.firstChild;
+ divStyle.cssText = 'position:absolute;top:0;left:0;overflow:visible;width:1.25em;';
+ div.appendChild(span);
+ document.body.insertBefore(div, firstChild);
+
+
/* get height of unwrapped text */
span.innerHTML = 'mm';
spanSize = span.offsetHeight;
@@ -96,8 +108,9 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
/* results and cleanup */
if (result1 === true && result2 === true) { result = true; }
- div.removeChild(span);
document.body.removeChild(div);
+ div.removeChild(span);
+
return result;
} catch(e) {
return false;
@@ -115,12 +128,15 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
div = document.createElement('div'),
testword = 'lebowski',
result = false,
- textrange;
+ textrange,
+ firstChild = document.body.firstElementChild || document.body.firstChild;
- document.body.appendChild(dummy);
- document.body.appendChild(div);
div.innerHTML = testword + delimiter + testword;
+ document.body.insertBefore(div, firstChild);
+ document.body.insertBefore(dummy, firstChild);
+
+
/* reset the selection to the dummy input element, i.e. BEFORE the div container
* stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area */
if (dummy.setSelectionRange) {
@@ -145,8 +161,10 @@ More details at https://github.com/Modernizr/Modernizr/issues/312
result = false;
}
}
+
document.body.removeChild(div);
document.body.removeChild(dummy);
+
return result;
} catch(e) {
return false;
Please sign in to comment.
Something went wrong with that request. Please try again.