Skip to content

Commit

Permalink
[#1251] Adds scrolling to resource nav
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmartin committed Nov 27, 2013
1 parent 8eeffdf commit 5287e8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
31 changes: 15 additions & 16 deletions ckan/public/base/javascript/modules/resource-views.js
Expand Up @@ -3,33 +3,32 @@
*/
this.ckan.module('resource-views', function($, _) {
return {
/* options object can be extended using data-module-* attributes */
options: {
view: false,
i18n: {
show_more: _('Show more')
}
},

/* Initialises the module setting up elements and event listeners.
*
* Returns nothing.
*/
initialize: function () {
$.proxyAll(this, /_/);

this.view = false;
$('nav', this.el).removeClass('hide');
if (!this.options.view) {
this.options.view = $('.resource-view:first', this.el).data('id');
$(window).on('hashchange', this._handleHash);

if (window.location.hash.indexOf('#view-') === 0) {
this._handleHash();
var position = $('.view-list li.active').position();
$('.view-list', this.el).scrollLeft(position.left);
} else {
this.view = $('.resource-view:first', this.el).data('id');
this._show();
}
$(window).on('hashchange', this._handleView);
this._handleView();
this._show();
},

_handleView: function () {
_handleHash: function () {
var hash = window.location.hash;
if (hash.indexOf('#view-') === 0) {
this.options.view = hash.substring(6);
this.view = hash.substring(6);
this._show();
}
},
Expand All @@ -38,10 +37,10 @@ this.ckan.module('resource-views', function($, _) {
// Hide all the other views
$('.resource-view', this.el).hide();
// Now show the relevant one
$('#view-' + this.options.view).show();
$('#view-' + this.view).show();
// Now do the same for the nav
$('.view-list li', this.el).removeClass('active');
$('.view-list a[data-id="' + this.options.view + '"]', this.el).parent().addClass('active');
$('.view-list a[data-id="' + this.view + '"]', this.el).parent().addClass('active');
}

}
Expand Down
7 changes: 5 additions & 2 deletions ckan/public/base/less/dataset.less
Expand Up @@ -288,9 +288,12 @@
}
}
&.stacked {
.clearfix;
overflow-y: hidden;
overflow-x: auto;
height: 100px;
white-space: nowrap;
li {
float: left;
display: inline-block;
width: 250px;
margin-right: 10px;
}
Expand Down

0 comments on commit 5287e8f

Please sign in to comment.