Main Contents

[wordpress] Google AJAX Libraries API Plugin

前幾天 Google 提供幾個知名 javascript 函式庫的hosting, 就想到 wordpress blog 能不能也利用該服務, 好歹可以省掉 jquery (30K) 和 prototype (124K) 的流量, 尤其是放在(暴)慢的主機 ( 如 dreamhoXt … ) 效果非常明顯…
用 google 找到 Google AJAX Libraries API Plugin , 可惜有些問題, 寄修改檔給作者, 希望下一個版本能修正.作者已於0.6版本修正, 請至該作者網頁下載.

==== GEEK 分隔線 ====
UPDATE: v0.6已修正
該 plugin 沒寫授權方法, 所以我不好意思直接修改放出…
wordpress 用的是加上 jQuery.noConflict() 的 jquery , 而 google 提供的沒有, 以至於直接使用 google 的 jquery 會導致和 prototype 衝突. 我的修改方式是在 jquery script 之後, 再加入一個內容為 jQuery.noConflict() 的 script .

在 usegooglelibrary.php (0.5版本) 加入
function gs_add_jquery_noconflict( $js_array ) {
if ( FALSE !== $jquery = array_search( 'jquery', $js_array ) ) {
wp_register_script('jquery_noconflict', '/wp-content/plugins/j.js', array('jquery'), null);
array_splice( $js_array, $jquery+1, 0, 'jquery_noconflict' );
}
return $js_array;
}
add_filter('print_scripts_array', 'gs_add_jquery_noconflict');

以及在 wp-content/plugins 裡新增一個名為 j.js 的檔案, 內容為
jQuery.noConflict();
就會在載入 jquery 之後, 載入 j.js . 且不會和 prototype 衝突. 效果請看筆者 blog 的原始碼. 有錯誤/建議歡迎指教.

1 則迴響

  1. » Google AJAX Libraries API 插件 坚定地走… 六月 9, 2008 @ 8:13 上午

    [...] 另外:有个修改jquery 和 prototype 冲突的方法,这里 [...]

發表迴響



Feed