Skip to content
This repository was archived by the owner on Feb 1, 2018. It is now read-only.

Commit 9331441

Browse files
committed
Add pagination links : previous, next
1 parent 6cbeb9b commit 9331441

7 files changed

Lines changed: 197 additions & 14 deletions

File tree

dist/css/main.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/main.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
};
9090

9191
options = $.extend({}, defaults, options);
92-
if(options.github.access_token) {
92+
if (options.github.access_token) {
9393
options.github.access_token = atob(options.github.access_token);
9494
}
9595
if (options.method === 'github') {
@@ -494,7 +494,7 @@
494494
};
495495
};
496496

497-
Route.URLCtrl = function($scope, $location, $filter, data, commits, $timeout) {
497+
Route.URLCtrl = function($scope, $route, $location, $filter, data, commits, $timeout, pagination) {
498498
$timeout(function() {
499499
$location.path(data.locationPath);
500500
$scope.index = false;
@@ -506,6 +506,7 @@
506506
$scope.logoSrc = Docbase.options.logoSrc;
507507
$scope.docbaseOptions = Docbase.options;
508508

509+
509510
function versionIn(folder) {
510511
if (folder.name === data.currentFolder) {
511512
$scope.indexList = folder.files;
@@ -526,6 +527,8 @@
526527
}
527528
}
528529
} else {
530+
531+
$scope.paginationLinks = pagination.getLink($scope.map, $route.current.params);
529532
var contribut_array = [];
530533
if (!data.fail) {
531534
var content = data.markdown;
@@ -630,6 +633,7 @@
630633
}
631634
}
632635
};
636+
633637
Route.updatePath = function(params) {
634638
var map = Docbase.map;
635639
var version = params.version;
@@ -687,6 +691,71 @@
687691
};
688692
};
689693

694+
Route.pagination = function() {
695+
var pageObj = {
696+
getLink: function(map, path) {
697+
var currentVersion = path.version;
698+
var currentMap = map[currentVersion];
699+
var currentFolderKey, currentFileKey, currentFolder;
700+
currentMap.forEach(function(folder, folderKey) {
701+
if (folder.name == path.folder) {
702+
currentFolder = folder;
703+
currentFolderKey = folderKey;
704+
folder.files.forEach(function(files, fileKey) {
705+
if (files.name == path.file) {
706+
currentFileKey = fileKey;
707+
}
708+
});
709+
}
710+
});
711+
712+
var prevLink = function() {
713+
var targetLink, targetFileKey, targetfolderKey, targetFolder;
714+
if (currentFolderKey === 0 && currentFileKey === 0) {
715+
targetLink = null;
716+
} else {
717+
if (currentFileKey === 0) {
718+
targetfolderKey = currentFolderKey - 1;
719+
targetFolder = map[currentVersion][targetfolderKey];
720+
targetFileKey = targetFolder.files.length - 2;
721+
} else {
722+
targetFileKey = currentFileKey - 1;
723+
targetFolder = currentFolder;
724+
}
725+
targetLink = '#/' + currentVersion + '/' + targetFolder.name + '/' + targetFolder.files[targetFileKey].name;
726+
}
727+
return targetLink;
728+
};
729+
730+
var nextLink = function() {
731+
var targetLink, targetFileKey, targetfolderKey, targetFolder;
732+
if (currentFolderKey === map[currentVersion].length - 1 && currentFileKey === map[currentVersion][currentFolderKey].files.length - 2) {
733+
targetLink = null;
734+
} else {
735+
if (currentFileKey === map[currentVersion][currentFolderKey].files.length - 2) {
736+
targetfolderKey = currentFolderKey + 1;
737+
targetFolder = map[currentVersion][targetfolderKey];
738+
targetFileKey = 0;
739+
} else {
740+
targetFileKey = currentFileKey + 1;
741+
targetFolder = currentFolder;
742+
}
743+
targetLink = '#/' + currentVersion + '/' + targetFolder.name + '/' + targetFolder.files[targetFileKey].name;
744+
}
745+
return targetLink;
746+
};
747+
var paginationLinks = {
748+
'prev': prevLink(),
749+
'next': nextLink()
750+
};
751+
752+
return paginationLinks;
753+
}
754+
};
755+
756+
return pageObj;
757+
};
758+
690759
function cutTrailingSlashes(value) {
691760
if (!angular.isString(value)) {
692761
return value;
@@ -814,8 +883,9 @@
814883

815884
var angApp = angular.module('docbaseApp', ['ngRoute'], function() {})
816885
.factory('FlatdocService', ['$q', '$route', '$location', '$anchorScroll', '$http', Route.fetch])
817-
.controller('URLCtrl', ['$scope', '$location', '$filter', 'data', 'commits', '$timeout', Route.URLCtrl])
818-
.controller('VersionCtrl', ['$scope', '$route', '$location', '$filter', '$timeout', '$rootScope', Route.VersionCtrl])
886+
.service('Pagination', [Route.pagination])
887+
.controller('URLCtrl', ['$scope', '$route', '$location', '$filter', 'data', 'commits', '$timeout', 'Pagination', Route.URLCtrl])
888+
.controller('VersionCtrl', ['$scope', '$route', '$location', '$filter', '$timeout', '$rootScope', Route.VersionCtrl])
819889
.controller('MainCtrl', ['$scope', '$location', '$timeout', '$rootScope', Route.mainCtrl])
820890
.config(['$routeProvider', '$locationProvider', Route.config])
821891
.run(

dist/js/main.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/main.unique.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

html/flatdoc.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@
44
<div class="menubar">
55
<div class="menu section" role="flatdoc-menu"></div>
66
</div>
7-
<div role="flatdoc-content" class="content"></div>
7+
<div class="content">
8+
<div role="flatdoc-content"></div>
9+
10+
<div class="footer">
11+
<div class="row">
12+
<div class="col-xs-12">
13+
<span data-ng-class="{disabled: paginationLinks.prev == null}" class=" pull-left">
14+
<a href="{{paginationLinks.prev}}" class="paginationLink pull-left">Previous</a>
15+
</span>
16+
<span data-ng-class="{disabled: paginationLinks.next == null}" class="pull-right">
17+
<a href="{{paginationLinks.next}}" class="paginationLink pull-right">Next</a>
18+
</span>
19+
</div>
20+
</div>
21+
</div>
22+
</div>
823
<a data-ng-if="docbaseOptions.method == 'github'" class="edit" ng-href="{{github}}" target="_blank">
924
<span class="fa fa-pencil"> Edit</span>
1025
</a>

scripts/docbase.js

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
};
6363

6464
options = $.extend({}, defaults, options);
65-
if(options.github.access_token) {
65+
if (options.github.access_token) {
6666
options.github.access_token = atob(options.github.access_token);
6767
}
6868
if (options.method === 'github') {
@@ -467,7 +467,7 @@
467467
};
468468
};
469469

470-
Route.URLCtrl = function($scope, $location, $filter, data, commits, $timeout) {
470+
Route.URLCtrl = function($scope, $route, $location, $filter, data, commits, $timeout, pagination) {
471471
$timeout(function() {
472472
$location.path(data.locationPath);
473473
$scope.index = false;
@@ -479,6 +479,7 @@
479479
$scope.logoSrc = Docbase.options.logoSrc;
480480
$scope.docbaseOptions = Docbase.options;
481481

482+
482483
function versionIn(folder) {
483484
if (folder.name === data.currentFolder) {
484485
$scope.indexList = folder.files;
@@ -499,6 +500,8 @@
499500
}
500501
}
501502
} else {
503+
504+
$scope.paginationLinks = pagination.getLink($scope.map, $route.current.params);
502505
var contribut_array = [];
503506
if (!data.fail) {
504507
var content = data.markdown;
@@ -603,6 +606,7 @@
603606
}
604607
}
605608
};
609+
606610
Route.updatePath = function(params) {
607611
var map = Docbase.map;
608612
var version = params.version;
@@ -660,6 +664,71 @@
660664
};
661665
};
662666

667+
Route.pagination = function() {
668+
var pageObj = {
669+
getLink: function(map, path) {
670+
var currentVersion = path.version;
671+
var currentMap = map[currentVersion];
672+
var currentFolderKey, currentFileKey, currentFolder;
673+
currentMap.forEach(function(folder, folderKey) {
674+
if (folder.name == path.folder) {
675+
currentFolder = folder;
676+
currentFolderKey = folderKey;
677+
folder.files.forEach(function(files, fileKey) {
678+
if (files.name == path.file) {
679+
currentFileKey = fileKey;
680+
}
681+
});
682+
}
683+
});
684+
685+
var prevLink = function() {
686+
var targetLink, targetFileKey, targetfolderKey, targetFolder;
687+
if (currentFolderKey === 0 && currentFileKey === 0) {
688+
targetLink = null;
689+
} else {
690+
if (currentFileKey === 0) {
691+
targetfolderKey = currentFolderKey - 1;
692+
targetFolder = map[currentVersion][targetfolderKey];
693+
targetFileKey = targetFolder.files.length - 2;
694+
} else {
695+
targetFileKey = currentFileKey - 1;
696+
targetFolder = currentFolder;
697+
}
698+
targetLink = '#/' + currentVersion + '/' + targetFolder.name + '/' + targetFolder.files[targetFileKey].name;
699+
}
700+
return targetLink;
701+
};
702+
703+
var nextLink = function() {
704+
var targetLink, targetFileKey, targetfolderKey, targetFolder;
705+
if (currentFolderKey === map[currentVersion].length - 1 && currentFileKey === map[currentVersion][currentFolderKey].files.length - 2) {
706+
targetLink = null;
707+
} else {
708+
if (currentFileKey === map[currentVersion][currentFolderKey].files.length - 2) {
709+
targetfolderKey = currentFolderKey + 1;
710+
targetFolder = map[currentVersion][targetfolderKey];
711+
targetFileKey = 0;
712+
} else {
713+
targetFileKey = currentFileKey + 1;
714+
targetFolder = currentFolder;
715+
}
716+
targetLink = '#/' + currentVersion + '/' + targetFolder.name + '/' + targetFolder.files[targetFileKey].name;
717+
}
718+
return targetLink;
719+
};
720+
var paginationLinks = {
721+
'prev': prevLink(),
722+
'next': nextLink()
723+
};
724+
725+
return paginationLinks;
726+
}
727+
};
728+
729+
return pageObj;
730+
};
731+
663732
function cutTrailingSlashes(value) {
664733
if (!angular.isString(value)) {
665734
return value;
@@ -787,8 +856,9 @@
787856

788857
var angApp = angular.module('docbaseApp', ['ngRoute'], function() {})
789858
.factory('FlatdocService', ['$q', '$route', '$location', '$anchorScroll', '$http', Route.fetch])
790-
.controller('URLCtrl', ['$scope', '$location', '$filter', 'data', 'commits', '$timeout', Route.URLCtrl])
791-
.controller('VersionCtrl', ['$scope', '$route', '$location', '$filter', '$timeout', '$rootScope', Route.VersionCtrl])
859+
.service('Pagination', [Route.pagination])
860+
.controller('URLCtrl', ['$scope', '$route', '$location', '$filter', 'data', 'commits', '$timeout', 'Pagination', Route.URLCtrl])
861+
.controller('VersionCtrl', ['$scope', '$route', '$location', '$filter', '$timeout', '$rootScope', Route.VersionCtrl])
792862
.controller('MainCtrl', ['$scope', '$location', '$timeout', '$rootScope', Route.mainCtrl])
793863
.config(['$routeProvider', '$locationProvider', Route.config])
794864
.run(

styles/main.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,32 @@ li.L1,li.L3,li.L5,li.L7,li.L9 { }
322322
.index-container li a:hover{
323323
background: #f0f0f0;
324324
text-decoration: none;
325+
}
326+
.footer {
327+
padding-top: 40px;
328+
}
329+
.paginationLink {
330+
padding: 5px 10px;
331+
border: 1px solid #50BAEF;
332+
border-radius: 2px;
333+
}
334+
.paginationLink:hover {
335+
background: #50BAEF;
336+
color: #fff;
337+
border-color: #21a8eb;
338+
text-decoration: none;
339+
}
340+
.disabled {
341+
cursor: not-allowed;
342+
position: relative;
343+
opacity: 0.5;
344+
}
345+
.disabled:before {
346+
content: " ";
347+
position: absolute;
348+
left: 0;
349+
top: 0;
350+
width: 100%;
351+
height: 100%;
352+
z-index: 2;
325353
}

0 commit comments

Comments
 (0)