kennejimaの日記

2007-11-14

lingr.jsroom.observeを繰り返していると404エラーが返ってきてしまう問題の修正 05:44

id:d:Gimiteさんがパッチを送ってきてくれたので適用しました。

http://svn.lingr.com/api/toolkits/javascript/infoteria/lingr.js/lingr.js

Thanks!

Index: lingr.js
===================================================================
--- lingr.js	(revision 42)
+++ lingr.js	(working copy)
@@ -11,6 +11,7 @@
   initialize: function(options) {
     this.options = {
       prefix: Math.round(Math.random() * 100) + '.',
+      prefixForObserve: Math.round(Math.random() * 100) + 'o.',
       apiDomain: 'www.lingr.com',
       dsrTimeout: 9000,
       userMessagesOnly: false,
@@ -29,8 +30,9 @@
   
   emptyFunction: function() {},
   
-  url: function(path) {
-    return "http://" + this.options.prefix + this.options.apiDomain + '/api' + path;
+  url: function(path, observe) {
+    var prefix = observe ? this.options.prefixForObserve : this.options.prefix;
+    return "http://" + prefix + this.options.apiDomain + '/api' + path;
   },
   
   formatParams: function(params) {
@@ -40,6 +42,7 @@
   request: function(method, path, params, options) {
     options = options || {};
     var head = document.getElementsByTagName('head')[0];
+    var url = this.url(path, options.observe);
     var script;
     if (this.options.useDsr) {
       
@@ -60,7 +63,7 @@
         script = document.createElement('script');
         script.type = 'text/javascript';
         script.charset = 'UTF-8';
-        script.src = this.url(path) + '?' + this.formatParams(params);
+        script.src = url + '?' + this.formatParams(params);
         head.appendChild(script);
         this.timeout = setTimeout(params.callback, options.timeout || this.options.dsrTimeout);
       } catch(e) {
@@ -68,7 +71,7 @@
       }
     }
     else {
-      new Ajax.Request(this.url(path), {
+      new Ajax.Request(url, {
         method: method,
         parameters: this.formatParams(params),
         onSuccess: (options.onSuccess || this.emptyFunction).bindWithEval(this),
@@ -354,7 +357,8 @@
     }.bind(this),
     onFailure: function(json) {
         this.session.lingr.dispatchEvent('ApiFailure', json);
-    }
+    },
+    observe: true
   });
 },