topic-page-2-min.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. KISSY.add('op_dever/topic-page-2',function (S, Node, DOM, Base, Event, IO) {
  2. var $ = Node.all;
  3. var TopicPage = function (target, config) {
  4. var self = this;
  5. if(!config) config = {};
  6. if(target) S.mix(config, {target: target});
  7. TopicPage.superclass.constructor.call(self, config);
  8. return self;
  9. }
  10. S.extend(TopicPage, Base, {
  11. /*设置页面数据*/
  12. setData: function (data) {
  13. var self = this;
  14. self.data = data;
  15. S.log(data);
  16. return self;
  17. },
  18. getData: function () {
  19. var self = this;
  20. return self.data;
  21. },
  22. /*代理页面渲染*/
  23. render: function () {
  24. var self = this;
  25. self._load(self._render);
  26. return self;
  27. },
  28. /*页面图片加载完成后回调*/
  29. _load: function (callback) {
  30. var self = this;
  31. var waitLoadingImgs = [];
  32. if (!S.isUndefined(self.data.bgimage_url)) {
  33. waitLoadingImgs.push(self.data.bgimage_url);
  34. }
  35. for ( var key in self.data.layers) {
  36. if (!S.isUndefined(self.data.layers[key].url))
  37. waitLoadingImgs.push(self.data.layers[key].url);
  38. }
  39. var hasLoadingTimes = 0;
  40. for (var i = 0; i < waitLoadingImgs.length; i++) {
  41. var oi = new Image();
  42. oi.src = waitLoadingImgs[i];
  43. oi.onload = function () {
  44. ++hasLoadingTimes;
  45. };
  46. }
  47. var ID = setInterval(function () {
  48. if (hasLoadingTimes == waitLoadingImgs.length) {
  49. clearInterval(ID);
  50. S.log('image loading done');
  51. //self._sleep(3);
  52. callback(self);
  53. }
  54. }, 10);
  55. return self;
  56. },
  57. _sleep: function (s) {
  58. var start = new Date().getTime();
  59. while(true) {
  60. if (new Date().getTime()-start > s*1000)
  61. break;
  62. }
  63. },
  64. _amin: function (node, style) {
  65. setTimeout(function () {
  66. node.css(style);
  67. }, 100);
  68. },
  69. /*页面渲染*/
  70. _render: function (self) {
  71. var data = self.data,
  72. target = self.get('target');
  73. target.html('');
  74. // if (!S.isUndefined(data.background_color)) {
  75. // target.css({'background-color': data.background_color});
  76. // }
  77. if (!S.isUndefined(data.bgimage_url) && (S.isUndefined(data.bgimage_isShow) || data.bgimage_isShow == true) ) {
  78. var $topic_bg_image = $('<div class="ks-topic-bg-image"></div>').appendTo(target);
  79. $topic_bg_image.css({'background-image': 'url('+data.bgimage_url+')'});
  80. }
  81. for ( var key in self.data.layers) {
  82. var layer_data = self.data.layers[key];
  83. if ((!S.isUndefined(layer_data.url) || !S.isUndefined(layer_data.video_url)) && (S.isUndefined(layer_data.isShow) || layer_data.isShow == true)) {
  84. if (!S.isUndefined(layer_data.url)) {
  85. var image_width = Math.round(layer_data.width/2),
  86. image_height = Math.round(layer_data.height/2);
  87. }
  88. if (!S.isUndefined(layer_data.video_url)) {
  89. var image_width = Math.round(layer_data.video_width),
  90. image_height = Math.round(layer_data.video_height);
  91. }
  92. if (S.isUndefined(layer_data.position)) { //布局:默认左上
  93. layer_data.position = 'leftup';
  94. }
  95. if (S.isUndefined(layer_data.action)) { //动作:默认静止
  96. layer_data.action = 'rest';
  97. }
  98. var $begin_style = {}, $end_style = {'opacity':'1'}; //用开始样式和结束样式来产生动画效果
  99. switch (layer_data.position) {
  100. case 'center':
  101. $begin_style = {
  102. 'left':'50%',
  103. 'top':'50%',
  104. 'margin-left':'-'+image_width/2+'px',
  105. 'margin-top':'-'+image_height/2+'px',
  106. 'opacity': '0'
  107. };
  108. if (layer_data.action == 'left') {
  109. $begin_style.left = '70%';
  110. $end_style.left = '50%';
  111. } else if (layer_data.action == 'up') {
  112. $begin_style.top = '70%';
  113. $end_style.top = '50%';
  114. }
  115. break;
  116. case 'up':
  117. $begin_style = {
  118. 'left':'50%',
  119. 'top':'0%',
  120. 'margin-left':'-'+image_width/2+'px',
  121. 'opacity': '0'
  122. };
  123. if (layer_data.action == 'left') {
  124. $begin_style.left = '70%';
  125. $end_style.left = '50%';
  126. } else if (layer_data.action == 'up') {
  127. $begin_style.top = '20%';
  128. $end_style.top = '0%';
  129. }
  130. break;
  131. case 'down':
  132. $begin_style = {
  133. 'left':'50%',
  134. 'bottom':'6%',
  135. 'margin-left':'-'+image_width/2+'px',
  136. 'opacity': '0'
  137. };
  138. if (layer_data.action == 'left') {
  139. $begin_style.left = '70%';
  140. $end_style.left = '50%';
  141. } else if (layer_data.action == 'up') {
  142. $begin_style.bottom = '-14%';
  143. $end_style.bottom = '6%';
  144. }
  145. break;
  146. case 'leftup':
  147. $begin_style = {
  148. 'left':'0%',
  149. 'top':'0%',
  150. 'opacity': '0'
  151. };
  152. if (layer_data.action == 'left') {
  153. $begin_style.left = '20%';
  154. $end_style.left = '0%';
  155. } else if (layer_data.action == 'up') {
  156. $begin_style.top = '20%';
  157. $end_style.top = '0%';
  158. }
  159. break;
  160. case 'leftdown':
  161. $begin_style = {
  162. 'left':'0%',
  163. 'bottom':'0%',
  164. 'opacity': '0'
  165. };
  166. if (layer_data.action == 'left') {
  167. $begin_style.left = '20%';
  168. $end_style.left = '0%';
  169. } else if (layer_data.action == 'up') {
  170. $begin_style.bottom = '-20%';
  171. $end_style.bottom = '0%';
  172. }
  173. break;
  174. case 'rightup':
  175. $begin_style = {
  176. 'right':'0%',
  177. 'top':'0%',
  178. 'opacity': '0'
  179. };
  180. if (layer_data.action == 'left') {
  181. $begin_style.right = '-20%';
  182. $end_style.right = '0%';
  183. } else if (layer_data.action == 'up') {
  184. $begin_style.top = '20%';
  185. $end_style.top = '0%';
  186. }
  187. break;
  188. case 'rightdown':
  189. $begin_style = {
  190. 'right':'0%',
  191. 'bottom':'0%',
  192. 'opacity': '0'
  193. };
  194. if (layer_data.action == 'left') {
  195. $begin_style.right = '-20%';
  196. $end_style.right = '0%';
  197. } else if (layer_data.action == 'up') {
  198. $begin_style.bottom = '-20%';
  199. $end_style.bottom = '0%';
  200. }
  201. break;
  202. default:
  203. alert('未知操作');
  204. }
  205. $begin_style.width = image_width; //图层图片尺寸压缩一倍
  206. if (!S.isUndefined(layer_data.url)) {
  207. var layer_image = $('<img class="layer_anim" src="'+layer_data.url+'" />');
  208. }
  209. if (!S.isUndefined(layer_data.url) && !S.isUndefined(layer_data.link) && layer_data.link) {
  210. var layer_image = $('<a class="layer_anim" href="'+layer_data.link+'" target="_blank"><img src="'+layer_data.url+'" style="width:100%" /></a>');
  211. }
  212. if (!S.isUndefined(layer_data.video_url)) {
  213. //var layer_image = $('<embed class="layer_anim" src="'+layer_data.video_url+'" allowFullScreen="true" quality="high" width="'+layer_data.video_width+'" height="'+layer_data.video_height+'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash"></embed>');
  214. var layer_image = $('<div class="layer_anim" style="width:'+layer_data.video_width+'px;height:'+layer_data.video_height+'px;background-color:#ccc;color:#fff;font-size:20px;text-align:center;line-height:'+layer_data.video_height+'px;" >视频</div>');
  215. }
  216. layer_image.css($begin_style);
  217. target.append(layer_image);
  218. self._amin(layer_image, $end_style);
  219. }
  220. }
  221. S.log('render done!');
  222. return self;
  223. }
  224. }, {
  225. ATTRS: {
  226. target: {
  227. value: "",
  228. getter: function (v) {
  229. return $(v);
  230. }
  231. }
  232. }
  233. });
  234. return TopicPage;
  235. }, {requires:['node', 'dom', 'base', 'event', 'io', './topic-page-2.css']});