Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds new JS module for hiding and showing extra meta information
- Loading branch information
1 parent
cf471c1
commit f88e8c0
Showing
7 changed files
with
130 additions
and
20 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* Table toggle more | ||
* When a table has more things to it that need to be hidden and then shown more | ||
*/ | ||
this.ckan.module('table-toggle-more', function($, _) { | ||
return { | ||
/* options object can be extended using data-module-* attributes */ | ||
options: { | ||
i18n: { | ||
show_more: _('Show more'), | ||
show_less: _('Hide') | ||
} | ||
}, | ||
|
||
/* Initialises the module setting up elements and event listeners. | ||
* | ||
* Returns nothing. | ||
*/ | ||
initialize: function () { | ||
$.proxyAll(this, /_on/); | ||
this.el.addClass('table-toggle-more'); | ||
// Do we actually want this table to expand? | ||
var rows = $('.toggle-more', this.el).length; | ||
if (rows) { | ||
// How much is the colspan? | ||
var cols = $('thead tr th', this.el).length; | ||
var template_more = [ | ||
'<tr class="toggle-show toggle-show-more">', | ||
'<td colspan="'+cols+'">', | ||
'<small>', | ||
'<a href="#" class="show-more">'+this.i18n('show_more')+'</a>', | ||
'<a href="#" class="show-less">'+this.i18n('show_less')+'</a>', | ||
'</small>', | ||
'</td>', | ||
'</tr>' | ||
].join('\n'); | ||
var template_seperator = [ | ||
'<tr class="toggle-seperator">', | ||
'<td colspan="'+cols+'">', | ||
'</td>', | ||
'</tr>' | ||
].join('\n'); | ||
|
||
var seperator = $(template_seperator).insertAfter($('.toggle-more:last-child', this.el)); | ||
$(template_more).insertAfter(seperator); | ||
|
||
$('.show-more', this.el).on('click', this._onShowMore); | ||
$('.show-less', this.el).on('click', this._onShowLess); | ||
} | ||
}, | ||
|
||
_onShowMore: function($e) { | ||
$e.preventDefault(); | ||
this.el | ||
.removeClass('table-toggle-more') | ||
.addClass('table-toggle-less'); | ||
}, | ||
|
||
_onShowLess: function($e) { | ||
$e.preventDefault(); | ||
this.el | ||
.removeClass('table-toggle-less') | ||
.addClass('table-toggle-more'); | ||
} | ||
|
||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters