Advertisement
philmottin

custom_js.js

Jun 16th, 2018
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. Pages start at 0 and go to 9
  3. Objects named 'show.pageN' where N is a number from 0-9 will show page N when clicked
  4. Objects named 'show.toggle' will cycle through all pages
  5. Layers in the SVG should be named page0-page9
  6. page0 is the default starting page
  7. */
  8. $( document ).on( "floorplan:loaded", function( event, arg, svg ) {
  9. //initial page
  10. var currentPage = 0;
  11. var pages = [];
  12.  
  13. //console.log(svg);
  14. for (var x=0;x<10;x++){
  15.     let page = $(svg).find(`[id="page${x}"]`)
  16.     if (page.length === 1)
  17.         pages.push(page);
  18. }
  19.  
  20. function showPage(pageToShow=0){
  21.     $.each(pages, function(n, pg){
  22.         if (n === pageToShow){
  23.             $(pg).show();
  24.             currentPage = pageToShow;
  25.         }else{
  26.             $(pg).hide();
  27.         }
  28.     });
  29. }
  30.  
  31. showPage(currentPage);
  32.  
  33. $.each($(svg).find("[id^='display.']"), function(i, e){
  34.                             $(e).css('cursor', 'pointer');
  35.     $(e).click(function() {
  36.         var pageName = $(e).attr('id').split('.')[1];
  37.         if (pageName === "toggle"){
  38.             currentPage++;
  39.             if (currentPage >= pages.length) currentPage = 0;
  40.             showPage(currentPage);
  41.         }else{
  42.             let pageNumber = pageName.replace('page','');
  43.             showPage(parseInt(pageNumber));
  44.         }
  45.     });
  46. });
  47.  
  48. $.each($(svg).find("[id^='show.']"), function(i, e){
  49.                             $(e).css('cursor', 'pointer');
  50.     $(e).click(function() {
  51.         var pageName = $(e).attr('id').split('.')[1];
  52.         if (pageName === "toggle"){
  53.             currentPage++;
  54.             if (currentPage >= pages.length) currentPage = 0;
  55.             showPage(currentPage);
  56.         }else{
  57.             let pageNumber = pageName.replace('page','');
  58.             showPage(parseInt(pageNumber));
  59.         }
  60.     });
  61. });
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement