<commit_before>/**
 *  Poppy Pagination
 *  Generate page options/results using pre-existing content
 *
 *  Copyright 2012-2014, <NAME> (http://mbrooks.info)
 *  Licensed under the MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 *
 *  Dependencies:
 *    jquery.js
 */

(function($) {
	var methods = {
		"init" : function(config, callback) {

			// default settings
			$.extend({
				totalResults : 0,
				perPage      : 10,
				startPage    : 1
			}, config);

			genResults($(this), config, callback);
		},

		"destroy" : function() {
			$(this).removeData();
		}
	};

	$.fn.PoppyPagination = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}
		else
		if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		}
		else {
			$.error('Method ' +  method + ' does not exist in jQuery.PoppyPagination');
		}
	};

	/**
	 * Generate last/next result pages
	 * @param Object $this
	 * @param Object data
	 * @param Function callback
	 */
	function genResults($this, data, callback) {
		var res = calcPageResults(data);

		// if results are available, create page elements
		if (res.total > 0) {
			var node  = $this.find('.poppy_pagination');

			if (node[0]) node.remove();

			// .. header
			var block1 = $('<div></div>')
				.addClass('poppy_pagination');

			var div1 = createResultBarElm(res, callback),
				div2 = createPaginateElm( res, callback);
			block1.append(div2, div1);

			$this.prepend(block1);

			// .. footer
			var block2 = block1.clone(true);
			block2.append(block2.children().get().reverse());

			$this.append(block2);
		}
	}

	/**
	 * Create page results bar elements
	 * @param Object data
	 * @param Function callback
	 * @returns Object
	 */
	function createResultBarElm(data, callback) {

		// create result detail elements
		var strong1 = $('<strong>' + data.first + '</strong>'),
			strong2 = $('<strong>' + data.last  + '</strong>'),
			strong3 = $('<strong>' + data.total + '</strong>');

		var span = $('<span></span>')
			.append(strong1, ' - ', strong2, ' of ', strong3, ' found');

		var form = $('<form></form>');

		if (data.total > 10 && !data.limit) {

			// .. select menu
			var label = $('<label></label>').append('Viewing');
			form.append(label);

			var option = $('<option>-</option>'),
				select = $('<select></select>')
				.append(option);

			var opts = [ 10, 20, 30, 40, 50 ];

			// .. options
			$.each(opts, function() {
				if (this <= data.total) {
					option = $('<option>' + this + '</option>')
						.attr('value', this);
					select.append(option);

					// if the option is selected
					if (this == data.limit) {
						select.selectedIndex = this;
					}
				}
			});

			// attach menu options events
			if (callback) {
				select.change(function() {
					data.limit = parseInt(this.value);
					callback(data);
				});
			}

			form.append(select);
		}

		// return HTML object
		return $('<div></div>')
			.addClass('options')
			.append(span, form);
	}

	/**
	 * Create the first/last and subsequent page links
	 * @param Object data<commit_msg>Fixed usage bug jQuery $.extend() not falling back to configuration defaults when options are not defined<commit_after>/**
 *  Poppy Pagination
 *  Generate page options/results using pre-existing content
 *
 *  Copyright 2012-2014, <NAME> (http://mbrooks.info)
 *  Licensed under the MIT license:
 *  http://www.opensource.org/licenses/mit-license.php
 *
 *  Dependencies:
 *    jquery.js
 */

(function($) {
	var methods = {
		"init" : function(config, callback) {

			// config defaults
			config = $.extend({
				totalResults : 0,
				perPage      : 10,
				startPage    : 1
			}, config);

			genResults($(this), config, callback);
		},

		"destroy" : function() {
			$(this).removeData();
		}
	};

	$.fn.PoppyPagination = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}
		else
		if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		}
		else {
			$.error('Method ' +  method + ' does not exist in jQuery.PoppyPagination');
		}
	};

	/**
	 * Generate last/next result pages
	 * @param Object $this
	 * @param Object data
	 * @param Function callback
	 */
	function genResults($this, data, callback) {
		var res = calcPageResults(data);

		// if results are available, create page elements
		if (res.total > 0) {
			var node  = $this.find('.poppy_pagination');

			if (node[0]) node.remove();

			// .. header
			var block1 = $('<div></div>')
				.addClass('poppy_pagination');

			var div1 = createResultBarElm(res, callback),
				div2 = createPaginateElm( res, callback);
			block1.append(div2, div1);

			$this.prepend(block1);

			// .. footer
			var block2 = block1.clone(true);
			block2.append(block2.children().get().reverse());

			$this.append(block2);
		}
	}

	/**
	 * Create page results bar elements
	 * @param Object data
	 * @param Function callback
	 * @returns Object
	 */
	function createResultBarElm(data, callback) {

		// create result detail elements
		var strong1 = $('<strong>' + data.first + '</strong>'),
			strong2 = $('<strong>' + data.last  + '</strong>'),
			strong3 = $('<strong>' + data.total + '</strong>');

		var span = $('<span></span>')
			.append(strong1, ' - ', strong2, ' of ', strong3, ' found');

		var form = $('<form></form>');

		if (data.total > 10 && data.limit > 1) {

			// .. select menu
			var label = $('<label></label>').append('Viewing');
			form.append(label);

			var option = $('<option>-</option>'),
				select = $('<select></select>')
				.append(option);

			var opts = [ 10, 20, 30, 40, 50 ];

			// .. options
			$.each(opts, function() {
				if (this <= data.total) {
					option = $('<option>' + this + '</option>')
						.attr('value', this);
					select.append(option);

					// if the option is selected
					if (this == data.limit) {
						select.selectedIndex = this;
					}
				}
			});

			// attach menu options events
			if (callback) {
				select.on('change', function() {
					data.limit = parseInt(this.value);
					callback(data);
				});
			}

			form.append(select);
		}

		// return HTML object
		return $('<div></div>')
			.addClass('options')
			.append(span, form);
	}

	/**
	 * Create the first/last and subsequent page links
	 * @param Object data
{'fraction_non_alphanumeric': 0.17923497267759564, 'fraction_numerical': 0.014207650273224045, 'mean_word_length': 2.8683574879227054, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3070769', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2048, 'n_words': 507}