ccm_activateTabBar() not defined when not logged in

Permalink
I did build a component with tabs in concrete5 v8 with this tutorial, when logged in as administrator it works just fine, when not logged in the tabs wont work, it seems to be some kind of missing asset error.

For more details I submitted this stackoverflow post:
https://stackoverflow.com/questions/48789390/concrete5-ccm-activatet...

 
hutman replied on at Permalink Reply
hutman
It sounds like you're just missing the jquery ui asset. Do you have these two lines in your view function for the block?

$this->requireAsset('javascript', 'jquery');
$this->requireAsset('jquery/ui');
Om3s replied on at Permalink Reply
Yes as I stated in my stackoverflow post.

Meanwhile I got an comment there, that those tabs are not meant to use outside of editing mode, if this is true, is there a way to workaround without refactoring the component with custom code?
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Hi Om3s,

To use the concrete5 tabs JavaScript outside of the concrete5 interface, you would need to require app.js. I would not recommend this because app.js is a very large file.

The ccm_activateTabBar() method is part of concrete\js\build\core\app\tabs.js. The tab.js file is part of concrete\js\app.js.

A suggestion would be to write your own tab JS, extract and modify the core JS, or use a tab JS library.
Om3s replied on at Permalink Reply
Thank you very much, I just copied the tabs.js (which only contain that missing function) and bind it if the user is not logged in. Works like a charm
linuxoid replied on at Permalink Reply
linuxoid
I want to resurrect this thread as I still face this issue even if I'm logged in.

I've simply copied the tabs.js into my package and use this in the controller:
public function registerViewAssets($outputContent = '')
{
    $this->requireAsset('javascript', 'jquery');
    $this->requireAsset('javascript', 'jquery/ui');
    $this->requireAsset('javascript', 'bootstrap/tooltip');
    $this->requireAsset('css', 'jquery/ui');
    $this->requireAsset('css', 'bootstrap/tooltip');
}
public function view() {
$pkg = $this->app->make(PackageService::class)->getByHandle('my_package');
$site_user = $this->app->make(User::class);
if (!$site_user->isLoggedIn()) {
    $html = $this->app->make('helper/html');
    $this->addFooterItem($html->javascript($pkg->getRelativePath() . '/js/tabs.js'));
}

When I'm not logged in, it works fine. When I'm logged in as an admin, it works fine. But when I'm logged in as a user, it doesn't work! Aren't the same assets loaded loaded for admin and non-admin users? What should I change here to make the tabs work for non-admins?
linuxoid replied on at Permalink Reply
linuxoid
Ok, I got it. It does look indeed that a normal user gets different set of assets than a superuser.

This has fixed it:
if (!$site_user->isLoggedIn() || !$site_user->isSuperUser()) {