fileUploader.min.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. (function (root, factory) {
  2. if (typeof define === 'function' && define.amd) {
  3. // AMD
  4. define(['underscore', 'webuploader', 'jquery.jplayer'], function (_, WebUploader) {
  5. return (root['fileUploader'] = factory(_, WebUploader));
  6. });
  7. } else if (typeof module === 'object' && typeof module.exports === 'object') {
  8. // commonJS
  9. module.exports = factory(require("underscore"),require("webuploader"),require("jquery.jplayer"),require("filestyle"));
  10. } else {
  11. // 普通引入:构造函数使用3个全局变量,但是还需要依赖 'jquery.jplayer', 'bootstrap', 'filestyle'
  12. root['fileUploader'] = factory(jQuery, underscore, WebUploader);
  13. }
  14. })(window, function(_, WebUploader){
  15. var uploader = {
  16. 'defaultoptions' : {
  17. direct : false,
  18. global : false,
  19. dest_dir : '',
  20. callback : null,
  21. type : 'image',
  22. mode : '',
  23. multiple : false,
  24. allowUploadVideo : true,
  25. fileSizeLimit: false,
  26. uploader : {
  27. //fileNumLimit: 30,
  28. //fileSizeLimit: 4 * 1024 * 1024,
  29. //fileSingleSizeLimit: 30* 4 * 1024 * 1024
  30. }
  31. },
  32. 'uploader' : {},
  33. 'upload_urls' : null,
  34. 'image_urls' : null,
  35. 'fetch_urls' : null,
  36. 'delete_urls' : null,
  37. 'video_urls' : null,
  38. 'upload_url' : function(upload_urls) {
  39. this.upload_urls = upload_urls
  40. },
  41. 'image_url' : function(image_urls) {
  42. this.image_urls = image_urls
  43. },
  44. 'fetch_url' : function(fetch_urls) {
  45. this.fetch_urls = fetch_urls
  46. },
  47. 'delet_url' : function(delete_urls) {
  48. this.delete_urls = delete_urls
  49. },
  50. 'video_url' : function(video_urls) {
  51. this.video_urls = video_urls
  52. },
  53. 'show' : function(callback, options){
  54. return this.init(callback, options);
  55. },
  56. 'init' : function(callback, options) {
  57. var $this = this;
  58. let o = this.fetch_urls;
  59. $this.options = $.extend({}, $this.defaultoptions, options);
  60. $this.options.callback = callback;
  61. // 微信
  62. if(this.options.isWechat){
  63. if(options.account_error) {
  64. util.message('公众号号没有上传素材的权限', '', 'info');
  65. return false;
  66. }
  67. } else {
  68. if(this.options.global){
  69. this.options.global = 'global';
  70. } else {
  71. this.options.global = '';
  72. }
  73. document.cookie = "__fileupload_type="+ escape (this.options.type);
  74. document.cookie = "__fileupload_dest_dir="+ escape (this.options.dest_dir);
  75. document.cookie = "__fileupload_global="+ escape (this.options.global);
  76. }
  77. $('#modal-webuploader').remove();
  78. if ($('#modal-webuploader').length == 0) {
  79. $(document.body).append($this.buildHtml().mainDialog);
  80. }
  81. $this.modalobj = $('#modal-webuploader');
  82. $this.modalobj.modal('show');
  83. $this.modalobj.on('shown.bs.modal', function(){
  84. if (!$(this).data('init')) {
  85. switch($this.options.type){
  86. case 'image':
  87. case 'thumb':
  88. // 普通
  89. if(!$this.options.isWechat){
  90. $this.initRemote(o);
  91. }
  92. $this.initLocal();
  93. break;
  94. case 'audio':
  95. $this.initLocalAudio();
  96. break;
  97. case 'voice':
  98. $this.initLocalVoice();
  99. break;
  100. case 'video':
  101. if(!$this.options.isWechat){
  102. $this.initVideoRemote();
  103. }
  104. // 新增图文时,不显示 '浏览视频'
  105. if($this.options.allowUploadVideo){
  106. $this.initLocalVideo();
  107. }
  108. break;
  109. }
  110. // 新增图文时,不显示 '上传视频'
  111. if($this.options.allowUploadVideo){
  112. $this['init' + $this.options.type.substring(0,1).toUpperCase() + $this.options.type.substring(1) + 'Uploader']();
  113. }
  114. }
  115. });
  116. return $this.modalobj;
  117. },
  118. 'initUploader' : function(type) {
  119. var $this = this, typeText, accept, fileNumLimit, fileSingleSizeLimit, fileSizeLimit, compress;
  120. switch(type) {
  121. case 'image':
  122. typeText = '图片';
  123. typeUnit = '张';
  124. accept = {
  125. title: 'Images',
  126. extensions: 'gif,jpg,jpeg,bmp,png,ico',
  127. mimeTypes: 'image/gif,image/jpg,image/jpeg,image/bmp,image/png,image/ico'
  128. };
  129. fileNumLimit = 30;
  130. fileSingleSizeLimit = 5 * 1024 * 1024;
  131. fileSizeLimit = fileNumLimit * fileSingleSizeLimit;
  132. compress = $this.options.isWechat ? {
  133. quality: 80,
  134. preserveHeaders: true,
  135. noCompressIfLarger: true,
  136. compressSize: 1 * 1024 * 1024
  137. } : false;
  138. break;
  139. case 'audio':
  140. case 'voice':
  141. typeText = '音频';
  142. typeUnit = '个';
  143. accept = {
  144. title: 'Audios',
  145. extensions: 'mp3,wma,wav,amr',
  146. mimeTypes: 'audio/*'
  147. };
  148. fileNumLimit = 30;
  149. fileSingleSizeLimit = 6 * 1024 * 1024;
  150. fileSizeLimit = fileNumLimit * fileSingleSizeLimit;
  151. compress = false;
  152. if ($this.options.isWechat) {
  153. fileNumLimit = 5;
  154. if($this.options.mode == 'temp'){
  155. accept.extensions = 'mp3';
  156. fileSingleSizeLimit = 2 * 1024 * 1024;
  157. fileSizeLimit = 5 * 2 * 1024 * 1024;
  158. }else{
  159. fileSingleSizeLimit = 5 * 1024 * 1024;
  160. fileSizeLimit = 5 * 5 * 1024 * 1024;
  161. }
  162. }
  163. break;
  164. case 'video':
  165. typeText = '视频';
  166. typeUnit = '个';
  167. accept = {
  168. title: 'Video',
  169. extensions: 'rm,rmvb,wmv,avi,mpg,mpeg,mp4',
  170. mimeTypes: 'video/*' // 这里不确定
  171. };
  172. fileNumLimit = 30;
  173. fileSingleSizeLimit = 20 * 1024 * 1024;
  174. fileSizeLimit = fileNumLimit * fileSingleSizeLimit;
  175. compress = false;
  176. if ($this.options.isWechat) {
  177. fileNumLimit = 5;
  178. if($this.options.mode == 'temp'){
  179. accept.extensions = 'mp4';
  180. fileSingleSizeLimit = 10 * 1024 * 1024;
  181. fileSizeLimit = 5 * 10 * 1024 * 1024;
  182. }else{
  183. fileSingleSizeLimit = 20 * 1024 * 1024;
  184. fileSizeLimit = 5 * 20 * 1024 * 1024;
  185. }
  186. }
  187. break;
  188. }
  189. if($this.options.isWechat){
  190. $this.options.flag = 0;
  191. $this.modalobj.find('#li_upload_perm a').html('上传永久'+typeText);
  192. $this.modalobj.find('#li_upload_temp a').html('上传临时'+typeText+'(保留3天)');
  193. }else{
  194. $this.modalobj.find('#li_upload a').html('上传'+typeText);
  195. }
  196. $this.modalobj.find('.modal-body').append(this.buildHtml().uploaderDialog);
  197. var $wrap = $('#uploader'),
  198. // 图片容器
  199. $queue = $( '<ul class="filelist"><li class="fileinput-button js-add-image" id="filePicker2" style="display:none;"> <a href="javascript:;" class="fileinput-button-icon">+</a></li></ul>' )
  200. .appendTo( $wrap.find( '.queueList' ) ),
  201. // 状态栏,包括进度和控制按钮
  202. $statusBar = $wrap.find( '.statusBar' ),
  203. // 文件总体选择信息。
  204. $info = $statusBar.find( '.info' ),
  205. // 上传按钮
  206. $upload = $wrap.find( '.uploadBtn' ),
  207. // 没选择文件之前的内容。
  208. $placeHolder = $wrap.find( '.placeholder' ),
  209. $progress = $statusBar.find( '.progress' ).hide(),
  210. $confirmBtn = $wrap.find('.btn-primary');
  211. // 添加的文件数量
  212. fileCount = 0,
  213. // 添加的文件总大小
  214. fileSize = 0,
  215. // 优化retina, 在retina下这个值是2
  216. ratio = window.devicePixelRatio || 1,
  217. // 缩略图大小
  218. thumbnailWidth = 110 * ratio,
  219. thumbnailHeight = 110 * ratio,
  220. // 可能有pedding, ready, uploading, confirm, done.
  221. state = 'pedding',
  222. // 所有文件的进度信息,key为file id
  223. percentages = {},
  224. supportTransition = (function(){
  225. var s = document.createElement('p').style,
  226. r = 'transition' in s ||
  227. 'WebkitTransition' in s ||
  228. 'MozTransition' in s ||
  229. 'msTransition' in s ||
  230. 'OTransition' in s;
  231. s = null;
  232. return r;
  233. })(),uploader;
  234. var options = {
  235. pick: {
  236. id: '#filePicker',
  237. label: '点击选择'+typeText,
  238. multiple : true
  239. },
  240. dnd: '#dndArea',
  241. paste: '#uploader',
  242. // swf文件路径
  243. swf: './resource/componets/webuploader/Uploader.swf',
  244. // 文件接收服务端。
  245. server: $this.options.isWechat ? './index.php?c=utility&a=wechat_file&do=upload' : this.upload_urls+type,
  246. compress: compress,
  247. accept: accept,
  248. fileNumLimit: fileNumLimit,
  249. fileSizeLimit: fileSizeLimit,
  250. fileSingleSizeLimit: fileSingleSizeLimit,
  251. }
  252. // warning: 1.options是 'webUploader的上传配置';2.$this.options是整个fileUploader的配置。注意区分开2者。注意区分开2者。注意区分开2者。注意区分开2者
  253. options = $.extend({}, options, $this.options.uploader);
  254. options.pick.multiple = $this.options.multiple;
  255. // 2个配置在下方需进行判别
  256. options.isWechat = $this.options.isWechat;
  257. options.type = $this.options.type
  258. if(type == 'audio' || type == 'voice'){
  259. if($this.options.isWechat){
  260. $('#dndArea p').html('临时语音只支持amr/mp3格式,大小不超过为2M,长度不超过60秒<br>永久语音只支持mp3/wma/wav/amr格式,大小不超过为5M,长度不超过60秒');
  261. }else{
  262. $('#dndArea p').html('最大支持 '+(WebUploader.formatSize(options.fileSingleSizeLimit ))+' MB 以内的语音 ('+(options.accept.extensions)+' 格式)');
  263. }
  264. }else if(type == 'video'){
  265. if($this.options.isWechat){
  266. $('#dndArea p').html('临时视频只支持mp4格式,大小不超过为10M<br>永久视频只支持rm/rmvb/wmv/avi/mpg/mpeg/mp4格式,大小不超过为20M');
  267. }else{
  268. $('#dndArea p').html('最大支持 '+(WebUploader.formatSize(options.fileSingleSizeLimit ))+' MB 以内的视频 ('+(options.accept.extensions)+' 格式)');
  269. }
  270. }
  271. if ($this.options.fileSizeLimit) {
  272. options.fileSizeLimit = $this.options.fileSizeLimit;
  273. }
  274. // 实例化
  275. uploader = WebUploader.create(options);
  276. uploader.uploadedFiles = [];
  277. // 添加“添加文件”的按钮,
  278. uploader.addButton({
  279. id: '#filePicker2',
  280. label: '+',
  281. multiple : $this.options.multiple
  282. });
  283. // 成功上传
  284. accept = 0;
  285. uploader.resetUploader = function(){
  286. fileCount = 0;
  287. fileSize = 0;
  288. accept = 0;
  289. uploader.uploadedFiles = [];
  290. $.each(uploader.getFiles(), function(index, file){
  291. removeFile( file );
  292. });
  293. if($this.options.isWechat){
  294. if($this.options.video){
  295. $("#upload :text[name='title']").val('');
  296. $("#upload :text[name='introduction']").val('');
  297. }
  298. updateTotalProgress();
  299. uploader.reset();
  300. uploader.refresh();
  301. $('#dndArea').removeClass('element-invisible');
  302. $('#uploader').find('.filelist').empty();
  303. $('#filePicker').find('.webuploader-pick').next().css({'left':'190px'});
  304. var bar = $('#uploader').find('.statusBar');
  305. bar.find('.info').empty();
  306. bar.find('.accept').empty();
  307. bar.hide();
  308. }else{
  309. uploader.refresh();
  310. uploader.reset();
  311. $upload.removeClass( 'disabled' );
  312. setState( 'pedding' );
  313. }
  314. }
  315. // 当有文件添加进来时执行,负责view的创建
  316. function addFile( file ) {
  317. var $li = $( '<li id="' + file.id + '">' +
  318. '<p class="title"'+(type=='audio' || type=='voice' ? 'style="top:40px;"' : '')+'>' + file.name + '</p>' +
  319. '<p class="imgWrap"'+(type=='audio' || type=='voice' ? 'style="top:30px;"' : '')+'></p>'+
  320. //'<p class="progress"><span></span></p>' +
  321. '</li>' ),
  322. $btns = $('<div class="file-panel">' +
  323. '<span class="cancel">删除</span></div>').appendTo( $li ),
  324. $prgress = $li.find('p.progress span'),
  325. $wrap = $li.find( 'p.imgWrap' ),
  326. $info = $('<p class="error"></p>'),
  327. showError = function( code ) {
  328. switch( code ) {
  329. case 'exceed_size':
  330. text = '文件大小超出';
  331. break;
  332. case 'interrupt':
  333. text = '上传暂停';
  334. break;
  335. default:
  336. text = '上传失败,请重试';
  337. break;
  338. }
  339. $info.text( text ).appendTo( $li );
  340. };
  341. if ( file.getStatus() === 'invalid' ) {
  342. showError( file.statusText );
  343. } else {
  344. // @todo lazyload
  345. if(type == 'image'){
  346. $wrap.text( '预览中' );
  347. uploader.makeThumb( file, function( error, src ) {
  348. if ( error ) {
  349. $wrap.text( '不能预览' );
  350. return;
  351. }
  352. var img = $('<img src="'+src+'">');
  353. $wrap.empty().append( img );
  354. }, thumbnailWidth, thumbnailHeight );
  355. }else{
  356. $wrap.text(WebUploader.formatSize( file.size ) + ' kb');
  357. }
  358. percentages[ file.id ] = [ file.size, 0 ];
  359. file.rotation = 0;
  360. }
  361. file.on('statuschange', function( cur, prev ) {
  362. if ( prev === 'progress' ) {
  363. $prgress.hide().width(0);
  364. } else if ( prev === 'queued' ) {
  365. $li.off( 'mouseenter mouseleave' );
  366. $btns.remove();
  367. }
  368. // 成功
  369. if ( cur === 'error' || cur === 'invalid' ) {
  370. showError( file.statusText );
  371. percentages[ file.id ][ 1 ] = 1;
  372. } else if ( cur === 'interrupt' ) {
  373. showError( 'interrupt' );
  374. } else if ( cur === 'queued' ) {
  375. percentages[ file.id ][ 1 ] = 0;
  376. } else if ( cur === 'progress' ) {
  377. $info.remove();
  378. if(type == 'image'){
  379. $prgress.css('display', 'block');
  380. }
  381. } else if ( cur === 'complete' ) {
  382. //$li.append( '<span class="success"></span>' );
  383. }
  384. $li.removeClass( 'state-' + prev ).addClass( 'state-' + cur );
  385. });
  386. $li.on( 'mouseenter', function() {
  387. $btns.stop().animate({height: 30});
  388. });
  389. $li.on( 'mouseleave', function() {
  390. $btns.stop().animate({height: 0});
  391. });
  392. $btns.on( 'click', 'span', function() {
  393. var index = $(this).index(),
  394. deg;
  395. switch ( index ) {
  396. case 0:
  397. uploader.removeFile( file );
  398. return;
  399. case 1:
  400. file.rotation += 90;
  401. break;
  402. case 2:
  403. file.rotation -= 90;
  404. break;
  405. }
  406. if ( supportTransition ) {
  407. deg = 'rotate(' + file.rotation + 'deg)';
  408. $wrap.css({
  409. '-webkit-transform': deg,
  410. '-mos-transform': deg,
  411. '-o-transform': deg,
  412. 'transform': deg
  413. });
  414. } else {
  415. $wrap.css( 'filter', 'progid:DXImageTransform.Microsoft.BasicImage(rotation='+ (~~((file.rotation/90)%4 + 4)%4) +')');
  416. }
  417. });
  418. if ($this.options.multiple) {
  419. $queue.find('.fileinput-button').show();
  420. }
  421. $li.insertBefore($queue.find('.fileinput-button'));
  422. }
  423. // 负责view的销毁
  424. function removeFile( file ) {
  425. var $li = $('#'+file.id);
  426. delete percentages[ file.id ];
  427. updateTotalProgress();
  428. $li.off().find('.file-panel').off().end().remove();
  429. }
  430. function updateTotalProgress() {
  431. var loaded = 0,
  432. total = 0,
  433. spans = $progress.children(),
  434. percent;
  435. $.each( percentages, function( k, v ) {
  436. total += v[ 0 ];
  437. loaded += v[ 0 ] * v[ 1 ];
  438. } );
  439. percent = total ? loaded / total : 0;
  440. spans.eq( 0 ).text( Math.round( percent * 100 ) + '%' );
  441. spans.eq( 1 ).css( 'width', Math.round( percent * 100 ) + '%' );
  442. updateStatus();
  443. }
  444. function updateStatus() {
  445. var text = '', stats;
  446. if ( state === 'ready' ) {
  447. if($this.options.isWechat){
  448. //根据素材类型(临时或永久)更改上传地址
  449. if($this.options.mode == '') {
  450. var mode = $this.modalobj.find('.nav-pills li.active').attr('data-mode');
  451. } else {
  452. var mode = $this.options.mode;
  453. }
  454. if(!$this.options.flag) {
  455. uploader.option('server', uploader.option('server') + '&mode=' + mode + '&types=' + $this.options.type);
  456. $this.options.flag = 1;
  457. }
  458. }
  459. text = '选中' + fileCount + typeUnit + typeText +',共' + WebUploader.formatSize( fileSize ) + '。';
  460. } else if ( state === 'confirm' ) {
  461. stats = uploader.getStats();
  462. if ( stats.uploadFailNum ) {
  463. text = '已上传'+stats.successNum+typeUnit+typeText+','+stats.uploadFailNum+typeUnit+typeText+'上传失败,<a class="retry" href="#">重新上传</a>失败'+typeText+'或<a class="ignore" href="#">忽略</a>'
  464. }
  465. } else {
  466. stats = uploader.getStats();
  467. text = '共'+fileCount+typeUnit+'('+WebUploader.formatSize(fileSize)+'),已上传' + stats.successNum + typeUnit;
  468. if ( stats.uploadFailNum ) {
  469. text += ',失败' + stats.uploadFailNum + typeUnit;
  470. }
  471. }
  472. $info.html( text );
  473. }
  474. function setState( val ) {
  475. var file, stats;
  476. if ( val === state ) {
  477. return;
  478. }
  479. $upload.removeClass( 'state-' + state );
  480. $upload.addClass( 'state-' + val );
  481. state = val;
  482. switch ( state ) {
  483. case 'pedding':
  484. $placeHolder.removeClass( 'element-invisible' );
  485. $queue.hide();
  486. uploader.refresh();
  487. break;
  488. case 'ready':
  489. $placeHolder.addClass( 'element-invisible' );
  490. if($this.options.isWechat && $this.options.type == 'video'){
  491. $('#upload form').removeClass('hide');
  492. }
  493. $queue.show();
  494. uploader.refresh();
  495. break;
  496. case 'uploading':
  497. $progress.show();
  498. $upload.text( '暂停上传' );
  499. break;
  500. case 'paused':
  501. $progress.show();
  502. $upload.text( '继续上传' );
  503. break;
  504. case 'confirm':
  505. $progress.hide();
  506. $upload.text( '开始上传' ).addClass( 'disabled' );
  507. stats = uploader.getStats();
  508. if ( stats.successNum && !stats.uploadFailNum ) {
  509. setState( 'finish' );
  510. return;
  511. }
  512. break;
  513. case 'finish':
  514. $upload.removeClass( 'disabled' );
  515. stats = uploader.getStats();
  516. if ( stats.successNum ) {
  517. if (uploader.uploadedFiles.length > 0) {
  518. $this.finish(uploader.uploadedFiles);
  519. uploader.resetUploader();
  520. return;
  521. }
  522. } else {
  523. // 没有成功的图片,重设
  524. state = 'done';
  525. location.reload();
  526. }
  527. break;
  528. }
  529. updateStatus();
  530. }
  531. uploader.onUploadProgress = function( file, percentage ) {
  532. var $li = $('#'+file.id),
  533. $percent = $li.find('.progress span');
  534. $percent.css( 'width', percentage * 100 + '%' );
  535. percentages[ file.id ][ 1 ] = percentage;
  536. fileid = file.id;
  537. updateTotalProgress();
  538. };
  539. uploader.onFileQueued = function( file ) {
  540. fileCount++;
  541. fileSize += file.size;
  542. if ( fileCount === 1 ) {
  543. $placeHolder.addClass( 'element-invisible' );
  544. $statusBar.show();
  545. }
  546. addFile( file );
  547. setState( 'ready' );
  548. updateTotalProgress();
  549. };
  550. uploader.onFileDequeued = function( file ) {
  551. fileCount--;
  552. fileSize -= file.size;
  553. if ( !fileCount ) {
  554. setState( 'pedding' );
  555. }
  556. removeFile( file );
  557. updateTotalProgress();
  558. };
  559. uploader.on( 'all', function( type ) {
  560. var stats;
  561. switch( type ) {
  562. case 'uploadFinished':
  563. setState( 'confirm' );
  564. break;
  565. case 'startUpload':
  566. setState( 'uploading' );
  567. break;
  568. case 'stopUpload':
  569. setState( 'paused' );
  570. break;
  571. }
  572. });
  573. uploader.on( 'uploadSuccess', function(file, result) {
  574. if (result.message){
  575. alert(result.message);
  576. uploader.resetUploader();
  577. return ;
  578. }
  579. if (result.attachment || result.media_id){
  580. accept++;
  581. uploader.uploadedFiles.push(result);
  582. $('#'+file.id).append( '<span class="success" style="line-height: 50px;">'+result.width +'x'+ result.height +'</span>' );
  583. $('.accept').text('成功上传 '+accept+' '+typeUnit+typeText);
  584. }
  585. });
  586. uploader.onError = function( code ) {
  587. if(code == 'Q_EXCEED_SIZE_LIMIT'){
  588. alert('错误信息: '+typeText+'大于 '+WebUploader.formatSize(options.fileSizeLimit )+' 无法上传.');
  589. return
  590. }
  591. if(code == 'F_DUPLICATE'){
  592. alert('错误信息: 不能重复上传'+typeText+'.');
  593. return
  594. }
  595. alert( 'Eroor: ' + code );
  596. };
  597. $upload.on('click', function() {
  598. if ( $(this).hasClass( 'disabled' ) ) {
  599. return false;
  600. }
  601. if(state != 'pedding' && uploader.options.isWechat && uploader.options.type == 'video'){
  602. var title = $('#upload :text[name="title"]').val();
  603. var introduction = $('#upload textarea[name="introduction"]').val();
  604. if(!title) {
  605. util.message('视频标题不能为空');
  606. return false;
  607. }
  608. if(!introduction) {
  609. util.message('视频描述不能为空');
  610. return false;
  611. }
  612. uploader.option('formData', {title : title, introduction : introduction});
  613. }
  614. if ( state === 'ready' ) {
  615. uploader.upload();
  616. } else if ( state === 'paused' ) {
  617. uploader.upload();
  618. } else if ( state === 'uploading' ) {
  619. uploader.stop();
  620. }
  621. });
  622. $info.on( 'click', '.retry', function() {
  623. uploader.retry();
  624. } );
  625. $info.on( 'click', '.ignore', function() {
  626. // alert( 'todo' );
  627. } );
  628. $upload.addClass( 'state-' + state );
  629. updateTotalProgress();
  630. },
  631. 'initImageUploader' : function () {
  632. this.initUploader('image');
  633. },
  634. 'initAudioUploader' : function () {
  635. this.initUploader('audio');
  636. },
  637. 'initVoiceUploader' : function () {
  638. this.initUploader('voice');
  639. },
  640. 'initVideoUploader' : function () {
  641. this.initUploader('video');
  642. },
  643. 'initRemote' : function(o) {
  644. var $this = this;
  645. $this.modalobj.find('#li_network').removeClass('hide');
  646. $this.modalobj.find('.modal-body').append($this.buildHtml().remoteDialog);
  647. $this.modalobj.find('.btn-primary').click(function(){
  648. var url = $this.modalobj.find('#networkurl').val();
  649. if (url.length > 0 && $this.options.type == 'image'){
  650. $.getJSON(o, {'url':url}, function(result){
  651. if(result.message){
  652. alert(result.message);
  653. }
  654. if (result) {
  655. $this.finish([result]);
  656. result = {};
  657. }
  658. });
  659. }
  660. });
  661. },
  662. 'initVideoRemote' : function() {
  663. var $this = this;
  664. $this.modalobj.find('#li_network').removeClass('hide');
  665. $this.modalobj.find('.modal-body').append($this.buildHtml().remoteVideoDialog);
  666. $this.modalobj.find('#networkurl').blur(function(){
  667. var url = $(this).val();
  668. if (url.length > 0) {
  669. createPreviewVideo(url);
  670. } else {
  671. $('#preview').html('');
  672. }
  673. });
  674. $this.modalobj.find('.btn-primary').click(function(){
  675. var url = $this.modalobj.find('#networkurl').val();
  676. if (url.length > 0 && $this.options.type == 'video'){
  677. // 远程获取视频地址
  678. var conUrl = convert_url(url);
  679. conUrl = unhtmlForUrl(conUrl);
  680. $this.finish([{'url' : conUrl, 'isRemote' : true}]); // 添加一个isRemote,在百度编辑器中进行判断
  681. }
  682. });
  683. function createPreviewVideo(url){
  684. if ( !url )return;
  685. var conUrl = convert_url(url);
  686. conUrl = unhtmlForUrl(conUrl);
  687. $("#preview").html('<div style="position:absolute;top:0;margin:0;padding:120px 50px;width:100%;height:100%;font-size:20px;"><span>只支持 腾讯,优酷,土豆视频,如无法预览视频,请前往视频网址处的分享区域,复制通用地址到编辑器内部!</span></div>'+
  688. '<iframe src="'+conUrl+'" allowfullscreen="true" style="border:0;position:absolute;top:0;left:0;margin:0;padding:0;width:100%;height:100%;"></iframe>');
  689. }
  690. function convert_url(url){
  691. if ( !url ) return '';
  692. var id, iframe_url;
  693. if (url.indexOf('v.qq.com') >= 0) {
  694. id = url.match(/vid\=([^\&]*)($|\&)/);
  695. if (id) {
  696. iframe_url = 'https://v.qq.com/iframe/player.html?vid='+id[1]+'&tiny=0&auto=0';
  697. } else {
  698. id = url.match(/\/([0-9a-zA-Z]+).html/);
  699. if(id) {
  700. iframe_url = 'https://v.qq.com/iframe/player.html?vid='+id[1]+'&tiny=0&auto=0';
  701. }
  702. }
  703. if (!id) {
  704. return;
  705. }
  706. } else if (url.indexOf('v.youku.com') >= 0) {
  707. id = url.match(/id_(.*)\.html/);
  708. iframe_url = 'https://player.youku.com/embed/' + id[1];
  709. } else if (url.indexOf('tudou.com') >= 0) {
  710. id = url.match(/\/([-\w]+)/g);
  711. id = id[id.length - 1].substring(1);
  712. iframe_url = 'https://www.tudou.com/programs/view/html5embed.action?code=' + id;
  713. } else {
  714. return;
  715. }
  716. return iframe_url;
  717. }
  718. function unhtmlForUrl(str, reg) {
  719. return str ? str.replace(reg || /[<">']/g, function (a) {
  720. return {
  721. '<':'&lt;',
  722. '&':'&amp;',
  723. '"':'&quot;',
  724. '>':'&gt;',
  725. "'":'&#39;'
  726. }[a]
  727. }) : '';
  728. }
  729. },
  730. 'initLocal' : function() {
  731. var $this = this;
  732. $this.modalobj.find('#li_history_image').removeClass('hide');
  733. $this.modalobj.find('.modal-body').append(this.buildHtml().localDialog);
  734. $this.localPage(1);
  735. },
  736. 'localPage' : function(page) {
  737. var $this = this;
  738. let o = this.delete_urls;
  739. if($this.options.isWechat){
  740. var type = $this.options.type;
  741. var mode = $this.options.mode;
  742. var url = './index.php?c=utility&a=wechat_file&do=browser';
  743. var params = {'page': page, 'type' : type, 'mode' : mode, 'psize' : 32};
  744. }else{
  745. var year = $this.modalobj.find('#select-year .btn-info').data('id');
  746. var month = $this.modalobj.find('#select-month .btn-info').data('id');
  747. var url = this.image_urls;
  748. var params = {'page': page, 'year': year, 'month': month, 'pagesize':36};
  749. }
  750. var $history = $this.modalobj.find('#history_image');
  751. $.getJSON(url, params, function(data){
  752. data = data.message.message;
  753. $history.find('.history-content').css('text-align', 'center').html('<i class="fa fa-spinner fa-pulse fa-5x"></i>');
  754. $history.find('#image-list-pager').html('');
  755. if(!_.isEmpty(data.items)) {
  756. $history.data('attachment', data.items);
  757. $history.find('.history-content').empty();
  758. $history.find('.history-content').html(_.template($this.buildHtml()[$this.options.isWechat ? 'weixin_localDialogLi' : 'localDialogLi'])(data));
  759. $history.find('#image-list-pager').html(data.page);
  760. $history.find('.pagination a').click(function(){
  761. $this.localPage($(this).attr('page'));
  762. });
  763. $history.find('.img-list li').click(function(event){
  764. $this.selectImage($(event.target).parents('li'));
  765. });
  766. //删除
  767. if($this.options.isWechat){
  768. $this.weixinDeletefile();
  769. }else{
  770. $this.deletefile(o);
  771. }
  772. } else {
  773. $history.find('.history-content').css('text-align', 'left').html('<i class="fa fa-info-circle"></i> 暂无数据');
  774. }
  775. });
  776. if(!$this.options.isWechat){
  777. $this.modalobj.find('.btn-select').unbind('click').click(function(){
  778. if($(this).hasClass('btn-info')) {
  779. return false;
  780. }
  781. if($(this).data('type') == 'month' && $(this).data('id') > 0) {
  782. if(!$this.modalobj.find('#select-year .btn-info').data('id')) {
  783. $this.modalobj.find('#select-year .btn-select').removeClass('btn-info');
  784. $this.modalobj.find('#select-year .btn-select').eq(1).addClass('btn-info');
  785. }
  786. }
  787. $(this).siblings().removeClass('btn-info');
  788. $(this).addClass('btn-info');
  789. $this.localPage(1);
  790. });
  791. }
  792. $history.find('.btn-primary').unbind('click').click(function(){
  793. var attachment = [];
  794. $history.find('.img-item-selected').each(function(){
  795. attachment.push($this.modalobj.find('#history_image').data('attachment')[$(this).attr('attachid')]);
  796. $(this).removeClass('img-item-selected');
  797. });
  798. $this.finish(attachment);
  799. });
  800. return false;
  801. },
  802. 'deletefile' : function(o){
  803. var $this = this;
  804. $this.modalobj.find('#history_image .img-list li .btnClose').unbind().click(function(){
  805. var $this = $(this);
  806. var id = $(this).data('id');
  807. if(!id) return false;
  808. $.post(o, {id:id}, function(data){
  809. if(data != 'success') {
  810. alert(data);
  811. } else {
  812. $this.parent().remove();
  813. util.message('删除成功', '', 'success');
  814. }
  815. });
  816. return false;
  817. });
  818. },
  819. 'weixinDeletefile' : function() {
  820. var $this = this;
  821. $this.modalobj.find('.history .delete-file').off('click');
  822. $this.modalobj.find('.history .delete-file').on('click', function(event){
  823. var $this = $(this);
  824. if (confirm("确定要删除文件吗?")){
  825. var id = $(this).parent().attr('attachid');
  826. var type = $(this).parent().attr('data-type');
  827. $.post('./index.php?c=utility&a=wechat_file&do=delete', {'id' : id}, function(data){
  828. var data = $.parseJSON(data);
  829. if(!data.error) {
  830. util.message(data.message);
  831. return false;
  832. }
  833. if(type == 'image') {
  834. $this.parent().remove();
  835. } else if(type == 'audio' || type == 'voice' || type == 'video') {
  836. $this.parents('tr').remove();
  837. }
  838. });
  839. }
  840. event.stopPropagation();
  841. });
  842. },
  843. 'selectImage' : function(obj) {
  844. var $this = this;
  845. $(obj).toggleClass('img-item-selected');
  846. // 微信
  847. if($this.options.isWechat){
  848. if ($this.options.direct) {
  849. $this.modalobj.find('#history_image').find('.btn-primary').trigger('click');
  850. }
  851. }else{
  852. if (!$this.options.multiple) {
  853. $this.modalobj.find('#history_image').find('.btn-primary').trigger('click');
  854. }
  855. }
  856. },
  857. 'initLocalAudio' : function() {
  858. var $this = this;
  859. $this.modalobj.find('#li_history_audio').removeClass('hide');
  860. $this.modalobj.find('.modal-body').append(this.buildHtml().localAudioDialog);
  861. $this.localAudioPage(1);
  862. },
  863. 'localAudioPage' : function(page) {
  864. var $this = this;
  865. if($this.options.isWechat){
  866. var type = $this.options.type;
  867. var mode = $this.options.mode;
  868. var url = './index.php?c=utility&a=wechat_file&do=browser';
  869. var params = {'page': page, 'type' : type, 'mode' : mode, 'psize' : 5};
  870. }else{
  871. var url = './index.php?c=utility&a=file&do=local&type=audio&pagesize=5';
  872. var params = {'page': page};
  873. }
  874. var $history = $this.modalobj.find('#history_audio');
  875. $.getJSON(url, params, function(data){
  876. data = data.message;
  877. $history.find('.history-content').html('<i class="fa fa-spinner fa-pulse"></i>');
  878. if(!_.isEmpty(data.items)) {
  879. $history.data('attachment', data.items);
  880. $history.find('.history-content').empty();
  881. $history.find('.history-content').html(_.template($this.buildHtml()[$this.options.isWechat ? 'weixin_localAudioDialogLi' : 'localAudioDialogLi'])(data));
  882. $history.find('#image-list-pager').html(data.page);
  883. $history.find('.pagination a').click(function(){
  884. $this.localAudioPage($(this).attr('page'));
  885. });
  886. $history.find('.js-btn-select').click(function(event){
  887. $(event.target).toggleClass('btn-primary');
  888. // 微信
  889. if($this.options.isWechat){
  890. if ($this.options.direct) {
  891. $this.modalobj.find('#history_audio').find('.modal-footer .btn-primary').trigger('click');
  892. }
  893. }else{
  894. if (!$this.options.multiple) {
  895. $this.modalobj.find('#history_audio').find('.modal-footer .btn-primary').trigger('click');
  896. }
  897. }
  898. });
  899. $this.playAudio();
  900. //微信
  901. if($this.options.isWechat){
  902. $this.weixinDeletefile();
  903. }
  904. }else{
  905. $history.find('.history-content').css('text-align', 'center').html('<i class="fa fa-info-circle"></i> 暂无数据');
  906. }
  907. });
  908. $history.find('.modal-footer .btn-primary').unbind('click').click(function(){
  909. var attachment = [];
  910. $history.find('.history-content .btn-primary').each(function(){
  911. attachment.push($this.modalobj.find('#history_audio').data('attachment')[$(this).attr('attachid')]);
  912. $(this).removeClass('btn-primary');
  913. });
  914. $this.finish(attachment);
  915. });
  916. return false;
  917. },
  918. 'playAudio' : function (){
  919. var $this = this;
  920. var $history = $this.modalobj.find('#history_audio');
  921. $(".audio-player-play").click(function(){
  922. var src = $(this).attr("attach");
  923. if(!src) {
  924. return;
  925. }
  926. if ($("#player")[0]) {
  927. var player = $("#player");
  928. } else {
  929. var player = $('<div id="player"></div>');
  930. $(document.body).append(player);
  931. }
  932. player.data('control', $(this));
  933. player.jPlayer({
  934. playing: function() {
  935. $(this).data('control').find("p").removeClass("fa-play").addClass("fa-stop");
  936. },
  937. pause: function (event) {
  938. $(this).data('control').find("p").removeClass("fa-stop").addClass("fa-play");
  939. },
  940. swfPath: "resource/components/jplayer",
  941. supplied: "mp3,wma,wav,amr",
  942. solution: "html, flash",
  943. });
  944. player.jPlayer("setMedia", {mp3: $(this).attr("attach")}).jPlayer("play");
  945. if($(this).find("p").hasClass("fa-stop")) {
  946. player.jPlayer("stop");
  947. } else {
  948. $history.find('.fa-stop').removeClass("fa-stop").addClass("fa-play");
  949. player.jPlayer("setMedia", {mp3: $(this).attr("attach")}).jPlayer("play");
  950. }
  951. });
  952. },
  953. 'initLocalVoice' : function() {
  954. this.initLocalAudio();
  955. },
  956. 'initLocalVideo' : function() {
  957. var $this = this;
  958. $this.modalobj.find('#li_history_video').removeClass('hide');
  959. $this.modalobj.find('.modal-body').append(this.buildHtml().localVideoDialog);
  960. $this.localVideoPage(1);
  961. },
  962. 'localVideoPage' : function(c) {
  963. var d = this;
  964. if (d.options.isWechat) var e = d.options.type,
  965. f = "./index.php?c=utility&a=wechat_file&do=browser",
  966. g = {
  967. page: c,
  968. type: e,
  969. psize: 5
  970. };
  971. else var f = this.video_urls,
  972. g = {
  973. page: c
  974. };
  975. var h = d.modalobj.find("#history_video");
  976. return $.getJSON(f, g,
  977. function(c) {
  978. c = c.message.message,
  979. _.isEmpty(c.items) ? c: c.items = d.foritem(c.items),
  980. h.find(".history-content").html('<i class="fa fa-spinner fa-pulse"></i>'),
  981. _.isEmpty(c.items) ? h.find(".history-content").css("text-align", "left").html('<i class="fa fa-info-circle"></i> 暂无数据') : (h.data("attachment", c.items), h.find(".history-content").empty(), h.find(".history-content").html(_.template(d.buildHtml()[d.options.isWechat ? "weixin_localVideoDialogLi": "localVideoDialogLi"])(c)), h.find("#image-list-pager").html(c.pager), h.find(".pagination a").click(function() {
  982. d.localVideoPage(a(this).attr("page"))
  983. }), h.find(".js-btn-select").click(function(b) {
  984. $(b.target).toggleClass("btn-primary"),
  985. d.options.isWechat ? d.options.direct && d.modalobj.find("#history_video").find(".modal-footer .btn-primary").trigger("click") : d.options.multiple || d.modalobj.find("#history_video").find(".modal-footer .btn-primary").trigger("click")
  986. }), d.deletevideofile())
  987. }),
  988. h.find(".modal-footer .btn-primary").unbind("click").click(function() {
  989. var b = [];
  990. h.find(".history-content .btn-primary").each(function() {
  991. var dd = d.modalobj.find("#history_video").data("attachment");
  992. for (cc in dd) {
  993. if (dd[cc].id == $(this).attr("attachid")) {
  994. var ee = dd[cc]
  995. }
  996. };
  997. b.push(ee),
  998. $(this).removeClass("btn-primary")
  999. }),
  1000. d.finish(b)
  1001. }),
  1002. !1
  1003. },
  1004. 'finish' : function(attachment) {
  1005. var $this = this;
  1006. if($.isFunction($this.options.callback)) {
  1007. if ($this.options.multiple == false) {
  1008. $this.options.callback(attachment[0]);
  1009. } else {
  1010. $this.options.callback(attachment);
  1011. }
  1012. $this.modalobj.modal('hide');
  1013. }
  1014. },
  1015. 'deletevideofile' : function() {
  1016. var b = this;
  1017. let o = this.delete_urls;
  1018. b.modalobj.find("#history_video .history-content td .delete-video-file").unbind().click(function() {
  1019. if (confirm("确定要删除文件吗?")) {
  1020. var b = a(this),
  1021. c = a(this).data("id");
  1022. return c ? (a.post(o, {
  1023. id: c
  1024. },
  1025. function(a) { !(a.error) ? (b.parents('tr').remove(), util.message("删除成功", "", "success")) : util.message(a.message, "", "error");
  1026. }), !1) : !1
  1027. }
  1028. })
  1029. },
  1030. 'foritem' : function(items) {
  1031. var d = this;
  1032. for (obj in items) {
  1033. items[obj].createtime = d.getdate(items[obj].createtime)
  1034. }
  1035. return items
  1036. },
  1037. 'getdate' : function(date) {
  1038. var now = new Date(date * 1000),
  1039. y = now.getFullYear(),
  1040. m = now.getMonth() + 1,
  1041. day = now.getDate();
  1042. return y + "-" + (m < 10 ? "0" + m: m) + "-" + (day < 10 ? "0" + day: day) + " " + now.toTimeString().substr(0, 8)
  1043. },
  1044. 'buildHtml' : function() {
  1045. var dialog = {};
  1046. var myDate = new Date();
  1047. var abcd = '';
  1048. for (var i = myDate.getFullYear(); i > 2012; i--) {
  1049. abcd += '<a href="javascript:;" data-id="' + i + '" data-type="year" class="btn btn-default btn-select">' + i + '年</a>'
  1050. }
  1051. dialog['mainDialog'] = '<div id="modal-webuploader" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">\n' +
  1052. ' <div class="modal-dialog">\n' +
  1053. ' <div class="modal-content" style="width:785px">\n' +
  1054. ' <div class="modal-header">\n' +
  1055. ' <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>\n' +
  1056. ' <ul class="nav nav-pills" role="tablist">\n' +
  1057. ' <li id="li_upload" '+(!this.options.isWechat && this.options.allowUploadVideo ? 'class="active"' : 'class="hide"')+' role="presentation"><a href="#upload" aria-controls="upload" role="tab" data-toggle="tab" onclick="$(\'#select\').hide();">上传</a></li>\n' +
  1058. ' <li id="li_upload_perm" '+(this.options.isWechat ? 'class="active"' : 'class="hide"')+' data-mode="perm" role="presentation"><a href="#upload" aria-controls="upload" role="tab" data-toggle="tab" onclick="$(\'#select\').hide();">上传</a></li>\n' +
  1059. ' <li id="li_upload_temp" '+(this.options.isWechat ? '' : 'class="hide"')+'data-mode="temp" role="presentation"><a href="#upload" aria-controls="upload" role="tab" data-toggle="tab" onclick="$(\'#select\').hide();">上传</a></li>\n' +
  1060. ' <li id="li_network" '+(!this.options.allowUploadVideo ? 'class="active"' : 'class="hide"')+' role="presentation"><a href="#network" aria-controls="network" role="tab" data-toggle="tab" onclick="$(\'#select\').hide();">提取网络'+(this.options.type == 'video' ? '视频' : '图片')+'</a></li>\n' +
  1061. ' <li id="li_history_image" class="hide" role="presentation"><a href="#history_image" aria-controls="history_image" role="tab" data-toggle="tab" onclick="$(\'#select\').show();">浏览图片</a></li>\n' +
  1062. ' <li id="li_history_audio" class="hide" role="presentation"><a href="#history_audio" aria-controls="history_audio" role="tab" data-toggle="tab" onclick="$(\'#select\').hide();">浏览音频</a></li>\n' +
  1063. ' <li id="li_history_video" class="hide" role="presentation"><a href="#history_video" aria-controls="history_video" role="tab" data-toggle="tab">浏览视频</a></li>\n' +
  1064. ' </ul>\n' +
  1065. ' </div>\n' +
  1066. (!this.options.isWechat ?
  1067. ' <div id="select" style="display: none;margin:10px 0 -10px 15px; padding-left:7px;">'+
  1068. ' <div id="select-year" style="margin-bottom:10px;">'+
  1069. ' <div class="btn-group">'+
  1070. ' <a href="javascript:;" data-id="0" data-type="year" class="btn btn-default btn-info btn-select">不限</a>'
  1071. + abcd +
  1072. ' </div>'+
  1073. ' </div>'+
  1074. ' <div id="select-month">'+
  1075. ' <div class="btn-group">'+
  1076. ' <a href="javascript:;" data-id="0" data-type="month" class="btn btn-default btn-info btn-select">不限</a>'+
  1077. ' <a href="javascript:;" data-id="1" data-type="month" class="btn btn-default btn-select">1</a>'+
  1078. ' <a href="javascript:;" data-id="2" data-type="month" class="btn btn-default btn-select">2</a>'+
  1079. ' <a href="javascript:;" data-id="3" data-type="month" class="btn btn-default btn-select">3</a>'+
  1080. ' <a href="javascript:;" data-id="4" data-type="month" class="btn btn-default btn-select">4</a>'+
  1081. ' <a href="javascript:;" data-id="5" data-type="month" class="btn btn-default btn-select">5</a>'+
  1082. ' <a href="javascript:;" data-id="6" data-type="month" class="btn btn-default btn-select">6</a>'+
  1083. ' <a href="javascript:;" data-id="7" data-type="month" class="btn btn-default btn-select">7</a>'+
  1084. ' <a href="javascript:;" data-id="8" data-type="month" class="btn btn-default btn-select">8</a>'+
  1085. ' <a href="javascript:;" data-id="9" data-type="month" class="btn btn-default btn-select">9</a>'+
  1086. ' <a href="javascript:;" data-id="10" data-type="month" class="btn btn-default btn-select">10</a>'+
  1087. ' <a href="javascript:;" data-id="11" data-type="month" class="btn btn-default btn-select">11</a>'+
  1088. ' <a href="javascript:;" data-id="12" data-type="month" class="btn btn-default btn-select">12</a>'+
  1089. ' </div>'+
  1090. ' </div>'+
  1091. ' </div>' : '') +
  1092. ' <div class="modal-body tab-content"></div>\n' +
  1093. ' </div>\n' +
  1094. ' </div>\n' +
  1095. '</div>';
  1096. dialog['uploaderDialog'] = '<div role="tabpanel" class="tab-pane upload active" id="upload">\n' +
  1097. (this.options.isWechat && this.options.type == 'video' ?
  1098. '<form class="form-horizontal hide" style="padding-right:10px;">' +
  1099. ' <div class="form-group">' +
  1100. ' <label class="col-xs-12 col-sm-2 control-label">视频标题</label>' +
  1101. ' <div class="col-sm-10">' +
  1102. ' <input type="text" name="title" class="form-control" placeholder="视频标题">'+
  1103. ' </div>' +
  1104. ' </div>' +
  1105. ' <div class="form-group">' +
  1106. ' <label class="col-xs-12 col-sm-2 control-label">视频描述</label>' +
  1107. ' <div class="col-sm-10">' +
  1108. ' <textarea name="introduction" class="form-control" placeholder="视频描述"></textarea>'+
  1109. ' </div>' +
  1110. ' </div></form>' : '') +
  1111. ' <div id="uploader" class="uploader">\n' +
  1112. ' <div class="queueList">\n' +
  1113. ' <div id="dndArea" class="placeholder">\n' +
  1114. ' <div id="filePicker">xx</div>\n' +
  1115. (this.options.multiple ? '<p id="">或将照片拖到这里,单次最多可选'+(this.options.isWechat ? 5 : 30)+'张</p>\n' : '<p id="">或将照片拖到这里</p>\n') +
  1116. ' </div>\n' +
  1117. ' </div>\n' +
  1118. ' <div class="statusBar">\n' +
  1119. ' <div class="infowrap">\n' +
  1120. ' <div class="progress">\n' +
  1121. ' <span class="text">0%</span>\n' +
  1122. ' <span class="percentage"></span>\n' +
  1123. ' </div>\n' +
  1124. ' <div class="info"></div>\n' +
  1125. ' <div class="accept"></div>\n' +
  1126. ' </div>\n' +
  1127. ' <div class="btns">\n' +
  1128. ' <div class="uploadBtn btn btn-primary" style="margin-top: 4px;">确定使用</div>\n' +
  1129. ' <div class="modal-button-upload" style="float: right; margin-left: 5px;">\n' +
  1130. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' +
  1131. ' </div>\n' +
  1132. ' </div>\n' +
  1133. ' </div>\n' +
  1134. ' </div>\n' +
  1135. '</div>';
  1136. dialog['remoteDialog'] = '<div role="tabpanel" class="tab-pane network" id="network">\n' +
  1137. ' <div style="margin-top: 10px;">\n' +
  1138. ' <form>\n' +
  1139. ' <div class="form-group">\n' +
  1140. ' <input type="url" class="form-control" id="networkurl" placeholder="请输入网络图片地址">\n' +
  1141. ' <input type="hidden" name="network_attachment" value="" >\n' +
  1142. ' <div id="network-img" class="network-img" style="background-image:url(\'{php echo tomedia(\'images/global/nopic.jpg\');}\')">\n' +
  1143. ' <span class="network-img-sizeinfo" id="network-img-sizeinfo"></span>\n' +
  1144. ' </div>\n' +
  1145. ' </div>\n' +
  1146. ' </form>\n' +
  1147. ' </div>\n' +
  1148. ' <div class="modal-footer" style="margin:0 -30px -30px;">\n' +
  1149. ' <button type="button" class="btn btn-primary">确认</button>\n' +
  1150. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' +
  1151. ' </div>\n' +
  1152. '</div>';
  1153. dialog['remoteVideoDialog'] = '<div role="tabpanel" class="tab-pane network'+(!this.options.allowUploadVideo ? ' active' : ' ')+'" id="network">\n' +
  1154. ' <div style="margin-top: 10px;">\n' +
  1155. ' <form>\n' +
  1156. ' <div class="form-group">\n' +
  1157. ' <div style="margin: -10px 0 10px 0;">为了在微信中有更好的体验,推荐使用<a href="http://v.qq.com" target="_blank">腾讯视频</a></div>\n' +
  1158. ' <input type="url" class="form-control" id="networkurl" placeholder="请输入网络视频地址">\n' +
  1159. ' <div id="preview" style="position:relative;width:600px;height:300px;margin:0 auto;margin-top:15px;text-align:center;background:#ccc;">\n' +
  1160. ' </div>\n' +
  1161. ' </div>\n' +
  1162. ' </form>\n' +
  1163. ' </div>\n' +
  1164. ' <div class="modal-footer" style="margin:0 -30px -30px;">\n' +
  1165. ' <button type="button" class="btn btn-primary">确认</button>\n' +
  1166. ' <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' +
  1167. ' </div>\n' +
  1168. '</div>';
  1169. dialog['localDialog'] = '<div role="tabpanel" class="tab-pane history" id="history_image">\n' +
  1170. ' <div class="history-content" style="height:310px;overflow-y: auto;"></div>\n' +
  1171. ' <nav id="image-list-pager" class="text-right we7-margin-vertical">\n' +
  1172. ' <ul class="pager" style="margin: 0;"></ul>\n' +
  1173. ' </nav>\n' +
  1174. ' <div class="modal-footer" style="margin:0 -30px -30px;">\n' +
  1175. ' <div style="float: right;">\n' +
  1176. ' <button '+(this.options.multiple ? '' : 'style="display:none;"')+' type="button" class="btn btn-primary">确认</button>\n' +
  1177. (this.options.multiple ? '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' : '') +
  1178. ' </div>\n' +
  1179. ' </div>\n' +
  1180. '</div>';
  1181. dialog['localDialogLi'] = '<ul class="img-list clearfix">\n' +
  1182. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  1183. '<%_.each(items, function(item) {%> \n' +
  1184. '<li class="img-item" attachid="<%=item.id%>" title="<%=item.filename%>">\n' +
  1185. ' <div class="img-container" style="background-image: url(\'<%=item.url%>\');">\n' +
  1186. ' <div class="select-status"><span></span></div>\n' +
  1187. ' </div>\n' +
  1188. ' <div class="btnClose" data-id="<%=item.id%>"><a href=""><i class="fa fa-times"></i></a></div>\n' +
  1189. '</li>\n' +
  1190. '<%});%>\n' +
  1191. '</ul>';
  1192. dialog['weixin_localDialogLi'] = '<ul class="img-list clearfix">\n' +
  1193. '<%_.each(items, function(item) {%> \n' +
  1194. '<li class="img-item" attachid="<%=item.id%>" data-type="image" title="<%=item.filename%>">\n' +
  1195. ' <div class="btnClose delete-file"><a href="javascript:;"><i class="fa fa-times"></i></a></div>'+
  1196. ' <div class="img-container" style="background-image: url(\'<%=item.url%>\');">\n' +
  1197. ' <div class="select-status"><span></span></div>\n' +
  1198. ' </div>\n' +
  1199. '</li>\n' +
  1200. '<%});%>\n' +
  1201. '</ul>';
  1202. dialog['localAudioDialog'] = '<div role="tabpanel" class="tab-pane history" id="history_audio">\n' +
  1203. ' <div style="height:310px; overflow-x:hidden; overflow-y: auto;">\n' +
  1204. ' <table class="table table-hover we7-table">\n' +
  1205. ' <thead class="navbar-inner">\n' +
  1206. ' <tr>\n' +
  1207. ' <th>标题</th>\n' +
  1208. (this.options.isWechat ?
  1209. ' <th style="width:30%;text-align:right">创建时间</th>\n' +
  1210. ' <th style="width:30%;text-align:right">\n' +
  1211. ' <div class="input-group input-group-sm hide">\n' :
  1212. ' <th style="width:20%;">创建时间</th>\n' +
  1213. ' <th style="width:30%;">\n' +
  1214. ' <div class="input-group input-group-sm">\n') +
  1215. ' <input type="text" class="form-control">\n' +
  1216. ' <span class="input-group-btn">\n' +
  1217. ' <button class="btn btn-default" type="button"><i class="fa fa-search" style="font-size:12px; margin-top:0;"></i></button>\n' +
  1218. ' </span>\n' +
  1219. ' </div>\n' +
  1220. ' </th>\n' +
  1221. ' </tr>\n' +
  1222. ' </thead>\n' +
  1223. ' <tbody class="history-content">\n' +
  1224. ' </tbody>\n' +
  1225. ' </table></div>\n' +
  1226. ' <nav id="image-list-pager" class="text-right we7-margin-vertical">\n' +
  1227. ' <ul class="pager" style="margin: 0;"></ul>\n' +
  1228. ' </nav>\n' +
  1229. ' <div class="modal-footer" style="margin:0 -30px -30px;">\n' +
  1230. ' <div style="float: right;">\n' +
  1231. ' <button '+(this.options.multiple ? '' : 'style="display:none;"')+' type="button" class="btn btn-primary">确认</button>\n' +
  1232. (this.options.multiple ? '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' : '') +
  1233. ' </div>\n' +
  1234. ' </div>\n' +
  1235. '</div>';
  1236. dialog['localAudioDialogLi'] =
  1237. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  1238. '<%_.each(items, function(item) {%> \n' +
  1239. '<tr>\n' +
  1240. ' <td><a href="#" title="<%=item.filename%>"><%=item.filename%></a></td>\n' +
  1241. ' <td class="text-right"><%=item.createtime%></td>\n' +
  1242. ' <td class="text-right">\n' +
  1243. ' <span class="input-group-btn">\n' +
  1244. ' <button class="btn btn-default audio-player-play" type="button" attach="<%=item.url%>"><p style="margin:0px;" class="fa fa-play"></p></button>\n' +
  1245. ' <button attachid="<%=item.id%>" class="btn btn-default js-btn-select">选取</button>\n' +
  1246. ' </span>\n' +
  1247. ' </td>\n' +
  1248. '</tr>\n' +
  1249. '<%});%>\n';
  1250. dialog['weixin_localAudioDialogLi'] =
  1251. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  1252. '<%_.each(items, function(item) {%> \n' +
  1253. '<tr>\n' +
  1254. ' <td><a href="<%=item.url%>" target="blank" title="<%=item.filename%>"><%=item.filename%></a></td>\n' +
  1255. ' <td class="text-right"><%=item.createtime%></td>\n' +
  1256. ' <td class="text-right">\n' +
  1257. ' <span class="input-group-btn" attachid="<%=item.id%>" data-type="audio">\n' +
  1258. ' <button class="btn btn-default audio-player-play" type="button" attach="<%=item.url%>"><p style="margin:0px;" class="fa fa-play"></p></button>\n' +
  1259. ' <button class="btn btn-default delete-file">删除</button>\n' +
  1260. ' <button attachid="<%=item.id%>" class="btn btn-default js-btn-select">选取</button>\n' +
  1261. ' </span>\n' +
  1262. ' </td>\n' +
  1263. '</tr>\n' +
  1264. '<%});%>\n';
  1265. dialog['localVideoDialog'] = '<div role="tabpanel" class="tab-pane history" id="history_video">\n' +
  1266. ' <div style="height:310px; overflow-x:hidden; overflow-y:auto;">\n' +
  1267. ' <table class="table table-hover we7-table">\n' +
  1268. ' <thead class="navbar-inner">\n' +
  1269. ' <tr>\n' +
  1270. ' <th>标题</th>\n' +
  1271. ' <th style="width:30%;text-align:right">创建时间</th>\n' +
  1272. ' <th style="width:30%;text-align:right">\n' +
  1273. ' <div class="input-group input-group-sm hide">\n' +
  1274. ' <input type="text" class="form-control">\n' +
  1275. ' <span class="input-group-btn">\n' +
  1276. ' <button class="btn btn-default" type="button"><i class="fa fa-search" style="font-size:12px; margin-top:0;"></i></button>\n' +
  1277. ' </span>\n' +
  1278. ' </div>\n' +
  1279. ' </th>\n' +
  1280. ' </tr>\n' +
  1281. ' </thead>\n' +
  1282. ' <tbody class="history-content">\n' +
  1283. ' </tbody>\n' +
  1284. ' </table></div>\n' +
  1285. ' <nav id="image-list-pager" class="text-right we7-margin-vertical">\n' +
  1286. ' <ul class="pager" style="margin: 0;"></ul>\n' +
  1287. ' </nav>\n' +
  1288. ' <div class="modal-footer" style="margin:0 -30px -30px;">\n' +
  1289. ' <div style="float: right;">\n' +
  1290. ' <button '+(this.options.multiple ? '' : 'style="display:none;"')+' type="button" class="btn btn-primary">确认</button>\n' +
  1291. (this.options.multiple ? '<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>\n' : '') +
  1292. ' </div>\n' +
  1293. ' </div>\n' +
  1294. '</div>';
  1295. dialog['localVideoDialogLi'] =
  1296. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  1297. '<%_.each(items, function(item) {%> \n' +
  1298. '<tr>\n' +
  1299. ' <td><a href="#" title="<%=item.filename%>"><%=item.filename%></a></td>\n' +
  1300. ' <td class="text-right"><%=item.createtime%></td>\n' +
  1301. ' <td class="text-right">\n' +
  1302. ' <span class="input-group-btn">\n' +
  1303. ' <button attachid="<%=item.id%>" class="btn btn-default js-btn-select">选取</button>\n' +
  1304. ' </span>\n' +
  1305. ' </td>\n' +
  1306. '</tr>\n' +
  1307. '<%});%>\n';
  1308. dialog['weixin_localVideoDialogLi'] =
  1309. '<%var items = _.sortBy(items, function(item) {return -item.id;});%>' +
  1310. '<%_.each(items, function(item) {%> \n' +
  1311. '<tr>\n' +
  1312. ' <td><a href="<%=item.url%>" target="blank" title="<%=item.filename%>"><%=item.filename%></a></td>\n' +
  1313. ' <td class="text-right"><%=item.createtime%></td>\n' +
  1314. ' <td class="text-right">\n' +
  1315. ' <span class="input-group-btn" attachid="<%=item.id%>" data-type="audio">\n' +
  1316. ' <button class="btn btn-default delete-file">删除</button>\n' +
  1317. ' <button attachid="<%=item.id%>" class="btn btn-default js-btn-select">选取</button>\n' +
  1318. ' </span>\n' +
  1319. ' </td>\n' +
  1320. '</tr>\n' +
  1321. '<%});%>\n';
  1322. return dialog;
  1323. }
  1324. };
  1325. return uploader;
  1326. });