Closed NickGreen closed 5 months ago
@NickGreen -- greetings and thanks for posting this here. :-)
Would it help to add this to the beginning of the blogroll
function?
function blogroll (userOptions) {
const $ = jQuery.
etc etc.
}
I updated the blogroll code to do that at the beginning.
Does that help??
That is a simple workaround, and would certainly make the code work. It sort of depends on how "correct" you want to be (as defined by jQuery, in this case).
The main difference between this and true no conflict mode is that this is merely an alias within a specific scope. jQuery's no-conflict mode is a method designed to relinquish control of the global variable $
so that other libraries can use it.
Totally a choice.
I'll keep that in mind, certainly something we could do later, esp when there are more people working on this stuff. ;-)
Fernando, would you be able to confirm for me that this will work?
I'm still getting a JS error for code.js
on line 2080 that $
is undefined here:
$(document).ready (function () {
@NickGreen, @scripting 👋🏻
I'm also getting the error you mentioned in the above comment. I think that part of code.js
was meant for use specifically for FeedLand, i.e. there's no #idPrefsDialog
when using just the blogroll.
Without breaking anything I think we could do the following:
Change this:
$(document).ready (function () {
$("#idPrefsDialog").bind ('show', function () {
prefsSetDefaultValues ();
});
});
to
(function($) {
$(document).ready (function () {
$("#idPrefsDialog").bind ('show', function () {
prefsSetDefaultValues ();
});
});
})(jQuery);
Of course, "without breaking anything" might be a bold statement and this needs testing, but it's the simplest solution I can think of. Leaving here just in case we come back to this issue later.
@NickGreen -- sorry I missed your comment from 3 days ago.
Took me a while to figure out where that is. :smile:
That code will never get called.
Is it getting called??
If so, can you get a stack crawl??
Basically I include a big file that has all my commonly-used routines. I could probably do a custom one for the blogroll package, but that's another thing to maintain, which is a problem I don't go looking for..
Never mind. I found it. That's a mistake. Now @fmfernandes comment is starting to make sense. ;-)
Ignore the comments above, I just fixed the problem, I believe. :smile:
I apologize for that. I wrote that code in 2014 when I was just making the transition from C to JavaScript.
If I were writing that today it would be organized like the blogroll code is, all in one function, with all its variables inside the function, so there couldn't be collisions.
In any case could you test the plugin and confirm that it doesn't get hung up there?
That fixed it, @scripting. Thanks.
WordPress runs jQuery in no conflict mode. In our code, we've done it a little less than ideal for now, by reassigning
$
, like this:<div id="divBlogrollContainer"></div><script>$=jQuery;blogroll(BLOGROLL_OPTIONS);</script>'
It would probably be better to do it in a more standard way.
A couple of possible solutions moving forward:
jQuery
instead of$
in the main code(function($){}(jQuery)
Personally, I've tended to prefer the second option in my own code. There are examples in the jQuery docs, but it would look essentially like this: