mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
more refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
90fb7d4f60
commit
e6d4afe1cd
54
ui/data4.js
54
ui/data4.js
@ -131,27 +131,14 @@ var DataClassPrototype = {
|
|||||||
// NOTE: ribbons are sparse...
|
// NOTE: ribbons are sparse...
|
||||||
//
|
//
|
||||||
var DataPrototype = {
|
var DataPrototype = {
|
||||||
// Reset the state to empty...
|
|
||||||
_reset: function(){
|
|
||||||
this.base = null
|
|
||||||
this.current = null
|
|
||||||
this.order = []
|
|
||||||
this.ribbon_order = []
|
|
||||||
this.ribbons = {}
|
|
||||||
|
|
||||||
this._gid_cache = []
|
/******************************************************* Utils ***/
|
||||||
|
|
||||||
return this
|
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Util methods...
|
|
||||||
|
|
||||||
// Compact a sparse list...
|
// Compact a sparse list...
|
||||||
compactSparseList: function(list){
|
compactSparseList: function(list){
|
||||||
return list.filter(function(){return true})
|
return list.filter(function(){return true})
|
||||||
},
|
},
|
||||||
|
|
||||||
// Make a sparse list of image gids...
|
// Make a sparse list of image gids...
|
||||||
//
|
//
|
||||||
// This will use this.order as the base for ordering the list.
|
// This will use this.order as the base for ordering the list.
|
||||||
@ -170,6 +157,7 @@ var DataPrototype = {
|
|||||||
|
|
||||||
return target
|
return target
|
||||||
},
|
},
|
||||||
|
|
||||||
// Generate a uniqie GID...
|
// Generate a uniqie GID...
|
||||||
//
|
//
|
||||||
// XXX generate a real gid...
|
// XXX generate a real gid...
|
||||||
@ -187,7 +175,7 @@ var DataPrototype = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
// Introspection...
|
/*********************************************** Introspection ***/
|
||||||
|
|
||||||
// Get image
|
// Get image
|
||||||
//
|
//
|
||||||
@ -375,6 +363,7 @@ var DataPrototype = {
|
|||||||
getImageOrder: function(target, mode, list){
|
getImageOrder: function(target, mode, list){
|
||||||
return this.order.indexOf(this.getImage(target, mode, list))
|
return this.order.indexOf(this.getImage(target, mode, list))
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get a list of gids...
|
// Get a list of gids...
|
||||||
//
|
//
|
||||||
// .getImages()
|
// .getImages()
|
||||||
@ -560,7 +549,7 @@ var DataPrototype = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Edit methods...
|
/******************************************************** Edit ***/
|
||||||
|
|
||||||
// This is signature compatible with .getImage(..), see it for more
|
// This is signature compatible with .getImage(..), see it for more
|
||||||
// info...
|
// info...
|
||||||
@ -581,6 +570,7 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
// This is signature compatible with .getRibbon(..), see it for more
|
// This is signature compatible with .getRibbon(..), see it for more
|
||||||
// info...
|
// info...
|
||||||
setBase: function(target, offset){
|
setBase: function(target, offset){
|
||||||
@ -606,6 +596,7 @@ var DataPrototype = {
|
|||||||
// XXX should we return this or gid???
|
// XXX should we return this or gid???
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
// Merge ribbons
|
// Merge ribbons
|
||||||
//
|
//
|
||||||
// .mergeRibbons('all')
|
// .mergeRibbons('all')
|
||||||
@ -644,6 +635,7 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
// Reverse .order and all the ribbons...
|
// Reverse .order and all the ribbons...
|
||||||
//
|
//
|
||||||
// NOTE: this sorts in-place
|
// NOTE: this sorts in-place
|
||||||
@ -749,7 +741,7 @@ var DataPrototype = {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Data-level edit methods...
|
/********************************************* Data-level edit ***/
|
||||||
|
|
||||||
// Split data into 2 or more sections...
|
// Split data into 2 or more sections...
|
||||||
//
|
//
|
||||||
@ -783,6 +775,7 @@ var DataPrototype = {
|
|||||||
res.push(tail)
|
res.push(tail)
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
// align can be:
|
// align can be:
|
||||||
// 'gid'
|
// 'gid'
|
||||||
// 'base'
|
// 'base'
|
||||||
@ -815,6 +808,7 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
return crop
|
return crop
|
||||||
},
|
},
|
||||||
|
|
||||||
// Merge changes from crop into data...
|
// Merge changes from crop into data...
|
||||||
//
|
//
|
||||||
// NOTE: this may result in empty ribbons...
|
// NOTE: this may result in empty ribbons...
|
||||||
@ -861,11 +855,24 @@ var DataPrototype = {
|
|||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Reset the state to empty...
|
||||||
|
_reset: function(){
|
||||||
|
this.base = null
|
||||||
|
this.current = null
|
||||||
|
this.order = []
|
||||||
|
this.ribbon_order = []
|
||||||
|
this.ribbons = {}
|
||||||
|
|
||||||
|
this._gid_cache = []
|
||||||
|
|
||||||
|
return this
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
// JSON serialization...
|
|
||||||
|
|
||||||
// NOTE: this loads in-place, use .fromJSON(..) to create new data...
|
/****************************************** JSON serialization ***/
|
||||||
|
|
||||||
|
// Convert gen3 data to gen4 json...
|
||||||
convertDataGen3: function(data){
|
convertDataGen3: function(data){
|
||||||
data = data.version == null ? convertDataGen1(data) : data
|
data = data.version == null ? convertDataGen1(data) : data
|
||||||
var that = this
|
var that = this
|
||||||
@ -885,6 +892,10 @@ var DataPrototype = {
|
|||||||
res.base = res.ribbon_order[0]
|
res.base = res.ribbon_order[0]
|
||||||
return res
|
return res
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Load data from JSON...
|
||||||
|
//
|
||||||
|
// NOTE: this loads in-place, use .fromJSON(..) to create new data...
|
||||||
loadJSON: function(data){
|
loadJSON: function(data){
|
||||||
if(typeof(data) == typeof('str')){
|
if(typeof(data) == typeof('str')){
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
@ -901,6 +912,9 @@ var DataPrototype = {
|
|||||||
}
|
}
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Generate JSON from data...
|
||||||
|
//
|
||||||
// NOTE: if mode is either 'str' or 'string' then this will stringify
|
// NOTE: if mode is either 'str' or 'string' then this will stringify
|
||||||
// the result...
|
// the result...
|
||||||
dumpJSON: function(mode){
|
dumpJSON: function(mode){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user