我創建了一個externs文件,可以使用Google Closure編譯器的ADVANCED_OPTIMIZATIONS編譯jQuery Star Rating Plugin fyneworks.com/jquery/star-rating/#tab-Testing。extern for jQuery Star Rating Plugin和Google Closure Compiler
但是,即使我引用了標準的jQuery extern,'$'也會被重命名,導致插件崩潰。
也許相關:如果我使用未修改的插件,'評分'也會被重命名。我可以修復與部分:
$.fn['rating'] = function(opts) {
從google closure compile jQuery Plugin ......但是,這並不固定「$」(它會是不錯的使用未修改的插件,如果可能的話)。
從我在一個外部的企圖(這可能是錯誤的和/或不完整):
// ??? for '$'
// this one does NOT prevent 'rating' from being renamed
function rating(arg1) {}
// the following seem to work: they prevent the functions from being renamed
rating.focus = function() {}
rating.blur = function() {}
rating.fill = function() {}
... etc.
命令行(和rating.sh在下載):
java -jar ../compiler-latest/compiler.jar --formatting pretty_print --compilation_level ADVANCED_OPTIMIZATIONS --externs externs/jquery-1.7.js --externs externs/jquery.rating-extern.js --js original/jquery.rating.js --js_output_file jquery.rating.gcc.js
錯誤信息:
Firefox:
$(".star1").rating is not a function
callback: function (value) {
jquery.ratingSampleCode.js (line 9)
Chrome:
Uncaught TypeError: Object [object Object] has no method 'rating'
jquery.ratingSampleCode.js:8
從我的示例代碼:
$('.star1').rating({
callback: function (value) {
測試:http://prefabsoftware.com/test/rating-july15/
下載:prefabsoftware.com/test/rating-july15.zip
一些有用的鏈接:(這我不能指定爲降價,因爲我不能」牛逼登錄與我的老口碑點...)
- 高級編輯和實習醫生:developers.google.com/closure/compiler/docs/api-tutorial3#externs
- 樣品實習醫生:contrib請:代碼。 google.com/p/closure-compiler/source/browse/#svn%2Ftrunk%2Fcontrib%2Fexterns)包括jQuery本身,但不包括評級插件
- 更多externs:code.google.com/p/closure-compiler/源/瀏覽/#svn%2Ftrunk%2Fexterns
是否有一個簡單的修復extern?還是更好的解決方案?
謝謝!
好吧,這個作品爲實習醫生文件:
$.prototype.rating = function(arg1) {}
jQuery.prototype.rating = function(arg1) {}
$.prototype.rating.focus = function() {}
... etc.
我看到:我應該實際編譯之外的所有插件,只是引用通常的方式。並且,非常感謝外部提示;我添加了以上工作代碼,因爲我無法添加此評論。 – 2012-07-18 10:49:07