ZF-9124: JQuery auto-enables if ZendX_Application_Resource_Jquery is used


When you add JQuery support via resources, e.g. in config.ini:

resources.jquery.stylesheet = "/styles/blitzer/jquery-ui.css"

It becomes always enabled. The problem is located inside ZendX_Application_Resource_Jquery::_parseOptions() method. Options are pared inside foreach loop:

109         foreach ($options as $key => $value) {
...         ...
156         }

But somebody put code for uienable parameter outside that loop:

158         if ((isset($key['uienable']) && (bool) $key['uienable'])
159             || (isset($key['ui_enable']) && (bool) $key['ui_enable'])
160             || (!isset($key['ui_enable']) && !isset($key['uienable'])))
161         {
162             $this->_view->JQuery()->uiEnable();
163         } else {
164             $this->_view->JQuery()->uiDisable();
165         }

There are two ways of solving this: First is to put code back into foreach loop, so the case will look like:

case 'uienable':
case 'ui_enable':
    if ((bool) $value) {
    } else {

I also propose to include new option:

case 'enable':
    if ((bool) $value) {
    } else {

But to keep less lines of code and to keep somebody's idea to move logic of uienable option parsing out from that loop, I have prepared a patch which I will attach to this report.


My proposed patch

I believe this is just an error, as in ZendX_Application_Resource_Jquery it says


 *   resources.Jquery.uienable = true;
 *   resources.Jquery.ui_enable = true;

Should be fixed, though,because there's no way to disable JQuery UI unless you put the "uienable" option last in the specified options, and even then, it will only work when you have specified a "cdn_ssl" option, as otherwise, the "cdn_ssl" option is appended to the specified options and will be the last value in the iteration.

Yes, it's an error. And that was what I said. Bug == error. Or what did you tried to say?

Benjamin, I think this is an issue with zendx_jquery, cause imho it shouldn't enable the ui part unless uiEnable() got called. If you disagree, please elaborate and reassign to me.

{quote}But to keep less lines of code and to keep somebody's idea to move logic of uienable option parsing out from that loop,{quote}

That 'somebody' would be me. So if you have any questions about that, feel free to ask.


I don't have any questions.

I found a bug, fixed it (at least in my project) and shared patch with you. If you'll look into the code (at least at the part that I showed) you'll see that this code is totally unpredictable. Using variables from the loop outside it - is not good idea at all.

This is not an issue with ZendX_JQuery, it's an issue with ZendX_Application_Resource_Jquery. ZendX_Jquery doesn't enabled by default, but it get's if you'll use ZendX_Application_Resource_Jquery, as the last auto-enables jQuery UI because of small bug (or one may call it a "feature"). And enabling of jQuery UI in it's turn enables jQuery.

So, NO! This is not an issue with ZendX_JQuery.

PS In fact, you can resolve this issue with "not a bug" and pretend that it should be as it is. All I wanted is to point out the bug someone can mess with (as I did) and share a solution. Will you fix it or not - I don't care. :))

Version 1.10.6 Still the same problem. :( Apply the patch.

This is definitely an issue with ZendX_Application_Resource_Jquery. Without even considering any jQuery plugin semantics: $key['uienable'] is currently used in a scope that $key is not even defined in. At least it wouldn't be if we were using a "real" programming language. ;-)

So please, fix this issue in the next release.

This issue was fixed with ZF-9980, committed with r22499 and merged with the release branch in r22500. Unfortunately 1.10.6 was packaged around r 22482, so it just missed it. You can either use trunk, apply the patch yourself, or wait for August. Usually in the first week of each month a new mini release is released.