Merge
authorAnthony Ly <anthonyly.com@gmail.com>
Mon, 15 Apr 2013 18:12:26 +0200
changeset 34 dca8dba08970
parent 33 ca5982c67338 (current diff)
parent 32 683a6d889924 (diff)
child 35 841c06278982
Merge
--- a/integ/js/iri-creation-cinecard.js	Mon Apr 15 18:11:24 2013 +0200
+++ b/integ/js/iri-creation-cinecard.js	Mon Apr 15 18:12:26 2013 +0200
@@ -230,7 +230,24 @@
 		catch(err) {
 			e.originalEvent.dataTransfer.setData("text",div.innerHTML);
 		}
-    });
+    }).on("touchmove", ".cinecard-draggable", function(e) {
+		e.preventDefault();
+		var touch = e.originalEvent.changedTouches[0],
+			off = _renkan.renderer.canvas_$.offset(),
+			w = _renkan.renderer.canvas_$.width(),
+			h = _renkan.renderer.canvas_$.height();
+		if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) {
+			if (elementDropped) {
+				_renkan.renderer.onMouseMove(touch, true);
+			} else {
+				elementDropped = true;
+	        	var div = document.createElement('div');
+	        	div.appendChild(this.cloneNode(true));
+				_renkan.renderer.dropData({"text/html": div.innerHTML}, touch);
+				_renkan.renderer.onMouseDown(touch, true);
+			}
+		}
+	});;
 
 $(".send").click(function() {
 	alert("Save JSON data:\n\n" + JSON.stringify(_renkan.project.toJSON()));
--- a/integ/renkan/js/main.js	Mon Apr 15 18:11:24 2013 +0200
+++ b/integ/renkan/js/main.js	Mon Apr 15 18:12:26 2013 +0200
@@ -183,6 +183,8 @@
     	}
     });
     
+    var elementDropped = false;
+    
     this.$.find(".Rk-Bins")
         .on("click",".Rk-Bin-Title,.Rk-Bin-Title-Icon", function() {
             var _mainDiv = Rkns.$(this).siblings(".Rk-Bin-Main");
@@ -207,6 +209,30 @@
 				this.dragDrop();
 			}
 			catch(err) {}
+        }).on("touchstart", ".Rk-Bin-Item", function(e) {
+			elementDropped = false;
+        }).on("touchmove", ".Rk-Bin-Item", function(e) {
+			e.preventDefault();
+        	var touch = e.originalEvent.changedTouches[0],
+        		off = _this.renderer.canvas_$.offset(),
+        		w = _this.renderer.canvas_$.width(),
+        		h = _this.renderer.canvas_$.height();
+    		if (touch.pageX >= off.left && touch.pageX < (off.left + w) && touch.pageY >= off.top && touch.pageY < (off.top + h)) {
+    			if (elementDropped) {
+    				_this.renderer.onMouseMove(touch, true);
+    			} else {
+    				elementDropped = true;
+		        	var div = document.createElement('div');
+		        	div.appendChild(this.cloneNode(true));
+    				_this.renderer.dropData({"text/html": div.innerHTML}, touch);
+    				_this.renderer.onMouseDown(touch, true);
+    			}
+    		}
+        }).on("touchend", ".Rk-Bin-Item", function(e) {
+			if (elementDropped) {
+				_this.renderer.onMouseUp(touch, true);
+			}
+			elementDropped = false;
         }).on("dragstart", ".Rk-Bin-Item", function(e) {
         	var div = document.createElement('div');
         	div.appendChild(this.cloneNode(true));
--- a/integ/renkan/js/paper-renderer.js	Mon Apr 15 18:11:24 2013 +0200
+++ b/integ/renkan/js/paper-renderer.js	Mon Apr 15 18:12:26 2013 +0200
@@ -222,6 +222,8 @@
 
 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
 
+Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {}
+
 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
 
 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
@@ -431,6 +433,7 @@
 }
 
 Rkns.Renderer.Node.prototype.select = function() {
+	this.selected = true;
     this.circle.strokeWidth = this.options.selected_node_stroke_width;
     if (this.renderer.isEditable()) {
     	this.buttons.forEach(function(b) {
@@ -457,6 +460,7 @@
 }
 
 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
+	this.selected = false;
     if (!_newTarget || _newTarget.source_representation !== this) {
     	this.buttons.forEach(function(b) {
     		b.hide();
@@ -469,6 +473,15 @@
     }
 }
 
+Rkns.Renderer.Node.prototype.toggleSelect = function() {
+	if (this.selected) {
+		this.unselect(null);
+	} else {
+		this.renderer.unselectAll();
+		this.select();
+	}
+}
+	
 Rkns.Renderer.Node.prototype.highlight = function() {
     this.circle.fillColor = this.options.highlighted_node_fill_color;
     if (this.node_image) {
@@ -496,12 +509,19 @@
     }
 }
 
-Rkns.Renderer.Node.prototype.mouseup = function(_event) {
+Rkns.Renderer.Node.prototype.mousedown = function(_event, _isTouch) {
+	if (_isTouch) {
+		this.toggleSelect();
+	}
+}
+
+Rkns.Renderer.Node.prototype.mouseup = function(_event, _isTouch) {
     if (this.renderer.isEditable() && this.renderer.is_dragging) {
         this.saveCoords();
-    }
-    else {
-        this.openEditor();
+    } else {
+    	if (!_isTouch) {
+    		this.openEditor();
+    	}
     }
     this.renderer.click_target = null;
     this.renderer.is_dragging = false;
@@ -633,6 +653,7 @@
 }
 
 Rkns.Renderer.Edge.prototype.select = function() {
+	this.selected = true;
     this.line.strokeWidth = this.options.selected_edge_stroke_width;
     if (this.renderer.isEditable()) {
 	    this.edit_button.show();
@@ -644,6 +665,7 @@
 }
 
 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
+	this.selected = false;
     if (!_newTarget || _newTarget.source_representation !== this) {
     	if (this.options.editor_mode) {
 	        this.edit_button.hide();
@@ -653,17 +675,32 @@
     }
 }
 
-Rkns.Renderer.Edge.prototype.mouseup = function(_event) {
-    if (!this.renkan.read_only) {
-        if (this.renderer.is_dragging) {
-            this.from_representation.saveCoords();
-            this.to_representation.saveCoords();
-            this.from_representation.is_dragging = false;
-            this.to_representation.is_dragging = false;
-        } else {
-            this.openEditor();
-        }
-    }
+Rkns.Renderer.Edge.prototype.toggleSelect = function() {
+	if (this.selected) {
+		this.unselect(null);
+	} else {
+		this.renderer.unselectAll();
+		this.select();
+	}
+}
+
+Rkns.Renderer.Edge.prototype.mousedown = function(_event, _isTouch) {
+	if (_isTouch) {
+		this.toggleSelect();
+	}
+}
+
+Rkns.Renderer.Edge.prototype.mouseup = function(_event, _isTouch) {
+    if (!this.renkan.read_only && this.renderer.is_dragging) {
+        this.from_representation.saveCoords();
+        this.to_representation.saveCoords();
+        this.from_representation.is_dragging = false;
+        this.to_representation.is_dragging = false;
+    } else {
+    	if (!_isTouch) {
+    		this.openEditor();
+    	}
+	}
     this.renderer.click_target = null;
     this.renderer.is_dragging = false;
 }
@@ -747,7 +784,7 @@
     this.redraw();
 }
 
-Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) {
+Rkns.Renderer.TempEdge.prototype.mouseup = function(_event, _isTouch) {
     var _hitResult = paper.project.hitTest(_event.point),
         _model = this.from_representation.model,
         _endDrag = true;
@@ -1203,6 +1240,19 @@
     this.text = "Link to another node";
 }
 
+Rkns.Renderer.NodeLinkButton.prototype.mousedown = function(_event, _isTouch) {
+    if (this.renderer.isEditable()) {
+	    var _off = this.renderer.canvas_$.offset(),
+	    	_point = new paper.Point([
+	            _event.pageX - _off.left,
+	            _event.pageY - _off.top
+	        ]);
+        this.renderer.click_target = null;
+        this.renderer.removeRepresentationsOfType("editor");
+        this.renderer.addTempEdge(this.source_representation, _point);
+    }
+}
+
 /* */
 
 Rkns.Renderer.NodeEnlargeButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
@@ -1270,6 +1320,8 @@
 }
 
 Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() {
+    this.renderer.click_target = null;
+    this.renderer.is_dragging = false;
     this.renderer.removeRepresentationsOfType("editor");
     if (this.renderer.isEditable() && confirm(this.renkan.translate('Do you really wish to remove edge ') + '"' + this.source_representation.model.get("title") + '"?')) {
         this.project.removeEdge(this.source_representation.model);
@@ -1351,28 +1403,61 @@
     this.click_mode = false;
     
     var _this = this,
-        _allowScroll = true;
+        _allowScroll = true,
+        _originalScale,
+        _zooming = false;
     
     this.canvas_$.on({
     	mousedown: function(_event) {
-    		_this.onMouseDown(_event);
+    		_this.onMouseDown(_event, false);
     	},
     	mousemove: function(_event) {
-        _this.onMouseMove(_event);
+        	_this.onMouseMove(_event, false);
 	    },
 	    mouseup: function(_event) {
-	        _this.onMouseUp(_event);
+	        _this.onMouseUp(_event, false);
 	    },
 	    mousewheel: function(_event, _delta) {
 	        if (_allowScroll) {
 	        	_this.onScroll(_event, _delta);
 	        }
 	    },
+	    touchstart: function(_event) {
+	    	_event.preventDefault();
+	    	_originalScale = _this.scale;
+	    	_zooming = false;
+	    	_this.onMouseDown(_event.originalEvent.changedTouches[0], true);
+	    },
+	    touchmove: function(_event) {
+	    	_event.preventDefault();
+	    	if (typeof _event.originalEvent.scale === "undefined" || _event.originalEvent.scale == 1) {
+	    		// On Android, scale is undefined, so no zooming..
+	    		_this.onMouseMove(_event.originalEvent.changedTouches[0], true);
+	    	} else {
+	    		if (!_zooming) {
+	    			_this.onMouseUp(_event, true);
+			        _this.click_target = null;
+			        _this.is_dragging = false;
+			        _zooming = true;
+	    		}
+	    		var _newScale = _event.originalEvent.scale * _originalScale,
+	    			_scaleRatio = _newScale / _this.scale,
+	    			_newOffset = new paper.Point([
+			            _this.canvas_$.width(),
+			            _this.canvas_$.height()
+			        ]).multiply( .5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
+	    		_this.setScale(_newScale, _this.offset);
+	    	}
+	    },
+	    touchend: function(_event) {
+	    	_event.preventDefault();
+	    	_this.onMouseUp(_event.originalEvent.changedTouches[0], true);
+	    },
 	    dblclick: function(_event) {
 	        _this.onDoubleClick(_event);
 	    },
 	    mouseleave: function(_event) {
-	        _this.onMouseUp(_event);
+	        _this.onMouseUp(_event, false);
 	        _this.click_target = null;
 	        _this.is_dragging = false;
 	    },
@@ -1387,145 +1472,47 @@
 	    	_allowScroll = true;
 	    	_event.preventDefault();
 	    },
-    drop: function(_event) {
-    	_event.preventDefault();
-    	_allowScroll = true;
-    	if (!_this.isEditable()) {
-    		return;
-    	}
-    	var res = {};
-    	Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) {
-    		try {
-    			res[t] = _event.originalEvent.dataTransfer.getData(t);
-    		} catch(e) {}
-    	});
-		var text = _event.originalEvent.dataTransfer.getData("Text");
-		if (typeof text === "string") {
-			switch(text[0]) {
-    			case "{":
-    			case "[":
-    				try {
-    					var data = JSON.parse(text);
-    					_(res).extend(data);
-    				}
-    				catch(e) {
-    					if (!res["text/plain"]) {
-    						res["text/plain"] = text;
-    					}
-    				}
-				break;
-				case "<":
-					if (!res["text/html"]) {
-						res["text/html"] = text;
-					}
-				break;
-				default:
-					if (!res["text/plain"]) {
-						res["text/plain"] = text;
-					}
-    		}
-		}
-		var url = _event.originalEvent.dataTransfer.getData("URL");
-		if (url && !res["text/uri-list"]) {
-			res["text/uri-list"] = url;
-		}
-		if (res["text/json"] || res["application/json"]) {
-			try {
-				var data = JSON.parse(res["text/json"] || res["application/json"]);
-				_(res).extend(data);
+	    drop: function(_event) {
+	    	_event.preventDefault();
+	    	_allowScroll = true;
+	    	var res = {};
+	    	Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) {
+	    		try {
+	    			res[t] = _event.originalEvent.dataTransfer.getData(t);
+	    		} catch(e) {}
+	    	});
+			var text = _event.originalEvent.dataTransfer.getData("Text");
+			if (typeof text === "string") {
+				switch(text[0]) {
+	    			case "{":
+	    			case "[":
+	    				try {
+	    					var data = JSON.parse(text);
+	    					_(res).extend(data);
+	    				}
+	    				catch(e) {
+	    					if (!res["text/plain"]) {
+	    						res["text/plain"] = text;
+	    					}
+	    				}
+					break;
+					case "<":
+						if (!res["text/html"]) {
+							res["text/html"] = text;
+						}
+					break;
+					default:
+						if (!res["text/plain"]) {
+							res["text/plain"] = text;
+						}
+	    		}
 			}
-			catch(e) {}
-		}
-    	var newNode = {};
-    	switch(res["text/x-iri-specific-site"]) {
-    		case "twitter":
-    			var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]),
-    				tweetdiv = snippet.find(".tweet")
-    			newNode.title = _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 = Rkns.$('<div>').html(res["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 (res["text/x-iri-source-uri"]) {
-		    		newNode.uri = res["text/x-iri-source-uri"];
-		    	}
-		    	if (res["text/plain"] || res["text/x-iri-selected-text"]) {
-		    		newNode.description = (res["text/plain"] || res["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim();
-		    	}
-		    	if (res["text/html"] || res["text/x-iri-selected-html"]) {
-		    		var snippet = Rkns.$('<div>').html(res["text/html"] || res["text/x-iri-selected-html"]);
-		    		var _imgs = snippet.find("img");
-		    		if (_imgs.length) {
-		    			newNode.image = _imgs[0].src;
-		    		}
-		    		var _as = snippet.find("a");
-		    		if (_as.length) {
-		    			newNode.uri = _as[0].href;
-		    		}
-		    		newNode.title = snippet.find("[title]").attr("title") || newNode.title;
-		    		newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
-		    	}
-		    	if (res["text/uri-list"]) {
-		    		newNode.uri = res["text/uri-list"];
-		    	}
-		    	if (res["text/x-moz-url"] && !newNode.title) {
-		    		newNode.title = (res["text/x-moz-url"].split("\n")[1] || "").trim();
-		    		if (newNode.title === newNode.uri) {
-		    			newNode.title = false;
-		    		}
-		    	}
-		    	if (res["text/x-iri-source-title"] && !newNode.title) {
-		    		newNode.title = res["text/x-iri-source-title"];
-		    	}
-		    	if (res["text/html"] || res["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;
-		    		newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
-		    	}
-    	}
-    	var fields = ["title", "description", "uri", "image"];
-    	for (var i = 0; i < fields.length; i++) {
-    		var f = fields[i];
-    		if (res["text/x-iri-" + f] || res[f]) {
-    			newNode[f] = res["text/x-iri-" + f] || res[f];
-    		}
-    		if (newNode[f] === "none" || newNode[f] === "null") {
-    			newNode[f] = undefined;
-    		}
-    	}
-    	if (newNode.title || newNode.description || newNode.uri) {
-    		var _off = _this.canvas_$.offset(),
-            _point = new paper.Point([
-                _event.originalEvent.pageX - _off.left,
-                _event.originalEvent.pageY - _off.top
-            ]),
-            _coords = _this.toModelCoords(_point),
-            _data = {
-                id: Rkns.Utils.getUID('node'),
-                created_by: _this.renkan.current_user,
-                uri: newNode.uri || "",
-                title: newNode.title || _this.renkan.translate("Dragged resource"),
-                description: newNode.description || "",
-                image: newNode.image || "",
-                color: newNode.color || undefined,
-                position: {
-                    x: _coords.x,
-                    y: _coords.y
-                }
-            };
-        	var _node = _this.renkan.project.addNode(_data);
-            _this.getRepresentationByModel(_node).openEditor();
-    	}
-    }
+			var url = _event.originalEvent.dataTransfer.getData("URL");
+			if (url && !res["text/uri-list"]) {
+				res["text/uri-list"] = url;
+			}
+			_this.dropData(res, _event.originalEvent);
+	    }
     });
     this.editor_$.find(".Rk-ZoomOut").click(function() {
     	var _newScale = _this.scale * Math.SQRT1_2,
@@ -1662,7 +1649,7 @@
         _thRedraw();
     });
     this.renkan.project.on("change:title", function(_model, _title) {
-        var el = $(".Rk-PadTitle");
+        var el = _this.$.find(".Rk-PadTitle");
         if (el.is("input")) {
             if (el.val() !== _title) {
                 el.val(_title);
@@ -1671,7 +1658,7 @@
             el.text(_title);
         }
     });
-    
+        
     this.redraw();
     
     if (this.minimap) {
@@ -1679,6 +1666,7 @@
 	    	_this.rescaleMinimap()
 	    }, 2000);
     }
+
 }
 
 Rkns.Renderer.Scene.prototype.template = Rkns._.template(
@@ -1692,8 +1680,8 @@
     + '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div>'
     + '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">'
     + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a>'
-    + '<div class="Rk-TopBar-Separator"></div></div>'
-    + '<% } } %>'
+    + '<div class="Rk-TopBar-Separator"></div>'
+    + '<% } %></div><% } %>'
     + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>"><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
@@ -1886,6 +1874,12 @@
     });
 }
 
+Rkns.Renderer.Scene.prototype.unselectAll = function(_model) {
+    Rkns._(this.representations).each(function(_repr) {
+        _repr.unselect();
+    });
+}
+
 Rkns.Renderer.Scene.prototype.redraw = function() {
     Rkns._(this.representations).each(function(_representation) {
     	_representation.redraw(true);
@@ -1916,7 +1910,7 @@
         }
     } else {
         if (this.selected_target) {
-            this.selected_target.unselect(null);
+            this.selected_target.unselect();
         }
         this.selected_target = null;
     }
@@ -1932,8 +1926,8 @@
     	_point = new paper.Point([
             _event.pageX - _off.left,
             _event.pageY - _off.top
-        ]);
-	var _delta = _point.subtract(this.last_point);
+        ]),
+        _delta = _point.subtract(this.last_point);
 	this.last_point = _point;
     if (!this.is_dragging && this.mouse_down && _delta.length > Rkns.Renderer._MIN_DRAG_DISTANCE) {
     	this.is_dragging = true;
@@ -1951,7 +1945,7 @@
     paper.view.draw();
 }
 
-Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
+Rkns.Renderer.Scene.prototype.onMouseDown = function(_event, _isTouch) {
     var _off = this.canvas_$.offset(),
     	_point = new paper.Point([
             _event.pageX - _off.left,
@@ -1963,12 +1957,9 @@
         this.removeRepresentationsOfType("editor");
         this.is_dragging = false;
         var _hitResult = paper.project.hitTest(_point);
-        if (this.isEditable() && _hitResult && typeof _hitResult.item.__representation !== "undefined") {
+        if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
             this.click_target = _hitResult.item.__representation;
-            if (this.click_target.type === "Node-link-button") {
-                this.removeRepresentationsOfType("editor");
-                this.addTempEdge(this.click_target.source_representation, _point);
-            }
+            this.click_target.mousedown(_event, _isTouch);
         } else {
             this.click_target = null;
             if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) {
@@ -1999,9 +1990,10 @@
             this.click_mode = false;
         }
     }
+    paper.view.draw();
 }
 
-Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
+Rkns.Renderer.Scene.prototype.onMouseUp = function(_event, _isTouch) {
 	this.mouse_down = false;
     if (this.click_target) {
         var _off = this.canvas_$.offset();
@@ -2011,12 +2003,17 @@
                     _event.pageX - _off.left,
                     _event.pageY - _off.top
                 ])
-            }
+            },
+            _isTouch
         );
     } else {
         this.click_target = null;
         this.is_dragging = false;
+        if (_isTouch) {
+        	this.unselectAll();
+        }
     }
+    paper.view.draw();
 }
 
 Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) {
@@ -2061,3 +2058,108 @@
     }
     paper.view.draw();
 }
+
+Rkns.Renderer.Scene.prototype.dropData = function(_data, _event) {
+	if (!this.isEditable()) {
+		return;
+	}
+	if (_data["text/json"] || _data["application/json"]) {
+		try {
+			var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]);
+			_(_data).extend(jsondata);
+		}
+		catch(e) {}
+	}
+	var newNode = {};
+	switch(_data["text/x-iri-specific-site"]) {
+		case "twitter":
+			var snippet = Rkns.$('<div>').html(_data["text/x-iri-selected-html"]),
+				tweetdiv = snippet.find(".tweet")
+			newNode.title = _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 = Rkns.$('<div>').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"];
+	    	}
+	    	if (_data["text/plain"] || _data["text/x-iri-selected-text"]) {
+	    		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 = Rkns.$('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]);
+	    		var _imgs = snippet.find("img");
+	    		if (_imgs.length) {
+	    			newNode.image = _imgs[0].src;
+	    		}
+	    		var _as = snippet.find("a");
+	    		if (_as.length) {
+	    			newNode.uri = _as[0].href;
+	    		}
+	    		newNode.title = snippet.find("[title]").attr("title") || newNode.title;
+	    		newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim();
+	    	}
+	    	if (_data["text/uri-list"]) {
+	    		newNode.uri = _data["text/uri-list"];
+	    	}
+	    	if (_data["text/x-moz-url"] && !newNode.title) {
+	    		newNode.title = (_data["text/x-moz-url"].split("\n")[1] || "").trim();
+	    		if (newNode.title === newNode.uri) {
+	    			newNode.title = false;
+	    		}
+	    	}
+	    	if (_data["text/x-iri-source-title"] && !newNode.title) {
+	    		newNode.title = _data["text/x-iri-source-title"];
+	    	}
+	    	if (_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;
+	    		newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description;
+	    	}
+	}
+	var fields = ["title", "description", "uri", "image"];
+	for (var i = 0; i < fields.length; i++) {
+		var f = fields[i];
+		if (_data["text/x-iri-" + f] || _data[f]) {
+			newNode[f] = _data["text/x-iri-" + f] || _data[f];
+		}
+		if (newNode[f] === "none" || newNode[f] === "null") {
+			newNode[f] = undefined;
+		}
+	}
+	if (newNode.title || newNode.description || newNode.uri) {
+		var _off = this.canvas_$.offset(),
+        _point = new paper.Point([
+            _event.pageX - _off.left,
+            _event.pageY - _off.top
+        ]),
+        _coords = this.toModelCoords(_point),
+        _nodedata = {
+            id: Rkns.Utils.getUID('node'),
+            created_by: this.renkan.current_user,
+            uri: newNode.uri || "",
+            title: newNode.title || this.renkan.translate("Dragged resource"),
+            description: newNode.description || "",
+            image: newNode.image || "",
+            color: newNode.color || undefined,
+            position: {
+                x: _coords.x,
+                y: _coords.y
+            }
+        };
+    	var _node = this.renkan.project.addNode(_nodedata),
+    		_repr = this.getRepresentationByModel(_node);
+    	if (_event.type === "drop") {
+        	_repr.openEditor();
+        }
+	}
+}