From b41bbd973856993b5b65d268bf70f2aa02bf1530 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 28 Dec 2015 07:09:06 +0300 Subject: [PATCH] added .replaceGid(..) + some work on URL hash support... Signed-off-by: Alex A. Naanou --- ui (gen4)/data.js | 29 ++++++++++++++++++++++++ ui (gen4)/features/base.js | 15 +++++++++++++ ui (gen4)/features/meta.js | 7 +++++- ui (gen4)/features/ui.js | 46 ++++++++++++++++++++++++++++++++++++++ ui (gen4)/images.js | 13 +++++++++++ ui (gen4)/lib/transform.js | 8 ++++++- ui (gen4)/ribbons.js | 12 ++++++++++ 7 files changed, 128 insertions(+), 2 deletions(-) diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index d00f5723..ef13c567 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -464,6 +464,35 @@ var DataPrototype = { return this }, + // Replace image gid... + // + // XXX should this work for ribbon gids??? + replaceGid: function(from, to){ + from = this.getImage(from) + var i = this.getImageOrder(from) + + var t = this.getImage(to) + + if(t != -1 && t != null){ + return + } + + // current... + if(from == this.current){ + this.current = to + } + // order... + this.order[i] = to + // image lists... + this.eachImageList(function(list){ + if(list[i] != null){ + list[i] = to + } + }) + + return this + }, + /*********************************************** Introspection ***/ diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index ff1e4528..cb65f07e 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -245,6 +245,21 @@ actions.Actions({ return res }], + replaceGid: ['- System/Replace image gid', + function(from, to){ + from = this.data.getImage(from) + + // data... + var res = this.data.replaceGid(from, to) + + if(res == null){ + return + } + + // images... + this.images && this.images.replaceGid(from, to) + }], + // basic navigation... // diff --git a/ui (gen4)/features/meta.js b/ui (gen4)/features/meta.js index a4efd8dc..377770fe 100755 --- a/ui (gen4)/features/meta.js +++ b/ui (gen4)/features/meta.js @@ -49,11 +49,15 @@ core.ImageGridFeatures.Feature('viewer-testing', [ 'image-marks', 'image-bookmarks', - // local storage... + + // local storage + url... 'config-local-storage', + // XXX make this browser-only... + 'ui-url-hash', 'url-history-local-storage', 'ui-single-image-view-local-storage', + 'fs-loader', 'ui-fs-loader', 'fs-url-history', @@ -92,6 +96,7 @@ core.ImageGridFeatures.Feature('viewer-testing', [ //'auto-single-image', //'auto-ribbon', + // XXX not yet fully tested... 'system-journal', ]) diff --git a/ui (gen4)/features/ui.js b/ui (gen4)/features/ui.js index 58005910..7d61851d 100755 --- a/ui (gen4)/features/ui.js +++ b/ui (gen4)/features/ui.js @@ -289,6 +289,13 @@ actions.Actions({ }], + replaceGid: [ + function(from, to){ + return function(res){ + res && this.ribbons.replaceGid(from, to) + } + }], + // This is called by .ribbons, the goal is to use it to hook into // image updating from features and extensions... // @@ -2802,6 +2809,45 @@ module.DirectControlGSAP = core.ImageGridFeatures.Feature({ +//--------------------------------------------------------------------- +// XXX make this browser specific... +// XXX BUG: loading of current gid from url for some reason is broken, +// race?... + +var URLHash = +module.URLHash = core.ImageGridFeatures.Feature({ + title: '', + doc: '', + + tag: 'ui-url-hash', + depends: ['ui'], + + handlers: [ + ['focusImage', + function(res, a){ + console.log('focus:', a) + if(this.current && this.current != ''){ + location.hash = this.current + } + }], + // XXX this does not work for some reason... + // ...likely because of the slow async load and sync set... + ['start', + function(){ + var h = location.hash + h = h.replace(/^#/, '') + + // for some odd reason this does not work... + if(h != ''){ + console.log('!!!!', h) + this.current = h + } + }], + ], +}) + + + //--------------------------------------------------------------------- // XXX console / log / status bar diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index 23fc3492..57ce9ae2 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -501,6 +501,19 @@ module.ImagesPrototype = { return r == null ? n : parseInt(r[1]) }, + // Replace image gid... + // + replaceGid: function(from, to){ + var img = this[from] + + // XXX is the test needed here??? + if(img != null){ + delete this[from] + this[to] = img + } + + return this + }, // Gid sorters... // XXX might be a good idea to add caching... diff --git a/ui (gen4)/lib/transform.js b/ui (gen4)/lib/transform.js index d0aa8ed0..3d680902 100755 --- a/ui (gen4)/lib/transform.js +++ b/ui (gen4)/lib/transform.js @@ -87,6 +87,11 @@ var obj2transform = function(obj, filter){ // .translate3d(1,2,3) // -> [1, 2, 3] // NOTE: both set data correctly... +// XXX add argument in place operations... +// += +// -= +// *= +// /= // XXX move the grammar out of this... // XXX need: // - a way to minimize this, i.e. get only full and minimal functions... @@ -116,7 +121,7 @@ var transformEditor = function(){ // methods... // XXX generate this... simplify: function(filter){ - data = this.data + var data = this.data // scale... if(data.scale @@ -375,6 +380,7 @@ var transformEditor = function(){ } // XXX get these from grammar... + // The Grammar... func('translate', ['px', 'px'], 0) func('translate3d', ['px', 'px', 'px'], 0) func('translateX', ['px'], 0) diff --git a/ui (gen4)/ribbons.js b/ui (gen4)/ribbons.js index 6822dbd5..5f4545b4 100755 --- a/ui (gen4)/ribbons.js +++ b/ui (gen4)/ribbons.js @@ -1315,6 +1315,18 @@ var RibbonsPrototype = { return img }, + // Replace image gid... + // + // XXX should this work for ribbon gids??? + replaceGid: function(from, to){ + var img = this.getImage(from) + + img && img.length > 0 + && this.setElemGID(img, to) + + return this + }, + // Update image(s)... // // Update current image: