mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 19:00:09 +00:00
updated .getRibbon(..), .getImage(..), .updateData(..) and added .setBaseRibbon(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
799f8a0e32
commit
f983a7b611
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
if(window.isNodeWebKit){
|
if(window.nodejs != null){
|
||||||
|
|
||||||
// node-webkit specific modules...
|
// node-webkit specific modules...
|
||||||
var gui = require('nw.gui')
|
var gui = require('nw.gui')
|
||||||
|
|||||||
@ -117,23 +117,45 @@ module.RibbonsPrototype = {
|
|||||||
//
|
//
|
||||||
// Get current ribbon:
|
// Get current ribbon:
|
||||||
// .getRibbon()
|
// .getRibbon()
|
||||||
|
// .getRibbon('current')
|
||||||
// -> ribbon
|
// -> ribbon
|
||||||
//
|
//
|
||||||
// Get ribbon by index/gid:
|
// Get base ribbon:
|
||||||
|
// .getRibbon('base')
|
||||||
|
// -> ribbon
|
||||||
|
//
|
||||||
|
// Get ribbon by its index/gid:
|
||||||
// .getRibbon(index)
|
// .getRibbon(index)
|
||||||
// .getRibbon(gid)
|
// .getRibbon(gid)
|
||||||
// -> ribbon
|
// -> ribbon
|
||||||
//
|
//
|
||||||
|
// Get ribbon by image:
|
||||||
|
// .getRibbon(image)
|
||||||
|
// -> ribbon
|
||||||
|
// NOTE: image must be .getImage(..) compatible.
|
||||||
|
//
|
||||||
// Get ribbons from list:
|
// Get ribbons from list:
|
||||||
// .getRibbon($(..))
|
// .getRibbon($(..))
|
||||||
// .getRibbon([..])
|
// .getRibbon([..])
|
||||||
// -> ribbon(s)
|
// -> ribbon(s)
|
||||||
// NOTE: this will filter the list but not search the tree...
|
// NOTE: this will filter the list but not search the tree...
|
||||||
//
|
//
|
||||||
|
//
|
||||||
|
// NOTE: if current image is unset then this will not be able to
|
||||||
|
// get it.
|
||||||
|
// NOTE: if base ribbon is unset this will return the first ribbon.
|
||||||
getRibbon: function(target){
|
getRibbon: function(target){
|
||||||
// current...
|
// current...
|
||||||
if(target == null) {
|
if(target == null || target == 'current') {
|
||||||
return this.viewer.find('.current.image').parents('.ribbon').first()
|
return this.getImage().parents('.ribbon').first()
|
||||||
|
|
||||||
|
// base...
|
||||||
|
} else if(target == 'base'){
|
||||||
|
var r = this.viewer.find('.base.ribbon').first()
|
||||||
|
if(r.length == 0){
|
||||||
|
return this.viewer.find('.ribbon').first()
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
|
||||||
// index...
|
// index...
|
||||||
} else if(typeof(target) == typeof(123)){
|
} else if(typeof(target) == typeof(123)){
|
||||||
@ -142,7 +164,11 @@ module.RibbonsPrototype = {
|
|||||||
// gid...
|
// gid...
|
||||||
} else if(typeof(target) == typeof('str')){
|
} else if(typeof(target) == typeof('str')){
|
||||||
//return this.viewer.find('.ribbon[gid="'+JSON.stringify(target)+'"]')
|
//return this.viewer.find('.ribbon[gid="'+JSON.stringify(target)+'"]')
|
||||||
return this.viewer.find('.ribbon[gid='+JSON.stringify(target)+']')
|
var r = this.viewer.find('.ribbon[gid='+JSON.stringify(target)+']')
|
||||||
|
// if no ribbon is found, try and get an image and it's ribbon...
|
||||||
|
return r.length == 0
|
||||||
|
? this.getImage(target).parents('.ribbon').first()
|
||||||
|
: r
|
||||||
}
|
}
|
||||||
return $(target).filter('.ribbon')
|
return $(target).filter('.ribbon')
|
||||||
},
|
},
|
||||||
@ -157,29 +183,73 @@ module.RibbonsPrototype = {
|
|||||||
//
|
//
|
||||||
// Get current image:
|
// Get current image:
|
||||||
// .getImage()
|
// .getImage()
|
||||||
|
// .getImage('current')
|
||||||
// -> image
|
// -> image
|
||||||
//
|
//
|
||||||
// Get image by gid:
|
// Get image by gid:
|
||||||
// .getImage(gid)
|
// .getImage(gid)
|
||||||
// -> image
|
// -> image
|
||||||
//
|
//
|
||||||
|
// Get image at offset relative to current image:
|
||||||
|
// .getImage('next')
|
||||||
|
// .getImage('prev')
|
||||||
|
// .getImage(offset)
|
||||||
|
// -> image
|
||||||
|
//
|
||||||
|
// Get image at offset relative to image:
|
||||||
|
// .getImage(image, 'next')
|
||||||
|
// .getImage(image, 'prev')
|
||||||
|
// .getImage(image, offset)
|
||||||
|
// -> image
|
||||||
|
//
|
||||||
// Get images from list:
|
// Get images from list:
|
||||||
// .getImage($(..))
|
// .getImage($(..))
|
||||||
// .getImage([..])
|
// .getImage([..])
|
||||||
// -> image(s)
|
// -> image(s)
|
||||||
// NOTE: this will filter the list but not search the tree...
|
// NOTE: this will filter the list but not search the tree...
|
||||||
//
|
//
|
||||||
getImage: function(target){
|
getImage: function(target, offset){
|
||||||
|
var img = null
|
||||||
|
|
||||||
|
// relative to current -- target is offset...
|
||||||
|
if(target == 'next'
|
||||||
|
|| target == 'prev'
|
||||||
|
|| typeof(target) == typeof(123)){
|
||||||
|
offset = target
|
||||||
|
target = 'current'
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the base image...
|
||||||
// current...
|
// current...
|
||||||
if(target == null) {
|
if(target == null || target == 'current') {
|
||||||
return this.viewer.find('.current.image')
|
img = this.viewer.find('.current.image')
|
||||||
|
|
||||||
// gid...
|
// gid...
|
||||||
} else if(typeof(target) == typeof('str')){
|
} else if(typeof(target) == typeof('str')){
|
||||||
//return this.viewer.find('.image[gid="'+JSON.stringify(target)+'"]')
|
//return this.viewer.find('.image[gid="'+JSON.stringify(target)+'"]')
|
||||||
return this.viewer.find('.image[gid='+JSON.stringify(target)+']')
|
img = this.viewer.find('.image[gid='+JSON.stringify(target)+']')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// we got a collection...
|
||||||
|
if(img == null){
|
||||||
return $(target).filter('.image')
|
return $(target).filter('.image')
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the offset...
|
||||||
|
if(offset != null && offset != 0){
|
||||||
|
// relative keywords...
|
||||||
|
offset = offset == 'next' ? 1
|
||||||
|
: offset == 'prev' ? -1
|
||||||
|
: offset
|
||||||
|
var list = offset > 0 ? 'nextAll' : 'prevAll'
|
||||||
|
offset = Math.abs(offset)-1
|
||||||
|
var res = img[list]('.image')
|
||||||
|
// handle overflow...
|
||||||
|
res = res.eq(Math.min(offset, res.length-1))
|
||||||
|
img = res.length == 0 ? img : res
|
||||||
|
}
|
||||||
|
|
||||||
|
return img
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -372,18 +442,51 @@ module.RibbonsPrototype = {
|
|||||||
|
|
||||||
// Update a data object in ribbons...
|
// Update a data object in ribbons...
|
||||||
//
|
//
|
||||||
|
// .updateData(data, settings)
|
||||||
|
// -> ribbons
|
||||||
|
//
|
||||||
|
//
|
||||||
// This uses .updateRibbon(..) to load individual ribbons, for
|
// This uses .updateRibbon(..) to load individual ribbons, for
|
||||||
// more info see docs for that.
|
// more info see docs for that.
|
||||||
//
|
//
|
||||||
// This uses data.ribbon_order to place the ribbons and data.ribbons
|
// This uses data.ribbon_order to place the ribbons and data.ribbons
|
||||||
// place the images, either is optional, but at least one of the two
|
// to place the images.
|
||||||
// must exist for this to work.
|
//
|
||||||
|
// This uses data.base and data.current to set the base ribbon and
|
||||||
|
// current image respectively.
|
||||||
|
//
|
||||||
|
// All the data fields are optional, but for this to make a change
|
||||||
|
// at least one must be present.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// Settings format:
|
||||||
|
// {
|
||||||
|
// // if true keep the unchanged ribbons (default: false)
|
||||||
|
// // NOTE: untouched ribbons are the ones loaded into DOM but
|
||||||
|
// // not included in any of:
|
||||||
|
// // - data.ribbon_order
|
||||||
|
// // - data.ribbons
|
||||||
|
// // - data.base
|
||||||
|
// keep_ribbons: bool,
|
||||||
|
//
|
||||||
|
// // if true do not update the base ribbon (default: false)
|
||||||
|
// keep_base: bool,
|
||||||
|
//
|
||||||
|
// // if true do not update the current image (default: false)
|
||||||
|
// keep_current: bool,
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // a shorthand setting all the above to true (default: false).
|
||||||
|
// // NOTE: if this is set to true all other settings will be
|
||||||
|
// // ignored...
|
||||||
|
// keep_all: bool,
|
||||||
|
// }
|
||||||
//
|
//
|
||||||
// NOTE: this will not clear the ribbons object explicitly.
|
// NOTE: this will not clear the ribbons object explicitly.
|
||||||
// NOTE: this will clear the ribbons that are not present in
|
// NOTE: this will never remove the ribbons included in any of the
|
||||||
// data.ribbon_order (if given) unless keep_untouched_ribbons
|
// data.base, data.ribbon_order or data.ribbons...
|
||||||
// is set.
|
updateData: function(data, settings){
|
||||||
updateData: function(data, keep_untouched_ribbons){
|
var settings = settings == null ? {} : settings
|
||||||
// load the data...
|
// load the data...
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
@ -401,9 +504,29 @@ module.RibbonsPrototype = {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!settings.keep_all){
|
||||||
|
// set base ribbon...
|
||||||
|
if(!settings.keep_base && data.base != null){
|
||||||
|
this.setBaseRibbon(data.base)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set base ribbon...
|
||||||
|
if(!settings.keep_current && data.current != null){
|
||||||
|
this.focusImage(data.current)
|
||||||
|
}
|
||||||
|
|
||||||
// clear the ribbons that did not get updated...
|
// clear the ribbons that did not get updated...
|
||||||
if(!keep_untouched_ribbons && data.ribbon_order != null){
|
if(!settings.keep_ribbons
|
||||||
var ribbons = data.ribbon_order
|
&& (data.ribbon_order != null || data.ribbons != null)){
|
||||||
|
var ribbons = []
|
||||||
|
ribbons = data.ribbon_order != null
|
||||||
|
? ribbons.concat(Object.keys(data.ribbon_order))
|
||||||
|
: ribbons
|
||||||
|
ribbons = data.ribbons != null
|
||||||
|
? ribbons.concat(Object.keys(data.ribbons))
|
||||||
|
: ribbons
|
||||||
|
ribbons.push(data.base)
|
||||||
|
|
||||||
that.viewer.find('.ribbon').each(function(){
|
that.viewer.find('.ribbon').each(function(){
|
||||||
var r = $(this)
|
var r = $(this)
|
||||||
if(ribbons.indexOf(that.getElemGID(r)) < 0){
|
if(ribbons.indexOf(that.getElemGID(r)) < 0){
|
||||||
@ -411,6 +534,7 @@ module.RibbonsPrototype = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
@ -482,17 +606,7 @@ module.RibbonsPrototype = {
|
|||||||
|
|
||||||
// offset...
|
// offset...
|
||||||
if(typeof(gid) == typeof(123)){
|
if(typeof(gid) == typeof(123)){
|
||||||
if(gid != 0){
|
return this.focusImage(this.getImage(gid))
|
||||||
var list = gid > 0 ? 'nextAll' : 'prevAll'
|
|
||||||
gid = Math.abs(gid)-1
|
|
||||||
var target = cur[list]('.image')
|
|
||||||
// handle overflow...
|
|
||||||
target = target.eq(Math.min(gid, target.length-1))
|
|
||||||
if(target.length > 0){
|
|
||||||
return this.focusImage(target)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cur
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cur.removeClass('current')
|
cur.removeClass('current')
|
||||||
@ -500,6 +614,12 @@ module.RibbonsPrototype = {
|
|||||||
.addClass('current')
|
.addClass('current')
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// XXX should this support keywords a-la .focusImage(..)???
|
||||||
|
setBaseRibbon: function(gid){
|
||||||
|
this.viewer.find('.base.ribbon').removeClass('base')
|
||||||
|
return this.getRibbon(gid).addClass('base')
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// Image manipulation...
|
// Image manipulation...
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user