fix api display

This commit is contained in:
Rex YE 2016-11-26 14:53:33 +00:00
parent dfe65b3ddb
commit d9c651fa47
4 changed files with 157 additions and 157 deletions

View File

@ -1,20 +1,20 @@
{ {
"currentEnvironment": "JavaScript", "currentEnvironment": "JavaScript",
"version": { "version": {
"raw": "2.2.0-beta.0", "raw": "2.3.0-beta.0",
"major": 2, "major": 2,
"minor": 2, "minor": 3,
"patch": 0, "patch": 0,
"prerelease": [ "prerelease": [
"local" "local"
], ],
"build": "sha.f6eeb79", "build": "sha.dfe65b3",
"version": "2.2.0-local", "version": "2.3.0-local",
"codeName": "snapshot", "codeName": "snapshot",
"isSnapshot": true, "isSnapshot": true,
"full": "2.2.0-local+sha.f6eeb79", "full": "2.3.0-local+sha.dfe65b3",
"branch": "master", "branch": "master",
"commitSHA": "f6eeb79d28bab55ae6d025f37368c4107bbcb408" "commitSHA": "dfe65b3ddbf365abd5b2e0a0b1f5972e38b8bc1c"
}, },
"sections": [ "sections": [
{ {

View File

@ -1,20 +1,20 @@
{ {
"currentEnvironment": "TypeScript", "currentEnvironment": "TypeScript",
"version": { "version": {
"raw": "2.2.0-beta.0", "raw": "2.3.0-beta.0",
"major": 2, "major": 2,
"minor": 2, "minor": 3,
"patch": 0, "patch": 0,
"prerelease": [ "prerelease": [
"local" "local"
], ],
"build": "sha.f6eeb79", "build": "sha.dfe65b3",
"version": "2.2.0-local", "version": "2.3.0-local",
"codeName": "snapshot", "codeName": "snapshot",
"isSnapshot": true, "isSnapshot": true,
"full": "2.2.0-local+sha.f6eeb79", "full": "2.3.0-local+sha.dfe65b3",
"branch": "master", "branch": "master",
"commitSHA": "f6eeb79d28bab55ae6d025f37368c4107bbcb408" "commitSHA": "dfe65b3ddbf365abd5b2e0a0b1f5972e38b8bc1c"
}, },
"sections": [ "sections": [
{ {

View File

@ -11,14 +11,6 @@
} }
} }
api-list .docs-content{
display: block;
}
api-list + .main-footer{
display: block;
}
h1.original-english { h1.original-english {
margin-top: -($unit * 2); margin-top: -($unit * 2);
} }
@ -69,6 +61,14 @@
display: none; display: none;
} }
api-list .docs-content{
display: block;
}
api-list + .main-footer{
display:block;
}
td, th { td, th {
> p:last-child { > p:last-child {
margin-bottom: 0; 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; 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;
} }

View File

@ -1,154 +1,154 @@
// TODO: refactor me! // TODO: refactor me!
var sourceVisible = localStorage.getItem('source-visible') === 'true'; var sourceVisible = localStorage.getItem('source-visible') === 'true';
(function ($) { (function ($) {
var content = document.querySelector('article'); var content = document.querySelector('article');
var footer = document.querySelector('.main-footer'); var footer = document.querySelector('.main-footer');
if(!content || !footer){
return;
}
processContainer(content);
processContainer(footer);
if (!sourceVisible) { processContainer(content);
var nodes = document.querySelectorAll('.original-english'); processContainer(footer);
_.each(nodes, function (node) {
$(node).addClass('hidden');
});
}
// restore if (!sourceVisible) {
var nodes = document.querySelectorAll('.original-english');
_.each(nodes, function (node) {
$(node).addClass('hidden');
});
}
// restore
if (content) {
content.style.display = 'block'; content.style.display = 'block';
footer.style.display = 'block'; }
footer.style.display = 'block';
/** /**
* Process container recursively. * Process container recursively.
* @param container * @param container
*/ */
function processContainer(container) { function processContainer(container) {
if (!container) { if (!container) {
return; return;
} }
var count = 0; var count = 0;
for (var i = 0; i < container.children.length; i++) { for (var i = 0; i < container.children.length; i++) {
var node = container.children[i]; var node = container.children[i];
var ignoredTagNames = ['CODE-EXAMPLE', 'SCRIPT', 'CODE', 'EM']; var ignoredTagNames = ['CODE-EXAMPLE', 'SCRIPT', 'CODE', 'EM'];
// ignore example code. // ignore example code.
if (node.classList.contains('code-example') || if (node.classList.contains('code-example') ||
ignoredTagNames.indexOf(node.tagName) >= 0) { ignoredTagNames.indexOf(node.tagName) >= 0) {
continue; 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) { return count;
case 'P': }
case 'H1':
case 'H2': /**
case 'H3': * Process block elements. The first element is original english, the
case 'H4': * second element is translated one.
case 'H5': * @param current the first element.
case 'H6': * @returns {boolean} Is success?
case 'HEADER': */
count++; function processBlock(current) {
if (processBlock(node)) { var sibling = current.nextElementSibling;
i++;
count++; var $current = $(current);
} var $sibling = $(sibling);
break;
case 'TD': if (sibling) {
case 'TH': if (isClonedNode(current, sibling)) {
case 'UL': if (isPureEnglish(current.textContent)) {
case 'OL': if (sibling.children) {
case 'DIV': processContainer(sibling);
processContainer(node); }
break; $current.addClass('original-english');
default: $sibling.addClass('translated');
if (processContainer(node) <= 1) { $sibling.addClass('translated-cn');
if (processBlock(node)) { $sibling.after($current);
i++; $sibling.on('click', function (event) {
count++; // for nested structure.
} event.stopPropagation();
} $current.toggleClass('hidden');
break; });
} // addSpacingBetweenCnAndEn(sibling);
return true;
} }
}
return count;
} }
/** return false;
* 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); function isPureEnglish(text) {
var $sibling = $(sibling); if (text) {
text = text.replace('在线例子', '');
return /^[\1-\255—“”ç®…à\u200B]*$/.test(text);
}
return false;
if (sibling) { }
if (isClonedNode(current, sibling)) {
if (isPureEnglish(current.textContent)) { function attributesToString(node) {
if (sibling.children) { return _.chain(node.attributes)
processContainer(sibling); .map(function (value) {
} if (value.name === 'id') {
$current.addClass('original-english'); return '';
$sibling.addClass('translated'); } else {
$sibling.addClass('translated-cn'); return value.name + '=' + value.value;
$sibling.after($current);
$sibling.on('click', function (event) {
// for nested structure.
event.stopPropagation();
$current.toggleClass('hidden');
});
// addSpacingBetweenCnAndEn(sibling);
return true;
}
}
} }
})
.sortBy()
.value()
.join(';');
}
return false; function isClonedNode(node1, node2) {
} return node1.tagName === node2.tagName && node1.tagName !== 'TR' &&
attributesToString(node1) === attributesToString(node2);
}
function isPureEnglish(text) { // function addSpacingBetweenCnAndEn(nodeCn) {
if (text) { // var text = nodeCn.innerHTML;
text = text.replace('在线例子', ''); // text = text.replace(/([\x20-\xff]+)/g, function (word) {
return /^[\1-\255—“”ç®…à\u200B]*$/.test(text); // if (!word.replace(/\s/, '')) {
} // return '';
return false; // } else if (/<[^>]*>/.test(word)) {
// return ' ' + word + ' ';
} // } else {
// return ' ' + word + ' ';
function attributesToString(node) { // }
return _.chain(node.attributes) // });
.map(function (value) { // nodeCn.innerHTML = text;
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;
// }
})(angular.element); })(angular.element);