lodlive.core.js 103 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118
  1. /*
  2. *
  3. * lodLive 1.0
  4. * is developed by Diego Valerio Camarda, Silvia Mazzini and Alessandro Antonuccio
  5. *
  6. * Licensed under the MIT license
  7. *
  8. * plase tell us if you use it!
  9. *
  10. * geodimail@gmail.com
  11. *
  12. */
  13. var debugOn = false;
  14. (function($, lodLiveProfile) {
  15. $.jsonp.setup({
  16. cache : true,
  17. callbackParameter : 'callback',
  18. callback : 'lodlive',
  19. pageCache : true,
  20. timeout : 30000
  21. });
  22. var globalInfoPanelMap = {};
  23. var globalInnerPageMap = {};
  24. var context;
  25. var methods = {
  26. init : function(firstUri) {
  27. context = this;
  28. context.append('<div id="lodlogo" class="sprite"></div>');
  29. // inizializzo il contenitore delle variabili di ambiente
  30. var storeIdsCleaner = $.jStorage.index();
  31. for (var int = 0; int < storeIdsCleaner.length; int++) {
  32. if (storeIdsCleaner[int].indexOf("storeIds-") == 0) {
  33. $.jStorage.deleteKey(storeIdsCleaner[int]);
  34. }
  35. }
  36. $.jStorage.set('imagesMap', {});
  37. $.jStorage.set('mapsMap', {});
  38. $.jStorage.set('infoPanelMap', {});
  39. // $.jStorage.set('storeIds',{});
  40. // template della query
  41. // creo il primo box, lo aggiungo al documento e lo posiziono
  42. // orizzontalmente nel centro
  43. var firstBox = $($.jStorage.get('boxTemplate'));
  44. methods.centerBox(firstBox);
  45. context.append(firstBox);
  46. firstBox.attr("id", MD5(firstUri));
  47. firstBox.attr("rel", firstUri);
  48. firstBox.css({
  49. 'zIndex' : 1
  50. });
  51. // inizializzo la mappa delle classi
  52. $.jStorage.set('classMap', {
  53. // randomize first color
  54. counter : Math.floor(Math.random() * 13) + 1
  55. });
  56. // imposto le dimensioni dell'area di lavoro
  57. // context.height($(document).height());
  58. // context.width($(document).width());
  59. // attivo le funzioni per il drag
  60. methods.renewDrag(context.children('.boxWrapper'));
  61. // carico il primo documento
  62. methods.openDoc(firstUri, firstBox);
  63. methods.controlPanel('init');
  64. // methods.controlPanel('move');
  65. methods.msg('', 'init');
  66. // methods.msg('', 'move');
  67. $(window).bind('scroll', function() {
  68. methods.docInfo(null, 'move');
  69. methods.controlPanel('move');
  70. });
  71. $(window).bind('resize', function() {
  72. methods.docInfo('', 'close');
  73. $('#controlPanel').remove();
  74. methods.controlPanel('init');
  75. // $(".tipsy").remove();
  76. });
  77. },
  78. close : function() {
  79. document.location = document.location.href.substring(0, document.location.href.indexOf("?"));
  80. },
  81. composeQuery : function(resource, module, testURI) {
  82. if (debugOn) {
  83. start = new Date().getTime();
  84. }
  85. var url = "";
  86. var res = "";
  87. var endpoint = "";
  88. $.each(lodLiveProfile.connection, function(key, value) {
  89. var keySplit = key.split(",");
  90. for (var a = 0; a < keySplit.length; a++) {
  91. if (( testURI ? testURI : resource).indexOf(keySplit[a]) == 0) {
  92. res = getSparqlConf(module, value, lodLiveProfile).replace(/\{URI\}/ig, resource.replace(/^.*~~/, ''));
  93. if (value.proxy) {
  94. url = value.proxy + '?endpoint=' + value.endpoint + "&" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + encodeURIComponent(res);
  95. } else {
  96. url = value.endpoint + "?" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + encodeURIComponent(res);
  97. }
  98. endpoint = value.endpoint;
  99. return false;
  100. }
  101. }
  102. });
  103. if (debugOn) {
  104. console.debug((new Date().getTime() - start) + ' composeQuery ');
  105. }
  106. if (url == '') {
  107. url = 'http://system/dummy?' + resource;
  108. }
  109. if (endpoint && $.jStorage.get('showInfoConsole')) {
  110. methods.queryConsole('log', {
  111. title : endpoint,
  112. text : res,
  113. id : url,
  114. uriId : resource
  115. });
  116. }
  117. return url;
  118. },
  119. guessingEndpoint : function(uri, onSuccess, onFail) {
  120. var base = uri.replace(/(^https?:\/\/[^\/]+\/).+/, "$1");
  121. var guessedEndpoint = base + "sparql?" + $.jStorage.get('endpoints')['all'] + "&query=" + encodeURIComponent("select * where {?a ?b ?c} LIMIT 1");
  122. $.jsonp({
  123. url : guessedEndpoint,
  124. success : function(data) {
  125. if (data && data.results && data.results.bindings[0]) {
  126. var connections = lodLiveProfile.connection;
  127. connections[base] = {
  128. endpoint : base + "sparql"
  129. };
  130. lodLiveProfile.connection = connections;
  131. onSuccess();
  132. } else {
  133. onFail();
  134. }
  135. },
  136. error : function() {
  137. onFail();
  138. }
  139. });
  140. },
  141. doStats : function(uri) {
  142. if ($('#stats').length == 0) {
  143. $('body').append('<div id="stats"><iframe src="stats.html?' + uri + '" style="display:none"></iframe></div>');
  144. } else if ($('#stats').children('iframe').length == 10) {
  145. $('#stats').empty();
  146. $('#stats').append('<iframe src="stats.html?' + uri + '" style="display:none"></iframe>');
  147. } else {
  148. $('#stats').append('<iframe src="stats.html?' + uri + '" style="display:none"></iframe>');
  149. }
  150. },
  151. msg : function(msg, action, type, endpoint, inverse) {
  152. // area dei messaggi
  153. var msgPanel = $('#msg');
  154. if (action == 'init') {
  155. if (msgPanel.length == 0) {
  156. msgPanel = $('<div id="msg"></div>');
  157. context.append(msgPanel);
  158. }
  159. } else if (action == 'move') {
  160. msgPanel.hide();
  161. msgPanel.css({
  162. display : 'none'
  163. });
  164. } else if (action == 'hide') {
  165. msgPanel.hide();
  166. } else {
  167. msgPanel.empty();
  168. msg = msg.replace(/http:\/\/.+~~/g, '');
  169. msg = msg.replace(/nodeID:\/\/.+~~/g, '');
  170. msg = msg.replace(/_:\/\/.+~~/g, '');
  171. msg = breakLines(msg);
  172. msg = msg.replace(/\|/g, '<br />');
  173. var msgs = msg.split(" \n ");
  174. if (type == 'fullInfo') {
  175. msgPanel.append("<div class=\"corner sprite\"></div>");
  176. msgPanel.append("<div class=\"endpoint\">" + endpoint + "</div>");
  177. if (msgs.length == 2) {
  178. msgPanel.append("<div class=\"separline sprite\"></div>");
  179. msgPanel.append("<div class=\"from upperline\">" + (msgs[0].length > 200 ? msgs[0].substring(0, 200) + "..." : msgs[0]) + "</div>");
  180. msgPanel.append("<div class=\"separline sprite\"></div>");
  181. msgPanel.append("<div class=\"from upperline\">" + msgs[1] + "</div>");
  182. } else {
  183. msgPanel.append("<div class=\"separline sprite\"></div>");
  184. msgPanel.append("<div class=\"from upperline\">" + msgs[0] + "</div>");
  185. }
  186. } else {
  187. if (msgs.length == 2) {
  188. msgPanel.append("<div class=\"from\">" + msgs[0] + "</div>");
  189. if (inverse) {
  190. msgPanel.append("<div class=\"separ inverse sprite\"></div>");
  191. } else {
  192. msgPanel.append("<div class=\"separ sprite\"></div>");
  193. }
  194. msgPanel.append("<div class=\"from\">" + msgs[1] + "</div>");
  195. } else {
  196. msgPanel.append("<div class=\"from\">" + msgs[0] + "</div>");
  197. }
  198. }
  199. /*
  200. * msgPanel.css({ left : $('body').scrollLeft(), top : $('body').scrollTop() + $(window).height() - msgPanel.height(), zIndex : 99999999 });
  201. */
  202. msgPanel.css({
  203. left : 0,
  204. top : $(window).height() - msgPanel.height(),
  205. position : 'fixed',
  206. zIndex : 99999999
  207. });
  208. msgPanel.show();
  209. }
  210. },
  211. queryConsole : function(action, toLog) {
  212. var id = MD5(toLog.uriId);
  213. var localId = MD5(toLog.id);
  214. var infoMap = globalInfoPanelMap;
  215. var panel = infoMap[id];
  216. if (action == 'init') {
  217. panel = $('<div id="q' + id + '" class="queryConsole"></div>');
  218. infoMap[id] = panel;
  219. globalInfoPanelMap = infoMap;
  220. } else if (action == 'log') {
  221. if (toLog.resource) {
  222. panel.append('<h3 class="sprite"><span>' + toLog.resource + '</span><a class="sprite">&#160;</a></h3>');
  223. panel.children("h3").children("a").click(function() {
  224. methods.queryConsole('close', {
  225. uriId : toLog.uriId
  226. });
  227. }).hover(function() {
  228. $(this).setBackgroundPosition({
  229. x : -641
  230. });
  231. }, function() {
  232. $(this).setBackgroundPosition({
  233. x : -611
  234. });
  235. });
  236. }
  237. if (panel) {
  238. if (toLog.title) {
  239. var h4 = $('<h4 class="t' + localId + ' sprite"><span>' + toLog.title + '</span></h4>');
  240. panel.append(h4);
  241. h4.hover(function() {
  242. $(this).setBackgroundPosition({
  243. y : -700
  244. });
  245. }, function() {
  246. $(this).setBackgroundPosition({
  247. y : -650
  248. });
  249. });
  250. h4.click(function() {
  251. if ($(this).data('show')) {
  252. $(this).data('show', false);
  253. $(this).setBackgroundPosition({
  254. x : -680
  255. });
  256. $(this).removeClass('slideOpen');
  257. $(this).next('div').slideToggle();
  258. } else {
  259. $(this).data('show', true);
  260. $(this).setBackgroundPosition({
  261. x : -1290
  262. });
  263. panel.find('.slideOpen').click();
  264. $(this).addClass('slideOpen');
  265. $(this).next('div').slideToggle();
  266. }
  267. });
  268. }
  269. if (toLog.text) {
  270. var aDiv = $('<div><span><span class="contentArea">' + (toLog.text).replace(/</gi, "&lt;").replace(/>/gi, "&gt;") + '</span></span></div>');
  271. var aEndpoint = $.trim(panel.find('h4.t' + localId).clone().find('strong').remove().end().text());
  272. if (aEndpoint.indexOf("http:") == 0) {
  273. var aLink = $('<span class="linkArea sprite" title="' + lang('executeThisQuery') + '"></span>');
  274. aLink.click(function() {
  275. window.open(aEndpoint + '?query=' + encodeURIComponent(toLog.text));
  276. });
  277. aLink.hover(function() {
  278. $(this).setBackgroundPosition({
  279. x : -630
  280. });
  281. }, function() {
  282. $(this).setBackgroundPosition({
  283. x : -610
  284. });
  285. });
  286. aDiv.children('span').prepend(aLink);
  287. }
  288. aDiv.css({
  289. opacity : 0.95
  290. });
  291. panel.append(aDiv);
  292. }
  293. if (toLog.error) {
  294. panel.find('h4.t' + localId + ' > span').append('<strong style="float:right">' + lang('enpointNotAvailable') + '</strong>');
  295. }
  296. if ( typeof toLog.founded == typeof 0) {
  297. if (toLog.founded == 0) {
  298. panel.find('h4.t' + localId + ' > span').append('<strong style="float:right">' + lang('propsNotFound') + '</strong>');
  299. } else {
  300. panel.find('h4.t' + localId + ' > span').append('<strong style="float:right">' + toLog.founded + ' ' + lang('propsFound') + ' </strong>');
  301. }
  302. }
  303. infoMap[id] = panel;
  304. globalInfoPanelMap = infoMap;
  305. }
  306. } else if (action == 'remove') {
  307. delete infoMap[id];
  308. globalInfoPanelMap = infoMap;
  309. } else if (action == 'show') {
  310. // panel.show();
  311. context.append(panel);
  312. } else if (action == 'close') {
  313. panel.detach();
  314. }
  315. },
  316. controlPanel : function(action) {
  317. if (debugOn) {
  318. start = new Date().getTime();
  319. }
  320. // pannello di controllo dell'applicazione
  321. var panel = $('#controlPanel');
  322. if (action == 'init') {
  323. panel = $('<div id="controlPanel"></div>');
  324. panel.css({
  325. left : 0,
  326. top : 10,
  327. position : 'fixed',
  328. zIndex : 999
  329. });
  330. panel.append('<div class="panel options sprite" ></div>');
  331. panel.append('<div class="panel legend sprite" ></div>');
  332. panel.append('<div class="panel help sprite" ></div>');
  333. panel.append('<div class="panel" ></div>');
  334. panel.append('<div class="panel2 maps sprite" ></div>');
  335. panel.append('<div class="panel2 images sprite" ></div>');
  336. panel.children('.panel,.panel2').hover(function() {
  337. $(this).setBackgroundPosition({
  338. y : -450
  339. });
  340. }, function() {
  341. $(this).setBackgroundPosition({
  342. y : -400
  343. });
  344. });
  345. context.append(panel);
  346. panel.attr("data-top", panel.position().top);
  347. panel.children('.panel').click(function() {
  348. panel.children('.panel,.panel2').hide();
  349. var close = $('<div class="panel close sprite" ></div>');
  350. close.click(function() {
  351. $(this).remove();
  352. panel.children('#panelContent').remove();
  353. panel.removeClass("justX");
  354. panel.children('.panel,.panel2').show();
  355. panel.children('.inactive').hide();
  356. });
  357. close.hover(function() {
  358. $(this).setBackgroundPosition({
  359. y : -550
  360. });
  361. }, function() {
  362. $(this).setBackgroundPosition({
  363. y : -500
  364. });
  365. });
  366. panel.append(close);
  367. close.css({
  368. position : 'absolute',
  369. left : 241,
  370. top : 0
  371. });
  372. var panelContent = $('<div id="panelContent"></div>');
  373. panel.append(panelContent);
  374. if ($(this).hasClass("options")) {
  375. var anUl = $('<ul class="optionsList"></ul>');
  376. panelContent.append('<div></div>');
  377. panelContent.children('div').append('<h2>' + lang('options') + '</h2>').append(anUl);
  378. anUl.append('<li ' + ($.jStorage.get('doInverse') ? 'class="checked"' : 'class="check"') + ' data-value="inverse" ><span class="spriteLegenda"></span>' + lang('generateInverse') + '</li>');
  379. anUl.append('<li ' + ($.jStorage.get('doAutoExpand') ? 'class="checked"' : 'class="check"') + ' data-value="autoExpand" ><span class="spriteLegenda"></span>' + lang('autoExpand') + '</li>');
  380. anUl.append('<li ' + ($.jStorage.get('doAutoSameas') ? 'class="checked"' : 'class="check"') + ' data-value="autoSameas"><span class="spriteLegenda"></span>' + lang('autoSameAs') + '</li>');
  381. anUl.append('<li ' + ($.jStorage.get('doCollectImages') ? 'class="checked"' : 'class="check"') + ' data-value="autoCollectImages"><span class="spriteLegenda"></span>' + lang('autoCollectImages') + '</li>');
  382. anUl.append('<li ' + ($.jStorage.get('doDrawMap') ? 'class="checked"' : 'class="check"') + ' data-value="autoDrawMap"><span class="spriteLegenda"></span>' + lang('autoDrawMap') + '</li>');
  383. anUl.append('<li>&#160;</li>');
  384. anUl.append('<li class="reload"><span class="spriteLegenda"></span>' + lang('restart') + '</li>');
  385. anUl.children('.reload').click(function() {
  386. context.lodlive('close');
  387. });
  388. anUl.children('li[data-value]').click(function() {
  389. if ($(this).hasClass('check')) {
  390. if ($(this).attr("data-value") == 'inverse') {
  391. $.jStorage.set('doInverse', true);
  392. } else if ($(this).attr("data-value") == 'autoExpand') {
  393. $.jStorage.set('doAutoExpand', true);
  394. } else if ($(this).attr("data-value") == 'autoSameas') {
  395. $.jStorage.set('doAutoSameas', true);
  396. } else if ($(this).attr("data-value") == 'autoCollectImages') {
  397. $.jStorage.set('doCollectImages', true);
  398. panel.children('div.panel2.images').removeClass('inactive');
  399. } else if ($(this).attr("data-value") == 'autoDrawMap') {
  400. $.jStorage.set('doDrawMap', true);
  401. panel.children('div.panel2.maps').removeClass('inactive');
  402. }
  403. $(this).attr('class', "checked");
  404. } else {
  405. if ($(this).attr("data-value") == 'inverse') {
  406. $.jStorage.set('doInverse', false);
  407. } else if ($(this).attr("data-value") == 'autoExpand') {
  408. $.jStorage.set('doAutoExpand', false);
  409. } else if ($(this).attr("data-value") == 'autoSameas') {
  410. $.jStorage.set('doAutoSameas', false);
  411. } else if ($(this).attr("data-value") == 'autoCollectImages') {
  412. $.jStorage.set('doCollectImages', false);
  413. panel.children('div.panel2.images').addClass('inactive');
  414. } else if ($(this).attr("data-value") == 'autoDrawMap') {
  415. panel.children('div.panel2.maps').addClass('inactive');
  416. $.jStorage.set('doDrawMap', false);
  417. }
  418. $(this).attr('class', "check");
  419. }
  420. });
  421. } else if ($(this).hasClass("help")) {
  422. var help = $('.help').children('div').clone();
  423. $('.videoHelp', help).fancybox({
  424. 'transitionIn' : 'elastic',
  425. 'transitionOut' : 'elastic',
  426. 'speedIn' : 400,
  427. 'type' : 'iframe',
  428. 'width' : 853,
  429. 'height' : 480,
  430. 'speedOut' : 200,
  431. 'hideOnContentClick' : false,
  432. 'showCloseButton' : true,
  433. 'overlayShow' : false
  434. });
  435. panelContent.append(help);
  436. if (help.height() > $(window).height() + 10) {
  437. panel.addClass("justX");
  438. }
  439. } else if ($(this).hasClass("legend")) {
  440. var legend = $('.legenda').children('div').clone();
  441. var counter = 0;
  442. legend.find("span.spriteLegenda").each(function() {
  443. $(this).css({
  444. 'background-position' : '-1px -' + (counter * 20) + 'px'
  445. });
  446. counter++;
  447. });
  448. panelContent.append(legend);
  449. if (legend.height() > $(window).height() + 10) {
  450. panel.addClass("justX");
  451. }
  452. }
  453. });
  454. if (!$.jStorage.get('doCollectImages', true)) {
  455. panel.children('div.panel2.images').addClass('inactive').hide();
  456. }
  457. if (!$.jStorage.get('doDrawMap', true)) {
  458. panel.children('div.panel2.maps').addClass('inactive').hide();
  459. }
  460. panel.children('.panel2').click(function() {
  461. panel.children('.panel,.panel2').hide();
  462. var close = $('<div class="panel close2 sprite" ></div>');
  463. close.click(function() {
  464. $(this).remove();
  465. $('#mapPanel', panel).hide();
  466. $('#imagePanel', panel).hide();
  467. panelContent.hide();
  468. panel.removeClass("justX");
  469. panel.children('.panel,.panel2').show();
  470. panel.children('.inactive').hide();
  471. });
  472. close.hover(function() {
  473. $(this).setBackgroundPosition({
  474. y : -550
  475. });
  476. }, function() {
  477. $(this).setBackgroundPosition({
  478. y : -500
  479. });
  480. });
  481. panel.append(close);
  482. var panelContent = $('#panel2Content', panel);
  483. if (panelContent.length == 0) {
  484. panelContent = $('<div id="panel2Content"></div>');
  485. panel.append(panelContent);
  486. } else {
  487. panelContent.show();
  488. }
  489. if ($(this).hasClass("maps")) {
  490. var mapPanel = $('#mapPanel');
  491. if (mapPanel.length == 0) {
  492. mapPanel = $('<div id="mapPanel"></div>');
  493. panelContent.width(800);
  494. panelContent.append(mapPanel);
  495. $('#mapPanel').gmap3({
  496. action : 'init',
  497. options : {
  498. zoom : 2,
  499. mapTypeId : google.maps.MapTypeId.HYBRID
  500. }
  501. });
  502. } else {
  503. mapPanel.show();
  504. }
  505. methods.updateMapPanel(panel);
  506. } else if ($(this).hasClass("images")) {
  507. var imagePanel = $('#imagePanel');
  508. if (imagePanel.length == 0) {
  509. imagePanel = $('<div id="imagePanel"><span id="imgesCnt"></span></div>');
  510. panelContent.append(imagePanel);
  511. } else {
  512. imagePanel.show();
  513. }
  514. methods.updateImagePanel(panel);
  515. }
  516. });
  517. } else if (action == 'show') {
  518. } else if (action == 'hide') {
  519. } else if (action == 'move') {
  520. if (panel.hasClass("justX")) {
  521. panel.css({
  522. position : 'absolute',
  523. left : $('body').scrollLeft(),
  524. top : panel.attr("data-top")
  525. });
  526. } else {
  527. panel.css({
  528. left : 0,
  529. top : 10,
  530. position : 'fixed'
  531. });
  532. if (panel.position()) {
  533. panel.attr("data-top", panel.position().top);
  534. }
  535. }
  536. }
  537. if (debugOn) {
  538. console.debug((new Date().getTime() - start) + ' controlPanel ');
  539. }
  540. },
  541. updateMapPanel : function(panel) {
  542. if ($.jStorage.get('doDrawMap', true)) {
  543. if ($("#mapPanel:visible", panel).length > 0) {
  544. $('#mapPanel').gmap3({
  545. action : 'clear'
  546. });
  547. var panelContent = $('#panel2Content', panel);
  548. panelContent.width(800);
  549. var close = $('.close2', panel);
  550. var mapsMap = $.jStorage.get('mapsMap');
  551. var mapSize = 0;
  552. for (var prop in mapsMap) {
  553. if (mapsMap.hasOwnProperty(prop)) {
  554. mapSize++;
  555. }
  556. }
  557. for (var prop in mapsMap) {
  558. if (mapsMap.hasOwnProperty(prop)) {
  559. $('#mapPanel').gmap3({
  560. action : 'addMarker',
  561. latLng : [mapsMap[prop].lats, mapsMap[prop].longs],
  562. title : unescape(mapsMap[prop].title)
  563. }, mapSize > 1 ? {
  564. action : "autofit"
  565. } : {});
  566. }
  567. }
  568. close.css({
  569. position : 'absolute',
  570. left : panelContent.width() + 1,
  571. top : 0
  572. });
  573. } else {
  574. methods.highlight(panel.children('.maps'), 2, 200, '-565px -450px');
  575. }
  576. }
  577. },
  578. updateImagePanel : function(panel) {
  579. if ($.jStorage.get('doCollectImages', true)) {
  580. var imagePanel = $('#imagePanel', panel).children("span");
  581. if ($("#imagePanel:visible", panel).length > 0) {
  582. var panelContent = $('#panel2Content', panel);
  583. var close = $('.close2', panel);
  584. var imageMap = $.jStorage.get('imagesMap');
  585. var mapSize = 0;
  586. for (var prop in imageMap) {
  587. if (imageMap.hasOwnProperty(prop)) {
  588. mapSize++;
  589. }
  590. }
  591. if (mapSize > 0) {
  592. imagePanel.children('.amsg').remove();
  593. var counter = 0;
  594. for (var prop in imageMap) {
  595. if (imageMap.hasOwnProperty(prop)) {
  596. for (var a = 0; a < imageMap[prop].length; a++) {
  597. for (var key in imageMap[prop][a]) {
  598. if (($.jStorage.get('noImagesMap', {})[prop + counter])) {
  599. counter--;
  600. } else if (imagePanel.children('.img-' + prop + '-' + counter).length == 0) {
  601. var img = $('<a href="' + unescape(key) + '" class="sprite relatedImage img-' + prop + '-' + counter + '"><img rel="' + unescape(imageMap[prop][a][key]) + '" src="' + unescape(key) + '"/></a>"');
  602. img.attr("data-prop", prop);
  603. imagePanel.prepend(img);
  604. img.fancybox({
  605. 'transitionIn' : 'elastic',
  606. 'transitionOut' : 'elastic',
  607. 'speedIn' : 400,
  608. 'type' : 'image',
  609. 'speedOut' : 200,
  610. 'hideOnContentClick' : true,
  611. 'showCloseButton' : false,
  612. 'overlayShow' : false
  613. });
  614. img.children('img').error(function() {
  615. $(this).parent().remove();
  616. counter--;
  617. if (counter < 3) {
  618. panelContent.width(148);
  619. } else {
  620. var tot = (counter / 3 + (counter % 3 > 0 ? 1 : 0) + '').split('.')[0];
  621. if (tot > 7) {
  622. tot = 7;
  623. }
  624. panelContent.width(20 + (tot) * 128);
  625. }
  626. close.css({
  627. position : 'absolute',
  628. left : panelContent.width() + 1,
  629. top : 0
  630. });
  631. var noImage = $.jStorage.get('noImagesMap', {});
  632. noImage[prop + counter] = true;
  633. $.jStorage.set('noImagesMap', noImage);
  634. close.css({
  635. position : 'absolute',
  636. left : panelContent.width() + 1,
  637. top : 0
  638. });
  639. });
  640. img.children('img').load(function() {
  641. var titolo = $(this).attr('rel');
  642. if ($(this).width() < $(this).height()) {
  643. $(this).height($(this).height() * 113 / $(this).width());
  644. $(this).width(113);
  645. } else {
  646. $(this).css({
  647. width : $(this).width() * 113 / $(this).height(),
  648. height : 113,
  649. marginLeft : -(($(this).width() * 113 / $(this).height() - 113) / 2)
  650. });
  651. }
  652. var controls = $('<span class="imgControls"><span class="imgControlCenter" title="' + lang('showResource') + '"></span><span class="imgControlZoom" title="' + lang('zoomIn') + '"></span><span class="imgTitle">' + titolo + '</span></span>');
  653. $(this).parent().append(controls);
  654. $(this).parent().hover(function() {
  655. $(this).children('img').hide();
  656. }, function() {
  657. $(this).children('img').show();
  658. });
  659. controls.children('.imgControlZoom').hover(function() {
  660. $(this).parent().parent().setBackgroundPosition({
  661. x : -1955
  662. });
  663. }, function() {
  664. $(this).parent().parent().setBackgroundPosition({
  665. x : -1825
  666. });
  667. });
  668. controls.children('.imgControlCenter').hover(function() {
  669. $(this).parent().parent().setBackgroundPosition({
  670. x : -2085
  671. });
  672. }, function() {
  673. $(this).parent().parent().setBackgroundPosition({
  674. x : -1825
  675. });
  676. });
  677. controls.children('.imgControlCenter').click(function() {
  678. $('.close2', panel).click();
  679. methods.highlight($('#' + $(this).parent().parent().attr("data-prop")).children('.box'), 8, 100, '0 0');
  680. // -390px
  681. return false;
  682. });
  683. if (counter < 3) {
  684. panelContent.width(148);
  685. } else {
  686. var tot = (counter / 3 + (counter % 3 > 0 ? 1 : 0) + '').split('.')[0];
  687. if (tot > 7) {
  688. tot = 7;
  689. }
  690. panelContent.width(20 + (tot) * 128);
  691. close.css({
  692. position : 'absolute',
  693. left : panelContent.width() + 1,
  694. top : 0
  695. });
  696. }
  697. });
  698. }
  699. counter++;
  700. }
  701. }
  702. }
  703. }
  704. } else {
  705. panelContent.width(148);
  706. if (imagePanel.children('.amsg').length == 0) {
  707. imagePanel.append('<span class="amsg">' + lang('imagesNotFound') + '</span>');
  708. }
  709. }
  710. close.css({
  711. position : 'absolute',
  712. left : panelContent.width() + 1,
  713. top : 0
  714. });
  715. } else {
  716. methods.highlight(panel.children('.images'), 2, 200, '-610px -450px');
  717. }
  718. }
  719. },
  720. highlight : function(object, times, speed, backmove) {
  721. if (times > 0) {
  722. times--;
  723. var css = object.css('background-position');
  724. object.doTimeout(speed, function() {
  725. object.css({
  726. 'background-position' : backmove
  727. });
  728. object.doTimeout(speed, function() {
  729. object.css({
  730. 'background-position' : css
  731. });
  732. methods.highlight(object, times, speed, backmove);
  733. });
  734. });
  735. }
  736. },
  737. renewDrag : function(aDivList) {
  738. if (debugOn) {
  739. start = new Date().getTime();
  740. }
  741. aDivList.each(function() {
  742. if ($(this).attr("class").indexOf('ui-draggable') == -1) {
  743. $(this).draggable({
  744. // handle:'.boxTitle',
  745. stack : '.boxWrapper',
  746. containment : "parent",
  747. start : function() {
  748. $(".toolBox").remove();
  749. $('#line-' + $(this).attr("id")).clearCanvas();
  750. var generatedRev = $.jStorage.get('storeIds-generatedByRev-' + $(this).attr("id"));
  751. if (generatedRev) {
  752. for (var a = 0; a < generatedRev.length; a++) {
  753. generated = $.jStorage.get('storeIds-generatedBy-' + generatedRev[a]);
  754. $('#line-' + generatedRev[a]).clearCanvas();
  755. }
  756. }
  757. },
  758. drag : function(event, ui) {
  759. },
  760. stop : function(event, ui) {
  761. methods.drawAllLines($(this));
  762. }
  763. });
  764. }
  765. });
  766. if (debugOn) {
  767. console.debug((new Date().getTime() - start) + ' renewDrag ');
  768. }
  769. },
  770. centerBox : function(aBox) {
  771. if (debugOn) {
  772. start = new Date().getTime();
  773. }
  774. var top = ($(context).height() - 65) / 2 + ($(context).scrollTop() || 0);
  775. var left = ($(context).width() - 65) / 2 + ($(context).scrollLeft() || 0);
  776. var props = {
  777. position : 'absolute',
  778. left : left,
  779. top : top
  780. };
  781. window.scrollBy(-context.width(), -context.height());
  782. window.scrollBy($(context).width() / 2 - $(window).width() / 2 + 25, $(context).height() / 2 - $(window).height() / 2 + 65);
  783. try {
  784. aBox.animate(props, 1000);
  785. } catch (e) {
  786. aBox.css(props);
  787. }
  788. if (debugOn) {
  789. console.debug((new Date().getTime() - start) + ' centerBox ');
  790. }
  791. },
  792. autoExpand : function(obj) {
  793. if (debugOn) {
  794. start = new Date().getTime();
  795. }
  796. $.each(globalInnerPageMap, function(key, element) {
  797. if (element.children(".relatedBox:not([class*=exploded])").length > 0) {
  798. if (element.parent().length == 0) {
  799. context.append(element);
  800. }
  801. element.children(".relatedBox:not([class*=exploded])").each(function() {
  802. var aId = $(this).attr("relmd5");
  803. var newObj = context.children('#' + aId);
  804. if (newObj.length > 0) {
  805. $(this).click();
  806. }
  807. });
  808. context.children('.innerPage').detach();
  809. }
  810. });
  811. context.find(".relatedBox:not([class*=exploded])").each(function() {
  812. var aId = $(this).attr("relmd5");
  813. var newObj = context.children('#' + aId);
  814. if (newObj.length > 0) {
  815. $(this).click();
  816. }
  817. });
  818. if (debugOn) {
  819. console.debug((new Date().getTime() - start) + ' autoExpand ');
  820. }
  821. },
  822. addNewDoc : function(obj, ele, callback) {
  823. if (debugOn) {
  824. start = new Date().getTime();
  825. }
  826. var aId = ele.attr("relmd5");
  827. var newObj = context.find('#' + aId);
  828. var isInverse = ele.attr("class").indexOf("inverse") != -1;
  829. var exist = true;
  830. // verifico se esistono box rappresentativi dello stesso documento
  831. // nella pagina
  832. if (newObj.length == 0) {
  833. newObj = $($.jStorage.get('boxTemplate'));
  834. exist = false;
  835. }
  836. var originalCircus = $("#" + ele.attr("data-circleId"));
  837. if (debugOn) {
  838. console.debug((new Date().getTime() - start) + ' addNewDoc 01 ');
  839. }
  840. if (!isInverse) {
  841. if (debugOn) {
  842. console.debug((new Date().getTime() - start) + ' addNewDoc 02 ');
  843. }
  844. var connected = $.jStorage.get('storeIds-generatedBy-' + originalCircus.attr("id"));
  845. if (!connected) {
  846. connected = [aId];
  847. } else {
  848. if ($.inArray(aId, connected) == -1) {
  849. connected.push(aId);
  850. } else {
  851. return;
  852. }
  853. }
  854. if (debugOn) {
  855. console.debug((new Date().getTime() - start) + ' addNewDoc 03 ');
  856. }
  857. $.jStorage.set('storeIds-generatedBy-' + originalCircus.attr("id"), connected);
  858. connected = $.jStorage.get('storeIds-generatedByRev-' + aId);
  859. if (!connected) {
  860. connected = [originalCircus.attr("id")];
  861. } else {
  862. if ($.inArray(originalCircus.attr("id"), connected) == -1) {
  863. connected.push(originalCircus.attr("id"));
  864. }
  865. }
  866. if (debugOn) {
  867. console.debug((new Date().getTime() - start) + ' addNewDoc 04 ');
  868. }
  869. $.jStorage.set('storeIds-generatedByRev-' + aId, connected);
  870. }
  871. var propertyName = ele.attr("data-property");
  872. newObj.attr("id", aId);
  873. newObj.attr("rel", ele.attr("rel"));
  874. var fromInverse = isInverse ? 'div[data-property="' + ele.attr("data-property") + '"][rel="' + obj.attr("rel") + '"]' : null;
  875. if (debugOn) {
  876. console.debug((new Date().getTime() - start) + ' addNewDoc 05 ');
  877. }
  878. // nascondo l'oggetto del click e carico la risorsa successiva
  879. $(ele).hide();
  880. if (!exist) {
  881. if (debugOn) {
  882. console.debug((new Date().getTime() - start) + ' addNewDoc 06 ');
  883. }
  884. var pos = parseInt(ele.attr("data-circlePos"), 10);
  885. var parts = parseInt(ele.attr("data-circleParts"), 10);
  886. // var chordsListExpand = this.lodlive('circleChords',
  887. // ele.attr("data-circleParts") > 10 ? (pos % 2 > 0 ?
  888. // originalCircus.width() * 3 : originalCircus.width() * 2) :
  889. // originalCircus.width() * 5 / 2,
  890. // parseInt(ele.attr("data-circleParts"), 10) + 4,
  891. // originalCircus.position().left + obj.width() / 2,
  892. // originalCircus.position().top + originalCircus.height() / 2,
  893. // pos + 1);
  894. var chordsListExpand = methods.circleChords(parts > 10 ? (pos % 2 > 0 ? originalCircus.width() * 3 : originalCircus.width() * 2) : originalCircus.width() * 5 / 2, parts, originalCircus.position().left + obj.width() / 2, originalCircus.position().top + originalCircus.height() / 2, null, pos);
  895. context.append(newObj);
  896. /*
  897. * newObj.css({ "left" : originalCircus.position().left + originalCircus.width() / 2 - newObj.width() / 2, "top" : originalCircus.position().top +
  898. * originalCircus.height() / 2 - newObj.height() / 2, "opacity" : 0.1, "zIndex" : 99 });
  899. */
  900. newObj.css({
  901. "left" : (chordsListExpand[0][0] - newObj.height() / 2),
  902. "top" : (chordsListExpand[0][1] - newObj.width() / 2),
  903. "opacity" : 1,
  904. "zIndex" : 99
  905. });
  906. /*
  907. * newObj.animate({ "left" : (chordsListExpand[pos][0] - newObj.height() / 2), "top" : (chordsListExpand[pos][1] - newObj.width() / 2), "opacity" : 1 }, 400, '',
  908. * function() {
  909. */
  910. methods.renewDrag(context.children('.boxWrapper'));
  911. if (debugOn) {
  912. console.debug((new Date().getTime() - start) + ' addNewDoc 07 ');
  913. }
  914. if (!isInverse) {
  915. if (debugOn) {
  916. console.debug((new Date().getTime() - start) + ' addNewDoc 08 ');
  917. }
  918. if ($.jStorage.get('doInverse')) {
  919. methods.openDoc($(ele).attr("rel"), newObj, fromInverse);
  920. } else {
  921. methods.openDoc($(ele).attr("rel"), newObj);
  922. }
  923. methods.drawaLine(obj, newObj, propertyName);
  924. } else {
  925. if (debugOn) {
  926. console.debug((new Date().getTime() - start) + ' addNewDoc 09 ');
  927. }
  928. methods.openDoc($(ele).attr("rel"), newObj, fromInverse);
  929. }
  930. // });
  931. } else {
  932. if (!isInverse) {
  933. if (debugOn) {
  934. console.debug((new Date().getTime() - start) + ' addNewDoc 10 ');
  935. }
  936. methods.renewDrag(context.children('.boxWrapper'));
  937. methods.drawaLine(obj, newObj, propertyName);
  938. } else {
  939. if (debugOn) {
  940. console.debug((new Date().getTime() - start) + ' addNewDoc 11 ');
  941. }
  942. try {
  943. // $(fromInverse).click();
  944. } catch (e) {
  945. }
  946. }
  947. }
  948. if (callback) {
  949. callback();
  950. }
  951. if (debugOn) {
  952. console.debug((new Date().getTime() - start) + ' addNewDoc ');
  953. }
  954. return false;
  955. },
  956. removeDoc : function(obj, callback) {
  957. if (debugOn) {
  958. start = new Date().getTime();
  959. }
  960. $(".toolBox").remove();
  961. // $(".tipsy").remove();
  962. var id = obj.attr("id");
  963. methods.queryConsole('remove', {
  964. uriId : obj.attr('rel')
  965. });
  966. $("#line-" + id).clearCanvas();
  967. var generatedRev = $.jStorage.get('storeIds-generatedByRev-' + id);
  968. if (generatedRev) {
  969. for (var a = 0; a < generatedRev.length; a++) {
  970. $('#line-' + generatedRev[a]).clearCanvas();
  971. }
  972. }
  973. methods.docInfo('', 'close');
  974. if ($.jStorage.get('doCollectImages', true)) {
  975. var imagesMap = $.jStorage.get("imagesMap", {});
  976. if (imagesMap[id]) {
  977. delete imagesMap[id];
  978. $.jStorage.set('imagesMap', imagesMap);
  979. methods.updateImagePanel($('#controlPanel'));
  980. $('#controlPanel').find('a[class*=img-' + id + ']').remove();
  981. }
  982. }
  983. if ($.jStorage.get('doDrawMap', true)) {
  984. var mapsMap = $.jStorage.get("mapsMap", {});
  985. if (mapsMap[id]) {
  986. delete mapsMap[id];
  987. $.jStorage.set('mapsMap', mapsMap);
  988. methods.updateMapPanel($('#controlPanel'));
  989. // $('#controlPanel').find('a[class*=img-' + id +
  990. // ']').remove();
  991. }
  992. }
  993. obj.fadeOut('normal', null, function() {
  994. obj.remove();
  995. $.each(globalInnerPageMap, function(key, element) {
  996. if (element.children("." + id).length > 0) {
  997. $('#' + key).append(element);
  998. }
  999. });
  1000. $("." + id).each(function() {
  1001. $(this).show();
  1002. $(this).removeClass("exploded");
  1003. });
  1004. $.each(globalInnerPageMap, function(key, element) {
  1005. if (element.children("." + id).length > 0) {
  1006. var lastClick = $('#' + key).find('.lastClick').attr("rel");
  1007. if ($('#' + key).children('.innerPage').children('.' + lastClick).length == 0) {
  1008. $('#' + key).children('.innerPage').detach();
  1009. }
  1010. }
  1011. });
  1012. // $('#'+id).children('.innerPage').detach();
  1013. var generated = $.jStorage.get('storeIds-generatedBy-' + id);
  1014. var generatedRev = $.jStorage.get('storeIds-generatedByRev-' + id);
  1015. if (generatedRev) {
  1016. for (var int = 0; int < generatedRev.length; int++) {
  1017. var generatedBy = $.jStorage.get('storeIds-generatedBy-' + generatedRev[int]);
  1018. if (generatedBy) {
  1019. for (var int2 = 0; int2 < generatedBy.length; int2++) {
  1020. if (generatedBy[int2] == id) {
  1021. generatedBy.splice(int2, 1);
  1022. }
  1023. }
  1024. }
  1025. $.jStorage.set('storeIds-generatedBy-' + generatedRev[int], generatedBy);
  1026. }
  1027. }
  1028. if (generated) {
  1029. for (var int = 0; int < generated.length; int++) {
  1030. var generatedBy = $.jStorage.get('storeIds-generatedByRev-' + generated[int]);
  1031. if (generatedBy) {
  1032. for (var int2 = 0; int2 < generatedBy.length; int2++) {
  1033. if (generatedBy[int2] == id) {
  1034. generatedBy.splice(int2, 1);
  1035. }
  1036. }
  1037. }
  1038. $.jStorage.set('storeIds-generatedByRev-' + generated[int], generatedBy);
  1039. }
  1040. }
  1041. generatedRev = $.jStorage.get('storeIds-generatedByRev-' + id);
  1042. if (generatedRev) {
  1043. for (var a = 0; a < generatedRev.length; a++) {
  1044. generated = $.jStorage.get('storeIds-generatedBy-' + generatedRev[a]);
  1045. if (generated) {
  1046. for (var a2 = 0; a2 < generated.length; a2++) {
  1047. methods.drawaLine($('#' + generatedRev[a]), $("#" + generated[a2]));
  1048. }
  1049. }
  1050. }
  1051. }
  1052. $.jStorage.set('storeIds-generatedByRev-' + id, []);
  1053. $.jStorage.set('storeIds-generatedBy-' + id, []);
  1054. });
  1055. if (debugOn) {
  1056. console.debug((new Date().getTime() - start) + ' removeDoc ');
  1057. }
  1058. },
  1059. addClick : function(obj, callback) {
  1060. if (debugOn) {
  1061. start = new Date().getTime();
  1062. }
  1063. // per ogni nuova risorsa collegata al documento corrente imposto le
  1064. // azioni "onclick"
  1065. obj.find("div.relatedBox").each(function() {
  1066. $(this).attr("relmd5", MD5($(this).attr("rel")));
  1067. $(this).click(function() {
  1068. $(this).addClass("exploded");
  1069. methods.addNewDoc(obj, $(this));
  1070. // methods.docInfo('', 'close');
  1071. return false;
  1072. });
  1073. $(this).hover(function() {
  1074. methods.msg($(this).attr('data-title'), 'show', null, null, $(this).hasClass("inverse"));
  1075. }, function() {
  1076. methods.msg(null, 'hide');
  1077. });
  1078. });
  1079. obj.find(".groupedRelatedBox").each(function() {
  1080. $(this).click(function() {
  1081. if ($(this).data('show')) {
  1082. $(this).data('show', false);
  1083. methods.docInfo('', 'close');
  1084. $(this).removeClass('lastClick');
  1085. obj.find("." + $(this).attr("rel")).fadeOut('fast');
  1086. $(this).fadeTo('fast', 1);
  1087. obj.children('.innerPage').detach();
  1088. } else {
  1089. $(this).data('show', true);
  1090. obj.append(globalInnerPageMap[obj.attr("id")]);
  1091. methods.docInfo('', 'close');
  1092. obj.find('.lastClick').removeClass('lastClick').click();
  1093. if (obj.children('.innerPage').length == 0) {
  1094. obj.append(globalInnerPageMap[obj.attr("id")]);
  1095. }
  1096. $(this).addClass('lastClick');
  1097. obj.find("." + $(this).attr("rel") + ":not([class*=exploded])").fadeIn('fast');
  1098. $(this).fadeTo('fast', 0.3);
  1099. }
  1100. });
  1101. $(this).hover(function() {
  1102. methods.msg($(this).attr('data-title'), 'show', null, null, $(this).hasClass("inverse"));
  1103. }, function() {
  1104. methods.msg(null, 'hide');
  1105. });
  1106. });
  1107. globalInnerPageMap[obj.attr("id")] = obj.children('.innerPage');
  1108. obj.children('.innerPage').detach();
  1109. // aggiungo le azioni dei tools
  1110. obj.find(".actionBox[rel=contents]").click(function() {
  1111. methods.docInfo(obj, 'open');
  1112. });
  1113. obj.find(".actionBox[rel=tools]").click(function() {
  1114. if ($(".toolBox:visible").length == 0) {
  1115. var pos = obj.position();
  1116. var tools = $("<div class=\"toolBox sprite\" style=\"display:none\" ><div class=\"innerActionBox infoQ\" rel=\"infoQ\" title=\"" + lang('moreInfoOnThis') + "\" >&#160;</div><div class=\"innerActionBox center\" rel=\"center\" title=\"" + lang('centerClose') + "\" >&#160;</div><div class=\"innerActionBox newpage\" rel=\"newpage\" title=\"" + lang('openOnline') + "\" >&#160;</div><div class=\"innerActionBox expand\" rel=\"expand\" title=\"" + lang('openRelated') + "\" >&#160;</div><div class=\"innerActionBox remove\" rel=\"remove\" title=\"" + lang('removeResource') + "\" >&#160;</div></div>");
  1117. context.append(tools);
  1118. tools.css({
  1119. top : pos.top - 23,
  1120. left : pos.left + 10
  1121. });
  1122. tools.fadeIn('fast');
  1123. tools.find(".innerActionBox[rel=expand]").each(function() {
  1124. $(this).click(function() {
  1125. tools.remove();
  1126. // $('.tipsy').remove();
  1127. methods.docInfo('', 'close');
  1128. var idx = 0;
  1129. var elements = obj.find("div.relatedBox:visible");
  1130. elements.doTimeout(250, function() {
  1131. var elem = this.eq(idx++);
  1132. if (elem.length) {
  1133. elem.trigger('click');
  1134. return true;
  1135. }
  1136. });
  1137. });
  1138. $(this).hover(function() {
  1139. tools.setBackgroundPosition({
  1140. y : -515
  1141. });
  1142. }, function() {
  1143. tools.setBackgroundPosition({
  1144. y : -395
  1145. });
  1146. });
  1147. });
  1148. tools.find(".innerActionBox[rel=infoQ]").each(function() {
  1149. $(this).click(function() {
  1150. tools.remove();
  1151. methods.queryConsole('show', {
  1152. uriId : obj.attr('rel')
  1153. });
  1154. });
  1155. $(this).hover(function() {
  1156. tools.setBackgroundPosition({
  1157. y : -425
  1158. });
  1159. }, function() {
  1160. tools.setBackgroundPosition({
  1161. y : -395
  1162. });
  1163. });
  1164. });
  1165. tools.find(".innerActionBox[rel=remove]").each(function() {
  1166. $(this).click(function() {
  1167. // $('.tipsy').remove();
  1168. methods.removeDoc(obj);
  1169. tools.remove();
  1170. methods.docInfo('', 'close');
  1171. });
  1172. $(this).hover(function() {
  1173. tools.setBackgroundPosition({
  1174. y : -545
  1175. });
  1176. }, function() {
  1177. tools.setBackgroundPosition({
  1178. y : -395
  1179. });
  1180. });
  1181. });
  1182. tools.find(".innerActionBox[rel=newpage]").each(function() {
  1183. $(this).click(function() {
  1184. tools.remove();
  1185. // $('.tipsy').remove();
  1186. methods.docInfo('', 'close');
  1187. window.open(obj.attr("rel"));
  1188. });
  1189. $(this).hover(function() {
  1190. $(this).parent().setBackgroundPosition({
  1191. y : -485
  1192. });
  1193. }, function() {
  1194. $(this).parent().setBackgroundPosition({
  1195. y : -395
  1196. });
  1197. });
  1198. });
  1199. tools.find(".innerActionBox[rel=center]").each(function() {
  1200. $(this).click(function() {
  1201. var loca = $(location).attr('href');
  1202. if (loca.indexOf('?http') != -1) {
  1203. document.location = loca.substring(0, loca.indexOf('?')) + '?' + obj.attr('rel');
  1204. }
  1205. });
  1206. $(this).hover(function() {
  1207. tools.setBackgroundPosition({
  1208. y : -455
  1209. });
  1210. }, function() {
  1211. tools.setBackgroundPosition({
  1212. y : -395
  1213. });
  1214. });
  1215. });
  1216. } else {
  1217. $(".toolBox").fadeOut('fast', null, function() {
  1218. $(".toolBox").remove();
  1219. });
  1220. }
  1221. });
  1222. if (callback) {
  1223. callback();
  1224. }
  1225. if (debugOn) {
  1226. console.debug((new Date().getTime() - start) + ' addClick ');
  1227. }
  1228. },
  1229. parseRawResourceDoc : function(destBox, URI) {
  1230. if (debugOn) {
  1231. start = new Date().getTime();
  1232. }
  1233. var uris = [];
  1234. var bnodes = [];
  1235. var values = [];
  1236. if (lodLiveProfile['default']) {
  1237. // attivo lo sparql interno basato su sesame
  1238. var res = getSparqlConf('document', lodLiveProfile['default'], lodLiveProfile).replace(/\{URI\}/ig, URI);
  1239. var url = lodLiveProfile['default'].endpoint + "?uri=" + encodeURIComponent(URI) + "&query=" + encodeURIComponent(res);
  1240. if ($.jStorage.get('showInfoConsole')) {
  1241. methods.queryConsole('log', {
  1242. title : lang('endpointNotConfiguredSoInternal'),
  1243. text : res,
  1244. uriId : URI
  1245. });
  1246. }
  1247. $.jsonp({
  1248. url : url,
  1249. beforeSend : function() {
  1250. $('body').append(destBox);
  1251. destBox.html('<img style=\"margin-left:' + (destBox.width() / 2) + 'px;margin-top:147px\" src="img/ajax-loader-gray.gif"/>');
  1252. destBox.css({
  1253. position : 'fixed',
  1254. left : $(window).width() - $('#docInfo').width() - 20,
  1255. top : 0
  1256. });
  1257. destBox.attr("data-top", destBox.position().top);
  1258. },
  1259. success : function(json) {
  1260. json = json['results']['bindings'];
  1261. $.each(json, function(key, value) {
  1262. if (value.object.type == 'uri') {
  1263. eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1264. } else if (value.object.type == 'bnode') {
  1265. eval('bnodes.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1266. } else {
  1267. eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1268. }
  1269. });
  1270. destBox.html('');
  1271. if (debugOn) {
  1272. console.debug(URI + ' ');
  1273. console.debug(values);
  1274. }
  1275. methods.formatDoc(destBox, values, uris, bnodes, URI);
  1276. },
  1277. error : function(e, b, v) {
  1278. destBox.html('');
  1279. values = [{
  1280. 'http://system/msg' : 'risorsa non trovata: ' + destBox.attr('rel')
  1281. }];
  1282. methods.formatDoc(destBox, values, uris, bnodes, URI);
  1283. }
  1284. });
  1285. }
  1286. if (debugOn) {
  1287. console.debug((new Date().getTime() - start) + ' parseRawResourceDoc ');
  1288. }
  1289. },
  1290. docInfo : function(obj, action) {
  1291. if (debugOn) {
  1292. start = new Date().getTime();
  1293. }
  1294. if (action == 'open') {
  1295. var URI = obj.attr('rel');
  1296. if ($('#docInfo').length > 0) {
  1297. $('#docInfo').fadeOut('fast', null, function() {
  1298. $('#docInfo').remove();
  1299. });
  1300. if ($('#docInfo[rel="info-' + URI + '"]').length > 0) {
  1301. return;
  1302. }
  1303. }
  1304. // predispongo il div contenente il documento
  1305. var destBox = $('<div id="docInfo" rel="info-' + URI + '"></div>');
  1306. $('body').append(destBox);
  1307. var SPARQLquery = methods.composeQuery(URI, 'document');
  1308. var uris = [];
  1309. var bnodes = [];
  1310. var values = [];
  1311. if (SPARQLquery.indexOf("http://system/dummy") == 0) {
  1312. methods.parseRawResourceDoc(destBox, URI);
  1313. } else {
  1314. $.jsonp({
  1315. url : SPARQLquery,
  1316. beforeSend : function() {
  1317. destBox.html('<img style=\"margin-left:' + (destBox.width() / 2) + 'px;margin-top:147px\" src="img/ajax-loader-gray.gif"/>');
  1318. destBox.css({
  1319. position : 'fixed',
  1320. left : $(window).width() - $('#docInfo').width() - 20,
  1321. // height : $(window).height() - 20,
  1322. top : 0
  1323. });
  1324. destBox.attr("data-top", destBox.position().top);
  1325. },
  1326. success : function(json) {
  1327. json = json['results']['bindings'];
  1328. $.each(json, function(key, value) {
  1329. if (value.object.type == 'uri') {
  1330. eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1331. } else if (value.object.type == 'bnode') {
  1332. eval('bnodes.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1333. } else {
  1334. eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  1335. }
  1336. });
  1337. destBox.html('');
  1338. methods.formatDoc(destBox, values, uris, bnodes, URI);
  1339. },
  1340. error : function(e, b, v) {
  1341. destBox.html('');
  1342. values = [{
  1343. 'http://system/msg' : 'risorsa non trovata: ' + destBox.attr('rel')
  1344. }];
  1345. methods.formatDoc(destBox, values, uris, bnodes, URI);
  1346. }
  1347. });
  1348. }
  1349. } else if (action == 'move') {
  1350. /*
  1351. * if ($('#docInfo').height() > $(window).height() + 10) { $('#docInfo').css({ position : 'absolute', left : $(window).width() + $('body').scrollLeft() -
  1352. * $('#docInfo').width() - 20, top : $('#docInfo').attr("data-top") }); } else { $('#docInfo').css({ position : 'fixed', left : $(window).width() -
  1353. * $('#docInfo').width() - 20, top : 0 }); }
  1354. */
  1355. } else {
  1356. $('#docInfo').fadeOut('fast', null, function() {
  1357. $('#docInfo').remove();
  1358. });
  1359. }
  1360. if (debugOn) {
  1361. console.debug((new Date().getTime() - start) + ' docInfo ');
  1362. }
  1363. },
  1364. processDraw : function(x1, y1, x2, y2, canvas, toId) {
  1365. try {
  1366. if (debugOn) {
  1367. start = new Date().getTime();
  1368. }
  1369. // recupero il nome della proprieta'
  1370. var label = "";
  1371. var lineStyle = "standardLine";
  1372. if ($("#" + toId).length > 0) {
  1373. label = canvas.attr("data-propertyName-" + toId);
  1374. var labeArray = label.split("\|");
  1375. label = "\n";
  1376. for (var o = 0; o < labeArray.length; o++) {
  1377. if (lodLiveProfile.arrows[$.trim(labeArray[o])]) {
  1378. lineStyle = lodLiveProfile.arrows[$.trim(labeArray[o])] + "Line";
  1379. }
  1380. var shortKey = $.trim(labeArray[o]);
  1381. if(lodLiveProfile['labeler'][shortKey]){
  1382. // replace property with a specific label
  1383. shortKey = lodLiveProfile['labeler'][shortKey];
  1384. }else{
  1385. // otherwise just a portion of the URI
  1386. while (shortKey.indexOf('/') > -1) {
  1387. shortKey = shortKey.substring(shortKey.indexOf('/') + 1);
  1388. }
  1389. while (shortKey.indexOf('#') > -1) {
  1390. shortKey = shortKey.substring(shortKey.indexOf('#') + 1);
  1391. }
  1392. }
  1393. if (label.indexOf("\n" + shortKey + "\n") == -1) {
  1394. label += shortKey + "\n";
  1395. }
  1396. }
  1397. }
  1398. if (lineStyle == 'standardLine') {
  1399. context.lodlive(lineStyle, label, x1, y1, x2, y2, canvas, toId);
  1400. } else {
  1401. $().customLines(context, lineStyle, label, x1, y1, x2, y2, canvas, toId);
  1402. }
  1403. if (debugOn) {
  1404. console.debug((new Date().getTime() - start) + ' processDraw ');
  1405. }
  1406. } catch (e) {
  1407. }
  1408. },
  1409. drawAllLines : function(obj) {
  1410. var generated = $.jStorage.get('storeIds-generatedBy-' + obj.attr("id"));
  1411. var generatedRev = $.jStorage.get('storeIds-generatedByRev-' + obj.attr("id"));
  1412. // elimino la riga se già presente (in caso di
  1413. // spostamento di un
  1414. // box)
  1415. $('#line-' + obj.attr("id")).clearCanvas();
  1416. if (generated) {
  1417. for (var a = 0; a < generated.length; a++) {
  1418. methods.drawaLine(obj, $("#" + generated[a]));
  1419. }
  1420. }
  1421. if (generatedRev) {
  1422. for (var a = 0; a < generatedRev.length; a++) {
  1423. generated = $.jStorage.get('storeIds-generatedBy-' + generatedRev[a]);
  1424. $('#line-' + generatedRev[a]).clearCanvas();
  1425. if (generated) {
  1426. for (var a2 = 0; a2 < generated.length; a2++) {
  1427. methods.drawaLine($('#' + generatedRev[a]), $("#" + generated[a2]));
  1428. }
  1429. }
  1430. }
  1431. }
  1432. },
  1433. drawaLine : function(from, to, propertyName) {
  1434. if (debugOn) {
  1435. start = new Date().getTime();
  1436. }
  1437. var pos1 = from.position();
  1438. var pos2 = to.position();
  1439. var aCanvas = $("#line-" + from.attr("id"));
  1440. // console.debug(new Date().getTime()+'moving - '+(new Date())+" -
  1441. // #line-" +
  1442. // from.attr("id") + "-" + to.attr("id"))
  1443. if (aCanvas.length == 1) {
  1444. if (propertyName) {
  1445. aCanvas.attr("data-propertyName-" + to.attr("id"), propertyName);
  1446. }
  1447. methods.processDraw(pos1.left + from.width() / 2, pos1.top + from.height() / 2, pos2.left + to.width() / 2, pos2.top + to.height() / 2, aCanvas, to.attr("id"));
  1448. } else {
  1449. aCanvas = $("<canvas data-propertyName-" + to.attr("id") + "=\"" + propertyName + "\" height=\"" + context.height() + "\" width=\"" + context.width() + "\" id=\"line-" + from.attr("id") + "\"></canvas>");
  1450. context.append(aCanvas);
  1451. aCanvas.css({
  1452. 'position' : 'absolute',
  1453. 'zIndex' : '0',
  1454. 'top' : 0,
  1455. 'left' : 0
  1456. });
  1457. methods.processDraw(pos1.left + from.width() / 2, pos1.top + from.height() / 2, pos2.left + to.width() / 2, pos2.top + to.height() / 2, aCanvas, to.attr("id"));
  1458. }
  1459. if (debugOn) {
  1460. console.debug((new Date().getTime() - start) + ' drawaLine ');
  1461. }
  1462. },
  1463. // formatto ed inserisco i valori recuperati dal json
  1464. formatDoc : function(destBox, values, uris, bnodes, URI) {
  1465. if (debugOn) {
  1466. console.debug("formatDoc " + 0);
  1467. start = new Date().getTime();
  1468. }
  1469. // recupero il doctype per caricare le configurazioni specifiche
  1470. var docType = methods.getJsonValue(uris, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'default');
  1471. // carico le configurazioni relative allo stile
  1472. destBox.addClass(methods.getProperty("document", "className", docType));
  1473. // ed ai path degli oggetti di tipo immagine
  1474. var images = methods.getProperty("images", "properties", docType);
  1475. // ed ai path dei link esterni
  1476. var weblinks = methods.getProperty("weblinks", "properties", docType);
  1477. // ed eventuali configurazioni delle proprietà da mostrare
  1478. // TODO: fare in modo che sia sempre possibile mettere il dominio come fallback
  1479. var propertiesMapper = methods.getProperty("document", "propertiesMapper", URI.replace(/(http:\/\/[^\/]+\/).+/, "$1"));
  1480. // se la proprieta' e' stata scritta come stringa la trasformo in un
  1481. // array
  1482. if ( typeof images == typeof '') {
  1483. images = [images];
  1484. }
  1485. if ( typeof weblinks == typeof '') {
  1486. weblinks = [weblinks];
  1487. }
  1488. var result = "<div></div>";
  1489. var jResult = $(result);
  1490. // destBox.append(jResult);
  1491. // estraggo i contenuti
  1492. var contents = [];
  1493. $.each(values, function(key, value) {
  1494. for (var akey in value) {
  1495. eval('contents.push({\'' + akey + '\':\'' + value[akey] + '\'})');
  1496. }
  1497. });
  1498. if (debugOn) {
  1499. console.debug("formatDoc " + 1);
  1500. }
  1501. // calcolo le uri e le url dei documenti correlati
  1502. var connectedImages = [];
  1503. var connectedWeblinks = [];
  1504. var types = [];
  1505. $.each(uris, function(key, value) {
  1506. for (var akey in value) {
  1507. // escludo la definizione della classe, le proprieta'
  1508. // relative alle immagini ed ai link web
  1509. if (akey != 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type') {
  1510. if ($.inArray(akey, images) != -1) {
  1511. eval('connectedImages.push({\'' + akey + '\':\'' + value[akey] + '\'})');
  1512. } else if ($.inArray(akey, weblinks) != -1) {
  1513. eval('connectedWeblinks.push({\'' + akey + '\':\'' + value[akey] + '\'})');
  1514. }
  1515. } else {
  1516. types.push(unescape(value[akey]));
  1517. }
  1518. }
  1519. });
  1520. if (debugOn) {
  1521. console.debug("formatDoc " + 2);
  1522. }
  1523. // aggiungo al box le immagini correlate
  1524. var imagesj = null;
  1525. if (connectedImages.length > 0) {
  1526. imagesj = $('<div class="section" style="height:80px"></div>');
  1527. $.each(connectedImages, function(key, value) {
  1528. for (var akey in value) {
  1529. imagesj.append("<a class=\"relatedImage\" href=\"" + unescape(value[akey]) + "\"><img src=\"" + unescape(value[akey]) + "\"/></a> ");
  1530. }
  1531. });
  1532. }
  1533. if (debugOn) {
  1534. console.debug("formatDoc " + 3);
  1535. }
  1536. var webLinkResult = null;
  1537. // aggiungo al box i link esterni correlati
  1538. if (connectedWeblinks.length > 0) {
  1539. webLinkResult = "<div class=\"section\"><ul style=\"padding:0;margin:0;display:block;overflow:hidden;tex-overflow:ellipses\">";
  1540. $.each(connectedWeblinks, function(key, value) {
  1541. for (var akey in value) {
  1542. webLinkResult += "<li><a class=\"relatedLink\" target=\"_blank\" data-title=\"" + akey + " \n " + unescape(value[akey]) + "\" href=\"" + unescape(value[akey]) + "\">" + unescape(value[akey]) + "</a></li>";
  1543. }
  1544. });
  1545. webLinkResult += "</ul></div>";
  1546. // jContents.append(webLinkResult);
  1547. }
  1548. if (debugOn) {
  1549. console.debug("formatDoc " + 4);
  1550. }
  1551. // aggiungo al box le informazioni descrittive della risorsa
  1552. var jContents = $('<div></div>');
  1553. var topSection = $('<div class="topSection sprite"><span>&#160;</span></div>');
  1554. jResult.append(topSection);
  1555. topSection.find('span').each(function() {
  1556. $(this).click(function() {
  1557. methods.docInfo('', 'close');
  1558. });
  1559. $(this).hover(function() {
  1560. topSection.setBackgroundPosition({
  1561. y : -410
  1562. });
  1563. }, function() {
  1564. topSection.setBackgroundPosition({
  1565. y : -390
  1566. });
  1567. });
  1568. });
  1569. if (debugOn) {
  1570. console.debug("formatDoc " + 5);
  1571. }
  1572. if (types.length > 0) {
  1573. var jSection = $("<div class=\"section\"><label data-title=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\">type</label><div></div></div>");
  1574. jSection.find('label').each(function() {
  1575. $(this).hover(function() {
  1576. methods.msg($(this).attr('data-title'), 'show');
  1577. }, function() {
  1578. methods.msg(null, 'hide');
  1579. });
  1580. });
  1581. for (var int = 0; int < types.length; int++) {
  1582. var shortKey = types[int];
  1583. // calcolo una forma breve per la
  1584. // visualizzazione
  1585. // dell'etichetta della proprieta'
  1586. while (shortKey.indexOf('/') > -1) {
  1587. shortKey = shortKey.substring(shortKey.indexOf('/') + 1);
  1588. }
  1589. while (shortKey.indexOf('#') > -1) {
  1590. shortKey = shortKey.substring(shortKey.indexOf('#') + 1);
  1591. }
  1592. jSection.children('div').append("<span title=\"" + types[int] + "\">" + shortKey + " </span>");
  1593. }
  1594. jContents.append(jSection);
  1595. jContents.append("<div class=\"separ sprite\"></div>");
  1596. }
  1597. if (debugOn) {
  1598. console.debug("formatDoc " + 6);
  1599. }
  1600. if (imagesj) {
  1601. jContents.append(imagesj);
  1602. jContents.append("<div class=\"separ sprite\"></div>");
  1603. }
  1604. if (webLinkResult) {
  1605. var jWebLinkResult = $(webLinkResult);
  1606. jWebLinkResult.find('a').each(function() {
  1607. $(this).hover(function() {
  1608. methods.msg($(this).attr('data-title'), 'show');
  1609. }, function() {
  1610. methods.msg(null, 'hide');
  1611. });
  1612. });
  1613. jContents.append(jWebLinkResult);
  1614. jContents.append("<div class=\"separ sprite\"></div>");
  1615. }
  1616. if (debugOn) {
  1617. console.debug("formatDoc " + 7);
  1618. }
  1619. if (propertiesMapper) {
  1620. $.each(propertiesMapper, function(filter, label) {
  1621. // show all properties
  1622. $.each(contents, function(key, value) {
  1623. for (var akey in value) {
  1624. if (filter == akey) {
  1625. var shortKey = label;
  1626. try {
  1627. var jSection = $("<div class=\"section\"><label data-title=\"" + akey + "\">" + shortKey + "</label><div>" + unescape(value[akey]) + "</div></div><div class=\"separ sprite\"></div>");
  1628. jSection.find('label').each(function() {
  1629. $(this).hover(function() {
  1630. methods.msg($(this).attr('data-title'), 'show');
  1631. }, function() {
  1632. methods.msg(null, 'hide');
  1633. });
  1634. });
  1635. jContents.append(jSection);
  1636. } catch (e) {
  1637. // /console.debug(value[akey] + " --- " + shortKey);
  1638. }
  1639. return true;
  1640. }
  1641. }
  1642. });
  1643. });
  1644. } else {
  1645. // show all properties
  1646. $.each(contents, function(key, value) {
  1647. for (var akey in value) {
  1648. var shortKey = akey;
  1649. // calcolo una forma breve per la visualizzazione
  1650. // dell'etichetta della proprieta'
  1651. while (shortKey.indexOf('/') > -1) {
  1652. shortKey = shortKey.substring(shortKey.indexOf('/') + 1);
  1653. }
  1654. while (shortKey.indexOf('#') > -1) {
  1655. shortKey = shortKey.substring(shortKey.indexOf('#') + 1);
  1656. }
  1657. try {
  1658. var jSection = $("<div class=\"section\"><label data-title=\"" + akey + "\">" + shortKey + "</label><div>" + unescape(value[akey]) + "</div></div><div class=\"separ sprite\"></div>");
  1659. jSection.find('label').each(function() {
  1660. $(this).hover(function() {
  1661. methods.msg($(this).attr('data-title'), 'show');
  1662. }, function() {
  1663. methods.msg(null, 'hide');
  1664. });
  1665. });
  1666. jContents.append(jSection);
  1667. } catch (e) {
  1668. // /console.debug(value[akey] + " --- " + shortKey);
  1669. }
  1670. }
  1671. });
  1672. }
  1673. if (bnodes.length > 0) {
  1674. // processo i blanknode
  1675. $.each(bnodes, function(key, value) {
  1676. for (var akey in value) {
  1677. var shortKey = akey;
  1678. // calcolo una forma breve per la visualizzazione
  1679. // dell'etichetta della proprieta'
  1680. while (shortKey.indexOf('/') > -1) {
  1681. shortKey = shortKey.substring(shortKey.indexOf('/') + 1);
  1682. }
  1683. while (shortKey.indexOf('#') > -1) {
  1684. shortKey = shortKey.substring(shortKey.indexOf('#') + 1);
  1685. }
  1686. var jBnode = $("<div class=\"section\"><label data-title=\"" + akey + "\">" + shortKey + "</label><span class=\"bnode\"></span></div><div class=\"separ sprite\"></div>");
  1687. jBnode.find('label').each(function() {
  1688. $(this).hover(function() {
  1689. methods.msg($(this).attr('data-title'), 'show');
  1690. }, function() {
  1691. methods.msg(null, 'hide');
  1692. });
  1693. });
  1694. methods.resolveBnodes(unescape(value[akey]), URI, jBnode, jContents);
  1695. }
  1696. });
  1697. }
  1698. if (contents.length == 0 && bnodes.length == 0) {
  1699. var jSection = $("<div class=\"section\"><label data-title=\"" + lang('resourceMissingDoc') + "\"></label><div>" + lang('resourceMissingDoc') + "</div></div><div class=\"separ sprite\"></div>");
  1700. jSection.find('label').each(function() {
  1701. $(this).hover(function() {
  1702. methods.msg($(this).attr('data-title'), 'show');
  1703. }, function() {
  1704. methods.msg(null, 'hide');
  1705. });
  1706. });
  1707. jContents.append(jSection);
  1708. }
  1709. destBox.append(jResult);
  1710. destBox.append(jContents);
  1711. // destBox.append("<div class=\"separLast\"></div>");
  1712. // aggiungo le funzionalita' per la visualizzazione delle immagini
  1713. jContents.find(".relatedImage").each(function() {
  1714. $(this).fancybox({
  1715. 'transitionIn' : 'elastic',
  1716. 'transitionOut' : 'elastic',
  1717. 'speedIn' : 400,
  1718. 'type' : 'image',
  1719. 'speedOut' : 200,
  1720. 'hideOnContentClick' : true,
  1721. 'showCloseButton' : false,
  1722. 'overlayShow' : false
  1723. });
  1724. $(this).find('img').each(function() {
  1725. $(this).load(function() {
  1726. if ($(this).width() > $(this).height()) {
  1727. $(this).height($(this).height() * 80 / $(this).width());
  1728. $(this).width(80);
  1729. } else {
  1730. $(this).width($(this).width() * 80 / $(this).height());
  1731. $(this).height(80);
  1732. }
  1733. });
  1734. $(this).error(function() {
  1735. $(this).attr("title", lang('noImage') + " \n" + $(this).attr("src"));
  1736. $(this).attr("src", "img/immagine-vuota-" + $.jStorage.get('selectedLanguage') + ".png");
  1737. });
  1738. });
  1739. });
  1740. if (jContents.height() + 40 > $(window).height()) {
  1741. destBox.find("div.separ:last").remove();
  1742. destBox.find("div.separLast").remove();
  1743. jContents.slimScroll({
  1744. height : $(window).height() - 40,
  1745. color : '#fff'
  1746. });
  1747. } else {
  1748. destBox.append("<div class=\"separLast\"></div>");
  1749. }
  1750. if (debugOn) {
  1751. console.debug((new Date().getTime() - start) + ' formatDoc ');
  1752. }
  1753. },
  1754. resolveBnodes : function(val, URI, destBox, jContents) {
  1755. if (debugOn) {
  1756. start = new Date().getTime();
  1757. }
  1758. var SPARQLquery = methods.composeQuery(val, 'bnode', URI);
  1759. $.jsonp({
  1760. url : SPARQLquery,
  1761. beforeSend : function() {
  1762. destBox.find('span[class=bnode]').html('<img src="img/ajax-loader-black.gif"/>');
  1763. },
  1764. success : function(json) {
  1765. destBox.find('span[class=bnode]').html('');
  1766. json = json['results']['bindings'];
  1767. $.each(json, function(key, value) {
  1768. var shortKey = value.property.value;
  1769. // calcolo una forma breve per la
  1770. // visualizzazione
  1771. // dell'etichetta della proprieta'
  1772. while (shortKey.indexOf('/') > -1) {
  1773. shortKey = shortKey.substring(shortKey.indexOf('/') + 1);
  1774. }
  1775. while (shortKey.indexOf('#') > -1) {
  1776. shortKey = shortKey.substring(shortKey.indexOf('#') + 1);
  1777. }
  1778. if (value.object.type == 'uri') {
  1779. } else if (value.object.type == 'bnode') {
  1780. var jBnode = $("<span><label data-title=\"" + value.property.value + "\"> / " + shortKey + "</label><span class=\"bnode\"></span></span>");
  1781. jBnode.find('label').each(function() {
  1782. $(this).hover(function() {
  1783. methods.msg($(this).attr('data-title'), 'show');
  1784. }, function() {
  1785. methods.msg(null, 'hide');
  1786. });
  1787. });
  1788. destBox.find('span[class=bnode]').attr("class", "").append(jBnode);
  1789. methods.resolveBnodes(value.object.value, URI, destBox, jContents);
  1790. } else {
  1791. destBox.find('span[class=bnode]').append('<div><em title="' + value.property.value + '">' + shortKey + "</em>: " + value.object.value + '</div>');
  1792. // destBox.find('span[class=bnode]').attr("class",
  1793. // "");
  1794. }
  1795. jContents.append(destBox);
  1796. if (jContents.height() + 40 > $(window).height()) {
  1797. jContents.slimScroll({
  1798. height : $(window).height() - 40,
  1799. color : '#fff'
  1800. });
  1801. jContents.parent().find("div.separLast").remove();
  1802. } else {
  1803. jContents.parent().append("<div class=\"separLast\"></div>");
  1804. }
  1805. });
  1806. },
  1807. error : function(e, b, v) {
  1808. destBox.find('span').html('');
  1809. }
  1810. });
  1811. if (debugOn) {
  1812. console.debug((new Date().getTime() - start) + ' resolveBnodes ');
  1813. }
  1814. return val;
  1815. },
  1816. format : function(destBox, values, uris, inverses) {
  1817. if (debugOn) {
  1818. start = new Date().getTime();
  1819. }
  1820. var containerBox = destBox.parent('div');
  1821. var thisUri = containerBox.attr('rel');
  1822. // recupero il doctype per caricare le configurazioni specifiche
  1823. var docType = methods.getJsonValue(uris, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 'default');
  1824. if (thisUri.indexOf("~~") != -1) {
  1825. docType = 'bnode';
  1826. }
  1827. // carico le configurazioni relative allo stile
  1828. var aClass = methods.getProperty("document", "className", docType);
  1829. if (docType == 'bnode') {
  1830. aClass = 'bnode';
  1831. }
  1832. // destBox.addClass(aClass);
  1833. if (aClass == null || aClass == 'standard' || aClass == '') {
  1834. if ($.jStorage.get('classMap')[docType]) {
  1835. aClass = $.jStorage.get('classMap')[docType];
  1836. } else {
  1837. var classMap = $.jStorage.get('classMap');
  1838. aClass = "box" + $.jStorage.get('classMap').counter;
  1839. if ($.jStorage.get('classMap').counter == 13) {
  1840. classMap.counter = 1;
  1841. $.jStorage.set('classMap', classMap);
  1842. } else {
  1843. classMap.counter = classMap.counter + 1;
  1844. $.jStorage.set('classMap', classMap);
  1845. }
  1846. classMap[docType] = aClass;
  1847. $.jStorage.set('classMap', classMap);
  1848. }
  1849. }
  1850. containerBox.addClass(aClass);
  1851. // ed ai path da mostrare nel titolo del box
  1852. var titles = methods.getProperty("document", "titleProperties", docType);
  1853. // ed ai path degli oggetti di tipo immagine
  1854. var images = methods.getProperty("images", "properties", docType);
  1855. // ed ai path dei link esterni
  1856. var weblinks = methods.getProperty("weblinks", "properties", docType);
  1857. // e le latitudini
  1858. var lats = methods.getProperty("maps", "lats", docType);
  1859. // e le longitudini
  1860. var longs = methods.getProperty("maps", "longs", docType);
  1861. // e punti
  1862. var points = methods.getProperty("maps", "points", docType);
  1863. // se la proprieta' e' stata scritta come stringa la trasformo in un
  1864. // array
  1865. if ( typeof titles == typeof '') {
  1866. titles = [titles];
  1867. }
  1868. if ( typeof images == typeof '') {
  1869. images = [images];
  1870. }
  1871. if ( typeof weblinks == typeof '') {
  1872. weblinks = [weblinks];
  1873. }
  1874. if ( typeof lats == typeof '') {
  1875. lats = [lats];
  1876. }
  1877. if ( typeof longs == typeof '') {
  1878. longs = [longs];
  1879. }
  1880. if ( typeof points == typeof '') {
  1881. points = [points];
  1882. }
  1883. // gestisco l'inserimento di messaggi di sistema come errori o altro
  1884. titles.push('http://system/msg');
  1885. // aggiungo al box il titolo
  1886. var result = "<div class=\"boxTitle\"><span class=\"ellipsis_text\">";
  1887. var maxTitles = 3;
  1888. for (var a = 0; a < titles.length && maxTitles > 0; a++) {
  1889. var resultArray = methods.getJsonValue(values, titles[a], titles[a].indexOf('http') == 0 ? '' : titles[a]);
  1890. if (titles[a].indexOf('http') != 0) {
  1891. if (result.indexOf($.trim(unescape(titles[a])) + " \n") == -1) {
  1892. result += $.trim(unescape(titles[a])) + " \n";
  1893. maxTitles--;
  1894. }
  1895. } else {
  1896. for (var af = 0; af < resultArray.length; af++) {
  1897. if (result.indexOf(unescape(resultArray[af]) + " \n") == -1) {
  1898. result += unescape(resultArray[af]) + " \n";
  1899. maxTitles--;
  1900. }
  1901. }
  1902. }
  1903. }
  1904. if ((values.length == 0 && uris.length == 0) || containerBox.attr("data-endpoint").indexOf("http://system/dummy") == 0) {
  1905. if (containerBox.attr("data-endpoint").indexOf("http://system/dummy") != -1) {
  1906. containerBox.attr("data-endpoint", lang('endpointNotConfigured'));
  1907. }
  1908. if (uris.length == 0 && values.length == 0) {
  1909. result = "<div class=\"boxTitle\" threedots=\"" + lang('resourceMissing') + "\"><a target=\"_blank\" href=\"" + thisUri + "\"><span class=\"spriteLegenda\"></span>" + thisUri + "</a>";
  1910. }
  1911. }
  1912. result += "</span></div>";
  1913. var jResult = $(result);
  1914. if (jResult.text() == '' && docType == 'bnode') {
  1915. jResult.text('[blank node]');
  1916. } else if (jResult.text() == '') {
  1917. jResult.text(lang('noName'));
  1918. }
  1919. destBox.append(jResult);
  1920. if (!jResult.children().html() || jResult.children().html().indexOf(">") == -1) {
  1921. jResult.ThreeDots({
  1922. max_rows : 3
  1923. });
  1924. }
  1925. var el = jResult.find('.threedots_ellipsis');
  1926. if (el.length > 0) {
  1927. el.detach();
  1928. jResult.children('span').append(el);
  1929. }
  1930. var resourceTitle = jResult.text();
  1931. // posiziono il titolo al centro del box
  1932. jResult.css({
  1933. 'marginTop' : jResult.height() == 13 ? 58 : jResult.height() == 26 ? 51 : 45,
  1934. 'height' : jResult.height() + 5
  1935. });
  1936. destBox.hover(function() {
  1937. methods.msg(jResult.attr("threedots") == '' ? jResult.text() : jResult.attr("threedots") + " \n " + thisUri, 'show', 'fullInfo', containerBox.attr("data-endpoint"));
  1938. }, function() {
  1939. methods.msg(null, 'hide');
  1940. });
  1941. // calcolo le uri e le url dei documenti correlati
  1942. var connectedDocs = [];
  1943. var invertedDocs = [];
  1944. var propertyGroup = {};
  1945. var propertyGroupInverted = {};
  1946. var connectedImages = [];
  1947. var connectedLongs = [];
  1948. var connectedLats = [];
  1949. var sameDocControl = [];
  1950. $.each(uris, function(key, value) {
  1951. for (var akey in value) {
  1952. // escludo la definizione della classe, le proprieta'
  1953. // relative alle immagini ed ai link web
  1954. if (lodLiveProfile.uriSubstitutor) {
  1955. $.each(lodLiveProfile.uriSubstitutor, function(skey, svalue) {
  1956. value[akey] = value[akey].replace(svalue.findStr, svalue.replaceStr);
  1957. });
  1958. }
  1959. if ($.inArray(akey, images) > -1) {
  1960. eval('connectedImages.push({\'' + value[akey] + '\':\'' + escape(resourceTitle) + '\'})');
  1961. // to expand types } else if (akey !=
  1962. // 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type' &&
  1963. // $.inArray(akey, weblinks) == -1) {
  1964. } else if ($.inArray(akey, weblinks) == -1) {
  1965. // controllo se trovo la stessa relazione in una
  1966. // proprieta' diversa
  1967. if ($.inArray(value[akey], sameDocControl) > -1) {
  1968. var aCounter = 0;
  1969. $.each(connectedDocs, function(key2, value2) {
  1970. for (var akey2 in value2) {
  1971. if (value2[akey2] == value[akey]) {
  1972. eval('connectedDocs[' + aCounter + '] = {\'' + akey2 + ' | ' + akey + '\':\'' + value[akey] + '\'}');
  1973. }
  1974. }
  1975. aCounter++;
  1976. });
  1977. } else {
  1978. eval('connectedDocs.push({\'' + akey + '\':\'' + value[akey] + '\'})');
  1979. sameDocControl.push(value[akey]);
  1980. }
  1981. }
  1982. }
  1983. });
  1984. if (inverses) {
  1985. sameDocControl = [];
  1986. $.each(inverses, function(key, value) {
  1987. for (var akey in value) {
  1988. if (docType == 'bnode' && value[akey].indexOf("~~") != -1) {
  1989. continue;
  1990. }
  1991. if (lodLiveProfile.uriSubstitutor) {
  1992. $.each(lodLiveProfile.uriSubstitutor, function(skey, svalue) {
  1993. value[akey] = value[akey].replace(escape(svalue.findStr), escape(svalue.replaceStr));
  1994. });
  1995. }
  1996. // controllo se trovo la stessa relazione in una
  1997. // proprieta' diversa
  1998. if ($.inArray(value[akey], sameDocControl) > -1) {
  1999. var aCounter = 0;
  2000. $.each(invertedDocs, function(key2, value2) {
  2001. for (var akey2 in value2) {
  2002. if (value2[akey2] == value[akey]) {
  2003. var theKey = akey2;
  2004. if (akey2 != akey) {
  2005. theKey = akey2 + ' | ' + akey;
  2006. }
  2007. eval('invertedDocs[' + aCounter + '] = {\'' + theKey + '\':\'' + value[akey] + '\'}');
  2008. return false;
  2009. }
  2010. }
  2011. aCounter++;
  2012. });
  2013. } else {
  2014. eval('invertedDocs.push({\'' + akey + '\':\'' + value[akey] + '\'})');
  2015. sameDocControl.push(value[akey]);
  2016. }
  2017. }
  2018. });
  2019. }
  2020. if ($.jStorage.get('doDrawMap', true)) {
  2021. for (var a = 0; a < points.length; a++) {
  2022. var resultArray = methods.getJsonValue(values, points[a], points[a]);
  2023. for (var af = 0; af < resultArray.length; af++) {
  2024. if (resultArray[af].indexOf(" ") != -1) {
  2025. eval('connectedLongs.push(\'' + unescape(resultArray[af].split(" ")[1]) + '\')');
  2026. eval('connectedLats.push(\'' + unescape(resultArray[af].split(" ")[0]) + '\')');
  2027. } else if (resultArray[af].indexOf("-") != -1) {
  2028. eval('connectedLongs.push(\'' + unescape(resultArray[af].split("-")[1]) + '\')');
  2029. eval('connectedLats.push(\'' + unescape(resultArray[af].split("-")[0]) + '\')');
  2030. }
  2031. }
  2032. }
  2033. for (var a = 0; a < longs.length; a++) {
  2034. var resultArray = methods.getJsonValue(values, longs[a], longs[a]);
  2035. for (var af = 0; af < resultArray.length; af++) {
  2036. eval('connectedLongs.push(\'' + unescape(resultArray[af]) + '\')');
  2037. }
  2038. }
  2039. for (var a = 0; a < lats.length; a++) {
  2040. var resultArray = methods.getJsonValue(values, lats[a], lats[a]);
  2041. for (var af = 0; af < resultArray.length; af++) {
  2042. eval('connectedLats.push(\'' + unescape(resultArray[af]) + '\')');
  2043. }
  2044. }
  2045. if (connectedLongs.length > 0 && connectedLats.length > 0) {
  2046. var mapsMap = $.jStorage.get("mapsMap", {});
  2047. mapsMap[containerBox.attr("id")] = {
  2048. longs : connectedLongs[0],
  2049. lats : connectedLats[0],
  2050. title : thisUri + "\n" + escape(resourceTitle)
  2051. };
  2052. $.jStorage.set('mapsMap', mapsMap);
  2053. methods.updateMapPanel($('#controlPanel'));
  2054. }
  2055. }
  2056. if ($.jStorage.get('doCollectImages', true)) {
  2057. if (connectedImages.length > 0) {
  2058. var imagesMap = $.jStorage.get("imagesMap", {});
  2059. imagesMap[containerBox.attr("id")] = connectedImages;
  2060. $.jStorage.set('imagesMap', imagesMap);
  2061. methods.updateImagePanel($('#controlPanel'));
  2062. }
  2063. }
  2064. var totRelated = connectedDocs.length + invertedDocs.length;
  2065. // se le proprieta' da mostrare sono troppe cerco di accorpare
  2066. // quelle uguali
  2067. if (totRelated > 16) {
  2068. $.each(connectedDocs, function(key, value) {
  2069. for (var akey in value) {
  2070. if (propertyGroup[akey]) {
  2071. var t = propertyGroup[akey];
  2072. t.push(value[akey]);
  2073. propertyGroup[akey] = t;
  2074. } else {
  2075. propertyGroup[akey] = [value[akey]];
  2076. }
  2077. }
  2078. });
  2079. $.each(invertedDocs, function(key, value) {
  2080. for (var akey in value) {
  2081. if (propertyGroupInverted[akey]) {
  2082. var t = propertyGroupInverted[akey];
  2083. t.push(value[akey]);
  2084. propertyGroupInverted[akey] = t;
  2085. } else {
  2086. propertyGroupInverted[akey] = [value[akey]];
  2087. }
  2088. }
  2089. });
  2090. totRelated = 0;
  2091. for (var prop in propertyGroup) {
  2092. if (propertyGroup.hasOwnProperty(prop)) {
  2093. totRelated++;
  2094. }
  2095. }
  2096. for (var prop in propertyGroupInverted) {
  2097. if (propertyGroupInverted.hasOwnProperty(prop)) {
  2098. totRelated++;
  2099. }
  2100. }
  2101. }
  2102. // calcolo le parti in cui dividere il cerchio per posizionare i
  2103. // link
  2104. // var chordsList = this.lodlive('circleChords',
  2105. // destBox.width() / 2 + 12, ((totRelated > 1 ? totRelated - 1 :
  2106. // totRelated) * 2) + 4, destBox.position().left + destBox.width() /
  2107. // 2, destBox.position().top + destBox.height() / 2, totRelated +
  2108. // 4);
  2109. var chordsList = methods.circleChords(75, 24, destBox.position().left + 65, destBox.position().top + 65);
  2110. var chordsListGrouped = methods.circleChords(95, 36, destBox.position().left + 65, destBox.position().top + 65);
  2111. // aggiungo al box i link ai documenti correlati
  2112. var a = 1;
  2113. var inserted = {};
  2114. var counter = 0;
  2115. var innerCounter = 1;
  2116. var objectList = [];
  2117. var innerObjectList = [];
  2118. $.each(connectedDocs, function(key, value) {
  2119. if (counter == 16) {
  2120. counter = 0;
  2121. }
  2122. if (a == 1) {
  2123. } else if (a == 15) {
  2124. a = 1;
  2125. }
  2126. for (var akey in value) {
  2127. var obj = null;
  2128. if (propertyGroup[akey] && propertyGroup[akey].length > 1) {
  2129. if (!inserted[akey]) {
  2130. innerCounter = 1;
  2131. inserted[akey] = true;
  2132. // var objBox = $("<div class=\"groupedRelatedBox
  2133. // sprite\" rel=\"" + MD5(akey) + "\" title=\"" +
  2134. // akey + "\" >" + (propertyGroup[akey].length) +
  2135. // "</div>");
  2136. var objBox = $("<div class=\"groupedRelatedBox sprite\" rel=\"" + MD5(akey) + "\" data-title=\"" + akey + " \n " + (propertyGroup[akey].length) + " " + lang('connectedResources') + "\" ></div>");
  2137. // containerBox.append(objBox);
  2138. var akeyArray = akey.split(" ");
  2139. if (unescape(propertyGroup[akey][0]).indexOf('~~') != -1) {
  2140. objBox.addClass('isBnode');
  2141. } else {
  2142. for (var i = 0; i < akeyArray.length; i++) {
  2143. if (lodLiveProfile.arrows[akeyArray[i]]) {
  2144. objBox.addClass(lodLiveProfile.arrows[akeyArray[i]]);
  2145. }
  2146. }
  2147. }
  2148. objBox.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
  2149. objectList.push(objBox);
  2150. // containerBox.append('<div data-circlePos="' + a +
  2151. // '" class="showGroupedRelated ' + MD5(akey) +
  2152. // '"></div>');
  2153. a++;
  2154. counter++;
  2155. }
  2156. // var alredyInserted = $('.relatedBox',
  2157. // containerBox).length;
  2158. // if (alredyInserted <
  2159. // document.lodliveVars['relationsLimit']) {
  2160. if (innerCounter < 25) {
  2161. obj = $("<div class=\"aGrouped relatedBox sprite " + MD5(akey) + " " + MD5(unescape(value[akey])) + "\" rel=\"" + unescape(value[akey]) + "\" data-title=\"" + akey + " \n " + unescape(value[akey]) + "\" ></div>");
  2162. // containerBox.append(obj);
  2163. obj.attr('style', 'display:none;position:absolute;top:' + (chordsListGrouped[innerCounter][1] - 8) + 'px;left:' + (chordsListGrouped[innerCounter][0] - 8) + 'px');
  2164. obj.attr("data-circlePos", innerCounter);
  2165. obj.attr("data-circleParts", 36);
  2166. obj.attr("data-circleId", containerBox.attr('id'));
  2167. }
  2168. /*
  2169. * } else if (alredyInserted == document.lodliveVars['relationsLimit']) { $('.' + MD5(akey), containerBox).append('<span class="relatedBox" title="altri
  2170. * elementi">[...]</span>'); }
  2171. */
  2172. innerCounter++;
  2173. } else {
  2174. obj = $("<div class=\"relatedBox sprite " + MD5(unescape(value[akey])) + "\" rel=\"" + unescape(value[akey]) + "\" data-title=\"" + akey + ' \n ' + unescape(value[akey]) + "\" ></div>");
  2175. // containerBox.append(obj);
  2176. obj.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
  2177. obj.attr("data-circlePos", a);
  2178. obj.attr("data-circleParts", 24);
  2179. a++;
  2180. counter++;
  2181. }
  2182. if (obj) {
  2183. obj.attr("data-circleId", containerBox.attr('id'));
  2184. obj.attr("data-property", akey);
  2185. // se si tratta di un Bnode applico una classe diversa
  2186. var akeyArray = akey.split(" ");
  2187. if (obj.attr('rel').indexOf('~~') != -1) {
  2188. obj.addClass('isBnode');
  2189. } else {
  2190. for (var i = 0; i < akeyArray.length; i++) {
  2191. if (lodLiveProfile.arrows[akeyArray[i]]) {
  2192. obj.addClass(lodLiveProfile.arrows[akeyArray[i]]);
  2193. }
  2194. }
  2195. }
  2196. if (obj.hasClass("aGrouped")) {
  2197. innerObjectList.push(obj);
  2198. } else {
  2199. objectList.push(obj);
  2200. }
  2201. }
  2202. }
  2203. });
  2204. inserted = {};
  2205. $.each(invertedDocs, function(key, value) {
  2206. if (counter == 16) {
  2207. counter = 0;
  2208. }
  2209. if (a == 1) {
  2210. } else if (a == 15) {
  2211. a = 1;
  2212. }
  2213. for (var akey in value) {
  2214. var obj = null;
  2215. if (propertyGroupInverted[akey] && propertyGroupInverted[akey].length > 1) {
  2216. if (!inserted[akey]) {
  2217. innerCounter = 1;
  2218. inserted[akey] = true;
  2219. // var objBox = $("<div class=\"groupedRelatedBox
  2220. // sprite\" rel=\"" + MD5(akey) + "\" title=\"" +
  2221. // akey + "\" >" + (propertyGroup[akey].length) +
  2222. // "</div>");
  2223. var objBox = $("<div class=\"groupedRelatedBox sprite inverse\" rel=\"" + MD5(akey) + "-i\" data-title=\"" + akey + " \n " + (propertyGroupInverted[akey].length) + " " + lang('connectedResources') + "\" ></div>");
  2224. // containerBox.append(objBox);
  2225. var akeyArray = akey.split(" ");
  2226. if (unescape(propertyGroupInverted[akey][0]).indexOf('~~') != -1) {
  2227. objBox.addClass('isBnode');
  2228. } else {
  2229. for (var i = 0; i < akeyArray.length; i++) {
  2230. if (lodLiveProfile.arrows[akeyArray[i]]) {
  2231. objBox.addClass(lodLiveProfile.arrows[akeyArray[i]]);
  2232. }
  2233. }
  2234. }
  2235. objBox.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
  2236. // containerBox.append('<div data-circlePos="' + a +
  2237. // '" class="showGroupedRelated ' + MD5(akey) +
  2238. // '"></div>');
  2239. objectList.push(objBox);
  2240. a++;
  2241. counter++;
  2242. }
  2243. // var alredyInserted = $('.relatedBox',
  2244. // containerBox).length;
  2245. // if (alredyInserted <
  2246. // document.lodliveVars['relationsLimit']) {
  2247. if (innerCounter < 25) {
  2248. var destUri = unescape(value[akey].indexOf('~~') == 0 ? thisUri + value[akey] : value[akey]);
  2249. obj = $("<div class=\"aGrouped relatedBox sprite inverse " + MD5(akey) + "-i " + MD5(unescape(value[akey])) + " \" rel=\"" + destUri + "\" data-title=\"" + akey + " \n " + unescape(value[akey]) + "\" ></div>");
  2250. // containerBox.append(obj);
  2251. obj.attr('style', 'display:none;position:absolute;top:' + (chordsListGrouped[innerCounter][1] - 8) + 'px;left:' + (chordsListGrouped[innerCounter][0] - 8) + 'px');
  2252. obj.attr("data-circlePos", innerCounter);
  2253. obj.attr("data-circleParts", 36);
  2254. obj.attr("data-circleId", containerBox.attr('id'));
  2255. }
  2256. /*
  2257. * } else if (alredyInserted == document.lodliveVars['relationsLimit']) { $('.' + MD5(akey), containerBox).append('<span class="relatedBox" title="altri
  2258. * elementi">[...]</span>'); }
  2259. */
  2260. innerCounter++;
  2261. } else {
  2262. obj = $("<div class=\"relatedBox sprite inverse " + MD5(unescape(value[akey])) + "\" rel=\"" + unescape(value[akey]) + "\" data-title=\"" + akey + ' \n ' + unescape(value[akey]) + "\" ></div>");
  2263. // containerBox.append(obj);
  2264. obj.attr('style', 'top:' + (chordsList[a][1] - 8) + 'px;left:' + (chordsList[a][0] - 8) + 'px');
  2265. obj.attr("data-circlePos", a);
  2266. obj.attr("data-circleParts", 24);
  2267. a++;
  2268. counter++;
  2269. }
  2270. if (obj) {
  2271. obj.attr("data-circleId", containerBox.attr('id'));
  2272. obj.attr("data-property", akey);
  2273. // se si tratta di un sameas applico una classe diversa
  2274. var akeyArray = akey.split(" ");
  2275. if (obj.attr('rel').indexOf('~~') != -1) {
  2276. obj.addClass('isBnode');
  2277. } else {
  2278. for (var i = 0; i < akeyArray.length; i++) {
  2279. if (lodLiveProfile.arrows[akeyArray[i]]) {
  2280. obj.addClass(lodLiveProfile.arrows[akeyArray[i]]);
  2281. }
  2282. }
  2283. }
  2284. if (obj.hasClass("aGrouped")) {
  2285. innerObjectList.push(obj);
  2286. } else {
  2287. objectList.push(obj);
  2288. }
  2289. }
  2290. }
  2291. });
  2292. var page = 0;
  2293. var totPages = objectList.length > 14 ? (objectList.length / 14 + (objectList.length % 14 > 0 ? 1 : 0)) : 1;
  2294. for (var i = 0; i < objectList.length; i++) {
  2295. if (i % 14 == 0) {
  2296. page++;
  2297. var aPage = $('<div class="page page' + page + '" style="display:none"></div>');
  2298. if (page > 1 && totPages > 1) {
  2299. aPage.append("<div class=\"pager pagePrev sprite\" data-page=\"page" + (page - 1) + "\" style=\"top:" + (chordsList[0][1] - 8) + "px;left:" + (chordsList[0][0] - 8) + "px\"></div>");
  2300. }
  2301. if (totPages > 1 && page < totPages - 1) {
  2302. aPage.append("<div class=\"pager pageNext sprite\" data-page=\"page" + (page + 1) + "\" style=\"top:" + (chordsList[15][1] - 8) + "px;left:" + (chordsList[15][0] - 8) + "px\"></div>");
  2303. }
  2304. containerBox.append(aPage);
  2305. }
  2306. containerBox.children('.page' + page).append(objectList[i]);
  2307. }
  2308. page = 0;
  2309. totPages = innerObjectList.length / 24 + (innerObjectList.length % 24 > 0 ? 1 : 0);
  2310. if (innerObjectList.length > 0) {
  2311. containerBox.append('<div class="innerPage"></div>');
  2312. for (var i = 0; i < innerObjectList.length; i++) {
  2313. containerBox.children('.innerPage').append(innerObjectList[i]);
  2314. }
  2315. }
  2316. containerBox.children('.page1').fadeIn('fast');
  2317. containerBox.children('.page').children('.pager').click(function() {
  2318. var pager = $(this);
  2319. containerBox.find('.lastClick').removeClass('lastClick').click();
  2320. pager.parent().fadeOut('fast', null, function() {
  2321. $(this).parent().children('.' + pager.attr("data-page")).fadeIn('fast');
  2322. });
  2323. }); {
  2324. var obj = $("<div class=\"actionBox contents\" rel=\"contents\" >&#160;</div>");
  2325. containerBox.append(obj);
  2326. obj.hover(function() {
  2327. $(this).parent().children('.box').setBackgroundPosition({
  2328. y : -260
  2329. });
  2330. }, function() {
  2331. $(this).parent().children('.box').setBackgroundPosition({
  2332. y : 0
  2333. });
  2334. });
  2335. obj = $("<div class=\"actionBox tools\" rel=\"tools\" >&#160;</div>");
  2336. containerBox.append(obj);
  2337. obj.hover(function() {
  2338. $(this).parent().children('.box').setBackgroundPosition({
  2339. y : -130
  2340. });
  2341. }, function() {
  2342. $(this).parent().children('.box').setBackgroundPosition({
  2343. y : 0
  2344. });
  2345. });
  2346. }
  2347. if (debugOn) {
  2348. console.debug((new Date().getTime() - start) + ' format ');
  2349. }
  2350. },
  2351. circleChords : function(radius, steps, centerX, centerY, breakAt, onlyElement) {
  2352. if (debugOn) {
  2353. start = new Date().getTime();
  2354. }
  2355. var values = [];
  2356. var i = 0;
  2357. if (onlyElement) {
  2358. // ottimizzo i cicli evitando di calcolare elementi che non
  2359. // servono
  2360. i = onlyElement;
  2361. var radian = (2 * Math.PI) * (i / steps);
  2362. values.push([centerX + radius * Math.cos(radian), centerY + radius * Math.sin(radian)]);
  2363. } else {
  2364. for (; i < steps; i++) {
  2365. // calcolo le coodinate lungo il cerchio del box per
  2366. // posizionare
  2367. // strumenti ed altre risorse
  2368. var radian = (2 * Math.PI) * (i / steps);
  2369. values.push([centerX + radius * Math.cos(radian), centerY + radius * Math.sin(radian)]);
  2370. }
  2371. }
  2372. if (debugOn) {
  2373. console.debug((new Date().getTime() - start) + ' circleChords ');
  2374. }
  2375. return values;
  2376. // console.debug(xValues)
  2377. // console.debug(yValues)
  2378. },
  2379. getJsonValue : function(map, key, defaultValue) {
  2380. if (debugOn) {
  2381. start = new Date().getTime();
  2382. }
  2383. var returnVal = [];
  2384. $.each(map, function(skey, value) {
  2385. for (var akey in value) {
  2386. if (akey == key) {
  2387. returnVal.push(unescape(value[akey]));
  2388. }
  2389. }
  2390. });
  2391. if (returnVal == []) {
  2392. returnVal = [defaultValue];
  2393. }
  2394. if (debugOn) {
  2395. console.debug((new Date().getTime() - start) + ' getJsonValue');
  2396. }
  2397. return returnVal;
  2398. },
  2399. getProperty : function(area, prop, context) {
  2400. if (debugOn) {
  2401. start = new Date().getTime();
  2402. }
  2403. if ( typeof context == typeof '') {
  2404. if (lodLiveProfile[context] && lodLiveProfile[context][area]) {
  2405. if (prop) {
  2406. return lodLiveProfile[context][area][prop] ? lodLiveProfile[context][area][prop] : lodLiveProfile['default'][area][prop];
  2407. } else {
  2408. return lodLiveProfile[context][area] ? lodLiveProfile[context][area] : lodLiveProfile['default'][area];
  2409. }
  2410. }
  2411. } else {
  2412. for (var a = 0; a < context.length; a++) {
  2413. if (lodLiveProfile[context[a]] && lodLiveProfile[context[a]][area]) {
  2414. if (prop) {
  2415. return lodLiveProfile[context[a]][area][prop] ? lodLiveProfile[context[a]][area][prop] : lodLiveProfile['default'][area][prop];
  2416. } else {
  2417. return lodLiveProfile[context[a]][area] ? lodLiveProfile[context[a]][area] : lodLiveProfile['default'][area];
  2418. }
  2419. }
  2420. }
  2421. }
  2422. if (debugOn) {
  2423. console.debug((new Date().getTime() - start) + ' getProperty');
  2424. }
  2425. if (lodLiveProfile['default'][area]) {
  2426. if (prop) {
  2427. return lodLiveProfile['default'][area][prop];
  2428. } else {
  2429. return lodLiveProfile['default'][area];
  2430. }
  2431. } else {
  2432. return '';
  2433. }
  2434. },
  2435. parseRawResource : function(destBox, resource, fromInverse) {
  2436. var values = [];
  2437. var uris = [];
  2438. if (lodLiveProfile['default']) {
  2439. // attivo lo sparql interno basato su sesame
  2440. var res = getSparqlConf('documentUri', lodLiveProfile['default'], lodLiveProfile).replace(/\{URI\}/ig, resource);
  2441. var url = lodLiveProfile['default'].endpoint + "?uri=" + encodeURIComponent(resource) + "&query=" + encodeURIComponent(res);
  2442. if ($.jStorage.get('showInfoConsole')) {
  2443. methods.queryConsole('log', {
  2444. title : lang('endpointNotConfiguredSoInternal'),
  2445. text : res,
  2446. uriId : resource
  2447. });
  2448. }
  2449. $.jsonp({
  2450. url : url,
  2451. beforeSend : function() {
  2452. destBox.children('.box').html('<img style=\"margin-top:' + (destBox.children('.box').height() / 2 - 8) + 'px\" src="img/ajax-loader.gif"/>');
  2453. },
  2454. success : function(json) {
  2455. json = json['results']['bindings'];
  2456. var conta = 0;
  2457. $.each(json, function(key, value) {
  2458. conta++;
  2459. if (value.object.type == 'uri') {
  2460. if (value.object.value != resource) {
  2461. eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  2462. }
  2463. } else {
  2464. eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  2465. }
  2466. });
  2467. if (debugOn) {
  2468. console.debug((new Date().getTime() - start) + ' openDoc eval uris & values');
  2469. }
  2470. var inverses = [];
  2471. var callback = function() {
  2472. destBox.children('.box').html('');
  2473. methods.format(destBox.children('.box'), values, uris, inverses);
  2474. methods.addClick(destBox, fromInverse ? function() {
  2475. try {
  2476. $(fromInverse).click();
  2477. } catch (e) {
  2478. }
  2479. } : null);
  2480. if ($.jStorage.get('doAutoExpand')) {
  2481. methods.autoExpand(destBox);
  2482. }
  2483. };
  2484. if ($.jStorage.get('doAutoSameas')) {
  2485. var counter = 0;
  2486. var tot = 0;
  2487. $.each(lodLiveProfile.connection, function(key, value) {
  2488. tot++;
  2489. });
  2490. methods.findInverseSameAs(resource, counter, inverses, callback, tot);
  2491. } else {
  2492. callback();
  2493. }
  2494. },
  2495. error : function(e, j, k) {
  2496. // console.debug(e);console.debug(j);
  2497. destBox.children('.box').html('');
  2498. var inverses = [];
  2499. if (fromInverse) {
  2500. eval('uris.push({\'' + fromInverse.replace(/div\[data-property="([^"]*)"\].*/, '$1') + '\':\'' + fromInverse.replace(/.*\[rel="([^"]*)"\].*/, '$1') + '\'})');
  2501. }
  2502. methods.format(destBox.children('.box'), values, uris, inverses);
  2503. methods.addClick(destBox, fromInverse ? function() {
  2504. try {
  2505. $(fromInverse).click();
  2506. } catch (e) {
  2507. }
  2508. } : null);
  2509. if ($.jStorage.get('doAutoExpand')) {
  2510. methods.autoExpand(destBox);
  2511. }
  2512. }
  2513. });
  2514. } else {
  2515. // console.debug(e);console.debug(j);
  2516. destBox.children('.box').html('');
  2517. var inverses = [];
  2518. if (fromInverse) {
  2519. eval('uris.push({\'' + fromInverse.replace(/div\[data-property="([^"]*)"\].*/, '$1') + '\':\'' + fromInverse.replace(/.*\[rel="([^"]*)"\].*/, '$1') + '\'})');
  2520. }
  2521. methods.format(destBox.children('.box'), values, uris, inverses);
  2522. methods.addClick(destBox, fromInverse ? function() {
  2523. try {
  2524. $(fromInverse).click();
  2525. } catch (e) {
  2526. }
  2527. } : null);
  2528. if ($.jStorage.get('doAutoExpand')) {
  2529. methods.autoExpand(destBox);
  2530. }
  2531. }
  2532. },
  2533. openDoc : function(anUri, destBox, fromInverse) {
  2534. if (debugOn) {
  2535. start = new Date().getTime();
  2536. }
  2537. var uris = [];
  2538. var values = [];
  2539. if ($.jStorage.get('showInfoConsole')) {
  2540. methods.queryConsole('init', {
  2541. uriId : anUri
  2542. });
  2543. methods.queryConsole('log', {
  2544. uriId : anUri,
  2545. resource : anUri
  2546. });
  2547. }
  2548. SPARQLquery = methods.composeQuery(anUri, 'documentUri');
  2549. if ($.jStorage.get('doStats')) {
  2550. methods.doStats(anUri);
  2551. }
  2552. if (SPARQLquery.indexOf("endpoint=") != -1) {
  2553. var endpoint = SPARQLquery.substring(SPARQLquery.indexOf("endpoint=") + 9);
  2554. endpoint = endpoint.substring(0, endpoint.indexOf("&"));
  2555. destBox.attr("data-endpoint", endpoint);
  2556. } else {
  2557. destBox.attr("data-endpoint", SPARQLquery.substring(0, SPARQLquery.indexOf("?")));
  2558. }
  2559. if (SPARQLquery.indexOf("http://system/dummy") == 0) {
  2560. // guessing endpoint from URI
  2561. methods.guessingEndpoint(anUri, function() {
  2562. methods.openDoc(anUri, destBox, fromInverse);
  2563. }, function() {
  2564. methods.parseRawResource(destBox, anUri, fromInverse);
  2565. });
  2566. } else {
  2567. $.jsonp({
  2568. url : SPARQLquery,
  2569. beforeSend : function() {
  2570. destBox.children('.box').html('<img style=\"margin-top:' + (destBox.children('.box').height() / 2 - 8) + 'px\" src="img/ajax-loader.gif"/>');
  2571. },
  2572. success : function(json) {
  2573. json = json['results']['bindings'];
  2574. // var tot = json.length;
  2575. var conta = 0;
  2576. // var aSpan = $('<span style="color:#000"><br />gg0/' +
  2577. // tot + '</span>');
  2578. // destBox.children('.box').append(aSpan);
  2579. // var control = {};
  2580. $.each(json, function(key, value) {
  2581. conta++;
  2582. if (value.object.type == 'uri' || value.object.type == 'bnode') {
  2583. if (value.object.value != anUri) {
  2584. if (value.object.type == 'bnode') {
  2585. eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(anUri + '~~' + value.object.value) + '\'})');
  2586. } else {
  2587. eval('uris.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  2588. }
  2589. }
  2590. } else {
  2591. eval('values.push({\'' + value['property']['value'] + '\':\'' + escape(value.object.value) + '\'})');
  2592. }
  2593. });
  2594. if ($.jStorage.get('showInfoConsole')) {
  2595. methods.queryConsole('log', {
  2596. founded : conta,
  2597. id : SPARQLquery,
  2598. uriId : anUri
  2599. });
  2600. }
  2601. if (debugOn) {
  2602. console.debug((new Date().getTime() - start) + ' openDoc eval uris & values');
  2603. }
  2604. destBox.children('.box').html('');
  2605. if ($.jStorage.get('doInverse')) {
  2606. SPARQLquery = methods.composeQuery(anUri, 'inverse');
  2607. var inverses = [];
  2608. $.jsonp({
  2609. url : SPARQLquery,
  2610. beforeSend : function() {
  2611. destBox.children('.box').html('<img style=\"margin-top:' + (destBox.children('.box').height() / 2 - 5) + 'px\" src="img/ajax-loader.gif"/>');
  2612. },
  2613. success : function(json) {
  2614. json = json['results']['bindings'];
  2615. var conta = 0;
  2616. // var tot = json.length;
  2617. // var aSpan = $('<span
  2618. // style="color:#000"><br />0/' + tot +
  2619. // '</span>');
  2620. // destBox.children('.box').append(aSpan);
  2621. $.each(json, function(key, value) {
  2622. conta++;
  2623. eval('inverses.push({\'' + value['property']['value'] + '\':\'' + (value.object.type == 'bnode' ? anUri + '~~' : '') + escape(value.object.value) + '\'})');
  2624. // aSpan.text(conta + '/' + tot);
  2625. });
  2626. if ($.jStorage.get('showInfoConsole')) {
  2627. methods.queryConsole('log', {
  2628. founded : conta,
  2629. id : SPARQLquery,
  2630. uriId : anUri
  2631. });
  2632. }
  2633. if (debugOn) {
  2634. console.debug((new Date().getTime() - start) + ' openDoc inverse eval uris ');
  2635. }
  2636. var callback = function() {
  2637. destBox.children('.box').html('');
  2638. methods.format(destBox.children('.box'), values, uris, inverses);
  2639. methods.addClick(destBox, fromInverse ? function() {
  2640. try {
  2641. $(fromInverse).click();
  2642. } catch (e) {
  2643. }
  2644. } : null);
  2645. if ($.jStorage.get('doAutoExpand')) {
  2646. methods.autoExpand(destBox);
  2647. }
  2648. };
  2649. if ($.jStorage.get('doAutoSameas')) {
  2650. var counter = 0;
  2651. var tot = 0;
  2652. $.each(lodLiveProfile.connection, function(key, value) {
  2653. tot++;
  2654. });
  2655. methods.findInverseSameAs(anUri, counter, inverses, callback, tot);
  2656. } else {
  2657. callback();
  2658. }
  2659. },
  2660. error : function(e, b, v) {
  2661. destBox.children('.box').html('');
  2662. methods.format(destBox.children('.box'), values, uris);
  2663. if ($.jStorage.get('showInfoConsole')) {
  2664. methods.queryConsole('log', {
  2665. error : 'error',
  2666. id : SPARQLquery,
  2667. uriId : anUri
  2668. });
  2669. }
  2670. methods.addClick(destBox, fromInverse ? function() {
  2671. try {
  2672. $(fromInverse).click();
  2673. } catch (e) {
  2674. }
  2675. } : null);
  2676. if ($.jStorage.get('doAutoExpand')) {
  2677. methods.autoExpand(destBox);
  2678. }
  2679. }
  2680. });
  2681. } else {
  2682. methods.format(destBox.children('.box'), values, uris);
  2683. methods.addClick(destBox, fromInverse ? function() {
  2684. try {
  2685. $(fromInverse).click();
  2686. } catch (e) {
  2687. }
  2688. } : null);
  2689. if ($.jStorage.get('doAutoExpand')) {
  2690. methods.autoExpand(destBox);
  2691. }
  2692. }
  2693. },
  2694. error : function(e, b, v) {
  2695. methods.errorBox(destBox);
  2696. }
  2697. });
  2698. }
  2699. if (debugOn) {
  2700. console.debug((new Date().getTime() - start) + ' openDoc');
  2701. }
  2702. },
  2703. errorBox : function(destBox) {
  2704. destBox.children('.box').addClass("errorBox");
  2705. destBox.children('.box').html('');
  2706. var jResult = $("<div class=\"boxTitle\"><span>" + lang('enpointNotAvailable') + "</span></div>");
  2707. destBox.children('.box').append(jResult);
  2708. jResult.css({
  2709. 'marginTop' : jResult.height() == 13 ? 58 : jResult.height() == 26 ? 51 : 45
  2710. });
  2711. var obj = $("<div class=\"actionBox tools\">&#160;</div>");
  2712. obj.click(function() {
  2713. methods.removeDoc(destBox);
  2714. });
  2715. destBox.append(obj);
  2716. destBox.children('.box').hover(function() {
  2717. methods.msg(lang('enpointNotAvailableOrSLow'), 'show', 'fullInfo', destBox.attr("data-endpoint"));
  2718. }, function() {
  2719. methods.msg(null, 'hide');
  2720. });
  2721. },
  2722. allClasses : function(SPARQLquery, destBox, destSelect, template) {
  2723. if (debugOn) {
  2724. start = new Date().getTime();
  2725. }
  2726. SPARQLquery = methods.composeQuery(SPARQLquery, 'allClasses');
  2727. var classes = [];
  2728. $.jsonp({
  2729. url : SPARQLquery,
  2730. beforeSend : function() {
  2731. destBox.html('<img src="img/ajax-loader.gif"/>');
  2732. },
  2733. success : function(json) {
  2734. destBox.html(lang('choose'));
  2735. json = json['results']['bindings'];
  2736. $.each(json, function(key, value) {
  2737. var aclass = json[key].object.value;
  2738. if (aclass.indexOf('http://www.openlinksw.com/') == -1) {
  2739. aclass = aclass.replace(/http:\/\//, "");
  2740. classes.push(aclass);
  2741. }
  2742. });
  2743. for (var i = 0; i < classes.length; i++) {
  2744. destSelect.append(template.replace(/\{CONTENT\}/g, classes[i]));
  2745. }
  2746. },
  2747. error : function(e, b, v) {
  2748. destSelect.append(template.replace(/\{CONTENT\}/g, 'si è verificato un errore'));
  2749. }
  2750. });
  2751. if (debugOn) {
  2752. console.debug((new Date().getTime() - start) + ' allClasses');
  2753. }
  2754. },
  2755. findInverseSameAs : function(anUri, counter, inverse, callback, tot) {
  2756. if (debugOn) {
  2757. start = new Date().getTime();
  2758. }
  2759. var innerCounter = 0;
  2760. $.each(lodLiveProfile.connection, function(key, value) {
  2761. if (innerCounter == counter) {
  2762. var skip = false;
  2763. var keySplit = key.split(",");
  2764. if (!value.useForInverseSameAs) {
  2765. skip = true;
  2766. } else {
  2767. for (var a = 0; a < keySplit.length; a++) {
  2768. // salto i sameas interni allo stesso endpoint
  2769. if (anUri.indexOf(keySplit[a]) != -1) {
  2770. skip = true;
  2771. }
  2772. }
  2773. }
  2774. if (skip) {
  2775. counter++;
  2776. if (counter < tot) {
  2777. methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
  2778. } else {
  2779. callback();
  2780. }
  2781. return false;
  2782. }
  2783. var SPARQLquery = value.endpoint + "?" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri));
  2784. if (value.proxy) {
  2785. SPARQLquery = value.proxy + '?endpoint=' + value.endpoint + "&" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri));
  2786. }
  2787. $.jsonp({
  2788. url : SPARQLquery,
  2789. timeout : 3000,
  2790. beforeSend : function() {
  2791. if ($.jStorage.get('showInfoConsole')) {
  2792. methods.queryConsole('log', {
  2793. title : value.endpoint,
  2794. text : getSparqlConf('inverseSameAs', value, lodLiveProfile).replace(/\{URI\}/g, anUri),
  2795. id : SPARQLquery,
  2796. uriId : anUri
  2797. });
  2798. }
  2799. },
  2800. success : function(json) {
  2801. json = json['results']['bindings'];
  2802. var conta = 0;
  2803. $.each(json, function(key, value) {
  2804. conta++;
  2805. if (value.property && value.property.value) {
  2806. eval('inverse.splice(1,0,{\'' + value.property.value + '\':\'' + escape(value.object.value) + '\'})');
  2807. } else {
  2808. eval('inverse.splice(1,0,{\'' + 'http://www.w3.org/2002/07/owl#sameAs' + '\':\'' + escape(value.object.value) + '\'})');
  2809. }
  2810. });
  2811. if ($.jStorage.get('showInfoConsole')) {
  2812. methods.queryConsole('log', {
  2813. founded : conta,
  2814. id : SPARQLquery,
  2815. uriId : anUri
  2816. });
  2817. }
  2818. counter++;
  2819. if (counter < tot) {
  2820. methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
  2821. } else {
  2822. callback();
  2823. }
  2824. },
  2825. error : function(e, b, v) {
  2826. if ($.jStorage.get('showInfoConsole')) {
  2827. methods.queryConsole('log', {
  2828. error : 'error',
  2829. id : SPARQLquery,
  2830. uriId : anUri
  2831. });
  2832. }
  2833. counter++;
  2834. if (counter < tot) {
  2835. methods.findInverseSameAs(anUri, counter, inverse, callback, tot);
  2836. } else {
  2837. callback();
  2838. }
  2839. }
  2840. });
  2841. if (debugOn) {
  2842. console.debug((new Date().getTime() - start) + ' findInverseSameAs ' + value.endpoint);
  2843. }
  2844. }
  2845. innerCounter++;
  2846. });
  2847. if (debugOn) {
  2848. console.debug((new Date().getTime() - start) + ' findInverseSameAs');
  2849. }
  2850. },
  2851. findSubject : function(SPARQLquery, selectedClass, selectedValue, destBox, destInput) {
  2852. if (debugOn) {
  2853. start = new Date().getTime();
  2854. }
  2855. $.each(lodLiveProfile.connection, function(key, value) {
  2856. var keySplit = key.split(",");
  2857. for (var a = 0; a < keySplit.length; a++) {
  2858. if (SPARQLquery.indexOf(keySplit[a]) != -1) {
  2859. SPARQLquery = value.endpoint + "?" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('findSubject', value, lodLiveProfile).replace(/\{CLASS\}/g, selectedClass).replace(/\{VALUE\}/g, selectedValue));
  2860. if (value.proxy) {
  2861. SPARQLquery = value.proxy + "?endpoint=" + value.endpoint + "&" + (value.endpointType ? $.jStorage.get('endpoints')[value.endpointType] : $.jStorage.get('endpoints')['all']) + "&query=" + escape(getSparqlConf('findSubject', value, lodLiveProfile).replace(/\{CLASS\}/g, selectedClass).replace(/\{VALUE\}/g, selectedValue));
  2862. }
  2863. }
  2864. }
  2865. });
  2866. var values = [];
  2867. $.jsonp({
  2868. url : SPARQLquery,
  2869. beforeSend : function() {
  2870. destBox.html('<img src="img/ajax-loader.gif"/>');
  2871. },
  2872. success : function(json) {
  2873. destBox.html('');
  2874. json = json['results']['bindings'];
  2875. $.each(json, function(key, value) {
  2876. values.push(json[key].subject.value);
  2877. });
  2878. for (var i = 0; i < values.length; i++) {
  2879. // console.debug(destInput)
  2880. destInput.val(values[i]);
  2881. }
  2882. },
  2883. error : function(e, b, v) {
  2884. destBox.html('errore: ' + e);
  2885. }
  2886. });
  2887. if (debugOn) {
  2888. console.debug((new Date().getTime() - start) + ' findSubject');
  2889. }
  2890. },
  2891. /* start lines */
  2892. standardLine : function(label, x1, y1, x2, y2, canvas, toId) {
  2893. // eseguo i calcoli e scrivo la riga di connessione tra i cerchi
  2894. var lineangle = (Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI) + 180;
  2895. var x2bis = x1 - Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) + 60;
  2896. // canvas.detectPixelRatio();
  2897. canvas.rotateCanvas({
  2898. rotate : lineangle,
  2899. x : x1,
  2900. y : y1
  2901. }).drawLine({
  2902. strokeStyle : "#fff",
  2903. strokeWidth : 1,
  2904. strokeCap : 'bevel',
  2905. x1 : x1 - 60,
  2906. y1 : y1,
  2907. x2 : x2bis,
  2908. y2 : y1
  2909. });
  2910. if (lineangle > 90 && lineangle < 270) {
  2911. canvas.rotateCanvas({
  2912. rotate : 180,
  2913. x : (x2bis + x1) / 2,
  2914. y : (y1 + y1) / 2
  2915. });
  2916. }
  2917. label = $.trim(label).replace(/\n/g, ', ');
  2918. canvas.drawText({// inserisco l'etichetta
  2919. fillStyle : "#606060",
  2920. strokeStyle : "#606060",
  2921. x : (x2bis + x1 + ((x1 + 60) > x2 ? -60 : +60)) / 2,
  2922. y : (y1 + y1 - ((x1 + 60) > x2 ? 18 : -18)) / 2,
  2923. text : ((x1 + 60) > x2 ? " « " : "") + label + ((x1 + 60) > x2 ? "" : " » "),
  2924. align : "center",
  2925. strokeWidth : 0.01,
  2926. fontSize : 11,
  2927. fontFamily : "'Open Sans',Verdana"
  2928. }).restoreCanvas().restoreCanvas();
  2929. // ed inserisco la freccia per determinarne il verso della
  2930. // relazione
  2931. lineangle = Math.atan2(y2 - y1, x2 - x1);
  2932. var angle = 0.79;
  2933. var h = Math.abs(8 / Math.cos(angle));
  2934. var fromx = x2 - 60 * Math.cos(lineangle);
  2935. var fromy = y2 - 60 * Math.sin(lineangle);
  2936. var angle1 = lineangle + Math.PI + angle;
  2937. var topx = (x2 + Math.cos(angle1) * h) - 60 * Math.cos(lineangle);
  2938. var topy = (y2 + Math.sin(angle1) * h) - 60 * Math.sin(lineangle);
  2939. var angle2 = lineangle + Math.PI - angle;
  2940. var botx = (x2 + Math.cos(angle2) * h) - 60 * Math.cos(lineangle);
  2941. var boty = (y2 + Math.sin(angle2) * h) - 60 * Math.sin(lineangle);
  2942. canvas.drawLine({
  2943. strokeStyle : "#fff",
  2944. strokeWidth : 1,
  2945. x1 : fromx,
  2946. y1 : fromy,
  2947. x2 : botx,
  2948. y2 : boty
  2949. });
  2950. canvas.drawLine({
  2951. strokeStyle : "#fff",
  2952. strokeWidth : 1,
  2953. x1 : fromx,
  2954. y1 : fromy,
  2955. x2 : topx,
  2956. y2 : topy
  2957. });
  2958. }
  2959. }
  2960. /* end lines */;
  2961. $.fn.lodlive = function(method) {
  2962. if (methods[method]) {
  2963. return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
  2964. } else if ( typeof method === 'object' || !method) {
  2965. return methods.init.apply(this, arguments);
  2966. } else {
  2967. $.error('Method ' + method + ' does not exist on jQuery.lodlive');
  2968. }
  2969. };
  2970. })(jQuery, $.jStorage.get('profile'));