<commit_before>'use strict';

var assign          = require('es5-ext/object/assign')
  , copy            = require('es5-ext/object/copy')
  , value           = require('es5-ext/object/valid-value')
  , ee              = require('event-emitter')
  , d               = require('d')
  , autoBind        = require('d/auto-bind')
  , memoizeMethods  = require('memoizee/methods-plain')
  , ObservableValue = require('observable-value')
  , replaceContent  = require('dom-ext/element/#/replace-content')
  , formatUrl       = require('url3/format')
  , parseUrl        = require('url3/parse')
  , ns              = require('mano').domjs.ns
  , location        = require('mano/lib/client/location');

var PaginationDom = function (pagination) {
	this.pagination = pagination;
	this.list = ns.ul({ class: 'pagination' });
	this.dom = ns._if(this.pagination.count.gt(1), this.list).toDOM(document);
	this.reload();
	this.pagination.count.on('change', this.reload);
};
Object.defineProperties(PaginationDom.prototype, assign({
	toDOM: d(function (document) { return this.dom; })
}, autoBind({
	reload: d(function () {
		var i, l = this.pagination.count.value, buttons = [];
		if (l < 2) return;
		for (i = 1; i <= l; ++i) buttons.push(this.getPageButton(i));
		replaceContent.call(this.list, buttons);
	})
}), memoizeMethods({
	getPageButton: d(function (page) {
		return ns.li({ class: ns._if(this.pagination.current.eq(page), 'pagination-active') },
			ns.a({ href: ns._if(this.pagination.current.eq(page), null, this.pagination.getLink(page)) },
				page));
	})
})));

var Pagination = module.exports = function (pathname, count, current) {
	if (!(this instanceof Pagination)) return new Pagination(pathname, count, current);
	this.pathname = String(value(pathname));
	this.url = parseUrl(this.pathname, true);
	delete this.url.search;
	this.url.query = copy(location.query);
	location.on('change', this.updateLinks);
	this.count = new ObservableValue(count);
	this.count.on('change', this.updateLinks);
	this.current = new ObservableValue(count);
};

ee(Object.defineProperties(Pagination.prototype, assign({
	toDOM: d(function (document) { return (new PaginationDom(this)).toDOM(document); })<commit_msg>Pagination-active class changed to appear on a element. #561<commit_after>'use strict';

var assign          = require('es5-ext/object/assign')
  , copy            = require('es5-ext/object/copy')
  , value           = require('es5-ext/object/valid-value')
  , ee              = require('event-emitter')
  , d               = require('d')
  , autoBind        = require('d/auto-bind')
  , memoizeMethods  = require('memoizee/methods-plain')
  , ObservableValue = require('observable-value')
  , replaceContent  = require('dom-ext/element/#/replace-content')
  , formatUrl       = require('url3/format')
  , parseUrl        = require('url3/parse')
  , ns              = require('mano').domjs.ns
  , location        = require('mano/lib/client/location');

var PaginationDom = function (pagination) {
	this.pagination = pagination;
	this.list = ns.ul({ class: 'pagination' });
	this.dom = ns._if(this.pagination.count.gt(1), this.list).toDOM(document);
	this.reload();
	this.pagination.count.on('change', this.reload);
};
Object.defineProperties(PaginationDom.prototype, assign({
	toDOM: d(function (document) { return this.dom; })
}, autoBind({
	reload: d(function () {
		var i, l = this.pagination.count.value, buttons = [];
		if (l < 2) return;
		for (i = 1; i <= l; ++i) buttons.push(this.getPageButton(i));
		replaceContent.call(this.list, buttons);
	})
}), memoizeMethods({
	getPageButton: d(function (page) {
		return ns.li(ns.a({ class: ns._if(this.pagination.current.eq(page), 'pagination-active'),
					href: ns._if(this.pagination.current.eq(page), null, this.pagination.getLink(page)) },
				page));
	})
})));

var Pagination = module.exports = function (pathname, count, current) {
	if (!(this instanceof Pagination)) return new Pagination(pathname, count, current);
	this.pathname = String(value(pathname));
	this.url = parseUrl(this.pathname, true);
	delete this.url.search;
	this.url.query = copy(location.query);
	location.on('change', this.updateLinks);
	this.count = new ObservableValue(count);
	this.count.on('change', this.updateLinks);
	this.current = new ObservableValue(count);
};

ee(Object.defineProperties(Pagination.prototype, assign({
	toDOM: d(function (document) { return (new PaginationDom(this)).toDOM(document); })
{'fraction_non_alphanumeric': 0.16948008102633355, 'fraction_numerical': 0.0042763898266936756, 'mean_word_length': 3.9876543209876543, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3602379', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1445, 'n_words': 269}