PageRenderTime 54ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/XCloud/js/main.js

https://gitlab.com/Mirros/libs
JavaScript | 273 lines | 256 code | 6 blank | 11 comment | 27 complexity | 7e57ed4a1eda5d30ddfd7f05d6991611 MD5 | raw file
  1. var dialog_tpl_css = "<style>\
  2. div.check_version_dialog .aui_header{background:transparent;opacity:1;filter: alpha(opacity=100);}\
  3. div.check_version_dialog .aui_title{color:#fff;text-shadow:none;}\
  4. div.check_version_dialog .aui_min,div.check_version_dialog .aui_max{display:none;}\
  5. div.check_version_dialog .aui_close{border-radius: 12px;}\
  6. div.dialog-simple .dialog_mouse_in{.aui_header{.opacity(100);}}\
  7. div.check_version_dialog .aui_content{overflow: visible;}\
  8. div.check_version_dialog .aui_title{background-color:transparent;border: none;}\
  9. .update_box .hidden{display: none;}\
  10. .update_box{background:#fff;font-size: 14px;box-shadow: 0 5px 30px rgba(0,0,0,0.5);margin-top:-35px;}\
  11. .update_box .title{width:100%;background:#6699cc;color:#fff;height:130px;}\
  12. .update_box .button_radius{text-align:center;margin: 0 auto;padding-top:50px;}\
  13. .update_box .button_radius a{color:#fff;text-decoration:none;border-bottom: 2px solid #f6f6f6;border:2px solid rgba(255,255,255,0.6);\
  14. border-radius:20px;padding:5px 10px;display: inline-block;font-size: 16px;}\
  15. .update_box .button_radius a i{padding-left: 8px;}\
  16. .update_box .button_radius a:hover,.button_radius a:focus,.button_radius a.this{background:rgba(255,255,255,0.3);}\
  17. .update_box .button_radius a.this:hover{cursor: default;}\
  18. .update_box .ver_tips{float:right; ;text-align: right;text-decoration: none;color:#9CF;display:block;margin-top: -26px;padding-right:10px;}\
  19. .update_box .ver_tips:hover{color:#fff;}\
  20. .update_box .version{color:#fff;font-size: 13px;text-align: center;line-height:50px;height:50px;}\
  21. .update_box .version_info{padding:20px;}\
  22. .update_box .version_info i{font-size:15px;display: block;border-left:3px solid #9cf;padding-left:10px;}\
  23. .update_box .version_info .version_info_content{color: #69c;background:#eee;margin-top: 10px;padding:10px;}\
  24. .update_box .version_info p{height:140px;overflow:auto;}\
  25. .update_box .version_info a{float: right;color:#69c;text-decoration: none;}\
  26. .update_box .progress{box-shadow:0 0 3px #fff;border-radius:20px;margin: 0 auto;margin-bottom:10px;width:170px;height:16px;margin-top: 10px;overflow:hidden !important;}\
  27. .update_box .progress img{width:170px;}\
  28. </style>";
  29. var dialog_tpl_html = "<div class='update_box'>\
  30. <div class='title'>\
  31. <div class='button_radius'>\
  32. <div class='progress hidden'><img src='{{loading_img}}'/></div>\
  33. {{if has_new}}\
  34. <a href='javascript:;' class='update_click'><span>{{LNG.update_auto_update}}</span><i class='icon-arrow-right'></i></a>\
  35. {{else}}\
  36. <a href='javascript:;' class='this'>{{LNG.update_is_new}}<i class='icon-smile'></i></a>\
  37. {{/if}}\
  38. </div>\
  39. {{if has_new}}<a class='ver_tips ignore' href='javascript:;'>{{LNG.update_ignore}}</a>{{/if}}\
  40. <div class='version'>{{LNG.update_version_local}}ver{{ver_local}} | {{LNG.update_version_newest}}ver {{ver_new}}\
  41. {{if has_new}}<span class='badge' style='background:#f60;'>new</span>{{/if}}</div>\
  42. <div style='clear:both'></div>\
  43. </div>\
  44. <div class='version_info'>\
  45. <i>ver {{ver_new}} {{LNG.update_whats_new}}</i>\
  46. <div class='version_info_content'>\
  47. <p>{{echo LNG.update_info}}</p>\
  48. <a class='more' href='{{readmore_href}}' target='_blank'>{{LNG.update_readmore}}</a>\
  49. <div style='clear:both'></div>\
  50. </div>\
  51. </div>\
  52. </div>";
  53. define(function(require, exports) {
  54. var server_version = '3.01';//最新版本
  55. var local_version = G.version;
  56. var readmore_href = 'http://kalcaddle.com/download.html';
  57. var current_version_file = 'http://static.kalcaddle.com/download/update/2.0-'+server_version+'.zip';
  58. var status_href = 'http://kalcaddle.com/tools/state/index.php';
  59. var kod_user_online = 'kod_user_online_version';
  60. var time = function(){var date = new Date();return parseInt(date.getTime()/1000);}
  61. var _download = function(from,to,callback){
  62. $.ajax({
  63. url:'?explorer/serverDownload&save_path='+to
  64. +'&url='+urlEncode2(from),
  65. dataType:'json',
  66. success:function(data){
  67. if (typeof (callback) == 'function') callback(data);
  68. }
  69. });
  70. };
  71. var _unzip = function(file,unzip_to,callback){
  72. $.ajax({
  73. url:'index.php?explorer/unzip&path_to='+urlEncode(unzip_to)
  74. +'&path='+urlEncode(file),
  75. success:function(data){
  76. if (typeof (callback) == 'function') callback(data);
  77. }
  78. });
  79. };
  80. var _remove = function(param,callback){
  81. $.ajax({
  82. url: 'index.php?explorer/pathDelete',
  83. type:'POST',
  84. dataType:'json',
  85. data:param,
  86. success:function(data){
  87. if (typeof (callback) == 'function') callback(data);
  88. }
  89. });
  90. };
  91. //自动更新
  92. var update = function(){
  93. if (G.is_root !=1) return;
  94. var id = 'check_version_dialog',
  95. $button = $('.'+id).find('.update_click'),
  96. $press = $('.'+id).find('.progress'),
  97. $tips = $('.'+id).find('.ver_tips');
  98. var new_file = current_version_file,
  99. save_to = G.basic_path+'data/',
  100. unzip_to = G.basic_path;
  101. $tips.removeClass('ignore').html(LNG.update_downloading);
  102. $button.addClass('hidden');
  103. $press.removeClass('hidden').fadeIn(300);
  104. _download(new_file,save_to,function(data){
  105. if (data.code) {
  106. var zipfile = data.info;
  107. if (zipfile.length<20) {//新的远程下载返回文件名 之前为全名。
  108. zipfile = save_to+zipfile;
  109. }
  110. var remove = 'list=[{"type":"file","path":"'+urlEncode(zipfile)+'"}]';
  111. _unzip(zipfile,G.basic_path,function(data){
  112. if (data.code) {//更新成功
  113. _remove(remove,function(){//删除下载的安装包
  114. Cookie.del(kod_user_online);
  115. $press.addClass('hidden');
  116. $tips.html(LNG.update_success);
  117. $button.removeClass('hidden')
  118. .unbind('click')
  119. .removeClass('update_click')
  120. .addClass('this')
  121. .html(LNG.update_success);
  122. setTimeout(function(){//更新完自动刷新
  123. FrameCall.goRefresh();
  124. },2000);
  125. });
  126. return;
  127. }
  128. //解压失败
  129. $press.addClass('hidden');
  130. $tips.html(LNG.update_unzip_fail);
  131. $button.removeClass('hidden').html(LNG.update_auto_update);
  132. });
  133. return;
  134. }
  135. //解压失败
  136. $press.addClass('hidden');
  137. $tips.html(LNG.update_download_fail);
  138. $button.removeClass('hidden').html(LNG.update_auto_update);
  139. });
  140. };
  141. var init_language = function(){
  142. var type = 'en';
  143. if (typeof(G["lang"]) != 'undefined') type = G["lang"];
  144. if (typeof(LNG["config"]) != 'undefined' &&
  145. typeof(LNG["config"]['type']) != 'undefined'){
  146. type = LNG["config"]['type'];
  147. }
  148. if (!inArray(['en','zh_CN'],type)) type = 'en';
  149. var L = {
  150. 'en':{
  151. 'update_downloading':'Downloading...',
  152. 'update_download_fail':'Download failed',
  153. 'update_unzip_fail':'Unzip update failed',
  154. 'update_doing':'Updating',
  155. 'update_title':"Update",
  156. 'update_success':"Update successful",
  157. 'update_fail':"Update failed",
  158. 'update_auto_update':"Update Now",
  159. 'update_is_new':"Aredy is the newest",
  160. 'update_version_newest':"Newest Version",
  161. 'update_version_local':"Current Version",
  162. 'update_ignore':"Ignore",
  163. 'update_readmore':"Read more",
  164. 'update_whats_new':"What's New",
  165. 'update_info':"1.zip bug<br/>2.drag ——cute<br/>3.search <br/>4.editor...<br/>"
  166. },
  167. 'zh_CN':{
  168. 'update_downloading':'下载中...',
  169. 'update_download_fail':'下载失败',
  170. 'update_unzip_fail':'解压覆盖失败',
  171. 'update_doing':'更新中...',
  172. 'update_title':"更新提示",
  173. 'update_success':"更新成功!",
  174. 'update_fail':"更新失败!",
  175. 'update_auto_update':"自动更新",
  176. 'update_is_new':"已经是最新版",
  177. 'update_version_newest':"最新版本",
  178. 'update_version_local':"当前版本",
  179. 'update_ignore':"暂时忽略",
  180. 'update_readmore':"查看更多",
  181. 'update_whats_new':"更新说明",
  182. 'update_info':"3.01:3.0的一些bug修复,分享优化<br/>1.文件分享<br/>2.大文件上传<br/>3.回收站<br/>4.自定义菜单....,more..."
  183. }
  184. };
  185. for (var key in L[type]){
  186. LNG[key] = L[type][key];
  187. }
  188. };
  189. //自动检查版本,自动更新
  190. var check_version = function(display){
  191. var ver_new = parseFloat(server_version),
  192. ver_local = parseFloat(local_version),
  193. key_timeout = 'kod_update_ignore_timeout',
  194. has_new = false;
  195. if (ver_new > ver_local) has_new=true;
  196. if (local_version.indexOf('commercial') >1) return;
  197. //if (ver_new != ver_local) has_new=true;
  198. //对话框显示
  199. var show_dialog = function(){
  200. var id = 'check_version_dialog';
  201. if ($('.'+id).length==0) {
  202. init_language();
  203. var render = template.compile(dialog_tpl_html);
  204. var html = dialog_tpl_css+render({
  205. loading_img:G.static_path+'images/loading_simple.gif',
  206. LNG:LNG,has_new:has_new,
  207. readmore_href:readmore_href,
  208. ver_new:server_version,ver_local:local_version});
  209. art.dialog.through({
  210. id:id,
  211. simple:true,
  212. top:'50%',
  213. resize:false,
  214. width:330,
  215. title:LNG.update_title,
  216. padding:'0',
  217. fixed:true,
  218. content:html
  219. });
  220. $('.'+id)
  221. .hide()
  222. .fadeIn(600)
  223. .find('.update_click').unbind('click').bind('click',function(){
  224. update();
  225. Cookie.del(key_timeout);
  226. });
  227. $('.'+id).find('.ignore').die('click').live('click',function(){
  228. //设置cookie一年有效,2天后检查;
  229. Cookie.set(key_timeout,time()+3600*24*2,24*365);
  230. art.dialog.list[id].close();
  231. });
  232. }
  233. };
  234. if (display) show_dialog();
  235. if (has_new && //第一次
  236. (Cookie.get(key_timeout) == undefined ||
  237. Cookie.get(key_timeout) <= time())) {
  238. show_dialog();
  239. }
  240. };
  241. var user_state = function(){
  242. //当前版本
  243. //if (Cookie.get(kod_user_online) != undefined) return;
  244. var url = status_href+'?is_root='+G.is_root
  245. +'&host='+urlEncode(G.app_host)+'&version='+local_version;
  246. require.async(url,function(){
  247. Cookie.set(kod_user_online,'check-at-'+time(),24);
  248. });
  249. };
  250. //入口函数,没有参数则默认检查版本
  251. var todo = function(action) {
  252. switch(action){
  253. case undefined:
  254. //自动检查版本,有更新才跳出对话框
  255. if (G.is_root == 1) {
  256. check_version(false);
  257. }
  258. user_state();
  259. break;
  260. case 'check':check_version(true);break;//检查版本,显示版本信息
  261. default:break;
  262. }
  263. };
  264. return {
  265. todo:todo
  266. };
  267. });