mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Merge pull request #2246 from knunery/issue#1432
Fixes client side bio character counter.
This commit is contained in:
commit
36102d4f9f
2 changed files with 36 additions and 8 deletions
14
core/client/assets/vendor/countable.js
vendored
14
core/client/assets/vendor/countable.js
vendored
|
@ -3,7 +3,7 @@
|
||||||
* counting on an HTML element.
|
* counting on an HTML element.
|
||||||
*
|
*
|
||||||
* @author Sacha Schmid (<https://github.com/RadLikeWhoa>)
|
* @author Sacha Schmid (<https://github.com/RadLikeWhoa>)
|
||||||
* @version 2.0.0
|
* @version 2.0.2
|
||||||
* @license MIT
|
* @license MIT
|
||||||
* @see <http://radlikewhoa.github.io/Countable/>
|
* @see <http://radlikewhoa.github.io/Countable/>
|
||||||
*/
|
*/
|
||||||
|
@ -124,9 +124,11 @@
|
||||||
* `_extendDefaults` is a function to extend a set of default options with the
|
* `_extendDefaults` is a function to extend a set of default options with the
|
||||||
* ones given in the function call. Available options are described below.
|
* ones given in the function call. Available options are described below.
|
||||||
*
|
*
|
||||||
* {Boolean} hardReturns Use two returns to seperate a paragraph instead of
|
* {Boolean} hardReturns Use two returns to seperate a paragraph instead
|
||||||
* one.
|
* of one.
|
||||||
* {Boolean} stripTags Strip HTML tags before counting the values.
|
* {Boolean} stripTags Strip HTML tags before counting the values.
|
||||||
|
* {Boolean} ignoreReturns Ignore returns when calculating the `all`
|
||||||
|
* property.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
*
|
*
|
||||||
|
@ -138,7 +140,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function _extendDefaults (options) {
|
function _extendDefaults (options) {
|
||||||
var defaults = { hardReturns: false, stripTags: false }
|
var defaults = { hardReturns: false, stripTags: false, ignoreReturns: false }
|
||||||
|
|
||||||
for (var prop in options) {
|
for (var prop in options) {
|
||||||
if (defaults.hasOwnProperty(prop)) defaults[prop] = options[prop]
|
if (defaults.hasOwnProperty(prop)) defaults[prop] = options[prop]
|
||||||
|
@ -163,7 +165,7 @@
|
||||||
|
|
||||||
function _count (element, options) {
|
function _count (element, options) {
|
||||||
var original = 'value' in element ? element.value : element.innerText || element.textContent,
|
var original = 'value' in element ? element.value : element.innerText || element.textContent,
|
||||||
temp, trimmed
|
trimmed
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The initial implementation to allow for HTML tags stripping was created
|
* The initial implementation to allow for HTML tags stripping was created
|
||||||
|
@ -187,7 +189,7 @@
|
||||||
paragraphs: trimmed ? (trimmed.match(options.hardReturns ? /\n{2,}/g : /\n+/g) || []).length + 1 : 0,
|
paragraphs: trimmed ? (trimmed.match(options.hardReturns ? /\n{2,}/g : /\n+/g) || []).length + 1 : 0,
|
||||||
words: trimmed ? (trimmed.replace(/['";:,.?¿\-!¡]+/g, '').match(/\S+/g) || []).length : 0,
|
words: trimmed ? (trimmed.replace(/['";:,.?¿\-!¡]+/g, '').match(/\S+/g) || []).length : 0,
|
||||||
characters: trimmed ? _decode(trimmed.replace(/\s/g, '')).length : 0,
|
characters: trimmed ? _decode(trimmed.replace(/\s/g, '')).length : 0,
|
||||||
all: _decode(original.replace(/[\n\r]/g, '')).length
|
all: _decode(options.ignoreReturns ? original.replace(/[\n\r]/g, '') : original).length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -154,3 +154,29 @@ CasperTest.begin("User settings screen validates email", 6, function suite(test)
|
||||||
test.assert(false, 'No success notification :(');
|
test.assert(false, 'No success notification :(');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CasperTest.begin("User settings screen shows remaining characters for Bio properly", 4, function suite(test) {
|
||||||
|
|
||||||
|
function getRemainingBioCharacterCount() {
|
||||||
|
return casper.getHTML('.word-count');
|
||||||
|
}
|
||||||
|
|
||||||
|
casper.thenOpen(url + "ghost/settings/user/", function testTitleAndUrl() {
|
||||||
|
test.assertTitle("Ghost Admin", "Ghost admin has no title");
|
||||||
|
test.assertUrlMatch(/ghost\/settings\/user\/$/, "Ghost doesn't require login this time");
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function checkCharacterCount() {
|
||||||
|
test.assert(getRemainingBioCharacterCount() === '200', 'Bio remaining characters is 200');
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function setBioToValid() {
|
||||||
|
casper.fillSelectors('.user-profile', {
|
||||||
|
'#user-bio': 'asdf\n' // 5 characters
|
||||||
|
}, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
casper.then(function checkCharacterCount() {
|
||||||
|
test.assert(getRemainingBioCharacterCount() === '195', 'Bio remaining characters is 195');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue