pager.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /**
  2. * DevExtreme (ui/pager.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var $ = require("../core/renderer");
  11. var eventsEngine = require("../events/core/events_engine");
  12. var Class = require("../core/class");
  13. var stringUtils = require("../core/utils/string");
  14. var registerComponent = require("../core/component_registrator");
  15. var commonUtils = require("../core/utils/common");
  16. var each = require("../core/utils/iterator").each;
  17. var typeUtils = require("../core/utils/type");
  18. var extend = require("../core/utils/extend").extend;
  19. var clickEvent = require("../events/click");
  20. var pointerEvents = require("../events/pointer");
  21. var messageLocalization = require("../localization/message");
  22. var Widget = require("./widget/ui.widget");
  23. var SelectBox = require("./select_box");
  24. var NumberBox = require("./number_box");
  25. var eventUtils = require("../events/utils");
  26. var accessibility = require("./shared/accessibility");
  27. var PAGES_LIMITER = 4;
  28. var PAGER_CLASS = "dx-pager";
  29. var PAGER_PAGE_CLASS = "dx-page";
  30. var PAGER_PAGE_CLASS_SELECTOR = "." + PAGER_PAGE_CLASS;
  31. var PAGER_PAGES_CLASS = "dx-pages";
  32. var LIGHT_MODE_CLASS = "dx-light-mode";
  33. var LIGHT_PAGES_CLASS = "dx-light-pages";
  34. var PAGER_PAGE_INDEX_CLASS = "dx-page-index";
  35. var PAGER_PAGES_COUNT_CLASS = "dx-pages-count";
  36. var PAGER_SELECTION_CLASS = "dx-selection";
  37. var PAGER_PAGE_SEPARATOR_CLASS = "dx-separator";
  38. var PAGER_PAGE_SIZES_CLASS = "dx-page-sizes";
  39. var PAGER_PAGE_SIZE_CLASS = "dx-page-size";
  40. var PAGER_PAGE_SIZE_CLASS_SELECTOR = "." + PAGER_PAGE_SIZE_CLASS;
  41. var PAGER_NAVIGATE_BUTTON = "dx-navigate-button";
  42. var PAGER_PREV_BUTTON_CLASS = "dx-prev-button";
  43. var PAGER_NEXT_BUTTON_CLASS = "dx-next-button";
  44. var PAGER_INFO_CLASS = "dx-info";
  45. var PAGER_INFO_TEXT_CLASS = "dx-info-text";
  46. var PAGER_BUTTON_DISABLE_CLASS = "dx-button-disable";
  47. var Page = Class.inherit({
  48. ctor: function(value, index) {
  49. var that = this;
  50. that.index = index;
  51. that._$page = $("<div>").text(value).addClass(PAGER_PAGE_CLASS)
  52. },
  53. value: function(_value) {
  54. var that = this;
  55. if (typeUtils.isDefined(_value)) {
  56. that._$page.text(_value)
  57. } else {
  58. var text = that._$page.text();
  59. if (typeUtils.isNumeric(text)) {
  60. return parseInt(text)
  61. } else {
  62. return text
  63. }
  64. }
  65. },
  66. element: function() {
  67. return this._$page
  68. },
  69. select: function(value) {
  70. this._$page.toggleClass(PAGER_SELECTION_CLASS, value)
  71. },
  72. render: function(rootElement, rtlEnabled) {
  73. rtlEnabled ? this._$page.prependTo(rootElement) : this._$page.appendTo(rootElement)
  74. }
  75. });
  76. var Pager = Widget.inherit({
  77. _getDefaultOptions: function() {
  78. return extend(this.callBase(), {
  79. visible: true,
  80. pagesNavigatorVisible: "auto",
  81. pageIndex: 1,
  82. maxPagesCount: 10,
  83. pageCount: 10,
  84. totalCount: 0,
  85. pageSize: 5,
  86. showPageSizes: true,
  87. pageSizes: [5, 10],
  88. hasKnownLastPage: true,
  89. showNavigationButtons: false,
  90. showInfo: false,
  91. infoText: messageLocalization.getFormatter("dxPager-infoText"),
  92. pagesCountText: messageLocalization.getFormatter("dxPager-pagesCountText"),
  93. rtlEnabled: false,
  94. lightModeEnabled: false,
  95. pageIndexChanged: commonUtils.noop,
  96. pageSizeChanged: commonUtils.noop
  97. })
  98. },
  99. _toggleVisibility: function(value) {
  100. var $element = this.$element();
  101. if ($element) {
  102. $element.css("display", value ? "" : "none")
  103. }
  104. },
  105. _getPages: function(currentPage, count) {
  106. var pages = [];
  107. var showMoreButton = !this.option("hasKnownLastPage");
  108. var firstValue;
  109. var i;
  110. if (count > 0 || showMoreButton) {
  111. if (count <= this.option("maxPagesCount")) {
  112. for (i = 1; i <= count; i++) {
  113. pages.push(new Page(i, i - 1))
  114. }
  115. if (showMoreButton) {
  116. pages.push(new Page(">", i - 1))
  117. }
  118. } else {
  119. pages.push(new Page(1, 0));
  120. firstValue = currentPage ? currentPage.value() - currentPage.index : 1;
  121. for (i = 1; i <= PAGES_LIMITER; i++) {
  122. pages.push(new Page(firstValue + i, i))
  123. }
  124. pages.push(new Page(count, PAGES_LIMITER + 1));
  125. if (showMoreButton) {
  126. pages.push(new Page(">", PAGES_LIMITER + 1))
  127. }
  128. }
  129. }
  130. return pages
  131. },
  132. _getPageByValue: function(value) {
  133. var that = this;
  134. var page;
  135. var i;
  136. for (i = 0; i < that._pages.length; i++) {
  137. page = that._pages[i];
  138. if (page.value() === value) {
  139. return page
  140. }
  141. }
  142. },
  143. _processSelectedPage: function(maxPagesCount, pageIndex, pageCount) {
  144. var that = this;
  145. var isPageIndexValid = false;
  146. var selectedPageIndex;
  147. if (that._pages) {
  148. each(that._pages, function(key, page) {
  149. if (pageIndex === page.value()) {
  150. isPageIndexValid = true
  151. }
  152. });
  153. if (!isPageIndexValid) {
  154. that.selectedPage = null
  155. }
  156. }
  157. if (typeUtils.isDefined(that.selectedPage)) {
  158. if (pageIndex === pageCount && pageCount > maxPagesCount && that.selectedPage.index !== PAGES_LIMITER + 1) {
  159. that.selectedPage.index = PAGES_LIMITER + 1
  160. }
  161. } else {
  162. if (pageIndex > PAGES_LIMITER && pageIndex < pageCount) {
  163. selectedPageIndex = pageCount - PAGES_LIMITER < pageIndex ? PAGES_LIMITER - (pageCount - pageIndex) + 1 : 2;
  164. that.selectedPage = new Page(pageIndex, selectedPageIndex)
  165. }
  166. }
  167. },
  168. _selectPageByValue: function(value) {
  169. var that = this;
  170. var i;
  171. var page = that._getPageByValue(value);
  172. var pages = that._pages;
  173. var pagesLength = pages.length;
  174. var nextPage;
  175. var morePage;
  176. if (!typeUtils.isDefined(page)) {
  177. return
  178. }
  179. var prevPage = that._pages[page.index - 1];
  180. nextPage = that._pages[page.index + 1];
  181. if (nextPage && ">" === nextPage.value()) {
  182. morePage = nextPage;
  183. nextPage = void 0;
  184. pagesLength--;
  185. pages.pop()
  186. }
  187. if (that.selectedPage) {
  188. that.selectedPage.select(false)
  189. }
  190. page.select(true);
  191. that.selectedPage = page;
  192. if (nextPage && nextPage.value() - value > 1) {
  193. if (0 !== page.index) {
  194. prevPage.value(value + 1);
  195. that._pages.splice(page.index, 1);
  196. that._pages.splice(page.index - 1, 0, page);
  197. that._pages[page.index].index = page.index;
  198. page.index = page.index - 1;
  199. for (i = page.index - 1; i > 0; i--) {
  200. that._pages[i].value(that._pages[i + 1].value() - 1)
  201. }
  202. } else {
  203. for (i = 0; i < pagesLength - 1; i++) {
  204. that._pages[i].value(i + 1)
  205. }
  206. }
  207. }
  208. if (prevPage && value - prevPage.value() > 1) {
  209. if (page.index !== pagesLength - 1) {
  210. nextPage.value(value - 1);
  211. that._pages.splice(page.index, 1);
  212. that._pages.splice(page.index + 1, 0, page);
  213. that._pages[page.index].index = page.index;
  214. page.index = page.index + 1;
  215. for (i = page.index + 1; i < pagesLength - 1; i++) {
  216. that._pages[i].value(that._pages[i - 1].value() + 1)
  217. }
  218. } else {
  219. for (i = 1; i <= pagesLength - 2; i++) {
  220. that._pages[pagesLength - 1 - i].value(that._pages[pagesLength - 1].value() - i)
  221. }
  222. }
  223. }
  224. if (morePage) {
  225. pages.push(morePage)
  226. }
  227. },
  228. _updatePagesTabIndices: function() {
  229. var _this = this;
  230. var $selectedPage = this.selectedPage._$page;
  231. var updatePageIndices = function updatePageIndices() {
  232. var buttons = $(_this.element()).find("[role=button]:not(.dx-button-disable)");
  233. each(buttons, function(_, element) {
  234. return $(element).attr("tabindex", 0)
  235. });
  236. eventsEngine.off($selectedPage, "focus", updatePageIndices)
  237. };
  238. eventsEngine.on($selectedPage, "focus", updatePageIndices)
  239. },
  240. _nextPage: function(direction) {
  241. var pageIndex = this.option("pageIndex");
  242. var pageCount = this.option("pageCount");
  243. if (typeUtils.isDefined(pageIndex)) {
  244. pageIndex = "next" === direction ? ++pageIndex : --pageIndex;
  245. if (pageIndex > 0 && pageIndex <= pageCount) {
  246. this.option("pageIndex", pageIndex)
  247. }
  248. }
  249. },
  250. _wrapClickAction: function(action) {
  251. var _this2 = this;
  252. return function(e) {
  253. if ("dxpointerup" === e.type) {
  254. _this2._pointerUpHappened = true
  255. } else {
  256. if (_this2._pointerUpHappened) {
  257. _this2._pointerUpHappened = false;
  258. return
  259. }
  260. }
  261. action({
  262. event: e
  263. })
  264. }
  265. },
  266. _renderPages: function(pages) {
  267. var that = this;
  268. var $separator;
  269. var pagesLength = pages.length;
  270. var clickPagesIndexAction = that._createAction(function(args) {
  271. var e = args.event;
  272. var pageNumber = $(e.target).text();
  273. var pageIndex = ">" === pageNumber ? that.option("pageCount") + 1 : Number(pageNumber);
  274. that.option("pageIndex", pageIndex)
  275. });
  276. var page;
  277. if (pagesLength > 1) {
  278. that._pageClickHandler = this._wrapClickAction(clickPagesIndexAction);
  279. eventsEngine.on(that._$pagesChooser, eventUtils.addNamespace([pointerEvents.up, clickEvent.name], that.Name + "Pages"), PAGER_PAGE_CLASS_SELECTOR, that._pageClickHandler);
  280. accessibility.registerKeyboardAction("pager", that, that._$pagesChooser, PAGER_PAGE_CLASS_SELECTOR, clickPagesIndexAction)
  281. }
  282. for (var i = 0; i < pagesLength; i++) {
  283. page = pages[i];
  284. page.render(that._$pagesChooser, that.option("rtlEnabled"));
  285. that.setAria({
  286. role: "button",
  287. label: "Page " + page.value()
  288. }, page.element());
  289. accessibility.setTabIndex(that, page.element());
  290. if (pages[i + 1] && pages[i + 1].value() - page.value() > 1) {
  291. $separator = $("<div>").text(". . .").addClass(PAGER_PAGE_SEPARATOR_CLASS);
  292. that.option("rtlEnabled") ? $separator.prependTo(that._$pagesChooser) : $separator.appendTo(that._$pagesChooser)
  293. }
  294. }
  295. },
  296. _calculateLightPagesWidth: function($pageIndex, pageCount) {
  297. return Number($pageIndex.css("minWidth").replace("px", "")) + 10 * pageCount.toString().length
  298. },
  299. _renderLightPages: function() {
  300. var that = this;
  301. var pageCount = this.option("pageCount");
  302. var pageIndex = this.option("pageIndex");
  303. var clickAction = that._createAction(function() {
  304. that.option("pageIndex", pageCount)
  305. });
  306. var pagesCountText = this.option("pagesCountText");
  307. var $container = $("<div>").addClass(LIGHT_PAGES_CLASS).appendTo(this._$pagesChooser);
  308. var $pageIndex = $("<div>").addClass(PAGER_PAGE_INDEX_CLASS).appendTo($container);
  309. that._pageIndexEditor = that._createComponent($pageIndex, NumberBox, {
  310. value: pageIndex,
  311. min: 1,
  312. max: pageCount,
  313. width: that._calculateLightPagesWidth($pageIndex, pageCount),
  314. onValueChanged: function(e) {
  315. that.option("pageIndex", e.value)
  316. }
  317. });
  318. $("<span>").text(pagesCountText).addClass(PAGER_INFO_TEXT_CLASS + " " + PAGER_INFO_CLASS).appendTo($container);
  319. var $pageCount = $("<span>").addClass(PAGER_PAGES_COUNT_CLASS).text(pageCount);
  320. eventsEngine.on($pageCount, eventUtils.addNamespace(clickEvent.name, that.Name + "PagesCount"), function(e) {
  321. clickAction({
  322. event: e
  323. })
  324. });
  325. accessibility.registerKeyboardAction("pager", that, $pageCount, void 0, clickAction);
  326. $pageCount.appendTo($container);
  327. that.setAria({
  328. role: "button",
  329. label: "Navigates to the last page"
  330. }, $pageCount)
  331. },
  332. _renderPagesChooser: function() {
  333. var that = this;
  334. var lightModeEnabled = that.option("lightModeEnabled");
  335. var pagesNavigatorVisible = that.option("pagesNavigatorVisible");
  336. var $element = that.$element();
  337. that._$pagesChooser && that._$pagesChooser.remove();
  338. if (!pagesNavigatorVisible) {
  339. return
  340. }
  341. if (that._pages && 0 === that._pages.length) {
  342. that.selectedPage = null;
  343. return
  344. }
  345. that._$pagesChooser = $("<div>").addClass(PAGER_PAGES_CLASS).appendTo($element);
  346. if ("auto" === pagesNavigatorVisible) {
  347. that._$pagesChooser.css("visibility", 1 === that.option("pageCount") ? "hidden" : "")
  348. }
  349. if (!lightModeEnabled) {
  350. that._renderInfo()
  351. }
  352. that._renderNavigateButton("prev");
  353. if (lightModeEnabled) {
  354. that._renderLightPages()
  355. } else {
  356. that._renderPages(that._pages)
  357. }
  358. that._renderNavigateButton("next");
  359. that._updatePagesChooserWidth()
  360. },
  361. _renderPageSizes: function() {
  362. var that = this;
  363. var i;
  364. var pageSizes = that.option("pageSizes");
  365. var pagesSizesLength = pageSizes && pageSizes.length;
  366. var pageSizeValue;
  367. var currentPageSize = that.option("pageSize");
  368. var $pageSize;
  369. var clickPagesSizeAction = that._createAction(function(args) {
  370. var e = args.event;
  371. pageSizeValue = parseInt($(e.target).text());
  372. that.option("pageSize", pageSizeValue)
  373. });
  374. eventsEngine.on(that._$pagesSizeChooser, eventUtils.addNamespace(clickEvent.name, that.Name + "PageSize"), PAGER_PAGE_SIZE_CLASS_SELECTOR, function(e) {
  375. clickPagesSizeAction({
  376. event: e
  377. })
  378. });
  379. accessibility.registerKeyboardAction("pager", that, that._$pagesSizeChooser, PAGER_PAGE_SIZE_CLASS_SELECTOR, clickPagesSizeAction);
  380. for (i = 0; i < pagesSizesLength; i++) {
  381. $pageSize = $("<div>").text(pageSizes[i]).addClass(PAGER_PAGE_SIZE_CLASS);
  382. that.setAria({
  383. role: "button",
  384. label: "Display " + pageSizes[i] + " items on page"
  385. }, $pageSize);
  386. accessibility.setTabIndex(that, $pageSize);
  387. if (currentPageSize === pageSizes[i]) {
  388. $pageSize.addClass(PAGER_SELECTION_CLASS)
  389. }
  390. that._$pagesSizeChooser.append($pageSize)
  391. }
  392. },
  393. _calculateLightPageSizesWidth: function(pageSizes) {
  394. return Number(this._$pagesSizeChooser.css("minWidth").replace("px", "")) + 10 * Math.max.apply(Math, pageSizes).toString().length
  395. },
  396. _renderLightPageSizes: function() {
  397. var that = this;
  398. var pageSizes = that.option("pageSizes");
  399. var $editor = $("<div>").appendTo(that._$pagesSizeChooser);
  400. that._pageSizeEditor = that._createComponent($editor, SelectBox, {
  401. dataSource: pageSizes,
  402. value: that.option("pageSize"),
  403. onSelectionChanged: function(e) {
  404. that.option("pageSize", e.selectedItem)
  405. },
  406. width: that._calculateLightPageSizesWidth(pageSizes)
  407. })
  408. },
  409. _renderPagesSizeChooser: function() {
  410. var that = this;
  411. var pageSizes = that.option("pageSizes");
  412. var showPageSizes = that.option("showPageSizes");
  413. var pagesSizesLength = pageSizes && pageSizes.length;
  414. var $element = that.$element();
  415. that._$pagesSizeChooser && that._$pagesSizeChooser.remove();
  416. if (!showPageSizes || !pagesSizesLength) {
  417. return
  418. }
  419. that._$pagesSizeChooser = $("<div>").addClass(PAGER_PAGE_SIZES_CLASS).appendTo($element);
  420. if (that.option("lightModeEnabled")) {
  421. that._renderLightPageSizes()
  422. } else {
  423. that._renderPageSizes()
  424. }
  425. that._pagesSizeChooserWidth = that._$pagesSizeChooser.width()
  426. },
  427. _renderInfo: function() {
  428. var infoText = this.option("infoText");
  429. if (this.option("showInfo") && typeUtils.isDefined(infoText)) {
  430. this._$info = $("<div>").css("display", this._isInfoHide ? "none" : "").addClass(PAGER_INFO_CLASS).text(stringUtils.format(infoText, this.selectedPage && this.selectedPage.value(), this.option("pageCount"), this.option("totalCount"))).appendTo(this._$pagesChooser);
  431. if (!this._isInfoHide) {
  432. this._infoWidth = this._$info.outerWidth(true)
  433. }
  434. }
  435. },
  436. _renderNavigateButton: function(direction) {
  437. var that = this;
  438. var clickAction = that._createAction(function() {
  439. that._nextPage(direction)
  440. });
  441. var $button;
  442. if (that.option("showNavigationButtons") || that.option("lightModeEnabled")) {
  443. $button = $("<div>").addClass(PAGER_NAVIGATE_BUTTON);
  444. eventsEngine.on($button, eventUtils.addNamespace([pointerEvents.up, clickEvent.name], that.Name + "Pages"), that._wrapClickAction(clickAction));
  445. accessibility.registerKeyboardAction("pager", that, $button, void 0, clickAction);
  446. that.setAria({
  447. role: "button",
  448. label: "prev" === direction ? "Previous page" : " Next page"
  449. }, $button);
  450. accessibility.setTabIndex(that, $button);
  451. if (that.option("rtlEnabled")) {
  452. $button.addClass("prev" === direction ? PAGER_NEXT_BUTTON_CLASS : PAGER_PREV_BUTTON_CLASS);
  453. $button.prependTo(this._$pagesChooser)
  454. } else {
  455. $button.addClass("prev" === direction ? PAGER_PREV_BUTTON_CLASS : PAGER_NEXT_BUTTON_CLASS);
  456. $button.appendTo(this._$pagesChooser)
  457. }
  458. }
  459. },
  460. _renderContentImpl: function() {
  461. this.$element().toggleClass(LIGHT_MODE_CLASS, this.option("lightModeEnabled"));
  462. this._toggleVisibility(this.option("visible"));
  463. this._updatePageSizes(true);
  464. this._updatePages(true);
  465. accessibility.restoreFocus(this)
  466. },
  467. _initMarkup: function() {
  468. var $element = this.$element();
  469. $element.addClass(PAGER_CLASS);
  470. var $pageSize = $("<div>").addClass(PAGER_PAGE_CLASS);
  471. this._$pagesChooser = $("<div>").addClass(PAGER_PAGES_CLASS).append($pageSize).appendTo($element)
  472. },
  473. _render: function() {
  474. this.option().lightModeEnabled = false;
  475. this.callBase();
  476. this._updateLightMode()
  477. },
  478. _updatePageSizes: function(forceRender) {
  479. var lightModeEnabled = this.option("lightModeEnabled");
  480. var pageSize = this.option("pageSize");
  481. var pageSizes = this.option("pageSizes");
  482. if (lightModeEnabled) {
  483. this._pageSizeEditor && this._pageSizeEditor.option({
  484. value: pageSize,
  485. dataSource: pageSizes,
  486. width: this._calculateLightPageSizesWidth(pageSizes)
  487. })
  488. }
  489. if (!lightModeEnabled || forceRender) {
  490. this._renderPagesSizeChooser()
  491. }
  492. },
  493. _updatePages: function(forceRender) {
  494. var pageCount = this.option("pageCount");
  495. var pageIndex = this.option("pageIndex");
  496. var lightModeEnabled = this.option("lightModeEnabled");
  497. if (!lightModeEnabled) {
  498. this._processSelectedPage(this.option("maxPagesCount"), pageIndex, pageCount);
  499. this._pages = this._getPages(this.selectedPage, pageCount);
  500. this._selectPageByValue(pageIndex)
  501. } else {
  502. this._pageIndexEditor && this._pageIndexEditor.option({
  503. value: pageIndex,
  504. width: this._calculateLightPagesWidth(this._pageIndexEditor.$element(), pageCount)
  505. })
  506. }
  507. if (!lightModeEnabled || forceRender) {
  508. this._renderPagesChooser()
  509. }
  510. this._updateButtonsState(pageIndex)
  511. },
  512. _isPageIndexInvalid: function(direction, pageIndex) {
  513. var isNextDirection = "next" === direction;
  514. var rtlEnabled = this.option("rtlEnabled");
  515. if (rtlEnabled && isNextDirection || !rtlEnabled && !isNextDirection) {
  516. return pageIndex <= 1
  517. }
  518. return pageIndex >= this.option("pageCount")
  519. },
  520. _updateButtonsState: function(pageIndex) {
  521. var nextButton = this.$element().find("." + PAGER_NEXT_BUTTON_CLASS);
  522. var prevButton = this.$element().find("." + PAGER_PREV_BUTTON_CLASS);
  523. nextButton.toggleClass(PAGER_BUTTON_DISABLE_CLASS, this._isPageIndexInvalid("next", pageIndex));
  524. prevButton.toggleClass(PAGER_BUTTON_DISABLE_CLASS, this._isPageIndexInvalid("prev", pageIndex))
  525. },
  526. _optionChanged: function(args) {
  527. switch (args.name) {
  528. case "visible":
  529. this._toggleVisibility(args.value);
  530. break;
  531. case "pageIndex":
  532. var pageIndexChanged = this.option("pageIndexChanged");
  533. if (pageIndexChanged) {
  534. pageIndexChanged(args.value)
  535. }
  536. this._updatePages();
  537. break;
  538. case "maxPagesCount":
  539. case "pageCount":
  540. case "totalCount":
  541. case "hasKnownLastPage":
  542. case "pagesNavigatorVisible":
  543. case "showNavigationButtons":
  544. this._updatePages();
  545. break;
  546. case "pageSize":
  547. var pageSizeChanged = this.option("pageSizeChanged");
  548. if (pageSizeChanged) {
  549. pageSizeChanged(args.value)
  550. }
  551. this._updatePageSizes();
  552. break;
  553. case "pageSizes":
  554. this._updatePageSizes();
  555. break;
  556. case "lightModeEnabled":
  557. this._renderContentImpl();
  558. !args.value && this._updateLightMode();
  559. break;
  560. default:
  561. this._invalidate()
  562. }
  563. },
  564. _clean: function() {
  565. if (this._$pagesChooser) {
  566. eventsEngine.off(this._$pagesChooser, eventUtils.addNamespace([pointerEvents.up, clickEvent.name], this.Name + "Pages"), PAGER_PAGE_CLASS_SELECTOR, this._pageClickHandler);
  567. accessibility.registerKeyboardAction("pager", this, this._$pagesChooser, PAGER_PAGE_CLASS_SELECTOR, this._pageKeyDownHandler)
  568. }
  569. this.callBase()
  570. },
  571. _getMinPagerWidth: function() {
  572. var pagesChooserWidth = typeUtils.isDefined(this._pagesChooserWidth) ? this._pagesChooserWidth : 0;
  573. var pagesSizeChooserWidth = typeUtils.isDefined(this._pagesSizeChooserWidth) ? this._pagesSizeChooserWidth : 0;
  574. return pagesChooserWidth + pagesSizeChooserWidth
  575. },
  576. _updatePagesChooserWidth: commonUtils.deferUpdater(function() {
  577. var lastPageWidth = this._pages && this._pages.length > 0 ? this._pages[this._pages.length - 1]._$page.width() : 0;
  578. this._pagesChooserWidth = this._$pagesChooser.width() + lastPageWidth
  579. }),
  580. _updateLightMode: commonUtils.deferUpdater(function() {
  581. var that = this;
  582. var width = this.$element().width();
  583. var infoWidth = typeUtils.isDefined(this._infoWidth) ? this._infoWidth : 0;
  584. commonUtils.deferRender(function() {
  585. if (that._isInfoHide && width > that._getMinPagerWidth() + infoWidth) {
  586. that._$info.show();
  587. that._updatePagesChooserWidth();
  588. that._isInfoHide = false
  589. }
  590. if (!that._isInfoHide && width > that._getMinPagerWidth() - infoWidth && width < that._getMinPagerWidth()) {
  591. that._$info.hide();
  592. that._updatePagesChooserWidth();
  593. that._isInfoHide = true
  594. }
  595. commonUtils.deferUpdate(function() {
  596. commonUtils.deferRender(function() {
  597. if (that.option("lightModeEnabled") && width > that._previousWidth) {
  598. that.option("lightModeEnabled", false)
  599. } else {
  600. if (width < that._getMinPagerWidth()) {
  601. that.option("lightModeEnabled", true)
  602. }
  603. }
  604. that._previousWidth = width
  605. })
  606. })
  607. })
  608. }),
  609. _dimensionChanged: function() {
  610. this._updateLightMode()
  611. },
  612. getHeight: function() {
  613. return this.option("visible") ? this.$element().outerHeight() : 0
  614. }
  615. });
  616. module.exports = Pager;
  617. registerComponent("dxPager", Pager);