CustomerWebview.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var CustomerWebView = cc.Class({
  2. extends: cc.WebView,
  3. onEnable: function(){
  4. let impl = this._impl;
  5. if (!CC_EDITOR) {
  6. impl.setVisible(true);
  7. } else {
  8. this.loadURL(this._url);
  9. }
  10. },
  11. /**
  12. * 加载URL,完成加载后显示
  13. * @param url
  14. * @param loaded 加载完成回调
  15. * @param loading 加载中回调
  16. * @param loadError 加载错误回调
  17. */
  18. loadURL: function(url, loaded, loading, loadError) {
  19. let impl = this._impl;
  20. this._url = url;
  21. impl.createDomElementIfNeeded(this.node.width, this.node.height);
  22. if (!CC_EDITOR) {
  23. var onLoaded = function(...args) {
  24. (loaded) ? loaded.call(this, ...args) : this._onWebViewLoaded.call(this, ...args);
  25. impl.setVisible(true);
  26. }
  27. impl.setEventListener(CustomerWebView.EventType.LOADED, onLoaded.bind(this));
  28. impl.setEventListener(CustomerWebView.EventType.LOADING, (loading) ? loading.bind(this) : this._onWebViewLoading.bind(this));
  29. impl.setEventListener(CustomerWebView.EventType.ERROR, (loadError) ? loadError.bind(this) : this._onWebViewLoadError.bind(this));
  30. } else {
  31. impl.setVisible(true);
  32. }
  33. impl.loadURL(url);
  34. }
  35. });
  36. module.exports = cc.CustomerWebView = CustomerWebView;