/javascripts/lib/docs/source/jsonp.html

https://bitbucket.org/ksokmesa/sina-asian · HTML · 88 lines · 80 code · 8 blank · 0 comment · 0 complexity · 4ab11c4d1bc83f41dd8394809d56da8f MD5 · raw file

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.2.1
  11. * Copyright(c) 2006-2010 Ext JS, Inc.
  12. * licensing@extjs.com
  13. * http://www.extjs.com/license
  14. */
  15. Ext.ns('Ext.ux');
  16. Ext.ux.JSONP = (function(){
  17. var _queue = [],
  18. _current = null,
  19. _nextRequest = function() {
  20. _current = null;
  21. if(_queue.length) {
  22. _current = _queue.shift();
  23. _current.script.src = _current.url + '?' + _current.params;
  24. document.getElementsByTagName('head')[0].appendChild(_current.script);
  25. }
  26. };
  27. return {
  28. request: function(url, o) {
  29. if(!url) {
  30. return;
  31. }
  32. var me = this;
  33. o.params = o.params || {};
  34. if(o.callbackKey) {
  35. o.params[o.callbackKey] = 'Ext.ux.JSONP.callback';
  36. }
  37. var params = Ext.urlEncode(o.params);
  38. var script = document.createElement('script');
  39. script.type = 'text/javascript';
  40. if(o.isRawJSON) {
  41. if(Ext.isIE) {
  42. Ext.fly(script).on('readystatechange', function() {
  43. if(script.readyState == 'complete') {
  44. var data = script.innerHTML;
  45. if(data.length) {
  46. me.callback(Ext.decode(data));
  47. }
  48. }
  49. });
  50. }
  51. else {
  52. Ext.fly(script).on('load', function() {
  53. var data = script.innerHTML;
  54. if(data.length) {
  55. me.callback(Ext.decode(data));
  56. }
  57. });
  58. }
  59. }
  60. _queue.push({
  61. url: url,
  62. script: script,
  63. callback: o.callback || function(){},
  64. scope: o.scope || window,
  65. params: params || null
  66. });
  67. if(!_current) {
  68. _nextRequest();
  69. }
  70. },
  71. callback: function(json) {
  72. _current.callback.apply(_current.scope, [json]);
  73. Ext.fly(_current.script).removeAllListeners();
  74. document.getElementsByTagName('head')[0].removeChild(_current.script);
  75. _nextRequest();
  76. }
  77. }
  78. })();</pre>
  79. </body>
  80. </html>