| changeset 72 | dbd90c784424 |
| parent 70 | 47b3125130a2 |
| child 73 | cc9deb3b3e13 |
| 71:9af0874ce43f | 72:dbd90c784424 |
|---|---|
30 get: function(attr) { |
30 get: function(attr) { |
31 return this[attr] || false; |
31 return this[attr] || false; |
32 } |
32 } |
33 }, |
33 }, |
34 _BOOKMARKLET_CODE: function(_renkan) { |
34 _BOOKMARKLET_CODE: function(_renkan) { |
35 return "(function(a,b,c,d,e,f,h,i,j,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
35 return "(function(a,b,c,d,e,f,h,i,j,k,l,m,n,o,p,q,r){a=document;b=a.body;c=a.location.href;j='draggable';m='text/x-iri-';d=a.createElement('div');d.innerHTML='<p_style=\"position:fixed;top:0;right:0;font:bold_18px_sans-serif;color:#fff;background:#909;padding:10px;z-index:100000;\">" |
36 + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
36 + _renkan.translate("Drag items from this website, drop them in Renkan").replace(/ /g,"_") |
37 + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/^http:\\/\\/ldt\\.iri\\.centrepompidou\\.fr/,s:'.Ldt-AnnotationsList-li,.Ldt-Polemic-TweetDiv,.Ldt-Segments-Segment',n:'ldt'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();" |
37 + "</p>'.replace(/_/g,String.fromCharCode(32));b.appendChild(d);e=[{r:/https?:\\/\\/[^\\/]*twitter\\.com\\//,s:'.tweet',n:'twitter'},{r:/https?:\\/\\/[^\\/]*google\\.[^\\/]+\\//,s:'.g',n:'google'},{r:/https?:\\/\\/[^\\/]*lemonde\\.fr\\//,s:'[data-vr-contentbox]',n:'lemonde'}];f=false;e.forEach(function(g){if(g.r.test(c)){f=g;}});if(f){h=function(){Array.prototype.forEach.call(a.querySelectorAll(f.s),function(i){i[j]=true;k=i.style;k.borderWidth='2px';k.borderColor='#909';k.borderStyle='solid';k.backgroundColor='rgba(200,0,180,.1)';})};window.setInterval(h,500);h();};a.addEventListener('dragstart',function(k){l=k.dataTransfer;l.setData(m+'source-uri',c);l.setData(m+'source-title',a.title);n=k.target;if(f){o=n;while(!o.attributes[j]){o=o.parentNode;if(o==b){break;}}}if(f&&o.attributes[j]){p=o.cloneNode(true);l.setData(m+'specific-site',f.n)}else{q=a.getSelection();if(q.type==='Range'||!q.type){p=q.getRangeAt(0).cloneContents();}else{p=n.cloneNode();}}r=a.createElement('div');r.appendChild(p);l.setData('text/x-iri-selected-text',r.textContent.trim());l.setData('text/x-iri-selected-html',r.innerHTML);},false);})();" |
38 } |
38 } |
39 } |
39 } |
40 |
40 |
41 Rkns.Renderer.Utils = { |
41 Rkns.Renderer.Utils = { |
42 drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
42 drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
1283 var res = {} |
1283 var res = {} |
1284 Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) { |
1284 Rkns._(_event.originalEvent.dataTransfer.types).each(function(t) { |
1285 return res[t] = _event.originalEvent.dataTransfer.getData(t); |
1285 return res[t] = _event.originalEvent.dataTransfer.getData(t); |
1286 }); |
1286 }); |
1287 var newNode = {}; |
1287 var newNode = {}; |
1288 console.log(res); |
|
1289 switch(res["text/x-iri-specific-site"]) { |
1288 switch(res["text/x-iri-specific-site"]) { |
1290 case "twitter": |
1289 case "twitter": |
1291 var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]), |
1290 var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]), |
1292 tweetdiv = snippet.find(".tweet") |
1291 tweetdiv = snippet.find(".tweet") |
1293 newNode.title = _renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
1292 newNode.title = _renkan.translate("Tweet by ") + tweetdiv.attr("data-name"); |
1299 var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]); |
1298 var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]); |
1300 newNode.title = snippet.find("h3:first").text().trim(); |
1299 newNode.title = snippet.find("h3:first").text().trim(); |
1301 newNode.uri = snippet.find("h3 a").attr("href"); |
1300 newNode.uri = snippet.find("h3 a").attr("href"); |
1302 newNode.description = snippet.find(".st:first").text().trim(); |
1301 newNode.description = snippet.find(".st:first").text().trim(); |
1303 break; |
1302 break; |
1304 case "ldt": |
|
1305 var snippet = Rkns.$('<div>').html(res["text/x-iri-selected-html"]), |
|
1306 tweetel = snippet.children().first(); |
|
1307 if (tweetel.hasClass("Ldt-AnnotationsList-li")) { |
|
1308 newNode.title = tweetel.find(".Ldt-AnnotationsList-Title").text().trim(); |
|
1309 newNode.description = tweetel.find(".Ldt-AnnotationsList-Description").text().trim(); |
|
1310 newNode.image = tweetel.find(".Ldt-AnnotationsList-Thumbnail").attr("src"); |
|
1311 var url = tweetel.find("a").attr("href"); |
|
1312 if (/^https?:\/\//.test(url)) { |
|
1313 newNode.uri = url; |
|
1314 } else { |
|
1315 newNode.uri = res["text/x-iri-source-uri"].replace(/#.*$/,'') + '#' + url.replace(/^.*#/,'') |
|
1316 } |
|
1317 newNode.color = tweetel[0].style.backgroundColor; |
|
1318 } |
|
1319 if (tweetel.hasClass("Ldt-Polemic-TweetDiv")) { |
|
1320 newNode.title = _renkan.translate("Annotation from PolemicTweet"); |
|
1321 newNode.uri = res["text/x-iri-source-uri"].replace(/#.*$/,'') + '#id=' + tweetel.attr("annotation-id"); |
|
1322 newNode.description = tweetel.attr("tweet-title"); |
|
1323 newNode.color = tweetel.attr("polemic-color"); |
|
1324 } |
|
1325 if (tweetel.hasClass("Ldt-Segments-Segment")) { |
|
1326 var text = tweetel.attr("segment-text").split(/<[^>]+>/g); |
|
1327 newNode.title = text[0]; |
|
1328 newNode.description = text.slice(1).join(""); |
|
1329 |
|
1330 newNode.uri = res["text/x-iri-source-uri"].replace(/#.*$/,''); |
|
1331 var match = tweetel.attr("trace-info").match(/segment-id:([\d\w_-]+)/); |
|
1332 if (match) { |
|
1333 newNode.uri += '#id=' + match[1]; |
|
1334 } |
|
1335 newNode.color = tweetel.attr("data-base-color"); |
|
1336 } |
|
1337 break; |
|
1338 case undefined: |
1303 case undefined: |
1339 default: |
1304 default: |
1340 if (res["text/x-iri-source-uri"]) { |
1305 if (res["text/x-iri-source-uri"]) { |
1341 newNode.uri = res["text/x-iri-source-uri"]; |
1306 newNode.uri = res["text/x-iri-source-uri"]; |
1342 } |
1307 } |
1346 if (res["text/html"] || res["text/x-iri-selected-html"]) { |
1311 if (res["text/html"] || res["text/x-iri-selected-html"]) { |
1347 var snippet = Rkns.$('<div>').html(res["text/html"] || res["text/x-iri-selected-html"]); |
1312 var snippet = Rkns.$('<div>').html(res["text/html"] || res["text/x-iri-selected-html"]); |
1348 newNode.image = snippet.find("img").attr("src") || ''; |
1313 newNode.image = snippet.find("img").attr("src") || ''; |
1349 newNode.uri = snippet.find("a").attr("href") || newNode.uri; |
1314 newNode.uri = snippet.find("a").attr("href") || newNode.uri; |
1350 newNode.title = snippet.find("[title]").attr("title"); |
1315 newNode.title = snippet.find("[title]").attr("title"); |
1316 newNode.description = snippet.text().replace(/[\s\n]+/gm,' ').trim(); |
|
1351 } |
1317 } |
1352 if (res["text/uri-list"]) { |
1318 if (res["text/uri-list"]) { |
1353 newNode.uri = res["text/uri-list"]; |
1319 newNode.uri = res["text/uri-list"]; |
1354 } |
1320 } |
1355 if (res["text/x-moz-url"] && !newNode.title) { |
1321 if (res["text/x-moz-url"] && !newNode.title) { |