This is a multi-
line headline.
{"ScriptPreparationCode":null,"TestCases":[{"Name":"Multi-line detection using getComputedStyles","Code":"function chekele(element) {\r\n var elementStyles = window.getComputedStyle(element);\r\n return elementStyles[\u0027line-height\u0027] \u003C elementStyles[\u0027height\u0027]\r\n}\r\n\r\nchekele(document.querySelector(\u0027h2\u0027));","IsDeferred":false},{"Name":"Multi-line detection using the NYT method","Code":"function chekele(element) {\r\n var firstWordHeight;\r\n var elementHeight;\r\n var HEIGHT_OFFSET;\r\n var elementWords;\r\n var firstWord;\r\n var ORIGINAL_ELEMENT_TEXT;\r\n\r\n ORIGINAL_ELEMENT_TEXT = element.innerHTML;\r\n\r\n // usually there is around a 5px discrepency between\r\n // the first word and the height of the whole headline\r\n // so subtract the height of the headline by 10 px and\r\n // we should be good\r\n HEIGHT_OFFSET = 10;\r\n\r\n // get all the words in the headline as\r\n // an array -- will include punctuation\r\n //\r\n // this is used to put the headline back together\r\n elementWords = element.innerHTML.split(\u0027 \u0027);\r\n\r\n // make span for first word and give it an id\r\n // so we can access it in le dom\r\n firstWord = document.createElement(\u0027span\u0027);\r\n firstWord.id = \u0027element-first-word\u0027;\r\n firstWord.innerHTML = elementWords[0];\r\n\r\n // this is the entire headline\r\n // as an array except for first word\r\n //\r\n // we will append it to the headline after the span\r\n elementWords = elementWords.slice(1);\r\n\r\n // empty the headline and append the span to it\r\n element.innerHTML = \u0027\u0027;\r\n element.appendChild(firstWord);\r\n\r\n // add the rest of the element back to it\r\n element.innerHTML \u002B= \u0027 \u0027 \u002B elementWords.join(\u0027 \u0027);\r\n\r\n // update the first word variable in the dom\r\n //firstWord = document.getElementById(\u0027element-first-word\u0027);\r\n\r\n firstWordHeight = firstWord.offsetHeight;\r\n console.log(firstWord.offsetHeight);\r\n elementHeight = element.offsetHeight;\r\n // restore the original element text\r\n element.innerHTML = ORIGINAL_ELEMENT_TEXT;\r\n\r\n // compare the height of the element and the height of the first word\r\n return elementHeight - HEIGHT_OFFSET \u003E firstWordHeight;\r\n}\r\n\r\nchekele(document.querySelector(\u0027h2\u0027));","IsDeferred":false}]}