/*
Pager handling
323043
private Integer decodeRow(final String page) {
        String[] terms = page.split(DELIM_GRID_NAME);

        /* todo: this is really an exception, not an assert */
        assert terms != null && terms.length == 2;
        String intString = terms[1];
        return new Integer(decodeInt(intString, DEFAULT_ROW));
    }
622226
function (e) {
        if (e && e.prevValue === e.newValue) {
            return;
        }

        var last = this.paginator.getTotalPages(),
            par  = this.current ? this.current.parentNode : null;

        if (this.paginator.getCurrentPage() !== last) {
            if (par && this.current === this.span) {
                par.replaceChild(this.link,this.current);
                this.current = this.link;
            }
        } else if (this.current === this.link) {
            if (par) {
                par.replaceChild(this.span,this.current);
                this.current = this.span;
            }
        }
    }
119554
function (page) {
        if (!lang.isNumber(page) || page < 1) {
            return false;
        }

        var totalPages = this.getTotalPages();

        return (totalPages === Paginator.VALUE_UNLIMITED || totalPages >= page);
    }
864905
function (options, callback) {
            options = options || {};

            if (options.limit || options.offset) {
                this.$offset = options.offset || 0;
                this.$limit = options.limit || this.$limit;
            }

            var self = this;

            function pageFetchedComplete(err, page, originalCallback) {
                var callback = function (err, page) {
                    if (originalCallback) {
                        originalCallback(err, page, options);
                    }
                };


                if (options.fetchModels || options.fetchSubModels) {

                    // TODO: introduce poolSize parameter for par, and parEach

                    flow()
                        .parEach(page.$items, function (model, cb) {
                            model.fetch({
                                fetchSubModels: options.fetchSubModels
                            }, cb);
                        })
                        .exec(function (err) {
                            callback(err, page);
                        });

                } else {
                    callback(err, page);
                }

            }

            if (this._fetch.state === State.LOADING) {
                // currently fetching -> register callback
                this._fetch.callbacks.push(function (err, page) {
                    pageFetchedComplete(err, page, callback);
                });
            } else if (this._fetch.state == State.LOADED) {
                // completed loaded -> execute
                pageFetchedComplete(null, this, callback);
            } else {
                // set state and start loading
                self._fetch.state = State.LOADING;

                this.$collection.$context.$dataSource.loadCollectionPage(this, options, function (err, page) {
                    self._fetch.state = err ? State.ERROR : State.LOADED;

                    // execute callbacks
                    pageFetchedComplete(err, page, callback);

                    _.each(self._fetch.callbacks, function (cb) {
                        cb(err, page);
                    });
                });
            }
        }
1067609
function handleQuery () {
    var searchText = $scope.searchText || '';
    var term = searchText.toLowerCase();

    // If caching is enabled and the current searchText is stored in the cache
    if (!$scope.noCache && cache[term]) {
      // The results should be handled as same as a normal un-cached request does.
      handleResults(cache[term]);
    } else {
      fetchResults(searchText);
    }

    ctrl.hidden = shouldHide();
  }
1099185
function pagedGet ({source, method, skip = 0, aggregatedResponse = null, query = null}) {
  const fullQuery = Object.assign({},
    {
      skip: skip,
      limit: pageLimit,
      order: 'sys.createdAt,sys.id'
    },
    query
  )

  return source[method](fullQuery)
    .then((response) => {
      if (!aggregatedResponse) {
        aggregatedResponse = response
      } else {
        aggregatedResponse.items = aggregatedResponse.items.concat(response.items)
      }
      const page = Math.ceil(skip / pageLimit) + 1
      const pages = Math.ceil(response.total / pageLimit)
      logEmitter.emit('info', `Fetched ${aggregatedResponse.items.length} of ${response.total} items (Page ${page}/${pages})`)
      if (skip + pageLimit <= response.total) {
        return pagedGet({source, method, skip: skip + pageLimit, aggregatedResponse, query})
      }
      return aggregatedResponse
    })
}
951633
function (e) {
        if (e && e.prevValue === e.newValue) {
            return;
        }

        var rpp     = this.paginator.get('rowsPerPage')+'',
            options = this.select.options,
            i,len;

        for (i = 0, len = options.length; i < len; ++i) {
            if (options[i].value === rpp) {
                options[i].selected = true;
                break;
            }
        }
    }
1279594
function (e) {
        var v = e.newValue,rpp,state;
        if (e.prevValue !== v) {
            if (v !== Paginator.VALUE_UNLIMITED) {
                rpp = this.get('rowsPerPage');

                if (rpp && this.get('recordOffset') >= v) {
                    state = this.getState({
                        totalRecords : e.prevValue,
                        recordOffset : this.get('recordOffset')
                    });

                    this.set('recordOffset', state.before.recordOffset);
                    this._firePageChange(state);
                }
            }
        }
    }
226380
private void updatePaginationState(final SimplePager pager) {

        for (int i = 0; i < getWidgetCount(); i++) {
            if (i == 0) { //previous button
                ((AnchorListItem)getWidget(i)).setEnabled(pager.hasPreviousPage());
            }
            else if (i == getWidgetCount() - 1) { //next button
                ((AnchorListItem)getWidget(i)).setEnabled(pager.hasNextPage());
            }
            else {
                int index = i - 1;
                if (index == pager.getPage()) {
                    ((AnchorListItem)getWidget(i)).setActive(true);
                }
                else {
                    ((AnchorListItem)getWidget(i)).setActive(false);
                }
            }
        }
   }
531176
function (e) {
        YAHOO.util.Event.stopEvent(e);
        this.paginator.setPage(this.paginator.getPreviousPage());
    }
247623
function paginate (num, page) {
  num = num || 50;
  page = page - 1 || 0;
  const pageStart = num * page;
  const pageEnd = pageStart + num;
  return R.slice(pageStart, pageEnd);
}
685319
function(callback){
    var self = this;

    // if we have no pages just fire callback
    if(self.pageCollection.length === 0){
      callback(self);
    }

    // this is called once a page is fully parsed
    whenPageIsFetched = function(){
      self.completed ++;
      if(self.completed === self.pageCollection.length){
        callback(self);
      } else {
        findUnfetchedPages();
      }  
    }

    findUnfetchedPages = function(){ 
      _.each(self.pageCollection, function (page) {
        if (page.status === "unfetched") {
          page.fetch(whenPageIsFetched);
        }
      });
    },

    findUnfetchedPages();
  }
802211
function pageInfoFromParent() {
        var msgBody = getData()
        log('PageInfoFromParent called from parent: ' + msgBody)
        onPageInfo(JSON.parse(msgBody))
        log(' --')
      }
1265262
function paging(res) {
		if ('pagination' in res) {
			res.paging = {
				next: res.pagination.next_url
			};
			delete res.pagination;
		}
	}
420773
def pager(__text: str, *, pager: Optional[str] = 'less'):
    
    if pager:
        run([pager, ], input=__text.encode())
    else:
        print(__text)
1004187
function waitForString(page, ph, str, callback) {
    var elapsed = 0;
    var currentDom = '';
    var timeout = false;

    async.until(
        function () {
            timeout = elapsed > constants.WAIT_TIMEOUT;
            return currentDom.indexOf(str) > -1 || timeout;
        },

        function (callback) {
            setTimeout(function () {
                getData.takeSnapshot(page, ph, function (error, page, ph, dom) {
                    if (error) {
                        callback(error);
                        return;
                    }
                    currentDom = dom;
                    elapsed += constants.POLL_INTERVAL;
                    callback();
                })
            }, constants.POLL_INTERVAL);
        },

        function (error) {
            if (error) {
                callback(error, page, ph);
                return;
            }
            if (timeout) {
                callback('Timeout while waiting for string', page, ph);
                return;
            }
            callback(null, page, ph);
        }
    );
}
58539
function handleScroll() {
        // if we are just starting scrolling, fire scrollstart event
        if (!scrollingStarted) {
            scrollingStarted = true;
            scope.broadcast('scrollstart', buildEventData());
        }
        clearTimeout(scrollendTID);
        scrollendTID = setTimeout(handleScrollEnd, SCROLL_END_TIMEOUT);
        fireScroll();
    }