2013-05-13 02:24:36 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
*
|
2013-05-17 02:30:24 +04:00
|
|
|
* TODO move DATA to a more logical context avoiding the global vars...
|
2013-05-13 02:24:36 +04:00
|
|
|
*
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
|
|
//var DEBUG = DEBUG != null ? DEBUG : true
|
2013-05-13 02:31:09 +04:00
|
|
|
|
2013-05-20 02:49:14 +04:00
|
|
|
var LOAD_SCREENS = 6
|
2013-05-25 14:24:29 +04:00
|
|
|
//var LOAD_THRESHOLD = 2
|
|
|
|
|
|
2013-05-20 02:49:14 +04:00
|
|
|
var DEFAULT_SCREEN_IMAGES = 4
|
2013-05-14 00:01:03 +04:00
|
|
|
var MAX_SCREEN_IMAGES = 12
|
2013-05-13 02:31:09 +04:00
|
|
|
|
2013-05-24 17:08:16 +04:00
|
|
|
// if set to true each image will have basic info written to its html
|
|
|
|
|
// title attr.
|
|
|
|
|
var IMAGE_TITLE_DATA = true
|
|
|
|
|
|
2013-05-26 02:55:41 +04:00
|
|
|
var CACHE_DIR = '.ImageGridCache'
|
|
|
|
|
|
2013-05-17 23:18:55 +04:00
|
|
|
// A stub image, also here for documentation...
|
2013-05-14 21:49:05 +04:00
|
|
|
var STUB_IMAGE_DATA = {
|
|
|
|
|
id: 'SIZE',
|
2013-05-17 23:18:55 +04:00
|
|
|
// entity type, can be 'image', 'group'
|
|
|
|
|
type: 'image',
|
|
|
|
|
// entity state, can be 'single', 'grouped', 'hidden', ...
|
|
|
|
|
state: 'single',
|
2013-05-14 21:49:05 +04:00
|
|
|
ctime: 0,
|
|
|
|
|
path: './images/sizes/900px/SIZE.jpg',
|
|
|
|
|
preview: {
|
|
|
|
|
'150px': './images/sizes/150px/SIZE.jpg',
|
|
|
|
|
'350px': './images/sizes/350px/SIZE.jpg',
|
|
|
|
|
'900px': './images/sizes/900px/SIZE.jpg',
|
|
|
|
|
},
|
|
|
|
|
classes: '',
|
2013-05-23 17:17:31 +04:00
|
|
|
orientation: 0,
|
2013-05-14 21:49:05 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// Data format...
|
|
|
|
|
var DATA = {
|
2013-05-19 22:48:28 +04:00
|
|
|
version: '2.0',
|
2013-05-13 02:24:36 +04:00
|
|
|
current: 0,
|
|
|
|
|
// the ribbon cache...
|
|
|
|
|
// in the simplest form this is a list of lists of GIDs
|
|
|
|
|
ribbons: [
|
|
|
|
|
$(new Array(100)).map(function(i){return i}).toArray()
|
|
|
|
|
],
|
|
|
|
|
// flat ordered list of images in current context...
|
|
|
|
|
// in the simplest form this is a list of GIDs.
|
|
|
|
|
order: $(new Array(100)).map(function(i){return i}).toArray(),
|
2013-05-19 22:48:28 +04:00
|
|
|
|
|
|
|
|
// this can be used to store the filename/path of the file containing
|
|
|
|
|
// image data...
|
|
|
|
|
image_file: null
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-19 22:48:28 +04:00
|
|
|
// the images object, this is indexed by image GID and contains all
|
|
|
|
|
// the needed data...
|
|
|
|
|
var IMAGES = {}
|
2013-05-28 02:17:24 +04:00
|
|
|
var IMAGES_UPDATED = []
|
2013-05-19 22:48:28 +04:00
|
|
|
|
|
|
|
|
var DATA_ATTR = 'DATA'
|
|
|
|
|
|
2013-05-17 04:52:43 +04:00
|
|
|
var MARKED = []
|
2013-05-14 18:10:33 +04:00
|
|
|
|
2013-05-17 01:04:20 +04:00
|
|
|
var IMAGE_CACHE = []
|
|
|
|
|
|
2013-05-17 17:58:23 +04:00
|
|
|
var SETTINGS = {
|
2013-05-24 00:09:13 +04:00
|
|
|
'theme': null,
|
|
|
|
|
'screen-images-ribbon-mode': null,
|
|
|
|
|
'screen-images-single-image-mode': null,
|
|
|
|
|
'single-image-mode-proportions': null,
|
2013-05-17 17:58:23 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-25 14:24:29 +04:00
|
|
|
var BASE_URL = '.'
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* Helpers
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-17 05:07:43 +04:00
|
|
|
// NOTE: this expects gids...
|
2013-05-17 15:34:45 +04:00
|
|
|
function imageDateCmp(a, b, data){
|
2013-05-20 02:49:14 +04:00
|
|
|
data = data == null ? IMAGES : data
|
|
|
|
|
return data[b].ctime - data[a].ctime
|
2013-05-17 05:07:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: this expects gids...
|
2013-05-17 15:34:45 +04:00
|
|
|
function imageNameCmp(a, b, data){
|
2013-05-20 02:49:14 +04:00
|
|
|
data = data == null ? IMAGES : data
|
|
|
|
|
a = data[b].path.split('/')[-1]
|
|
|
|
|
b = data[a].path.split('/')[-1]
|
2013-05-17 05:07:43 +04:00
|
|
|
if(a == b){
|
|
|
|
|
return 0
|
|
|
|
|
} else if(a < b){
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
|
|
|
|
return +1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-18 15:48:22 +04:00
|
|
|
// Check if a is at position i in lst
|
|
|
|
|
//
|
|
|
|
|
// This will return:
|
|
|
|
|
// - 0 if a is equal to position i
|
2013-05-19 17:26:53 +04:00
|
|
|
// - -1 if a is less than position i
|
|
|
|
|
// - +1 if a is greater than position i
|
2013-05-18 15:48:22 +04:00
|
|
|
//
|
|
|
|
|
// NOTE: the signature is different from the traditional cmp(a, b) so as
|
|
|
|
|
// to enable more complex comparisons involving adjacent elements
|
|
|
|
|
// (see isBetween(...) for an example)
|
|
|
|
|
function cmp(a, i, lst){
|
|
|
|
|
var b = lst[i]
|
|
|
|
|
if(a == b){
|
|
|
|
|
return 0
|
|
|
|
|
} else if(a < b){
|
|
|
|
|
return -1
|
|
|
|
|
} else {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check if a is at position i in lst or between positions i and i+1
|
|
|
|
|
//
|
|
|
|
|
// This will return:
|
2013-05-13 02:24:36 +04:00
|
|
|
// - 0 if a is equal at position i in lst or is between i and i+1
|
|
|
|
|
// - -1 if a is "below" position i
|
|
|
|
|
// - +1 if a is "above" position i
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this is here mostly to make debuging easy...
|
|
|
|
|
function isBetween(a, i, lst){
|
|
|
|
|
var b = lst[i]
|
2013-05-19 17:26:53 +04:00
|
|
|
|
|
|
|
|
// special case: tail...
|
|
|
|
|
if(i == lst.length-1 && a >= b){
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
var c = lst[i+1]
|
2013-05-19 17:26:53 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// hit...
|
|
|
|
|
if(a == b || (a > b && a < c)){
|
|
|
|
|
return 0
|
|
|
|
|
// before...
|
|
|
|
|
} else if(a < b){
|
|
|
|
|
return -1
|
|
|
|
|
// later...
|
|
|
|
|
} else {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Basic liner search...
|
2013-05-19 17:43:28 +04:00
|
|
|
//
|
|
|
|
|
// NOTE: this is here for testing reasons only...
|
2013-05-19 17:26:53 +04:00
|
|
|
function linSearch(target, lst, check, return_position){
|
|
|
|
|
check = check == null ? cmp : check
|
2013-05-13 02:24:36 +04:00
|
|
|
|
|
|
|
|
for(var i=0; i < lst.length; i++){
|
|
|
|
|
if(check(target, i, lst) == 0){
|
|
|
|
|
return return_position ? i : lst[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// no hit...
|
|
|
|
|
return return_position ? -1 : null
|
|
|
|
|
}
|
2013-05-19 17:26:53 +04:00
|
|
|
Array.prototype.linSearch = function(target, cmp){
|
|
|
|
|
return linSearch(target, this, cmp, true)
|
|
|
|
|
}
|
2013-05-13 02:24:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// Basic binary search implementation...
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will return the object by default, to return position set
|
|
|
|
|
// return_position to true.
|
2013-05-19 17:26:53 +04:00
|
|
|
// NOTE: by default this will use cmp as a predicate.
|
|
|
|
|
function binSearch(target, lst, check, return_position){
|
|
|
|
|
check = check == null ? cmp : check
|
|
|
|
|
var h = 0
|
|
|
|
|
var t = lst.length - 1
|
|
|
|
|
var m, res
|
|
|
|
|
|
|
|
|
|
while(h <= t){
|
|
|
|
|
m = Math.floor((h + t)/2)
|
|
|
|
|
res = check(target, m, lst)
|
|
|
|
|
|
|
|
|
|
// match...
|
|
|
|
|
if(res == 0){
|
|
|
|
|
return return_position ? m : lst[m]
|
|
|
|
|
|
|
|
|
|
// below...
|
2013-05-13 02:24:36 +04:00
|
|
|
} else if(res < 0){
|
2013-05-19 17:26:53 +04:00
|
|
|
t = m - 1
|
|
|
|
|
|
|
|
|
|
// above...
|
2013-05-13 02:24:36 +04:00
|
|
|
} else {
|
2013-05-19 17:26:53 +04:00
|
|
|
h = m + 1
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
}
|
2013-05-19 17:26:53 +04:00
|
|
|
|
|
|
|
|
// no result...
|
2013-05-13 02:24:36 +04:00
|
|
|
return return_position ? -1 : null
|
|
|
|
|
}
|
2013-05-19 17:26:53 +04:00
|
|
|
Array.prototype.binSearch = function(target, cmp){
|
|
|
|
|
return binSearch(target, this, cmp, true)
|
|
|
|
|
}
|
2013-05-13 02:24:36 +04:00
|
|
|
|
|
|
|
|
|
2013-05-28 21:59:38 +04:00
|
|
|
// Normalize the path...
|
|
|
|
|
//
|
|
|
|
|
// This will:
|
|
|
|
|
// - convert windows absolute paths 'X:\...' -> 'file:///X:/...'
|
|
|
|
|
// - if mode is 'absolute':
|
|
|
|
|
// - return absolute paths as-is
|
|
|
|
|
// - base relative paths on base/BASE_URL, returning an absolute
|
|
|
|
|
// path
|
|
|
|
|
// - if mode is relative:
|
|
|
|
|
// - if absolute path is based on base/BASE_URL make a relative
|
|
|
|
|
// to base path out of it buy cutting the base out.
|
|
|
|
|
// - return absolute paths as-is
|
|
|
|
|
// - return relative paths as-is
|
|
|
|
|
//
|
|
|
|
|
// NOTE: mode can be either 'absolute' (default) or 'relative'...
|
|
|
|
|
function normalizePath(url, base, mode){
|
|
|
|
|
mode = mode == null ? 'absolute' : mode
|
|
|
|
|
base = base == null ? BASE_URL : base
|
|
|
|
|
|
|
|
|
|
// windows path...
|
|
|
|
|
// - replace all '\\' with '/'...
|
|
|
|
|
url = url.replace(/\\/g, '/')
|
|
|
|
|
// - replace 'X:/...' with 'file:///X:/...'
|
|
|
|
|
if(/^[A-Z]:\//.test(url)){
|
|
|
|
|
url = 'file:///' + url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// we got absolute path...
|
|
|
|
|
if(/^(file|http|https):\/\/.*$/.test(url)){
|
|
|
|
|
// check if we start with base, and remove it if so...
|
|
|
|
|
if(mode == 'relative' && url.substring(0, base.length) == base){
|
|
|
|
|
url = url.substring(base.length - 1)
|
|
|
|
|
return url[0] == '/' ? url.substring(1) : url
|
|
|
|
|
|
|
|
|
|
// if it's a different path, return as-is
|
|
|
|
|
} else if(mode == 'absolute'){
|
|
|
|
|
return url
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// make an absolute path...
|
|
|
|
|
} else if(mode == 'absolute') {
|
|
|
|
|
// if base ends and url starts with '.' avoid making it a '..'
|
|
|
|
|
if(base[base.length-1] == '.' && url[0] == '.'){
|
|
|
|
|
return base + url.substring(1)
|
|
|
|
|
// avoid creating '//'...
|
|
|
|
|
} else if(base[base.length-1] != '/' && url[0] != '/'){
|
|
|
|
|
return base + '/' + url
|
|
|
|
|
} else {
|
|
|
|
|
return base + url
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// Same as getImageBefore, but uses gids and searches in DATA...
|
2013-05-19 17:26:53 +04:00
|
|
|
//
|
|
|
|
|
// NOTE: this uses it's own predicate...
|
2013-05-13 02:24:36 +04:00
|
|
|
function getGIDBefore(gid, ribbon, search){
|
2013-05-28 21:59:38 +04:00
|
|
|
gid = gid == null ? getImageGID() : gid
|
|
|
|
|
ribbon = ribbon == null ? getRibbonIndex() : ribbon
|
2013-05-19 17:26:53 +04:00
|
|
|
search = search == null ? binSearch : search
|
2013-05-19 17:43:28 +04:00
|
|
|
//search = search == null ? match2(linSearch, binSearch) : search
|
2013-05-13 02:24:36 +04:00
|
|
|
ribbon = DATA.ribbons[ribbon]
|
|
|
|
|
var order = DATA.order
|
|
|
|
|
|
|
|
|
|
var target = order.indexOf(gid)
|
|
|
|
|
|
2013-05-19 17:26:53 +04:00
|
|
|
return search(target, ribbon, function(a, i, lst){
|
2013-05-13 02:24:36 +04:00
|
|
|
var b = order.indexOf(lst[i])
|
2013-05-19 17:26:53 +04:00
|
|
|
|
|
|
|
|
// special case: tail...
|
|
|
|
|
if(i == lst.length-1 && a >= b){
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
var c = order.indexOf(lst[i+1])
|
2013-05-19 17:26:53 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// hit...
|
|
|
|
|
if(a == b || (a > b && a < c)){
|
|
|
|
|
return 0
|
2013-05-19 17:26:53 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// before...
|
|
|
|
|
} else if(a < b){
|
|
|
|
|
return -1
|
2013-05-19 17:26:53 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
// later...
|
|
|
|
|
} else {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
// Get a "count" of GIDs starting with a given gid ("from")
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will not include the 'from' GID in the resulting list,
|
|
|
|
|
// unless inclusive is set to true.
|
2013-05-13 02:24:36 +04:00
|
|
|
// NOTE: count can be either negative or positive, this will indicate
|
|
|
|
|
// load direction...
|
2013-05-28 02:17:24 +04:00
|
|
|
// NOTE: this can calculate the ribbon number where the image is located.
|
2013-05-13 02:24:36 +04:00
|
|
|
// NOTE: if an image can be in more than one ribbon, one MUST suply the
|
|
|
|
|
// correct ribbon number...
|
2013-05-28 02:17:24 +04:00
|
|
|
//
|
2013-05-13 02:24:36 +04:00
|
|
|
// XXX do we need more checking???
|
|
|
|
|
function getImageGIDs(from, count, ribbon, inclusive){
|
|
|
|
|
if(count == 0){
|
|
|
|
|
return []
|
|
|
|
|
}
|
|
|
|
|
// ribbon default value...
|
|
|
|
|
if(ribbon == null){
|
|
|
|
|
$(DATA.ribbons).each(function(i, e){
|
|
|
|
|
if(e.indexOf(from) >= 0){
|
|
|
|
|
ribbon = i
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
// XXX check if this is empty...
|
|
|
|
|
ribbon = DATA.ribbons[ribbon]
|
|
|
|
|
|
|
|
|
|
if(count > 0){
|
|
|
|
|
var c = inclusive == null ? 1 : 0
|
|
|
|
|
var start = ribbon.indexOf(from) + c
|
|
|
|
|
return ribbon.slice(start, start + count)
|
|
|
|
|
} else {
|
|
|
|
|
var c = inclusive == null ? 0 : 1
|
|
|
|
|
var end = ribbon.indexOf(from)
|
|
|
|
|
return ribbon.slice((Math.abs(count) >= end ? 0 : end + count + c), end + c)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-17 01:04:20 +04:00
|
|
|
// Select best preview by size...
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will use the original if everything else is smaller...
|
|
|
|
|
function getBestPreview(gid, size){
|
2013-05-28 21:59:38 +04:00
|
|
|
gid = gid == null ? getImageGID(): gid
|
2013-05-17 16:21:03 +04:00
|
|
|
size = size == null ? getVisibleImageSize('max') : size
|
2013-05-17 01:04:20 +04:00
|
|
|
var s
|
2013-05-19 22:48:28 +04:00
|
|
|
var img_data = IMAGES[gid]
|
2013-05-17 01:04:20 +04:00
|
|
|
var url = img_data.path
|
|
|
|
|
var preview_size = 'Original'
|
|
|
|
|
var p = Infinity
|
|
|
|
|
|
|
|
|
|
for(var k in img_data.preview){
|
|
|
|
|
s = parseInt(k)
|
|
|
|
|
if(s < p && s > size){
|
|
|
|
|
preview_size = k
|
|
|
|
|
p = s
|
|
|
|
|
url = img_data.preview[k]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {
|
2013-05-25 14:24:29 +04:00
|
|
|
url: normalizePath(url),
|
2013-05-17 01:04:20 +04:00
|
|
|
size: preview_size
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-13 02:31:09 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* Constructors
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-28 21:59:38 +04:00
|
|
|
function imagesFromUrls(lst){
|
2013-05-28 19:25:13 +04:00
|
|
|
var res = {}
|
|
|
|
|
|
|
|
|
|
$.each(lst, function(i, e){
|
|
|
|
|
var gid = 'image-' + i
|
|
|
|
|
res[gid] = {
|
|
|
|
|
id: gid,
|
|
|
|
|
type: 'image',
|
|
|
|
|
state: 'single',
|
|
|
|
|
path: e,
|
|
|
|
|
ctime: Date.now(),
|
|
|
|
|
preview: {},
|
|
|
|
|
classes: '',
|
|
|
|
|
orientation: 0,
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function dataFromImages(images){
|
|
|
|
|
var gids = Object.keys(images).sort()
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
version: '2.0',
|
|
|
|
|
current: gids[0],
|
|
|
|
|
ribbons: [
|
|
|
|
|
gids
|
|
|
|
|
],
|
|
|
|
|
order: gids.slice(),
|
|
|
|
|
image_file: null
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* Format conversion
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// Convert legacy Gen1 data format to current Gen3 (v2.0)
|
|
|
|
|
function convertDataGen1(data, cmp){
|
|
|
|
|
var res = {
|
|
|
|
|
data: {
|
|
|
|
|
version: '2.0',
|
|
|
|
|
current: null,
|
|
|
|
|
ribbons: [],
|
|
|
|
|
order: [],
|
|
|
|
|
},
|
|
|
|
|
images: {}
|
|
|
|
|
}
|
|
|
|
|
cmp = cmp == null ?
|
|
|
|
|
function(a, b){
|
|
|
|
|
return imageDateCmp(a, b, res.images)
|
|
|
|
|
}
|
|
|
|
|
: cmp
|
|
|
|
|
var ribbons = res.data.ribbons
|
|
|
|
|
var order = res.data.order
|
|
|
|
|
var images = res.images
|
|
|
|
|
|
|
|
|
|
// position...
|
|
|
|
|
res.data.current = data.position
|
|
|
|
|
|
|
|
|
|
// ribbons and images...
|
|
|
|
|
$.each(data.ribbons, function(i, input_images){
|
|
|
|
|
var ribbon = []
|
|
|
|
|
ribbons.push(ribbon)
|
|
|
|
|
for(var id in input_images){
|
|
|
|
|
var image = input_images[id]
|
|
|
|
|
ribbon.push(id)
|
|
|
|
|
order.push(id)
|
|
|
|
|
images[id] = image
|
|
|
|
|
}
|
|
|
|
|
ribbon.sort(cmp)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
order.sort(cmp)
|
|
|
|
|
|
|
|
|
|
// XXX STUB
|
|
|
|
|
res.data.current = order[0]
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-13 02:31:09 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* Loaders
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
function updateImage(image, gid, size){
|
|
|
|
|
image = $(image)
|
2013-05-24 17:08:16 +04:00
|
|
|
var title = ''
|
2013-05-13 02:24:36 +04:00
|
|
|
if(gid == null){
|
2013-05-14 21:49:05 +04:00
|
|
|
gid = getImageGID(image)
|
2013-05-13 02:24:36 +04:00
|
|
|
} else {
|
|
|
|
|
image.attr('gid', JSON.stringify(gid))
|
|
|
|
|
}
|
2013-05-17 16:21:03 +04:00
|
|
|
size = size == null ? getVisibleImageSize('max') : size
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-19 22:48:28 +04:00
|
|
|
var img_data = IMAGES[gid]
|
2013-05-14 21:49:05 +04:00
|
|
|
if(img_data == null){
|
|
|
|
|
img_data = STUB_IMAGE_DATA
|
|
|
|
|
}
|
2013-05-24 17:08:16 +04:00
|
|
|
var name = img_data.path.split('/').pop()
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-17 01:04:20 +04:00
|
|
|
// get the url...
|
|
|
|
|
var preview = getBestPreview(gid, size)
|
2013-05-23 17:17:31 +04:00
|
|
|
image
|
|
|
|
|
.css({
|
2013-05-26 02:55:41 +04:00
|
|
|
'background-image': 'url("'+ preview.url +'")',
|
2013-05-23 17:17:31 +04:00
|
|
|
})
|
|
|
|
|
.attr({
|
2013-05-24 17:08:16 +04:00
|
|
|
order: DATA.order.indexOf(gid),
|
2013-05-23 17:17:31 +04:00
|
|
|
orientation: img_data.orientation == null ? 0 : img_data.orientation,
|
2013-05-24 17:08:16 +04:00
|
|
|
title: IMAGE_TITLE_DATA ?
|
|
|
|
|
'Image: ' + name +'\n'+
|
|
|
|
|
'Order: ' + DATA.order.indexOf(gid) +'\n'+
|
|
|
|
|
'GID: '+ gid +'\n'+
|
|
|
|
|
'Preview size:'+ preview.size : '',
|
2013-05-23 17:17:31 +04:00
|
|
|
})
|
2013-05-14 21:49:05 +04:00
|
|
|
|
2013-05-24 17:08:16 +04:00
|
|
|
// setup marks...
|
|
|
|
|
if(MARKED.indexOf(gid) != -1){
|
|
|
|
|
image.addClass('marked')
|
|
|
|
|
} else {
|
|
|
|
|
image.removeClass('marked')
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 21:49:05 +04:00
|
|
|
|
|
|
|
|
return image
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-13 02:31:09 +04:00
|
|
|
|
2013-05-28 21:59:38 +04:00
|
|
|
// Same as updateImage(...) but will update all images.
|
2013-05-13 02:24:36 +04:00
|
|
|
function updateImages(size){
|
2013-05-17 16:21:03 +04:00
|
|
|
size = size == null ? getVisibleImageSize('max') : size
|
2013-05-13 02:24:36 +04:00
|
|
|
return $('.image').each(function(){
|
|
|
|
|
updateImage($(this), null, size)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load count images around a given image/gid into the given ribbon.
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will reload the current image elements...
|
|
|
|
|
// NOTE: this is similar to extendRibbon(...) but different in interface...
|
2013-05-16 20:50:31 +04:00
|
|
|
// NOTE: load only what is needed instead of reloading everything...
|
|
|
|
|
// NOTE: this will not change alignment if the current image is within
|
|
|
|
|
// the target range...
|
2013-05-13 02:24:36 +04:00
|
|
|
function loadImages(ref_gid, count, ribbon){
|
|
|
|
|
ribbon = $(ribbon)
|
|
|
|
|
var images = ribbon.find('.image')
|
|
|
|
|
var ribbon_i = getRibbonIndex(ribbon)
|
|
|
|
|
var gid = getGIDBefore(ref_gid, ribbon_i)
|
|
|
|
|
gid = gid == null ? DATA.ribbons[ribbon_i][0] : gid
|
|
|
|
|
|
|
|
|
|
// start/end points...
|
|
|
|
|
var l = DATA.ribbons[ribbon_i].length
|
|
|
|
|
if(l <= count){
|
|
|
|
|
var from_i = 0
|
2013-05-16 21:46:56 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
} else {
|
|
|
|
|
var from_i = DATA.ribbons[ribbon_i].indexOf(gid) - Math.floor(count/2)
|
2013-05-16 21:46:56 +04:00
|
|
|
// special case: head...
|
|
|
|
|
from_i = from_i < 0 ? 0 : from_i
|
|
|
|
|
// special case: tail...
|
|
|
|
|
from_i = l - from_i < count ? l - count : from_i
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
var from_gid = DATA.ribbons[ribbon_i][from_i]
|
|
|
|
|
|
2013-05-16 18:13:02 +04:00
|
|
|
var old_gids = getImageGIDs(getImageGID(images.first()), images.length, ribbon_i, true)
|
2013-05-13 02:24:36 +04:00
|
|
|
var gids = getImageGIDs(from_gid, count, ribbon_i, true)
|
|
|
|
|
|
2013-05-16 22:53:10 +04:00
|
|
|
// check if heads have a common gid and get the diff length...
|
|
|
|
|
var i = gids.indexOf(old_gids[0])
|
|
|
|
|
var j = old_gids.indexOf(gids[0])
|
|
|
|
|
var head = i != -1 ? i
|
|
|
|
|
// check if we need to truncate...
|
|
|
|
|
: j != -1 ? -j
|
|
|
|
|
: 0
|
|
|
|
|
// check if tails have a common gid and get the diff length...
|
|
|
|
|
i = gids.indexOf(old_gids[old_gids.length-1])
|
|
|
|
|
j = old_gids.indexOf(gids[gids.length-1])
|
|
|
|
|
var tail = i > 0 ? gids.length - i - 1
|
|
|
|
|
// check if we need to truncate...
|
|
|
|
|
: j > 0 ? -(old_gids.length - j - 1)
|
|
|
|
|
: 0
|
2013-05-16 20:48:26 +04:00
|
|
|
|
2013-05-17 16:21:03 +04:00
|
|
|
var size = getVisibleImageSize('max')
|
2013-05-16 20:50:31 +04:00
|
|
|
|
2013-05-17 02:30:24 +04:00
|
|
|
// XXX the next section might need some simplification -- feels bulky...
|
2013-05-16 20:48:26 +04:00
|
|
|
// check if we have a common section at all / full reload...
|
|
|
|
|
if(head == 0 && tail == 0){
|
|
|
|
|
if(gids.indexOf(old_gids[0]) == -1){
|
2013-05-16 22:34:26 +04:00
|
|
|
window.DEBUG && console.log('>>> (ribbon:', ribbon_i, ') FULL RELOAD --', gids.length)
|
2013-05-16 20:48:26 +04:00
|
|
|
extendRibbon(0, gids.length - old_gids.length, ribbon)
|
2013-05-17 01:04:20 +04:00
|
|
|
var images = ribbon
|
2013-05-16 20:48:26 +04:00
|
|
|
.find('.image')
|
|
|
|
|
.each(function(i, e){
|
|
|
|
|
updateImage(e, gids[i], size)
|
|
|
|
|
})
|
2013-05-17 01:04:20 +04:00
|
|
|
$('.viewer').trigger('reloadedRibbon', [ribbon])
|
|
|
|
|
|
2013-05-16 20:48:26 +04:00
|
|
|
// do nothing...
|
|
|
|
|
// ...the requested section is the same as the one already loaded...
|
|
|
|
|
} else {
|
2013-05-16 22:34:26 +04:00
|
|
|
window.DEBUG && console.log('>>> (ribbon:', ribbon_i, ') NOTHING TO DO.')
|
2013-05-24 19:28:05 +04:00
|
|
|
return images
|
2013-05-16 20:48:26 +04:00
|
|
|
}
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-16 20:48:26 +04:00
|
|
|
// do a partial reload...
|
|
|
|
|
} else {
|
2013-05-16 22:34:26 +04:00
|
|
|
window.DEBUG && console.log('>>> (ribbon:', ribbon_i, ')', head, '+-('+ (old_gids.length) +')-+', tail)
|
2013-05-16 20:48:26 +04:00
|
|
|
// NOTE: we do not need to do anything about alignment as
|
|
|
|
|
// extendRibbon will get the correct head and tail so as to
|
|
|
|
|
// align everything by itself...
|
|
|
|
|
var res = extendRibbon(head, tail, ribbon)
|
|
|
|
|
|
|
|
|
|
// NOTE: if there was no extension (i.e. head/tail <= 0) then
|
|
|
|
|
// these will do nothing...
|
|
|
|
|
res.left.each(function(i, e){
|
|
|
|
|
updateImage(e, gids[i], size)
|
|
|
|
|
})
|
|
|
|
|
res.right.each(function(i, e){
|
|
|
|
|
updateImage(e, gids[i + gids.length - tail], size)
|
|
|
|
|
})
|
2013-05-17 01:04:20 +04:00
|
|
|
$('.viewer').trigger('updatedRibbon', [ribbon])
|
2013-05-24 17:08:16 +04:00
|
|
|
images = ribbon.find('.image')
|
2013-05-16 20:48:26 +04:00
|
|
|
}
|
2013-05-24 17:08:16 +04:00
|
|
|
|
|
|
|
|
// XXX is this the right place for this?
|
2013-05-24 19:28:05 +04:00
|
|
|
// XXX this might be too global, do only the images loaded...
|
2013-05-24 17:08:16 +04:00
|
|
|
correctImageProportionsForRotation(images)
|
|
|
|
|
return images
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-13 02:31:09 +04:00
|
|
|
|
2013-05-16 20:50:31 +04:00
|
|
|
// NOTE: this is here for testing...
|
2013-05-13 02:24:36 +04:00
|
|
|
function loadImagesAround(ref_gid, count, ribbon){
|
|
|
|
|
var ribbon_i = getRibbonIndex(ribbon)
|
|
|
|
|
var gid = getGIDBefore(ref_gid, ribbon_i)
|
2013-05-14 21:49:05 +04:00
|
|
|
return loadImages(ref_gid, count, ribbon).filter('[gid="'+JSON.stringify(gid)+'"]').click()
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
// Roll ribbon and load new images in the updated section.
|
|
|
|
|
//
|
2013-05-13 02:24:36 +04:00
|
|
|
// NOTE: this is signature-compatible with rollRibbon...
|
|
|
|
|
// NOTE: this will load data ONLY if it is available, otherwise this
|
|
|
|
|
// will have no effect...
|
|
|
|
|
// NOTE: this can roll past the currently loaded images (n > images.length)
|
2013-05-14 00:01:03 +04:00
|
|
|
function rollImages(n, ribbon, extend, no_compensate_shift){
|
2013-05-13 02:24:36 +04:00
|
|
|
if(n == 0){
|
|
|
|
|
return $([])
|
|
|
|
|
}
|
|
|
|
|
ribbon = ribbon == null ? getRibbon() : $(ribbon)
|
|
|
|
|
var images = ribbon.find('.image')
|
|
|
|
|
|
2013-05-14 21:49:05 +04:00
|
|
|
var from = n > 0 ? getImageGID(ribbon.find('.image').last())
|
|
|
|
|
: getImageGID(ribbon.find('.image').first())
|
2013-05-13 02:24:36 +04:00
|
|
|
var gids = getImageGIDs(from, n)
|
|
|
|
|
if(gids.length == 0){
|
|
|
|
|
return $([])
|
|
|
|
|
}
|
|
|
|
|
// truncate the results to the length of images...
|
|
|
|
|
if(n > images.length){
|
|
|
|
|
gids.reverse().splice(images.length)
|
|
|
|
|
gids.reverse()
|
|
|
|
|
} else if(Math.abs(n) > images.length){
|
|
|
|
|
gids.splice(images.length)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(n < images.length){
|
2013-05-14 00:01:03 +04:00
|
|
|
images = rollRibbon(gids.length * (n > 0 ? 1 : -1), ribbon, extend, no_compensate_shift)
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-17 16:21:03 +04:00
|
|
|
var size = getVisibleImageSize('max')
|
2013-05-13 02:24:36 +04:00
|
|
|
images.each(function(i, e){
|
|
|
|
|
updateImage($(e), gids[i], size)
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-17 01:04:20 +04:00
|
|
|
$('.viewer').trigger('updatedRibbon', [ribbon])
|
|
|
|
|
|
2013-05-24 17:08:16 +04:00
|
|
|
// XXX is this the right place for this?
|
|
|
|
|
correctImageProportionsForRotation(images)
|
2013-05-13 02:24:36 +04:00
|
|
|
return images
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-19 22:48:28 +04:00
|
|
|
function loadData(images_per_screen){
|
2013-05-13 02:31:09 +04:00
|
|
|
var ribbons_set = $('.ribbon-set')
|
2013-05-19 22:48:28 +04:00
|
|
|
var current = DATA.current
|
2013-05-13 02:31:09 +04:00
|
|
|
// if no width is given, use the current or default...
|
|
|
|
|
var w = images_per_screen == null ? getScreenWidthInImages() : images_per_screen
|
|
|
|
|
w = w > MAX_SCREEN_IMAGES ? DEFAULT_SCREEN_IMAGES : w
|
|
|
|
|
|
|
|
|
|
// clear data...
|
|
|
|
|
$('.ribbon').remove()
|
|
|
|
|
|
|
|
|
|
// create ribbons...
|
2013-05-19 22:48:28 +04:00
|
|
|
$.each(DATA.ribbons, function(i, e){
|
2013-05-13 02:31:09 +04:00
|
|
|
createRibbon().appendTo(ribbons_set)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// create images...
|
|
|
|
|
$('.ribbon').each(function(i, e){
|
2013-05-19 22:48:28 +04:00
|
|
|
loadImages(current, Math.min(w * LOAD_SCREENS, DATA.ribbons[i].length), $(this))
|
2013-05-13 02:31:09 +04:00
|
|
|
})
|
|
|
|
|
|
2013-05-14 21:49:05 +04:00
|
|
|
focusImage($('.image').filter('[gid="'+JSON.stringify(current)+'"]'))
|
2013-05-13 02:31:09 +04:00
|
|
|
|
|
|
|
|
fitNImages(w)
|
|
|
|
|
centerRibbons('css')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-24 00:32:42 +04:00
|
|
|
function loadSettings(){
|
|
|
|
|
toggleTheme(SETTINGS['theme'])
|
|
|
|
|
|
|
|
|
|
if(toggleSingleImageMode('?') == 'on'){
|
|
|
|
|
var w = SETTINGS['screen-images-single-image-mode']
|
|
|
|
|
var p = SETTINGS['single-image-mode-proportions']
|
|
|
|
|
toggleImageProportions(p)
|
|
|
|
|
} else {
|
|
|
|
|
var w = SETTINGS['screen-images-ribbon-mode']
|
|
|
|
|
}
|
|
|
|
|
fitNImages(w)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* Image caching...
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// NOTE: this will always overwrite the previous cache set for a ribbon...
|
|
|
|
|
function preCacheRibbonImages(ribbon){
|
|
|
|
|
var i = getRibbonIndex(ribbon)
|
|
|
|
|
var size = getVisibleImageSize('max')
|
|
|
|
|
var screen_size = getScreenWidthInImages(getVisibleImageSize())
|
|
|
|
|
var cache_frame_size = (screen_size * LOAD_SCREENS) / 2
|
|
|
|
|
var images = ribbon.find('.image')
|
|
|
|
|
var first = getImageGID(images.first())
|
|
|
|
|
var last = getImageGID(images.last())
|
|
|
|
|
|
|
|
|
|
var gids = getImageGIDs(first, -cache_frame_size)
|
|
|
|
|
.concat(getImageGIDs(last, cache_frame_size))
|
|
|
|
|
|
|
|
|
|
var cache = []
|
|
|
|
|
IMAGE_CACHE[i] = cache
|
|
|
|
|
$.each(gids, function(i, e){
|
|
|
|
|
var img = new Image()
|
|
|
|
|
img.src = getBestPreview(e, size).url
|
|
|
|
|
cache.push(img)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return cache
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function preCacheAllRibbons(){
|
|
|
|
|
$('.ribbon').each(function(){
|
|
|
|
|
preCacheRibbonImages($(this))
|
|
|
|
|
})
|
|
|
|
|
return IMAGE_CACHE
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-16 21:46:56 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* localStorage
|
|
|
|
|
*
|
|
|
|
|
* XXX should we use jStorage here?
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-19 22:48:28 +04:00
|
|
|
function loadLocalStorageData(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
var data = localStorage[attr]
|
|
|
|
|
if(data == null){
|
|
|
|
|
data = '{}'
|
|
|
|
|
}
|
2013-05-28 04:41:16 +04:00
|
|
|
var base = localStorage[attr + '_BASE_URL']
|
|
|
|
|
base = base == null ? '.' : base
|
2013-05-26 03:34:15 +04:00
|
|
|
return {
|
|
|
|
|
data: JSON.parse(data),
|
2013-05-28 04:41:16 +04:00
|
|
|
base_url: base,
|
2013-05-26 03:34:15 +04:00
|
|
|
}
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
|
|
|
|
function saveLocalStorageData(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
localStorage[attr] = JSON.stringify(DATA)
|
2013-05-26 03:34:15 +04:00
|
|
|
localStorage[attr + '_BASE_URL'] = BASE_URL
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function loadLocalStorageImages(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_IMAGES'
|
|
|
|
|
var images = localStorage[attr]
|
|
|
|
|
if(images == null){
|
|
|
|
|
images = '{}'
|
|
|
|
|
}
|
|
|
|
|
return JSON.parse(images)
|
|
|
|
|
}
|
|
|
|
|
function saveLocalStorageImages(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_IMAGES'
|
|
|
|
|
localStorage[attr] = JSON.stringify(IMAGES)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-17 04:52:43 +04:00
|
|
|
function loadLocalStorageMarks(attr){
|
2013-05-19 22:48:28 +04:00
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_MARKED'
|
|
|
|
|
var marked = localStorage[attr]
|
|
|
|
|
if(marked == null){
|
|
|
|
|
marked = '[]'
|
|
|
|
|
}
|
|
|
|
|
MARKED = JSON.parse(marked)
|
|
|
|
|
return loadData()
|
2013-05-17 04:52:43 +04:00
|
|
|
}
|
|
|
|
|
function saveLocalStorageMarks(attr){
|
2013-05-19 22:48:28 +04:00
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_MARKED'
|
2013-05-17 04:52:43 +04:00
|
|
|
localStorage[attr] = JSON.stringify(MARKED)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-24 00:32:42 +04:00
|
|
|
function loadLocalStorageSettings(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_SETTINGS'
|
|
|
|
|
SETTINGS = JSON.parse(localStorage[attr])
|
|
|
|
|
|
|
|
|
|
loadSettings()
|
|
|
|
|
}
|
|
|
|
|
function saveLocalStorageSettings(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
attr += '_SETTINGS'
|
|
|
|
|
localStorage[attr] = JSON.stringify(SETTINGS)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
// generic save/load...
|
|
|
|
|
function loadLocalStorage(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
var d = loadLocalStorageData(attr)
|
|
|
|
|
BASE_URL = d.base_url
|
|
|
|
|
DATA = d.data
|
|
|
|
|
IMAGES = loadLocalStorageImages(attr)
|
|
|
|
|
return loadData()
|
|
|
|
|
}
|
|
|
|
|
function saveLocalStorage(attr){
|
|
|
|
|
attr = attr == null ? DATA_ATTR : attr
|
|
|
|
|
saveLocalStorageData(attr)
|
|
|
|
|
saveLocalStorageImages(attr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-16 21:46:56 +04:00
|
|
|
|
2013-05-19 22:48:28 +04:00
|
|
|
/**********************************************************************
|
2013-05-28 02:17:24 +04:00
|
|
|
* File storage (Extension API -- CEF/PhoneGap/...)
|
|
|
|
|
*
|
|
|
|
|
* XXX need to cleanup this section...
|
2013-05-19 22:48:28 +04:00
|
|
|
*/
|
|
|
|
|
|
2013-05-28 21:59:38 +04:00
|
|
|
// load the target-specific handlers...
|
2013-05-28 02:17:24 +04:00
|
|
|
// CEF
|
|
|
|
|
if(window.CEF_dumpJSON != null){
|
|
|
|
|
var dumpJSON = CEF_dumpJSON
|
|
|
|
|
var listDir = CEF_listDir
|
|
|
|
|
var removeFile = CEF_removeFile
|
|
|
|
|
var runSystem = CEF_runSystem
|
|
|
|
|
|
|
|
|
|
// PhoneGap
|
|
|
|
|
} else if(false) {
|
|
|
|
|
// XXX
|
|
|
|
|
var dumpJSON = null
|
|
|
|
|
var listDir = null
|
|
|
|
|
var removeFile = null
|
|
|
|
|
var runSystem = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 04:41:16 +04:00
|
|
|
// Load images from file
|
|
|
|
|
//
|
|
|
|
|
// This will also merge all diff files.
|
2013-05-28 02:17:24 +04:00
|
|
|
function loadFileImages(path, no_load_diffs, callback){
|
2013-05-28 15:22:05 +04:00
|
|
|
no_load_diffs = window.listDir == null ? true : no_load_diffs
|
2013-05-28 02:17:24 +04:00
|
|
|
|
2013-05-28 15:22:05 +04:00
|
|
|
// default locations...
|
2013-05-28 02:17:24 +04:00
|
|
|
if(path == null){
|
|
|
|
|
var base = normalizePath(CACHE_DIR)
|
2013-05-28 15:22:05 +04:00
|
|
|
// find the latest images file...
|
2013-05-28 02:17:24 +04:00
|
|
|
var path = $.map(listDir(base), function(e){
|
|
|
|
|
return /.*-images.json$/.test(e) ? e : null
|
|
|
|
|
}).sort().reverse()[0]
|
|
|
|
|
path = path == null ? 'images.json' : path
|
|
|
|
|
|
|
|
|
|
console.log('Loading:', path)
|
|
|
|
|
|
|
|
|
|
path = base +'/'+ path
|
|
|
|
|
|
2013-05-28 15:22:05 +04:00
|
|
|
// explicit path...
|
|
|
|
|
// XXX need to account for paths without a CACHE_DIR
|
2013-05-28 02:17:24 +04:00
|
|
|
} else {
|
|
|
|
|
path = normalizePath(path)
|
|
|
|
|
var base = path.split(CACHE_DIR)[0]
|
|
|
|
|
base += '/'+ CACHE_DIR
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var diff_data = {}
|
|
|
|
|
var diff = true
|
|
|
|
|
|
2013-05-28 04:41:16 +04:00
|
|
|
// collect and merge image diffs...
|
2013-05-28 02:17:24 +04:00
|
|
|
// XXX no error handling if one of the diff loads fail...
|
|
|
|
|
if(!no_load_diffs){
|
2013-05-28 04:41:16 +04:00
|
|
|
var diff_data = [diff_data]
|
2013-05-28 02:17:24 +04:00
|
|
|
var diffs_names = $.map(listDir(base), function(e){
|
|
|
|
|
return /.*-images-diff.json$/.test(e) ? e : null
|
|
|
|
|
}).sort()
|
|
|
|
|
diff = $.when.apply(null, $.map(diffs_names, function(e, i){
|
|
|
|
|
return $.getJSON(normalizePath(base +'/'+ e))
|
2013-05-28 04:41:16 +04:00
|
|
|
// XXX this is ugly, had to do it this way as .then(...)
|
|
|
|
|
// handlers get different argument sets depending on
|
|
|
|
|
// whether we have one or more deffereds here...
|
2013-05-28 02:17:24 +04:00
|
|
|
.done(function(data){
|
2013-05-28 04:41:16 +04:00
|
|
|
diff_data[i+1] = data
|
2013-05-28 02:17:24 +04:00
|
|
|
console.log('Loaded:', e)
|
|
|
|
|
})
|
|
|
|
|
}))
|
|
|
|
|
.then(function(){
|
2013-05-28 04:41:16 +04:00
|
|
|
$.extend.apply(null, diff_data)
|
|
|
|
|
diff_data = diff_data[0]
|
2013-05-28 02:17:24 +04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 15:22:05 +04:00
|
|
|
// load the main image file and merge the diff with it...
|
2013-05-28 02:17:24 +04:00
|
|
|
return $.when(diff, $.getJSON(path))
|
|
|
|
|
.done(function(_, json){
|
|
|
|
|
json = json[0]
|
|
|
|
|
$.extend(json, diff_data)
|
2013-05-22 03:10:24 +04:00
|
|
|
IMAGES = json
|
2013-05-28 02:17:24 +04:00
|
|
|
|
2013-05-22 03:10:24 +04:00
|
|
|
console.log('Loaded IMAGES...')
|
2013-05-19 22:48:28 +04:00
|
|
|
|
2013-05-22 03:10:24 +04:00
|
|
|
callback != null && callback()
|
|
|
|
|
})
|
2013-05-22 03:41:51 +04:00
|
|
|
.fail(function(){
|
|
|
|
|
console.error('ERROR LOADING:', path)
|
|
|
|
|
})
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 03:41:51 +04:00
|
|
|
|
2013-05-28 15:22:05 +04:00
|
|
|
// Save current images list...
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will save the merged images and remove the diff files...
|
|
|
|
|
// NOTE: if an explicit name is given then this will not remove anything.
|
|
|
|
|
// NOTE: if not explicit name is given this will save to the current
|
|
|
|
|
// cache dir.
|
|
|
|
|
function saveFileImages(name){
|
|
|
|
|
var remove_diffs = (name == null)
|
|
|
|
|
name = name == null ? normalizePath(CACHE_DIR +'/'+ Date.timeStamp()) : name
|
|
|
|
|
|
|
|
|
|
if(window.dumpJSON == null){
|
|
|
|
|
console.error('Can\'t save to file.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// remove the diffs...
|
|
|
|
|
if(remove_diffs){
|
|
|
|
|
$.each($.map(listDir(normalizePath(CACHE_DIR)), function(e){
|
|
|
|
|
return /.*-images-diff.json$/.test(e) ? e : null
|
|
|
|
|
}), function(i, e){
|
|
|
|
|
console.log('removeing:', e)
|
|
|
|
|
removeFile(normalizePath(CACHE_DIR +'/'+ e))
|
|
|
|
|
})
|
|
|
|
|
IMAGES_UPDATED = []
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dumpJSON(name + '-images.json', IMAGES)
|
|
|
|
|
//DATA.image_file = normalizePath(name + '-images.json', null, 'relative')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 04:41:16 +04:00
|
|
|
function loadFileState(data_path, callback){
|
2013-05-26 02:55:41 +04:00
|
|
|
var base = data_path.split(CACHE_DIR)[0]
|
|
|
|
|
base = base == data_path ? '.' : base
|
2013-05-28 04:41:16 +04:00
|
|
|
var res = $.Deferred()
|
|
|
|
|
|
|
|
|
|
$.getJSON(data_path)
|
2013-05-22 03:10:24 +04:00
|
|
|
.done(function(json){
|
2013-05-26 02:55:41 +04:00
|
|
|
BASE_URL = base
|
2013-05-28 04:41:16 +04:00
|
|
|
|
2013-05-22 03:10:24 +04:00
|
|
|
// legacy format...
|
|
|
|
|
if(json.version == null){
|
|
|
|
|
json = convertDataGen1(json)
|
|
|
|
|
DATA = json.data
|
|
|
|
|
IMAGES = json.images
|
2013-05-24 19:28:05 +04:00
|
|
|
MARKED = []
|
2013-05-22 03:10:24 +04:00
|
|
|
loadData()
|
|
|
|
|
|
|
|
|
|
// version 2.0
|
|
|
|
|
} else if(json.version == '2.0') {
|
|
|
|
|
DATA = json
|
2013-05-28 15:22:05 +04:00
|
|
|
loadFileImages(DATA.image_file == null ?
|
|
|
|
|
normalizePath(DATA.image_file, base)
|
|
|
|
|
: null)
|
|
|
|
|
.done(function(){
|
|
|
|
|
loadData()
|
|
|
|
|
callback != null && callback()
|
|
|
|
|
res.resolve()
|
|
|
|
|
})
|
2013-05-22 03:10:24 +04:00
|
|
|
|
|
|
|
|
// unknown format...
|
|
|
|
|
} else {
|
|
|
|
|
console.error('unknown format.')
|
|
|
|
|
return
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
2013-05-22 03:10:24 +04:00
|
|
|
})
|
2013-05-22 03:41:51 +04:00
|
|
|
.fail(function(){
|
|
|
|
|
console.error('ERROR LOADING:', data_path)
|
|
|
|
|
})
|
2013-05-28 04:41:16 +04:00
|
|
|
|
|
|
|
|
return res
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
|
|
|
|
|
2013-05-22 03:41:51 +04:00
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
function saveFileState(name, no_normalize_path){
|
|
|
|
|
name = name == null ? Date.timeStamp() : name
|
|
|
|
|
|
|
|
|
|
if(!no_normalize_path){
|
|
|
|
|
name = normalizePath(CACHE_DIR +'/'+ name)
|
|
|
|
|
|
|
|
|
|
// write .image_file only if saving data to a non-cache dir...
|
|
|
|
|
// XXX check if this is correct...
|
|
|
|
|
} else {
|
2013-05-19 22:48:28 +04:00
|
|
|
if(DATA.image_file == null){
|
2013-05-20 02:49:14 +04:00
|
|
|
DATA.image_file = name + '-images.json'
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
2013-05-28 02:17:24 +04:00
|
|
|
}
|
2013-05-19 22:48:28 +04:00
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
dumpJSON(name + '-data.json', DATA)
|
|
|
|
|
dumpJSON(name + '-marked.json', MARKED)
|
|
|
|
|
|
|
|
|
|
// save the updated images...
|
|
|
|
|
if(IMAGES_UPDATED.length > 0){
|
|
|
|
|
var updated = {}
|
|
|
|
|
$.each(IMAGES_UPDATED, function(i, e){
|
|
|
|
|
updated[e] = IMAGES[e]
|
|
|
|
|
})
|
|
|
|
|
dumpJSON(name + '-images-diff.json', updated)
|
|
|
|
|
IMAGES_UPDATED = []
|
2013-05-19 22:48:28 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
// Load a path
|
|
|
|
|
//
|
|
|
|
|
// This will try and to this in the following order:
|
|
|
|
|
// 1) find a data file in the given path
|
|
|
|
|
// 2) find a cache directory and a data file there
|
|
|
|
|
// 3) list the images and load them as-is
|
|
|
|
|
//
|
|
|
|
|
// XXX make sure that save works...
|
|
|
|
|
function loadDir(path, raw_load){
|
2013-05-28 02:17:24 +04:00
|
|
|
path = normalizePath(path)
|
2013-05-28 19:25:13 +04:00
|
|
|
var orig_path = path
|
|
|
|
|
var data
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-28 02:17:24 +04:00
|
|
|
var files = listDir(path)
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
if(files == null){
|
|
|
|
|
console.error('Path error:', path)
|
|
|
|
|
return
|
|
|
|
|
}
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
if(!raw_load){
|
|
|
|
|
data = $.map(files, function(e){
|
2013-05-28 02:17:24 +04:00
|
|
|
return /.*-data.json$/.test(e) ? e : null
|
|
|
|
|
}).sort().reverse()[0]
|
|
|
|
|
data = (data == null && files.indexOf('data.json') >= 0) ? 'data.json' : data
|
2013-05-28 19:25:13 +04:00
|
|
|
|
|
|
|
|
// look in the cache dir...
|
|
|
|
|
if(data == null){
|
|
|
|
|
path += '/' + CACHE_DIR
|
|
|
|
|
|
|
|
|
|
files = listDir(path)
|
|
|
|
|
if(files != null){
|
|
|
|
|
data = $.map(listDir(path), function(e){
|
|
|
|
|
return /.*-data.json$/.test(e) ? e : null
|
|
|
|
|
}).sort().reverse()[0]
|
|
|
|
|
data = (data == null && files.indexOf('data.json') >= 0) ? 'data.json' : data
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-28 02:17:24 +04:00
|
|
|
}
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
// load the found data file...
|
|
|
|
|
if(data != null){
|
|
|
|
|
console.log('Loading:', data)
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
data = path + '/' + data
|
2013-05-17 02:30:24 +04:00
|
|
|
|
2013-05-28 19:25:13 +04:00
|
|
|
return loadFileState(data)
|
|
|
|
|
|
|
|
|
|
// load the dir as-is...
|
|
|
|
|
} else {
|
|
|
|
|
files = listDir(orig_path)
|
|
|
|
|
var image_paths = $.map(files, function(e){
|
|
|
|
|
return /.*\.(jpg|jpeg|png|gif)$/i.test(e) ? e : null
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if(image_paths.length == 0){
|
|
|
|
|
console.error('No images in:', orig_path)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-28 21:59:38 +04:00
|
|
|
IMAGES = imagesFromUrls(image_paths)
|
2013-05-28 19:25:13 +04:00
|
|
|
DATA = dataFromImages(IMAGES)
|
|
|
|
|
MARKED = []
|
|
|
|
|
BASE_URL = orig_path
|
|
|
|
|
|
|
|
|
|
loadData()
|
|
|
|
|
}
|
2013-05-17 01:04:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-28 04:41:16 +04:00
|
|
|
// Open image in an external editor/viewer
|
|
|
|
|
//
|
|
|
|
|
// NOTE: this will open the default editor/viewer.
|
|
|
|
|
function openImage(){
|
|
|
|
|
if(window.runSystem == null){
|
|
|
|
|
console.error('Can\'t run external programs.')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// XXX if path is not present try and open the biggest preview...
|
|
|
|
|
return runSystem(normalizePath(IMAGES[getImageGID()].path, BASE_URL))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-05-20 04:43:00 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
/**********************************************************************
|
|
|
|
|
* Setup
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-14 16:04:57 +04:00
|
|
|
// Setup event handlers for data bindings...
|
|
|
|
|
//
|
|
|
|
|
// This does two jobs:
|
|
|
|
|
// - maintain DATA state
|
|
|
|
|
// - editor actions
|
|
|
|
|
// - focus
|
|
|
|
|
// - marking
|
|
|
|
|
// - maintain view consistency
|
|
|
|
|
// - centering/moving (roll)
|
|
|
|
|
// - shifting (expand/contract)
|
|
|
|
|
// - zooming (expand/contract)
|
|
|
|
|
//
|
2013-05-14 00:01:03 +04:00
|
|
|
function setupDataBindings(viewer){
|
|
|
|
|
viewer = viewer == null ? $('.viewer') : viewer
|
|
|
|
|
viewer
|
2013-05-14 02:42:19 +04:00
|
|
|
// XXX need to maintain the correct number of images per ribbon
|
|
|
|
|
// per zoom setting -- things get really odd when a ribbon
|
|
|
|
|
// is smaller than it should be...
|
2013-05-20 02:49:14 +04:00
|
|
|
// XXX this does not get called on marking...
|
2013-05-13 02:24:36 +04:00
|
|
|
.on('preCenteringRibbon', function(evt, ribbon, image){
|
|
|
|
|
// NOTE: we do not need to worry about centering the ribbon
|
|
|
|
|
// here, just ball-park-load the correct batch...
|
|
|
|
|
|
|
|
|
|
var gid = getImageGID(image)
|
|
|
|
|
var r = getRibbonIndex(ribbon)
|
|
|
|
|
var gr = DATA.ribbons[r]
|
|
|
|
|
var img_before = getImageBefore(image, ribbon)
|
|
|
|
|
var gid_before = getGIDBefore(gid, r)
|
2013-05-14 00:01:03 +04:00
|
|
|
var screen_size = getScreenWidthInImages()
|
2013-05-25 14:24:29 +04:00
|
|
|
screen_size = screen_size < 1 ? 1 : screen_size
|
2013-05-14 02:42:19 +04:00
|
|
|
var l = ribbon.find('.image').length
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-14 00:01:03 +04:00
|
|
|
// load images if we do a long jump -- start, end or some mark
|
|
|
|
|
// outside of currently loaded section...
|
2013-05-14 02:42:19 +04:00
|
|
|
if(gid_before == null
|
|
|
|
|
|| gid_before != getImageGID(img_before)
|
|
|
|
|
// also load if we run out of images in the current ribbon,
|
|
|
|
|
// likely due to shifting...
|
|
|
|
|
|| ( gr.length > l
|
|
|
|
|
&& l < screen_size * LOAD_SCREENS)){
|
2013-05-14 02:04:12 +04:00
|
|
|
loadImages(gid, Math.round(screen_size * LOAD_SCREENS), ribbon)
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 02:42:19 +04:00
|
|
|
// roll the ribbon while we are advancing...
|
2013-05-14 02:04:12 +04:00
|
|
|
var head = img_before.prevAll('.image')
|
|
|
|
|
var tail = img_before.nextAll('.image')
|
|
|
|
|
|
|
|
|
|
// NOTE: if this is greater than the number of images currently
|
|
|
|
|
// loaded, it might lead to odd effects...
|
2013-05-25 14:24:29 +04:00
|
|
|
var frame_size = Math.ceil((screen_size * LOAD_SCREENS) / 2)
|
|
|
|
|
//var threshold = Math.ceil(screen_size * LOAD_THRESHOLD)
|
|
|
|
|
var threshold = Math.floor(frame_size / 2)
|
|
|
|
|
threshold = threshold < 1 ? 1 : threshold
|
2013-05-14 02:04:12 +04:00
|
|
|
|
|
|
|
|
// do the loading...
|
2013-05-25 14:24:29 +04:00
|
|
|
// XXX need to expand/contract the ribbon depending on speed...
|
|
|
|
|
// ...might also be a good idea to load smaller images
|
|
|
|
|
// while scrolling really fast...
|
2013-05-14 02:04:12 +04:00
|
|
|
// XXX use extendRibbon, to both roll and expand/contract...
|
2013-05-25 14:24:29 +04:00
|
|
|
// XXX BUG: when rolling a ribbon, this will sometimes
|
|
|
|
|
// misalign an image...
|
|
|
|
|
// ...where exactly this happens in the ribbon depends on
|
|
|
|
|
// its size and LOAD_SCREENS...
|
|
|
|
|
// NOTE: calling centerView() will fix this.
|
|
|
|
|
// ...the problem is in centerRibbon
|
2013-05-14 02:04:12 +04:00
|
|
|
if(tail.length < threshold){
|
|
|
|
|
var rolled = rollImages(frame_size, ribbon)
|
|
|
|
|
}
|
|
|
|
|
if(head.length < threshold){
|
|
|
|
|
var rolled = rollImages(-frame_size, ribbon)
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
2013-05-14 00:01:03 +04:00
|
|
|
})
|
2013-05-13 02:24:36 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
.on('shiftedImage', function(evt, image, from, to){
|
|
|
|
|
from = getRibbonIndex(from)
|
|
|
|
|
var ribbon = to
|
|
|
|
|
to = getRibbonIndex(to)
|
|
|
|
|
|
|
|
|
|
var gid = getImageGID(image)
|
2013-05-14 02:04:12 +04:00
|
|
|
var after = getGIDBefore(gid, to)
|
2013-05-13 02:24:36 +04:00
|
|
|
|
2013-05-14 02:04:12 +04:00
|
|
|
// remove the elem from the from ribbon...
|
2013-05-13 02:24:36 +04:00
|
|
|
var index = DATA.ribbons[from].indexOf(gid)
|
|
|
|
|
var img = DATA.ribbons[from].splice(index, 1)
|
|
|
|
|
|
2013-05-14 02:04:12 +04:00
|
|
|
// put the elem in the to ribbon...
|
|
|
|
|
index = after == null ? 0 : DATA.ribbons[to].indexOf(after) + 1
|
2013-05-13 02:24:36 +04:00
|
|
|
DATA.ribbons[to].splice(index, 0, gid)
|
2013-05-14 16:21:45 +04:00
|
|
|
|
|
|
|
|
// indicators...
|
|
|
|
|
flashIndicator(from < to ? 'next' : 'prev')
|
2013-05-13 02:24:36 +04:00
|
|
|
})
|
|
|
|
|
|
2013-05-14 00:01:03 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
.on('createdRibbon', function(evt, index){
|
|
|
|
|
index = getRibbonIndex(index)
|
|
|
|
|
DATA.ribbons.splice(index, 0, [])
|
|
|
|
|
})
|
|
|
|
|
.on('removedRibbon', function(evt, index){
|
|
|
|
|
DATA.ribbons.splice(index, 1)
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-14 00:01:03 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
.on('requestedFirstImage', function(evt, ribbon){
|
|
|
|
|
var r = getRibbonIndex(ribbon)
|
|
|
|
|
var gr = DATA.ribbons[r]
|
|
|
|
|
rollImages(-gr.length, ribbon)
|
|
|
|
|
})
|
|
|
|
|
.on('requestedLastImage', function(evt, ribbon){
|
|
|
|
|
var r = getRibbonIndex(ribbon)
|
|
|
|
|
var gr = DATA.ribbons[r]
|
|
|
|
|
rollImages(gr.length, ribbon)
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-14 00:01:03 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
.on('fittingImages', function(evt, n){
|
2013-05-14 02:42:19 +04:00
|
|
|
// load correct amount of images in each ribbon!!!
|
|
|
|
|
var screen_size = getScreenWidthInImages()
|
|
|
|
|
var gid = getImageGID()
|
|
|
|
|
$('.ribbon').each(function(){
|
|
|
|
|
var r = $(this)
|
|
|
|
|
loadImages(gid, Math.round(screen_size * LOAD_SCREENS), r)
|
|
|
|
|
})
|
|
|
|
|
centerView(null, 'css')
|
2013-05-17 01:04:20 +04:00
|
|
|
|
2013-05-24 00:42:39 +04:00
|
|
|
// update settings...
|
2013-05-24 00:32:42 +04:00
|
|
|
if(toggleSingleImageMode('?') == 'on'){
|
|
|
|
|
SETTINGS['screen-images-single-image-mode'] = n
|
|
|
|
|
} else {
|
|
|
|
|
SETTINGS['screen-images-ribbon-mode'] = n
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-14 02:42:19 +04:00
|
|
|
// update previews...
|
|
|
|
|
// XXX make this update only what needs updating...
|
2013-05-13 02:24:36 +04:00
|
|
|
updateImages()
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-14 02:42:19 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
.on('focusingImage', function(evt, image){
|
|
|
|
|
DATA.current = getImageGID($(image))
|
|
|
|
|
})
|
2013-05-14 18:10:33 +04:00
|
|
|
|
2013-05-23 17:28:00 +04:00
|
|
|
|
2013-05-23 17:17:31 +04:00
|
|
|
// basic image manipulation...
|
|
|
|
|
// XXX after this we need to save the images...
|
|
|
|
|
.on('rotatingLeft rotatingRight', function(evt, image){
|
|
|
|
|
$(image).each(function(i, e){
|
|
|
|
|
var img = $(this)
|
|
|
|
|
var gid = getImageGID(img)
|
|
|
|
|
var orientation = img.attr('orientation')
|
|
|
|
|
|
|
|
|
|
IMAGES[gid].orientation = orientation
|
2013-05-28 02:17:24 +04:00
|
|
|
if(IMAGES_UPDATED.indexOf(gid) == -1){
|
|
|
|
|
IMAGES_UPDATED.push(gid)
|
|
|
|
|
}
|
2013-05-23 17:17:31 +04:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-14 18:10:33 +04:00
|
|
|
|
2013-05-14 18:35:09 +04:00
|
|
|
// marks...
|
|
|
|
|
// XXX toggle marking a block is not yet supported...
|
2013-05-14 18:10:33 +04:00
|
|
|
.on('togglingMark', function(evt, img, action){
|
|
|
|
|
var gid = getImageGID(img)
|
|
|
|
|
|
|
|
|
|
// add marked image to list...
|
|
|
|
|
if(action == 'on'){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.push(gid)
|
2013-05-14 18:10:33 +04:00
|
|
|
|
|
|
|
|
// remove marked image from list...
|
|
|
|
|
} else {
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.splice(MARKED.indexOf(gid), 1)
|
2013-05-14 18:10:33 +04:00
|
|
|
}
|
|
|
|
|
})
|
2013-05-14 18:35:09 +04:00
|
|
|
.on('removeingRibbonMarks', function(evt, ribbon){
|
|
|
|
|
$.each(DATA.ribbons[getRibbonIndex(ribbon)], function(_, e){
|
2013-05-17 04:52:43 +04:00
|
|
|
var i = MARKED.indexOf(e)
|
2013-05-14 18:35:09 +04:00
|
|
|
if(i != -1){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.splice(i, 1)
|
2013-05-14 18:35:09 +04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.on('removeingAllMarks', function(evt){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.splice(0, MARKED.length)
|
2013-05-14 18:35:09 +04:00
|
|
|
})
|
|
|
|
|
.on('markingRibbon', function(evt, ribbon){
|
|
|
|
|
$.each(DATA.ribbons[getRibbonIndex(ribbon)], function(_, e){
|
2013-05-17 04:52:43 +04:00
|
|
|
var i = MARKED.indexOf(e)
|
2013-05-14 18:35:09 +04:00
|
|
|
if(i == -1){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.push(e)
|
2013-05-14 18:35:09 +04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.on('markingAll', function(evt){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.splice(0, MARKED.length)
|
|
|
|
|
MARKED.concat(DATA.order)
|
2013-05-14 18:35:09 +04:00
|
|
|
})
|
|
|
|
|
.on('invertingMarks', function(evt, ribbon){
|
|
|
|
|
$.each(DATA.ribbons[getRibbonIndex(ribbon)], function(_, e){
|
2013-05-17 04:52:43 +04:00
|
|
|
var i = MARKED.indexOf(e)
|
2013-05-14 18:35:09 +04:00
|
|
|
if(i == -1){
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.push(e)
|
2013-05-14 18:35:09 +04:00
|
|
|
} else {
|
2013-05-17 04:52:43 +04:00
|
|
|
MARKED.splice(i, 1)
|
2013-05-14 18:35:09 +04:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
2013-05-17 01:04:20 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// caching...
|
|
|
|
|
.on('reloadedRibbon updatedRibbon', function(evt, ribbon){
|
|
|
|
|
|
|
|
|
|
window.DEBUG && console.log('>>> (ribbon:', getRibbonIndex(ribbon), ') Updating cache...')
|
|
|
|
|
|
|
|
|
|
preCacheRibbonImages(ribbon)
|
|
|
|
|
})
|
2013-05-13 02:24:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-17 06:59:04 +04:00
|
|
|
|
2013-05-13 02:24:36 +04:00
|
|
|
/**********************************************************************
|
2013-05-28 02:17:24 +04:00
|
|
|
* vim:set ts=4 sw=4 spell : */
|