gcmsAudio.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /**
  2. * [ONEMAP.M.gcmsAudio]
  3. * @return {[object]}
  4. */
  5. define([
  6. 'html!templates/gcms/gcmsAudio',
  7. 'vendorDir/handlebars/handlebars',
  8. 'css!styles/gcms/gcmsAudio'],
  9. function(tpcLayout,Handlebars){
  10. //参数
  11. var modValue= {
  12. options:{}
  13. };
  14. /**
  15. * 模块初始化
  16. * @return {[type]} [description]
  17. */
  18. function init(options){
  19. modValue.options = {};
  20. for(var op in options){
  21. modValue.options[op] = options[op];
  22. }
  23. //获取内容数据
  24. getDetailData({callback:function(){
  25. showAudio();
  26. }});
  27. //订阅推送
  28. subscribe();
  29. }
  30. function getDetailData(options){
  31. ONEMAP.V.loading.load();
  32. $.ajax({
  33. url: onemapUrlConfig.gcmsServiceUrl+'/show/'+modValue.options['column_name']+'/'+modValue.options['article_id'],
  34. type:"GET",
  35. dataType: 'json'
  36. })
  37. .done(function(data) {
  38. ONEMAP.V.loading.loaded();
  39. if(data.code == 4){
  40. ONEMAP.C.noPermission('getDetailData');
  41. return false;
  42. }
  43. if(data.code == 3){
  44. ONEMAP.C.logout('getDetailData');
  45. }
  46. if(JSON.parse(data['data']['record'][modValue.options['field_name']]).length == 0){
  47. ONEMAP.C.publisher.publish({ type: 'warning', message: '没有音频数据' }, 'noteBar::add');
  48. remove();
  49. }else {
  50. ONEMAP.D.gcmsCurArticleData = data['data'];
  51. options.callback();
  52. }
  53. })
  54. .fail(function() {
  55. ONEMAP.V.loading.loaded();
  56. });
  57. }
  58. /**
  59. * 事件绑定
  60. * @return {[type]} [description]
  61. */
  62. function bindEvent(){
  63. $('#gcmsAudioModal .modal-header .close').bind('click', function() {
  64. remove();
  65. });
  66. $('#gcmsAudioModal .modal-header').dragmove($('#gcmsAudioModal'));
  67. var $box2 = $('#gcmsAudioModal').on('mousedown', '#coorForGcmsAudioModal', function(e) {
  68. var posix = {
  69. 'w': $box2.width(),
  70. 'h': $box2.height(),
  71. 'x': e.pageX,
  72. 'y': e.pageY
  73. };
  74. $.extend(document, {'move': true, 'call_down': function(e) {
  75. $box2.css({
  76. 'width': Math.max(30, e.pageX - posix.x + posix.w),
  77. 'height': Math.max(30, e.pageY - posix.y + posix.h)
  78. });
  79. var bodyHeight = Math.max(30, e.pageY - posix.y + posix.h )-145;
  80. $("#gcmsAudioModal .modal-body").css({height:bodyHeight});
  81. }});
  82. $.extend(document, {'move': true, 'call_up': function(e) {
  83. $('#gcmsAudioList .selected').click();
  84. }});
  85. return false;
  86. });
  87. }
  88. function showAudio(){
  89. $('body').append(tpcLayout);
  90. bindEvent();
  91. var audioFileUrl = onemapUrlConfig.gcmsServiceUrl+'/file'+JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']])[0]+'?jwt='+ONEMAP.D.user.ticket;
  92. // if(Modernizr.video.h264.length>0){
  93. // var audioPlayerHtml = '<audio src="'+audioFileUrl+'" width="400" height="80" autoplay controls></audio>';
  94. // }else {
  95. var flashPlayerInfo = flashChecker();
  96. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  97. var audioPlayerHtml = _setFlashPlayer("audioPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp3;url:" + audioFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  98. } else {
  99. if (document.all) {
  100. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  101. } else {
  102. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  103. }
  104. var audioPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  105. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  106. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  107. '</div>';
  108. }
  109. //}
  110. $('#gcmsAudioPlayer').empty().append(audioPlayerHtml);
  111. $('#gcmsAudioModal').show();
  112. //显示列表
  113. $('#gcmsAudioList').empty();
  114. $(JSON.parse(ONEMAP.D.gcmsCurArticleData['record'][modValue.options['field_name']])).each(function(index, el) {
  115. $('<li><button vUrl="'+onemapUrlConfig.gcmsServiceUrl+'/file'+el+'" class="btn">音频['+(index+1)+']</button></li>').appendTo($('#gcmsAudioList'));
  116. });
  117. $('#gcmsAudioList .btn:eq(0)').addClass('selected');
  118. $('#gcmsAudioList .btn').bind('click',function(){
  119. var audioFileUrl = $(this).attr('vUrl');
  120. // if(Modernizr.video.h264.length>0){
  121. // var audioPlayerHtml = '<audio src="'+audioFileUrl+'" width="400" height="80" autoplay controls></audio>';
  122. // }else {
  123. var flashPlayerInfo = flashChecker();
  124. if (flashPlayerInfo && flashPlayerInfo.v > 10) {
  125. var audioPlayerHtml = _setFlashPlayer("audioPlayer", "scripts/vendor/player/snplayer.swf?file=type:mp3;url:" + audioFileUrl + "", "100%", "100%", "SkinURL=skin/default.zip", true);
  126. } else {
  127. if (document.all) {
  128. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_winax.exe';
  129. } else {
  130. var flashPlayerLink = onemapUrlConfig.siteUrl+'/soft/flashplayer_win.exe';
  131. }
  132. var audioPlayerHtml = '<div class="install-flash-player" style="text-align:center">' +
  133. '<p><strong>请安装Adobe flash player 11以上版本的播放器。</strong></p>' +
  134. '<a href="' + flashPlayerLink + '"><img src="images/layout/get_flash.png"/><br/><span>Adobe Flash Player 11</span></a>' +
  135. '</div>';
  136. }
  137. //}
  138. $('#gcmsAudioPlayer').empty().append(audioPlayerHtml);
  139. $('#gcmsAudioModal').show();
  140. $('#gcmsAudioModal .selected').removeClass('selected');
  141. $(this).addClass('selected');
  142. });
  143. }
  144. function flashChecker(){
  145. var hasFlash = 0;
  146. var flashVersion =0;
  147. try{
  148. if(document.all){
  149. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  150. if(swf){
  151. hasFlash = 1;
  152. VSwf = swf.GetVariable('$version');
  153. flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]);
  154. }
  155. }else {
  156. if(navigator.plugins && navigator.plugins.length > 0){
  157. var swf = navigator.plugins["Shockwave Flash"];
  158. }
  159. if(swf){
  160. hasFlash = 1;
  161. var words = swf.description.split(" ");
  162. for(var i=0;i<words.length; i++){
  163. if(isNaN(parseInt(words[i]))) continue;
  164. flashVersion = parseInt(words[i]);
  165. }
  166. }
  167. }
  168. }catch (e) {
  169. }
  170. return {
  171. f:hasFlash,
  172. v:flashVersion
  173. };
  174. }
  175. /**
  176. * 添加Flash Player
  177. * @type {Function}
  178. * @param id {String} 容器id
  179. * @param url {String} url
  180. * @param width {Number} 宽度
  181. * @param height {Number} 高度
  182. * @param vars {String} 参数
  183. * @param transparent {String} 是否透明
  184. * @returns {string} flash player code
  185. * @private
  186. */
  187. function _setFlashPlayer(id, url, width, height, vars, transparent){
  188. $('#DIVSNplayerWMPaudioPlayer').remove();
  189. var wmode = transparent ? "transparent" : "opaque";
  190. var html = '';
  191. html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
  192. html += 'width="'+width+'" ';
  193. html += 'height="'+height+'" ';
  194. html += 'id="'+id+'"';
  195. html += '>';
  196. html += '<param name="movie" value="'+url+'" />';
  197. html += '<param name="allowFullScreen" value="true" />';
  198. html += '<param name="allowScriptAccess" value="always" />';
  199. html += '<param name="quality" value="high" />';
  200. html += '<param name="wmode" value="'+wmode+'" />';
  201. html += '<param name="flashvars" value="'+vars+'" />';
  202. html += '<embed type="application/x-shockwave-flash" ';
  203. html += 'width="'+width+'" ';
  204. html += 'height="'+height+'" ';
  205. html += 'name="'+id+'" ';
  206. html += 'src="'+url+'" ';
  207. html += 'allowfullscreen="true" ';
  208. html += 'allowscriptaccess="always" ';
  209. html += 'quality="high" ';
  210. html += 'wmode="'+wmode+'" ';
  211. html += 'flashvars="'+vars+'"'
  212. html += '></embed>';
  213. html += '</object>';
  214. return html;
  215. };
  216. /**
  217. * 界面布局重置
  218. * @type {Function}
  219. */
  220. function layoutResize(){
  221. }
  222. /**
  223. * 注册监听
  224. * @type {Function}
  225. */
  226. function subscribe(){
  227. ONEMAP.C.publisher.subscribe(remove,'gcmsArticleShowRemove');
  228. ONEMAP.C.publisher.subscribe(remove, 'cleanMap');
  229. }
  230. /**
  231. * 取消监听
  232. * @type {Function}
  233. */
  234. function unSubscribe() {}
  235. /**
  236. * 模块移除
  237. * @return {[type]} [description]
  238. */
  239. function remove(){
  240. $('#gcmsAudioModal').remove();
  241. $('#DIVSNplayerWMPaudioPlayer').remove();
  242. unSubscribe();
  243. }
  244. return ONEMAP.M.gcmsAudio = {
  245. init:init,
  246. remove:remove
  247. }
  248. });