Ticket #3171 (closed enhancement: fixed)

Opened 6 years ago

Last modified 4 years ago

have option to remove tab by href content, not just by index

Reported by: tiago.freire@… Owned by: klaus.hartl
Priority: minor Milestone: 1.8.3
Component: ui.tabs Version: 1.6rc6
Keywords: Cc:
Blocking: Blocked by:

Description

My system generates tabs on runtime, with UUIDs as the ID attribute to ensure uniqueness. This way the menu has an href=#<uuid>, and the div has id=#<uuid>. Tracking the index of each content is tiresome, and deletion requires re-scanning the menu and updating the indexes so that I can delete the content correctly. It would be better (for me at least) if I also could use the code:

$(#menu).tabs("remove",'#<uuid>');

and not care about the indexes (which are useful in other circumstances).

Attachments

patch_3171.patch Download (2.8 KB) - added by francois 5 years ago.
remove, enable and disable tab by href

Change History

comment:1 Changed 6 years ago by brazilianjoe

I noticed that I can use the select function to select a tab by the href. I digged the tabs code and copied 2 lines of the tabs select function to the remove function, and the enhancement request I made came true.

I just copied those 2 lines from the tabs(select) action to tabs(remove), this way I can delete by the href as wel as the index. Should be trivial to add those 2 lines to the next release.

if (typeof index == 'string')

index = this.$tabs.index( this.$tabs.filter('[href$=' + index + ']')[0] );

comment:2 Changed 6 years ago by Cloudream

  • Owner changed from paul to klaus.hartl
  • Priority changed from major to minor
  • Component changed from ui.core to ui.tabs
  • Milestone set to TDB

comment:3 Changed 6 years ago by brazilianjoe

Hi, klaus.hartl!

I want to give you heads-up on this bug. It's a no-brainer, and will add a good functionality to jQuery tabs.

as of jQuery 1.6rc6, function remove begins like this:

/ when generated by themeroller, the remove() function is in line 5681 /...

remove: function(index) {

var o = this.options, $li = this.$lis.eq(index).remove(),

$panel = this.$panels.eq(index).remove();

/...

you just have to change it to:

/...

remove: function(index) {

if (typeof index == 'string')

index = this.$tabs.index( this.$tabs.filter('[href$=' + index + ']')[0] );

var o = this.options, $li = this.$lis.eq(index).remove(),

$panel = this.$panels.eq(index).remove();

/...

And fix with this bug/enhancement.

This enables the possibility of removing a tab using the tab's href property without losing the ability to remove according to the tab index.

Please add this feature! I need this and can patch jQuery tabs every new version, but I bet it will be a nice feature for others too.

best regards

comment:4 Changed 6 years ago by klaus.hartl

I'm considering to add that functionality, but: if so, I'd like to add that consistently to all methods where it applies.

comment:5 Changed 5 years ago by klaus.hartl

  • Version changed from 1.5.2 to 1.6rc6
  • Milestone changed from TBD to 1.7

comment:6 Changed 5 years ago by rdworth

  • Milestone changed from 1.7 to 1.8

Changed 5 years ago by francois

remove, enable and disable tab by href

comment:7 Changed 5 years ago by francois

With this patch I think tabs is more coherent.

comment:8 Changed 5 years ago by brazilianjoe

Just to give the heads up, since the last post is 9 months old. Will this be implemented in 1.8? Pretty please? I haven't found any mention of it being implemented on the changelogs up to 1.8rc1.

comment:9 Changed 4 years ago by francois

patch updated with latest version of jquery-ui. Available here  http://github.com/francois2metz/jquery-ui/commit/d00db9f0ccd81c0ec6458cabab08f66866b26ea0

comment:10 Changed 4 years ago by remoteportal

Respectfully, this seems like a "no brainer" feature enhancement... and it's so trivial to add, how come it's taking so long to get this the code base? The tab component will be MUCH easier to use if this fix is in place for all applicable verbs.

comment:11 Changed 4 years ago by brazilianjoe

placed my version of a patch on github. I tried to make it as small as possible, without sacrificing readability and maintainability, and change as little as possible. Hope you find this code acceptable:  http://github.com/BrazilianJoe/jquery-ui/blob/56a65a2571c81bd94ae8925b85f0e5621b51a1cb/ui/jquery.ui.tabs.js

comment:12 Changed 4 years ago by brazilianjoe

Further comments on my proposed changes to jquery.ui.tabs.js:

I have created a small helper function for internal use only. It is called _getIndex(). It receives the index variable, and parses it. if it is a string, it assumes it contains a href and looks for a tab with this href in the <a> link at the tab top. If it finds no tab, it returns NaN.

Next, it checks if it is a number, and similarly sanitizes it to a valid number.

It always returns a typeof number , thus required very little change on the other functions which can benefit from this behaviour.

I have used _getIndex to implement href functionality to the methods enable, disable, select, remove and load.

comment:13 Changed 4 years ago by scott.gonzalez

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in  fde8c64.

comment:14 Changed 4 years ago by scott.gonzalez

  • Milestone changed from 1.9 to 1.8.3

comment:15 Changed 4 years ago by Tiago Freire

Tabs: Added ability to reference tabs by href. Fixes #3171 - have option to remove tab by href content, not just by index.

Changeset: fde8c64fd37d6700e174ccf5ea1574e418db2c1e

Note: See TracTickets for help on using tickets.