diff -r f67047a16084 -r fba23fde14ba client/js/renderer/scene.js
--- a/client/js/renderer/scene.js Fri May 16 12:37:51 2014 +0200
+++ b/client/js/renderer/scene.js Fri May 16 14:09:57 2014 +0200
@@ -1,9 +1,9 @@
-"use strict";
define(['jquery', 'underscore', 'requtils', 'renderer/miniframe'], function ($, _, requtils, MiniFrame) {
-
+ 'use strict';
+
var Utils = requtils.getUtils();
-
+
/* Scene Begin */
var Scene = function(_renkan) {
@@ -28,7 +28,7 @@
this.node_layer = new paper.Layer();
this.buttons_layer = new paper.Layer();
this.delete_list = [];
-
+
if (_renkan.options.show_minimap) {
this.minimap = {
background_layer: new paper.Layer(),
@@ -45,7 +45,7 @@
this.minimap.rectangle.strokeColor = _renkan.options.minimap_border_color;
this.minimap.rectangle.strokeWidth = 4;
this.minimap.offset = new paper.Point(this.minimap.size.divide(2));
- this.minimap.scale = .1;
+ this.minimap.scale = 0.1;
this.minimap.node_layer.activate();
this.minimap.cliprectangle = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
@@ -54,7 +54,7 @@
this.minimap.miniframe = new paper.Path.Rectangle(this.minimap.topleft, this.minimap.size);
this.minimap.node_group.addChild(this.minimap.miniframe);
this.minimap.miniframe.fillColor = '#c0c0ff';
- this.minimap.miniframe.opacity = .3;
+ this.minimap.miniframe.opacity = 0.3;
this.minimap.miniframe.strokeColor = '#000080';
this.minimap.miniframe.strokeWidth = 3;
this.minimap.miniframe.__representation = new MiniFrame(this, null);
@@ -82,7 +82,7 @@
img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
_this.icon_cache[imgname] = img;
});
-
+
var throttledMouseMove = _.throttle(function(_event, _isTouch) {
_this.onMouseMove(_event, _isTouch);
}, Utils._MOUSEMOVE_RATE);
@@ -112,9 +112,9 @@
_event.preventDefault();
var _touches = _event.originalEvent.touches[0];
if (
- _renkan.options.allow_double_click
- && new Date() - _lastTap < Utils._DOUBLETAP_DELAY
- && ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE )
+ _renkan.options.allow_double_click &&
+ new Date() - _lastTap < Utils._DOUBLETAP_DELAY &&
+ ( Math.pow(_lastTapX - _touches.pageX, 2) + Math.pow(_lastTapY - _touches.pageY, 2) < Utils._DOUBLETAP_DISTANCE )
) {
_lastTap = 0;
_this.onDoubleClick(_touches);
@@ -130,7 +130,7 @@
touchmove: function(_event) {
_event.preventDefault();
_lastTap = 0;
- if (_event.originalEvent.touches.length == 1) {
+ if (_event.originalEvent.touches.length === 1) {
_this.onMouseMove(_event.originalEvent.touches[0], true);
} else {
if (!_zooming) {
@@ -147,7 +147,7 @@
_newOffset = new paper.Point([
_this.canvas_$.width(),
_this.canvas_$.height()
- ]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
+ ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
_this.setScale(_newScale, _newOffset);
}
},
@@ -256,15 +256,16 @@
bindClick(".Rk-Save-Button", "save");
bindClick(".Rk-Open-Button", "open");
this.$.find(".Rk-Bookmarklet-Button")
- .attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan))
- .click(function(){
- _this.notif_$
- .text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan."))
- .fadeIn()
- .delay(5000)
- .fadeOut();
- return false;
- });
+ /*jshint scripturl:true */
+ .attr("href","javascript:" + Utils._BOOKMARKLET_CODE(_renkan))
+ .click(function(){
+ _this.notif_$
+ .text(_renkan.translate("Drag this button to your bookmark bar. When on a third-party website, click it to enable drag-and-drop from the website to Renkan."))
+ .fadeIn()
+ .delay(5000)
+ .fadeOut();
+ return false;
+ });
this.$.find(".Rk-TopBar-Button").mouseover(function() {
$(this).find(".Rk-TopBar-Tooltip").show();
}).mouseout(function() {
@@ -338,8 +339,8 @@
if (_renkan.options.size_bug_fix) {
var _delay = (
- typeof _renkan.options.size_bug_fix === "number"
- ? _renkan.options.size_bug_fix
+ typeof _renkan.options.size_bug_fix === "number" ?
+ _renkan.options.size_bug_fix
: 500
);
window.setTimeout(
@@ -404,7 +405,7 @@
if (rxs.test(n.get("title")) || rxs.test(n.get("description"))) {
_this.getRepresentationByModel(n).highlight(rxs);
} else {
- _this.getRepresentationByModel(n).unhighlight();
+ _this.getRepresentationByModel(n).unhighlight();
}
});
}
@@ -442,31 +443,31 @@
_(Scene.prototype).extend({
template: _.template(
- '<% if (options.show_top_bar) { %>
<% if (!options.editor_mode) { %>
<%- project.get("title") || translate("Untitled project")%>
'
- + '<% } else { %>
" placeholder="<%-translate("Untitled project")%>" /><% } %>'
- + '<% if (options.show_user_list) { %>
<% if (options.user_color_editable) { %><% } %>'
- + '<% if (options.user_color_editable) { print(colorPicker) } %>
<unknown user><% } %>'
- + '<% if (options.home_button_url) {%>
<% } %>'
- + '<% if (options.show_fullscreen_button) { %>
<% } %>'
- + '<% if (options.editor_mode) { %>'
- + '<% if (options.show_addnode_button) { %>
<% } %>'
- + '<% if (options.show_addedge_button) { %>
<% } %>'
- + '<% if (options.show_save_button) { %>
<% } %>'
- + '<% if (options.show_open_button) { %>
<% } %>'
- + '<% if (options.show_bookmarklet) { %>
<% } %>'
- + '
<% }; if (options.show_search_field) { %>'
- + '
<% } %>
<% } %>'
- + ''
- + '
'
- + '<% if (options.show_bins) { %>
«
<% } %>'
- + '
'
- + '
'
+ '<% if (options.show_top_bar) { %><% if (!options.editor_mode) { %>
<%- project.get("title") || translate("Untitled project")%>
' +
+ '<% } else { %>
" placeholder="<%-translate("Untitled project")%>" /><% } %>' +
+ '<% if (options.show_user_list) { %>
<% if (options.user_color_editable) { %><% } %>' +
+ '<% if (options.user_color_editable) { print(colorPicker) } %>
<unknown user><% } %>' +
+ '<% if (options.home_button_url) {%>
<% } %>' +
+ '<% if (options.show_fullscreen_button) { %>
<% } %>' +
+ '<% if (options.editor_mode) { %>' +
+ '<% if (options.show_addnode_button) { %>
<% } %>' +
+ '<% if (options.show_addedge_button) { %>
<% } %>' +
+ '<% if (options.show_save_button) { %>
<% } %>' +
+ '<% if (options.show_open_button) { %>
<% } %>' +
+ '<% if (options.show_bookmarklet) { %>
<% } %>' +
+ '
<% }; if (options.show_search_field) { %>' +
+ '
<% } %>
<% } %>' +
+ '' +
+ '
' +
+ '<% if (options.show_bins) { %>
«
<% } %>' +
+ '
' +
+ '
'
),
fixSize: function(_autoscale) {
var w = this.$.width(),
@@ -508,7 +509,7 @@
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy,
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx,
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy,
- _centerR = (_inR + _outR)/2,
+ _centerR = (_inR + _outR) / 2,
_centerRads = (_startRads + _endRads) / 2,
_centerX = Math.cos(_centerRads) * _centerR,
_centerY = Math.sin(_centerRads) * _centerR,
@@ -525,7 +526,7 @@
_path.lineTo([_endXOut, _endYOut]);
_path.arcTo([_centerXOut, _centerYOut], [_startXOut, _startYOut]);
_path.fillColor = _options.buttons_background;
- _path.opacity = .5;
+ _path.opacity = 0.5;
_path.closed = true;
_path.__representation = _repr;
var _text = new paper.PointText(_textX,_textY);
@@ -568,11 +569,11 @@
_grp.position = _restPos;
},
select: function() {
- _path.opacity = .8;
+ _path.opacity = 0.8;
_text.visible = true;
},
unselect: function() {
- _path.opacity = .5;
+ _path.opacity = 0.5;
_text.visible = false;
},
destroy: function() {
@@ -595,9 +596,9 @@
},
addToBundles: function(_edgeRepr) {
var _bundle = _(this.bundles).find(function(_bundle) {
- return (
- ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation )
- || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
+ return (
+ ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) ||
+ ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation )
);
});
if (typeof _bundle !== "undefined") {
@@ -683,8 +684,8 @@
_maxx = Math.max.apply(Math, _xx),
_maxy = Math.max.apply(Math, _yy);
var _scale = Math.min(
- this.scale * .8 * this.renkan.options.minimap_width / paper.view.bounds.width,
- this.scale * .8 * this.renkan.options.minimap_height / paper.view.bounds.height,
+ this.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width,
+ this.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height,
( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
);
@@ -692,7 +693,7 @@
this.minimap.scale = _scale;
}
if (nodes.length === 1) {
- this.minimap.scale = .1;
+ this.minimap.scale = 0.1;
this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale));
}
this.redraw();
@@ -707,8 +708,8 @@
return _point.subtract(this.offset).divide(this.scale);
},
addRepresentation: function(_type, _model) {
- var r = requtils.getRenderer()[_type];
- var _repr = new r(this, _model);
+ var RendererType = requtils.getRenderer()[_type];
+ var _repr = new RendererType(this, _model);
this.representations.push(_repr);
return _repr;
},
@@ -781,7 +782,7 @@
_representation.destroy();
this.representations = _(this.representations).reject(
function(_repr) {
- return _repr == _representation;
+ return _repr === _representation;
}
);
},
@@ -795,7 +796,7 @@
},
removeRepresentationsOfType: function(_type) {
var _representations = _(this.representations).filter(function(_repr) {
- return _repr.type == _type;
+ return _repr.type === _type;
}),
_this = this;
_(_representations).each(function(_repr) {
@@ -990,22 +991,22 @@
},
defaultDropHandler: function(_data) {
var newNode = {};
+ var snippet = "";
switch(_data["text/x-iri-specific-site"]) {
case "twitter":
- var snippet = $('').html(_data["text/x-iri-selected-html"]),
- tweetdiv = snippet.find(".tweet");
+ snippet = $('
').html(_data["text/x-iri-selected-html"]);
+ var tweetdiv = snippet.find(".tweet");
newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name");
newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id");
newNode.image = tweetdiv.find(".avatar").attr("src");
newNode.description = tweetdiv.find(".js-tweet-text:first").text();
break;
case "google":
- var snippet = $('
').html(_data["text/x-iri-selected-html"]);
+ snippet = $('
').html(_data["text/x-iri-selected-html"]);
newNode.title = snippet.find("h3:first").text().trim();
newNode.uri = snippet.find("h3 a").attr("href");
newNode.description = snippet.find(".st:first").text().trim();
break;
- case undefined:
default:
if (_data["text/x-iri-source-uri"]) {
newNode.uri = _data["text/x-iri-source-uri"];
@@ -1015,7 +1016,7 @@
newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
}
if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
- var snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
+ snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
var _svgimgs = snippet.find("image");
if (_svgimgs.length) {
newNode.image = _svgimgs.attr("xlink:href");
@@ -1048,7 +1049,7 @@
newNode.title = _data["text/x-iri-source-title"];
}
if (_data["text/html"] || _data["text/x-iri-selected-html"]) {
- var snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
+ snippet = $('
').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
newNode.image = snippet.find("[data-image]").attr("data-image") || newNode.image;
newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri;
newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title;
@@ -1069,11 +1070,11 @@
newNode[f] = undefined;
}
}
-
+
if(typeof this.renkan.options.drop_enhancer === "function"){
newNode = this.renkan.options.drop_enhancer(newNode, _data);
}
-
+
return newNode;
},
@@ -1088,9 +1089,9 @@
}
catch(e) {}
}
-
+
var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data);
-
+
var _off = this.canvas_$.offset(),
_point = new paper.Point([
_event.pageX - _off.left,
@@ -1119,18 +1120,19 @@
},
fullScreen: function() {
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen,
- _el = this.renkan.$[0],
- _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
- _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"];
+ _el = this.renkan.$[0],
+ _requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"],
+ _cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"],
+ i;
if (_isFull) {
- for (var i = 0; i < _cancelMethods.length; i++) {
+ for (i = 0; i < _cancelMethods.length; i++) {
if (typeof document[_cancelMethods[i]] === "function") {
document[_cancelMethods[i]]();
break;
}
}
} else {
- for (var i = 0; i < _requestMethods.length; i++) {
+ for (i = 0; i < _requestMethods.length; i++) {
if (typeof _el[_requestMethods[i]] === "function") {
_el[_requestMethods[i]]();
break;
@@ -1143,7 +1145,7 @@
_offset = new paper.Point([
this.canvas_$.width(),
this.canvas_$.height()
- ]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
+ ]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
this.setScale( _newScale, _offset );
},
zoomIn: function() {
@@ -1151,7 +1153,7 @@
_offset = new paper.Point([
this.canvas_$.width(),
this.canvas_$.height()
- ]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
+ ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
this.setScale( _newScale, _offset );
},
addNodeBtn: function() {
@@ -1177,9 +1179,9 @@
foldBins: function() {
var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
bins = this.renkan.$.find(".Rk-Bins");
+ var _this = this;
if (bins.offset().left < 0) {
bins.animate({left: 0},250);
- var _this = this;
this.$.animate({left: 300},250,function() {
var w = _this.$.width();
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
@@ -1187,7 +1189,6 @@
foldBinsButton.html("«");
} else {
bins.animate({left: -300},250);
- var _this = this;
this.$.animate({left: 0},250,function() {
var w = _this.$.width();
paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
@@ -1198,9 +1199,9 @@
save: function() { },
open: function() { }
});
-
+
/* Scene End */
-
+
return Scene;
-
+
});