popup.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. cc.Class({
  11. extends: require("Base"),
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. back: {
  29. default: null,
  30. type: cc.Sprite
  31. },
  32. detail: {
  33. default: null,
  34. type: cc.Sprite
  35. },
  36. popup_prefab: {
  37. default: null,
  38. type: cc.Prefab
  39. },
  40. popup_layout: {
  41. default: null,
  42. type: cc.Layout
  43. },
  44. tab_layout: {
  45. default: null,
  46. type: cc.Layout
  47. },
  48. nav_prefab: {
  49. default: null,
  50. type: cc.Prefab
  51. },
  52. video_prefab: {
  53. default: null,
  54. type: cc.Prefab
  55. }
  56. // videoplayer: cc.VideoPlayer
  57. },
  58. // LIFE-CYCLE CALLBACKS:
  59. onLoad () {
  60. // console.log(this.back.node)
  61. setViewTouch(
  62. this.back,
  63. null,
  64. function() {
  65. this.node.destroy();
  66. },
  67. null,
  68. this
  69. );
  70. // this.detailInit();
  71. setViewTouch(
  72. this.detail,
  73. null,
  74. function() {
  75. this.showDetail()
  76. },
  77. null,
  78. this
  79. );
  80. this.tabInit()
  81. // setViewTouch(
  82. // this.shu,
  83. // null,
  84. // function() {
  85. // var url = 'HelloWorld.png';
  86. // var _this = this;
  87. // cc.loader.loadRes(url, cc.SpriteFrame, function(err, spriteFrame) {
  88. // if (err) {
  89. // cc.error(err.message || err);
  90. // return;
  91. // }
  92. // _this.shu.spriteFrame = spriteFrame;
  93. // });
  94. // },
  95. // null,
  96. // this
  97. // );
  98. // this.videoplayer.node.on('ready-to-play', this.callback, this);
  99. },
  100. tabInit: function () {
  101. var tabContent = cc.instantiate(this.nav_prefab);
  102. this.tab_layout.node.addChild(tabContent);
  103. var video = cc.instantiate(this.video_prefab);
  104. for (let i = 0; i < 5; i++) {
  105. var courseware = cc.instantiate(this.popup_prefab);
  106. this.popup_layout.node.addChild(courseware);
  107. var length = this.popup_layout.node.childrenCount;
  108. // courseware.getComponent("课件icon").kejian = this;
  109. var temp = this;
  110. courseware.getComponent("tabItem").setClickFunction(function(item) {
  111. for(var index = 0; index < length; index++) {
  112. temp.popup_layout.node.children[index].getComponent("tabItem").shu.enabled = true
  113. tabContent.getComponent("nav")['nav'+ (index+1)].enabled = false
  114. }
  115. item.target.getComponent("tabItem").shu.enabled = false
  116. tabContent.getComponent("nav")['nav'+ (i+1)].enabled = true
  117. if(i == 1) {
  118. tabContent.getComponent("nav").node.addChild(video)
  119. }else if(tabContent.getComponent("nav").node.childrenCount == 7) {
  120. tabContent.getComponent("nav").node.removeChild(video)
  121. }
  122. });
  123. }
  124. },
  125. // detailInit () {
  126. // console.log(1111, cc.instantiate(this.detail))
  127. // },
  128. // callback: function (event) {
  129. // console.log(event)
  130. // //这里的 event 是一个 EventCustom 对象,你可以通过 event.detail 获取 VideoPlayer 组件
  131. // var videoplayer = event.detail;
  132. // //do whatever you want with videoplayer
  133. // //另外,注意这种方式注册的事件,也无法传递 customEventData
  134. // },
  135. start () {
  136. },
  137. showDetail: function() {
  138. this.curriculum_window.showDetail();
  139. }
  140. // update (dt) {},
  141. });