Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | 1x 5x 5x 3x 3x 3x 30x 3x 5x 5x 38x 5x 3x 2x 3x 3x 2x 3x 1x 1x 1x 1x 2x 1x 2x 1x | import DefineMap from 'can-define/map/map';
/**
* @class ViewModel
* @memberof sp-paginate
*
* @description A `<sp-paginate />` component's ViewModel
*/
const ViewModel = DefineMap.extend('PaginateWidget', {
/** @lends sp-paginate.ViewModel.prototype*/
/**
* The number of pages to show in the widget
* @type {Number}
* @memberof sp-paginate.ViewModel.prototype
*/
pages: {
type: 'number',
default: 10
},
/**
* The active page index
* @type {Number}
* @memberof sp-paginate.ViewModel.prototype
*/
activePageIndex: {
default: 0,
type: 'number'
},
/**
* The number of pages to show on either side of the currently selected page. The default is 3. For example, if the selected page is 5, the visible pages should be 2,3,4,5,6,7,8.
* @type {Number}
* @memberof sp-paginate.ViewModel.prototype
*/
activeOffset: {
default: 3,
type: 'number'
},
/**
* A virtual property used by the template to indicate whether or not there is a next page
* @type {Boolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hasNext: {
get () {
return this.activePageIndex < this.pages - 1;
}
},
/**
* A virtual property used by the template to indicate whether or not there is a previous page
* @type {Boolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hasPrevious: {
get () {
return this.activePageIndex > 0;
}
},
/**
* The array of currently shown pages in the widget
* @type {Array<Number>}
* @memberof sp-paginate.ViewModel.prototype
*/
visiblePages: {
get () {
var pages = this.pages;
var active = this.activePageIndex + 1;
var arr = this.pageArray.filter((p) => {
return p <= active + 3 && p >= active - 3 && p > 0 && p <= pages;
});
return arr;
}
},
/**
* The array of numbers 0 through number of pages. This is a helper for the visiblePages getter
* @type {Array<Number>}
* @memberof sp-paginate.ViewModel.prototype
*/
pageArray: {
get () {
var arr = [];
for (var i = 1; i <= this.pages; i++) {
arr.push(i);
}
return arr;
}
},
/**
* Hides the first button
* @signature `<sp-paginate hide-first />`
* @type {HTMLBoolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hideFirst: {
type: 'htmlbool',
default: false
},
/**
* Hides the last button
* @signature `<sp-paginate hide-last />`
* @type {HTMLBoolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hideLast: {
type: 'htmlbool',
default: false
},
/**
* Hides the previous button
* @signature `<sp-paginate hide-previous />`
* @type {HTMLBoolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hidePrevious: {
type: 'htmlbool',
default: false
},
/**
* Hides the next button
* @signature `<sp-paginate hide-next />`
* @type {HTMLBoolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hideNext: {
type: 'htmlbool',
default: false
},
/**
* Hides the list of pages
* @signature `<sp-paginate hide-pages />`
* @type {HTMLBoolean}
* @memberof sp-paginate.ViewModel.prototype
*/
hidePages: {
type: 'htmlbool',
default: false
},
/**
* Navigates to the next page
* @return {Boolean} returns false to prevent the link from navigating to the next page
*/
gotoNext () {
if (this.hasNext) {
this.activePageIndex++;
}
return false;
},
/**
* Navigates to the previous page
* @return {Boolean} returns false to prevent the link from navigating to the next page
*/
gotoPrevious () {
if (this.hasPrevious) {
this.activePageIndex--;
}
return false;
},
/**
* Navigates to the first page
* @return {Boolean} returns false to prevent the link from navigating to the next page
*/
gotoFirst () {
this.activePageIndex = 0;
return false;
},
/**
* Navigates to the last page
* @return {Boolean} returns false to prevent the link from navigating to the next page
*/
gotoLast () {
this.activePageIndex = this.pages - 1;
return false;
},
/**
* Navigates to the page
* @param {Number} p The page index to navigate to
* @return {Boolean} returns false to prevent the link from navigating to the next page
*/
gotoPage (p) {
if (p > 0 && p <= this.pages) {
this.activePageIndex = p - 1;
}
return false;
},
/**
* Checks to see if the passed page is the active page index
* @param {Number} p The page to check
* @return {Boolean} Returns a boolean value that tells the template whether or not the passed page is the active page
*/
isActive (p) {
return this.activePageIndex === p - 1;
}
});
export default ViewModel;
|