Skip to content

Commit

Permalink
Item13898: fix foswiki.getScriptUrl for short urls
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum authored and gac410 committed Jan 6, 2016
1 parent 7ebc93c commit ff2e27f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions JQueryPlugin/lib/Foswiki/Plugins/JQueryPlugin/FOSWIKI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ sub init {
Foswiki::Func::expandCommonVariables( '%' . $pref . '%' );
}

# add {ScriptUrlPaths}
if ( defined $Foswiki::cfg{ScriptUrlPaths} ) {
%{ $prefs{"SCRIPTURLPATHS"} } = %{ $Foswiki::cfg{ScriptUrlPaths} };
}
$prefs{"URLHOST"} = Foswiki::Func::getUrlHost();

my $text =
"<script class='\$zone \$id foswikiPreferences' type='text/json'>"
. JSON::to_json( \%prefs, { pretty => 1 } )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,20 @@ var foswiki = foswiki || {
* Get url path for a specific script
*/
function _getScriptUrl(absolute, script, web, topic, params) {
var prefName = (absolute?"SCRIPTURL":"SCRIPTURLPATH"),
suffix = foswiki.getPreference("SCRIPTSUFFIX") || "",
url, arr = [];
var suffix = foswiki.getPreference("SCRIPTSUFFIX") || "",
scriptUrlPaths = foswiki.getPreference("SCRIPTURLPATHS"),
url = "", arr = [];

script = script || '';

url = foswiki.getPreference(prefName+"_"+script.toUpperCase());
if (absolute) {
url = foswiki.getPreference("URLHOST");
}

if (!url) {
url = foswiki.getPreference(prefName) + "/" + script + suffix;
if (typeof(scriptUrlPaths[script]) === 'undefined') {
url += foswiki.getPreference("SCRIPTURLPATH") + "/" + script + suffix;
} else {
url += scriptUrlPaths[script];
}

if (typeof(web) !== 'undefined') {
Expand All @@ -184,6 +188,7 @@ var foswiki = foswiki || {
url += (arr.length?"?"+arr.join("&"):"");
}


return url;
}

Expand Down Expand Up @@ -236,7 +241,7 @@ var foswiki = foswiki || {
$('body').removeClass('foswikiNoJs').addClass("foswikiJs");

/* load foswiki preferences */
$(".foswikiPreferences").each(function() {
$(".foswikiPreferences").livequery(function() {
$.extend(foswiki.preferences, $.parseJSON($(this).html()));
});

Expand Down

0 comments on commit ff2e27f

Please sign in to comment.