Last active
December 24, 2015 03:29
-
-
Save nickfun/6737562 to your computer and use it in GitHub Desktop.
page scratch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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