Loading jquery + jquery-ui

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Loading jquery + jquery-ui

by 23425675747 on Fri Oct 27, 2017 7:38 am

Hi there,

i am a long time imacros user and i use jquery as follows:
Code: Select all
function myRequire( url ) {
   const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1");
   var ajax = XMLHttpRequest();
    ajax.open( 'GET', url, false );
    ajax.onreadystatechange = function () {
       var script = ajax.response || ajax.responseText;
       if (ajax.readyState === 4) {
          switch( ajax.status) {
             case 200:
                eval.apply( window, [script] );
                iimDisplay("script loaded: ", url);
             break;
             default:
                iimDisplay("ERROR: script not loaded: ", url);
          }
       }
    };
    ajax.send(null);
}
myRequire("file:///jquery-3.1.0.min.js");
$ = window.$;
JQuery = window.JQuery;
myRequire("file:///jquery-ui.min.js");

Loading jquery and using it in my imacro script works as expected but the jquery-ui plugin does not seem to get properly registered, cause a call to:
Code: Select all
$("#jqDialog").dialog();


result in the following error:

Code: Select all
TypeError: $(...).dialog is not a function, line 971 (Error code: -991)


This is the normal error you get when jquery-ui did not load correctly (in a non imacros context).

I am not really sure what is going on but for some reason it doesn't work.
Hope someone else had this problem before and can give me a hint..

*edit:
System specs:
imacros: 8.9.7
firefox: 55 - 56
OS: Arch Linux (Kernel: 4.9.58)

Cheers
Last edited by 23425675747 on Mon Oct 30, 2017 7:13 am, edited 1 time in total.
23425675747
 
Posts: 4
Joined: Fri Oct 27, 2017 7:28 am

Re: Loading jquery + jquery-ui

by chivracq on Fri Oct 27, 2017 7:56 pm

23425675747 wrote:Hi there,

i am a long time imacros user and i use jquery as follows:
Code: Select all
function myRequire( url ) {
   const XMLHttpRequest = Components.Constructor("@mozilla.org/xmlextras/xmlhttprequest;1");
   var ajax = XMLHttpRequest();
    ajax.open( 'GET', url, false );
    ajax.onreadystatechange = function () {
       var script = ajax.response || ajax.responseText;
       if (ajax.readyState === 4) {
          switch( ajax.status) {
             case 200:
                eval.apply( window, [script] );
                iimDisplay("script loaded: ", url);
             break;
             default:
                iimDisplay("ERROR: script not loaded: ", url);
          }
       }
    };
    ajax.send(null);
}
myRequire("file:///jquery-3.1.0.min.js");
$ = window.$;
JQuery = window.JQuery;
myRequire("file:///jquery-ui.min.js");

Loading jquery and using it in my imacro script works as expected but the jquery-ui plugin does not seem to get properly registered, cause a call to:
Code: Select all
$("#jqDialog").dialog();


result in the following error:

Code: Select all
TypeError: $(...).dialog is not a function, line 971 (Error code: -991)


This is the normal error you get when jquery-ui did not load correctly (in a non imacros context).

I am not really sure what is going on but for some reason it doesn't work.
Hope someone else had this problem before and can give me a hint..

Cheers

Hum, FCIM...! :mrgreen: (Read my Sig..., but mention your FCI when you open a Thread on this Forum if you want me to try to help you... :idea: )
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Loading jquery + jquery-ui

by 23425675747 on Mon Oct 30, 2017 7:15 am

chivracq wrote:Hum, FCIM...! :mrgreen: (Read my Sig..., but mention your FCI when you open a Thread on this Forum if you want me to try to help you... :idea: )

Fair enough. I am pretty sure this is not related to a specific imacros, firefox or OS version,so i figured it wasn't that important.
Anyway, i added it to my initial post.

Cheers
23425675747
 
Posts: 4
Joined: Fri Oct 27, 2017 7:28 am

Re: Loading jquery + jquery-ui

by chivracq on Mon Oct 30, 2017 8:35 am

23425675747 wrote:
chivracq wrote:Hum, FCIM...! :mrgreen: (Read my Sig..., but mention your FCI when you open a Thread on this Forum if you want me to try to help you... :idea: )

System specs:
Code: Select all
imacros: 8.9.7
firefox: 55 - 56
OS: Arch Linux (Kernel: 4.9.58)


Fair enough. I am pretty sure this is not related to a specific imacros, firefox or OS version,so i figured it wasn't that important.
Anyway, i added it to my initial post.

Cheers

"... I am pretty sure this is not related to a specific imacros, firefox or OS version..."
=> You could be right, but I usually simply don't read the Qt and certainly don't answer if that Info is not mentioned... :wink:
You could have mentioned the 'jQuery' Version(s) as well, even if it/they can be found in your Script...:
Code: Select all
jQuery v3.1.0_min + jQuery UI v1.12.1_min(?).


But OK, you are on v8.9.7 for FF, good-good as a lot of Functionality/Commands are not supported anymore or got broken in v9.0.3 for FF...

But hum..., I don't use '.js' Scripts, and 'jQuery' even less, ah-ah...!, so I'm afraid I won't be of much Help on this one..., but I don't know if you searched the Forum, but we have quite a few other Threads related to 'jQuery' (and a few fairly recent as well, from only a few months ago) and the (Advanced) Users who posted their Script might be using using a different way to call 'jQuery' in their Script... :idea:

The only "Suggestion" I would have is that I see that you call 'jQuery' from a Local Copy located in your Root Directory..., you could try placing those Files in some Intermediary Folder, as..., not sure about Linux..., but on Windows OS'es, File-IO Access is prevented (from the Browser since FF14 I think) for Files located in the 'C:\' Root Directory... :idea:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Loading jquery + jquery-ui

by chivracq on Mon Oct 30, 2017 10:11 am

But OK, a few more "Thoughts", ah-ah...!

I guess my "Sugg" about an "Intermediary Folder" for the 'jQuery' Libraries won't really make a Difference, you would get a different RuntimeError I would think, and you wouldn't be able to access any 'jQuery' Functionality at all otherwise... :oops:

But I suspect you might be hitting a Bug in iMacros for FF since v7.5 related to 'alert()'/'confirm()'/'prompt()' as I reckon this 'dialog()' 'jQuery' Function probably relies on one of the 3 JS DialogBox Functions...

Those 3 Commands should still work if you call them "natively" from your '.js' Script without trying to use the 'jQuery' extra-Layer...

Or in the same Thread I already referred to, you have a Workaround where you can embed them within 'setTimeout()' provided by Advanced User @iimfun (who also uses 'jQuery' I think, so if you are a bit "lucky", he might notice and jump into your Thread...), that you might be able to apply to your Case...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Loading jquery + jquery-ui

by iimfun on Wed Nov 01, 2017 12:47 am

As to this particular problem I would load the jquery-ui script directly to the page.

Code: Select all
iimPlayCode('URL GOTO=javascript:document.body.appendChild(document.createElement("script")).src="file:///path/jquery-3.1.0.min.js";void(0);' + '\n' + 'WAIT SECONDS=1' + '\n' + 'URL GOTO=javascript:document.body.appendChild(document.createElement("script")).src="file:///path/jquery-ui.js";void(0);' + '\n' + 'WAIT SECONDS=1');

// calling a dialog
window.location.href = 'javascript:$("#jqDialog").dialog();void(0);';

Btw the idea has already appeared somewhere in my posts on this forum.
iimfun
 
Posts: 239
Joined: Tue Jul 19, 2016 6:06 am

Re: Loading jquery + jquery-ui

by 23425675747 on Wed Nov 01, 2017 6:08 am

Thx for the responses guys, I really appreciate it.

@iimfun i am sure this works to execute the script but i need it in the same context as the imacros javascript to be able to pass values back and forth.

To me it looks like jQuery-ui does not recognize the jQuery instance for some reason. This is probably a problem with the namespace of the two but i am not sure how to fix it.

I searched the forum but so far i only found solution on "how to load and use jQuery" but that's not my problem. jQuery works fine it's just that jQuery plugins don't.

Cheers
23425675747
 
Posts: 4
Joined: Fri Oct 27, 2017 7:28 am

Re: Loading jquery + jquery-ui

by chivracq on Wed Nov 01, 2017 4:16 pm

iimfun wrote:As to this particular problem I would load the jquery-ui script directly to the page.

Code: Select all
iimPlayCode('URL GOTO=javascript:document.body.appendChild(document.createElement("script")).src="file:///path/jquery-3.1.0.min.js";void(0);' + '\n' + 'WAIT SECONDS=1' + '\n' + 'URL GOTO=javascript:document.body.appendChild(document.createElement("script")).src="file:///path/jquery-ui.js";void(0);' + '\n' + 'WAIT SECONDS=1');

// calling a dialog
window.location.href = 'javascript:$("#jqDialog").dialog();void(0);';

Btw the idea has already appeared somewhere in my posts on this forum.

Yep..., exactly why I mentioned to search the Forum a bit, but @OP didn't react at all... 8)

And hum, @iimfun, like each time you post stg, you never mention in which FCI (if...?) you've tested if the '#jqDialog' Call works using your Script, v8.9.7 for FF I guess + FF55 I guess, oh no, you were using FF52 Portable I think..., a bit tired of having to ask each time... :roll:

23425675747 wrote:Thx for the responses guys, I really appreciate it.

@iimfun i am sure this works to execute the script but i need it in the same context as the imacros javascript to be able to pass values back and forth.

To me it looks like jQuery-ui does not recognize the jQuery instance for some reason. This is probably a problem with the namespace of the two but i am not sure how to fix it.

I searched the forum but so far i only found solution on "how to load and use jQuery" but that's not my problem. jQuery works fine it's just that jQuery plugins don't.

Cheers

OK, Thanks for the "Thx", I guess the "s" in "guys" is for me, but you didn't react to any of my Sugg's, except mentioning your FCI with some "mumbling"... But OK, you are in "good hands with @iimfun" now (I don't know anything about 'jQuery' anyway...!, happy he jumped in, ah-ah...!), I'll follow the Thread from some distance... :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6489
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Loading jquery + jquery-ui

by 23425675747 on Sat Nov 04, 2017 9:28 am

chivracq wrote:Yep..., exactly why I mentioned to search the Forum a bit, but @OP didn't react at all... 8)

well, i did not react to what you said because your suggestions have nothing to do with what my problem. It's a problem with jQuery Plugins in general and not specific to jQuery-uis dialog plugin. Beside that, you said yourself, you don't work with jQuery, so i waited for people more familiar with it (as you suggested).

And yes, the "s" in guys was for you. ;)

Cheers
23425675747
 
Posts: 4
Joined: Fri Oct 27, 2017 7:28 am

Re: Loading jquery + jquery-ui

by iimfun on Mon Nov 06, 2017 1:09 am

23425675747 wrote:i waited for people more familiar with it
It still seems that my approach is more promising and jQuery version independent. There should be some mechanism or task specific workarounds to access window context of the page itself. Sometimes I work with my own old tricks regarding that and at the moment have no enough time & motivation for extra searches and experiments, thus hope that you'll get a solution anyways.

chivracq wrote:... you are in "good hands with @iimfun" now ...
Yeah, thanks for advertising my expertise. Believe that I am not the only one who reads this.

Cheers!
iimfun
 
Posts: 239
Joined: Tue Jul 19, 2016 6:06 am


Return to iMacros for Firefox

Who is online

Users browsing this forum: Google [Bot] and 8 guests

-->