jQuery Plugin: TinyPagination

On February 6, 2012, in CSS, HTML, JavaScript, by Mewes Kochheim


With this plugin I tried to achieve the goal to have a fully functional pagination for usage in areas with a very limited amount of space, like sidebars. To make the pagination more compact it shows by default only the “first”, “previous”, “next”, “last” button, together with a button showing the current page. After clicking on that last mentioned button, a list with proceeding and following pages will be displayed. Those list are shown vertically following the idea that i should be used for sidebars. This kind of layout allows to have huge numbers of pages (several hundreds) without the pagination to screw the overall page layout.


.tinypagination( options )

  • options A map of data containing the user settings.  All settings are optional.

.tinypagination( method [, parameter1 [, parameter2] ] )

  • method A string containing the name of the method to be called.


Name Default Value Description
change function(page, sender) {} Callback function called everytime the page value changes.
classBig tpBig The class name representing the big button.
classBottom tpBottom The class name representing the bottom page list.
classButton tpButton The class name representing all buttons excluding the list buttons.
classList tpList The class name representing both page lists.
classListButton tpListButton The class name representing the list buttons.
classSmall tpSmall The class name representing the all small buttons.
classTop tpTop The class name representing the top page list.
contentFirst << The content of the “first” button.
contentLast >> The content of the “last” button.
contentNext > The content of the “next” button.
contentPrevious < The content of the “previous” button.
contentSeperator / The seperator used for the “current” button t o seperate the current page from the max. page.
current 1 The page currently visible page. The first page is 1, not 0.
pages 1 The amount of pages.
steps [1, 2, 3] The steps used for the page lists. [1,2,3,8] would generate for page 50 the following page lists: [42,47,48,49], [51,52,53,58]
tag div The tag used for all HTML elements the plugin is creating.


Name Parameters Description
destroy Destroys the HTML elements and event handlers created by the plugin.
first Jumps to the first page.
previous Jumps to the previous page.
next Jumps to the next page.
last Jumps to the last page.
page int page Jumps to the given page.
exists int page Checks whether the given page exists. Returns true or false.
options object options, boolean reinit Expands the internal options object with the given options. If reinit is set to true, the pagination will be re-initialized.


<div id="list">
<div id="title">Persons</div>
<ul id="items">
	<li>Person 1</li>
	<li>Person 2</li>
	<li>Person 3</li>
	<li>Person 4</li>
	<li>Person 5</li>
	<li>Person 6</li>
	<li>Person 7</li>
	<li>Person 8</li>
	<li>Person 9</li>
	<li>Person 10</li>
<div id="pagination"></div>


// Init
    'current' : 1,
    'pages' : 50,
    'change' : function(page, sender) {
        var items = $('#items li');
        for (var i = 0; i < items.length; i++) {
            $(items.get(i)).html('Person ' + ((page - 1) * 10 + i + 1));

// Public methods
$('#pagination').tinypagination('page', 7);
  { 'current' : 7, 'steps' : [2,4,6] });
  { 'current' : 7, 'steps' : [2,4,6] }, true);
console.log($('#pagination').tinypagination('exists', 40));



Tagged with:  

UserScript: YTProfit

On June 2, 2011, in JavaScript, UserScript, by Mewes Kochheim

A few days ago I read the article “How Much Is Rebecca Black Making From Friday?” on Mashable. It included an interesting information:

According to Forbes columnist Chris Barth, YouTube makes about $1 per thousand page views, of which content creators like Black (and Ark Music Factory, the Los Angeles-based producer that wrote the tune) get 68% of the profit.

Based on that the formula to calculate the profit a content creator makes is: Profit = Views / 1000 * 0.68

Now let’s put that in in a small UserScript which inserts this number to YouTube. It will work on channel pages and normal video pages. However you need to have Greasemonkey installed to make it work.

Click here to install it.

// ==UserScript==
// @name           YTProfit
// @namespace      bananenpelle.de
// @include        http://www.youtube.com/watch?*
// @include        http://www.youtube.com/user/*
// @require        http://code.jquery.com/jquery-1.5.min.js
// ==/UserScript==
(function($) {
		var reference = '<a href="http://mashable.com/2011/03/26/rebecca-black-friday/" target="_blank">*</a>';
		// http://www.youtube.com/watch?*
		var elem1 = $('#watch-description-extras');
		if (elem1 != null) {
~'+calcProfit($('.watch-view-count strong').html())+'$'+reference+'

		// http://www.youtube.com/user/*
		var elem2 = $('.profile_info');
		if (elem2 != null) {
<div class="show_info outer-box-bg-as-border">
<div class="profile-info-label">Profit:</div>
<div id="profile_show_total_video_views" class="profile-info-value">~'+
	function calcProfit(views_str) {
		if (views_str != null && views_str != '') {
			// parse & calculate & round
			views_str = views_str.replace(/[,. ]/g, '');
			views_str = new Number(parseInt(views_str) / 1000 * 0.68).toFixed(2);
			// add commas
			var p = views_str.split('.'),
				ip = p[0],
				rgip = /(\d+)(\d{3})/;
			while (rgip.test(ip)) {
				ip = ip.replace(rgip, '$1'+','+'$2');
			return ip + (p.length > 1 ? '.' + p[1] : '');
		return '-/-'
	function log(obj) { unsafeWindow.console.log(obj); }
Tagged with:  

jQuery Plugin: keysequence Event

On March 26, 2011, in JavaScript, by Mewes Kochheim


This plugin adds a new event to jQuery. It works similar to the keydown, keyup and keypress events but instead of getting fired for each key it will only get fired if a specified key code combination was entered. Therefore it shares the behaviour with the other key events. This means that the element with the event must have the focus to capture the entered keys.

Initially this plugin was only designed to add the Konami Code to a web site. But after some cleaning it became a customizable event. Additionally it comes with a helper class called KeySequenceHelper to convert strings to key code arrays and the other way around.


.keysequence( sequence, handler(eventObject) )

  • sequence An array of key codes which trigger the event.
  • handler(eventObject) A function to execute each time the event is triggered.

.keysequence( sequence, [ eventData ], handler(eventObject) )

  • sequence An array of key codes which trigger the event.
  • eventData A map of data that will be passed to the event handler. (optional)
  • handler(eventObject) A function to execute each time the event is triggered.



// event initialization with a key code array
var keyCodeArray = [65,67,68,69];
$(window).keysequence(keyCodeArray, function(event) {
	var string = KeySequenceHelper.keyCodeArrayToString(event.sequence);
	$('body').append(event.sequence)); // 65, 67, 68, 69
	$('body').append(string); // ABCD

// event initialization with a string
var keyCodeArray = KeySequenceHelper.stringToKeyCodeArray('foobar');
$(window).keysequence(keyCodeArray, function(event) {
	var string = KeySequenceHelper.keyCodeArrayToString(event.sequence);
	$('body').append(string); // FOOBAR

// event initialization with the Konami Code
$(window).keysequence(KeySequenceHelper.konamiCode, function(event) {

// manual event triggering


Tagged with: