mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
cleanup and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
429ad0730b
commit
8ac7b160e6
@ -17,8 +17,8 @@ $(document).ready(function() {
|
|||||||
.swipe({
|
.swipe({
|
||||||
swipeLeft: nextImage,
|
swipeLeft: nextImage,
|
||||||
swipeRight: prevImage,
|
swipeRight: prevImage,
|
||||||
swipeUp: demoteImage,
|
swipeUp: shiftImageUp,
|
||||||
swipeDown: promoteImage,
|
swipeDown: shiftImageDown,
|
||||||
})
|
})
|
||||||
/* XXX jquery.mobile handlers... (with this I'm getting way too much bling)
|
/* XXX jquery.mobile handlers... (with this I'm getting way too much bling)
|
||||||
.bind('swipeleft', function(e){
|
.bind('swipeleft', function(e){
|
||||||
@ -32,13 +32,13 @@ $(document).ready(function() {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
$(".image").click(handleClick)
|
$(".image").click(handleImageClick)
|
||||||
|
|
||||||
// control elements...
|
// control elements...
|
||||||
$('.next-image').click(nextImage)
|
$('.next-image').click(nextImage)
|
||||||
$('.prev-image').click(prevImage)
|
$('.prev-image').click(prevImage)
|
||||||
$('.demote').click(demoteImage)
|
$('.demote').click(shiftImageUp)
|
||||||
$('.promote').click(promoteImage)
|
$('.promote').click(shiftImageDown)
|
||||||
$('.toggle-wide').click(toggleWideView)
|
$('.toggle-wide').click(toggleWideView)
|
||||||
$('.toggle-single').click(toggleRibbonView)
|
$('.toggle-single').click(toggleRibbonView)
|
||||||
|
|
||||||
@ -50,9 +50,10 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
// set the default position and init...
|
// set the default position and init...
|
||||||
$('.current-image').click()
|
$('.current-image').click()
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function loadImages(json){
|
function loadImages(json){
|
||||||
var images = json.images
|
var images = json.images
|
||||||
var ribbon = $('.ribbon').last()
|
var ribbon = $('.ribbon').last()
|
||||||
@ -62,20 +63,22 @@ function loadImages(json){
|
|||||||
for(var i = 0; i < images.length; i++){
|
for(var i = 0; i < images.length; i++){
|
||||||
$('<div class="image"></div>')
|
$('<div class="image"></div>')
|
||||||
.css({ 'background-image': 'url('+images[i]+')' })
|
.css({ 'background-image': 'url('+images[i]+')' })
|
||||||
.click(handleClick)
|
.click(handleImageClick)
|
||||||
.appendTo(ribbon)
|
.appendTo(ribbon)
|
||||||
}
|
}
|
||||||
ribbon.children().first().click()
|
ribbon.children().first().click()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// XXX jquery.gestures handler...
|
// XXX jquery.gestures handler...
|
||||||
function handleGestures(e){
|
function handleGestures(e){
|
||||||
switch (e){
|
switch (e){
|
||||||
case 'N':
|
case 'N':
|
||||||
demoteImage()
|
shiftImageUp()
|
||||||
break
|
break
|
||||||
case 'S':
|
case 'S':
|
||||||
promoteImage()
|
shiftImageDown()
|
||||||
break
|
break
|
||||||
case 'E':
|
case 'E':
|
||||||
prevImage()
|
prevImage()
|
||||||
@ -87,7 +90,8 @@ function handleGestures(e){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleClick(e) {
|
|
||||||
|
function handleImageClick(e) {
|
||||||
|
|
||||||
var cur = $(this)
|
var cur = $(this)
|
||||||
|
|
||||||
@ -119,6 +123,10 @@ function handleClick(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// key configuration...
|
||||||
|
// XXX need to make this handle modifiers gracefully...
|
||||||
var keys = {
|
var keys = {
|
||||||
toggleHelpKeys: [72],
|
toggleHelpKeys: [72],
|
||||||
toggleRibbonView: [70],
|
toggleRibbonView: [70],
|
||||||
@ -151,20 +159,20 @@ function handleKeys(event){
|
|||||||
if(event.ctrlKey){
|
if(event.ctrlKey){
|
||||||
createRibbon('next')
|
createRibbon('next')
|
||||||
}
|
}
|
||||||
promoteImage()
|
shiftImageDown()
|
||||||
}()
|
}()
|
||||||
: (fn(code, keys.demoteKeys) >= 0) ? function(){
|
: (fn(code, keys.demoteKeys) >= 0) ? function(){
|
||||||
if(event.ctrlKey){
|
if(event.ctrlKey){
|
||||||
createRibbon('prev')
|
createRibbon('prev')
|
||||||
}
|
}
|
||||||
demoteImage()
|
shiftImageUp()
|
||||||
}()
|
}()
|
||||||
: (fn(code, keys.downKeys) >= 0) ? function(){
|
: (fn(code, keys.downKeys) >= 0) ? function(){
|
||||||
if(event.shiftKey){
|
if(event.shiftKey){
|
||||||
if(event.ctrlKey){
|
if(event.ctrlKey){
|
||||||
createRibbon('next')
|
createRibbon('next')
|
||||||
}
|
}
|
||||||
promoteImage()
|
shiftImageDown()
|
||||||
} else {
|
} else {
|
||||||
focusBelowRibbon()
|
focusBelowRibbon()
|
||||||
}
|
}
|
||||||
@ -174,7 +182,7 @@ function handleKeys(event){
|
|||||||
if(event.ctrlKey){
|
if(event.ctrlKey){
|
||||||
createRibbon('prev')
|
createRibbon('prev')
|
||||||
}
|
}
|
||||||
demoteImage()
|
shiftImageUp()
|
||||||
} else {
|
} else {
|
||||||
focusAboveRibbon()
|
focusAboveRibbon()
|
||||||
}
|
}
|
||||||
@ -188,6 +196,7 @@ function handleKeys(event){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// modes...
|
// modes...
|
||||||
function showRibbon(){
|
function showRibbon(){
|
||||||
$('.single-image-mode')
|
$('.single-image-mode')
|
||||||
@ -213,6 +222,9 @@ function toggleRibbonView(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// XXX replace this with adequate zooming...
|
||||||
// XXX need to reposition the whole thing correctly...
|
// XXX need to reposition the whole thing correctly...
|
||||||
function toggleWideView(){
|
function toggleWideView(){
|
||||||
if($('.wide-view-mode').length > 0){
|
if($('.wide-view-mode').length > 0){
|
||||||
@ -236,34 +248,33 @@ function toggleWideView(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// basic navigation...
|
// basic navigation...
|
||||||
function firstImage(){
|
function firstImage(){
|
||||||
$('.current-ribbon').children('.image').first().click()
|
$('.current-ribbon').children('.image').first().click()
|
||||||
}
|
}
|
||||||
|
|
||||||
function prevImage(){
|
function prevImage(){
|
||||||
$('.current-image').prev('.image').click()
|
$('.current-image').prev('.image').click()
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextImage(){
|
function nextImage(){
|
||||||
$('.current-image').next('.image').click()
|
$('.current-image').next('.image').click()
|
||||||
}
|
}
|
||||||
|
|
||||||
function lastImage(){
|
function lastImage(){
|
||||||
$('.current-ribbon').children('.image').last().click()
|
$('.current-ribbon').children('.image').last().click()
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX select appropriate image...
|
// XXX select appropriate image...
|
||||||
function focusAboveRibbon(){
|
function focusAboveRibbon(){
|
||||||
$('.current-ribbon').prev('.ribbon').children('.image').first().click()
|
$('.current-ribbon').prev('.ribbon').children('.image').first().click()
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX select appropriate image...
|
// XXX select appropriate image...
|
||||||
function focusBelowRibbon(){
|
function focusBelowRibbon(){
|
||||||
$('.current-ribbon').next('.ribbon').children('.image').first().click()
|
$('.current-ribbon').next('.ribbon').children('.image').first().click()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// basic actions...
|
||||||
|
|
||||||
// create ribbon above/below helpers...
|
// create ribbon above/below helpers...
|
||||||
function createRibbon(direction){
|
function createRibbon(direction){
|
||||||
if(direction == 'next'){
|
if(direction == 'next'){
|
||||||
@ -291,7 +302,6 @@ function createRibbon(direction){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Modifiers...
|
|
||||||
|
|
||||||
// XXX sort elements correctly...
|
// XXX sort elements correctly...
|
||||||
function mergeRibbons(direction){
|
function mergeRibbons(direction){
|
||||||
@ -299,6 +309,7 @@ function mergeRibbons(direction){
|
|||||||
.children()
|
.children()
|
||||||
.detach()
|
.detach()
|
||||||
.insertAfter('.current-image')
|
.insertAfter('.current-image')
|
||||||
|
// animate...
|
||||||
$('.current-ribbon')[direction]('.ribbon')
|
$('.current-ribbon')[direction]('.ribbon')
|
||||||
.slideUp(function(){
|
.slideUp(function(){
|
||||||
$(this).remove()
|
$(this).remove()
|
||||||
@ -306,8 +317,11 @@ function mergeRibbons(direction){
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// now the actual modifiers...
|
|
||||||
|
|
||||||
|
|
||||||
|
// Modifiers...
|
||||||
|
|
||||||
|
// now the actual modifiers...
|
||||||
function shiftImage(direction){
|
function shiftImage(direction){
|
||||||
if($('.current-ribbon')[direction]('.ribbon').length == 0){
|
if($('.current-ribbon')[direction]('.ribbon').length == 0){
|
||||||
createRibbon(direction)
|
createRibbon(direction)
|
||||||
@ -331,13 +345,12 @@ function shiftImage(direction){
|
|||||||
$('.current-image').click()
|
$('.current-image').click()
|
||||||
}
|
}
|
||||||
|
|
||||||
function promoteImage(){
|
function shiftImageDown(){
|
||||||
return shiftImage('next')
|
return shiftImage('next')
|
||||||
}
|
}
|
||||||
|
|
||||||
// XXX this has problems, when creating a new ribbon this does not settle
|
// XXX this has problems, when creating a new ribbon this does not settle
|
||||||
// into a correct spot...
|
// into a correct spot...
|
||||||
function demoteImage(){
|
function shiftImageUp(){
|
||||||
return shiftImage('prev')
|
return shiftImage('prev')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -77,8 +77,8 @@
|
|||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<button onclick="demoteImage()">demote image (shift-up)</button><br>
|
<button onclick="shiftImageUp()">demote image (shift-up)</button><br>
|
||||||
<button onclick="promoteImage()">promote image (shift-down)</button><br>
|
<button onclick="shiftImageDown()">promote image (shift-down)</button><br>
|
||||||
NOTE: ctrl-shift-up / ctrl-shift-down will demote / promote an image to a new empty ribbon (the default if no ribbon exists)
|
NOTE: ctrl-shift-up / ctrl-shift-down will demote / promote an image to a new empty ribbon (the default if no ribbon exists)
|
||||||
|
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user