mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
renamed promptPlus to formDialog(...), rewritten alert and prompt using the new functionality, several bugs squashed...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9721fbef61
commit
f7e635c05f
34
ui/base.js
34
ui/base.js
@ -460,8 +460,9 @@ function rollRibbon(n, ribbon, extend, no_compensate_shift){
|
||||
|
||||
function focusImage(image){
|
||||
image.closest('.viewer').find('.current.image').removeClass('current')
|
||||
image.addClass('current')
|
||||
$('.viewer').trigger('focusingImage', [image])
|
||||
return image.addClass('current')
|
||||
return image
|
||||
}
|
||||
|
||||
|
||||
@ -694,6 +695,7 @@ function nextImage(n, mode){
|
||||
var target = getImage().nextAll('.image' + mode)
|
||||
if(target.length < n){
|
||||
target = target.last()
|
||||
target = target.length == 0 ? getImage() : target
|
||||
// XXX this fires if we hit the end of the currently loaded
|
||||
// images while scrolling very fast rather than when we are
|
||||
// out of images in the current ribbon...
|
||||
@ -709,6 +711,7 @@ function prevImage(n, mode){
|
||||
var target = getImage().prevAll('.image' + mode)
|
||||
if(target.length < n){
|
||||
target = target.last()
|
||||
target = target.length == 0 ? getImage() : target
|
||||
// XXX this fires if we hit the end of the currently loaded
|
||||
// images while scrolling very fast rather than when we are
|
||||
// out of images in the current ribbon...
|
||||
@ -762,17 +765,19 @@ function prevRibbon(mode){
|
||||
var target_ribbon = getRibbon(cur).prevAll('.ribbon' + NAV_RIBBON_DEFAULT).first()
|
||||
var target = getImageBefore(cur, target_ribbon)
|
||||
|
||||
// no ribbon above...
|
||||
if(target_ribbon.length == 0){
|
||||
flashIndicator('top')
|
||||
}
|
||||
|
||||
// first image...
|
||||
if(target.length == 0){
|
||||
target = target_ribbon.find('.image' + mode).first()
|
||||
|
||||
target = getImage()
|
||||
} else {
|
||||
var next = target.nextAll('.image' + mode).first()
|
||||
target = next.length > 0 ? next : target
|
||||
// first image...
|
||||
if(target.length == 0){
|
||||
target = target_ribbon.find('.image' + mode).first()
|
||||
|
||||
} else {
|
||||
var next = target.nextAll('.image' + mode).first()
|
||||
target = next.length > 0 ? next : target
|
||||
}
|
||||
}
|
||||
return centerView(focusImage(target))
|
||||
}
|
||||
@ -782,14 +787,17 @@ function nextRibbon(mode){
|
||||
var target_ribbon = getRibbon(cur).nextAll('.ribbon' + NAV_RIBBON_DEFAULT).first()
|
||||
var target = getImageBefore(cur, target_ribbon)
|
||||
|
||||
// no ribbon below...
|
||||
if(target_ribbon.length == 0){
|
||||
flashIndicator('bottom')
|
||||
target = getImage()
|
||||
} else {
|
||||
// first image...
|
||||
if(target.length == 0){
|
||||
target = target_ribbon.find('.image' + mode).first()
|
||||
}
|
||||
}
|
||||
|
||||
// first image...
|
||||
if(target.length == 0){
|
||||
target = target_ribbon.find('.image' + mode).first()
|
||||
}
|
||||
return centerView(focusImage(target))
|
||||
}
|
||||
|
||||
|
||||
105
ui/ui.js
105
ui/ui.js
@ -378,69 +378,6 @@ function hideOverlay(root){
|
||||
}
|
||||
|
||||
|
||||
|
||||
/************************************************ Standard dialogs ***/
|
||||
|
||||
var _alert = alert
|
||||
function alert(){
|
||||
var res = $.Deferred()
|
||||
showInOverlay($('.viewer'), $('<span/>')
|
||||
.html(Array.apply(null, arguments).join(' ')))
|
||||
.addClass('alert dialog')
|
||||
.on('close accept', function(){
|
||||
res.resolve()
|
||||
})
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
var _prompt = prompt
|
||||
function prompt(message, dfl, btn){
|
||||
btn = btn == null ? 'OK' : btn
|
||||
var root = $('.viewer')
|
||||
var res = $.Deferred()
|
||||
|
||||
var form = $('<div>'+
|
||||
'<div class="text">'+message+'</div>'+
|
||||
'<input type="text" tabindex=1/>'+
|
||||
'<button tabindex=2>'+btn+'</button>'+
|
||||
'</div>')
|
||||
|
||||
var overlay = showInOverlay(root, form)
|
||||
.addClass('prompt dialog')
|
||||
.on('close', function(){
|
||||
res.reject()
|
||||
})
|
||||
.on('accept', function(){
|
||||
res.resolve(form.find('input').attr('value'))
|
||||
})
|
||||
|
||||
form.find('button')
|
||||
.click(function(){
|
||||
overlay.trigger('accept')
|
||||
hideOverlay(root)
|
||||
})
|
||||
|
||||
var input = form.find('input')
|
||||
|
||||
input
|
||||
.focus()
|
||||
setTimeout(function(){
|
||||
input
|
||||
.attr('value', dfl == null ? '' : dfl)
|
||||
.select()
|
||||
}, 100)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function confirm(){
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
var FIELD_TYPES = {
|
||||
text: {
|
||||
type: 'text',
|
||||
@ -519,9 +456,11 @@ var FIELD_TYPES = {
|
||||
//
|
||||
// XXX add form testing...
|
||||
// XXX add undefined field handling/reporting...
|
||||
// XXX find a better name...
|
||||
function promptPlus(message, config, btn, cls){
|
||||
// XXX revise...
|
||||
function formDialog(root, message, config, btn, cls){
|
||||
cls = cls == null ? '' : cls
|
||||
root = root == null ? $('.viewer') : root
|
||||
|
||||
var form = $('<div class="form"/>')
|
||||
var data = {}
|
||||
var res = $.Deferred()
|
||||
@ -557,6 +496,7 @@ function promptPlus(message, config, btn, cls){
|
||||
|
||||
// handle unresolved fields...
|
||||
if(!did_handling){
|
||||
console.warn('formDialog: not all fields understood.')
|
||||
// XXX skipping field...
|
||||
// XXX
|
||||
}
|
||||
@ -566,8 +506,6 @@ function promptPlus(message, config, btn, cls){
|
||||
var button = $('<button class="accept">'+btn+'</button>')
|
||||
form.append(button)
|
||||
|
||||
var root = $('.viewer')
|
||||
|
||||
var overlay = showInOverlay(root, form)
|
||||
.addClass('dialog ' + cls)
|
||||
.on('accept', function(){
|
||||
@ -589,10 +527,43 @@ function promptPlus(message, config, btn, cls){
|
||||
overlay.trigger('accept')
|
||||
})
|
||||
|
||||
setTimeout(function(){
|
||||
form.find('.field').first()
|
||||
.focus()
|
||||
.select()
|
||||
}, 100)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
/************************************************ Standard dialogs ***/
|
||||
|
||||
var _alert = alert
|
||||
function alert(){
|
||||
var message = Array.apply(null, arguments).join(' ')
|
||||
return formDialog(null, message, {}, 'OK', 'alert')
|
||||
}
|
||||
|
||||
|
||||
var _prompt = prompt
|
||||
function prompt(message, dfl, btn){
|
||||
btn = btn == null ? 'OK' : btn
|
||||
var res = $.Deferred()
|
||||
formDialog(null, message, {'': ''+(dfl == null ? '' : dfl)}, 'OK', 'alert')
|
||||
.done(function(data){ res.resolve(data['']) })
|
||||
.fail(function(){ res.reject() })
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
function confirm(){
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/************************************************ Specific dialogs ***/
|
||||
|
||||
function showImageInfo(){
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user