Skip to content

Instantly share code, notes, and snippets.

@nickfun
Last active December 24, 2015 03:29
Show Gist options
  • Save nickfun/6737562 to your computer and use it in GitHub Desktop.
Save nickfun/6737562 to your computer and use it in GitHub Desktop.
page scratch
<!doctype html>
<html>
<head>
<title>Scratch</title>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://raw.github.com/lodash/lodash/2.1.0/dist/lodash.js"></script>
<script src="./test.js"></script>
</head>
<body>
<h1>Scratch</h1>
<div id="output"></div>
</body>
// Scratch!!!!!
var tpl = _.template(' <a href="<%- link %>"><%- text %></a> ');
function out(str) {
$('#output').append(str);
}
function render( iCurrentPage, iMaxPages, iPagePadding ) {
var start,end,general=' ',iTotal=(iPagePadding*2);
if( iCurrentPage-iPagePadding < 0 ) {
start = 0;
} else {
start = iCurrentPage-iPagePadding;
}
if( iCurrentPage+iPagePadding > iMaxPages ) {
end = iMaxPages;
} else {
end = iCurrentPage+iPagePadding;
}
if( start != 0 && end != iMaxPages ) {
start = iCurrentPage - iPagePadding;
end = iCurrentPage + iPagePadding;
general = 'general';
}
// expand end?
if( end < iTotal && iTotal < iMaxPages ) {
end = iTotal;
}
// end start?
if( end+iPagePadding>iMaxPages ) {
start = (end-iTotal>0) ? end-iTotal : 0;
}
x=[];
for( var i=start;i<=end;i++ ) {
x.push(i);
}
//console.log(iCurrentPage,start,end,x,general,iTotal);
console.log(x);
}
$(function() {
var iMax = 20;
for( var i=0; i<=iMax; i++ ) {
render( i, iMax, 3 );
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment