main.js 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  1. /**
  2. * @author Lukas Goldschmidt
  3. * @projectDescription A 3D Interface to Wikipeda,
  4. showcasing HTML5, WebGL, Three.js, JQuery-UI andseveral APIs.
  5. * @fileOverview A 3D Interface to Wikipeda,
  6. showcasing HTML5, WebGL, Three.js, JQuery-UI andseveral APIs.
  7. * @name wiki_browser
  8. * @version 0.1
  9. */
  10. /**
  11. * @namespace LG
  12. * @desc Namespace of Lukas Goldschmidt
  13. */
  14. /**
  15. * @namespace LG.wb
  16. * @desc Namespace of Wikipedia 3D Browser 2011
  17. */
  18. /**
  19. * Holds all Classes of Wikipedia 3D Browser 2011
  20. * @namespace LG.wb.Class
  21. */
  22. Namespace.Manager.Register("LG.wb.Class");
  23. /*
  24. * @namespace LG.wb.App
  25. * @desc Holds all Instances of Classes in the Wikipedia 3D Browser 2011
  26. */
  27. Namespace.Manager.Register("LG.wb.App");
  28. /**
  29. * Shows the given error message in the browser.
  30. * @param msg Error message to show in the browser.
  31. */
  32. function handleError(msg) {
  33. alert('ERROR: ' + msg);
  34. }
  35. LG.wb.Class.Browser = new Class(/** @lends LG.wb.Class.Browser.prototype */
  36. {
  37. /** a maximum value for elements */
  38. maxele : 3,
  39. /** a maximum value for x position */
  40. maxx : 950,
  41. /** a maximum value for y position */
  42. miny : -950,
  43. /** initial value for x position */
  44. ini_xpos : -850,
  45. /** initial value for y position */
  46. ini_ypos : 850,
  47. /** initial value for z position */
  48. ini_zpos : 0,
  49. xpos : -850,
  50. ypos : 850,
  51. zpos : 0,
  52. xdis : 411,
  53. ydis : 411,
  54. zdis : 500,
  55. /** FavMe Icon Image */
  56. favmeUrl : '/wikipedia3d/images/Favorite-icon.png',
  57. /** DelMe Icon Image */
  58. delmeUrl : '/wikipedia3d/images/Remove-icon.png',
  59. /** BlMe Icon Image */
  60. blmeUrl : '/wikipedia3d/images/blacklist.png',
  61. /** SoloMe Icon Image */
  62. solomeUrl : '/wikipedia3d/images/eye-icon.png',
  63. /** object to hold our item instances */
  64. items : {},
  65. /** array to hold our item ids in sequence */
  66. items_ref : [],
  67. /** array for clickable items */
  68. click_items : [],
  69. /** array for favourite items */
  70. fav_items : [],
  71. /** array for blacklisted items */
  72. bl_items : [],
  73. sky : [],
  74. /**
  75. * @class LG.wb.Class.Browser
  76. * The Main Object containing the central logic framework .
  77. * @member LG.wb.Class.Browser
  78. * @param {Object} ele
  79. * @param {int} width
  80. * @param {int} height
  81. * @constructs LG.wb.Class.Browser
  82. */
  83. initialize : function(ele, width, height) {
  84. this.width = width;
  85. this.height = height;
  86. // Update proportions
  87. this.resized();
  88. this.isShiftDown = false;
  89. this.cur_lang = DEF_LANG;
  90. this.alurl = 'http://access.alchemyapi.com/calls/url/URLGetRankedNamedEntities';
  91. this.wpurl = 'http://' + DEF_LANG + '.wikipedia.org/w/api.php';
  92. this.proxyurl = "/proxy?mode=native&url=";
  93. this.proxyurl_json = "/proxy?url=";
  94. //this.img_url = "http://www.world.eu.org/~lucky/wiki_browser/imgsrch.php?wpage=";
  95. // this.dbp_onto_url = "http://www.world.eu.org/~lucky/wiki_browser/dbpedia.ontology.owx"; // URL of the ontology
  96. this.dbp_onto_url = "/dbpedia.ontology.owx";
  97. // URL of the ontology
  98. if($.Storage.get("skydir") != undefined){
  99. this.bg_dir = $.Storage.get("skydir");
  100. }else{
  101. this.bg_dir = "images/cube/night_1/";
  102. }
  103. if($.Storage.get("maxTypeFetch") != undefined){
  104. this.maxTypeFetch = $.Storage.get("maxTypeFetch");
  105. }else{
  106. this.maxTypeFetch = 128;
  107. }
  108. $("#maxtypefetch").val(this.maxTypeFetch);
  109. this.projector = new THREE.Projector();
  110. // this.renderer = new THREE.CanvasRenderer();
  111. this.renderer = new THREE.WebGLRenderer();
  112. var that = this;
  113. // Google Maps Initialization finished
  114. // Ontology Initialization
  115. var text = ungzip(wStr);
  116. var onto = jsw.owl.xml.parse(text, handleError);
  117. // this.dbp_onto = jsw.owl.xml.parseUrl(this.dbp_onto_url , handleError);
  118. // console.log(text);
  119. // console.log(onto);
  120. try {
  121. this.reasoner = new jsw.owl.BrandT(onto);
  122. } catch (ex) {
  123. handleError(ex);
  124. }
  125. // Onto Ini Finished
  126. this.renderer.setSize(this.width, this.height);
  127. ele.innerHTML = "";
  128. ele.appendChild(this.renderer.domElement);
  129. ele.onBlur = function() {
  130. LG.wb.App.Browser.camera.isShiftDown = false;
  131. };
  132. this.ctarget = new THREE.Object3D();
  133. this.ctarget.position.x = 0;
  134. this.ctarget.position.y = 0;
  135. this.ctarget.position.z = 0;
  136. // this.camera = new LG.FirstPersonCamera({
  137. this.camera = new LG.THREE.FirstPersonCamera({
  138. fov : 33,
  139. aspect : this.width / this.height,
  140. near : 1,
  141. far : 30000,
  142. target : this.ctarget,
  143. lookSpeed : 1.8,
  144. movementSpeed : 220,
  145. noFly : true,
  146. activeLook : false,
  147. domElemnt : this.renderer.domElement,
  148. verticalMin : Math.PI * 0.35,
  149. verticalMax : Math.PI * 0.65
  150. });
  151. this.camera.Browser = this;
  152. // this.camera.position.z = 1900;
  153. this.camera.position.x = 300;
  154. this.camera.position.y = 0;
  155. this.camera.position.z = 340;
  156. this.camera.lon = 180;
  157. this.camera.constrainVertical = true;
  158. this.scene = new THREE.Scene();
  159. // this.scene.fog = new THREE.FogExp2( 0xffffff, 0.002 );
  160. // this.scene.fog = new THREE.Fog( 0xffffff, 30,10000 );
  161. this.ray = new THREE.Ray(this.camera.position, null)
  162. this.pointLight = new THREE.PointLight(0xFFFFFF);
  163. this.pointLight.position.x = 300;
  164. this.pointLight.position.y = 1000;
  165. this.pointLight.position.z = 630;
  166. this.scene.addLight(this.pointLight);
  167. this.texture_placeholder = document.createElement('canvas');
  168. this.texture_placeholder.width = 128;
  169. this.texture_placeholder.height = 128;
  170. var context = this.texture_placeholder.getContext('2d');
  171. context.fillStyle = 'rgb( 200, 200, 200 )';
  172. context.fillRect(0, 0, this.texture_placeholder.width, this.texture_placeholder.height);
  173. var that = this;
  174. $.each(BG_ARR, function(key, val) {
  175. var materials = [that.loadTexture(val + 'px.jpg'), // right 2
  176. that.loadTexture(val + 'nx.jpg'), // left 4
  177. that.loadTexture(val + 'py.jpg'), // top 5
  178. that.loadTexture(val + 'ny.jpg'), // bottom 6
  179. that.loadTexture(val + 'pz.jpg'), // back 1
  180. that.loadTexture(val + 'nz.jpg') // front 3
  181. ];
  182. that.sky[val] = new THREE.Mesh( new THREE.CubeGeometry( 10000, 10000, 10000, 30, 30, 30, materials, true ), new THREE.MeshFaceMaterial() );
  183. that.sky[val].overdraw = true;
  184. that.sky[val].visible=false;
  185. that.scene.addObject( that.sky[val]);
  186. if(val == that.bg_dir){
  187. that.sky[val].visible=true;
  188. that.skycube=that.sky[val];
  189. }
  190. });
  191. // grid
  192. plane = new THREE.Mesh(new THREE.PlaneGeometry(2200, 2200, 20, 20), new THREE.MeshBasicMaterial({
  193. color : 0x339933,
  194. wireframe : true
  195. }));
  196. plane.rotation.x = -90 * Math.PI / 180;
  197. plane.position.y = -170;
  198. this.scene.addObject(plane);
  199. $("#ac").focus();
  200. this.resized();
  201. },
  202. setSkycube : function(skydir) {
  203. $.Storage.set({"skydir":skydir});
  204. this.sky[this.bg_dir].visible = false;
  205. this.bg_dir = skydir;
  206. this.sky[this.bg_dir].visible = true;
  207. this.skycube=this.sky[this.bg_dir];
  208. },
  209. setMaxtypefetch : function (val){
  210. $.Storage.set({"maxTypeFetch":val});
  211. this.maxTypeFetch = val;
  212. },
  213. setlang: function(lang){
  214. var url = false;
  215. for(var idx in this.wp_languages){
  216. if(this.wp_languages[idx].lang == lang){
  217. url = this.wp_languages[idx].url;
  218. }
  219. }
  220. if(url != false){
  221. this.wpurl = url + 'w/api.php';
  222. this.cur_lang = lang;
  223. }
  224. },
  225. resized : function() {
  226. var c = $("canvas:last");
  227. this.offset = c.offset();
  228. //console.log(this.offset);
  229. $("#dialog-message").dialog.height = window.innerHeight;
  230. },
  231. render : function() {
  232. for(index in this.items) {
  233. this.items[index].animate();
  234. }
  235. if(this.skycube !== undefined)
  236. this.skycube.position = this.camera.position;
  237. this.pointLight.position = this.camera.position;
  238. this.renderer.render(this.scene, this.camera);
  239. },
  240. animate : function() {
  241. requestAnimationFrame(LG.wb.App.Browser.animate);
  242. LG.wb.App.Browser.render();
  243. },
  244. reset : function() {
  245. //alert('reset pushed');
  246. var tmp = this.items;
  247. // remove from scene
  248. for(index in this.items) {
  249. this.remove(this.items[index]);
  250. }
  251. // empty array
  252. this.items = {};
  253. this.click_items = [];
  254. this.items_ref = [];
  255. this.xpos = this.ini_xpos;
  256. this.ypos = this.ini_ypos;
  257. this.zpos = this.ini_zpos;
  258. document.getElementById('mapFrame').contentWindow.clearMarkers();
  259. $("#ac").val('');
  260. this.render();
  261. $("#ac").focus();
  262. },
  263. /**
  264. * Show the full text of the wikipage, some text
  265. * @param (Object) item an Instance of the Class LG.wb.Class.Item
  266. */
  267. showFullText : function(item) {
  268. var Browser = this;
  269. $("body").css("cursor", "wait");
  270. Browser.dialogOpen = true;
  271. if(item.parsedText == undefined || item.parsedText == ""){
  272. if(item.text){
  273. $("#dialog-message").html(item.text);
  274. $("#dialog-message a[href^='\/wiki\/']").each(function() {
  275. var wpage = this.href.substr(this.href.lastIndexOf("/") + 1);
  276. this.onclick = function() {
  277. Browser.load(decodeURIComponent(wpage));
  278. $("#dialog-message").dialog("close");
  279. };
  280. // this.href = 'javascript:LG.wb.App.Browser.load("' + wpage + '"); $("#dialog-message").dialog("close");return false;';
  281. this.href = "#";
  282. });
  283. $("#dialog-message a[href^='\/w\/']").each(function() {
  284. this.href = '#';
  285. }).css('color', '#333333');
  286. // $("#dialog-message td").each(function() {
  287. // if(this.css('background-color') == "#f2f2f4"){
  288. // this.css('background-color', '#020204');
  289. // }
  290. // });
  291. $("#dialog-message a[href^='http']").each(function() {
  292. this.target = '_blank';
  293. this.onclick = 'javascript: $("#dialog-message").dialog("close");';
  294. });
  295. item.parsedText = $("#dialog-message").html();
  296. }else{
  297. $("body").css("cursor", "default");
  298. return;
  299. }
  300. } else{
  301. $("#dialog-message").html(item.parsedText);
  302. }
  303. $("#dialog-message").dialog("option", "height", window.innerHeight);
  304. $("#dialog-message").dialog("option", "title", item.wpage);
  305. $("body").css("cursor", "default");
  306. Browser.setlang(item.lang);
  307. $("#dialog-message").dialog('open');
  308. },
  309. /**
  310. * makes an item a favorite item
  311. * @param {Object} item a LG.wb.Class.Item
  312. */
  313. makeFav : function (item){
  314. var l_item={
  315. wpage:encodeURI(item.wpage),
  316. id:Sha1.hash(item.lang + "_" + item.wpage.replace(/[\s\,]/g,"_")),
  317. lang:item.lang,
  318. img:item.images[0],
  319. };
  320. // console.log(l_item);
  321. // console.log(this.fav_items);
  322. $("#tabs").tabs('select','tabs-Favourites');
  323. for ( var myi in this.fav_items){
  324. if(this.fav_items[myi].id == l_item.id){
  325. console.log(this.fav_items[myi].id);
  326. return false ;
  327. }
  328. }
  329. this.fav_items.push(l_item);
  330. $('#favs').append('<div title="' + l_item.lang + " " + decodeURI(l_item.wpage) + '" id="' + l_item.id + '" style="float:left;display:inline;margin:4px;"></div>');
  331. $( "#" + l_item.id ).append('<span style="background: #333 url(css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png) 50% 50% repeat-x;" >' + decodeURI(l_item.wpage) + '</span><br />');
  332. $( "#" + l_item.id ).append('<div style="background: black url(css/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png) 50% bottom repeat-x;"><img src="' + l_item.img + '" width="64" height="64"></div>');
  333. /// $( "#" + l_item.id ).append('<div style="clear: both;"></div>');
  334. // $( "#favs").append('<div style="clear: both;"></div>');
  335. $( "#" + l_item.id ).draggable({ revert: false, helper: "clone" });
  336. this.saveLists();
  337. },
  338. /**
  339. * makes an item a blacklisted item
  340. * @param {Object} item a LG.wb.Class.Item
  341. */
  342. makeBL : function (item){
  343. var l_item={
  344. wpage:encodeURI(item.wpage),
  345. id:Sha1.hash(item.lang + "_" + item.wpage.replace(/[\s\,]/g,"_")),
  346. lang:item.lang,
  347. img:item.images[0],
  348. };
  349. console.log(l_item);
  350. // console.log(this.fav_items);
  351. this.remove(item);
  352. $("#tabs").tabs('select','tabs-Blacklist');
  353. for ( var myi in this.fav_items){
  354. if(this.fav_items[myi].id == l_item.id){
  355. console.log("Already favorite : " + this.fav_items[myi].id);
  356. return false ;
  357. }
  358. }
  359. for ( var myi in this.bl_items){
  360. if(this.bl_items[myi].id == l_item.id){
  361. console.log("Already Blacklisted : " + this.bl_items[myi].id);
  362. return false ;
  363. }
  364. }
  365. this.bl_items.push(l_item);
  366. $('#blstd').append('<div title="' + l_item.lang + " " + decodeURI(l_item.wpage) + '" id="' + l_item.id + '" style="float:left;display:inline;margin:4px;"></div>');
  367. $( "#" + l_item.id ).append('<span style="background: #333 url(css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png) 50% 50% repeat-x;" >' + decodeURI(l_item.wpage) + '</span><br />');
  368. // $( "#" + l_item.id ).append('<div style="background: black url(images/ui-bg_inset-soft_25_000000_1x100.png) 50% bottom repeat-x;"><img src="' + l_item.img + '" width="64" height="64"></div>');
  369. /// $( "#" + l_item.id ).append('<div style="clear: both;"></div>');
  370. // $( "#favs").append('<div style="clear: both;"></div>');
  371. $( "#" + l_item.id ).draggable({ revert: false, helper: "clone" });
  372. this.saveLists();
  373. },
  374. saveLists : function (){
  375. // serialize^
  376. // local store ...
  377. $.Storage.set("favs", serialize(this.fav_items));
  378. $.Storage.set("blstd", serialize(this.bl_items));
  379. },
  380. loadLists : function (){
  381. if($.Storage.get("favs") !== undefined){
  382. var list = unserialize($.Storage.get("favs"));
  383. this.fav_items = new Array();
  384. for (var idx in list){
  385. var l_item = list[idx];
  386. this.fav_items.push(l_item);
  387. $('#favs').append('<div title="' + l_item.lang + " " + decodeURI(l_item.wpage) + '" id="' + l_item.id + '" style="float:left;display:inline;margin:4px;"></div>');
  388. $( "#" + l_item.id ).append('<span style="background: #333 url(css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png) 50% 50% repeat-x;" >' + decodeURI(l_item.wpage) + '</span><br />');
  389. $( "#" + l_item.id ).append('<div style="background: black url(css/ui-darkness/images/ui-bg_inset-soft_25_000000_1x100.png) 50% bottom repeat-x;"><img src="' + l_item.img + '" width="64" height="64"></div>');
  390. $( "#" + l_item.id ).draggable({ revert: false, helper: "clone" });
  391. }
  392. }
  393. if($.Storage.get("blstd") !== undefined){
  394. var list = unserialize($.Storage.get("blstd"));
  395. this.bl_items = new Array();
  396. for (var idx in list){
  397. var l_item = list[idx];
  398. this.bl_items.push(l_item);
  399. $('#blstd').append('<div title="' + l_item.lang + " " + decodeURI(l_item.wpage) + '" id="' + l_item.id + '" style="float:left;display:inline;margin:4px;"></div>');
  400. $( "#" + l_item.id ).append('<span style="background: #333 url(css/ui-darkness/images/ui-bg_gloss-wave_25_333333_500x100.png) 50% 50% repeat-x;" >' + decodeURI(l_item.wpage) + '</span><br />');
  401. // $( "#" + l_item.id ).append('<div style="background: black url(images/ui-bg_inset-soft_25_000000_1x100.png) 50% bottom repeat-x;"><img src="' + l_item.img + '" width="64" height="64"></div>');
  402. $( "#" + l_item.id ).draggable({ revert: false, helper: "clone" });
  403. }
  404. }
  405. },
  406. removeFav : function (id){
  407. for ( var myi in this.fav_items){
  408. if(this.fav_items[myi].id == id){
  409. var ci = this.fav_items.indexOf(this.fav_items[myi]);
  410. this.fav_items.splice(ci,1);
  411. $("#" + id).remove();
  412. this.saveLists();
  413. return true;
  414. }
  415. }
  416. return false;
  417. },
  418. /**
  419. * load a favorite item into the Browser
  420. * @param {String} id hash id of the item
  421. */
  422. loadFav : function (id){
  423. for ( var myi in this.fav_items){
  424. if(this.fav_items[myi].id == id){
  425. console.log("Loading " + this.fav_items[myi].id);
  426. var lang = $("#langsel option:selected").val();
  427. this.setlang( this.fav_items[myi].lang);
  428. this.load(decodeURI(this.fav_items[myi].wpage));
  429. this.setlang(lang);
  430. if(lang != this.fav_items[myi].lang){
  431. $(document).oneTime(1800, "translate", function() {
  432. if (LG.wb.App.Browser.items[id].langlinks[lang] != undefined) {
  433. var link = LG.wb.App.Browser.items[id].langlinks[lang];
  434. var _wpage = link.substring(link.lastIndexOf("/")+1);
  435. LG.wb.App.Browser.load(decodeURI(_wpage));
  436. };
  437. });
  438. };
  439. return true;
  440. }
  441. }
  442. return false;
  443. },
  444. removeBL : function (id){
  445. for ( var myi in this.bl_items){
  446. if(this.bl_items[myi].id == id){
  447. var ci = this.bl_items.indexOf(this.bl_items[myi]);
  448. this.bl_items.splice(ci,1);
  449. $("#" + id).remove();
  450. this.saveLists();
  451. return true;
  452. }
  453. }
  454. return false;
  455. },
  456. showTypeLinks : function (item, type){
  457. var Browser = this;
  458. $("#dialog-busy").dialog("open");
  459. Browser.dialogOpen = true;
  460. if(item.yago_type_links[type] !== undefined && item.yago_type_links[type].length > 0 ) {
  461. item.yago_type_links[type].sort();
  462. var el = $( document.createElement('div') );
  463. el.append('<h2>'+ type +'</h2>');
  464. for (var i = item.yago_type_links[type].length - 1; i >= 0; i--){
  465. el.append('<a href="#" onclick="LG.wb.App.Browser.load(\''+ item.yago_type_links[type][i]['label'].value +'\'); $(\'#dialog-message\').dialog(\'close\');" title="'+ item.yago_type_links[type][i]['abstract'].value +'" >'+item.yago_type_links[type][i]['label'].value+'</a> | ');
  466. };
  467. }
  468. var txt = el.html();
  469. $("#dialog-message").html(txt);
  470. $("#dialog-message").dialog("option", "title", type);
  471. $("#dialog-message").dialog("option", "height", window.innerHeight);
  472. $("#dialog-busy").dialog("close");
  473. Browser.setlang(item.lang);
  474. $("#dialog-message").dialog("open");
  475. },
  476. showCatLinks : function (item, cat){
  477. var Browser = this;
  478. $("#dialog-busy").dialog("open");
  479. Browser.dialogOpen = true;
  480. if(item.cat_links[cat] !== undefined && item.cat_links[cat].length > 0 ) {
  481. item.cat_links[cat].sort();
  482. var el = $( document.createElement('div') );
  483. el.append('<h2>'+ cat +'</h2>');
  484. for (var i = item.cat_links[cat].length - 1; i >= 0; i--){
  485. el.append('<a href="#" onclick="LG.wb.App.Browser.load(\''+ item.cat_links[cat][i] +'\'); $(\'#dialog-message\').dialog(\'close\');">'+item.cat_links[cat][i]+'</a> | ');
  486. };
  487. }
  488. var txt = el.html();
  489. $("#dialog-message").html(txt);
  490. $("#dialog-message").dialog("option", "height", window.innerHeight);
  491. $("#dialog-message").dialog("option", "title", cat);
  492. $("#dialog-busy").dialog("close");
  493. Browser.setlang(item.lang);
  494. $("#dialog-message").dialog("open");
  495. },
  496. loadTexture : function(path) {
  497. var texture = new THREE.Texture(this.texture_placeholder), material = new THREE.MeshBasicMaterial({
  498. map : texture
  499. }), image = new Image();
  500. image.onload = function() {
  501. texture.needsUpdate = true;
  502. material.map.image = this;
  503. // this.render();
  504. };
  505. image.src = path;
  506. return material;
  507. },
  508. remove: function(item){
  509. if(this.items[item.hashid] !== undefined ) {
  510. for(var i in item.click_items){
  511. var ci = this.click_items.indexOf(item.click_items[i]);
  512. if(ci !== -1){
  513. this.click_items.splice(ci,1);
  514. }
  515. }
  516. var idx = this.items_ref.indexOf(item.hashid);
  517. this.items_ref.splice(idx,1);
  518. this.scene.removeObject(item.model);
  519. delete(this.items[item.hashid]);
  520. item.model = null;
  521. delete(item);
  522. } else {
  523. return false;
  524. }
  525. },
  526. toPrev : function() {
  527. var idx = this.items_ref.indexOf(this.cur_item_idx);
  528. idx += 1;
  529. if(idx > this.items_ref.length - 1) {
  530. idx = 0;
  531. }
  532. console.log("toNext - idx:" + idx + " id:" + this.items_ref[idx]);
  533. this.items[this.items_ref[idx]].panToMe();
  534. this.cur_item_idx = this.items_ref[idx];
  535. },
  536. toNext : function() {
  537. var idx = this.items_ref.indexOf(this.cur_item_idx);
  538. idx -= 1;
  539. if(idx < 0) {
  540. idx = this.items_ref.length - 1;
  541. }
  542. console.log("toPrev - idx:" + idx + " id:" + this.items_ref[idx]);
  543. this.items[this.items_ref[idx]].panToMe();
  544. this.cur_item_idx = this.items_ref[idx];
  545. },
  546. overView : function(){
  547. // var dest = new THREE.Vector3(this.model.position.x+80, this.model.position.y+30, this.model.position.z-380);
  548. if(this.cur_item_idx == undefined){
  549. var dest = new THREE.Vector3(0, 830, -1500);
  550. this.camera.panTo(dest,90,-72);
  551. }
  552. var idx = this.cur_item_idx;
  553. if(this.overview_toggle){
  554. this.overview_toggle = false;
  555. this.items[idx].panToMe();
  556. }else{
  557. this.overview_toggle = true;
  558. var dest = new THREE.Vector3(680, this.items[idx].model.position.y+530, this.items[idx].model.position.z-1180);
  559. this.camera.panTo(dest,116,-42);
  560. }
  561. },
  562. findPages : function(latLong){
  563. console.log(latLong.lat(), latLong.lng());
  564. var that = this;
  565. var url = "http://api.geonames.org/findNearbyWikipediaJSON";
  566. var param = "username=lgolds";
  567. param += "&maxRows=12";
  568. param += "&lng=" + latLong.lng();
  569. param += "&lat=" + latLong.lat();
  570. param += "&radius=12";
  571. param += "&lang=" + that.cur_lang;
  572. $.ajax({
  573. url : url,
  574. data : param,
  575. context : that,
  576. dataType : 'jsonp',
  577. success : function(data) {
  578. console.log(data);
  579. if(data.geonames !== undefined){
  580. var res=data.geonames;
  581. for(idx in res){
  582. that.load(res[idx].title);
  583. }
  584. }
  585. }
  586. });
  587. },
  588. load : function(wpage) {
  589. // take a wiki page and initialize an Item Object
  590. $("#ac").val('');
  591. $("#ac").blur();
  592. if(wpage.indexOf("#")>0)
  593. wpage = wpage.substring(0,wpage.indexOf("#"))
  594. var s = Sha1.hash(this.cur_lang + "_" + wpage.replace(/[\s\,]/g,"_"));
  595. // var s = str_clean(wpage);
  596. for ( var myi in this.bl_items){
  597. if(this.bl_items[myi].id == s){
  598. console.log(wpage + " is blacklisted ...." );
  599. return false;
  600. }
  601. }
  602. if(this.items[s] !== undefined){
  603. this.items[s].panToMe();
  604. return;
  605. }
  606. // item exists, bye
  607. this.items[s] = new LG.wb.Class.Item(this, wpage);
  608. // add geometry to scene
  609. this.scene.addObject(this.items[s].model);
  610. this.click_items = this.click_items.concat(this.items[s].click_items);
  611. // this.click_items.push(this.items[s].Label1);
  612. this.items[s].goTo(this.xpos, this.ypos, this.zpos);
  613. // this.items[s].panToMe();
  614. this.cur_item_idx = s;
  615. this.items_ref.push(s);
  616. this.camera.panTo(new THREE.Vector3(this.xpos+80, this.zpos+30, this.ypos-380),100,33);
  617. this.overview_toggle = false;
  618. // advance position
  619. this.xpos += this.xdis;
  620. if(this.xpos > this.maxx) {
  621. this.xpos = this.ini_xpos;
  622. this.ypos -= this.ydis;
  623. }
  624. if(this.ypos < this.miny) {
  625. this.xpos = this.ini_xpos;
  626. this.ypos = this.ini_ypos;
  627. this.zpos += this.zdis;
  628. }
  629. },
  630. });
  631. // End of LG.wb.Class.Browser
  632. include('js/wb_item.js');
  633. // Callbacks
  634. var ac_callback = function(data) {
  635. // part of the wikipedia Site restriction workaround
  636. $('#ac').autocomplete('option', 'source', data[1]);
  637. }
  638. // Helper
  639. function str_clean(str) {
  640. // make function name out of wiki page
  641. // return 'f_' + str.replace(/\W|\s/gi, "_");
  642. var out= "";
  643. for(var i = 0; i < str.length; i++) {
  644. out += str.charCodeAt(i).toString();
  645. }
  646. return out;
  647. }
  648. // user resized window
  649. function resizeUpdate() {
  650. LG.wb.App.Browser.resized();
  651. };
  652. var resizeTimer;
  653. $(window).resize(function() {
  654. clearTimeout(resizeTimer);
  655. resizeTimer = setTimeout(resizeUpdate, 100);
  656. });
  657. /* Execution starts here */
  658. $(document).ready(function() {
  659. if ( ! Detector.webgl ) {
  660. Detector.addGetWebGLMessage();
  661. return false;
  662. }
  663. /**
  664. * The object acts as a hub, and vontainer for items and such
  665. */
  666. LG.wb.App.Browser = new LG.wb.Class.Browser(document.getElementById('content'), 960, 480);
  667. // LG.wb.App.Browser.wpurl = 'http://de.wikipedia.org/w/api.php';
  668. // LG.wb.App.Browser.display('The_Beatles');
  669. // LG.wb.App.Browser.display('Bob_Marley');
  670. // LG.wb.App.Browser.display('Barack_Obama');
  671. // LG.wb.App.Browser.display('Star_Trek');
  672. // LG.wb.App.Browser.display('Stargate_Atlantis');
  673. $("#ac").autocomplete({
  674. source : function(request, response) {
  675. url = LG.wb.App.Browser.wpurl + "?action=opensearch&search=" + this.value + "&format=json&callback=ac_callback ";
  676. var elem = document.createElement('script');
  677. elem.setAttribute('src', url);
  678. elem.setAttribute('type', 'text/javascript');
  679. document.getElementsByTagName ('head')[0].appendChild(elem);
  680. response([]);
  681. },
  682. search : function(event, ui) {
  683. //url: 'http://en.wikipedia.org/w/api.php?action=opensearch',
  684. url = LG.wb.App.Browser.wpurl + "?action=opensearch&search=" + this.value + "&format=json&callback=ac_callback ";
  685. var elem = document.createElement('script');
  686. elem.setAttribute('src', url);
  687. elem.setAttribute('type', 'text/javascript');
  688. document.getElementsByTagName ('head')[0].appendChild(elem);
  689. return true;
  690. },
  691. // autoFocus:true,
  692. minLength : 2,
  693. position : {
  694. my : "left bottom",
  695. at : "left top"
  696. },
  697. select : function(event, ui) {
  698. LG.wb.App.Browser.load(ui.item.label);
  699. LG.wb.App.Browser.renderer.domElement.focus();
  700. }
  701. });
  702. $("#ac").click(self.focus());
  703. $("#dialog-message").dialog({
  704. maxHeight : window.innerHeight,
  705. draggable : true,
  706. minWidth : 800,
  707. autoOpen : false,
  708. modal : false,
  709. close : function(event, ui) {
  710. LG.wb.App.Browser.dialogOpen = false;
  711. LG.wb.App.Browser.setlang($("#langsel option:selected").val());
  712. },
  713. buttons : {
  714. Ok : function() {
  715. $(this).dialog("close");
  716. },
  717. }
  718. });
  719. $("#dialog-about").dialog({
  720. minWidth : 480,
  721. autoOpen : false,
  722. modal : true,
  723. close : function(event, ui) {
  724. LG.wb.App.Browser.dialogOpen = false;
  725. },
  726. buttons : {
  727. Ok : function() {
  728. $(this).dialog("close");
  729. }
  730. }
  731. });
  732. $("#dialog-busy").dialog({
  733. minWidth : 480,
  734. autoOpen : false,
  735. modal : false,
  736. });
  737. //
  738. $("#about").button({
  739. // text:false,
  740. icons : {
  741. primary : "ui-icon-help"
  742. }
  743. }).click(function() {
  744. LG.wb.App.Browser.dialogOpen = true;
  745. $("#dialog-about").dialog('open');
  746. });
  747. $("#reset").button({
  748. // text: false,
  749. icons : {
  750. primary : "ui-icon-document"
  751. }
  752. }).click(function() {
  753. LG.wb.App.Browser.reset();
  754. });
  755. $("#mapButton").button({
  756. // text: false,
  757. icons : {
  758. primary : "ui-icon-document"
  759. }
  760. }).click(function() {
  761. $( "#GMap" ).dialog('open');
  762. });
  763. // Language Selector
  764. var options = $("#langsel");
  765. LG.wb.App.Browser.wp_languages = wp_languages;
  766. $.each(LG.wb.App.Browser.wp_languages, function() {
  767. if(this.lang == DEF_LANG) {
  768. options.append($("<option selected />").val(this.lang).text(this.name));
  769. } else {
  770. options.append($("<option />").val(this.lang).text(this.name));
  771. }
  772. });
  773. options.change(function() {
  774. var lang = $("#langsel option:selected").val();
  775. LG.wb.App.Browser.setlang(lang);
  776. $.each(LG.wb.App.Browser.items, function(key,val){
  777. // lookup corresponding entries in selected language
  778. if (val.langlinks[lang] != undefined) {
  779. var link = val.langlinks[lang];
  780. var _wpage = link.substring(link.lastIndexOf("/")+1);
  781. LG.wb.App.Browser.load(decodeURI(_wpage));
  782. };
  783. });
  784. });
  785. // End of Language Selector
  786. // BG Selector
  787. var bgoptions = $("#bgsel");
  788. LG.wb.App.Browser.bg_arr = BG_ARR;
  789. $.each(LG.wb.App.Browser.bg_arr, function(name, url) {
  790. if(LG.wb.App.Browser.bg_dir == url) {
  791. bgoptions.append($("<option selected />").val(url).text(name));
  792. } else {
  793. bgoptions.append($("<option />").val(url).text(name));
  794. }
  795. });
  796. bgoptions.change(function() {
  797. // LG.wb.App.Browser.bg_url = $("#bgsel option:selected").val() ;
  798. LG.wb.App.Browser.setSkycube($("#bgsel option:selected").val());
  799. });
  800. // End of BG Selector
  801. $("#maxtypefetch").change(function(){
  802. LG.wb.App.Browser.setMaxtypefetch($(this).val());
  803. });
  804. //
  805. //
  806. $("#icon_help").append('<img src="'+LG.wb.App.Browser.delmeUrl+'" width="24" height="24" />: Delete Item, ');
  807. $("#icon_help").append('<img src="'+LG.wb.App.Browser.blmeUrl+'" width="24" height="24" />: Blacklist Item, ');
  808. $("#icon_help").append('<img src="'+LG.wb.App.Browser.favmeUrl+'" width="24" height="24" />: Favourite Item, ');
  809. $("#icon_help").append('<img src="'+LG.wb.App.Browser.solomeUrl+'" width="24" height="24" />: Solo Item, ');
  810. // Set up Fav Tab
  811. $("#tabs-Favourites").append('<h2>Favourites :</h2>');
  812. $("#tabs-Favourites").append('<div id="trash" style="display:inline;float:left;"><img src="images/trashcan.png"></div>');
  813. $("#tabs-Favourites").append('<div id="favs" style="overflow:scroll;height:160px"></div>');
  814. // Set up Blacklist Tab
  815. $("#tabs-Blacklist").append('<h2>Blacklisted :</h2>');
  816. $("#tabs-Blacklist").append('<div id="trash2" style="display:inline;float:left;"><img src="images/trash2.png"></div>');
  817. $("#tabs-Blacklist").append('<div id="blstd" style="overflow:scroll;height:160px"></div>');
  818. // set up the drop targets ...
  819. // trash
  820. $("#trash").droppable({
  821. drop: function( event, ui ) {
  822. if(confirm("Trash " + ui.draggable.context.title + " ??")){
  823. LG.wb.App.Browser.removeFav(ui.draggable.context.id);
  824. }
  825. },
  826. });
  827. // trash
  828. $("#trash2").droppable({
  829. drop: function( event, ui ) {
  830. if(confirm("Remove " + ui.draggable.context.title + " from blacklist ??")){
  831. LG.wb.App.Browser.removeBL(ui.draggable.context.id);
  832. }
  833. },
  834. });
  835. // 3d canvas as drop target
  836. $("#content").droppable({
  837. drop : function(event, ui) {
  838. // console.log(ui);
  839. LG.wb.App.Browser.loadFav(ui.draggable.context.id);
  840. }
  841. });
  842. $('#tabs-About').mouseover(function() {
  843. $(this).css('cursor', 'help');
  844. });
  845. // Activate Tabs
  846. $("#tabs").tabs();
  847. $('#tabs').css('display', 'block');
  848. LG.wb.App.Browser.loadLists();
  849. //
  850. $("#tabs-Favourites img").each(function(){
  851. var imgsrc = $(this).attr('src');
  852. // if(imgsrc.match('_th.jpg') || imgsrc.match('_home.jpg')){
  853. // imgsrc = thumbToLarge(imgsrc);
  854. (new Image()).src = imgsrc;
  855. // }
  856. });
  857. LG.wb.App.Browser.resized();
  858. LG.wb.App.Browser.animate();
  859. // open something or not ??
  860. if(DEF_WPAGE != '') {
  861. setTimeout(function(){
  862. LG.wb.App.Browser.load(DEF_WPAGE);
  863. }, 1000);
  864. }
  865. });