From 114f879b3089a8b0ed3dc9a23e77d10f62000442 Mon Sep 17 00:00:00 2001 From: ruanwz Date: Wed, 23 Apr 2014 12:24:18 +0800 Subject: [PATCH] Display 7 CJK unicode characters at a time In the languages using CJK unicode, the words are not separated by spaces. So it needs to be separated manually. Need to adjust the WPM indicator for CJK unicode later. --- squirt.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/squirt.js b/squirt.js index 270581e..b2d00fd 100644 --- a/squirt.js +++ b/squirt.js @@ -235,13 +235,28 @@ sq.host = window.location.search.match('sq-dev') ? dispatch('squirt.play'); }; }; + //split for CJK unicode + String.prototype.squirt_split = function() { + var space_split_list = this.split(/[\s]+/g); + var final_list = []; + space_split_list.forEach( + function(i) { + if (i.match(/[\u3400-\u9FBF]/)) { + final_list = final_list.concat(i.match(/.{1,7}/g)); + } else { + final_list.push(i); + } + } + ) + return final_list; + } function makeTextToNodes(wordToNode) { return function textToNodes(text) { text = "3\n 2\n 1\n " + text.trim('\n').replace(/\s+\n/g,'\n'); return text .replace(/[\,\.\!\:\;](?![\"\'\)\]\}])/g, "$& ") - .split(/[\s]+/g) + .squirt_split() .filter(function(word){ return word.length; }) .map(wordToNode); };