The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
add menu item: go to page... unless I'm already on that page
#1
Hi,

I want ot add a new item to the navigation bar (using db based navigation), that navigates to a particular page, unless the user is already on that page, in which case it should just run some javascript function.


I guess the link could call a function that parses the page URL and decides based on that - but neiter I'm sure how to do htis, nor do I know if there's a better / more idiomatic solution.

Sorry if this is a dumb beginners question, looks like I am Wink

tia
  Reply
#2
It's not a dumb question. It's actually a good idea, but something I don't think is possible in the current db nav.

Can you give me an idea of the type of js you want to run and I will see if there is a workaround I can think of?
  Reply
#3
The link should take you to a page with a map (leaflet), and ping the current location, or just ping the current location when already on that page.

So roughly

if (already on landing page)
{
locate();
}
else
{
window.location='<?=$abs_us_root.$us_url_root?>app.php';
// will run locate() in e.g. onload
}

Where locate is to center map on current location and draw a temporary circle,

function locate()
{
map.locate({setView: true, maxZoom: 16});
// triggers more stuff in onLocationFound if location sharing is enabled
}


----

as for workarounds, is it possible to have two identical looking links, one that's visible on the app page and just calls the locate() function, the other visible on all other pages and linking to the app page normally?

Maybe just allow to give the menu items an id='...', so I can show/hide them dynamically
  Reply
#4
(11-20-2018, 11:57 PM)peterchen Wrote: The link should take you to a page with a map (leaflet), and ping the current location, or just ping the current location when already on that page.

So roughly  

if (already on landing page)
{
   locate();
}
else
{
   window.location='<?=$abs_us_root.$us_url_root?>app.php';
   // will run locate() in e.g. onload
}

Where locate is to center map on current location and draw a temporary circle,

function locate()
{
   map.locate({setView: true, maxZoom: 16});
   // triggers more stuff in onLocationFound if location sharing is enabled
}


----

as for workarounds, is it possible to have two identical looking links, one that's visible on the app page and just calls the locate() function, the other visible on all other pages and linking to the app page normally?

Maybe just allow to give the menu items an id='...', so I can show/hide them dynamically

I'm wondering if instead of an id if you can put a unique class on each one in the "icon" class section of the menu builder. I'm out of town at the moment so I'm not able to do a lot of testing, but with jquery you should be able to either target that class or something like a.nearest to target the closest link to that unique class.
  Reply
#5
(11-21-2018, 12:54 AM)mudmin Wrote:
(11-20-2018, 11:57 PM)peterchen Wrote: The link should take you to a page with a map (leaflet), and ping the current location, or just ping the current location when already on that page.

...

I'm wondering if instead of an id if you can put a unique class on each one in the "icon" class section of the menu builder. I'm out of town at the moment so I'm not able to do a lot of testing, but with jquery you should be able to either target that class or something like a.nearest to target the closest link to that unique class.

Yes, this works:

I add one (!) menu item, with a custom class 'menu-wai' on the icon class, and then, on the landing page, in ready(), I attach the onclick handler to $('.menu-wai').parent()

This feels a bit dirty-ish,as it requires the item to have an icon, and that icon being a tag inside the 'a', but I'm fine with that. Thank you!
  Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)