iframe-wrap.js 981 B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict';
  2. var inherits = require('inherits')
  3. , IframeTransport = require('../iframe')
  4. , objectUtils = require('../../utils/object')
  5. ;
  6. module.exports = function(transport) {
  7. function IframeWrapTransport(transUrl, baseUrl) {
  8. IframeTransport.call(this, transport.transportName, transUrl, baseUrl);
  9. }
  10. inherits(IframeWrapTransport, IframeTransport);
  11. IframeWrapTransport.enabled = function(url, info) {
  12. if (!global.document) {
  13. return false;
  14. }
  15. var iframeInfo = objectUtils.extend({}, info);
  16. iframeInfo.sameOrigin = true;
  17. return transport.enabled(iframeInfo) && IframeTransport.enabled();
  18. };
  19. IframeWrapTransport.transportName = 'iframe-' + transport.transportName;
  20. IframeWrapTransport.needBody = true;
  21. IframeWrapTransport.roundTrips = IframeTransport.roundTrips + transport.roundTrips - 1; // html, javascript (2) + transport - no CORS (1)
  22. IframeWrapTransport.facadeTransport = transport;
  23. return IframeWrapTransport;
  24. };