News:

Support the VirtueMart project and become a member

Main Menu

vmJsApi broken for google hosted api

Started by mmally, July 26, 2013, 20:53:06 PM

Previous topic - Next topic

mmally

when using vmJsAPI to load e.g. jquery hosted on google the function builds the path wrong.

For Example:
vmJsApi::js('jquery', '//ajax.googleapis.com/ajax/libs/jquery','1.10.2',true);

results in
<script src="//ajax.googleapis.com/ajax/libs/jquery/jquery.1.10.2.min.js" type="text/javascript"></script>

instead of
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>


Here is a fix, which is working for me. The following is valid for 2.0.22a.
In \administrator\components\com_virtuemart\helpers\config.php add beginning with line 1040:


public static function setPath( $namespace ,$path = FALSE ,$version='' ,$minified = NULL , $ext = 'js', $absolute_path=false)
{

   if (strpos($path,"ajax.googleapis.com") !== FALSE)
   {
      $min = $minified ? '.min' : '';
      $file = $namespace.$min.'.'.$ext;
      return "$path/$version/$file";
    }
    else
    {
      $version = $version ? '.'.$version : '';
      $min = $minified ? '.min' : '';
      $file = $namespace.$version.$min.'.'.$ext ;
    }


I hope this will be fixed in VM to make updates easier.

Cheers,
Mike

mmally

Just noticed that the real problem is an outdated Wiki, which is not valid anymore.

Instead of using

vmJsApi::js('jquery-ui','//ajax.googleapis.com/ajax/libs/jqueryui','1.8.16',true);

the correct way seems to be

vmJsApi::js('jquery-ui','//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16','',true);


so there is no need fo a fix, please just update the Wiki.

PRO

link to the wiki page and what needs to be corrected

mmally

Wiki page: http://dev.virtuemart.net/projects/virtuemart/wiki/JavascriptCSS_Template_Overrides_and_Avoiding_Conflicts_between_Libraries

current text
A Full Example:
vmJsApi::js('jquery-ui','//ajax.googleapis.com/ajax/libs/jqueryui';,'1.8.16',true);
....
In this example we load '//ajax.googleapis.com/ajax/libs/jqueryui/jquery-ui.1.8.16.min.js'


new text
vmJsApi::js('jquery-ui','//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16','',true);
...
In this example we load '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js'

Regards,
Mike