2012-08-01 111 views
1

我有一個Wordpress網站,最終是一個流式廣播網站。在標頭,我是從我的專用服務器的CP拉流數據(如聽衆數和當前播放)的腳本。(Centova演員)

我註冊function.php腳本:

這是寄存器

wp_register_script(’streaminfo’, 'http://94.23.250.14:2199/system/streaminfo.js',false,null); wp_enqueue_script(’streaminfo’);

這是在整個jQuery的部分供您查看..

/* ------------------------------------ 

:: INITIATE JQUERY/STYLING 

------------------------------------ */ 

function init_dynscripts() { 
    if (!is_admin()) { 

     if (function_exists('bp_is_blog_page')) { 
      if (!bp_is_blog_page()) { 
       wp_enqueue_script('bp-js', BP_PLUGIN_URL . '/bp-themes/bp-default/_inc/global.js', array('jquery')); 
      } 
     } 

     wp_register_style('northvantage-style', get_bloginfo('stylesheet_url'),false,null); 
     wp_enqueue_style('northvantage-style'); 


     if(get_option('enable_responsive')!='disable') : 

     wp_register_style('northvantage-responsive', get_template_directory_uri().'/stylesheets/responsive.css',false,null); 
     wp_enqueue_style('northvantage-responsive'); 

     endif; 

     wp_enqueue_script('jquery-ui-core',false,null); 
     wp_enqueue_script('jquery-ui-tabs',false,null); 
     wp_enqueue_script("jquery-ui-accordion",false,null); 
     wp_enqueue_script("swfobject",false,null); 
     wp_deregister_script("jquery-effects-core"); 

     wp_deregister_script('libertas'); 
     wp_register_script('libertas',get_template_directory_uri().'/js/nv-script.pack.js',false,null); 
     wp_enqueue_script('libertas'); 
     wp_register_script(’streaminfo’, 'http://94.23.250.14:2199/system/streaminfo.js',false,null); 
     wp_enqueue_script(’streaminfo’); 
     wp_register_script(’jpie’, get_template_directory_uri().'/js/jpie.js',false,null); 
     wp_enqueue_script(’jpie’); 
     wp_register_style('jpiestyle', get_template_directory_uri().'/jpie.css',false,null); 
     wp_enqueue_style('jpiestyle'); 


     if(get_option('jwplayer_js')) { // Check jw player javascript file is present 

     $NV_jwplayer_js = get_option('jwplayer_js'); 

     wp_deregister_script('jw-player');  
     wp_register_script('jw-player', $NV_jwplayer_js,false,null); 
     wp_enqueue_script('jw-player');  
     } 
    } 
}  
add_action('init', 'init_dynscripts',100); 


function _remove_script_version($src){ // remove script version 
    $parts = explode('?', $src); 
    return $parts[0]; 
} 
add_filter('script_loader_src', '_remove_script_version', 15, 1); 
add_filter('style_loader_src', '_remove_script_version', 15, 1); 

看來我有streaminfo之間的衝突。 JS和我的網站。 元素檢驗得出:

Uncaught TypeError: Property '$' of object [object Window] is not a function

爲了讓事情short..everything我試圖與文件結束了錯。

我試着改變每個$符號到文件中的jQuery,它消除了衝突,但與其他文件產生衝突。

我嘗試添加

jQuery(document).ready(function ($) {

到文件的頭部,但它打破對CP的其他元素。

最終我跑了一個簡單的測試,並創建了一個網頁,只有這樣的代碼:

<html> 
<body> 
<span id="cc_strinfo_title_tranceilfm" class="cc_streaminfo"></span> 
<script language="javascript" type="text/javascript" src="http://94.23.250.14:2199/system/streaminfo.js"></script> 
</body> 
</html> 

和頁面沒有返回任何錯誤。 (我包括谷歌jQuery文件的路徑)

在WordPress的東西搞亂了jQuery插件?或者我的代碼中缺少一些字符串?

www.tranceil.fm

回答

4

嘗試在您的document.ready頂部添加jQuery.noConflict()。這將解除綁定$變量,這應該消除你的衝突。

在迴應我們的意見的討論,並幫助其他人誰看到這個問題,這裏的概述一點:

如何jQuery和jQuery.noConflicts()工作:

當你加載jQuery庫,創建一個名爲jQuery的變量,它代表「jQuery」函數。還創建了名稱爲$jQuery的別名。

無論出於何種原因,其他幾個JavaScript庫都會更改$別名以表示它們自己的函數。發生這種情況時,您會發生衝突,因爲兩種不同的事情都試圖控制$變量。 jQuery.noConflict()所做的是將$jQuery關聯,允許任何其他嘗試使用$的地方自由使用它。

美中不足的是,現在$並不是指jQuery,所以處處要訪問jQuery對象,你需要使用jQuery,而不是$

+0

像這樣? jQuery.noConflict(document).ready(function($){我應該如何關閉它?http://94.23.250.14:2199/system/streaminfo.js – Trance84 2012-08-01 17:15:18

+0

像這樣:jQuery(document).ready(function() {jQuery.noConflict();}); – 2012-08-01 17:17:21

+0

Uncaught TypeError:無法調用null的方法'match':( – Trance84 2012-08-01 17:19:35