gcmsVideo.js 9.8 KB

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