-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage with Require JS #829
Comments
Hi @skoch! I haven't used Require JS, but I wonder if the problem is because the widget code isn't wrapped as an AMD module. Try wrapping the widget code in this: Replace the first line ;(function ($, window, document) { with this (function(factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof module === 'object' && typeof module.exports === 'object') {
module.exports = factory(require('jquery'));
} else {
factory(jQuery);
}
}(function($, window, document) { and replace this at the end of the file: })(jQuery); with this: return ts;
})); If that fixes the issue, please tell me... I'll need to include that in the build script, and I might end up wrapping every widget individually. |
Fixes upstream issue Mottie#829 Update Gruntfile.js to wrap the whole `jquery.tablesorter.widgets.js` file in a requirejs-compatible factory.
I ran into this same problem. The suggested fix is close to what's needed, but 'ts' is not actually in scope, so I've used a slightly different footer: return $.tablesorter;
})); This fixes the issue for me, so I've filed a pull request. |
@nburlett Thanks, I did have to remove the window and document parameters because with them included, I was getting undefined errors.
|
I just pushed v2.21.1 which adds a UMD wrapper to the "jquery.tablesorter.widgets.js" file. The separate widget files are not wrapped, but I'll look into adding individual wrappers to each if it is needed. |
@Mottie 👍 Apologies for not getting back to you sooner but happy to report that v2.21.1 fixes the issue. (Client finally made a decision!) Many thanks! |
I'm using v.2.21.1 of the built widgets file and I'm still seeing this issue, but only intermittently. The only widget I'm using is uitheme. I'm using jQuery v2.1.1, fyi. |
Hi @seemikehack! Only the combined
If you only need the uitheme widget, then create a custom build. I'll add an option to the custom build, so you can name the output file whatever you want. |
I need the AMD wrapper, and was just using the built file out of convenience. The confusion came with the intermittent error: sometimes I would get it, sometimes not. I haven't gotten a reliable repro either, which is frustrating. I will create a custom build Update: still intermittently getting the error. Can post config files and usage if it'd help. |
What error? Hmm, the parsers and "extras" code don't include a wrapper... maybe I can add a UMD wrapper to all minified files. |
Sorry for not being very helpful :) I occasionally get
main.js:
Some controller:
Stack trace:
Where line 197 in the custom widgets file is
|
I don't use requirejs, so I'm not familiar with it. I do have some questions, maybe this would work better if you could jump on our IRC channel - it's |
It appears that the files are loading asynchronously... the widgets need to be added as a dependency of tablesorter. Please see #855 for more details. |
I'm using tablesorter within a project built using require.js and I can get everything to work fine in develop mode however when I attempt to build my project (minimizing JS) I'm consistently getting an error that
addWidget
is not a function. Below are my apps main entry point as well as the build file (with code removed for brevity.)Has anyone attempted to build a project using require.js and succeeded?
main.js
build.js
The usage from within one of my components uses the following code:
Console error
And the cursor is clearly at
t.addWidget({id:"uitheme"...
from the built JS file.The text was updated successfully, but these errors were encountered: