desktop.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224
  1. //桌面脚本
  2. var win8Desktop={ getType : function(object) {
  3. return Object.prototype.toString.call(object).match(
  4. /^\[object\s(.*)\]$/)[1];
  5. },
  6. isTypeOf : function(object, typeStr) {
  7. return this.getType(object) == typeStr;
  8. },
  9. textLength : function(text) {
  10. var intLength = 0;
  11. for ( var i = 0; i < text.length; i++) {
  12. if ((text.charCodeAt(i) < 0) || (text.charCodeAt(i) > 255)) {
  13. intLength = intLength + 2;
  14. } else {
  15. intLength = intLength + 1;
  16. }
  17. }
  18. return intLength
  19. },
  20. getImgWh : function(url, callback) {
  21. var width, height, intervalId, check, div, img = new Image(), body = document.body;
  22. img.src = url;
  23. if (img.complete) {
  24. return callback(img.width, img.height);
  25. }
  26. ;
  27. if (body) {
  28. div = document.createElement('div');
  29. div.style.cssText = 'visibility:hidden;position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden';
  30. div.appendChild(img)
  31. body.appendChild(div);
  32. width = img.offsetWidth;
  33. height = img.offsetHeight;
  34. check = function() {
  35. if (img.offsetWidth !== width || img.offsetHeight !== height) {
  36. clearInterval(intervalId);
  37. callback(img.offsetWidth, img.clientHeight);
  38. img.onload = null;
  39. div.innerHTML = '';
  40. div.parentNode.removeChild(div);
  41. }
  42. ;
  43. };
  44. intervalId = setInterval(check, 150);
  45. }
  46. ;
  47. img.onload = function() {
  48. callback(img.width, img.height);
  49. img.onload = img.onerror = null;
  50. clearInterval(intervalId);
  51. body && img.parentNode.removeChild(img);
  52. };
  53. },
  54. fullscreen : function() {
  55. var docElm = document.documentElement;
  56. if (docElm.requestFullscreen) {
  57. docElm.requestFullscreen();
  58. } else if (docElm.mozRequestFullScreen) {
  59. docElm.mozRequestFullScreen();
  60. } else if (docElm.webkitRequestFullScreen) {
  61. docElm.webkitRequestFullScreen();
  62. }
  63. },
  64. exitFullscreen : function() {
  65. if (document.exitFullscreen) {
  66. document.exitFullscreen();
  67. } else if (document.mozCancelFullScreen) {
  68. document.mozCancelFullScreen();
  69. } else if (document.webkitCancelFullScreen) {
  70. document.webkitCancelFullScreen();
  71. }
  72. },
  73. fullscreenIE : function() {
  74. if ($.browser.msie) {
  75. var wsh = new ActiveXObject("WScript.Shell");
  76. wsh.sendKeys("{F11}");
  77. }
  78. },
  79. includFile : function(includePath, file) {
  80. var files = typeof file == "string" ? [ file ] : file;
  81. for ( var i = 0; i < files.length; i++) {
  82. var name = files[i].replace(/^\s|\s$/g, "");
  83. var att = name.split('.');
  84. var ext = att[att.length - 1].toLowerCase();
  85. var isCSS = ext == "css";
  86. var tag = isCSS ? "link" : "script";
  87. var attr = isCSS ? " type='text/css' rel='stylesheet' "
  88. : " language='javascript' type='text/javascript' ";
  89. var link = (isCSS ? "href" : "src") + "='" + includePath + name
  90. + "'";
  91. if ($(tag + "[" + link + "]").length == 0)
  92. document.write("<" + tag + attr + link + "></" + tag + ">");
  93. }
  94. },
  95. trim : function(str) {
  96. if(str==null)return "";
  97. return str.replace(/^\s+|\s+$/g, "");
  98. }
  99. };
  100. win8Desktop.wallpaper = {
  101. init : function(imgUrl, type) {
  102. var _self = this;
  103. if (type != 3) {
  104. win8Desktop.getImgWh(imgUrl, function(imgWidth, imgHeight) {
  105. $("<img src='" + imgUrl + "' />").appendTo("#wallpaper");
  106. _self.setWallpaper(imgWidth, imgHeight, type);
  107. $(window).wresize(function() {
  108. _self.setWallpaper(imgWidth, imgHeight, type);
  109. });
  110. });
  111. } else {
  112. $("#wallpaper").css({
  113. "background" : "url(" + imgUrl + ") repeat 0 0"
  114. });
  115. }
  116. },
  117. setWallpaper : function(imgWidth, imgHeight, type) {
  118. var winW = $(window).width(), winH = $(window).height();
  119. if (type == 1) {
  120. $("#wallpaper").find("img").css({
  121. 'width' : winW,
  122. 'height' : winH
  123. });
  124. }
  125. if (type == 2) {
  126. if (imgWidth > winW) {
  127. $("#wallpaper").find("img").css({
  128. 'width' : imgWidth,
  129. 'height' : imgHeight,
  130. 'margin-left' : (imgWidth - winW) / 2 + "px",
  131. 'margin-top' : (imgHeight - winH) / 2 + "px"
  132. });
  133. } else {
  134. $("#wallpaper").find("img").css({
  135. 'width' : imgWidth,
  136. 'height' : imgHeight,
  137. 'margin-left' : -(imgWidth - winW) / 2 + "px",
  138. 'margin-top' : -(imgHeight - winH) / 2 + "px"
  139. });
  140. }
  141. }
  142. }
  143. };
  144. win8Desktop.myWindow = {
  145. init : function(options) {
  146. var wh = {
  147. "w" : $(window).width(),
  148. "h" : $(window).height()
  149. }, curWinNum = $("div.myWindow").size(), defaults = {
  150. windowTitle : null,
  151. windowsId : null,
  152. windowPositionTop : 0,
  153. windowPositionLeft : 0,
  154. windowWidth : Math.round(wh['w'] * 0.9),
  155. windowHeight : Math.round(wh['h'] * 0.8),
  156. windowMinWidth : 250,
  157. windowMinHeight : 250,
  158. iframSrc : null,
  159. windowResizable : true,
  160. windowMaximize : true,
  161. windowMinimize : true,
  162. windowClosable : true,
  163. windowDraggable : true,
  164. windowStatus : 'regular',
  165. windowAnimationSpeed : 500,
  166. windowAnimation : true,
  167. parentPanel : 'body'
  168. }, options = $.extend(defaults, options), $newWin = $("#win_"
  169. + options['windowsId']), winHtml = function(options) {
  170. var winHtml = "<div class='myWindow tc_b' id='win_" + options.windowsId
  171. + "' >";
  172. /* winHtml += "<div class='winTitle'>";
  173. // winHtml += "<span class='winTitleName'>"
  174. // + options.windowTitle+ "</span>";
  175. winHtml += "<span class='winControlBtn'>" +
  176. // "<a href='#' class='winMinBtn' title='最小化'></a>" +
  177. // "<a href='#' class='winMaxBtn' title='最大化'></a>" +
  178. // "<a href='#' class='winRestore' title='还原'></a>" +
  179. "<a href='#' class='winCloseBtn' title='关闭'></a>" +
  180. "</span></div>";*/
  181. winHtml += "<div class='winClose' style='cursor:pointer'></div>";
  182. winHtml += "<div class='winContent'>";
  183. winHtml += "<div class='loading'>正在加载中</div>";
  184. winHtml += "<iframe scrolling='auto' frameborder='no' class='iframeApp' name='iframeApp_"
  185. + options.windowsId
  186. + "' id='iframeApp_"
  187. + options.windowsId + "' src=''></iframe>";
  188. winHtml += "<div class='iframeFix' id='iframeFix_" + options.windowsId + "'></div>";
  189. winHtml += "</div>";
  190. winHtml += "<div class='win_bottom' title='双击放大/还原' id='win_bottom' style='text-align:center;padding-top:5px;'>" +
  191. "<a href='#' class='winMinBtn' title='home'>" +
  192. "<img src='/shares/images/master1/home_b.png' width='53px' height='56px' />" +
  193. "</a>" +
  194. "<a href='#' style='float:right;' class='winMaxBtn' title='最大化'></a>"+
  195. "<a href='#' style='float:right;' class='winRestore' title='还原'></a>"+
  196. "</div>";
  197. winHtml += "</div>";
  198. return winHtml;
  199. }, _self = this;
  200. if (!$newWin.size()) {
  201. $(winHtml(options)).appendTo(options.parentPanel);
  202. var $newWin = $("#win_" + options['windowsId']), $allWins = $("div.myWindow"), $iframe = $newWin
  203. .find("iframe"),
  204. $loading = $newWin.find("div.loading"),
  205. $wincontent = $newWin.find("div.winContent"),
  206. $winTitle = $newWin.find("div.winTitle"),
  207. winMaximize_btn = $newWin.find('a.winMaxBtn'),
  208. winMinimize_btn = $newWin.find('a.winMinBtn'),
  209. // winClose_btn = $newWin.find('a.winCloseBtn'),
  210. winClose_btn = $newWin.find('div.winClose'),
  211. winHyimize_btn = $newWin.find('a.winRestore');
  212. var $topWin = $("div.topWin,div.topWin:hidden"),
  213. // dx = Math.floor((Math.random() * 200))+ (wh['w'] - options['windowWidth']) / 2,
  214. dx = (wh['w'] - options['windowWidth']) / 2,
  215. // dy = Math.floor((Math.random() * 200))+ (wh['h'] - options['windowHeight']) / 2,
  216. dy = 100+(wh['h'] - options['windowHeight']) / 2,
  217. zindex = curWinNum ? parseInt($topWin.css("z-index")?$topWin.css("z-index"):"100") + 1: curWinNum + 100,
  218. //zindex = 100;
  219. wLeft = win8Desktop.isTypeOf(
  220. options['windowPositionLeft'], "Number") ? options['windowPositionLeft']
  221. + dx
  222. : dx, wTop = win8Desktop.isTypeOf(
  223. options['windowPositionTop'], "Number") ? options['windowPositionTop']
  224. + dy / 2
  225. : dy / 2,
  226. iframe_init = function() {
  227. $iframe.attr("src", options['iframSrc']).load(function() {
  228. $loading.hide();
  229. $(this).css("left", 0);
  230. });
  231. };
  232. wTop = wTop-40;
  233. $newWin.find("div.win_bottom img").hover(function(){
  234. $(this).attr("src","/shares/images/master1/home.png");
  235. },function(){
  236. $(this).attr("src","/shares/images/master1/home_b.png");
  237. });
  238. $newWin.find("div.winClose").css({
  239. "left" : options['windowWidth']-20,
  240. "top" : -20,
  241. "z-index" : zindex+1
  242. });
  243. $allWins.removeClass("topWin").find("div.iframeFix").show();
  244. $newWin.addClass("topWin").css({
  245. "width" : options['windowWidth'],
  246. "height" : options['windowHeight']+65,
  247. "left" : wLeft,
  248. "top" : wTop,
  249. "z-index" : zindex
  250. }).find("div.winContent").css({
  251. "width" : options['windowWidth'],
  252. "height" : options['windowHeight'] - $winTitle.height()
  253. }).end().find("div.iframeFix").hide();
  254. _self.mask($newWin);
  255. if (!options.windowMaximize) {
  256. winMaximize_btn.hide();
  257. }
  258. if (!options.windowMinimize) {
  259. winMinimize_btn.hide();
  260. }
  261. if (!options.windowClosable) {
  262. winClose_btn.hide();
  263. }
  264. winHyimize_btn.hide();
  265. if (!options.windowAnimation) {
  266. $newWin.show(options.windowAnimationSpeed, function() {
  267. iframe_init();
  268. });
  269. } else {
  270. var o = $("#" + options.windowsId), offset = o.offset();
  271. $newWin.css({
  272. "left" : 0,
  273. "top" : 0
  274. }).animate({
  275. top : wTop,
  276. left : wLeft
  277. }, options.windowAnimationSpeed, function() {
  278. iframe_init();
  279. });
  280. }
  281. $newWin.data('winLocation', {
  282. 'w' : options['windowWidth'],
  283. 'h' : options['windowHeight']+65,
  284. 'left' : wLeft,
  285. 'top' : wTop,
  286. 'ch':options['windowHeight'] - $winTitle.height(),
  287. "closeLeft" : options['windowWidth']-20,
  288. "closeTop" : -20
  289. });
  290. $allWins.mousedown(function(event) {
  291. event.stopPropagation();
  292. var $topWin = $("div.topWin,div.topWin:hidden"), id = this.id;
  293. if (!$topWin.is($(this))) {
  294. var maxZindx = $topWin.removeClass("topWin").find(
  295. "div.iframeFix").show().end().css("z-index");
  296. $(this).css("z-index", parseInt(maxZindx) + 1).find(
  297. "div.iframeFix").hide().end().addClass("topWin");
  298. win8Desktop.taskBar.upTaskTab(id);
  299. }
  300. });
  301. var type = loadBrowserType();
  302. if("win"==type){
  303. if (options.windowDraggable) {
  304. _self.winDrag($newWin);
  305. }
  306. if (options.windowResizable) {
  307. _self.winResize($newWin, [ options.windowMinWidth,
  308. options.windowMinHeight, wh['w'] - wLeft,
  309. wh['h'] - wTop ]);
  310. }
  311. }
  312. winClose_btn.click(function() {
  313. _self.winClose($newWin);
  314. });
  315. winMaximize_btn.click(function() {
  316. _self.winMaximize($newWin);
  317. });
  318. $newWin.find("div.win_bottom").dblclick(function(){
  319. if ($newWin.data('windowStatus') == "maximized"){
  320. _self.winHyimize($newWin);
  321. }else{
  322. _self.winMaximize($newWin);
  323. }
  324. });
  325. winMinimize_btn.click(function() {
  326. _self.winMinize($newWin);
  327. });
  328. winHyimize_btn.click(function() {
  329. _self.winHyimize($newWin);
  330. });
  331. $winTitle.dblclick(function() {
  332. var hasMaximizeBtn = $(this).find(winMaximize_btn);
  333. if (!hasMaximizeBtn.is(":hidden")) {
  334. winMaximize_btn.trigger("click");
  335. } else {
  336. winHyimize_btn.trigger("click");
  337. }
  338. });
  339. $(window).wresize(
  340. function() {
  341. if ($newWin.data('windowStatus') == "maximized") {
  342. _self.winMaximize($newWin);
  343. }
  344. _self.winResize($newWin, [ options.windowMinWidth,
  345. options.windowMinHeight, $(window).width(),
  346. $(window).height() ]);
  347. });
  348. } else {
  349. if ($newWin.data('windowStatus') == "minsize") {
  350. _self.mask($newWin);
  351. win8Desktop.taskBar.openDialog(options.windowsId);
  352. // $("#taskTab_" + options.windowsId).click();
  353. }
  354. }
  355. },
  356. mask:function($newWin){
  357. //mask遮罩层
  358. var index = 1;
  359. if($newWin&&$newWin[0].style.zIndex){
  360. index = $newWin[0].style.zIndex -1;
  361. }
  362. var newMask = document.createElement("div");
  363. newMask.id = "win_mask";
  364. if($("#win_mask").length>0){
  365. newMask.id = "win_mask"+index;
  366. }
  367. newMask.setAttribute("name", "win_mask");
  368. newMask.style.position = "absolute";
  369. newMask.style.zIndex = index;
  370. _scrollWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
  371. _scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
  372. newMask.style.width = _scrollWidth + "px";
  373. newMask.style.height = _scrollHeight + "px";
  374. newMask.style.top = "0px";
  375. newMask.style.left = "0px";
  376. newMask.style.background = "#33393C";
  377. newMask.style.filter = "alpha(opacity=10)";
  378. newMask.style.opacity = "0.50";
  379. document.body.appendChild(newMask);
  380. },
  381. winDrag : function($newWin) {
  382. var winHeihgt = $newWin.height();
  383. var wh = {
  384. 'w' : $(window).width(),
  385. 'h' : $(window).height()
  386. }, _self = this;
  387. $newWin.draggable({
  388. handle : 'div.win_bottom',
  389. scroll : false
  390. }).bind("drag", function(event, ui) {
  391. $(this).find("div.iframeFix").show();
  392. }).bind("dragstop", function(event, ui) {
  393. $(this).find("div.iframeFix").hide();
  394. if (event.pageY > wh.h) {
  395. $(this).css("top", wh.h-winHeihgt);
  396. } else if (event.pageY < 0) {
  397. $(this).css("top", 0);
  398. }
  399. $newWin.data('winLocation', {
  400. 'w' : $(this).width(),
  401. 'h' : $(this).height(),
  402. 'left' : $(this).css("left"),
  403. 'top' : $(this).css("top")
  404. });
  405. });
  406. },
  407. winResize : function($newWin, arr) {
  408. var status = $newWin.data("windowStatus");
  409. var wh = {
  410. "w" : $(window).width(),
  411. "h" : $(window).height()
  412. };
  413. var w = Math.round(wh['w'] * 0.9);
  414. var h = Math.round(wh['h'] * 0.8);
  415. var dx = (wh['w'] - w) / 2;
  416. if("maximized" == status){
  417. w = wh['w'] - 2;
  418. h = wh['h'] - 60;
  419. dx = 0;
  420. $newWin.find("div.winClose").css({
  421. "left" : w-40,
  422. "top" : -10,
  423. });
  424. }else{
  425. $newWin.find("div.winClose").css({
  426. "left" : w-20,
  427. "top" : -20,
  428. });
  429. }
  430. if("minsize" == status){
  431. dx = -99999;
  432. }
  433. $newWin.css({
  434. "width" : w,
  435. "height" : h+65,
  436. "left" : dx
  437. }).find("div.winContent").css({
  438. "width" : w,
  439. "height" : h
  440. });
  441. },
  442. findTopWin : function($win, maxZ) {
  443. var topWin;
  444. $win.each(function(index) {
  445. if ($(this).css("z-index") == maxZ) {
  446. topWin = $(this);
  447. return false;
  448. }
  449. });
  450. return topWin;
  451. },
  452. findNextWin : function($win) {
  453. var nextWin;
  454. $win.each(function(index) {
  455. if (!$(this).hasClass("hideWin")) {
  456. var fix = $(this).find("div.iframeFix");
  457. if($(fix).css("display")=="block"){
  458. nextWin = $(this);
  459. }
  460. }
  461. });
  462. return nextWin;
  463. },
  464. winClose : function($newWin) {
  465. var $topWin = $("div.myWindow,div.myWindow:hidden"),
  466. nextWin = this.findNextWin($topWin);
  467. nextWin == undefined ? "" : nextWin.addClass("topWin");
  468. $newWin.remove();
  469. win8Desktop.taskBar.removeTaskTab($newWin.attr("id"));
  470. var winId = $newWin.attr("id");
  471. winId = winId.replace("win_","");
  472. win8Desktop.taskBar.removeTaskMap(winId);
  473. if (nextWin !== undefined) {
  474. nextWin.find("div.iframeFix").hide();
  475. }
  476. var winMask = $('[name="win_mask"]');
  477. let ix = 0;
  478. for(let i=0;i<winMask.length;i++){
  479. let maskId = winMask[i].id;
  480. let index = maskId.replace("win_mask", "");
  481. if(!index){
  482. continue;
  483. }
  484. if(parseInt(index) > ix){
  485. ix = index;
  486. }
  487. }
  488. if(ix === 0){
  489. $("#win_mask").remove();
  490. }else{
  491. $("#win_mask"+ix).remove();
  492. }
  493. },
  494. winMaximize : function($newWin) {
  495. var wh = {
  496. 'w' : $(window).width(),
  497. 'h' : $(window).height()
  498. }, winHyimize_btn = $newWin.find("a.winRestore"), winMaximize_btn = $newWin
  499. .find("a.winMaxBtn");
  500. $newWin.data("windowStatus", "maximized").removeClass("ui-state-disabled").css({
  501. "width" : wh['w'] - 2,
  502. "height" : wh['h'],
  503. "left" : 0,
  504. "top" : 0
  505. }).find("div.winContent").css({
  506. "width" : wh['w'] - 2,
  507. "height" : wh['h'] - 60
  508. });
  509. var closeObj = $newWin.find("div.winClose");
  510. $(closeObj).css({
  511. "left" : wh['w']-40,
  512. "top" : -10,
  513. });
  514. winMaximize_btn.hide();
  515. winHyimize_btn.css("display", "inline-block");
  516. },
  517. winHyimize : function($newWin) {
  518. var winInfo = $newWin.data("winLocation"), winHyimize_btn = $newWin
  519. .find("a.winRestore"), winMaximize_btn = $newWin
  520. .find("a.winMaxBtn");
  521. $newWin.data("windowStatus", "regular").css({
  522. "width" : winInfo.w,
  523. "height" : winInfo.h,
  524. "left" : winInfo.left,
  525. "top" : winInfo.top
  526. }).find("div.winContent").css({
  527. "width" : winInfo.w,
  528. "height" : winInfo.ch
  529. });
  530. $newWin.find("div.winClose").css({
  531. "left" : winInfo.closeLeft,
  532. "top" : winInfo.closeTop
  533. });
  534. winHyimize_btn.hide();
  535. winMaximize_btn.show();
  536. },
  537. winMinize : function($newWin) {
  538. var p = $("div.desktop").index($newWin.parent());
  539. $newWin.data({
  540. "oldLeft" : $newWin.css("left"),
  541. "index" : p
  542. }).css("left", -99999).addClass("hideWin");
  543. $newWin.data("windowStatus", "minsize");
  544. if ($("div.myWindow").size() > 1) {
  545. $newWin.removeClass("topWin");
  546. }
  547. nextWin = this.findNextWin($("div.myWindow,div.myWindow:hidden"));
  548. // nextWin = this.findTopWin($("div.myWindow,div.myWindow:hidden"),
  549. // parseInt($newWin.css("z-index")) - 1);
  550. if (nextWin !== undefined) {
  551. // nextWin.addClass("topWin").css("z-index",
  552. // parseInt($newWin.css("z-index")) + 1);
  553. // win8Desktop.taskBar.upTaskTab(nextWin.attr("id"));
  554. nextWin.find("div.iframeFix").hide();
  555. } else {
  556. $("div.taskTab").removeClass("taskCurrent");
  557. }
  558. $("#win_mask").remove();
  559. var winId = $newWin.attr("id");
  560. winId = winId.replace("win_","");
  561. var win = $("#"+winId);
  562. if(win.length==0){
  563. win = win8Desktop.taskMap.get(winId);
  564. }else{
  565. win = $(win).data("winAttrData");
  566. }
  567. if(win==null){
  568. var iframeName = "iframeApp_"+winId;
  569. var id = winId.split("_").slice(0);
  570. var deskWin = $("#"+id).data("winAttrData");
  571. var doc = window.frames[iframeName].document;
  572. var title = doc.title;
  573. if(!title){
  574. title = deskWin.title;
  575. }
  576. win = {"id":winId,"title":doc.title,"iconUrl":deskWin.iconUrl,"bgColor":deskWin.bgColor};
  577. }
  578. win8Desktop.taskBar.addNewTask(win.id, win.title,win.iconUrl,win.bgColor);
  579. }
  580. };
  581. win8Desktop.desktop = {
  582. init : function(data, options) {
  583. var defaults = {
  584. 'desktopMargin' : 70,
  585. 'iconMargin' : 7
  586. }, _self = this;
  587. var options = $.extend(defaults, options);
  588. $("body").data("desktopCofig", options);
  589. var desktopInner = $("#desktopInner"), desktop = $("div.desktop");
  590. $(desktopInner).css("left",0);
  591. _self.desktopIconInit(data);
  592. _self.iconSort();
  593. var innerWidth = $(desktopInner).width();
  594. $(window).wresize(function() {
  595. if($(".taskDesktop").length>0){
  596. win8Desktop.taskBar.showTask();
  597. return;
  598. }
  599. _self.desktopIconInit(data);
  600. _self.iconSort();
  601. _self.iconBehavior($("div.desktopIcon:not(.addIcon)"));
  602. _self.initDesktop();
  603. innerWidth = $(desktopInner).width();
  604. });
  605. _self.iconBehavior($("div.desktopIcon:not(.addIcon)"));
  606. if($.browser.msie&&$.browser.version == "8.0"){
  607. $(desktopInner).css({"background-image":"url(#)","filter":"alpha(opacity=0)","opacity":"0"});
  608. }
  609. desktopInner.bind("mousedown",function(e){
  610. var wh = $(window).width();
  611. var dx = e.pageX;
  612. if((wh-dx)<50){
  613. $(desktopInner).css({"width":"100%"});
  614. $(desktopInner).css({"overflow":"hidden"});
  615. }
  616. }).bind("mouseup",function(e){
  617. $(desktopInner).css({"width":innerWidth});
  618. });
  619. var type = loadBrowserType();
  620. if("ipad"==type){
  621. $.fn.draggable = function(action) {
  622. var start = function(e) {
  623. var orig = e.originalEvent;
  624. timeStart = new Date().getTime();
  625. dxStart = orig.changedTouches[0].pageX;
  626. };
  627. var move = function(e) {
  628. var orig = e.originalEvent;
  629. var wt = $(window).width()-80;
  630. var dx = orig.changedTouches[0].pageX;
  631. if(dx>wt){
  632. return false;
  633. }
  634. };
  635. var stop = function(e){
  636. var event = e.originalEvent;
  637. $(this).css("cursor", "inherit");
  638. timeEnd = new Date().getTime();
  639. desktop = $("div.desktop");
  640. dxEnd = event.changedTouches[0].pageX;
  641. var timeCha = (timeEnd - timeStart) > 2 ? 2: (timeEnd - timeStart),
  642. dxCha = dxEnd - dxStart,
  643. currDesktop = $(this).find("div.currDesktop"),
  644. deskIndex = desktop.index(currDesktop),
  645. moveDx = currDesktop.width()+ options.desktopMargin,
  646. dates = 1000 + timeCha;
  647. if (dxCha < -150 && deskIndex < desktop.size() - 1) {
  648. _self.desktopMove(dates, moveDx, deskIndex + 1);
  649. } else if (dxCha > 150 && deskIndex > 0) {
  650. _self.desktopMove(dates, moveDx, deskIndex - 1);
  651. } else {
  652. $(this).animate({
  653. left : -(deskIndex) * moveDx
  654. }, 500);
  655. }
  656. };
  657. this.bind("touchstart", start);
  658. this.bind("touchmove", move);
  659. this.bind("touchend", stop);
  660. };
  661. desktopInner.draggable();
  662. }else{
  663. desktopInner.draggable({
  664. axis : 'x',
  665. start : function(event, ui) {
  666. $(this).css("cursor", "move");
  667. timeStart = new Date().getTime();
  668. dxStart = event.pageX;
  669. },
  670. drag :function(event, ui){
  671. var wt = $(window).width()-80;
  672. var dx = event.pageX;
  673. if(dx>wt){
  674. return false;
  675. }
  676. },
  677. stop : function(event, ui) {
  678. $(this).css("cursor", "inherit");
  679. timeEnd = new Date().getTime();
  680. desktop = $("div.desktop");
  681. dxEnd = event.pageX;
  682. var timeCha = (timeEnd - timeStart) > 2 ? 2: (timeEnd - timeStart),
  683. dxCha = dxEnd - dxStart,
  684. currDesktop = $(this).find("div.currDesktop"),
  685. deskIndex = desktop.index(currDesktop),
  686. moveDx = currDesktop.width()+ options.desktopMargin,
  687. dates = 1000 + timeCha;
  688. if (dxCha < -150 && deskIndex < desktop.size() - 1) {
  689. _self.desktopMove(dates, moveDx, deskIndex + 1);
  690. } else if (dxCha > 150 && deskIndex > 0) {
  691. _self.desktopMove(dates, moveDx, deskIndex - 1);
  692. } else {
  693. $(this).animate({
  694. left : -(deskIndex) * moveDx
  695. }, 500);
  696. }
  697. }
  698. });
  699. }
  700. },
  701. desktopMove : function(dates, moveDx, nextIndex) {
  702. var desktopInner = $("#desktopInner"), desktop = desktopInner
  703. .find("div.desktop");
  704. desktopInner.stop().animate(
  705. {
  706. left : -nextIndex * moveDx
  707. },
  708. dates,
  709. function() {
  710. desktop.removeClass("currDesktop").eq(nextIndex).addClass(
  711. "currDesktop");
  712. var deskId = $(desktop).eq(nextIndex).attr("id");
  713. if(!deskId)return;
  714. var currentId = deskId.split("_");
  715. $(".pageCount img").attr("src","/shares/images/master1/ce_white.png");
  716. $("#pc_"+currentId[1]).find("img").attr("src","/shares/images/master1/ce_blue.png");
  717. });
  718. },
  719. initDesktop:function(){
  720. win8Desktop.desktop.desktopMove(1000,0,0);
  721. },
  722. changeDesktop:function(options,e){
  723. $(".pageCount img").attr("src","/shares/images/master1/ce_white.png");
  724. $("img",e).attr("src","/shares/images/master1/ce_blue.png");
  725. var clickDesk = $(e).attr("id");
  726. var clickId = clickDesk.split("_");
  727. var i = clickId[1];
  728. var currDesktop = $("div.currDesktop");
  729. var moveDx = currDesktop.width()+ options.desktopMargin;
  730. var nextIndex = i-1;
  731. var desktopInner = $("#desktopInner"), desktop = desktopInner
  732. .find("div.desktop");
  733. desktopInner.stop().animate(
  734. {
  735. left : -nextIndex * moveDx
  736. },
  737. 1000,
  738. function() {
  739. desktop.removeClass("currDesktop").eq(nextIndex).addClass(
  740. "currDesktop");
  741. });
  742. },
  743. iconBehavior : function(o) {
  744. var type = loadBrowserType();
  745. if("win"==type){
  746. o.hover(function() {
  747. $(this).append("<div class='hover'></div>");
  748. }, function() {
  749. $(this).find("div.hover").remove();
  750. }).on(
  751. "click",
  752. function() {
  753. var winData = $(this).data("winAttrData");
  754. var url = winData.url;
  755. var str = "?";
  756. if(url.indexOf("?")){
  757. str = "&";
  758. }
  759. url = url+str+"t="+new Date().getTime();
  760. win8Desktop.myWindow.init({
  761. windowTitle : winData.title,
  762. windowsId : winData.id+"_"+new Date().getTime(),
  763. // windowsId : winData.id,
  764. iframSrc : url,
  765. windowResizable:false
  766. });
  767. // if (!$("#taskTab_" + winData.id).size()) {
  768. // win8Desktop.taskBar.addTask(winData.id, winData.title,
  769. // winData.iconUrl);
  770. // }
  771. });
  772. }else{
  773. o.on("click",
  774. function() {
  775. var winData = $(this).data("winAttrData");
  776. var url = winData.url;
  777. var str = "?";
  778. if(url.indexOf("?")){
  779. str = "&";
  780. }
  781. url = url+str+"t="+new Date().getTime();
  782. win8Desktop.myWindow.init({
  783. windowTitle : winData.title,
  784. windowsId : winData.id+"_"+new Date().getTime(),
  785. iframSrc : url,
  786. windowResizable:false
  787. });
  788. });
  789. }
  790. },
  791. iconSort : function() {
  792. var desktopWrap = $("#desktopWrap"), desktopInner = $("#desktopInner"), desktop = $("div.desktop"),
  793. header = $("#header"),
  794. ww = $(window).width(),
  795. wh = $(window).height();
  796. var dh = wh * 0.6, opt = $("body").data("desktopCofig");
  797. dh = wh - (wh * 0.4 / 2)-155;
  798. var maxRows = Math.round(dh / (107 + opt.iconMargin)), dinnerWidth = 0;
  799. desktopWrap.css({
  800. "height" : dh,
  801. "top" : wh * 0.4 / 2
  802. });
  803. header.css("left", opt.desktopMargin);
  804. desktop.find("div.desktopIcon").css({
  805. "margin-left" : opt.iconMargin,
  806. "margin-top" : opt.iconMargin
  807. });
  808. desktop.eq(0).addClass("currDesktop");
  809. desktop.each(function() {
  810. var desktopIcon = $(this).find("div.desktopIcon"),
  811. iconNum = $(this).find(".minStyle").size()+ $(this).find(".bigStyle").size() * 2,
  812. tw = ww-(108 + opt.iconMargin);//Math.ceil(iconNum/maxRows)* (118 + opt.iconMargin);
  813. $(this).css({
  814. "width" : tw,
  815. "height" : dh,
  816. "margin-left" : opt.desktopMargin
  817. });
  818. dinnerWidth += tw + opt.desktopMargin;
  819. var bigIcon = $(this).find(".bigStyle").find(".iconText");
  820. var textHeight = bigIcon.height();
  821. bigIcon.css("padding-top", (107 - textHeight) / 2);
  822. });
  823. desktopInner.width(dinnerWidth);
  824. },
  825. desktopIconInit : function(data) {
  826. var opt = $("body").data("desktopCofig");
  827. $("#pageCount").empty();
  828. var ww = $(window).width();
  829. var deskWidth = ww-(108 + opt.iconMargin);
  830. var totleWidth = 0;
  831. var wh = $(window).height();
  832. var dh = wh * 0.6;
  833. dh = wh - (wh * 0.4 / 2)-155;
  834. var row = (Math.floor(dh/108));
  835. if(!row){
  836. $("#desktopInner").html("");
  837. return;
  838. }
  839. var j = 1;
  840. var d = 1;
  841. var html = "";
  842. var last = 0;
  843. for ( var a in data) {
  844. var arr = data[a];
  845. if(!arr){
  846. break;
  847. }
  848. for ( var i = 0; i < arr.length; i++) {
  849. var type = arr[i].iconType;
  850. if("bigStyle" == type){
  851. totleWidth += 230;
  852. last = 230;
  853. }else{
  854. totleWidth += 115;
  855. last = 115;
  856. }
  857. if(totleWidth>deskWidth){
  858. totleWidth = last;
  859. j++;
  860. }
  861. if(j > row){
  862. d++;
  863. html += "</div>";
  864. if(i!=arr.length){
  865. $("div#pc_1").show();
  866. $("#pageCount").append("<div class='pageCount' id='pc_"+d+"'></div>");
  867. $("div#pc_"+d).bind("click",function(){
  868. win8Desktop.desktop.changeDesktop(opt,this);
  869. }).html("<img src='/shares/images/master1/ce_white.png' />");
  870. html += "<div class='desktop' id='desktop_" + d + "'>";
  871. }
  872. j = 1;
  873. }
  874. if(i==0){
  875. $("#pageCount").append("<div class='pageCount currentPage' id='pc_"+d+"'></div>");
  876. $("div#pc_"+d).bind("click",function(){
  877. win8Desktop.desktop.changeDesktop(opt,this);
  878. }).html("<img src='/shares/images/master1/ce_blue.png' />").hide();
  879. html += "<div class='desktop' id='desktop_" + d + "'>";
  880. }
  881. html += "<div class='desktopIcon " + arr[i].iconType + "' id='"
  882. + arr[i].id + "' style='background-color:"
  883. + arr[i].bgColor + "'>";
  884. if (win8Desktop.trim(arr[i].iconUrl).length) {
  885. html += "<div class='iconImg'><img src='" + arr[i].iconUrl
  886. + "' title='" + arr[i].title
  887. + "'/></div><div class='iconText'>" + arr[i].title
  888. + "</div>";
  889. } else {
  890. html += "<div class='iconText_noIcon'>" + arr[i].title
  891. + "</div>";
  892. }
  893. var extHtml = arr[i].extHtml;
  894. if(extHtml){
  895. html += extHtml;
  896. }
  897. html += "</div>";
  898. }
  899. //html += "<div class='desktopIcon addIcon minStyle'><a class='iconImg'></a><div class='iconText'>添加应用</div></div>";
  900. html += "</div>";
  901. }
  902. $("#desktopInner").html(html);
  903. $("#desktopInner").css({"index":1});
  904. for ( var a in data) {
  905. var arr = data[a];
  906. if(!arr){
  907. break;
  908. }
  909. for ( var i = 0; i < arr.length; i++) {
  910. $("#" + arr[i].id).data("winAttrData", arr[i]);
  911. }
  912. }
  913. }
  914. };
  915. win8Desktop.taskMap = new map();
  916. win8Desktop.taskBar = {
  917. init : function() {
  918. this.taskData();
  919. var taskBarData = $("body").data("taskBar"), taskNextBox = taskBarData.taskNextBox, taskPreBox = taskBarData.taskPreBox, ww = taskBarData.ww, taskInnnerBlock = taskBarData.taskInnnerBlock, taskOuterBlock = taskBarData.taskOuterBlock, ow = ww
  920. - taskNextBox.outerWidth(true) * 2, _self = this;
  921. taskOuterBlock.width(ow);
  922. $(window).wresize(
  923. function() {
  924. taskOuterBlock.width($(window).width()
  925. - taskNextBox.outerWidth(true) * 2);
  926. });
  927. function taskMove(a) {
  928. taskInnnerBlock.animate({
  929. "margin-right" : '+=' + a
  930. }, 1000);
  931. }
  932. taskNextBox
  933. .on(
  934. "click",
  935. function() {
  936. var mr = taskInnnerBlock.css("margin-right"), mr = parseInt(mr), taskTabWidth = $(
  937. "body").data("tabWidth");
  938. if (Math.abs(mr) > taskTabWidth) {
  939. taskMove(taskTabWidth);
  940. } else {
  941. taskMove(Math.abs(mr));
  942. }
  943. });
  944. taskPreBox
  945. .on("click",
  946. function() {
  947. var ml = taskInnnerBlock.position(), ml = Math
  948. .abs(ml.left), taskTabWidth = $("body")
  949. .data("tabWidth");
  950. if (ml > taskTabWidth) {
  951. taskMove(taskTabWidth * -1);
  952. } else {
  953. taskMove(ml * -1);
  954. }
  955. });
  956. },
  957. taskData : function() {
  958. $("body").data("taskBar", {
  959. taskBlock : $("#taskBlock"),
  960. taskInnnerBlock : $("#taskInnnerBlock"),
  961. taskOuterBlock : $("#taskOuterBlock"),
  962. taskNextBox : $("#taskNextBox"),
  963. taskPreBox : $("#taskPreBox"),
  964. ww : $(window).width(),
  965. wh : $(window).height()
  966. });
  967. },
  968. upTaskTab : function(id) {
  969. var str = id.split("_").slice(1);
  970. $("div.taskTab").removeClass("taskCurrent");
  971. $("#taskTab_" + str).parent().addClass("taskCurrent");
  972. },
  973. removeTaskTab : function(id) {
  974. var str = id.replace("win_",""),
  975. taskBarData = $("body").data("taskBar"), taskTabWidth = $("body").data("tabWidth");
  976. $("#taskTab_" + str).remove();
  977. var taskTabNum = $("div.taskTab").size(), maxTabNum = $("body").data(
  978. "maxTabNum");
  979. taskBarData.taskInnnerBlock.width(taskTabNum * taskTabWidth);
  980. if (taskTabNum <= maxTabNum) {
  981. taskBarData.taskNextBox.hide();
  982. taskBarData.taskPreBox.hide();
  983. }
  984. },
  985. removeTaskMap:function(key){
  986. key = win8Desktop.trim(key);
  987. var taskMap = win8Desktop.taskMap;
  988. var tempTaskMap = new map();
  989. for (var i = 0; i < taskMap.arr.length; i++) {
  990. if (taskMap.arr[i].key !== key){
  991. tempTaskMap.put(taskMap.arr[i].key, taskMap.arr[i].value);
  992. }
  993. }
  994. win8Desktop.taskMap = tempTaskMap;
  995. win8Desktop.taskBar.taskCount();
  996. },
  997. removeCurrentTask:function(id){
  998. var winId = "win_"+id;
  999. winId = win8Desktop.trim(winId);
  1000. win8Desktop.taskBar.removeTaskTab(winId);
  1001. win8Desktop.taskBar.removeTaskMap(id);
  1002. },
  1003. removeAllTask:function(id){
  1004. $(".taskTab").remove();
  1005. win8Desktop.taskMap = new map();
  1006. win8Desktop.taskBar.taskCount();
  1007. },
  1008. removeFirstTask:function(){
  1009. var key = win8Desktop.taskMap.arr[0].key;
  1010. var winId = "win_"+key;
  1011. win8Desktop.taskBar.removeTaskTab(winId);
  1012. win8Desktop.taskBar.removeTaskMap(key);
  1013. win8Desktop.taskBar.taskCount();
  1014. },
  1015. addNewTask:function(id, text, icon,bgColor){
  1016. var taks = {"id":id,"title":text,"iconUrl":icon,"bgColor":bgColor};
  1017. win8Desktop.taskMap.put(id,taks);
  1018. win8Desktop.taskBar.taskCount();
  1019. },
  1020. taskCount:function(){
  1021. var taskLen = win8Desktop.taskMap.arr.length;
  1022. if(taskLen==0){
  1023. $(".task_count").hide();
  1024. }else{
  1025. $(".task_count").show();
  1026. $(".task_count").html(taskLen);
  1027. }
  1028. },
  1029. openDialog:function(id){
  1030. var win = $("#win_" + id),
  1031. des = $("#" + id).parents("div.desktop"),
  1032. left = win.data("oldLeft");
  1033. if (win.hasClass("hideWin")) {
  1034. win.css("left", left).removeClass("hideWin");
  1035. }
  1036. win.data('windowStatus',"");
  1037. win.trigger("mousedown");
  1038. $("#taskBlock").hide();
  1039. },
  1040. showTask:function(){
  1041. var map = win8Desktop.taskMap;
  1042. var taskInnnerBlock = $("#desktopInner");
  1043. $(taskInnnerBlock).addClass("taskDesktop");
  1044. $(taskInnnerBlock).empty();
  1045. var data = new Array();
  1046. var desk = new Array();
  1047. for(var i=0,j=map.arr.length;i<map.arr.length;i++,j--){
  1048. data[i] = map.arr[j-1].value;
  1049. data[i]["iconType"] = "minStyle";
  1050. }
  1051. desk[0] = data;
  1052. var html = win8Desktop.taskBar.getTaskHtml(desk);
  1053. $(taskInnnerBlock).append(html);
  1054. win8Desktop.desktop.iconSort();
  1055. win8Desktop.desktop.initDesktop();
  1056. win8Desktop.taskBar.bindEventTask();
  1057. var type = loadBrowserType();
  1058. if("win"==type){
  1059. $("#taskTab_clear").hover(function(){
  1060. $(this).append("<div class='hover'></div>");
  1061. }, function() {
  1062. $(this).find("div.hover").remove();
  1063. }).bind("click",function(){
  1064. win8Desktop.taskBar.removeAllTask();
  1065. $("#task_task").click();
  1066. });
  1067. }else{
  1068. $("#taskTab_clear").bind("click",function(){
  1069. win8Desktop.taskBar.removeAllTask();
  1070. $("#task_task").click();
  1071. });
  1072. }
  1073. },
  1074. getTaskHtml :function(data){
  1075. var opt = $("body").data("desktopCofig");
  1076. $("#pageCount").empty();
  1077. var ww = $(window).width();
  1078. var deskWidth = ww-(108 + opt.iconMargin);
  1079. var totleWidth = 0;
  1080. var wh = $(window).height();
  1081. var dh = wh * 0.6;
  1082. dh = wh - (wh * 0.4 / 2)-155;
  1083. var row = (Math.floor(dh/108));
  1084. if(!row){
  1085. $("#desktopInner").html("");
  1086. return;
  1087. }
  1088. var j = 1;
  1089. var d = 1;
  1090. var html = "";
  1091. var last = 0;
  1092. var arr = data[0];
  1093. for ( var i = 0; i < arr.length; i++) {
  1094. var type = arr[i].iconType;
  1095. if("bigStyle" == type){
  1096. totleWidth += 230;
  1097. last = 230;
  1098. }else{
  1099. totleWidth += 115;
  1100. last = 115;
  1101. }
  1102. if(totleWidth>deskWidth){
  1103. totleWidth = last;
  1104. j++;
  1105. }
  1106. if(j > row){
  1107. d++;
  1108. html += "</div>";
  1109. if(i!=arr.length){
  1110. $("div#pc_1").show();
  1111. $("#pageCount").append("<div class='pageCount' id='pc_"+d+"'></div>");
  1112. $("div#pc_"+d).bind("click",function(){
  1113. win8Desktop.desktop.changeDesktop(opt,this);
  1114. }).html("<img src='/shares/images/master1/ce_white.png' />");
  1115. html += "<div class='desktop' id='desktop_" + d + "'>";
  1116. }
  1117. j = 1;
  1118. }
  1119. if(i==0){
  1120. $("#pageCount").append("<div class='pageCount currentPage' id='pc_"+d+"'></div>");
  1121. $("div#pc_"+d).bind("click",function(){
  1122. win8Desktop.desktop.changeDesktop(opt,this);
  1123. }).html("<img src='/shares/images/master1/ce_blue.png' />").hide();
  1124. html += "<div class='desktop currDesktop' id='desktop_" + d + "'>";
  1125. }
  1126. var taskTabHtml = '<div class="desktopIcon minStyle taskTab" id="taskTab_'+arr[i].id+'" style="margin-top: 7px; margin-left: 7px;background:'+arr[i].bgColor+'">';
  1127. taskTabHtml += '<div class="task_remove" style="position:absolute;width:100px;display:none;color:red;z-index:999">';
  1128. taskTabHtml += '<div class="task_remove_img" style=";width:12px;height:12px;float:right;margin-top:3px;" id="task_remove_'+arr[i].id+' ">';
  1129. taskTabHtml += ' <span>';
  1130. taskTabHtml += ' <img src="/shares/images/master1/app/icon_minus.png" />';
  1131. taskTabHtml += ' </span>';
  1132. taskTabHtml += '</div>';
  1133. taskTabHtml += '</div>';
  1134. taskTabHtml += '<div class="iconImg">';
  1135. taskTabHtml += ' <img title="'+arr[i].title+'" src="'+arr[i].iconUrl+'">';
  1136. taskTabHtml += '</div><div class="iconText">'+arr[i].title+'</div>';
  1137. taskTabHtml += '</div>';
  1138. html = html + taskTabHtml;
  1139. }
  1140. if(arr.length==0){
  1141. html += "<div class='desktop currDesktop' id='desktop_" + d + "'>";
  1142. }
  1143. var clearTabHtml = '<div class="desktopIcon minStyle" id="taskTab_clear" style="margin-top: 7px; margin-left: 7px">';
  1144. clearTabHtml += '<div id="task_remove_clear" class="task_remove" style="position:absolute;display:none;float:right;width:12px;height:12px;border:1px solid #ccc;color:red;z-index:999">-</div>';
  1145. clearTabHtml += '<div class="iconImg">';
  1146. clearTabHtml += ' <img title="清空" src="/shares/images/master1/icon/clear.png">';
  1147. clearTabHtml += '</div><div class="iconText">清空</div>';
  1148. clearTabHtml += '</div>';
  1149. html = html + clearTabHtml;
  1150. html += "</div>";
  1151. return html;
  1152. },
  1153. bindEventTask : function() {
  1154. var taskBarData = $("body").data("taskBar"),
  1155. taskNextBox = taskBarData.taskNextBox,
  1156. taskPreBox = taskBarData.taskPreBox,
  1157. ww = taskBarData.ww;
  1158. $("div.taskTab").removeClass("taskCurrent");
  1159. $("div.task_remove_img").each(function(){
  1160. $(this).bind("click",function(){
  1161. var removeId = this.id;
  1162. var tid = removeId.replace("task_remove_","");
  1163. win8Desktop.taskBar.removeCurrentTask(tid);
  1164. win8Desktop.taskBar.showTask();
  1165. });
  1166. });
  1167. var taskTab = $("div.taskTab"),
  1168. tabNum = taskTab.size(),
  1169. tabWidth = taskTab.width();
  1170. maxTabNum = Math.floor((ww - taskNextBox.outerWidth() * 2) / tabWidth);
  1171. var type = loadBrowserType();
  1172. if("win"==type){
  1173. $(taskTab).hover(function(){
  1174. $(this).append("<div class='hover'></div>");
  1175. $(".task_remove",this).show();
  1176. }, function() {
  1177. $(".task_remove",this).hide();
  1178. $(this).find("div.hover").remove();
  1179. });
  1180. }
  1181. $("body").data({
  1182. "tabWidth" : tabWidth,
  1183. "maxTabNum" : maxTabNum
  1184. });
  1185. $(".taskTab").on("click",
  1186. function() {
  1187. var taskId = $(this).attr("id");
  1188. var id = taskId.replace("taskTab_","");
  1189. var win = $("#win_" + id);
  1190. win8Desktop.myWindow.mask($(win));
  1191. win8Desktop.taskBar.openDialog(id);
  1192. });
  1193. if (tabNum > maxTabNum) {
  1194. taskNextBox.show();
  1195. taskPreBox.show();
  1196. }
  1197. }
  1198. };