commit
11ed7f1cae
|
@ -1,20 +1,20 @@
|
|||
{
|
||||
"currentEnvironment": "JavaScript",
|
||||
"version": {
|
||||
"raw": "2.2.0-beta.0",
|
||||
"raw": "2.3.0-beta.0",
|
||||
"major": 2,
|
||||
"minor": 2,
|
||||
"minor": 3,
|
||||
"patch": 0,
|
||||
"prerelease": [
|
||||
"local"
|
||||
],
|
||||
"build": "sha.f6eeb79",
|
||||
"version": "2.2.0-local",
|
||||
"build": "sha.dfe65b3",
|
||||
"version": "2.3.0-local",
|
||||
"codeName": "snapshot",
|
||||
"isSnapshot": true,
|
||||
"full": "2.2.0-local+sha.f6eeb79",
|
||||
"full": "2.3.0-local+sha.dfe65b3",
|
||||
"branch": "master",
|
||||
"commitSHA": "f6eeb79d28bab55ae6d025f37368c4107bbcb408"
|
||||
"commitSHA": "dfe65b3ddbf365abd5b2e0a0b1f5972e38b8bc1c"
|
||||
},
|
||||
"sections": [
|
||||
{
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
{
|
||||
"currentEnvironment": "TypeScript",
|
||||
"version": {
|
||||
"raw": "2.2.0-beta.0",
|
||||
"raw": "2.3.0-beta.0",
|
||||
"major": 2,
|
||||
"minor": 2,
|
||||
"minor": 3,
|
||||
"patch": 0,
|
||||
"prerelease": [
|
||||
"local"
|
||||
],
|
||||
"build": "sha.f6eeb79",
|
||||
"version": "2.2.0-local",
|
||||
"build": "sha.dfe65b3",
|
||||
"version": "2.3.0-local",
|
||||
"codeName": "snapshot",
|
||||
"isSnapshot": true,
|
||||
"full": "2.2.0-local+sha.f6eeb79",
|
||||
"full": "2.3.0-local+sha.dfe65b3",
|
||||
"branch": "master",
|
||||
"commitSHA": "f6eeb79d28bab55ae6d025f37368c4107bbcb408"
|
||||
"commitSHA": "dfe65b3ddbf365abd5b2e0a0b1f5972e38b8bc1c"
|
||||
},
|
||||
"sections": [
|
||||
{
|
||||
|
|
|
@ -11,14 +11,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
api-list .docs-content{
|
||||
display: block;
|
||||
}
|
||||
|
||||
api-list + .main-footer{
|
||||
display: block;
|
||||
}
|
||||
|
||||
h1.original-english {
|
||||
margin-top: -($unit * 2);
|
||||
}
|
||||
|
@ -69,6 +61,14 @@
|
|||
display: none;
|
||||
}
|
||||
|
||||
api-list .docs-content{
|
||||
display: block;
|
||||
}
|
||||
|
||||
api-list + .main-footer{
|
||||
display:block;
|
||||
}
|
||||
|
||||
td, th {
|
||||
> p:last-child {
|
||||
margin-bottom: 0;
|
||||
|
@ -100,7 +100,7 @@ td, th {
|
|||
}
|
||||
}
|
||||
|
||||
body, .main-nav .main-nav-button,.translated-cn code {
|
||||
body, .main-nav .main-nav-button, .translated-cn code {
|
||||
font-family: "Helvetica Neue", Arial, STHeiti, "Microsoft YaHei", sans-serif, Helvetica, "DroidSansFallback", FreeSans, Arimo, "Droid Sans", "wenquanyi micro hei", "Hiragino Sans GB", "Hiragino Sans GB W3" !important;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,154 +1,154 @@
|
|||
// TODO: refactor me!
|
||||
var sourceVisible = localStorage.getItem('source-visible') === 'true';
|
||||
(function ($) {
|
||||
var content = document.querySelector('article');
|
||||
var footer = document.querySelector('.main-footer');
|
||||
if(!content || !footer){
|
||||
return;
|
||||
}
|
||||
processContainer(content);
|
||||
processContainer(footer);
|
||||
var content = document.querySelector('article');
|
||||
var footer = document.querySelector('.main-footer');
|
||||
|
||||
if (!sourceVisible) {
|
||||
var nodes = document.querySelectorAll('.original-english');
|
||||
_.each(nodes, function (node) {
|
||||
$(node).addClass('hidden');
|
||||
});
|
||||
}
|
||||
processContainer(content);
|
||||
processContainer(footer);
|
||||
|
||||
// restore
|
||||
if (!sourceVisible) {
|
||||
var nodes = document.querySelectorAll('.original-english');
|
||||
_.each(nodes, function (node) {
|
||||
$(node).addClass('hidden');
|
||||
});
|
||||
}
|
||||
|
||||
// restore
|
||||
if (content) {
|
||||
content.style.display = 'block';
|
||||
footer.style.display = 'block';
|
||||
}
|
||||
footer.style.display = 'block';
|
||||
|
||||
/**
|
||||
* Process container recursively.
|
||||
* @param container
|
||||
*/
|
||||
function processContainer(container) {
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
var count = 0;
|
||||
for (var i = 0; i < container.children.length; i++) {
|
||||
var node = container.children[i];
|
||||
var ignoredTagNames = ['CODE-EXAMPLE', 'SCRIPT', 'CODE', 'EM'];
|
||||
// ignore example code.
|
||||
if (node.classList.contains('code-example') ||
|
||||
ignoredTagNames.indexOf(node.tagName) >= 0) {
|
||||
continue;
|
||||
/**
|
||||
* Process container recursively.
|
||||
* @param container
|
||||
*/
|
||||
function processContainer(container) {
|
||||
if (!container) {
|
||||
return;
|
||||
}
|
||||
var count = 0;
|
||||
for (var i = 0; i < container.children.length; i++) {
|
||||
var node = container.children[i];
|
||||
var ignoredTagNames = ['CODE-EXAMPLE', 'SCRIPT', 'CODE', 'EM'];
|
||||
// ignore example code.
|
||||
if (node.classList.contains('code-example') ||
|
||||
ignoredTagNames.indexOf(node.tagName) >= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (node.tagName) {
|
||||
case 'P':
|
||||
case 'H1':
|
||||
case 'H2':
|
||||
case 'H3':
|
||||
case 'H4':
|
||||
case 'H5':
|
||||
case 'H6':
|
||||
case 'HEADER':
|
||||
count++;
|
||||
if (processBlock(node)) {
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case 'TD':
|
||||
case 'TH':
|
||||
case 'UL':
|
||||
case 'OL':
|
||||
case 'DIV':
|
||||
processContainer(node);
|
||||
break;
|
||||
default:
|
||||
if (processContainer(node) <= 1) {
|
||||
if (processBlock(node)) {
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (node.tagName) {
|
||||
case 'P':
|
||||
case 'H1':
|
||||
case 'H2':
|
||||
case 'H3':
|
||||
case 'H4':
|
||||
case 'H5':
|
||||
case 'H6':
|
||||
case 'HEADER':
|
||||
count++;
|
||||
if (processBlock(node)) {
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
break;
|
||||
case 'TD':
|
||||
case 'TH':
|
||||
case 'UL':
|
||||
case 'OL':
|
||||
case 'DIV':
|
||||
processContainer(node);
|
||||
break;
|
||||
default:
|
||||
if (processContainer(node) <= 1) {
|
||||
if (processBlock(node)) {
|
||||
i++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process block elements. The first element is original english, the
|
||||
* second element is translated one.
|
||||
* @param current the first element.
|
||||
* @returns {boolean} Is success?
|
||||
*/
|
||||
function processBlock(current) {
|
||||
var sibling = current.nextElementSibling;
|
||||
|
||||
var $current = $(current);
|
||||
var $sibling = $(sibling);
|
||||
|
||||
if (sibling) {
|
||||
if (isClonedNode(current, sibling)) {
|
||||
if (isPureEnglish(current.textContent)) {
|
||||
if (sibling.children) {
|
||||
processContainer(sibling);
|
||||
}
|
||||
$current.addClass('original-english');
|
||||
$sibling.addClass('translated');
|
||||
$sibling.addClass('translated-cn');
|
||||
$sibling.after($current);
|
||||
$sibling.on('click', function (event) {
|
||||
// for nested structure.
|
||||
event.stopPropagation();
|
||||
$current.toggleClass('hidden');
|
||||
});
|
||||
// addSpacingBetweenCnAndEn(sibling);
|
||||
return true;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process block elements. The first element is original english, the
|
||||
* second element is translated one.
|
||||
* @param current the first element.
|
||||
* @returns {boolean} Is success?
|
||||
*/
|
||||
function processBlock(current) {
|
||||
var sibling = current.nextElementSibling;
|
||||
return false;
|
||||
}
|
||||
|
||||
var $current = $(current);
|
||||
var $sibling = $(sibling);
|
||||
function isPureEnglish(text) {
|
||||
if (text) {
|
||||
text = text.replace('在线例子', '');
|
||||
return /^[\1-\255—’“”ç®…à\u200B]*$/.test(text);
|
||||
}
|
||||
return false;
|
||||
|
||||
if (sibling) {
|
||||
if (isClonedNode(current, sibling)) {
|
||||
if (isPureEnglish(current.textContent)) {
|
||||
if (sibling.children) {
|
||||
processContainer(sibling);
|
||||
}
|
||||
$current.addClass('original-english');
|
||||
$sibling.addClass('translated');
|
||||
$sibling.addClass('translated-cn');
|
||||
$sibling.after($current);
|
||||
$sibling.on('click', function (event) {
|
||||
// for nested structure.
|
||||
event.stopPropagation();
|
||||
$current.toggleClass('hidden');
|
||||
});
|
||||
// addSpacingBetweenCnAndEn(sibling);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function attributesToString(node) {
|
||||
return _.chain(node.attributes)
|
||||
.map(function (value) {
|
||||
if (value.name === 'id') {
|
||||
return '';
|
||||
} else {
|
||||
return value.name + '=' + value.value;
|
||||
}
|
||||
})
|
||||
.sortBy()
|
||||
.value()
|
||||
.join(';');
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
function isClonedNode(node1, node2) {
|
||||
return node1.tagName === node2.tagName && node1.tagName !== 'TR' &&
|
||||
attributesToString(node1) === attributesToString(node2);
|
||||
}
|
||||
|
||||
function isPureEnglish(text) {
|
||||
if (text) {
|
||||
text = text.replace('在线例子', '');
|
||||
return /^[\1-\255—’“”ç®…à\u200B]*$/.test(text);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
function attributesToString(node) {
|
||||
return _.chain(node.attributes)
|
||||
.map(function (value) {
|
||||
if (value.name === 'id') {
|
||||
return '';
|
||||
} else {
|
||||
return value.name + '=' + value.value;
|
||||
}
|
||||
})
|
||||
.sortBy()
|
||||
.value()
|
||||
.join(';');
|
||||
}
|
||||
|
||||
function isClonedNode(node1, node2) {
|
||||
return node1.tagName === node2.tagName && node1.tagName !== 'TR' &&
|
||||
attributesToString(node1) === attributesToString(node2);
|
||||
}
|
||||
|
||||
// function addSpacingBetweenCnAndEn(nodeCn) {
|
||||
// var text = nodeCn.innerHTML;
|
||||
// text = text.replace(/([\x20-\xff]+)/g, function (word) {
|
||||
// if (!word.replace(/\s/, '')) {
|
||||
// return '';
|
||||
// } else if (/<[^>]*>/.test(word)) {
|
||||
// return ' ' + word + ' ';
|
||||
// } else {
|
||||
// return ' ' + word + ' ';
|
||||
// }
|
||||
// });
|
||||
// nodeCn.innerHTML = text;
|
||||
// }
|
||||
// function addSpacingBetweenCnAndEn(nodeCn) {
|
||||
// var text = nodeCn.innerHTML;
|
||||
// text = text.replace(/([\x20-\xff]+)/g, function (word) {
|
||||
// if (!word.replace(/\s/, '')) {
|
||||
// return '';
|
||||
// } else if (/<[^>]*>/.test(word)) {
|
||||
// return ' ' + word + ' ';
|
||||
// } else {
|
||||
// return ' ' + word + ' ';
|
||||
// }
|
||||
// });
|
||||
// nodeCn.innerHTML = text;
|
||||
// }
|
||||
})(angular.element);
|
||||
|
|
Loading…
Reference in New Issue