ZF-8794: addJavascriptFile() with support to prefix with javascript code

Issue Type: Improvement Created: 2010-01-12T13:58:31.000+0000 Last Updated: 2012-11-20T21:37:33.000+0000 Status: Open Fix version(s): Reporter: Martin Minka (k2s) Assignee: None Tags: - ZendX_JQuery

Related issues: Attachments:


There is problem to load jQuery plugins which require some configuration in jQuery namespace before loading of js file. As an example I will use jqGrid library.

Following code will not work, because jQuery() will render always files before embeded scripts and we need to set useJSON before jquery.jqGrid.min.js, but after grid.locale-en.js.

<pre class="highlight">
echo $this->jQuery()
    ->addJavascriptFile($jqgridLibPath . '/js/i18n/grid.locale-en.js')
    ->addJavascript('jQuery.jgrid.useJSON = true;')
    ->addJavascriptFile($jqgridLibPath . '/js/jquery.jqGrid.min.js');

With Zend_View_Helper_HeadScript I could do following:

<pre class="highlight">
echo $this->headScript()
    ->appendFile($jqgridLibPath . '/js/i18n/grid.locale-en.js')
    ->appendScript('jQuery.jgrid.useJSON = true;')
    ->appendFile($jqgridLibPath . '/js/jquery.jqGrid.min.js');
  1. Solution could be to change the rendering order to comply with Zend_View_Helper_HeadScript, so it will mix embeded and loaded Javascript in order it was added.
  2. Other solution could be to add function like addJavascriptBetweenFiles() and only that would keep the order:
<pre class="highlight">
echo $this->jQuery()
    ->addJavascriptFile($jqgridLibPath . '/js/i18n/grid.locale-en.js')
    ->addJavascriptBetweenFiles('jQuery.jgrid.useJSON = true;')
    ->addJavascriptFile($jqgridLibPath . '/js/jquery.jqGrid.min.js');


Posted by Benjamin Eberlei (beberlei) on 2010-01-29T01:49:29.000+0000

Not a blocker, I have to think how to solve this.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.