mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 10:42:45 +03:00
parent
4b64336119
commit
6e1d5e8e0d
18
core/client/assets/vendor/countable.js
vendored
18
core/client/assets/vendor/countable.js
vendored
@ -3,7 +3,7 @@
|
||||
* counting on an HTML element.
|
||||
*
|
||||
* @author Sacha Schmid (<https://github.com/RadLikeWhoa>)
|
||||
* @version 2.0.0
|
||||
* @version 2.0.2
|
||||
* @license MIT
|
||||
* @see <http://radlikewhoa.github.io/Countable/>
|
||||
*/
|
||||
@ -124,9 +124,11 @@
|
||||
* `_extendDefaults` is a function to extend a set of default options with the
|
||||
* ones given in the function call. Available options are described below.
|
||||
*
|
||||
* {Boolean} hardReturns Use two returns to seperate a paragraph instead of
|
||||
* one.
|
||||
* {Boolean} stripTags Strip HTML tags before counting the values.
|
||||
* {Boolean} hardReturns Use two returns to seperate a paragraph instead
|
||||
* of one.
|
||||
* {Boolean} stripTags Strip HTML tags before counting the values.
|
||||
* {Boolean} ignoreReturns Ignore returns when calculating the `all`
|
||||
* property.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
@ -138,7 +140,7 @@
|
||||
*/
|
||||
|
||||
function _extendDefaults (options) {
|
||||
var defaults = { hardReturns: false, stripTags: false }
|
||||
var defaults = { hardReturns: false, stripTags: false, ignoreReturns: false }
|
||||
|
||||
for (var prop in options) {
|
||||
if (defaults.hasOwnProperty(prop)) defaults[prop] = options[prop]
|
||||
@ -163,7 +165,7 @@
|
||||
|
||||
function _count (element, options) {
|
||||
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
|
||||
@ -187,7 +189,7 @@
|
||||
paragraphs: trimmed ? (trimmed.match(options.hardReturns ? /\n{2,}/g : /\n+/g) || []).length + 1 : 0,
|
||||
words: trimmed ? (trimmed.replace(/['";:,.?¿\-!¡]+/g, '').match(/\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
|
||||
}
|
||||
}
|
||||
|
||||
@ -374,4 +376,4 @@
|
||||
} else {
|
||||
global.Countable = Countable
|
||||
}
|
||||
}(this))
|
||||
}(this))
|
||||
|
@ -153,4 +153,30 @@ CasperTest.begin("User settings screen validates email", 6, function suite(test)
|
||||
}, function onTimeout() {
|
||||
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…
Reference in New Issue
Block a user