提交 3c6d4d57 编写于 作者: C Catouse

* update document.

上级 76b4487e
/*!
* ZUI - v1.3.0 - 2015-04-18
* ZUI - v1.3.0 - 2015-04-20
* http://zui.sexy
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2015 cnezsoft.com; Licensed MIT
......@@ -417,7 +417,7 @@ body {
display: block;
padding: 3px 8px;
color: #fff;
content: '按Enter键打开';
content: '按Enter键打开';
-webkit-transition: all .1s cubic-bezier(.175, .885, .32, 1);
-o-transition: all .1s cubic-bezier(.175, .885, .32, 1);
transition: all .1s cubic-bezier(.175, .885, .32, 1);
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
......@@ -29,7 +29,7 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/easysoft/zui" target="_blank">论坛</a></li>
<li><a href="https://github.com/easysoft/zui" target="_blank">Github</a></li>
<li><a href="https://github.com/easysoft/zui" target="_blank"><i class="icon icon-github"></i></a></li>
</ul>
</nav>
</div>
......
......@@ -9,8 +9,8 @@
[
{
"id": "qqgroup",
"name": "QQ",
"desc": "384135104",
"name": "QQ讨论",
"desc": "官方QQ群:384135104",
"icon": "icon-qq",
"url": null
},
......@@ -24,7 +24,7 @@
{
"id": "github",
"name": "Github",
"icon": "icon-code-fork",
"icon": "icon-github",
"desc": "Star或Fork来支持项目",
"url": "https://github.com/easysoft/zui"
},
......
/*!
* ZUI - v1.3.0 - 2015-04-18
* ZUI - v1.3.0 - 2015-04-20
* http://zui.sexy
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2015 cnezsoft.com; Licensed MIT
......@@ -52,11 +52,14 @@
var INDEX_JSON = 'index.json';
var UNDEFINED = undefined;
var PAGE_SHOW_FULL = 'page-show-full';
var dataVersion;
var storageEnable;
var dataset = {
// 'index.json': null
};
if(debug) window.dataset = dataset;
var sectionsShowed;
var scrollBarWidth = -1;
var bestPageWidth = 1120;
var $body, $window, $grid, $sectionTemplate,
......@@ -65,6 +68,20 @@
$pageContainer, $pageBody, $navbar,
$header, $sections, $chapterHeadings; // elements
var limitString = function(str, len) {
if(str && str.length > len) {
return str.substr(0, len) + '...[' + str.length + ']';
}
return str;
};
var getQueryString = function(name)
{
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]); return null;
};
var checkScrollbar = function()
{
if (document.body.clientWidth >= window.innerWidth) return;
......@@ -77,8 +94,6 @@
$body[0].removeChild(scrollDiv);
}
console.log('checkScrollbar', scrollBarWidth);
if (scrollBarWidth) {
var bodyPad = parseInt(($body.css('padding-right') || 0), 10);
$body.css('padding-right', bodyPad + scrollBarWidth);
......@@ -92,42 +107,57 @@
$navbar.css('padding-right', '');
};
var loadData = function(url, callback, forceLoad) {
var data = dataset[url];
var isFirstLoad = data === UNDEFINED || data === null;
if(isFirstLoad) {
data = $.store.get(url, null);
dataset[url] = data;
if(data !== null) {
if(debug) {
console.log('Load data from storage: ', url, ', size:', data.length);
var loadData = function(url, callback) {
var cacheData = dataset[url];
var isHasCache = cacheData && cacheData.version;
var isIndexJson = url === INDEX_JSON;
if(!isHasCache && storageEnable) {
var storedData = $.store.get('//' + url, null);
if(storedData !== null) {
var storedVersion = $.store.get('//' + url + '::V');
if(storedVersion) {
cacheData = {data: storedData, version: storedVersion};
dataset[url] = cacheData;
isHasCache = true;
if(debug) console.log('Load', url, 'from storage:', cacheData);
}
callback(data);
}
} else if(data !== null) {
if(debug) console.log('Load data from cache: ', url, ', size:', data.length);
callback(data);
}
if(isFirstLoad || data === null || forceLoad || isFirstLoad || (!saveTraffic)) {
var dataType = url.endsWith('.json') ? 'json' : 'html';
$.get(url, function(remoteData){
if(!debug && data !== null) {
if(dataType === 'json' && $.isPlainObject(remoteData) && data.version && remoteData.version && remoteData.version === data.version) return;
if(dataType === 'html' && data === remoteData) return;
}
dataset[url] = remoteData;
if(debug) {
console.log('Load data from remote: ', url, ', size:', remoteData.length);
}
callback(remoteData);
$.store.set(url, remoteData);
}, dataType);
if(isHasCache && (isIndexJson || cacheData.version === dataVersion)) {
if(debug) console.log('Load', url, 'from cache:', cacheData);
callback(cacheData.data);
if(!isIndexJson) return;
}
var dataType = url.endsWith('.json') ? 'json' : 'html';
$.get(url, function(data){
if(data !== null) {
if(isIndexJson) {
dataVersion = data.version;
}
cacheData = {data: data, version: dataVersion};
dataset[url] = cacheData;
$.store.set('//' + url, data);
$.store.set('//' + url + '::V', dataVersion);
if(debug) console.log('Load', url, 'from remote:', cacheData);
callback(data);
} else if(isHasCache && !isIndexJson) {
if(debug) console.log('Failed load', url, 'from remote, instead load cache:', cacheData);
callback(cacheData.data);
}
}, dataType).error(function(){
if(debug) console.error("Ajax error:", url);
if(isHasCache && !isIndexJson) {
if(debug) console.log('Failed load', url, 'from remote with error, instead load cache:', cacheData);
callback(cacheData.data);
}
});
};
var eachSection = function(callback, eachChapterCallback) {
var docIndex = dataset[INDEX_JSON];
var docIndex = dataset[INDEX_JSON].data;
if (!docIndex) {
console.error("Document index is empty.");
return false;
......@@ -184,18 +214,22 @@
$topics.remove('.card-content');
$tpl.addClass('without-topics');
}
$sectionList.append($tpl.addClass('show'));
$sectionList.append($tpl.addClass('show' + (sectionsShowed ? ' in' : '')));
}, function(chapter, sections){
var $sectionList = chapter.$sections;
$sectionList.children().remove();
return $sectionList;
})) {
$body.children('.loader').removeClass('loading');
clearTimeout($grid.data(LAST_RELOAD_ANIMATE_ID));
$grid.data(LAST_RELOAD_ANIMATE_ID, setTimeout(function(){
$sections = $grid.find('.section').addClass('in');
$chapterHeadings.addClass('in');
}, 100));
$sections = $grid.find('.section');
if(!sectionsShowed) {
clearTimeout($grid.data(LAST_RELOAD_ANIMATE_ID));
$grid.data(LAST_RELOAD_ANIMATE_ID, setTimeout(function(){
$sections.addClass('in');
$chapterHeadings.addClass('in');
}, 100));
sectionsShowed = true;
}
} else if(debug) {
console.error("Display sections failed.");
}
......@@ -361,7 +395,10 @@
};
var query = function(keyString) {
if(!$sections) return;
if(!$sections) {
if(debug) console.log('Query failed, $sections is empty. key:', keyString);
return;
}
if($queryInput.data('queryString') !== keyString) {
$queryInput.data('queryString', keyString).val(keyString);
......@@ -697,7 +734,7 @@
var $section;
if($.isArray(section)) {
var docIndex = dataset[INDEX_JSON];
var docIndex = dataset[INDEX_JSON].data;
if(docIndex && section.length > 1) {
var sectionId = section[1];
var sections = docIndex.chapters[section[0]].sections;
......@@ -792,18 +829,42 @@
chapter.id = chapterId;
chapter.$sections = $('#sections-' + chapterId);
});
bestPageWidth = $grid.children('.container').outerWidth();
$body.toggleClass(PAGE_SHOW_FULL, $.store.get(PAGE_SHOW_FULL, false));
// check storage
storageEnable = $.store && $.store.enable;
// Get document version
// dataVersion = $body.data('version');
// Setup ajax
$.ajaxSetup({cache: false});
// Load index.json
loadData(INDEX_JSON, function(data){
var firstLoad = !sectionsShowed;
displaySection(data);
var hash = window.location.hash
if(hash) {
hash = hash.substr(1);
setTimeout(function(){
openSection(hash.split('-'));
}, 300);
} else {
$queryInput.focus();
if(!firstLoad) {
var q = getQueryString('q');
if(q) {
setTimeout(function(){
query(q);
}, 300);
}
var hash = window.location.hash
if(hash) {
hash = hash.substr(1);
setTimeout(function(){
openSection(hash.split('-'));
}, 600);
} else {
$queryInput.focus();
}
}
});
......
此差异已折叠。
/*!
* ZUI - v1.3.0 - 2015-04-18
* ZUI - v1.3.0 - 2015-04-20
* http://zui.sexy
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2015 cnezsoft.com; Licensed MIT
......
/*!
* ZUI - v1.3.0 - 2015-04-18
* ZUI - v1.3.0 - 2015-04-20
* http://zui.sexy
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2015 cnezsoft.com; Licensed MIT
......
/*!
* ZUI - v1.3.0 - 2015-04-18
* ZUI - v1.3.0 - 2015-04-20
* http://zui.sexy
* GitHub: https://github.com/easysoft/zui.git
* Copyright (c) 2015 cnezsoft.com; Licensed MIT
......@@ -1585,7 +1585,12 @@
Store.prototype.get = function(key, defaultValue)
{
var val = this.deserialize(this.getItem(key));
return (defaultValue !== undefined && (typeof val === 'undefined' || val === null || val === undefined)) ? defaultValue : val;
if(typeof val === 'undefined' || val === null) {
if(typeof defaultValue !== 'undefined') {
return defaultValue;
}
}
return val;
};
/* Get item key by index and deserialize it */
......
此差异已折叠。
......@@ -214,10 +214,11 @@
return $sectionList;
})) {
$body.children('.loader').removeClass('loading');
$sections = $grid.find('.section');
if(!sectionsShowed) {
clearTimeout($grid.data(LAST_RELOAD_ANIMATE_ID));
$grid.data(LAST_RELOAD_ANIMATE_ID, setTimeout(function(){
$sections = $grid.find('.section').addClass('in');
$sections.addClass('in');
$chapterHeadings.addClass('in');
}, 100));
sectionsShowed = true;
......
......@@ -535,7 +535,7 @@ body {
&:before {
.transition-quickly();
content: '按Enter键打开';
content: '按Enter键打开';
display: block;
position: absolute;
right: -100%;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册