sdk-jsb.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. 'use strict'
  2. cc.loader.downloader.loadSubpackage = function(name, progressCallback, completeCallback) {
  3. if (!completeCallback && progressCallback) {
  4. completeCallback = progressCallback;
  5. progressCallback = null;
  6. }
  7. if (completeCallback) {
  8. completeCallback(null);
  9. }
  10. }
  11. var AdObj = {
  12. load: function() {
  13. setTimeout(function() {
  14. adsdk_request_result("onLoad", this._jid);
  15. }.bind(this), 100);
  16. return this;
  17. },
  18. then: function(callback) {
  19. this._cb_then = callback;
  20. return this;
  21. },
  22. catch: function(callback) {
  23. this._cb_catch = callback;
  24. return this;
  25. },
  26. show: function() {
  27. setTimeout(function() {
  28. adsdk_request_result("onClose", this._jid, true);
  29. }.bind(this), 100);
  30. return this;
  31. },
  32. onLoad: function(callback) {
  33. this._cb_onLoad = callback;
  34. return this;
  35. },
  36. onClose: function(callback) {
  37. this._cb_onClose = callback;
  38. return this;
  39. },
  40. onError: function(callback) {
  41. this._cb_onError = callback;
  42. return this;
  43. },
  44. offClose: function(callback) {
  45. return this;
  46. },
  47. offError: function(callback) {
  48. return this;
  49. },
  50. offLoad: function(callback) {
  51. return this;
  52. },
  53. destroy: function() {
  54. return this;
  55. },
  56. hide: function() {
  57. return this;
  58. },
  59. onResize: function() {
  60. return this;
  61. },
  62. style: function() {
  63. return this._style;
  64. }
  65. }
  66. var _style = function(objId, left, top, width, height) {
  67. this._objId = objId;
  68. this._left = left;
  69. this._top = top;
  70. this._width = width;
  71. this._height = height;
  72. }
  73. _style.prototype = {
  74. set left(val) {
  75. this._left = val;
  76. this._update(0, val);
  77. },
  78. get left() {
  79. return this._left;
  80. },
  81. set top(val) {
  82. this._top = val;
  83. this._update(1, val);
  84. },
  85. get top() {
  86. return this._top;
  87. },
  88. set width(val) {
  89. this._width = val;
  90. this._update(2, val);
  91. },
  92. get width() {
  93. return this._width;
  94. },
  95. set height(val) {
  96. this._height = val;
  97. this._update(3, val);
  98. },
  99. get height() {
  100. return this._height;
  101. },
  102. _update(t, v) {
  103. }
  104. }
  105. window.AdSdk = {
  106. adObjectCache: new Map(),
  107. createRewardedVideoAd: function(params) {
  108. return createAdObj("reward", params);
  109. },
  110. createInterstitialAd: function(params) {
  111. return createAdObj("Interstitial", params);
  112. },
  113. createBannerAd: function(params) {
  114. let obj = createAdObj("banner", params);
  115. obj.style = new _style(obj._objId, params.style.left, params.style.top, params.style.width, params.style.height);
  116. return obj;
  117. },
  118. createFullscreenVideoAd: function(params) {
  119. return createAdObj("Fullscreen", params);
  120. },
  121. }
  122. window.createAdObj = function(type, params) {
  123. let adUnitId = params.adUnitId;
  124. for (let [key, value] of AdSdk.adObjectCache) {
  125. if (value._adUnitId == adUnitId) {
  126. return value;
  127. }
  128. }
  129. let adObj = Object.create(AdObj);
  130. adObj._type = type;
  131. adObj._adUnitId = adUnitId;
  132. adObj._jid = adsdk_createAdObj(type, params);
  133. AdSdk.adObjectCache.set(adObj._jid, adObj);
  134. return adObj;
  135. }
  136. window.adsdk_createAdObj = function(type, params) {
  137. if (AdSdk._adObjIndex == undefined) {
  138. AdSdk._adObjIndex = 0;
  139. } else {
  140. AdSdk._adObjIndex++;
  141. }
  142. return AdSdk._adObjIndex;
  143. }
  144. window.adsdk_request_result = function(cmd, objId, params) {
  145. let adObj = AdSdk.adObjectCache.get(objId);
  146. if (!adObj) {
  147. return;
  148. }
  149. if (cmd === "onLoad") {
  150. if (adObj._cb_onLoad) {
  151. adObj._cb_onLoad();
  152. }
  153. if (adObj._cb_then) {
  154. adObj._cb_then();
  155. }
  156. } else if (cmd === "onClose") {
  157. if (adObj._cb_onClose) {
  158. if (params) {
  159. adObj._cb_onClose({ isEnded: true });
  160. } else {
  161. adObj._cb_onClose({ isEnded: false });
  162. }
  163. }
  164. } else if (cmd === "onError") {
  165. }
  166. }