989 paper.view.draw(); |
989 paper.view.draw(); |
990 }, |
990 }, |
991 defaultDropHandler: function(_data) { |
991 defaultDropHandler: function(_data) { |
992 var newNode = {}; |
992 var newNode = {}; |
993 switch(_data["text/x-iri-specific-site"]) { |
993 switch(_data["text/x-iri-specific-site"]) { |
994 case "twitter": |
994 case "twitter": |
995 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]), |
995 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]), |
996 tweetdiv = snippet.find(".tweet"); |
996 tweetdiv = snippet.find(".tweet"); |
997 newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
997 newNode.title = this.renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
998 newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
998 newNode.uri = "http://twitter.com/" + tweetdiv.attr("data-screen-name") + "/status/" + tweetdiv.attr("data-tweet-id"); |
999 newNode.image = tweetdiv.find(".avatar").attr("src"); |
999 newNode.image = tweetdiv.find(".avatar").attr("src"); |
1000 newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
1000 newNode.description = tweetdiv.find(".js-tweet-text:first").text(); |
1001 break; |
1001 break; |
1002 case "google": |
1002 case "google": |
1003 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
1003 var snippet = $('<div>').html(_data["text/x-iri-selected-html"]); |
1004 newNode.title = snippet.find("h3:first").text().trim(); |
1004 newNode.title = snippet.find("h3:first").text().trim(); |
1005 newNode.uri = snippet.find("h3 a").attr("href"); |
1005 newNode.uri = snippet.find("h3 a").attr("href"); |
1006 newNode.description = snippet.find(".st:first").text().trim(); |
1006 newNode.description = snippet.find(".st:first").text().trim(); |
1007 break; |
1007 break; |
1008 case undefined: |
1008 case undefined: |
1009 default: |
1009 default: |
1010 if (_data["text/x-iri-source-uri"]) { |
1010 if (_data["text/x-iri-source-uri"]) { |
1011 newNode.uri = _data["text/x-iri-source-uri"]; |
1011 newNode.uri = _data["text/x-iri-source-uri"]; |
1012 } |
1012 } |
|
1013 } |
1013 if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1014 if (_data["text/plain"] || _data["text/x-iri-selected-text"]) { |
1014 newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
1015 newNode.description = (_data["text/plain"] || _data["text/x-iri-selected-text"]).replace(/[\s\n]+/gm,' ').trim(); |
1015 } |
1016 } |
1016 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1017 if (_data["text/html"] || _data["text/x-iri-selected-html"]) { |
1017 var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1018 var snippet = $('<div>').html(_data["text/html"] || _data["text/x-iri-selected-html"]); |
1052 newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
1053 newNode.uri = snippet.find("[data-uri]").attr("data-uri") || newNode.uri; |
1053 newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
1054 newNode.title = snippet.find("[data-title]").attr("data-title") || newNode.title; |
1054 newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
1055 newNode.description = snippet.find("[data-description]").attr("data-description") || newNode.description; |
1055 newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
1056 newNode.clipPath = snippet.find("[data-clip-path]").attr("data-clip-path") || newNode.clipPath; |
1056 } |
1057 } |
1057 } |
|
1058 |
|
1059 if(typeof this.renkan.options.drop_enhancer === "function"){ |
|
1060 newNode = this.renkan.options.drop_enhancer(newNode, _data); |
|
1061 } |
|
1062 return newNode; |
|
1063 |
|
1064 }, |
|
1065 dropData: function(_data, _event) { |
|
1066 if (!this.isEditable()) { |
|
1067 return; |
|
1068 } |
|
1069 if (_data["text/json"] || _data["application/json"]) { |
|
1070 try { |
|
1071 var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]); |
|
1072 _(_data).extend(jsondata); |
|
1073 } |
|
1074 catch(e) {} |
|
1075 } |
|
1076 |
|
1077 var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data); |
|
1078 |
1058 |
1079 if (!newNode.title) { |
1059 if (!newNode.title) { |
1080 newNode.title = this.renkan.translate("Dragged resource"); |
1060 newNode.title = this.renkan.translate("Dragged resource"); |
1081 } |
1061 } |
1082 var fields = ["title", "description", "uri", "image"]; |
1062 var fields = ["title", "description", "uri", "image"]; |
1087 } |
1067 } |
1088 if (newNode[f] === "none" || newNode[f] === "null") { |
1068 if (newNode[f] === "none" || newNode[f] === "null") { |
1089 newNode[f] = undefined; |
1069 newNode[f] = undefined; |
1090 } |
1070 } |
1091 } |
1071 } |
|
1072 |
|
1073 if(typeof this.renkan.options.drop_enhancer === "function"){ |
|
1074 newNode = this.renkan.options.drop_enhancer(newNode, _data); |
|
1075 } |
|
1076 |
|
1077 return newNode; |
|
1078 |
|
1079 }, |
|
1080 dropData: function(_data, _event) { |
|
1081 if (!this.isEditable()) { |
|
1082 return; |
|
1083 } |
|
1084 if (_data["text/json"] || _data["application/json"]) { |
|
1085 try { |
|
1086 var jsondata = JSON.parse(_data["text/json"] || _data["application/json"]); |
|
1087 _(_data).extend(jsondata); |
|
1088 } |
|
1089 catch(e) {} |
|
1090 } |
|
1091 |
|
1092 var newNode = (typeof this.renkan.options.drop_handler === "undefined")?this.defaultDropHandler(_data):this.renkan.options.drop_handler(_data); |
|
1093 |
1092 var _off = this.canvas_$.offset(), |
1094 var _off = this.canvas_$.offset(), |
1093 _point = new paper.Point([ |
1095 _point = new paper.Point([ |
1094 _event.pageX - _off.left, |
1096 _event.pageX - _off.left, |
1095 _event.pageY - _off.top |
1097 _event.pageY - _off.top |
1096 ]), |
1098 ]), |