Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Fixes #333
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 24, 2018
1 parent 950db5c commit 2ba5fc6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
11 changes: 9 additions & 2 deletions src/tables.intro.jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@
return (root.Tablesaw = factory(jQuery, root));
});
} else if (typeof exports === 'object') {
module.exports = factory(require('jquery')(root), root);
if( "document" in root ) {
module.exports = factory(require('jquery'), root);
} else {
// special jQuery case for CommonJS (pass in a window)
module.exports = factory(require('jquery')(root), root);
}
} else {
root.Tablesaw = factory(jQuery, root);
}
}(typeof window !== "undefined" ? window : this, function ($, win) {
}(typeof window !== "undefined" ? window : this, function ($, window) {
"use strict";

var document = window.document;
4 changes: 3 additions & 1 deletion src/tables.intro.shoestring.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
} else {
root.Tablesaw = factory(shoestring, root);
}
}(typeof window !== "undefined" ? window : this, function ($, win) {
}(typeof window !== "undefined" ? window : this, function ($, window) {
"use strict";

var document = window.document;
14 changes: 7 additions & 7 deletions src/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var Tablesaw = {
}
};

$(win.document).on("enhance.tablesaw", function() {
$(document).on("enhance.tablesaw", function() {
// Extend i18n config, if one exists.
if (typeof TablesawConfig !== "undefined" && TablesawConfig.i18n) {
Tablesaw.i18n = $.extend(Tablesaw.i18n, TablesawConfig.i18n || {});
Expand Down Expand Up @@ -471,7 +471,7 @@ if (Tablesaw.mustard) {
});
};

var $doc = $(win.document);
var $doc = $(document);
$doc.on("enhance.tablesaw", function(e) {
// Cut the mustard
if (Tablesaw.mustard) {
Expand All @@ -491,17 +491,17 @@ if (Tablesaw.mustard) {
$doc.on("scroll.tablesaw", function() {
isScrolling = true;

win.clearTimeout(scrollTimeout);
scrollTimeout = win.setTimeout(function() {
window.clearTimeout(scrollTimeout);
scrollTimeout = window.setTimeout(function() {
isScrolling = false;
}, 300); // must be greater than the resize timeout below
});

var resizeTimeout;
$(win).on("resize", function() {
$(window).on("resize", function() {
if (!isScrolling) {
win.clearTimeout(resizeTimeout);
resizeTimeout = win.setTimeout(function() {
window.clearTimeout(resizeTimeout);
resizeTimeout = window.setTimeout(function() {
$doc.trigger(events.resize);
}, 150); // must be less than the scrolling timeout above.
}
Expand Down
8 changes: 4 additions & 4 deletions src/tables.minimap.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
if (mq === "") {
// value-less but exists
return true;
} else if (mq && "matchMedia" in win) {
} else if (mq && "matchMedia" in window) {
// has a mq value
return win.matchMedia(mq).matches;
return window.matchMedia(mq).matches;
}

return false;
Expand Down Expand Up @@ -57,7 +57,7 @@

// run on init and resize
showHideNav();
$(win).on(Tablesaw.events.resize, showHideNav);
$(window).on(Tablesaw.events.resize, showHideNav);

$table
.on("tablesawcolumns.minimap", function() {
Expand All @@ -67,7 +67,7 @@
var $t = $(this);

tblsaw.$toolbar.find(".tablesaw-advance").remove();
$(win).off(Tablesaw.events.resize, showHideNav);
$(window).off(Tablesaw.events.resize, showHideNav);

$t.off(".minimap");
});
Expand Down
2 changes: 1 addition & 1 deletion src/tables.modeswitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
}
};

$(win.document).on(Tablesaw.events.create, function(e, Tablesaw) {
$(document).on(Tablesaw.events.create, function(e, Tablesaw) {
if (Tablesaw.$table.is(S.selectors.init)) {
S.init(Tablesaw.table);
}
Expand Down
10 changes: 5 additions & 5 deletions src/tables.swipetoggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@

function matchesMedia() {
var matchMedia = $table.attr("data-tablesaw-swipe-media");
return !matchMedia || ("matchMedia" in win && win.matchMedia(matchMedia).matches);
return !matchMedia || ("matchMedia" in window && window.matchMedia(matchMedia).matches);
}

function fakeBreakpoints() {
Expand Down Expand Up @@ -277,7 +277,7 @@
var y;
var scrollTop = window.pageYOffset;

$(win).off(Tablesaw.events.resize, fakeBreakpoints);
$(window).off(Tablesaw.events.resize, fakeBreakpoints);

$(this)
.on("touchmove.swipetoggle", function(e) {
Expand Down Expand Up @@ -314,7 +314,7 @@
}

window.setTimeout(function() {
$(win).on(Tablesaw.events.resize, fakeBreakpoints);
$(window).on(Tablesaw.events.resize, fakeBreakpoints);
}, 300);

$(this).off("touchmove.swipetoggle touchend.swipetoggle");
Expand Down Expand Up @@ -344,7 +344,7 @@

$t.removeClass("tablesaw-swipe");
tblsaw.$toolbar.find(".tablesaw-advance").remove();
$(win).off(Tablesaw.events.resize, fakeBreakpoints);
$(window).off(Tablesaw.events.resize, fakeBreakpoints);

$t.off(".swipetoggle");
})
Expand All @@ -355,7 +355,7 @@
});

fakeBreakpoints();
$(win).on(Tablesaw.events.resize, fakeBreakpoints);
$(window).on(Tablesaw.events.resize, fakeBreakpoints);
}

// on tablecreate, init
Expand Down

0 comments on commit 2ba5fc6

Please sign in to comment.