Skip to content

[fix] Bug in setting startOffset to tabs - using localStorage all the time#6080

Merged
roland-d merged 1 commit intojoomla:stagingfrom
gunjanpatel:tabsFix
May 6, 2015
Merged

[fix] Bug in setting startOffset to tabs - using localStorage all the time#6080
roland-d merged 1 commit intojoomla:stagingfrom
gunjanpatel:tabsFix

Conversation

@gunjanpatel
Copy link
Copy Markdown
Contributor

To reproduce the issue

Do this before applyting patch

Add the following code in any joomla template file (for example: <any-component>/views/tmpl/default.php)

// We are setting start offset to 2 and setting browser storage to false
$options = array(
    'startOffset' => 2,
    'useCookie'   => false
);

echo JHtml::_('tabs.start', 'pane', $options);

echo JHtml::_('tabs.panel', "Tab1", 'tab1');

    echo "Tab1 content";

echo JHtml::_('tabs.panel', 'Tab2', 'tab2');

    echo "Tab2 content";

echo JHtml::_('tabs.panel', 'Tab3', 'tab3');

    echo "Tab3 content";

echo JHtml::_('tabs.panel', 'Tab4', 'tab4');

    echo "Tab4 content";
echo JHtml::_('tabs.end');

Ideally you should have open Tab3 as we have set offset to 2. Now, if you have Tab1 as selected then select Tab2 and simply refresh the page. We have disabled the broweser storage, it means Tab3 should be selected. But it's not.

Reason:

https://github.com/joomla/joomla-cms/blob/staging/media/system/js/tabs.js#L45 this line of code is expecting boolean but when you will check in cosole with code,

console.log(typeof this.options.useStorage);

it will show string and because of that condition in above file always become true.

Test & Confirm fix

Apply this patch and confirm with enabling or disabling browser storage.

@Erftralle
Copy link
Copy Markdown
Contributor

@test:
I can confirm the bug.
After applying the patch and setting 'useCookie' to false always Tab3 is opened (first and subsequent loads).
After applying the patch and setting 'useCookie' to true Tab1 is opened on first load and the last selected tab on all subsequent loads.

So the patch works like expected regarding to the bug with 'useCookie', but the 'startOffset' seems to be ineffective when setting 'useCookie' to true. Maybe another bug?

@gunjanpatel
Copy link
Copy Markdown
Contributor Author

Thanks @Erftralle for testing.

Yes, agree with you that when using useCookie true and trying to set startOffset is doesn't work because it's conflict with browser localStorage or cookie. That's the another bug and it can be fixed by resetting localStorage (assumption) not pratically tested.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/6080.

@roland-d
Copy link
Copy Markdown
Contributor

roland-d commented May 6, 2015

@test works as described. Before the patch, the chosen tab is not selected, after applying path the chosen tab is selected.

@roland-d roland-d added this to the Joomla! 3.4.2 milestone May 6, 2015
roland-d added a commit that referenced this pull request May 6, 2015
[fix] Bug in setting startOffset to tabs - using localStorage all the time
@roland-d roland-d merged commit 702129d into joomla:staging May 6, 2015
@gunjanpatel gunjanpatel deleted the tabsFix branch May 6, 2015 05:31
gunjanpatel pushed a commit to gunjanpatel/joomla-cms that referenced this pull request May 7, 2015
gunjanpatel pushed a commit to gunjanpatel/joomla-cms that referenced this pull request Sep 4, 2015
Kubik-Rubik pushed a commit that referenced this pull request May 7, 2016
* [related #6080] Fix startOffset issue when useCookie is true

* [cs] Improved condition by optimizing code - set useCookie as default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants