main.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. $(document).ready(function() {
  2. console.log("ready");
  3. var _current_pages = 0,
  4. _page_left_bg, _page_right_bg,
  5. _$page_left = $('#page-left'), _$page_right = $('#page-right'),
  6. _$overlay_left = $('#page-left .overlay'), _$overlay_right = $('#page-right .overlay'),
  7. _$maps_left = $('#page-left .maps'), _$maps_right = $('#page-right .maps'),
  8. _bgs_prefix = "images/pages/";
  9. // ____ _ __
  10. // / _/___ (_) /_
  11. // / // __ \/ / __/
  12. // _/ // / / / / /_
  13. // /___/_/ /_/_/\__/
  14. function init(){
  15. console.log("init", _PAGES[0].bg);
  16. initkeyboard();
  17. changePages();
  18. };
  19. // ____
  20. // / __ \____ _____ ____ _____
  21. // / /_/ / __ `/ __ `/ _ \/ ___/
  22. // / ____/ /_/ / /_/ / __(__ )
  23. // /_/ \__,_/\__, /\___/____/
  24. // /____/
  25. function nextPages(){
  26. if(_current_pages < _PAGES.length-2){
  27. _current_pages+=2;
  28. changePages();
  29. }
  30. };
  31. function prevPages(){
  32. if(_current_pages > -1){
  33. _current_pages-=2;
  34. changePages();
  35. }
  36. };
  37. function changePages(){
  38. console.log("changePages");
  39. _page_left_bg = _bgs_prefix+_PAGES[_current_pages].bg;
  40. _page_right_bg = _bgs_prefix+_PAGES[_current_pages+1].bg;
  41. console.log(_page_left_bg+" | "+_page_right_bg);
  42. _$page_left
  43. .css({'background-image': "url("+_page_left_bg+")"})
  44. .removeClass(pageClassToRemove)
  45. .addClass('page-'+_current_pages);
  46. _$page_right
  47. .css({'background-image': "url("+_page_right_bg+")"})
  48. .removeClass(pageClassToRemove)
  49. .addClass('page-'+(_current_pages+1));
  50. updatePagesOverlays();
  51. };
  52. function pageClassToRemove(){
  53. var c = $(this).attr('class').match(/page-+\d+/);
  54. if(c && c.length)
  55. return c[0];
  56. };
  57. function updatePagesOverlays(){
  58. console.log("updatePagesOverlays");
  59. // remove all pages overlays
  60. $('.overlay, .maps',_$page_left).children().remove();
  61. $('.overlay, .maps',_$page_right).children().remove();
  62. console.log("Overlays", _PAGES[_current_pages].overlays);
  63. // build page_left overlays
  64. for (var map in _PAGES[_current_pages].overlays) {
  65. if (_PAGES[_current_pages].overlays.hasOwnProperty(map)) {
  66. map = _PAGES[_current_pages].overlays[map];
  67. console.log("Map",map);
  68. _$maps_left.append(
  69. $('<div>')
  70. .addClass("map")
  71. .attr('overlay', map.over)
  72. .css({
  73. "left":map.x,
  74. "top":map.y,
  75. "width":map.w,
  76. "height":map.h
  77. })
  78. .bind("mouseover", function(e){
  79. $(this)
  80. .parents('.page').find('.overlay')
  81. .css({
  82. // 'background-color':"red",
  83. 'background-image':'url(images/vectos/'+$(this).attr('overlay')+')'
  84. });
  85. })
  86. );
  87. }
  88. }
  89. };
  90. // __ __ __ __
  91. // / //_/__ __ __/ /_ ____ ____ __________/ /
  92. // / ,< / _ \/ / / / __ \/ __ \/ __ `/ ___/ __ /
  93. // / /| / __/ /_/ / /_/ / /_/ / /_/ / / / /_/ /
  94. // /_/ |_\___/\__, /_.___/\____/\__,_/_/ \__,_/
  95. // /____/
  96. function initkeyboard(){
  97. keyboardJS.bind('right', function(event) {
  98. // console.log(event);
  99. nextPages();
  100. });
  101. keyboardJS.bind('left', function(event) {
  102. // console.log(event);
  103. prevPages();
  104. });
  105. };
  106. init();
  107. });