Browse Source

Showing simple form if nanogong doesn't load see #4493

Julio Montoya 12 years ago
parent
commit
732aed1cb8
3 changed files with 63 additions and 66 deletions
  1. 5 18
      main/document/document.php
  2. 47 2
      main/inc/lib/document.lib.php
  3. 11 46
      main/inc/lib/nanogong.lib.php

+ 5 - 18
main/document/document.php

@@ -492,24 +492,11 @@ if (!empty($docs_and_folders))
                     $extension = 'oga';
                 }
                 //$("#jplayer_inspector_'.$count.'").jPlayerInspector({jPlayer:$("#jquery_jplayer_'.$count.'")});
-                $jquery .= ' $("#jquery_jplayer_' . $count . '").jPlayer({                                
-                                ready: function() {                    
-                                    $(this).jPlayer("setMedia", {                                        
-                                        ' . $extension . ' : "' . $document_data['direct_url'] . '"                                                                                  
-                                    });
-                                },
-                                play: function() { // To avoid both jPlayers playing together.
-                                    $(this).jPlayer("pauseOthers");
-                                },                                
-                                //errorAlerts: true,
-                                //warningAlerts: true,
-                                swfPath: "' . $js_path . 'jquery-jplayer",
-                                //supplied: "m4a, oga, mp3, ogg, wav",
-                                supplied: "' . $extension . '",
-                                wmode: "window",
-                                solution: "flash, html",  // Do not change this setting 
-                                cssSelectorAncestor: "#jp_container_' . $count . '", 
-                            });  	 ' . "\n\n";
+                $params = array('url' => $document_data['direct_url'],
+                                'extension' =>$extension,
+                                'count'=> $count
+                 );
+                $jquery .= DocumentManager::generate_jplayer_jquery($params);
                 $count++;
             }
         }

+ 47 - 2
main/inc/lib/document.lib.php

@@ -2448,6 +2448,36 @@ class DocumentManager {
         }
         return true;
     }
+    
+    /**
+     * 
+     * @param array paremeters: count, url, extension
+     * @return string
+     */
+    
+    function generate_jplayer_jquery($params = array()) {
+        $js_path 		= api_get_path(WEB_LIBRARY_PATH).'javascript/';        
+        
+        $jplayer_definition = ' $("#jquery_jplayer_' . $params['count'] . '").jPlayer({                                
+                            ready: function() {                    
+                                $(this).jPlayer("setMedia", {                                        
+                                    ' . $params['extension'] . ' : "' . $params['url'] . '"                                                                                  
+                                });
+                            },
+                            play: function() { // To avoid both jPlayers playing together.
+                                $(this).jPlayer("pauseOthers");
+                            },                                
+                            //errorAlerts: true,
+                            //warningAlerts: true,
+                            swfPath: "' . $js_path . 'jquery-jplayer",
+                            //supplied: "m4a, oga, mp3, ogg, wav",
+                            supplied: "' . $params['extension'] . '",
+                            wmode: "window",
+                            solution: "flash, html",  // Do not change this setting 
+                            cssSelectorAncestor: "#jp_container_' . $params['count'] . '", 
+                        });  	 ' . "\n\n";
+        return $jplayer_definition;
+    }
 
     /**
      *
@@ -2455,8 +2485,21 @@ class DocumentManager {
      * @param int
      * @return string	html content
      */
-    function generate_media_preview($i) {
+    function generate_media_preview($i, $type = 'simple') {
         $i = intval($i);
+        
+        $extra_controls = $progress = '';
+        if ($type == 'advanced') {
+            $extra_controls = ' <li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li>
+                                <li><a href="#" class="jp-mute" tabindex="1">mute</a></li>
+								<li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li>';
+            $progress = '<div class="jp-progress">
+                                <div class="jp-seek-bar">
+                                    <div class="jp-play-bar"></div>
+                                </div>
+                            </div>';
+        }
+        
         //Shows only the play button
         $html = '<div id="jquery_jplayer_'.$i.'" class="jp-jplayer"></div>
                 <div id="jp_container_'.$i.'" class="jp-audio">
@@ -2465,7 +2508,9 @@ class DocumentManager {
                             <ul class="jp-controls">
                                 <li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li>
                                 <li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li>
-                            </ul>
+                                '.$extra_controls.'
+                            </ul>                            
+                            '.$progress.'                            
                         </div>
                     </div>
                 </div>';

+ 11 - 46
main/inc/lib/nanogong.lib.php

@@ -352,67 +352,32 @@ class Nanogong {
 					$html .= '</div>';
 				$html .= '</div>';
 						
-				$html .= '<div id="nanogong_warning">'.Display::return_message(get_lang('BrowserNotSupportNanogongListen'),'warning').$download_button.'</div>';
-				
+				$html .= '<div id="nanogong_warning">'.Display::return_message(get_lang('BrowserNotSupportNanogongListen'),'warning').$download_button.'</div>';				
 				
 			} elseif(in_array($path_info['extension'],array('mp3', 'ogg','wav'))) {
 				$js_path 		= api_get_path(WEB_LIBRARY_PATH).'javascript/';
 				
 				$html .= '<link rel="stylesheet" href="'.$js_path.'jquery-jplayer/skins/blue/jplayer.blue.monday.css" type="text/css">';
+                //$html .= '<link rel="stylesheet" href="' . $js_path . 'jquery-jplayer/skins/chamilo/jplayer.blue.monday.css" type="text/css">';
 				$html .= '<script type="text/javascript" src="'.$js_path.'jquery-jplayer/jquery.jplayer.min.js"></script>';
 				
 				$html .= '<div class="nanogong_player"></div>';
 				$html .= '<br /><div class="action_player">'.$actions.'</div><br /><br /><br />';
 				
-				$jquery .= ' $("#audio_preview").jPlayer({
-                                ready: function() {                    
-                                    $(this).jPlayer("setMedia", {                                        
-                                        '.$path_info['extension'].' : "'.$url.'"                                                                                  
-                                    });
-                                },                            
-                                swfPath: "'.$js_path.'jquery-jplayer",                                
-                                supplied: "mp3, ogg, oga, wav",
-		                        solution: "flash, html",  // Do not change this setting otherwise
-		                        width:0,
-		                        height:0,
-                            });';
+                $params = array('url' => $url,
+                                'extension' =>$path_info['extension'],
+                                'count'=> 1                                 
+                 );
+                $jquery = DocumentManager::generate_jplayer_jquery($params);
+                
 				
-				$html .= '<script type="text/javascript">
+				$html .= '<script>
 				$(document).ready( function() {        
 				    //Experimental changes to preview mp3, ogg files        
 				     '.$jquery.'                 
 				});
-				</script>';
-				
-				//@todo fix this
-				$html .= '
-						<div id="audio_preview" class="jp-jplayer"></div>
-							<div class="jp-audio audio_preview_container">
-								<div class="jp-type-single">
-									<div id="jp_interface_1" class="jp-interface">
-										<ul class="jp-controls">
-											<li><a href="#" class="jp-play" tabindex="1">play</a></li>
-											<li><a href="#" class="jp-pause" tabindex="1">pause</a></li>
-											<li><a href="#" class="jp-stop" tabindex="1">stop</a></li>
-											<li><a href="#" class="jp-mute" tabindex="1">mute</a></li>
-											<li><a href="#" class="jp-unmute" tabindex="1">unmute</a></li>
-										</ul>
-										<div class="jp-progress">
-											<div class="jp-seek-bar">
-												<div class="jp-play-bar"></div>
-											</div>
-										</div>
-										<div class="jp-volume-bar">
-											<div class="jp-volume-bar-value"></div>
-										</div>
-										<div class="jp-current-time"></div>
-										<div class="jp-duration"></div>
-									</div>					
-									<div id="jp_playlist_1" class="jp-playlist">					
-									</div>
-								</div>
-							</div>
-							<br />';				
+				</script>';				
+				$html .= DocumentManager::generate_media_preview(1, 'advanced');
 			}
 			return $html;
 		}