Responsive tables and individual content filters

This commit is contained in:
Brian Miyaji
2014-01-24 00:05:45 +11:00
parent f21ed7f522
commit ef3136801f
17 changed files with 339 additions and 196 deletions

View File

@@ -1,21 +1,98 @@
function viewport() {
var e = window, a = 'inner';
if (!('innerWidth' in window )) {
a = 'client';
e = document.documentElement || document.body;
}
return { width : e[ a+'Width' ] , height : e[ a+'Height' ] };
}
(function($) {
// Data Tables
$(".sp-data-table").dataTable({
"aaSorting": [],
"bAutoWidth": false,
"bFilter": false,
"bInfo": false,
"bPaginate": false,
"bSort": true,
"oLanguage": {
"oAria": {
"sSortAscending": "",
"sSortDescending": ""
}
}
// Data tables
if (viewport().width > 640) {
$(".sp-data-table").dataTable({
"aaSorting": [],
"bAutoWidth": false,
"bFilter": false,
"bInfo": false,
"bPaginate": false,
"bSort": true,
"oLanguage": {
"oAria": {
"sSortAscending": "",
"sSortDescending": ""
}
}
});
}
// Responsive tables
var switched = false;
var updateTables = function() {
if ((viewport().width <= 640) && !switched ){
switched = true;
$(".sp-responsive-table").each(function(i, element) {
splitTable($(element));
});
return true;
}
else if (switched && (viewport().width > 640)) {
switched = false;
$(".sp-responsive-table").each(function(i, element) {
unsplitTable($(element));
});
}
};
$(window).load(updateTables);
$(window).on("redraw",function(){switched=false;updateTables();}); // An event to listen for
$(window).on("resize", updateTables);
function splitTable(original)
{
original.wrap("<div class='sp-responsive-table-wrapper' />");
var copy = original.clone();
copy.find("td:not(.data-number):not(.data-name), th:not(.data-number):not(.data-name)").css("display", "none");
copy.removeClass("sp-responsive-table");
original.closest(".sp-responsive-table-wrapper").append(copy);
copy.wrap("<div class='sp-pinned-table' />");
original.wrap("<div class='scrollable' />");
setCellHeights(original, copy);
}
function unsplitTable(original) {
original.closest(".sp-responsive-table-wrapper").find(".sp-pinned-table").remove();
original.unwrap();
original.unwrap();
}
function setCellHeights(original, copy) {
var tr = original.find('tr'),
tr_copy = copy.find('tr'),
heights = [];
tr.each(function (index) {
var self = $(this),
tx = self.find('th, td');
tx.each(function () {
var height = $(this).outerHeight(true);
heights[index] = heights[index] || 0;
if (height > heights[index]) heights[index] = height;
});
});
tr_copy.each(function (index) {
$(this).height(heights[index]);
});
}
// Google Maps
function initialize_google_maps() {
$maps = $('.sp-google-map');