我创建了一个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