[LON-CAPA-cvs] cvs: loncom /interface lonmenu.pm

raeburn raeburn at source.lon-capa.org
Sun Sep 21 21:02:53 EDT 2014


raeburn		Mon Sep 22 01:02:53 2014 EDT

  Modified files:              
    /loncom/interface	lonmenu.pm 
  Log:
  Bug 6744
  - Avoid conflict between location.host and host used in absolute URL
    for javascript:gopost() and javascript:gocmd() links in inline menu 
    (external resources and syllabus on SSL server -- bug 6662). 
  
  
Index: loncom/interface/lonmenu.pm
diff -u loncom/interface/lonmenu.pm:1.428 loncom/interface/lonmenu.pm:1.429
--- loncom/interface/lonmenu.pm:1.428	Sun Jun 22 19:46:48 2014
+++ loncom/interface/lonmenu.pm	Mon Sep 22 01:02:52 2014
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines to control the menu
 #
-# $Id: lonmenu.pm,v 1.428 2014/06/22 19:46:48 raeburn Exp $
+# $Id: lonmenu.pm,v 1.429 2014/09/22 01:02:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1506,8 +1506,26 @@
 
     my $countdown = &countdown_toggle_js();
 
+    my $hostvar = '
+function setLCHost() {
+    var lcHostname="";
+';
+    if ($httphost =~ m{^https?\://}) {
+        $hostvar .= '    var lcServer="'.$httphost.'";'."\n".
+                    '    var hostReg = /^https?:\/\/([^\/]+)$/i;'."\n".
+                    '    var match = hostReg.exec(lcServer);'."\n".
+                    '    if (match.length) {'."\n".
+                    '        if (match[1] == location.hostname) {'."\n".
+                    '            lcHostname=lcServer;'."\n".
+                    '        }'."\n".
+                    '    }'."\n";
+    }
+    
+    $hostvar .= '    return lcHostname;'."\n".
+'}'."\n";
+
 return (<<ENDUTILITY)
-    var host="$httphost";
+    $hostvar
     var currentURL=unescape("$esc_url");
     var reloadURL=unescape("$esc_url");
     var currentSymb=unescape("$esc_symb");
@@ -1518,7 +1536,8 @@
 
 function gopost(url,postdata) {
    if (url!='') {
-      this.document.server.action=host+url;
+      var lcHostname = setLCHost();
+      this.document.server.action=lcHostname+url;
       this.document.server.postdata.value=postdata;
       this.document.server.command.value='';
       this.document.server.url.value='';
@@ -1529,7 +1548,8 @@
 
 function gocmd(url,cmd) {
    if (url!='') {
-      this.document.server.action=host+url;
+      var lcHostname = setLCHost();
+      this.document.server.action=lcHostname+url;
       this.document.server.postdata.value='';
       this.document.server.command.value=cmd;
       this.document.server.url.value=currentURL;
@@ -1581,7 +1601,8 @@
    if (url!='' && url!= null) {
        currentURL = null;
        currentSymb= null;
-       top.location.href=host+url;
+       var lcHostname = setLCHost();
+       top.location.href=lcHostname+url;
    }
 }
 
@@ -1596,11 +1617,13 @@
 }
 
 function chat_win() {
-   lonchat=window.open(host+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
+   var lcHostname = setLCHost();
+   lonchat=window.open(lcHostname+'/res/adm/pages/chatroom.html',"LONchat",'height=320,width=480,resizable=yes,location=no,menubar=no,toolbar=no');
 }
 
 function group_chat(group) {
-   var url = host+'/adm/groupchat?group='+group;
+   var lcHostname = setLCHost();
+   var url = lcHostname+'/adm/groupchat?group='+group;
    var winName = 'LONchat_'+group;
    grpchat=window.open(url,winName,'height=320,width=280,resizable=yes,location=no,menubar=no,toolbar=no');
 }
@@ -1620,12 +1643,13 @@
 
 function open_StoredLinks_Import(rat) {
    var newWin;
+   var lcHostname = setLCHost();
    if (rat) {
-       newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
+       newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import&rat='+rat,
                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
    }
    else {
-       newWin = window.open(host+'/adm/wishlist?inhibitmenu=yes&mode=import',
+       newWin = window.open(lcHostname+'/adm/wishlist?inhibitmenu=yes&mode=import',
                             'wishlistImport','scrollbars=1,resizable=1,menubar=0');
    }
    newWin.focus();




More information about the LON-CAPA-cvs mailing list