2013-04-12 17:24:06 +04:00
|
|
|
<html>
|
|
|
|
|
|
|
|
|
|
<script src="jquery.js"></script>
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
|
|
function focus(elem){
|
|
|
|
|
$('.current.square').removeClass('current')
|
|
|
|
|
return $(elem).closest('.square').addClass('current')
|
|
|
|
|
}
|
|
|
|
|
function clickHandler(){
|
|
|
|
|
focus(this)
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-16 15:45:49 +04:00
|
|
|
|
|
|
|
|
|
2013-04-16 15:56:22 +04:00
|
|
|
/* Focus next/prev container element
|
|
|
|
|
*
|
|
|
|
|
* This will shift focus within a container.
|
|
|
|
|
*
|
|
|
|
|
* If we reach the start/end of the container, we will "warp" around it
|
|
|
|
|
* and focus an element from the other end.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2013-04-16 15:45:49 +04:00
|
|
|
function shiftSquare(direction, n){
|
|
|
|
|
if(n == null){
|
|
|
|
|
n = 1
|
|
|
|
|
}
|
2013-04-12 17:24:06 +04:00
|
|
|
var cur = $('.current.square')
|
|
|
|
|
// trigger the event...
|
|
|
|
|
cur.closest('.container')
|
2013-04-16 15:45:49 +04:00
|
|
|
.trigger('shift'+direction, n)
|
|
|
|
|
// if we move to the same spot, do nothing...
|
|
|
|
|
if(n == 0){
|
|
|
|
|
return cur
|
|
|
|
|
}
|
2013-04-16 15:56:22 +04:00
|
|
|
// see if we need to warp arund...
|
2013-04-16 15:45:49 +04:00
|
|
|
if(cur[direction+'All']('.square').length < n){
|
|
|
|
|
var sq = cur.closest('.container').children('.square')
|
|
|
|
|
var i = sq.index(cur)
|
|
|
|
|
return focus($(sq[ direction == 'next'
|
|
|
|
|
? (i + n) % sq.length
|
|
|
|
|
: sq.length - (Math.abs(i - n) % sq.length) ]))
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
|
|
|
|
// shift the current element...
|
2013-04-16 15:45:49 +04:00
|
|
|
return focus($(cur[direction+'All']('.square')[n-1]))
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
2013-04-16 15:56:22 +04:00
|
|
|
// shift focus left/right wrappers...
|
2013-04-16 15:45:49 +04:00
|
|
|
function next(n){
|
|
|
|
|
return shiftSquare('next', n)
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
2013-04-16 15:45:49 +04:00
|
|
|
function prev(n){
|
|
|
|
|
return shiftSquare('prev', n)
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
|
|
|
|
|
2013-04-16 15:45:49 +04:00
|
|
|
|
|
|
|
|
|
2013-04-12 17:24:06 +04:00
|
|
|
// these will roll the container...
|
|
|
|
|
// XXX this needs a means to update the element content...
|
2013-04-16 15:45:49 +04:00
|
|
|
function rollRight(n){
|
|
|
|
|
if(n == null){
|
|
|
|
|
n = 1
|
|
|
|
|
}
|
|
|
|
|
$($('.square').splice(0, n)).appendTo($('.container'))
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
2013-04-16 15:45:49 +04:00
|
|
|
function rollLeft(n){
|
|
|
|
|
if(n == null){
|
|
|
|
|
n = 1
|
|
|
|
|
}
|
|
|
|
|
var sq = $('.square')
|
|
|
|
|
var l = sq.length
|
|
|
|
|
$(sq.splice(l-n, l)).prependTo($('.container'))
|
2013-04-12 17:24:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-04-16 15:45:49 +04:00
|
|
|
|
2013-04-12 17:24:06 +04:00
|
|
|
$(function(){
|
|
|
|
|
$('.container')
|
2013-04-16 15:45:49 +04:00
|
|
|
.on('shiftnext', function(evt, n){rollRight(n)})
|
|
|
|
|
.on('shiftprev', function(evt, n){rollLeft(n)})
|
2013-04-12 17:24:06 +04:00
|
|
|
|
|
|
|
|
$('.square')
|
|
|
|
|
.click(clickHandler)
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
|
|
|
.container {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
height: auto;
|
|
|
|
|
min-width: 0px;
|
|
|
|
|
overflow: visible;
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
font-size: 0;
|
|
|
|
|
|
|
|
|
|
background: gray;
|
|
|
|
|
padding: 10px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.square {
|
|
|
|
|
position: relative;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
text-align;left;
|
|
|
|
|
width: 100px;
|
|
|
|
|
height: 100px;
|
|
|
|
|
background: silver;
|
|
|
|
|
font-size: 12pt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.current.square {
|
|
|
|
|
background: red;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
|
|
|
2013-04-16 15:45:49 +04:00
|
|
|
<button onclick="prev(5)"><<</button>
|
|
|
|
|
<button onclick="prev()"><</button>
|
|
|
|
|
<button onclick="next()">></button>
|
|
|
|
|
<button onclick="next(5)">>></button>
|
2013-04-12 17:24:06 +04:00
|
|
|
|
|
|
|
|
<div class="meta-container">
|
|
|
|
|
<div class="container">
|
|
|
|
|
<!-- BUG: when current is first hell breaks lose... -->
|
|
|
|
|
<div class="square">1</div>
|
|
|
|
|
<div class="square">2</div>
|
|
|
|
|
<div class="square current">3</div>
|
|
|
|
|
<div class="square">4</div>
|
|
|
|
|
<div class="square">5</div>
|
|
|
|
|
<div class="square">6</div>
|
|
|
|
|
<div class="square">7</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</body>
|
|
|
|
|
<!-- vim:set ts=4 sw=4 : -->
|
|
|
|
|
</html>
|