| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779 |
- /**
- * DevExtreme (ui/list/ui.list.base.js)
- * Version: 19.1.16
- * Build date: Tue Oct 18 2022
- *
- * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
- * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
- */
- "use strict";
- var $ = require("../../core/renderer");
- var eventsEngine = require("../../events/core/events_engine");
- var commonUtils = require("../../core/utils/common");
- var typeUtils = require("../../core/utils/type");
- var iconUtils = require("../../core/utils/icon");
- var getPublicElement = require("../../core/utils/dom").getPublicElement;
- var each = require("../../core/utils/iterator").each;
- var compileGetter = require("../../core/utils/data").compileGetter;
- var extend = require("../../core/utils/extend").extend;
- var fx = require("../../animation/fx");
- var clickEvent = require("../../events/click");
- var swipeEvents = require("../../events/swipe");
- var support = require("../../core/utils/support");
- var messageLocalization = require("../../localization/message");
- var inkRipple = require("../widget/utils.ink_ripple");
- var devices = require("../../core/devices");
- var ListItem = require("./item");
- var Button = require("../button");
- var eventUtils = require("../../events/utils");
- var themes = require("../themes");
- var windowUtils = require("../../core/utils/window");
- var ScrollView = require("../scroll_view");
- var deviceDependentOptions = require("../scroll_view/ui.scrollable").deviceDependentOptions;
- var CollectionWidget = require("../collection/ui.collection_widget.live_update").default;
- var BindableTemplate = require("../widget/bindable_template");
- var Deferred = require("../../core/utils/deferred").Deferred;
- var DataConverterMixin = require("../shared/grouped_data_converter_mixin").default;
- var LIST_CLASS = "dx-list";
- var LIST_ITEM_CLASS = "dx-list-item";
- var LIST_ITEM_SELECTOR = "." + LIST_ITEM_CLASS;
- var LIST_ITEM_ICON_CONTAINER_CLASS = "dx-list-item-icon-container";
- var LIST_ITEM_ICON_CLASS = "dx-list-item-icon";
- var LIST_GROUP_CLASS = "dx-list-group";
- var LIST_GROUP_HEADER_CLASS = "dx-list-group-header";
- var LIST_GROUP_BODY_CLASS = "dx-list-group-body";
- var LIST_COLLAPSIBLE_GROUPS_CLASS = "dx-list-collapsible-groups";
- var LIST_GROUP_COLLAPSED_CLASS = "dx-list-group-collapsed";
- var LIST_GROUP_HEADER_INDICATOR_CLASS = "dx-list-group-header-indicator";
- var LIST_HAS_NEXT_CLASS = "dx-has-next";
- var LIST_NEXT_BUTTON_CLASS = "dx-list-next-button";
- var SELECT_ALL_ITEM_SELECTOR = ".dx-list-select-all";
- var LIST_ITEM_DATA_KEY = "dxListItemData";
- var LIST_FEEDBACK_SHOW_TIMEOUT = 70;
- var groupItemsGetter = compileGetter("items");
- var ListBase = CollectionWidget.inherit({
- _activeStateUnit: [LIST_ITEM_SELECTOR, SELECT_ALL_ITEM_SELECTOR].join(","),
- _supportedKeys: function() {
- var that = this;
- var moveFocusPerPage = function(direction) {
- var $item = getEdgeVisibleItem(direction);
- var isFocusedItem = $item.is(that.option("focusedElement"));
- if (isFocusedItem) {
- scrollListTo($item, direction);
- $item = getEdgeVisibleItem(direction)
- }
- that.option("focusedElement", getPublicElement($item));
- that.scrollToItem($item)
- };
- var getEdgeVisibleItem = function(direction) {
- var scrollTop = that.scrollTop();
- var containerHeight = that.$element().height();
- var $item = $(that.option("focusedElement"));
- var isItemVisible = true;
- if (!$item.length) {
- return $()
- }
- while (isItemVisible) {
- var $nextItem = $item[direction]();
- if (!$nextItem.length) {
- break
- }
- var nextItemLocation = $nextItem.position().top + $nextItem.outerHeight() / 2;
- isItemVisible = nextItemLocation < containerHeight + scrollTop && nextItemLocation > scrollTop;
- if (isItemVisible) {
- $item = $nextItem
- }
- }
- return $item
- };
- var scrollListTo = function($item, direction) {
- var resultPosition = $item.position().top;
- if ("prev" === direction) {
- resultPosition = $item.position().top - that.$element().height() + $item.outerHeight()
- }
- that.scrollTo(resultPosition)
- };
- return extend(this.callBase(), {
- leftArrow: commonUtils.noop,
- rightArrow: commonUtils.noop,
- pageUp: function() {
- moveFocusPerPage("prev");
- return false
- },
- pageDown: function() {
- moveFocusPerPage("next");
- return false
- }
- })
- },
- _getDefaultOptions: function() {
- return extend(this.callBase(), {
- hoverStateEnabled: true,
- pullRefreshEnabled: false,
- scrollingEnabled: true,
- showScrollbar: "onScroll",
- useNativeScrolling: true,
- bounceEnabled: true,
- scrollByContent: true,
- scrollByThumb: false,
- pullingDownText: messageLocalization.format("dxList-pullingDownText"),
- pulledDownText: messageLocalization.format("dxList-pulledDownText"),
- refreshingText: messageLocalization.format("dxList-refreshingText"),
- pageLoadingText: messageLocalization.format("dxList-pageLoadingText"),
- onScroll: null,
- onPullRefresh: null,
- onPageLoading: null,
- pageLoadMode: "scrollBottom",
- nextButtonText: messageLocalization.format("dxList-nextButtonText"),
- onItemSwipe: null,
- grouped: false,
- onGroupRendered: null,
- collapsibleGroups: false,
- groupTemplate: "group",
- indicateLoading: true,
- activeStateEnabled: true,
- _itemAttributes: {
- role: "option"
- },
- _listAttributes: {
- role: "listbox"
- },
- useInkRipple: false,
- showChevronExpr: function(data) {
- return data ? data.showChevron : void 0
- },
- badgeExpr: function(data) {
- return data ? data.badge : void 0
- }
- })
- },
- _defaultOptionsRules: function() {
- var themeName = themes.current();
- return this.callBase().concat(deviceDependentOptions(), [{
- device: function() {
- return !support.nativeScrolling
- },
- options: {
- useNativeScrolling: false
- }
- }, {
- device: function(_device) {
- return !support.nativeScrolling && !devices.isSimulator() && "generic" === devices.real().platform && "generic" === _device.platform
- },
- options: {
- showScrollbar: "onHover",
- pageLoadMode: "nextButton"
- }
- }, {
- device: function() {
- return "desktop" === devices.real().deviceType && !devices.isSimulator()
- },
- options: {
- focusStateEnabled: true
- }
- }, {
- device: function() {
- return "win" === devices.current().platform && devices.isSimulator()
- },
- options: {
- bounceEnabled: false
- }
- }, {
- device: function() {
- return themes.isMaterial(themeName)
- },
- options: {
- pullingDownText: "",
- pulledDownText: "",
- refreshingText: "",
- pageLoadingText: "",
- useInkRipple: true
- }
- }])
- },
- _visibilityChanged: function(visible) {
- if (visible) {
- this._updateLoadingState(true)
- }
- },
- _itemClass: function() {
- return LIST_ITEM_CLASS
- },
- _itemDataKey: function() {
- return LIST_ITEM_DATA_KEY
- },
- _itemContainer: function() {
- return this._$container
- },
- _refreshItemElements: function() {
- if (!this.option("grouped")) {
- this._itemElementsCache = this._itemContainer().children(this._itemSelector())
- } else {
- this._itemElementsCache = this._itemContainer().children("." + LIST_GROUP_CLASS).children("." + LIST_GROUP_BODY_CLASS).children(this._itemSelector())
- }
- },
- _modifyByChanges: function() {
- this.callBase.apply(this, arguments);
- this._refreshItemElements()
- },
- reorderItem: function(itemElement, toItemElement) {
- var promise = this.callBase(itemElement, toItemElement);
- return promise.done(function() {
- this._refreshItemElements()
- })
- },
- deleteItem: function(itemElement) {
- var promise = this.callBase(itemElement);
- return promise.done(function() {
- this._refreshItemElements()
- })
- },
- _itemElements: function() {
- return this._itemElementsCache
- },
- _itemSelectHandler: function(e) {
- if ("single" === this.option("selectionMode") && this.isItemSelected(e.currentTarget)) {
- return
- }
- this.callBase(e)
- },
- _allowDynamicItemsAppend: function() {
- return true
- },
- _init: function() {
- this.callBase();
- this._$container = this.$element();
- this._initScrollView();
- this._feedbackShowTimeout = LIST_FEEDBACK_SHOW_TIMEOUT;
- this._createGroupRenderAction()
- },
- _scrollBottomMode: function() {
- return "scrollBottom" === this.option("pageLoadMode")
- },
- _nextButtonMode: function() {
- return "nextButton" === this.option("pageLoadMode")
- },
- _dataSourceOptions: function() {
- var scrollBottom = this._scrollBottomMode();
- var nextButton = this._nextButtonMode();
- return extend(this.callBase(), {
- paginate: commonUtils.ensureDefined(scrollBottom || nextButton, true)
- })
- },
- _getGroupedOption: function() {
- return this.option("grouped")
- },
- _dataSourceFromUrlLoadMode: function() {
- return "raw"
- },
- _initScrollView: function() {
- var scrollingEnabled = this.option("scrollingEnabled");
- var pullRefreshEnabled = scrollingEnabled && this.option("pullRefreshEnabled");
- var autoPagingEnabled = scrollingEnabled && this._scrollBottomMode() && !!this._dataSource;
- this._scrollView = this._createComponent(this.$element(), ScrollView, {
- disabled: this.option("disabled") || !scrollingEnabled,
- onScroll: this._scrollHandler.bind(this),
- onPullDown: pullRefreshEnabled ? this._pullDownHandler.bind(this) : null,
- onReachBottom: autoPagingEnabled ? this._scrollBottomHandler.bind(this) : null,
- showScrollbar: this.option("showScrollbar"),
- useNative: this.option("useNativeScrolling"),
- bounceEnabled: this.option("bounceEnabled"),
- scrollByContent: this.option("scrollByContent"),
- scrollByThumb: this.option("scrollByThumb"),
- pullingDownText: this.option("pullingDownText"),
- pulledDownText: this.option("pulledDownText"),
- refreshingText: this.option("refreshingText"),
- reachBottomText: this.option("pageLoadingText"),
- useKeyboard: false
- });
- this._$container = $(this._scrollView.content());
- this._createScrollViewActions()
- },
- _createScrollViewActions: function() {
- this._scrollAction = this._createActionByOption("onScroll");
- this._pullRefreshAction = this._createActionByOption("onPullRefresh");
- this._pageLoadingAction = this._createActionByOption("onPageLoading")
- },
- _scrollHandler: function(e) {
- this._scrollAction && this._scrollAction(e)
- },
- _initTemplates: function() {
- this.callBase();
- this._defaultTemplates.group = new BindableTemplate(function($container, data) {
- if (typeUtils.isPlainObject(data)) {
- if (data.key) {
- $container.text(data.key)
- }
- } else {
- $container.text(String(data))
- }
- }, ["key"], this.option("integrationOptions.watchMethod"))
- },
- _prepareDefaultItemTemplate: function(data, $container) {
- this.callBase(data, $container);
- if (data.icon) {
- var $icon = iconUtils.getImageContainer(data.icon).addClass(LIST_ITEM_ICON_CLASS);
- var $iconContainer = $("<div>").addClass(LIST_ITEM_ICON_CONTAINER_CLASS);
- $iconContainer.append($icon);
- $container.prepend($iconContainer)
- }
- },
- _getBindableFields: function() {
- return ["text", "html", "icon"]
- },
- _updateLoadingState: function(tryLoadMore) {
- var isDataLoaded = !tryLoadMore || this._isLastPage();
- var scrollBottomMode = this._scrollBottomMode();
- var stopLoading = isDataLoaded || !scrollBottomMode;
- var hideLoadIndicator = stopLoading && !this._isDataSourceLoading();
- if (stopLoading || this._scrollViewIsFull()) {
- this._scrollView.release(hideLoadIndicator);
- this._toggleNextButton(this._shouldRenderNextButton() && !this._isLastPage());
- this._loadIndicationSuppressed(false)
- } else {
- this._infiniteDataLoading()
- }
- },
- _shouldRenderNextButton: function() {
- return this._nextButtonMode() && this._dataSource && this._dataSource.isLoaded()
- },
- _dataSourceLoadingChangedHandler: function(isLoading) {
- if (this._loadIndicationSuppressed()) {
- return
- }
- if (isLoading && this.option("indicateLoading")) {
- this._showLoadingIndicatorTimer = setTimeout(function() {
- var isEmpty = !this._itemElements().length;
- if (this._scrollView && !isEmpty) {
- this._scrollView.startLoading()
- }
- }.bind(this))
- } else {
- clearTimeout(this._showLoadingIndicatorTimer);
- this._scrollView && this._scrollView.finishLoading()
- }
- },
- _dataSourceChangedHandler: function(newItems) {
- if (!this._shouldAppendItems() && windowUtils.hasWindow()) {
- this._scrollView && this._scrollView.scrollTo(0)
- }
- this.callBase.apply(this, arguments)
- },
- _refreshContent: function() {
- this._prepareContent();
- this._fireContentReadyAction()
- },
- _hideLoadingIfLoadIndicationOff: function() {
- if (!this.option("indicateLoading")) {
- this._dataSourceLoadingChangedHandler(false)
- }
- },
- _loadIndicationSuppressed: function(value) {
- if (!arguments.length) {
- return this._isLoadIndicationSuppressed
- }
- this._isLoadIndicationSuppressed = value
- },
- _scrollViewIsFull: function() {
- return !this._scrollView || this._scrollView.isFull()
- },
- _pullDownHandler: function(e) {
- this._pullRefreshAction(e);
- if (this._dataSource && !this._isDataSourceLoading()) {
- this._clearSelectedItems();
- this._dataSource.pageIndex(0);
- this._dataSource.reload()
- } else {
- this._updateLoadingState()
- }
- },
- _infiniteDataLoading: function() {
- var isElementVisible = this.$element().is(":visible");
- if (isElementVisible && !this._scrollViewIsFull() && !this._isDataSourceLoading() && !this._isLastPage()) {
- clearTimeout(this._loadNextPageTimer);
- this._loadNextPageTimer = setTimeout(this._loadNextPage.bind(this))
- }
- },
- _scrollBottomHandler: function(e) {
- this._pageLoadingAction(e);
- if (!this._isDataSourceLoading() && !this._isLastPage()) {
- this._loadNextPage()
- } else {
- this._updateLoadingState()
- }
- },
- _renderItems: function(items) {
- if (this.option("grouped")) {
- each(items, this._renderGroup.bind(this));
- this._attachGroupCollapseEvent();
- this._renderEmptyMessage();
- if (themes.isMaterial()) {
- this.attachGroupHeaderInkRippleEvents()
- }
- } else {
- this.callBase.apply(this, arguments)
- }
- this._refreshItemElements();
- this._updateLoadingState(true)
- },
- _attachGroupCollapseEvent: function() {
- var eventName = eventUtils.addNamespace(clickEvent.name, this.NAME);
- var selector = "." + LIST_GROUP_HEADER_CLASS;
- var $element = this.$element();
- var collapsibleGroups = this.option("collapsibleGroups");
- $element.toggleClass(LIST_COLLAPSIBLE_GROUPS_CLASS, collapsibleGroups);
- eventsEngine.off($element, eventName, selector);
- if (collapsibleGroups) {
- eventsEngine.on($element, eventName, selector, function(e) {
- this._createAction(function(e) {
- var $group = $(e.event.currentTarget).parent();
- this._collapseGroupHandler($group);
- if (this.option("focusStateEnabled")) {
- this.option("focusedElement", getPublicElement($group.find("." + LIST_ITEM_CLASS).eq(0)))
- }
- }.bind(this), {
- validatingTargetName: "element"
- })({
- event: e
- })
- }.bind(this))
- }
- },
- _collapseGroupHandler: function($group, toggle) {
- var deferred = new Deferred;
- if ($group.hasClass(LIST_GROUP_COLLAPSED_CLASS) === toggle) {
- return deferred.resolve()
- }
- var $groupBody = $group.children("." + LIST_GROUP_BODY_CLASS);
- var startHeight = $groupBody.outerHeight();
- var endHeight = 0 === startHeight ? $groupBody.height("auto").outerHeight() : 0;
- $group.toggleClass(LIST_GROUP_COLLAPSED_CLASS, toggle);
- fx.animate($groupBody, {
- type: "custom",
- from: {
- height: startHeight
- },
- to: {
- height: endHeight
- },
- duration: 200,
- complete: function() {
- this.updateDimensions();
- this._updateLoadingState();
- deferred.resolve()
- }.bind(this)
- });
- return deferred.promise()
- },
- _dataSourceLoadErrorHandler: function() {
- this._forgetNextPageLoading();
- if (this._initialized) {
- this._renderEmptyMessage();
- this._updateLoadingState()
- }
- },
- _initMarkup: function() {
- this._itemElementsCache = $();
- this.$element().addClass(LIST_CLASS);
- this.callBase();
- this.option("useInkRipple") && this._renderInkRipple();
- this.setAria("role", this.option("_listAttributes").role)
- },
- _renderInkRipple: function() {
- this._inkRipple = inkRipple.render()
- },
- _toggleActiveState: function($element, value, e) {
- this.callBase.apply(this, arguments);
- var that = this;
- if (!this._inkRipple) {
- return
- }
- var config = {
- element: $element,
- event: e
- };
- if (value) {
- if (themes.isMaterial()) {
- this._inkRippleTimer = setTimeout(function() {
- that._inkRipple.showWave(config)
- }, LIST_FEEDBACK_SHOW_TIMEOUT / 2)
- } else {
- that._inkRipple.showWave(config)
- }
- } else {
- clearTimeout(this._inkRippleTimer);
- this._inkRipple.hideWave(config)
- }
- },
- _postprocessRenderItem: function(args) {
- this._refreshItemElements();
- this.callBase.apply(this, arguments);
- if (this.option("onItemSwipe")) {
- this._attachSwipeEvent($(args.itemElement))
- }
- },
- _attachSwipeEvent: function($itemElement) {
- var endEventName = eventUtils.addNamespace(swipeEvents.end, this.NAME);
- eventsEngine.on($itemElement, endEventName, this._itemSwipeEndHandler.bind(this))
- },
- _itemSwipeEndHandler: function(e) {
- this._itemDXEventHandler(e, "onItemSwipe", {
- direction: e.offset < 0 ? "left" : "right"
- })
- },
- _nextButtonHandler: function() {
- var source = this._dataSource;
- if (source && !source.isLoading()) {
- this._scrollView.toggleLoading(true);
- this._$nextButton.detach();
- this._loadIndicationSuppressed(true);
- this._loadNextPage()
- }
- },
- _renderGroup: function(index, group) {
- var $groupElement = $("<div>").addClass(LIST_GROUP_CLASS).appendTo(this._itemContainer());
- var $groupHeaderElement = $("<div>").addClass(LIST_GROUP_HEADER_CLASS).appendTo($groupElement);
- var groupTemplateName = this.option("groupTemplate");
- var groupTemplate = this._getTemplate(group.template || groupTemplateName, group, index, $groupHeaderElement);
- var renderArgs = {
- index: index,
- itemData: group,
- container: getPublicElement($groupHeaderElement)
- };
- this._createItemByTemplate(groupTemplate, renderArgs);
- if (themes.isMaterial()) {
- $("<div>").addClass(LIST_GROUP_HEADER_INDICATOR_CLASS).prependTo($groupHeaderElement)
- }
- this._renderingGroupIndex = index;
- var $groupBody = $("<div>").addClass(LIST_GROUP_BODY_CLASS).appendTo($groupElement);
- each(groupItemsGetter(group) || [], function(index, item) {
- this._renderItem(index, item, $groupBody)
- }.bind(this));
- this._groupRenderAction({
- groupElement: getPublicElement($groupElement),
- groupIndex: index,
- groupData: group
- })
- },
- downInkRippleHandler: function(e) {
- this._toggleActiveState($(e.currentTarget), true, e)
- },
- upInkRippleHandler: function(e) {
- this._toggleActiveState($(e.currentTarget), false)
- },
- attachGroupHeaderInkRippleEvents: function() {
- var selector = "." + LIST_GROUP_HEADER_CLASS;
- var $element = this.$element();
- this._downInkRippleHandler = this._downInkRippleHandler || this.downInkRippleHandler.bind(this);
- this._upInkRippleHandler = this._upInkRippleHandler || this.upInkRippleHandler.bind(this);
- var downArguments = [$element, "dxpointerdown", selector, this._downInkRippleHandler];
- var upArguments = [$element, "dxpointerup dxpointerout", selector, this._upInkRippleHandler];
- eventsEngine.off.apply(eventsEngine, downArguments);
- eventsEngine.on.apply(eventsEngine, downArguments);
- eventsEngine.off.apply(eventsEngine, upArguments);
- eventsEngine.on.apply(eventsEngine, upArguments)
- },
- _createGroupRenderAction: function() {
- this._groupRenderAction = this._createActionByOption("onGroupRendered")
- },
- _clean: function() {
- clearTimeout(this._inkRippleTimer);
- if (this._$nextButton) {
- this._$nextButton.remove();
- this._$nextButton = null
- }
- this.callBase.apply(this, arguments)
- },
- _dispose: function() {
- clearTimeout(this._holdTimer);
- clearTimeout(this._loadNextPageTimer);
- clearTimeout(this._showLoadingIndicatorTimer);
- this.callBase()
- },
- _toggleDisabledState: function(value) {
- this.callBase(value);
- this._scrollView.option("disabled", value || !this.option("scrollingEnabled"))
- },
- _toggleNextButton: function(value) {
- var dataSource = this._dataSource;
- var $nextButton = this._getNextButton();
- this.$element().toggleClass(LIST_HAS_NEXT_CLASS, value);
- if (value && dataSource && dataSource.isLoaded()) {
- $nextButton.appendTo(this._itemContainer())
- }
- if (!value) {
- $nextButton.detach()
- }
- },
- _getNextButton: function() {
- if (!this._$nextButton) {
- this._$nextButton = this._createNextButton()
- }
- return this._$nextButton
- },
- _createNextButton: function() {
- var $result = $("<div>").addClass(LIST_NEXT_BUTTON_CLASS);
- var $button = $("<div>").appendTo($result);
- this._createComponent($button, Button, {
- text: this.option("nextButtonText"),
- onClick: this._nextButtonHandler.bind(this),
- type: themes.isMaterial() ? "default" : void 0,
- integrationOptions: {}
- });
- return $result
- },
- _moveFocus: function() {
- this.callBase.apply(this, arguments);
- this.scrollToItem(this.option("focusedElement"))
- },
- _refresh: function() {
- if (!windowUtils.hasWindow()) {
- this.callBase()
- } else {
- var scrollTop = this._scrollView.scrollTop();
- this.callBase();
- scrollTop && this._scrollView.scrollTo(scrollTop)
- }
- },
- _optionChanged: function(args) {
- switch (args.name) {
- case "pageLoadMode":
- this._toggleNextButton(args.value);
- this._initScrollView();
- break;
- case "dataSource":
- this.callBase(args);
- this._initScrollView();
- break;
- case "pullingDownText":
- case "pulledDownText":
- case "refreshingText":
- case "pageLoadingText":
- case "useNative":
- case "showScrollbar":
- case "bounceEnabled":
- case "scrollByContent":
- case "scrollByThumb":
- case "scrollingEnabled":
- case "pullRefreshEnabled":
- this._initScrollView();
- this._updateLoadingState();
- break;
- case "nextButtonText":
- case "onItemSwipe":
- case "useInkRipple":
- this._invalidate();
- break;
- case "onScroll":
- case "onPullRefresh":
- case "onPageLoading":
- this._createScrollViewActions();
- this._invalidate();
- break;
- case "grouped":
- case "collapsibleGroups":
- case "groupTemplate":
- this._invalidate();
- break;
- case "onGroupRendered":
- this._createGroupRenderAction();
- break;
- case "width":
- case "height":
- this.callBase(args);
- this._scrollView.update();
- break;
- case "indicateLoading":
- this._hideLoadingIfLoadIndicationOff();
- break;
- case "visible":
- this.callBase(args);
- this._scrollView.update();
- break;
- case "rtlEnabled":
- this._initScrollView();
- this.callBase(args);
- break;
- case "showChevronExpr":
- case "badgeExpr":
- this._invalidate();
- break;
- case "_listAttributes":
- break;
- default:
- this.callBase(args)
- }
- },
- _extendActionArgs: function($itemElement) {
- if (!this.option("grouped")) {
- return this.callBase($itemElement)
- }
- var $group = $itemElement.closest("." + LIST_GROUP_CLASS);
- var $item = $group.find("." + LIST_ITEM_CLASS);
- return extend(this.callBase($itemElement), {
- itemIndex: {
- group: $group.index(),
- item: $item.index($itemElement)
- }
- })
- },
- expandGroup: function(groupIndex) {
- var deferred = new Deferred;
- var $group = this._itemContainer().find("." + LIST_GROUP_CLASS).eq(groupIndex);
- this._collapseGroupHandler($group, false).done(function() {
- deferred.resolveWith(this)
- }.bind(this));
- return deferred.promise()
- },
- collapseGroup: function(groupIndex) {
- var deferred = new Deferred;
- var $group = this._itemContainer().find("." + LIST_GROUP_CLASS).eq(groupIndex);
- this._collapseGroupHandler($group, true).done(function() {
- deferred.resolveWith(this)
- }.bind(this));
- return deferred
- },
- updateDimensions: function() {
- var that = this;
- var deferred = new Deferred;
- if (that._scrollView) {
- that._scrollView.update().done(function() {
- !that._scrollViewIsFull() && that._updateLoadingState(true);
- deferred.resolveWith(that)
- })
- } else {
- deferred.resolveWith(that)
- }
- return deferred.promise()
- },
- reload: function() {
- this.callBase();
- this.scrollTo(0);
- this._pullDownHandler()
- },
- repaint: function() {
- this.scrollTo(0);
- this.callBase()
- },
- scrollTop: function() {
- return this._scrollView.scrollOffset().top
- },
- clientHeight: function() {
- return this._scrollView.clientHeight()
- },
- scrollHeight: function() {
- return this._scrollView.scrollHeight()
- },
- scrollBy: function(distance) {
- this._scrollView.scrollBy(distance)
- },
- scrollTo: function(location) {
- this._scrollView.scrollTo(location)
- },
- scrollToItem: function(itemElement) {
- var $item = this._editStrategy.getItemElement(itemElement);
- this._scrollView.scrollToElement($item)
- }
- }).include(DataConverterMixin);
- ListBase.ItemClass = ListItem;
- module.exports = ListBase;
|