Skip to content
This repository has been archived by the owner on Apr 12, 2019. It is now read-only.

Commit

Permalink
Fix URI encoded tabs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexia committed Jan 25, 2018
1 parent 7b302a2 commit 49cd5b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Tabber",
"version": "2.4.1",
"version": "2.4.2",
"author": [
"Eric Fortin",
"Alexia E. Smith"
Expand Down
64 changes: 32 additions & 32 deletions js/tabber.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
( function ( $ ) {
$.fn.tabber = function () {
return this.each( function () {
(function($) {
$.fn.tabber = function() {
return this.each(function() {
// create tabs
var $this = $( this ),
tabContent = $this.children( '.tabbertab' ),
nav = $( '<ul>' ).addClass( 'tabbernav' ),
var $this = $(this),
tabContent = $this.children('.tabbertab'),
nav = $('<ul>').addClass('tabbernav'),
loc;

tabContent.each( function () {
var anchor = $( '<a>' ).text( this.title ).attr( 'title', this.title ).attr( 'href', '#' );
$( '<li>' ).append( anchor ).appendTo( nav );
tabContent.each(function() {
var anchor = $('<a>').text(this.title).attr('title', this.title).attr('href', '#');
$('<li>').append(anchor).appendTo(nav);

// Append a manual word break point after each tab
nav.append( $( '<wbr>' ) );
} );
nav.append($('<wbr>'));
});

$this.prepend( nav );
$this.prepend(nav);

/**
* Internal helper function for showing content
* @param {string} title to show, matching only 1 tab
* @return {bool} true if matching tab could be shown
*/
function showContent( title ) {
var content = tabContent.filter( '[title="' + title + '"]' );
if ( content.length !== 1 ) { return false; }
function showContent(title) {
var content = tabContent.filter('[title="' + title + '"]');
if (content.length !== 1) { return false; }
tabContent.hide();
content.show();
nav.find( '.tabberactive' ).removeClass( 'tabberactive' );
nav.find( 'a[title="' + title + '"]' ).parent().addClass( 'tabberactive' );
nav.find('.tabberactive').removeClass('tabberactive');
nav.find('a[title="' + title + '"]').parent().addClass('tabberactive');
return true;
}

// setup initial state
loc = location.hash.replace( '#', '' );
if ( loc === '' || !showContent( loc ) ) {
showContent( tabContent.first().attr( 'title' ) );
var tab = decodeURI(location.hash.replace('#', ''));
if (tab === '' || !showContent(tab)) {
showContent(tabContent.first().attr('title'));
}

// Respond to clicks on the nav tabs
nav.on( 'click', 'a', function ( e ) {
var title = $( this ).attr( 'title' );
nav.on('click', 'a', function(e) {
var title = $(this).attr('title');
e.preventDefault();
if ( history.pushState ) {
history.pushState( null, null, '#' + title );
if (history.pushState) {
history.pushState(null, null, '#' + title);
switchTab(title);
} else {
location.hash = '#' + title;
}
} );
});

$(window).on('hashchange', function(event) {
switchTab(event);
});

function switchTab(event) {
var tab = location.hash.replace('#', '');
var tab = decodeURI(location.hash.replace('#', ''));
if (!tab.length) {
showContent(tabContent.first().attr('title'));
}
Expand All @@ -64,11 +64,11 @@
}
}

$this.addClass( 'tabberlive' );
} );
$this.addClass('tabberlive');
});
};
}( jQuery ) );
}(jQuery));

$( document ).ready( function () {
$( '.tabber' ).tabber();
} );
$(document).ready(function() {
$('.tabber').tabber();
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tabber",
"version": "2.4.0",
"version": "2.4.2",
"description": "Allows to create tabs within a page",
"main": "js/tabber.js",
"scripts": {
Expand Down

0 comments on commit 49cd5b8

Please sign in to comment.