diff --git a/README.md b/README.md index 3faa4cc..8c1026d 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ amWiki是一套非常简单基于atom编辑器markdown语法的轻量级wiki文 2. 安装Atom插件amWiki,并重启Atom - Atom菜单,File -> Setting -> Install -> 搜索`amWiki` - 或者,运行cmd:`apm install amWiki` - - 或者,从Github的 [amWiki项目托管](https://github.com/TevinLi/amWiki) 下载zip,解压到`C:\Users\Administrator\.atom\packages`,并将文件夹名`amWiki-master`改为`amWiki` + - 或者,从Github的 [amWiki项目托管·版本发布](https://github.com/TevinLi/amWiki/releases) 下载zip,解压到`C:\Users\Administrator\.atom\packages`,并将文件夹名`amWiki-master`改为`amWiki` 3. (在本地服务器静态目录)创建一个文件夹 diff --git a/files/amWiki.docs.js b/files/amWiki.docs.js index f66183a..48ea0d7 100644 --- a/files/amWiki.docs.js +++ b/files/amWiki.docs.js @@ -1,6 +1,6 @@ /** + * @desc 文档加载渲染模块 * @author Tevin - * @desc 文档加载渲染管理 */ ; @@ -12,6 +12,9 @@ var marked = win.marked; var URL_ENCODE_NAME = 'AMWikiUrlEncode'; //记录url编码的键名 + /** + * @class 创建一个文档管理对象 + */ var Docs = function () { this.$e = { win: $(win), diff --git a/files/amWiki.js b/files/amWiki.js index 5b9840b..552e4ac 100644 --- a/files/amWiki.js +++ b/files/amWiki.js @@ -1,9 +1,8 @@ /** - * amWiki - * https://github.com/TevinLi/amWiki - * by Tevin - * - * Released under the MIT license. + * @desc amwiki主执行模块 + * @author Tevin + * @see {@link https://github.com/TevinLi/amWiki} + * @license MIT - Released under the MIT license. */ $(function () { @@ -23,116 +22,144 @@ $(function () { //是否支持history.state的API (IE9不支持) var historyStated = 'pushState' in history; - //菜单折叠 + //页面基本显示与操作 var $menuBar = $('#menuBar'); - $menuBar.on('click', 'h5', function () { - var $this = $(this), - $next = $this.next('ul'); - if ($this.hasClass('on')) { - $this.removeClass('on'); - $next.slideUp(200); - } else { - $this.addClass('on'); - $next.slideDown(200); - } - }); - $menuBar.on('click', 'h4', function () { - var $this = $(this); - if (!$this.hasClass('on')) { - $this.addClass('on'); - $menuBar.find('a').removeClass('on'); - } - $menuBar.find('h5').removeClass('on').next('ul').hide(); - }); - $menuBar.on('click', 'strong', function () { - var $this = $(this), - $next = $this.next('ul'); - if ($this.hasClass('on')) { - $this.removeClass('on'); - $next.slideUp(200); - } else { - $this.addClass('on'); - $next.slideDown(200); - } - }); - //展开折叠所有导航栏位按钮 - var setMenuFolding = function () { - var $this = $(this); - if ($this.hasClass('on')) { - $this.removeClass('on').find('use').attr('xlink:href', '#navFolder1'); + var pageBase = function () { + //菜单折叠 + $menuBar.on('click', 'h5', function () { + var $this = $(this), + $next = $this.next('ul'); + if ($this.hasClass('on')) { + $this.removeClass('on'); + $next.slideUp(200); + } else { + $this.addClass('on'); + $next.slideDown(200); + } + }); + $menuBar.on('click', 'h4', function () { + var $this = $(this); + if (!$this.hasClass('on')) { + $this.addClass('on'); + $menuBar.find('a').removeClass('on'); + } $menuBar.find('h5').removeClass('on').next('ul').hide(); + }); + $menuBar.on('click', 'strong', function () { + var $this = $(this), + $next = $this.next('ul'); + if ($this.hasClass('on')) { + $this.removeClass('on'); + $next.slideUp(200); + } else { + $this.addClass('on'); + $next.slideDown(200); + } + }); + //展开折叠所有导航栏位按钮 + $('.menu-fold').on('click', function () { + var $this = $(this); + if ($this.hasClass('on')) { + $this.removeClass('on').find('use').attr('xlink:href', '#navFolder1'); + $menuBar.find('h5').removeClass('on').next('ul').hide(); + } else { + $this.addClass('on').find('use').attr('xlink:href', '#navFolder2'); + $menuBar.find('h5').addClass('on').next('ul').show(); + } + }); + //响应式菜单 + var $nav = $('.nav'), + $menuIcon = $('.menu_icon'); + $menuIcon.on('click', function () { + var $this = $(this); + if ($this.hasClass('close')) { + $this.removeClass('close'); + $menuIcon.find('use').attr('xlink:href', '#navStart'); + $nav.removeClass('on'); + } else { + $this.addClass('close'); + $menuIcon.find('use').attr('xlink:href', '#navClose'); + $nav.addClass('on'); + } + }); + $menuBar.on('click', 'li a', function () { + $nav.removeClass('on'); + }); + $menuBar.on('click', 'h4', function () { + $nav.removeClass('on'); + }); + //页面筛选 + var $filter = $('#menuFilter'); + var $filterClean = $filter.next('i'); + $filter.on('blur change input propertychange', function () { + var value = $filter.val(); + if (value != '') { + $filterClean.removeClass('off'); + $menuBar.find('h5').removeClass('on').next('ul').hide(); + $menuBar.find('a').each(function () { + var $this = $(this); + if ($this.text().indexOf(value) >= 0) { + $this.parent().removeClass('off').parent().show().prev('h5').addClass('on'); + } else { + $this.parent().addClass('off'); + } + }); + } else { + $filterClean.addClass('off'); + $menuBar.find('a').parent().removeClass('off'); + } + }); + $filterClean.on('click', function () { + $filter.val('').trigger('change'); + }); + //显示svg图标 + if (sessionStorage['AMWikiIconsSvg']) { + $('#svgSymbols').append(sessionStorage['AMWikiIconsSvg']); } else { - $this.addClass('on').find('use').attr('xlink:href', '#navFolder2'); - $menuBar.find('h5').addClass('on').next('ul').show(); + $.get('amWiki/images/icons.svg', function (svg) { + sessionStorage['AMWikiIconsSvg'] = svg; + $('#svgSymbols').append(svg); + }, 'text'); } }; - //响应式菜单 - var $nav = $('.nav'), - $menuIcon = $('.menu_icon'), - $win = $(window); - $menuIcon.on('click', function () { - var $this = $(this); - if ($this.hasClass('close')) { - $this.removeClass('close'); - $menuIcon.find('use').attr('xlink:href', '#navStart'); - $nav.removeClass('on'); + //改变导航显示 + var changeNav = function (path) { + if (path == '首页') { + $menuBar.find('h4').addClass('on'); + $menuBar.find('a').removeClass('on'); } else { - $this.addClass('close'); - $menuIcon.find('use').attr('xlink:href', '#navClose'); - $nav.addClass('on'); - } - }); - $menuBar.on('click', 'li a', function () { - $nav.removeClass('on'); - }); - $menuBar.on('click', 'h4', function () { - $nav.removeClass('on'); - }); - - //页面筛选 - var $filter = $('#menuFilter'); - var $filterClean = $filter.next('i'); - $filter.on('blur change input propertychange', function () { - var value = $filter.val(); - if (value != '') { - $filterClean.removeClass('off'); - $menuBar.find('h5').removeClass('on').next('ul').hide(); + var hsLink = false; $menuBar.find('a').each(function () { var $this = $(this); - if ($this.text().indexOf(value) >= 0) { - $this.parent().removeClass('off').parent().show().prev('h5').addClass('on'); + var path2 = $this.attr('href').split('file=')[1]; + if (path2 == path) { + hsLink = true; + //第一层 + var $prev = $this.addClass('on').parent().parent().show().prev().addClass('on'); + //第二层 + if ($prev[0].tagName.toLowerCase() == 'strong') { + $prev.parent().parent().show().prev().addClass('on'); + } } else { - $this.parent().addClass('off'); + $this.removeClass('on'); } }); - } else { - $filterClean.addClass('off'); - $menuBar.find('a').parent().removeClass('off'); + if (hsLink) { + $menuBar.find('h4').removeClass('on'); + } } - }); - $filterClean.on('click', function () { - $filter.val('').trigger('change'); - }); - - //显示svg图标 - if (sessionStorage['AMWikiIconsSvg']) { - $('#svgSymbols').append(sessionStorage['AMWikiIconsSvg']); - } else { - $.get('amWiki/images/icons.svg', function (svg) { - sessionStorage['AMWikiIconsSvg'] = svg; - $('#svgSymbols').append(svg); - }, 'text'); - } + }; //改变页面 - var changePage = function (path, firstOpen) { + var changePage = function (path, withOutPushState) { //第一步,从本地缓存读取并渲染页面 var localDoc = storage.read(path); docs.renderDoc(localDoc); + testing && testing.crawlContent(); //更新history记录 - if (!firstOpen && historyStated) { - history.pushState(null, '', '?file=' + path); + if (!withOutPushState && historyStated) { + history.pushState({path: path}, '', '?file=' + path); } //第二步,加载服务器上的文档资源,如果有更新重新渲染 docs.loadPage(path, function (type, content) { @@ -146,7 +173,7 @@ $(function () { } }); if (historyStated) { - history.pushState(null, '', '?file=首页'); + history.replaceState({path: '首页'}, '', '?file=首页'); } } //如果本地缓存不为空,但服务器文档读取失败,不进行任何操作 @@ -164,6 +191,29 @@ $(function () { }); }; + //读取目录导航 + var loadNav = function (callback) { + $.get('library/$navigation.md', function (data) { + $menuBar.html(marked(data)); + $menuBar + .find('h4').prepend('').end() + .find('h5').prepend(''); + //支持history api时,改变默认事件,导航不再跳转页面 + $menuBar.find('a').each(function () { + if (historyStated) { + var $this = $(this); + $this.on('click', function () { + var path = $this.attr('href').split('file=')[1]; + changeNav(path); + changePage(path); + return false; + }); + } + }); + callback && callback(); + }, 'text'); + }; + //解析地址参数 var path = tools.getURLParameter('file'); if (!path) { @@ -171,47 +221,28 @@ $(function () { } else { path = decodeURI(path); } - changePage(path, true); - //读取导航目录 - $.get('library/$navigation.md', function (data) { - $menuBar.html(marked(data)); - $('.menu-fold').on('click', setMenuFolding); - $menuBar - .find('h4').prepend('').end() - .find('h5').prepend(''); - //初次打开页面设置导航显示 - if (path == '首页') { - $menuBar.find('h4').addClass('on'); - } else { - var hsLink = false; - $menuBar.find('a').each(function () { - var $this = $(this); - var path2 = $(this).attr('href').split('file=')[1]; - if (path2 == path) { - hsLink = true; - //第一层 - var $prev = $this.addClass('on').parent().parent().show().prev().addClass('on'); - //第二层 - if ($prev[0].tagName.toLowerCase() == 'strong') { - $prev.parent().parent().show().prev().addClass('on'); - } - } else { - $this.removeClass('on'); - } - //支持历史api时改变默认事件 - if (historyStated) { - $this.on('click', function () { - changePage(path2); - return false; - }); - } - }); - if (hsLink) { - $menuBar.find('h4').removeClass('on'); - } - } - }, 'text'); + //页面基本 + pageBase(); + //加载导航 + loadNav(function () { + //首次打开改变导航 + changeNav(path); + //首次打开改变页面 + changePage(path, true); + }); + + //history api 前进后退响应 + if (historyStated) { + $(window).on('popstate', function (e) { + var path = e.originalEvent.state.path; + //改变导航 + changeNav(path); + //改变页面 + changePage(path, true); + }); + } }); + diff --git a/files/amWiki.storage.js b/files/amWiki.storage.js index b17d4c7..e713f1a 100644 --- a/files/amWiki.storage.js +++ b/files/amWiki.storage.js @@ -1,6 +1,6 @@ /** + * @desc 本地缓存模块 * @author Tevin - * @desc 本地缓存 */ ; @@ -11,6 +11,9 @@ var tools = win.tools; var LOCAL_STORAGE_NAME = 'AMWikiDataBase'; //本地数据localStorage键名 + /** + * @class 创建一个本地存储管理对象 + */ var Storage = function () { this.db = null; //内存中的文库缓存 this.bridgeLocalStorage('read'); diff --git a/files/amWiki.testing.js b/files/amWiki.testing.js index 537a52d..c428b4a 100644 --- a/files/amWiki.testing.js +++ b/files/amWiki.testing.js @@ -1,11 +1,16 @@ /** + * @desc 简单ajax测试模块 * @author Tevin - * @desc 简单发送ajax测试工具 - * 仅当页面存在“请求地址”、“请求类型”、“请求参数”三个h3标题时触发 + * @summary 仅当页面存在“请求地址”、“请求类型”、“请求参数”三个h3标题时触发 */ (function (win, doc, $) { + 'use strict'; + + /** + * @class 创建一个借口测试管理对象 + */ var Testing = function () { //缓存元素 this.$e = { @@ -121,6 +126,9 @@ //关闭测试面板 Testing.prototype.offPanel = function () { this.$e.testingShow.removeClass('show'); + if (this.$e.testingShow.hasClass('on')) { + this.displayBox('off'); + } //清除抓取参数 this.request.url = ''; this.request.method = ''; diff --git a/files/amWiki.tools.js b/files/amWiki.tools.js index 88002aa..0dd3a79 100644 --- a/files/amWiki.tools.js +++ b/files/amWiki.tools.js @@ -1,6 +1,6 @@ /** - * @author Tevin * @desc 工具集 + * @author Tevin */ ;