poly-js-utils
Advanced tools
Comparing version 1.2.6 to 1.2.7
{ | ||
"name": "poly-js-utils", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "Common client-side tools used in HSS Sites themes and locators.", | ||
@@ -5,0 +5,0 @@ "main": "main.js", |
@@ -1,4 +0,1 @@ | ||
var $ = require('jquery'); | ||
var _ = require('underscore'); | ||
var utils = require('../src/utils'); | ||
@@ -48,45 +45,2 @@ | ||
describe("Test setUniformHeight on elements", function() { | ||
it("should set uniform height on selected elements", function() { | ||
// 'first' var is unused, but needed for setUniformHeight to return expected result. | ||
// Disable linting rule. | ||
var first = $('<div>').height(400).addClass('container').appendTo('body'); // eslint-disable-line no-unused-vars | ||
var second = $('<div>').height(200).addClass('container').appendTo('body'); | ||
utils.setUniformHeight('.container'); | ||
expect(second.height()).toBe(400); | ||
}); | ||
}); | ||
describe("Test ellipsifying elements", function() { | ||
it("should shorten long text and stub end with ...", function() { | ||
var longText = "Lorem ipsum dolor sit amet, consectetur adipisicing\ | ||
elit, sed do eiusmod tempor incididunt ut labore et dolore magna\ | ||
aliqua. Ut enim ad minim veniam, quis nostrud exercitation\ | ||
ullamco laboris nisi ut aliquip ex ea commodo consequat.\ | ||
Duis aute irure dolor in reprehenderit in voluptate\ | ||
velit esse cillum dolore eu fugiat nulla pariatur.\ | ||
Excepteur sint occaecat cupidatat non proident, sunt in\ | ||
culpa qui officia deserunt mollit anim id est laborum."; | ||
// Make a container that will overflow with longText | ||
$("<div>").height(100).addClass("text_container").appendTo("body"); | ||
var $div = $("<div>").addClass("text-box").text(longText).appendTo(".text_container"); | ||
utils.ellipsify(".text-box"); | ||
var lastThree = _.last($div.text(), 3).join(""); // Last three chars in div text. | ||
expect(lastThree).toBe("..."); | ||
}); | ||
it("should not ellipsify text that fits in the container", function() { | ||
var shortText = "Hi"; | ||
$("<div>").height(100).addClass("text_container").appendTo("body"); | ||
var $div = $("<div>").addClass("text-box").text(shortText).appendTo(".text_container"); | ||
utils.ellipsify(".text-box"); | ||
var lastThree = _.last($div.text(), 3).join(""); | ||
expect(lastThree).not.toBe("..."); | ||
}); | ||
}); | ||
describe("Test parsing url", function() { | ||
@@ -93,0 +47,0 @@ it("should break up a url into parts", function() { |
@@ -1,2 +0,1 @@ | ||
var $ = require('jquery'); | ||
var _ = require('underscore'); | ||
@@ -21,27 +20,2 @@ | ||
// Sets elements corresponding to a given css selector to a uniform | ||
// height, determined by the maximum height from the selected set. | ||
var setUniformHeight = function(selector) { | ||
var maxHeight = 0; | ||
$(selector).each(function() { | ||
maxHeight = Math.max(maxHeight, $(this).height()); | ||
}).height(maxHeight); | ||
}; | ||
// Replace overflowing text with ellipses in selection set. | ||
var ellipsify = function(selector) { | ||
$(selector).each(function() { | ||
var $ellipsisText = $(this); | ||
var textContainerHeight = $ellipsisText.closest('.box__content').height(); | ||
while ($ellipsisText.closest('.text_container').outerHeight() > textContainerHeight) { | ||
var text = $ellipsisText.text(); | ||
if(text.match(/\W*\s(\S)*$/)) { | ||
$ellipsisText.text(text.replace(/\W*\s(\S)*$/, "...")); | ||
} else { | ||
break; | ||
} | ||
} | ||
}); | ||
}; | ||
// Parse a url into its components | ||
@@ -138,4 +112,2 @@ var parseUrl = function(url) { | ||
exports.makeAbsolute = makeAbsolute; | ||
exports.setUniformHeight = setUniformHeight; | ||
exports.ellipsify = ellipsify; | ||
exports.parseUrl = parseUrl; | ||
@@ -142,0 +114,0 @@ exports.getPageName = getPageName; |
96501
33
2079