Skip to content
This repository was archived by the owner on Nov 21, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bower install simpletabs
<script src="/path/to/simpletabs.js"></script>
```

A full working example is on [CodePen](http://codepen.io/romulomachado/full/rVYVqr/).
A full working example is on [CodePen](http://codepen.io/magalhaespaulo/full/MaOqpo/).

## Contributing

Expand Down
12 changes: 12 additions & 0 deletions dist/simpletabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@
.content__item.is-active {
display: block;
}

@media (max-width: 767px) {
.large__screen {
display: none;
}
}

@media (min-width: 768px) {
.small__screen {
display: none;
}
}
15 changes: 14 additions & 1 deletion dist/simpletabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
},
updateURLHash: function() {
return window.location.hash = this._element.data('tab');
},
responsiveTab: function() {
var elements, list;
list = this._element.parent().parent();
elements = $(list).find('li');
return elements.each(function(i) {
var content, dataTab;
dataTab = $('[data-tab]')[i].attributes['data-tab'].nodeValue;
content = $('[data-content=\'' + dataTab + '\']')[0];
return $(this).addClass('large__screen').clone().removeClass('large__screen').addClass('small__screen').insertBefore(content);
});
}
};
};
Expand All @@ -42,10 +53,12 @@
hash = window.location.hash.replace('#', '');
tabs = new hashTabs();
tabs.element($('[data-tab=\'' + hash + '\']'));
tabs.responsiveTab();
return tabs.updateTab();
} else {
tabs = new hashTabs();
tabs.element($('[data-tab]').first());
tabs.responsiveTab();
return tabs.updateTab(updateHash = false);
}
});
Expand All @@ -65,4 +78,4 @@
});
}
});
}.call(this));
}.call(this));
12 changes: 11 additions & 1 deletion simpletabs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,26 @@ $ ->
updateURLHash: ->
window.location.hash = this._element.data('tab')

responsiveTab: ->
list = this._element.parent().parent();
elements = $(list).find('li')
elements.each (i) ->
dataTab = $('[data-tab]')[i].attributes['data-tab'].nodeValue
content = $('[data-content=\'' + dataTab + '\']')[0]
$(this).addClass('large__screen').clone().removeClass('large__screen').addClass('small__screen').insertBefore(content)

if $('[data-tab]').length
$(window).on 'load', ->
if window.location.hash != ""
hash = window.location.hash.replace("#", "")
tabs = new hashTabs()
tabs.element $("[data-tab='"+hash+"']")
tabs.responsiveTab()
tabs.updateTab()
else
tabs = new hashTabs()
tabs.element $("[data-tab]").first()
tabs.responsiveTab()
tabs.updateTab(updateHash=false)

$(window).on 'hashchange', ->
Expand All @@ -47,4 +57,4 @@ $ ->
tabs = new hashTabs()
tabs.element $(this)
tabs.updateTab()
e.preventDefault()
e.preventDefault()