update the url on papershift or zoom
add update_url bool to the default options to activate or not this behavior
--- a/client/js/defaults.js Thu Jun 25 18:09:49 2015 +0200
+++ b/client/js/defaults.js Tue Aug 04 18:02:54 2015 +0200
@@ -50,6 +50,10 @@
default_view: false,
/* Allows to load default view (zoom+offset) at start on read_only mode, instead of autoScale. the default_view will be the last */
+ /* URL parsing */
+ update_url:true,
+ /* update the url each time the paper shift or on zoom in/out, with the serialized view (offset and scale) */
+
/* TOP BAR BUTTONS */
show_search_field: true,
--- a/client/js/renderer/scene.js Thu Jun 25 18:09:49 2015 +0200
+++ b/client/js/renderer/scene.js Tue Aug 04 18:02:54 2015 +0200
@@ -829,10 +829,6 @@
this.selected_target = null;
}
},
- paperShift: function(_delta) {
- this.view.offset = this.view.offset.add(_delta);
- this.redraw();
- },
onMouseMove: function(_event) {
var _off = this.canvas_$.offset(),
_point = new paper.Point([
@@ -849,7 +845,7 @@
if (this.click_target && typeof this.click_target.paperShift === "function") {
this.click_target.paperShift(_delta);
} else {
- this.paperShift(_delta);
+ this.view.paperShift(_delta);
}
} else {
this.findTarget(_hitResult);
@@ -922,6 +918,7 @@
if (_isTouch) {
this.unselectAll();
}
+ this.view.updateUrl();
}
paper.view.draw();
},
@@ -1207,22 +1204,16 @@
this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
return;
}
- if (typeof _params.idnode !== 'undefined'){
- console.log('params idnode');
- this.unhighlightAll();
- this.highlightModel(this.renkan.project.get("nodes").get(_params.idnode));
- }
if (typeof _params.view !== 'undefined'){
var viewParams = _params.view.split(",");
if (viewParams.length >= 3){
var params = {
- "project": this.renkan.project,
- "zoom_level": parseFloat(viewParams[0]),
- "offset": {
- "x": parseFloat(viewParams[1]),
- "y": parseFloat(viewParams[2])
- },
- "hidden_nodes": []
+ "project": this.renkan.project,
+ "offset": {
+ "x": parseFloat(viewParams[0]),
+ "y": parseFloat(viewParams[1])
+ },
+ "zoom_level": parseFloat(viewParams[2])
};
for (var i = 3; i < viewParams.length; i++){
params.hidden_nodes.push(viewParams[i]);
@@ -1241,6 +1232,11 @@
this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
}
}
+ //other parameters must go after because most of them depends on a view that must be initialize before
+ if (typeof _params.idNode !== 'undefined'){
+ this.unhighlightAll();
+ this.highlightModel(this.renkan.project.get("nodes").get(_params.iNnode));
+ }
},
foldBins: function() {
var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
--- a/client/js/renderer/viewrepr.js Thu Jun 25 18:09:49 2015 +0200
+++ b/client/js/renderer/viewrepr.js Tue Aug 04 18:02:54 2015 +0200
@@ -97,6 +97,7 @@
addHiddenNode: function(_model){
this.hideNode(_model);
this.hiddenNodes.push(_model.id);
+ this.updateUrl();
},
hideNode: function(_model){
if (typeof this.renderer.getRepresentationByModel(_model) !== 'undefined'){
@@ -132,6 +133,7 @@
this.offset = _offset;
}
this.renderer.redraw();
+ this.updateUrl();
}
},
zoomOut: function() {
@@ -183,9 +185,25 @@
},
paperShift: function(_delta) {
this.offset = this.offset.add(_delta);
- this.renderer.offset = this.renderer.offset.add(_delta);
this.renderer.redraw();
},
+ updateUrl: function(){
+ if(this.options.update_url){
+ var result = {};
+ var parameters = Backbone.history.getFragment().split('?');
+ if (parameters.length > 1){
+ parameters[1].split("&").forEach(function(part) {
+ var item = part.split("=");
+ result[item[0]] = decodeURIComponent(item[1]);
+ });
+ }
+ result.view = Math.round(this.offset.x*1000)/1000 + ',' + Math.round(this.offset.y*1000)/1000 + ',' + Math.round(this.scale*1000)/1000;
+// if (this.hiddenNodes.length > 0){
+// result.hiddenNodes = this.hiddenNodes.join();
+// }
+ this.renkan.router.navigate("?" + decodeURIComponent($.param(result)), {trigger: false, replace: false});
+ }
+ },
}).value();
return ViewRepr;