[ticket/10390] Improve the jQuery CDN url generation function

Per p's comments, return the remote url from a variable instead of
using multiple returns. Also put the logic for creating Google's version
on its own line, and count the version number's dots instead of length
so it will be less likely to break if jQuery goes to version 1.10.

PHPBB3-10390
This commit is contained in:
Matt Friedman 2011-09-25 18:16:25 -07:00
parent 39840ef36d
commit abb0f3f96d

View file

@ -4781,18 +4781,21 @@ function remote_jquery_url($host)
switch($host)
{
case 'google':
// Google uses a 1.5.0, 1.5.1 format (it is always a three numbered version)
return '//ajax.googleapis.com/ajax/libs/jquery/' . ((strlen(JQUERY_VERSION) == 3) ? JQUERY_VERSION . '.0' : JQUERY_VERSION) . '/jquery.min.js';
// Google uses a 1.5.0, 1.5.1 format (it adds a .0 to new 1.X releases)
$version = (substr_count(JQUERY_VERSION, '.') == 1) ? JQUERY_VERSION . '.0' : JQUERY_VERSION;
// HTTP protocol intentionally omitted - its the best way to reference third party content that is available via both HTTP and HTTPS
$url = '//ajax.googleapis.com/ajax/libs/jquery/' . $version . '/jquery.min.js';
break;
case 'microsoft':
// Microsoft uses a 1.5, 1.5.1 format
return 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' . JQUERY_VERSION . '.min.js';
$url = 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-' . JQUERY_VERSION . '.min.js';
break;
case 'jquery':
// jQuery uses a 1.5, 1.5.1 format
return 'http://code.jquery.com/jquery-' . JQUERY_VERSION . '.min.js';
$url = 'http://code.jquery.com/jquery-' . JQUERY_VERSION . '.min.js';
break;
}
return $url;
}