It seems that you're using an outdated browser. Some things may not work as they should (or don't work at all).
We suggest you upgrade newer and better browser like: Chrome, Firefox, Internet Explorer or Opera

×
I have another question.

A little background: My previous little script was wildly popular, and so now I'm getting my feet wet in making a full-blown extension.

My first extension's purpose is to lengthen our main viewing window of a table. The original table is regrettably tiny and doesn't use our window space.

Right now, when I go to the page, it lengthens the window correctly. However, after I reload some data (but not reloading the page) as selected from "ddlMyWorkOrderFilter", the view of the table shrinks back down to its default.

My solution to this was to make a function call to reformat the screen again every time ddlMyWorkOrderFilter changes. However, the function isn't calling. I've tried .onchange and addEventListener() to no avail. The function simply won't run. So I figure I'm missing some sort of fundamental issue.

I should note that the original code has an onchange event set to ddlMyWorkOrderFilter, so I also tried click and lose focus events to see if that was an issue.

Here's my extension's code thus far:


// This section makes the table bigger:
function reformatPage()
{
//changeFilter();
document.getElementById('tblWOWrapper').style.height= "500px";
document.getElementById('gview_tblWO').style.height= "480px";
document.getElementsByClassName('ui-jqgrid-bdiv')[0].style.height = "457px";

window.alert("reformatPage() executed");
}

//Remove logo
//document.getElementById('Image1').src = "";


//change size of text area when new filters are selected
//document.getElementById('ddlMyWorkOrderFilter').addEventListener=("change", reformatPage());
//document.getElementById('ddlMyWorkOrderFilter').onchange=reformatPage();



// Reformat the page the first time we get to it.
reformatPage();
Any ideas?

Thank you!!!
avatar
Tallima: I have another question.

A little background: My previous little script was wildly popular, and so now I'm getting my feet wet in making a full-blown extension.

My first extension's purpose is to lengthen our main viewing window of a table. The original table is regrettably tiny and doesn't use our window space.

Right now, when I go to the page, it lengthens the window correctly. However, after I reload some data (but not reloading the page) as selected from "ddlMyWorkOrderFilter", the view of the table shrinks back down to its default.

My solution to this was to make a function call to reformat the screen again every time ddlMyWorkOrderFilter changes. However, the function isn't calling. I've tried .onchange and addEventListener() to no avail. The function simply won't run. So I figure I'm missing some sort of fundamental issue.

I should note that the original code has an onchange event set to ddlMyWorkOrderFilter, so I also tried click and lose focus events to see if that was an issue.
What actually happens when the data reloads? Does the onchange event actually call (pop a console.log in there to see if is being called) or is the element just replaced with a new one?

If the element is replaced you might to find a different way to call the function...

Is the data retrieved by an AJAX call?
You can check by opening the console and reloading the data (in Firefox it will show in the normal console, in Chrome you have to go to the Network tab).
You need to use jQuery, but if it is retrieved by AJAX you can make a function call every time the AJAX returns with , unfortunately I can't see a similar way to do it easily in plain javascript, though [url=http://stackoverflow.com/questions/20689481/recreating-jquerys-ajaxstart-and-ajaxcomplete-functionality]this question might help.
avatar
adaliabooks: What actually happens when the data reloads? Does the onchange event actually call (pop a console.log in there to see if is being called) or is the element just replaced with a new one?

If the element is replaced you might to find a different way to call the function...

Is the data retrieved by an AJAX call?
You can check by opening the console and reloading the data (in Firefox it will show in the normal console, in Chrome you have to go to the Network tab).
You need to use jQuery, but if it is retrieved by AJAX you can make a function call every time the AJAX returns with , unfortunately I can't see a similar way to do it easily in plain javascript, though [url=http://stackoverflow.com/questions/20689481/recreating-jquerys-ajaxstart-and-ajaxcomplete-functionality]this question might help.
Thanks for the reply!

What happens when the data reloads: The table data reverts to its original height (190px). I want it to be 457px. The table goes to its intended height if I go to the console and type:
document.getElementsByClassName('ui-jqgrid-bdiv')[0].style.height = "457px";

The onchange function does not call. I put this line: window.alert("reformatPage() executed"); into the function so I knew it was actually firing. It never fires except on the page load.

I don't have any AJAXing going on, as far as I'm aware. The network tab in Chrome says some jQuery events are happening.

I'll try some jQuerying around. I haven't tried any jQuery at all yet. I have more to learn.
Post edited February 03, 2016 by Tallima
avatar
Tallima: Thanks for the reply!

What happens when the data reloads: The table data reverts to its original height (190px). I want it to be 457px. The table goes to its intended height if I go to the console and type:
document.getElementsByClassName('ui-jqgrid-bdiv')[0].style.height = "457px";

The onchange function does not call. I put this line: window.alert("reformatPage() executed"); into the function so I knew it was actually firing. It never fires except on the page load.

I don't have any AJAXing going on, as far as I'm aware. The network tab in Chrome says some jQuery events are happening.

I'll try some jQuerying around. I haven't tried any jQuery at all yet. I have more to learn.
It sounds like the table is probably just being replaced when new data is loaded.
(Though thinking about it I think onChange may only work on inputs like text boxes and not on divs or tables etc.)

I would assume the jQuery things in the network tab may be AJAX calls (not sure what else would go on in there) and if jQuery is already in use by the page (so you're not adding any new dependencies) it might just be worth trying adding this line:

$.ajaxComplete(reformatPage);

That may not be entirely the right syntax, on my phone so I can't check it properly, but I think it's about right.

If that doesn't work I found a useful plug in for my script that lets you listen for changes in an element and fire events, which may help if it's not loaded by AJAX.
avatar
Tallima: Thanks for the reply!

What happens when the data reloads: The table data reverts to its original height (190px). I want it to be 457px. The table goes to its intended height if I go to the console and type:
document.getElementsByClassName('ui-jqgrid-bdiv')[0].style.height = "457px";

The onchange function does not call. I put this line: window.alert("reformatPage() executed"); into the function so I knew it was actually firing. It never fires except on the page load.

I don't have any AJAXing going on, as far as I'm aware. The network tab in Chrome says some jQuery events are happening.

I'll try some jQuerying around. I haven't tried any jQuery at all yet. I have more to learn.
avatar
adaliabooks: It sounds like the table is probably just being replaced when new data is loaded.
(Though thinking about it I think onChange may only work on inputs like text boxes and not on divs or tables etc.)

I would assume the jQuery things in the network tab may be AJAX calls (not sure what else would go on in there) and if jQuery is already in use by the page (so you're not adding any new dependencies) it might just be worth trying adding this line:

$.ajaxComplete(reformatPage);

That may not be entirely the right syntax, on my phone so I can't check it properly, but I think it's about right.

If that doesn't work I found a useful plug in for my script that lets you listen for changes in an element and fire events, which may help if it's not loaded by AJAX.
The onchange is attached to a drop-down selector, not the table. The table does not change without the drop-down select box being changed.

I tried your line and it didn't change anything. But thank you anyway! I'll research this some more. If I can use jQuery, that will change my options entirely.
avatar
Tallima: The onchange is attached to a drop-down selector, not the table. The table does not change without the drop-down select box being changed.

I tried your line and it didn't change anything. But thank you anyway! I'll research this some more. If I can use jQuery, that will change my options entirely.
Ah, ok. But you said this onchange was still not being called at all.. I'm not sure why that would happen..
I would say wrap the function contents in a call to setTimeout (basically to delay the function until the table is loaded if that was the problem) but of the onchange function isn't even being called that probably won't help..
avatar
Tallima: The onchange is attached to a drop-down selector, not the table. The table does not change without the drop-down select box being changed.

I tried your line and it didn't change anything. But thank you anyway! I'll research this some more. If I can use jQuery, that will change my options entirely.
avatar
adaliabooks: Ah, ok. But you said this onchange was still not being called at all.. I'm not sure why that would happen..
I would say wrap the function contents in a call to setTimeout (basically to delay the function until the table is loaded if that was the problem) but of the onchange function isn't even being called that probably won't help..
A big issue is that the selector already has an .onchange associated with it in the original programming. I think that may be a huge issue.

That's why I tried to do an onclick event or something similar, but that didn't work either.

The element is declared here:

<select name="ddlMyWorkOrderFilter" id="ddlMyWorkOrderFilter" tabindex="1" class="textboxlabel" onchange="return changeFilter();" style="width:200px;">
<option values....">...proprietary info...

</select>

I reference it by doing this:

document.getElementById('ddlMyWorkOrderFilter').onchange=reformatPage();
and I've tried this:
$("#ddlMyWorkOrderFilter").click(reformatPage());

P.S. and I've tried these:
document.getElementById('ddlMyWorkOrderFilter').onchange="return reformatPage();"
document.getElementById('ddlMyWorkOrderFilter').onchange="reformatPage();"

I don't need to return a result, but I figured what the heck, give it a shot. :)


Here's another oddity:

I added this line:
onkeydown=reformatPage();

And now it reformats the page twice on load, but not again.
Post edited February 03, 2016 by Tallima
avatar
Tallima: A big issue is that the selector already has an .onchange associated with it in the original programming. I think that may be a huge issue.

That's why I tried to do an onclick event or something similar, but that didn't work either.

The element is declared here:

<select name="ddlMyWorkOrderFilter" id="ddlMyWorkOrderFilter" tabindex="1" class="textboxlabel" onchange="return changeFilter();" style="width:200px;">
<option values....">...proprietary info...

</select>

I reference it by doing this:

document.getElementById('ddlMyWorkOrderFilter').onchange=reformatPage();
and I've tried this:
$("#ddlMyWorkOrderFilter").click(reformatPage());

P.S. and I've tried these:
document.getElementById('ddlMyWorkOrderFilter').onchange="return reformatPage();"
document.getElementById('ddlMyWorkOrderFilter').onchange="reformatPage();"

I don't need to return a result, but I figured what the heck, give it a shot. :)

Here's another oddity:

I added this line:
onkeydown=reformatPage();

And now it reformats the page twice on load, but not again.
Hmmm, it is possible (I think?) the other onchange function stops the event propagating and your event never fires..
You could try unbinding the event that's already there and then attach yours (although this will of course stop the data from changing if that function is what is doing it) just to see if that is the cause..
Or you could put the call to the function that is already bound inside your function and then unbind and rebind with your own..
avatar
dtgreene: If you look at the resulting assembly file, you will notice that no memset appears at all. In other words, the compiler has optimized it away!
Because it's a fixed state at a certain point in the code where it will never change, of course it can.

But there's also a C trick that you can use, if you partially set the array, the remainder is set to 0 by default. So... This would have a similar effect. (assuming i'm writing this correctly, been a while).

[code] char x[16] = {0}; [/code]

memset, memcpy, strlen, etc several functions are often inlined, and then after in-lining it can go through another stage of optimization where it realizes what you're doing.

Similar to the effect of doing a bunch of work to calculate a number, if it's all static beforehand then all the calculations are dropped and instead you only get the static number. So say
[code] a=1*2*3*4; [/code]
gets shortened to
[code] a=24; [/code]
Post edited February 03, 2016 by rtcvb32
low rated
avatar
dtgreene: If you look at the resulting assembly file, you will notice that no memset appears at all. In other words, the compiler has optimized it away!
avatar
rtcvb32: Because it's a fixed state at a certain point in the code where it will never change, of course it can.

But there's also a C trick that you can use, if you partially set the array, the remainder is set to 0 by default. So... This would have a similar effect. (assuming i'm writing this correctly, been a while).

[code] char x[16] = {0}; [/code]

memset, memcpy, strlen, etc several functions are often inlined, and then after in-lining it can go through another stage of optimization where it realizes what you're doing.

Similar to the effect of doing a bunch of work to calculate a number, if it's all static beforehand then all the calculations are dropped and instead you only get the static number. So say
[code] a=1*2*3*4; [/code]
gets shortened to
[code] a=24; [/code]
The problem here is that the memory has already been used for some useful purpose, but because it contains sensitive material (like a password or encryption key), we want to clear the memory so that it can't be revealed later.

The situation we want to avoid is something like this:
1. Private key gets used by encryption
2. The memset call is optimized out, so the key is still in memory
3. A bug in the code causes the memory containing the key to be disclosed. (Heartbleed is an example of this type of security vulnerability.)

When writing security sensitive code, optimizations are sometimes *not* what you want.

Your example of a number being calculated at compile time can yield a similar issue. If a remote system responds faster when the username is invalid than if it is valid (assuming an invalid password), that can be used to search for valid usernames. Hence an optimization might not be a good idea; you want operations to be reasonably predictable rather than as fast as possible. (Of course, in this case adding a slightly random delay can be useful, as long as the attacker doesn't manage to crack the RNG.)

Incidentally, OpenBSD's library contains a function called explicit_bzero() which is specified to not be optimized away.
avatar
dtgreene: When writing security sensitive code, optimizations are sometimes *not* what you want.
Hmmm... Optimizations are suppose to run code properly, the fact that it doesn't mean it's possibly a bug, or perhaps you need a special pragma to override how it handles in-lining functions. To be fair though, a huge amount of code doesn't need to be super sensitive.

And usually it will optimize out things it knows statically. Something that changes your stuff by routines it can't guarantee it's results will generally not be optimized; Although i couldn't duplicate that effect with my quick tests, which is too bad.
Post edited February 04, 2016 by rtcvb32
IT? I'm IT. I guess. Software Engineering and Information Systems degrees.

I work on games. Battlefield and Star Wars Battlefront before. Mirror's Edge now.
I have another java question. Thanks for all your help, adaliabooks!

If I hit F12, I can run a function that is present in the original script of the website I'm trying to edit.

I can run it by typing its name().

However, if I try to run that function from a function in a script of mine, it doesn't process.

Should it go through? Do I need to set some sort of permissions or use the original file as a namespace somehow?

avatar
Elenarie: IT? I'm IT. I guess. Software Engineering and Information Systems degrees.

I work on games. Battlefield and Star Wars Battlefront before. Mirror's Edge now.
It's a pleasure to have you here! :)

Press those boys (edit: and girls -- I wasn't trying to be sexist. My bad!) at EA to release some Linux games! :)
Post edited February 04, 2016 by Tallima
avatar
Tallima: I have another java question. Thanks for all your help, adaliabooks!

If I hit F12, I can run a function that is present in the original script of the website I'm trying to edit.

I can run it by typing its name().

However, if I try to run that function from a function in a script of mine, it doesn't process.

Should it go through? Do I need to set some sort of permissions or use the original file as a namespace somehow?
Ehm... it depends if you have any @grants in your script..
Without them I found I could interact with the page's scripts fine, but with them the script is put in a sandbox and is severely limited in accessing javascript from the page.
I doubt you have any grants, so it could just be you need to try window.name() to access the function, or unsafeWindow.name() (which is the sandbox script version of window)

If neither of those work, there are some more complicated methods which can be used (script injection is what I use a lot to make AF work)
avatar
Tallima: I have another java question. Thanks for all your help, adaliabooks!

If I hit F12, I can run a function that is present in the original script of the website I'm trying to edit.

I can run it by typing its name().

However, if I try to run that function from a function in a script of mine, it doesn't process.

Should it go through? Do I need to set some sort of permissions or use the original file as a namespace somehow?
avatar
adaliabooks: Ehm... it depends if you have any @grants in your script..
Without them I found I could interact with the page's scripts fine, but with them the script is put in a sandbox and is severely limited in accessing javascript from the page.
I doubt you have any grants, so it could just be you need to try window.name() to access the function, or unsafeWindow.name() (which is the sandbox script version of window)

If neither of those work, there are some more complicated methods which can be used (script injection is what I use a lot to make AF work)
I must be doing something fundamentally wrong. I'll spend some more time researching it.

If I try to call the function, my entire script doesn't work at all. So something is very, very goofy compared to how I think it should work.

I have lots of others things to do that are more important than this part, anyway. So I'll work on those while I figure out how this all will work.

Thanks again for all your time!