[Pkg-javascript-commits] [sockjs-client] 110/350: Cleanup jsonp sender a little bit

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:48 UTC 2016


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch upstream
in repository sockjs-client.

commit 2dd5811ea01343874c7c86676acc4129d4f4f7af
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Fri Oct 10 13:20:02 2014 -0400

    Cleanup jsonp sender a little bit
---
 lib/transport/sender/jsonp.js | 59 +++++++++++++++++++++++++------------------
 1 file changed, 34 insertions(+), 25 deletions(-)

diff --git a/lib/transport/sender/jsonp.js b/lib/transport/sender/jsonp.js
index 0484526..e9ae503 100644
--- a/lib/transport/sender/jsonp.js
+++ b/lib/transport/sender/jsonp.js
@@ -3,37 +3,46 @@
 var random = require('../../utils/random')
   ;
 
-module.exports = function (url, payload, callback) {
-  var form = global._sendForm;
-  var area = global._sendArea;
+var form, area;
+
+function createIframe (id) {
+  try {
+    // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
+    return global.document.createElement('<iframe name="' + id + '">');
+  } catch(x) {
+    var iframe = global.document.createElement('iframe');
+    iframe.name = id;
+    return iframe;
+  }
+}
+
+function createForm() {
+  form = global.document.createElement('form');
+  form.style.display = 'none';
+  form.style.position = 'absolute';
+  form.method = 'POST';
+  form.enctype = 'application/x-www-form-urlencoded';
+  form.acceptCharset = 'UTF-8';
+
+  area = global.document.createElement('textarea');
+  area.name = 'd';
+  form.appendChild(area);
 
+  global.document.body.appendChild(form);
+}
+
+module.exports = function (url, payload, callback) {
   if (!form) {
-    form = global._sendForm = global.document.createElement('form');
-    area = global._sendArea = global.document.createElement('textarea');
-    area.name = 'd';
-    form.style.display = 'none';
-    form.style.position = 'absolute';
-    form.method = 'POST';
-    form.enctype = 'application/x-www-form-urlencoded';
-    form.acceptCharset = 'UTF-8';
-    form.appendChild(area);
-    global.document.body.appendChild(form);
+    createForm();
   }
   var id = 'a' + random.string(8);
   form.target = id;
   form.action = url + '/jsonp_send?i=' + id;
 
-  var iframe;
-  try {
-    // ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
-    iframe = global.document.createElement('<iframe name="' + id + '">');
-  } catch(x) {
-    iframe = global.document.createElement('iframe');
-    iframe.name = id;
-  }
+  var iframe = createIframe(id);
   iframe.id = id;
-  form.appendChild(iframe);
   iframe.style.display = 'none';
+  form.appendChild(iframe);
 
   try {
     area.value = payload;
@@ -50,9 +59,9 @@ module.exports = function (url, payload, callback) {
     // Opera mini doesn't like if we GC iframe
     // immediately, thus this timeout.
     setTimeout(function() {
-                   iframe.parentNode.removeChild(iframe);
-                   iframe = null;
-               }, 500);
+      iframe.parentNode.removeChild(iframe);
+      iframe = null;
+    }, 500);
     area.value = '';
     // It is not possible to detect if the iframe succeeded or
     // failed to submit our form.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list